From 5835379ec30b1667c4e522db9d294c9b7bb8633a Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期二, 26 四月 2022 12:00:31 +0800
Subject: [PATCH] SSBG Back up

---
 force-app/main/default/classes/NewQuoteEntryController.cls | 9759 ++++++++++++++++++++++++++++++-----------------------------
 1 files changed, 4,965 insertions(+), 4,794 deletions(-)

diff --git a/force-app/main/default/classes/NewQuoteEntryController.cls b/force-app/main/default/classes/NewQuoteEntryController.cls
index 2547ecc..bec9234 100644
--- a/force-app/main/default/classes/NewQuoteEntryController.cls
+++ b/force-app/main/default/classes/NewQuoteEntryController.cls
@@ -1,4887 +1,5058 @@
-// FIXME 瑕嬬銈傘倞鍟嗗搧銇� Asset_Model_No__c 銇с仚銇屻�佹暟寮忋伀銇仯銇︺亜銇俱仚銆傘儓銉┿兂銈躲偗銈枫儳銉炽儑銉笺偪銇ㄣ仐銇︺�侀爡鐩倰鎸併仱銇广亶銇嬨仺鎬濄亜銇俱仚銆俠y katsu 20130216
-// 鍟嗚珖鍟嗗搧銇甀d__c 銈� PricebookEntry.Product2Id銇鏇淬仚銇广亶
-// 瑕嬬銈傘倞鍙惁 銇с仚銇屻�佷繚瀛樻檪銇裤仸銇勩伨銇欍亴銆丼ales_Possibility銈掕銇亜銇с仚銇嬶紵銇勩亜銇堛�乯s鍋淬仹瑕嬨仸銇勩伨銇�
-public class NewQuoteEntryController {
-  public Integer quoteEntryMaxLine { get; private set; }
-  public Id oppId { get; set; }
-  public Id quoId { get; set; }
-  public Boolean productStatusUpdated { get; set; }               // 鐘舵厠鏇存柊銆亄!$Label.Status_Update} 銈掓娂涓嬨仐銇熴亱銇┿亞銇�
-  public Boolean changedAfterPrint { get; set; }                  // true 銇牬鍚堛�佺敾闈€伀 confirm 銉°儍銈汇兗銈搞亴琛ㄧず銇椼伨銇欍�俼uoId銈掓柊銇椼亜insert銆傚垽瀹氥伅js銇仸瀹熸柦
-  public Boolean changedAfterBid { get; set; }                    // true 銇牬鍚堛�佺敾闈€伀 confirm 銉°儍銈汇兗銈搞亴琛ㄧず銇椼伨銇欍�俼uoId銈掓柊銇椼亜insert銆傚垽瀹氥伅js銇仹瀹熸柦
-  //public Id qlistId { get; set; }
-  //lastbuy  2022/2/9 fy start
-  public Boolean filg { get; set; }
-  //lastbuy  2022/2/9 fy end
+public without sharing class NewQuoteEntryController {
+    public Integer quoteEntryMaxLine {get; private set;}
+    public Integer quoteEntryMaxSet {get; private set;}
 
-  public String excel_text { get; set; }
-  public Integer select_index { get; set; }                       // excelImport灏傜敤銇с仚銇屻�乯s銇仸鍒跺尽銇欍倠銇撱仺銇仾銈嬨伄銇с�乀ODO katsu 鍓婇櫎浜堝畾
-  public String Product_text { get; set; }
-  public String setProduct_text { get; set; }
+    public Id oppId { get; set; }
+    public Id quoId {get;set;}
+    public Id pricebook2Id {get;set;}
+    public Id accountId {get;set;}
+    public String currencyIsoCode {get;set;}
 
-  public List<QELine> activities { get; set; }
-  public List<QELine> tmpactivities { get; set; }
-  public QELine active_activity { get; set; }
-  public OppInfo oppInfo { get; set; }
-  //鐢ㄤ簬妫�鏌ヨ浠锋姤浠峰叿浣撲骇鍝佺姸鎬佹槸鍚﹀彉鏇�
-  public List<QuoteLineItem> CheckItem {get; set;}
-  //鍊ゅ紩銇�
-  public Decimal DisCalculation { get; set; }
-  public Decimal DisAmount { get; set; }
+    public boolean specialerrorflg {get;set;}
+    public boolean errorflg {get;set;}
+    public String errorMessage {get;set;}
 
-  //绗竴璨╁2搴�
-  //public String SalesName1 { get; set; }
-  public String SalesShopClass1 { get; set; }
-  //public Decimal SalesAmount1 { get; set; }
-  public Decimal Salesprofit1 { get; set; }
-  public Decimal SalesCalculation1 { get; set; }
-  public String SalesId1 { get; set; }
-  // 2018/09/29 CHAN-B4YAB8 缁忛攢鍟嗘姌鎵� start
-  public Decimal AgencyDiscount { get; set; }
-  //绗簩璨╁2搴�
-  //public String SalesName2 { get; set; }
-  public String SalesShopClass2 { get; set; }
-  //public Decimal SalesAmount2 { get; set; }
-  public Decimal Salesprofit2 { get; set; }
-  public Decimal SalesCalculation2 { get; set; }
-  public String SalesId2 { get; set; }
-  //鐥呴櫌銉炪偣銈块伕鎶炪儶銈广儓
-  public String selection_hp { get; set; }
-  public List<SelectOption> options_hp { get; set; }
-  //鐢婚潰鍒跺尽鍒ゅ畾鐢�
-  public Boolean displayCost { get; set; }
-  //public Boolean enableEntry { get; set; }
-  public Boolean enableSales { get; set; }
-  public Boolean specialAuthority { get; set; }
-  public Boolean verified { get; set; }
-  public Boolean QuoteDecision { get; set; }
-  public boolean QuoteDecide {get; set;}
-  public Boolean QuoteSapSented { get; set; }
-  public Boolean QuoteCorrect { get; set; }
-  //public Boolean salesEntry { get; set; }
-  public Boolean enableContract { get; set; }
-  //銉溿偪銉冲埗寰$敤
-  public Boolean print_button { get; set; }
-  public Boolean sap_button { get; set; }
-  public Boolean Decision_button { get; set; }
-  public Boolean Save_button { get; set; }
-  public Boolean WinOrDecideAlert {get; set;}
+    public boolean Messageflg {get;set;}
+    public String Message {get;set;}
+    
+    public Quote quo {get;set;}
+    public Decimal discount {get;set;}
+    public List<QELine> activities {get;set;}
+    private List<QELine> activitiesbk;
+    public List<QELine> tmpactivities = new List<QELine>();
+    public QELine active_activity;
+    public Boolean productStatusUpdated;
+    public List<Boolean> hidFlg {get;set;}
+    public String excel_text { get; set; }
+    public String baseUrl { get; set; }
+    public String rtUrl { get; set; }
 
-  public Boolean over3month { get; set; }
-  public Boolean newQuoteFlag=false;
+    public boolean decideFlg { get; set; }
+    public boolean isdecide { get; set; }
+    public boolean printFlg { get; set; }
+    private boolean doDecide { get; set; }
+    public String productSegment { get; set; }
+    public boolean isAdmin { get; set; }
 
-  // 澶氬勾淇濅慨 start
-  public string trade {get; private set;}
-  public string quoteGurantee_Period;
-  public string quotemultiYearWarranty;
-  // 澶氬勾淇濅慨 end
-  //鎶ヤ环璇曠畻 鍒ゆ柇缁忛攢鍟嗘槸鍚﹀彉鍖� start
-  public string agency1Name;
-  public string agency2Name;
-  //鎶ヤ环璇曠畻 鍒ゆ柇缁忛攢鍟嗘槸鍚﹀彉鍖� end
-  public Boolean getHiddenSaveBtn() {
-    Boolean rtn = quo.Cancel_Decide__c;
-    Schema.DescribeSObjectResult quoteDesc = Quote.SObjectType.getDescribe();
-    rtn = (rtn == false) ? !quoteDesc.isUpdateable() : rtn;
-    return rtn;
-  }
-  //瑕嬬瑾挎暣閲戦
-  //public Decimal QuoAmount { get; set; }
-  //public Decimal QuoCalculation { get; set; }
-  //瑕嬬
-  public Pricebook2 standardPricebook;                // 鐢婚潰涓婁娇銈忋仾銇勩仧銈併�乬et set銇仐
-  public Quote quo { get; set; }
-  public Decimal quoStocking_Price_c { get; set; }
+    public String fileName { get; set; }
+    public String strExpirationDate { get; set; }
+    public List<QELine> csv_activities {get;set;}
+    public Blob contentFile { get; set; }
+    public String nameFile { get; set; }
 
-  //Get Opportunity Object
-  public Opportunity opp;
+    public String openType { get; set; }
+    public boolean isService { get; set; }
+    public boolean is_Parts_direct { get; set; }
+    public boolean is_Parts_dealer { get; set; }
+    public boolean is_hidden_user { get; set; }
+    public boolean is_dealer_user { get; set; }
 
-  private Map<Id, Product2> prd2LatestValMap;
+    public boolean is_hidden_all { get; set; }
+    public Decimal dealer_coefficient { get; set; }
 
-  public boolean errorflg { get; set; }
-  public String errorMessage { get; set; }
-  public String errorMessagechack { get; set; }
-  public String baseUrl { get; set; }
-  public boolean Messageflg { get; set; }
-  public String Message { get; set; }
-  public Boolean viewSpecialAgencyAmout { get; set; }
-  public Boolean displayFlg { get; set; }
-  public QuoteBean qb { get; set; }
-  public Integer rowIdx { get; set; }
+    public Boolean specialDealer { get; set; }
+    //XHL-20190426-AddStart
+    public String setProduct_text { get; set; }
+    public Integer activitiesSize {get;set;}
+    public Integer singleNo {get;set;}
+    public Map<String,String> errorMap {get;set;}
+    public String singleProduct {get; private set;}
+    public Map<String,String> quoteLineSetNameDiscountMap {get; private set;}
+    public String quoteLineSetNameDiscountJson {get; private set;}
+    //XHL-20190426-AddEnd
+    public Opportunity opp {get;set;}
 
-  public NewQuoteEntryController() {
-    quoteEntryMaxLine = Integer.valueOf(System.Label.QuoteEntryMaxLine2);
-    //Apexpages.currentPage().getHeaders().put('X-UA-Compatible', 'IE=8');
-    baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
-    changedAfterPrint = false;
-    changedAfterBid = false;
-    productStatusUpdated = false;
-    // CHAN-AVG3PW 璇环鎶ヤ环鐢婚潰瑙勫垯鍙樻洿
-    over3month = false;
-    newQuoteFlag = false;
-  }
+    // WLIG-BTA8C2 XHL 20200925 -Start
+    public String initStringConcatenation;
+    public String saveStringConcatenation;
+    public Boolean verifyProductValidFlag;
+    // WLIG-BTA8C2 XHL 20200925 -End
+    private static Map<String, String> paymentTermsMap = new Map<String, String> {
+        'Z001' => '棰勬敹娆�/棰勪粯娆�',
+        'Z002' => '绔嬪嵆浠樻',
+        'Z003' => '鏈堢粨30澶╁唴浠樻',
+        'Z004' => '鏈堢粨60澶╁唴浠樻',
+        'Z005' => '鏈堢粨90澶╁唴浠樻',
+        'Z006' => '鏈堢粨120澶╁唴浠樻',
+        'Z007' => '鏈堢粨25澶╁唴浠樻',
+        'Z008' => '鏈堢粨55澶╁唴浠樻',
+        'Z009' => '鏈堢粨85澶╁唴浠樻',
+        'Z010' => '鏈堢粨115澶╁唴浠樻',
+        'Z011' => '鏈堢粨175澶╁唴浠樻',
+        'Z012' => '鏈堢粨205澶╁唴浠樻',
+        'Z013' => '鍗婃湀缁擄紝15鏃ヤ箣鍓嶅彂璐э紝褰撴湀15鏃ュ埌鏈�',
+        'Z014' => '鏈堢粨30澶╁唴浠樻',
+        'Z015' => '楠屾敹鍚�15澶╃數姹�',
+        'Z020' => '100%鍙戣揣鍚�30澶╁唴鏀粯',
+        'Z021' => '100%鍙戣揣鍚�60澶╁唴鐢垫眹鏀粯',
+        'Z030' => '鏀跺埌鍙戠エ鍚�30澶╁唴鐢垫眹',
+        'Z045' => '鏈堢粨45澶╁唴浠樻',
+        'Z060' => '鏀跺埌鍙戠エ鍚�60澶╁唴鐢垫眹',
+        'Z075' => '鏀跺埌鍙戠エ鍚�75澶╁唴鐢垫眹',
+        'Z090' => '鏀跺埌鍙戠エ鍚�90澶╁唴鐢垫眹',
+        'Z0LC' => '100% L/C (90/10)',
+        'Z120' => '鏀跺埌鍙戠エ鍚�120澶╁唴鐢垫眹',
+        'Z1LC' => '100% L/C (80/20)',
+        'Z1TT' => '90%TT ADV锛�10%TT AFTER',
+        'Z2LC' => '100% L/C (70/30)',
+        'Z2TT' => '80%TT ADV锛�20%TT AFTER',
+        'Z30E' => '涓嬫湀鏈�',
+        'Z3LC' => '100% L/C 90 days',
+        'Z3TT' => '70%TT ADV锛�30%TT AFTER',
+        'Z4LC' => '90%L/CTransfer 10%TT AFTER',
+        'Z4TT' => '100% TT AFTER',
+        'Z5LC' => '100%L/C at sight Transfer',
+        'Z5TT' => '30% TT ADV锛�50% TT AT SIGHT锛�20% TT AFTER',
+        'Z60E' => '涓�2涓湀鏈�',
+        'Z6LC' => '100%L/C (85/15)',
+        'Z6TT' => '30% TT ADV锛�60% TT AT SIGHT锛�10% TT AFTER',
+        'Z7LC' => '100% L/C (60/40)',
+        'Z7TT' => '100锛匱T AFTER(80/20)',
+        'Z8TT' => '100% TT AFTER锛�70/30锛�',
+        'Z9TT' => '100%TT鍙戣揣鍚�20澶╁唴鏀粯',
+        'ZCOD' => 'C.O.D.',
+        'ZD60' => '绔嬪嵆搴斾粯鐨� 鍒版湡鍑�鍊�',
+        'ZFR1' => '鍗婃湀缁擄紝15鏃ヤ箣鍓嶅彂璐э紝褰撴湀15鏃ュ埌鏈�',
+        'ZL6T' => '90% LC 60 days锛�10% TT AFTER',
+        'ZL95' => '95% L/C AFTER,5% L/C AFTER 6M FROM ACCEPTANCE DATE',
+        'ZLC1' => '100% L/C (90/10) Transfer',
+        'ZLC2' => '100% L/C AT SIGHT (95/5)',
+        'ZLT1' => '90%LC锛�10%TT',
+        'ZLT2' => '80%LC锛�20%TT',
+        'ZLT3' => '70%LC锛�30%TT',
+        'ZLT4' => '95%LC锛�5%TT',
+        'ZLT5' => '50%L/C锛�50%TT after',
+        'ZT20' => '20% T/T ADV,80% T/T AFTER',
+        'ZT30' => '30% T/T ADV, 70%T/T AFTER',
+        'ZT35' => '35% TT ADV锛�65% TT AFTER',
+        'ZT40' => '40% TT ADV锛�60% TT AFTER',
+        'ZT50' => '50% TT ADV锛�50% TT AFTER',
+        'ZT55' => '95%TT ADV锛�5%TT AFTER',
+        'ZT90' => '楠屾敹鍚堟牸鍚嶵/T鏀粯90%锛岃澶囨甯歌繍琛屼笁涓湀T/T鏀粯10%',
+        'ZTT1' => 'TT AFTER DELIVERY 45 DAY',
+        'ZTT2' => 'TT AFTER DELIVERY 120 DAY',
+        'ZTT3' => '100%TT鍙戣揣鍚�15涓伐浣滄棩鍐呮敮浠�',
+        'ZTT4' => '楠屾敹鍚堟牸鍚嶵/T鏀粯80%锛岃澶囨甯歌繍琛屼笁涓湀T/T鏀粯20%',
+        'ZZ60' => '60 DAYS AFTER ISSUING INVOICE',
+        'ZZ95' => '95% L/C AFTER,5% T/T AFTER 6M FROM ACCEPTANCE DATE',
+        'ZZLC' => '100% L/C AT SIGHT',
+        'ZZTT' => '100% TT IN ADVANCE',
+        'Z022' => '100% T/T WITHIN 90 DAYS AFTER SHIPMENT'
+    };
 
-  public NewQuoteEntryController(ApexPages.StandardController controller) {
-    this();
-  }
+    public NewQuoteEntryController() {
 
-  public PageReference init() {
+        initStringConcatenation = '';
+        saveStringConcatenation = '';
+        verifyProductValidFlag = false;
 
-    system.debug('============start init==============');
-    boolean quoteflg = true;
-    WinOrDecideAlert = false;
-    errorflg = false;
-    displayFlg = true;
-    //Quote
-    standardPricebook = ControllerUtil.getStandardPricebook();
-    quo = new Quote();
-    qb = new QuoteBean();
-    String DeveloperName = '';
-    //Opportunityid
-    if (oppId == null) {
-      oppId = System.currentPageReference().getParameters().get('oppid');
-      if (oppId == Null) {
-        quoId = System.currentPageReference().getParameters().get('id');
 
-        List<Quote> ql = New List<Quote>();
-        //娣诲姞琛�
-        ql = [select Id, OpportunityId, Opportunity.RecordType.DeveloperName,LineItemCount From Quote Where Id = :quoId];
-        if (ql.size() > 0) {
-          oppId = ql[0].OpportunityId;
-          //娣诲姞琛�
-          if(ql[0].LineItemCount >quoteEntryMaxLine){
-            quoteEntryMaxLine = ql[0].LineItemCount;
-          }
-          DeveloperName = ql[0].Opportunity.RecordType.DeveloperName;
-        }
-      } else {
-        quoId = System.currentPageReference().getParameters().get('copyid');
-        system.debug('copyid++++++++++++'+quoId);
-        if (quoId != null) {
-          // 銈炽償銉笺伄銉囥兗銈裤亴寰屻仹浣滄垚銇欍倠
-        } else {
-          List<Quote> ql = New List<Quote>();
-          //娣诲姞琛�
-          ql = [select Id, OpportunityId,LineItemCount From Quote Where OpportunityId = :oppId];
-          if (ql.size() > 0) {
-            //娣诲姞琛�
-            if(ql[0].LineItemCount >quoteEntryMaxLine){
-                quoteEntryMaxLine = ql[0].LineItemCount;
+        singleProduct  = System.Label.SingleProduct;
+        quoteEntryMaxLine = Integer.valueOf(System.Label.QuoteEntryMaxLine);
+        quoteEntryMaxSet = Integer.valueOf(System.Label.QuoteEntryMaxSet);
+        hidFlg = new List<Boolean>(30);
+        for (Integer i = 0; i < 30; i++) {
+            if (i<quoteEntryMaxSet) {
+                hidFlg[i] = true;
+            } else {
+                hidFlg[i] = false;
             }
-            quoteflg = true;
-          } else {
-            quoteflg = false;
-          }
-        }
-      }
-    }
-
-    if (DeveloperName == 'SI_Oppor') {
-      PageReference pageRef = new PageReference('/apex/SI_NewQuoteEntry?id=' + quoId);
-      return pageRef;
-    }
-    system.debug('DeveloperName============' + DeveloperName);
-    //--User
-    List<User> us = New List<User>();
-    String userid = UserInfo.getUserId();
-    if (userid != null) {
-      us = [Select Quote_Correct__c, Quote_Special_Operation__c, Cost_Referable__c, ViewSpecialAgencyAmout__c From User Where Id = :userid];
-      if (us.size() > 0) {
-        verified = us[0].Quote_Correct__c;
-        specialAuthority = us[0].Quote_Special_Operation__c;
-        displayCost = us[0].Cost_Referable__c;
-        viewSpecialAgencyAmout = us[0].ViewSpecialAgencyAmout__c;
-      }
-    }
-    //--Opportunity
-    List<Opportunity> oppList = New List<Opportunity>();
-    String accountid;
-
-    oppList = [SELECT Account.Name, Account.RecordType.DeveloperName,
-               CLBIC_Category__c, HP_Name__c, Name, CurrencyIsoCode, Wholesale_Price__c, Department_Name__c,
-               Direct_Separate__c, Trade__c, AccountId, New_Opportunity__c, Estimation_Decision__c, SAP_Send_OK__c, Sales_Root__c,
-               Agency1__c, Agency2__c, Stocking_Price__c, Purchasing_Cost__c, Opportunity_No__c, StageName,
-               Agency1__r.Special__c, Agency2__r.Special__c, Account.Parent.Special__c
-               // LHJ Start
-               , Authorized_DB_No__c, Authorized_Finish_Sales__c, If_Need_Authorize__c
-               // LHJ End
-               // 澶氬勾淇濅慨 start
-               , Gurantee_Period__c , multiYearWarranty__c, MultiYearWarrantyTotalPrice__c
-               // 澶氬勾淇濅慨 end
-               // CHAN-BEN5UC start
-               , Hospital__c, Department_Class__c
-               ,Is_Corrosion__c,
-               // CHAN-BEN5UC end
-               //銆愭槸鍚﹂渶瑕佷环鏍肩敵璇枫�� thh start
-               If_Need_PriceApply__c
-               //銆愭槸鍚﹂渶瑕佷环鏍肩敵璇枫�� thh end
-               FROM Opportunity Where Id = :oppId];
-    // 澶氬勾淇濅慨 start
-    trade = '澶栬部';
-    // 澶氬勾淇濅慨 end
-    if (oppList.size() > 0) {
-
-      opp = oppList[0];
-      // 澶氬勾淇濅慨 start
-      trade = opp.Trade__c;
-      // 澶氬勾淇濅慨 end
-      QuoteDecision = opp.Estimation_Decision__c;
-      QuoteDecide = QuoteDecision;
-      QuoteSapSented = opp.SAP_Send_OK__c;
-      QuoteCorrect = opp.New_Opportunity__c;
-
-      enableSales = false;
-      if (opp.Sales_Root__c != null) {
-        if (opp.Sales_Root__c == '璨╁2搴�') {
-          enableSales = true;
-          opp.Sales_Root__c = System.Label.Sales_Outlet;
-        } else {
-          enableSales = false;
-          opp.Sales_Root__c = System.Label.OCM_Direct;
-        }
-      }
-
-      accountid = opp.AccountId;
-
-      if (QuoteDecision == true) {
-        enableContract = true;
-      } else {
-        enableContract = false;
-      }
-
-      oppInfo = new OppInfo(opp);
-
-      if (opp.SAP_Send_OK__c == false) {
-        displayFlg = true;
-      } else {
-        if (opp.Agency1__r.Special__c || opp.Agency1__r.Special__c || opp.Account.Parent.Special__c) {
-          // 鐗瑰垾璨╁2搴椼伄寮曞悎銇�
-          if (viewSpecialAgencyAmout) {
-            displayFlg = true;
-          } else {
-            displayFlg = false;
-          }
-        } else {
-          displayFlg = true;
-        }
-      }
-    }
-
-    //Quote
-    Integer i;
-    if (quoId == null) {
-      quoId = System.currentPageReference().getParameters().get('id');
-    }
-    if (quoId == null) {
-      if (quoteflg == false) {
-        //鍟嗚珖鍟嗗搧銇屽瓨鍦ㄣ�佽绌嶃亴瀛樺湪銇椼仾銇勩儑銉笺偪銇蹇�
-        List<OpportunityLineItem> items = New List<OpportunityLineItem>();
-        if (oppId == null) {
-          oppId = System.currentPageReference().getParameters().get('oppid');
-        }
-        items = [Select Id, Asset_Model_No__c, SFDA_Status__c, Name__c, ProductCode__c, PricebookEntry.Product2.StorageStatus__c,
-                 //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 Start 澧炲姞瀛楁,涓嶅彲鍙栨秷澶氬勾淇�&& 澧炲姞妫�绱㈤樋瑗胯禌澶� 2020/09/10start
-                 Qty_Unit__c, Cost__c, UnitPrice, ListPrice__c, Quantity, BSS_Category__c, TotalPrice,PricebookEntry.Product2.VenderName__c,PricebookEntry.Product2.CanNotCancelledGurantee__c,PricebookEntry.Product2.Is_DangerousChemicals__c,
-                 //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 end 澧炲姞瀛楁
-                 PricebookEntry.Product2.SFDA_Status__c, Product_Cost__c, Product_ListPrice__c, PricebookEntry.Product2.Sales_Possibility__c, PricebookEntry.Product2.Name,
-                 PricebookEntryId, PricebookEntry.Product2Id, Opportunity.Trade__c, PricebookEntry.Product2.Intra_Trade_List_RMB__c, PricebookEntry.Product2.Intra_Trade_Cost_RMB__c,
-                 PricebookEntry.Product2.Foreign_Trade_List_US__c, PricebookEntry.Product2.Packing_list_manual__c, PricebookEntry.Product2.Foreign_Trade_Cost_US__c, UnitPrice__c, TotalPrice__c
-                 , AgencyUnitPrice__c, AgencySubtotal__c, Present__c // CHAN-B4YAB8 2018/09/29 涓氬姟鏈轰細浜у搧鐨勮禒閫併�佺粡閿�鍟嗗皬璁°�佸崟浠�
-                 //澶氬勾淇濅慨 start
-                 , multiYearWarranty__c , If_Cancel_Guarantee__c , GuaranteePeriod__c,
-                 ServicePrice__c , GuranteePrice__c,
-                 ProductEntend_gurantee_period_all__c,
-                 ProductGuranteePrice__c, GuranteeType__c,
-                 //ProductIfConsumable__c,
-                 warrantyType__c, productServicePrice__c,
-                 NoDiscountTotal__c
-                 , provistonPeriod__c
-                 , PricebookEntry.Product2.Entend_gurantee_period_all__c
-                 , PricebookEntry.Product2.Intra_Trade_Gurantee_RMB__c
-                 , PricebookEntry.Product2.Intra_Trade_Service_RMB__c
-                 , PricebookEntry.Product2.GuranteeType__c
-                 // 缁翠慨鍚堝悓鎶ヤ环
-                 , PricebookEntry.Product2.Maintenance_Price_Year__c
-                 , Maintenance_Price_Year__c
-                 //澶氬勾淇濅慨 end
-                 //澶栬锤澶氬勾淇� 2021/01/04 绮剧悽鎶�鏈� wql start
-                 //缁翠慨鍚堝悓鎶ヤ环锛圲SD锛�
-                 ,PricebookEntry.Product2.Repair_Contract_USD__c
-                 //璁℃彁閲戦锛堜笉鍚◣锛孶SD锛�
-                 ,PricebookEntry.Product2.Intra_Trade_Foreign_RMB__c
-                 //NoDiscount 閲戦锛圲SD锛�
-                 ,PricebookEntry.Product2.NoDiscount_Foreign__c
-                 //澶栬锤澶氬勾淇� 2021/01/04 绮剧悽鎶�鏈� wql end
-
-                //SFDC鍋滄棰勮 lt 20211009 start
-                ,PricebookEntry.Product2.Estimated_ConsumptionDueDate__c
-                //SFDC鍋滄棰勮 lt 20211009 end
-
-                 From OpportunityLineItem
-                 Where OpportunityId = :oppId Order by Item_Order__c, Id];
-
-        if (items.size() > 0) {
-          activities = new List<QELine>();
-          i = 0;
-
-          for (OpportunityLineItem o : items) {
-            QELine c = new QELine(o, i);
-            activities.add(c);
-            i++;
-          }
-          for (integer j = i; j < quoteEntryMaxLine; j++) {
-            QELine c = new QELine(j);
-            activities.add(c);
-          }
-          productStatusUpdated = true;
-
-        } else {
-          //鏂拌銉偣銉堛偝銉炽儓銉兗銉┿伄鍙栧緱
-          if (activities == null) {
-            activities = new List<QELine>();
-            for (i = 0; i < quoteEntryMaxLine; i++) {
-              QELine active_activity = new QELine(i);
-              activities.add(active_activity);
-            }
-          }
-        }
-      } else {
-        //鏂拌銉偣銉堛偝銉炽儓銉兗銉┿伄鍙栧緱
-        if (activities == null) {
-          activities = new List<QELine>();
-          for (i = 0; i < quoteEntryMaxLine; i++) {
-            QELine active_activity = new QELine(i);
-            activities.add(active_activity);
-          }
-        }
-      }
-    } else {
-      //娣诲姞琛�
-      List<Quote> quoList =
-        [ SELECT Id, Name, Cancel_Decide__c, CreatedDate, PriceRefreshDate__c, Quote_Print_Date__c,
-          Dealer_Final_Price__c, TotalPrice__c, Estimation_List_Price__c, QuoteNumber,
-          QuoteToName, Quote_Expiration_Date__c, Quote_Comment__c, Stocking_Price__c, Unit_Price__c,
-          Offer_Amount__c, TOTAL__c, Discount__c, Pricing__c, Preferential_Trading_Price__c, Contract__c,
-          Agency1__c, OCM_Agent1_Price__c, Agency1_Profit__c, Agency1_Profit_Rate__c, Print_HP_Name__c,
-          Agency2__c, Agent1_Agent2_Price__c, Agency2_Profit__c, Agency2_Profit_Rate__c, Quote_No__c,
-          Quote_Adjust_Amount__c, Quote_Adjust_Calculate__c, Discount_Amount__c, Discount_Amount_Calculate__c, Installation_location__c,
-          QuoteTotal_Page__c, Dealer_Final_Price_Page__c, Quote_Adjust_Amount_Page__c, OCM_Agent1_Price_Page__c, Agent1_Agent2_Price_Page__c
-          , AgencyDiscount__c //  2018/09/28 CHAN-B4YAB8 缁忛攢鍟嗘姌鎵�
-          //  澶氬勾淇濅慨 start
-          , Gurantee_Period__c , multiYearWarranty__c, MultiYearWarrantyTotalPrice__c,
-          Preferential_Gurantee_Period__c,LineItemCount 
-          // 澶氬勾淇濅慨 end
-          //鎶ヤ环璇曠畻 start
-            ,IsQuoteTrial__c  
-            //鎶ヤ环璇曠畻 end
-          FROM Quote Where Id = :quoId];
-      List<QuoteLineItem> items =
-        [Select Id, Asset_Model_No__c, SFDA_Status__c, Product_Sales_Possibility__c,
-        //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 Start 澧炲姞瀛楁 涓嶅彲鍙栨秷澶氬勾淇�&&澧炲姞妫�绱㈤樋瑗胯禌澶� 2020/09/10
-         Name__c, BSS_Category__c, Quote.Quote_Print_Date__c,PricebookEntry.Product2.VenderName__c,PricebookEntry.Product2.CanNotCancelledGurantee__c,PricebookEntry.Product2.Is_DangerousChemicals__c,
-         //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 end 澧炲姞瀛楁
-         Qty_Unit__c, Cost__c, UnitPrice__c, ListPrice__c, Quantity, TotalPrice__c,
-         PricebookEntry.Product2.SFDA_Status__c, ProductCode__c, Product_Cost__c, Product_ListPrice__c, PricebookEntry.Product2.Sales_Possibility__c, PricebookEntry.Product2.Name,
-         PricebookEntryId, PricebookEntry.Product2Id, UnitPrice_Page__c, PricebookEntry.Product2.Packing_list_manual__c, PricebookEntry.Product2.StorageStatus__c
-         , AgencyUnitPrice__c, AgencySubtotal__c, Present__c // CHAN-B4YAB8 2018/9/29 璧犻�併�佺粡閿�鍟嗗崟浠峰拰灏忚
-         //  澶氬勾淇濅慨 start
-         //ET淇冮攢鏍囪 start
-         , multiYearWarranty__c , If_Cancel_Guarantee__c , GuaranteePeriod__c,
-         //ET淇冮攢鏍囪 end
-         ServicePrice__c , GuranteePrice__c, ProductEntend_gurantee_period_all__c,
-         ProductGuranteePrice__c,  GuranteeType__c,
-         warrantyType__c, productServicePrice__c, NoDiscountTotal__c
-         , provistonPeriod__c
-         , PricebookEntry.Product2.Entend_gurantee_period_all__c
-         , PricebookEntry.Product2.Intra_Trade_Gurantee_RMB__c
-         , PricebookEntry.Product2.Intra_Trade_Service_RMB__c
-         , PricebookEntry.Product2.GuranteeType__c
-         // 缁翠慨鍚堝悓鎶ヤ环
-         , PricebookEntry.Product2.Maintenance_Price_Year__c
-         , Maintenance_Price_Year__c
-         // 澶氬勾淇濅慨 end
-         //澶栬锤澶氬勾淇� 2021/01/04 绮剧悽鎶�鏈� wql start
-         //缁翠慨鍚堝悓鎶ヤ环锛圲SD锛�
-         ,PricebookEntry.Product2.Repair_Contract_USD__c
-         //璁℃彁閲戦锛堜笉鍚◣锛孶SD锛�
-         ,PricebookEntry.Product2.Intra_Trade_Foreign_RMB__c
-         //NoDiscount 閲戦锛圲SD锛�
-         ,PricebookEntry.Product2.NoDiscount_Foreign__c 
-         ,Quote.Opportunity.Trade__c 
-         //澶栬锤澶氬勾淇� 2021/01/04 绮剧悽鎶�鏈� wql end
-
-         //SFDC鍋滄棰勮 lt 20211009 start
-         ,PricebookEntry.Product2.Estimated_ConsumptionDueDate__c
-         //SFDC鍋滄棰勮 lt 20211009 end
-
-         From QuoteLineItem where Quoteid = :quoId Order by Item_Order__c, Id];
-      String copyQuoId = System.currentPageReference().getParameters().get('copyid');
-      system.debug('copyid2++++++++++++'+copyQuoId);
-      CheckItem = items;
-
-      if (copyQuoId == null) {
-      } else {
-        // copy銇牬鍚堛�乹uoId銈抧ull銇埢銇�
-        quoId = null;
-      }
-      if (quoList.size() > 0) {
-        //娣诲姞琛�
-        if(quoList[0].LineItemCount >quoteEntryMaxLine){
-            quoteEntryMaxLine = quoList[0].LineItemCount;
-        }
-        if (copyQuoId == null) {
-          quo = quoList[0];
-          quo.QuoteName__c = quo.Name;
-          // 澶氬勾淇濅慨 start
-          quoteGurantee_Period = quo.Gurantee_Period__c;
-          quotemultiYearWarranty = '' + quo.multiYearWarranty__c;
-          // 澶氬勾淇濅慨 end
-          //鎶ヤ环璇曠畻 澧炲姞缁忛攢鍟嗗墠鍚庡姣� wql 20210508 start
-          agency1Name = quo.Agency1__c;
-          agency2Name = quo.Agency2__c;
-          //鎶ヤ环璇曠畻 澧炲姞缁忛攢鍟嗗墠鍚庡姣� wql 20210508 end
-          // 澶氬勾淇濅慨 start
-          //HWAG-BLDE6J   甯﹀嚭瀛楁 2020/02/10 Start
-          quo.Gurantee_Period__c              = quoList[0].Gurantee_Period__c;
-          quo.multiYearWarranty__c            = quoList[0].multiYearWarranty__c;
-          quo.MultiYearWarrantyTotalPrice__c  = quoList[0].MultiYearWarrantyTotalPrice__c;
-          // 澶氬勾淇濅慨 end
-          qb.setPriceRefreshPeriodByDate(quo.PriceRefreshDate__c == null ? quo.CreatedDate.Date() : quo.PriceRefreshDate__c);
-          qb.Estimation_List_Price = quo.Estimation_List_Price__c;
-          quo.QuoteTotal_Page__c = quo.TotalPrice__c;
-          quo.Dealer_Final_Price_Page__c = quo.Dealer_Final_Price__c;
-          qb.Quote_Adjust_Calculate = quo.Quote_Adjust_Calculate__c;
-          quo.Quote_Adjust_Amount_Page__c = quo.Quote_Adjust_Amount__c;
-          DisCalculation = quo.Discount_Amount_Calculate__c;
-          DisAmount = quo.Discount_Amount__c;
-          quo.Agency1__c = quo.Agency1__c;
-          AgencyDiscount = quo.AgencyDiscount__c; //2018/09/28 CHAN-B4YAB8 缁忛攢鍟嗘姌鎵�
-          quo.OCM_Agent1_Price_Page__c = quo.OCM_Agent1_Price__c;
-          Salesprofit1 = quo.Agency1_Profit__c;
-          qb.SalesCalculation1 = quo.Agency1_Profit_Rate__c;
-          //                quo.Agency1_Profit_Rate__c = quo.Agency1_Profit_Rate__c;
-          quo.Agency2__c = quo.Agency2__c;
-          quo.Agent1_Agent2_Price_Page__c = quo.Agent1_Agent2_Price__c;
-          Salesprofit2 = quo.Agency2_Profit__c;
-          qb.SalesCalculation2 = quo.Agency2_Profit_Rate__c;
-        //HWAG-BLDE6J   甯﹀嚭瀛楁 2020/02/10 end
-        } else {
-          
-          
-          //HWAG-BLDE6J   甯﹀嚭瀛楁 2020/02/11 Start
-          // quo.QuoteName__c = '';
-          quo = quoList[0];
-          //鍐嶆姤浠锋柊鍑烘潵鐨勬姤浠峰悕绉帮紝鎶娾�滃凡鍙栨秷鈥濅笁涓瓧鍘绘帀  绮剧悽鎶�鏈� thh 2021-09-30 start
-          Integer QX = quo.Name.indexof('宸插彇娑�:');
-          System.debug('Name is ' + quo.Name + ', QX is ' + QX);
-          if (QX >= 0) {
-            quo.Name = quo.Name.subString(QX + 4);
-          }
-          //鍐嶆姤浠锋柊鍑烘潵鐨勬姤浠峰悕绉帮紝鎶娾�滃凡鍙栨秷鈥濅笁涓瓧鍘绘帀  绮剧悽鎶�鏈� thh 2021-09-30 end
-          //鎶ヤ环鍚嶇О
-          quo.QuoteName__c = quo.Name;
-          //鍐嶆姤浠锋椂鏄惁杩涜杩囨姤浠疯绠楄涓烘湭杩涜杩囨姤浠疯绠�  fy 2021-11-23 start
-          quo.IsQuoteTrial__c = false;
-          //鍐嶆姤浠锋椂鏄惁杩涜杩囨姤浠疯绠楄涓烘湭杩涜杩囨姤浠疯绠�  fy 2021-11-23 end
-          quo.Cancel_Decide__c = quo.Cancel_Decide__c;
-          quo.Cancel_Decide__c = false;
-          quo.PriceRefreshDate__c = Date.today();
-          quo.Quote_Date__c = null;
-          quo.Quote_Print_Date__c = null;
-          //鎶ヤ环鎬婚
-          quo.QuoteTotal_Page__c = quo.TotalPrice__c;
-          //绗竴缁忛攢鍟�
-          quo.OCM_Agent1_Price_Page__c = quo.OCM_Agent1_Price__c;
-          //绗簩缁忛攢鍟�
-          quo.Agent1_Agent2_Price_Page__c = quo.Agent1_Agent2_Price__c;
-          //鍖婚櫌鐨勫悎鍚岄噾棰�
-          quo.Dealer_Final_Price_Page__c = quo.Dealer_Final_Price__c;
-          //HWAG-BLDE6J   甯﹀嚭瀛楁 2020/02/11 end
-        }
-        // 澶氬勾淇濅慨 start
-        // quo.Gurantee_Period__c              = quoList[0].Gurantee_Period__c;
-        // quo.multiYearWarranty__c            = quoList[0].multiYearWarranty__c;
-        // quo.MultiYearWarrantyTotalPrice__c  = quoList[0].MultiYearWarrantyTotalPrice__c;
-        // // 澶氬勾淇濅慨 end
-        // qb.setPriceRefreshPeriodByDate(quo.PriceRefreshDate__c == null ? quo.CreatedDate.Date() : quo.PriceRefreshDate__c);
-        // qb.Estimation_List_Price = quo.Estimation_List_Price__c;
-        // quo.QuoteTotal_Page__c = quo.TotalPrice__c;
-        // quo.Dealer_Final_Price_Page__c = quo.Dealer_Final_Price__c;
-        // qb.Quote_Adjust_Calculate = quo.Quote_Adjust_Calculate__c;
-        // quo.Quote_Adjust_Amount_Page__c = quo.Quote_Adjust_Amount__c;
-        // DisCalculation = quo.Discount_Amount_Calculate__c;
-        // DisAmount = quo.Discount_Amount__c;
-        // quo.Agency1__c = quo.Agency1__c;
-        // AgencyDiscount = quo.AgencyDiscount__c; //2018/09/28 CHAN-B4YAB8 缁忛攢鍟嗘姌鎵�
-        // quo.OCM_Agent1_Price_Page__c = quo.OCM_Agent1_Price__c;
-        // Salesprofit1 = quo.Agency1_Profit__c;
-        // qb.SalesCalculation1 = quo.Agency1_Profit_Rate__c;
-        // //                quo.Agency1_Profit_Rate__c = quo.Agency1_Profit_Rate__c;
-        // quo.Agency2__c = quo.Agency2__c;
-        // quo.Agent1_Agent2_Price_Page__c = quo.Agent1_Agent2_Price__c;
-        // Salesprofit2 = quo.Agency2_Profit__c;
-        // qb.SalesCalculation2 = quo.Agency2_Profit_Rate__c;
-        //                quo.Agency2_Profit_Rate__c = quo.Agency2_Profit_Rate__c;
-      }
-
-      activities = new List<QELine>();
-      i = 0;
-      QELine c = new QELine(i);
-      if (items.size() > 0) {
-        for (QuoteLineItem o : items) {
-          c = new QELine(o, i, copyQuoId);
-          activities.add(c);
-          i++;
         }
 
-        for (integer j = i; j < quoteEntryMaxLine; j++) {
-          c = new QELine(j);
-          activities.add(c);
-        }
-
-      } else {
-        activities = new List<QELine>();
-        for (i = 0; i < quoteEntryMaxLine; i++) {
-          QELine active_activity = new QELine(i);
-          activities.add(active_activity);
-        }
-      }
-      //******************************************************************************************
-      //            澧炲姞妫�娴嬩骇鍝佺姸鎬佹槸鍚﹀彂鐢熷彉鍖�
-      //******************************************************************************************
-
-      // CHAN-BHN7P5 start
-
-      //鍏ㄤ欢娲椼亜鏇裤亪銇椼伨銇欍��
-      if (activities.size() > 0  && !QuoteDecision) {
         productStatusUpdated = false;
-        for (QELine a : activities) {
-          if (string.isNotEmpty(a.Asset_Model)) {
-            // CHAN-AVG3PW 璇环鎶ヤ环鐢婚潰瑙勫垯鍙樻洿
-            // 鍙鏇存柊锛屽氨鐢熸垚鏂版姤浠风紪鐮�
-            if (a.PageObject.SFDA_Status__c != a.latestInfo.SFDA_Status ||
-                a.PageObject.Name__c != a.latestInfo.ProductName ||
-                a.ListPrice_Page != a.latestInfo.ListPrice ||
-                a.PageObject.Cost__c != a.latestInfo.Cost ||
-                a.Cost_c != a.latestInfo.Cost
-                // 澶氬勾淇濅慨 start
-                //璁℃彁閲戦
-                || a.ProductGuranteePrice != a.latestInfo.Intra_Trade_Gurantee
-                || a.PageObject.productServicePrice__c  != a.latestInfo.Intra_Trade_Service
-                // 缁翠慨鍚堝悓鎶ヤ环
-                || a.Maintenance_Price_Year != a.latestInfo.Maintenance_Price_Year
-                || a.PageObject.GuranteeType__c != a.latestInfo.GuranteeType
-                || a.PageObject.ProductEntend_gurantee_period_all__c != a.latestInfo.ProductEntend_gurantee_period_all
-                //涓嶅彲鍙栨秷澶氬勾淇� 璇环鏍规嵁鍕句笉鍚� 鑷姩鏇存柊浠锋牸 绮剧悽鎶�鏈� wql 20200924
-                || a.PageObject.PricebookEntry.Product2.CanNotCancelledGurantee__c != a.latestInfo.CanNotCancelledGurantee
-                //涓嶅彲鍙栨秷澶氬勾淇� 璇环鏍规嵁鍕句笉鍚� 鑷姩鏇存柊浠锋牸 绮剧悽鎶�鏈� wql 20200924
-                // 澶氬勾淇濅慨 end
-               ) {
-              system.debug('qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq:');
-               system.debug('涓婃SFDA鐘舵�侊細'+a.PageObject.SFDA_Status__c);
-                system.debug('鏈�鏂扮殑SFDA鐘舵�侊細'+a.latestInfo.SFDA_Status);
-                system.debug('涓婃Name__c锛�'+a.PageObject.Name__c);
-                system.debug('鏈�鏂扮殑ProductName锛�'+a.latestInfo.ProductName);
-                system.debug('涓婃ListPrice锛�'+a.ListPrice_Page);
-                system.debug('鏈�鏂扮殑涓婃ListPrice锛�'+a.latestInfo.ListPrice);
-                system.debug('涓婃Cost__c锛�'+a.Cost_c);
-                system.debug('鏈�鏂扮殑Cost锛�'+a.latestInfo.Cost);
-                system.debug('涓婃Cost__c锛�'+a.Cost_c);
-                system.debug('鏈�鏂扮殑Cost锛�'+a.latestInfo.Cost);
-                system.debug('涓婃璁℃彁閲戦锛�'+a.ProductGuranteePrice);
-                system.debug('鏈�鏂扮殑璁℃彁閲戦锛�'+a.latestInfo.Intra_Trade_Gurantee);
-                system.debug('涓婃nodis锛�'+a.PageObject.productServicePrice__c);
-                system.debug('鏈�鏂扮殑nodis锛�'+a.latestInfo.Intra_Trade_Service);
-                system.debug('涓婃缁翠慨鍚堝悓鎶ヤ环锛�'+a.Maintenance_Price_Year);
-                system.debug('鏈�鏂扮殑缁翠慨鍚堝悓鎶ヤ环锛�'+a.latestInfo.Maintenance_Price_Year);
-                system.debug('涓婃GuranteeType__c锛�'+a.PageObject.GuranteeType__c);
-                system.debug('鏈�鏂扮殑GuranteeType__c锛�'+a.latestInfo.GuranteeType);
-                system.debug('涓婃ProductEntend_gurantee_period_all__c锛�'+a.PageObject.ProductEntend_gurantee_period_all__c);
-                system.debug('鏈�鏂扮殑ProductEntend_gurantee_period_all__c锛�'+a.latestInfo.ProductEntend_gurantee_period_all);
-                system.debug('涓婃CanNotCancelledGurantee__c锛�'+a.PageObject.PricebookEntry.Product2.CanNotCancelledGurantee__c);
-                system.debug('鏈�鏂扮殑CanNotCancelledGurantee__c锛�'+a.latestInfo.CanNotCancelledGurantee);
-                system.debug('newQuoteFlag11:'+newQuoteFlag);
-              newQuoteFlag = true;
-              productStatusUpdated = true;
-            }
-            if (a.pageObject.Name__c != a.latestInfo.ProductName) {
-              a.changed_name = true;
-              productStatusUpdated = true;
-            }
-            if (a.pageObject.SFDA_Status__c != a.latestInfo.SFDA_Status) {
-              a.changed_sfda = true;
-              productStatusUpdated = true;
-            }
-            if (a.ListPrice_Page != a.latestInfo.ListPrice) {
-              a.changed_list = true;
-              productStatusUpdated = true;
-            }
-            if (a.pageObject.Cost__c != a.latestInfo.Cost) {
-              a.changed_cost = true;
-              productStatusUpdated = true;
-            }
-            // TODO katsu SFDA銈广儐銉笺偪銈广伄纰鸿獚銇仼銇勩倝銇亜銇с仚銇嬶紙鏈�鏂板晢鍝乆XX銇爡鐩倐锛�
-
-            a.PageObject.SFDA_Status__c = a.latestInfo.SFDA_Status;
-
-            a.PageObject.Name__c = a.latestInfo.ProductName;
-            a.ListPrice_Page = a.latestInfo.ListPrice;
-            a.PageObject.Cost__c = a.latestInfo.Cost;
-            a.Cost_c = a.latestInfo.Cost;
-            //澶氬勾淇濅慨 start
-            a.ProductGuranteePrice =  a.latestInfo.Intra_Trade_Gurantee;
-            // 璁℃彁閲戦
-            a.PageObject.productServicePrice__c = a.latestInfo.Intra_Trade_Service;
-            // 缁翠慨鍚堝悓鎶ヤ环
-            a.Maintenance_Price_Year = a.latestInfo.Maintenance_Price_Year;
-            // 澶氬勾淇濅慨骞撮檺
-            a.PageObject.ProductEntend_gurantee_period_all__c
-              = a.latestInfo.ProductEntend_gurantee_period_all;
-            a.PageObject.GuranteeType__c = a.latestInfo.GuranteeType;
-            //澶氬勾淇濅慨 end
-          }
+        baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
+        String path = URL.getCurrentRequestUrl().getPath();
+        if (path.indexOf('/apex') > 0) {
+            baseUrl += path.substring(0,path.indexOf('/apex'));
+        } else if (path.indexOf('production/') > 0) {
+            baseUrl += '/production';
+        }
+        rtUrl = System.currentPageReference().getParameters().get('retURL');
+        System.debug('path: ' + path);
+        System.debug('baseUrl: ' + baseUrl);
+        System.debug('rtUrl: ' + rtUrl);
+        if (rtUrl == null || rtUrl == 'null') {
+            rtUrl = '';
         }
 
-      }
-      pageArrange();
-
-      // CHAN-BHN7P5 end
-      // CHAN-BHN7P5 鍘熼�昏緫 start
-      // else {
-      //   List<String> product2Ids = New List<String>();
-      //   if (activities.size() > 0) {
-      //     for (QELine a : activities) {
-      //       if (String.isBlank(a.PageObject.Id__c) == false) {
-      //         product2Ids.add(a.PageObject.Id__c);
-      //       }
-      //     }
-      //   }
-      //   Map<String, QuoteLineItem> loopMap = new Map<String, QuoteLineItem>();
-      //   if (CheckItem.size() > 0) {
-      //     for (QuoteLineItem qli : CheckItem) {
-      //       loopMap.put(qli.PricebookEntry.Product2Id, qli);
-      //     }
-      //   }
-      //   // 銇撱亾銈掍慨姝c仐銇熴倝銆丯FM007.trigger銈傝纰鸿獚
-      //   prd2LatestValMap = new Map<Id, Product2>();
-      //   if (CheckItem.size() > 0) {
-      //     List<Product2> plo = [Select Id, Name, Estimation_Entry_Possibility__c, SFDA_Status__c, Packing_list_manual__c,
-      //                           Intra_Trade_List_RMB__c, Foreign_Trade_List_US__c,
-      //                           Intra_Trade_Cost_RMB__c, Foreign_Trade_Cost_US__c
-      //                           // 澶氬勾淇濅慨 start
-      //                           , Intra_Trade_Gurantee_RMB__c
-      //                           , Intra_Trade_Service_RMB__c
-      //                           , Maintenance_Price_Year__c
-      //                           // 澶氬勾淇濅慨 end
-      //                           From Product2 Where Id IN :product2Ids];
-      //     if (plo.size() > 0) {
-      //       for (Product2 prd2 : plo) {
-      //         Decimal listPrice = 0;
-      //         Decimal costPrice = 0;
-      //         //澶氬勾淇濅慨 start
-      //         decimal ProductGuranteePrice = 0;
-      //         decimal productService = 0;
-      //         decimal productMaintenance_Price_Year = 0;
-      //         //澶氬勾淇濅慨 end
-      //         if (opp.Trade__c == '鍐呰部') {
-      //           listPrice = prd2.Intra_Trade_List_RMB__c;
-      //           costPrice = prd2.Intra_Trade_Cost_RMB__c;
-      //           //澶氬勾淇濅慨 start
-      //           ProductGuranteePrice = prd2.Intra_Trade_Gurantee_RMB__c;
-      //           productService = prd2.Intra_Trade_Service_RMB__c;
-      //           productMaintenance_Price_Year = prd2.Maintenance_Price_Year__c == null ? 0 : prd2.Maintenance_Price_Year__c;
-      //           //澶氬勾淇濅慨 end
-      //         } else if (opp.Trade__c == '澶栬部') {
-      //           listPrice = prd2.Foreign_Trade_List_US__c;
-      //           costPrice = prd2.Foreign_Trade_Cost_US__c;
-      //         }
-      //         if ( prd2.Name.replaceAll('\\s+', '')            != loopMap.get(prd2.Id).Name__c.replaceAll('\\s+', '')     ||
-      //              prd2.SFDA_Status__c != loopMap.get(prd2.Id).SFDA_Status__c ||
-      //              listPrice           != loopMap.get(prd2.Id).ListPrice__c   ||
-      //              costPrice           != loopMap.get(prd2.Id).Cost__c
-      //              // 澶氬勾淇濅慨 start
-      //              || ( opp.Trade__c == '鍐呰部' &&
-      //                   (ProductGuranteePrice != loopMap.get(prd2.Id).ProductGuranteePrice__c
-      //                    || productService != loopMap.get(prd2.Id).productServicePrice__c
-      //                    || productMaintenance_Price_Year !=
-      //                    loopMap.get(prd2.Id).Maintenance_Price_Year__c
-      //                   ))
-      //              // 澶氬勾淇濅慨 end
-      //            ) {
-      //           WinOrDecideAlert = true;
-      //         }
-
-      //       }
-      //     }
-
-      //   }
-      //   system.debug('WinOrDecideAlert:::::::2' + WinOrDecideAlert );
-      // }// CHAN-BHN7P5 鍘熼�昏緫 end
-      //******************************************************************************************
-      //            澧炲姞妫�娴嬩骇鍝佺姸鎬佹槸鍚﹀彂鐢熷彉鍖�==================End 20161115 by ZDF
-      //******************************************************************************************
+        //system.debug('22222222222222' + quo);
     }
 
-    // 澶氬勾淇濅慨 start
-    if (quo.Gurantee_Period__c == null) {
-      quo.Gurantee_Period__c = '1';
+    public NewQuoteEntryController(ApexPages.StandardController controller) {
+        this();
     }
 
-    // 澶氬勾淇濅慨 end
-    //鍒濇湡鍊よō瀹�
-    if (accountid != null) {
-      List<Account> accs2 = [Select Id, RecordType.DeveloperName, Hospital__c, Agent_Ref__c From Account Where Id = :accountid];
-      if (accs2.size() > 0) {
-        List<Account> accs = new List<Account>();
-        if (accs2[0].RecordType.DeveloperName != 'AgencyContract') {
-          accs = [Select Id, Name, Site, Alias_Name2__c From Account Where Id = :accs2[0].Hospital__c];
-        } else {
-          accs = [Select Id, Name, Site, Alias_Name2__c From Account Where Id = :accs2[0].Agent_Ref__c];
-        }
-        if (accs.size() > 0) {
-          options_hp = new List<SelectOption>();
-          if (accs[0].Name != null) {
-            options_hp.add(new SelectOption(accs[0].Name, accs[0].Name));
-          }
-          if (accs[0].Site != null) {
-            options_hp.add(new SelectOption(accs[0].Site, accs[0].Site));
-          }
-          if (accs[0].Alias_Name2__c != null) {
-            options_hp.add(new SelectOption(accs[0].Alias_Name2__c, accs[0].Alias_Name2__c));
-          }
-          //鍒濇湡鍊よō瀹�
-          if (quo.Print_HP_Name__c == null) {
-            selection_hp = accs[0].Name;
-          } else {
-            selection_hp = quo.Print_HP_Name__c;
-          }
-        }
-      }
-    }
+    public void init () {
+        specialerrorflg = false ;
+        activitiesSize = 0;
+        errorflg = false;
+        errormessage = null;
 
-    if (quo.Quote_Expiration_Date__c == null) {
-      quo.Quote_Expiration_Date__c = Date.today() + 30;
-    }
+        decideFlg = false;
+        isdecide = false;
+        printFlg = false;
+        doDecide = false;
+        productSegment = '';
+        errorMap = new Map<String,String>();
+        quoteLineSetNameDiscountMap = new Map<String,String>();
+        quoteLineSetNameDiscountJson = '';
+        isAdmin = false;
+        String profileId = UserInfo.getProfileId();
+        profileId = profileId.substring(0, 15);
 
-    //--Printbutton
-    if (QuoteCorrect == false) {
-      print_button = true;
-    } else if (verified == false) {
-      print_button = true;
-    } else {
-      print_button = false;
-    }
-    //--SAPButton
-    if (QuoteDecision == false) {
-      sap_button = true;
-    } else if (specialAuthority == false) {
-      sap_button = true;
-    } else {
-      sap_button = false;
-    }
-    //--Decisionbutton
-    if (verified == true) {
-      Decision_button = false;
-    } else if (QuoteCorrect == false) {
-      Decision_button = true;
-    } else if (QuoteDecision == true) {
-      Decision_button = true;
-    } else {
-      Decision_button = false;
-    }
-    // 銈傘仐銆併仚銇с伀姹哄畾銇氥伩銇牬鍚堛�佹焙瀹氥儨銈裤兂銈掋仱銇嬨亪銇亜銈堛亞銇仚銈�
-    if (QuoteSapSented == true || QuoteDecision == true) {
-      Decision_button = true;
-    }
-    //--Savebutton
-    if (QuoteDecision == true) {
-      Save_button = true;
-    } else {
-      Save_button = false;
-    }
-    // CHAN-AVG3PW 璇环鎶ヤ环鐢婚潰瑙勫垯鍙樻洿
-    Datetime cDate = quo.CreatedDate;
-    over3month = cDate != null && cDate.date().addMonths(3) < Date.today();
+        //鏂扮殑鑾峰彇绠�妗D  calendarUtil.getMemberProfileID  杩欓噷鐢ㄥ埌鐨勪汉鍛業D 鍜岃幏鍙栧埌鐨勭畝妗D閮芥槸15浣嶇殑
+        String new_profileId = calendarUtil.getMemberProfileID(UserInfo.getUserId().subString(0,15));
 
-    return null;
-  }
-
-
-  //Search Events============================================================
-  // TODO ManualEntry銇ㄥ悓妲樸�乯s銇仸瑙f焙銇с亶銈嬨�併亾銇撱仹webservice銇犮亼銈掑疅瑁呫�佷粖寰� by katsu
-  public PageReference setProductEntry() {
-    system.debug('-----:start');
-    system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼媁elcome to setProductEntry!!');
-    system.debug('鈻尖柤鈻尖柤鈻約etProduct_text:' + setProduct_text);
-    setOppFromOppInfo();
-    List<String> productIDLIST = new List<String>();
-    //鏃㈠瓨銉囥兗銈挎暟銇⒑瑾�
-    Integer currentDetailNumber = 0;
-    for (QELine s : activities) {
-      //銉囥兗銈垮垽瀹氥伀Asset_Model_No銈掍娇鐢�
-      if ((s.Asset_Model == null) || (s.Asset_Model == '')) {
-        break;
-      }
-      currentDetailNumber++;
-    }
-
-    //鏃㈠瓨銉囥兗銈挎暟銇�150浠ヤ笂锛�
-    if (currentDetailNumber >= quoteEntryMaxLine) {
-      //娣诲姞琛�
-      errorflg = true;
-      errormessage = System.Label.Error_Message32;
-      PageArrange();
-      system.debug('-----:寮峰埗绲備簡:00');
-      return null;
-    }
-
-    // SearchSetProduct銇嬨倝銆併偦銉冦儓鍝併偝銉笺儔銇浮銇c仸銇嶃仧銇嬶紵
-    if (setProduct_text == null) {
-      // 銈汇儍銉堝搧銈炽兗銉夈亴娓°仯銇︺亾銇亱銇c仧鍫村悎
-      // 绲備簡
-      PageArrange();
-      system.debug('-----:寮峰埗绲備簡:01');
-      return null;
-    } else {
-      productIDLIST = setProduct_text.split(',');
-    }
-
-    // 銈汇儍銉堝搧鏄庣窗銇� ProductId涓�瑕с倰鏍肩磵銇欍倠
-    // pricebookEntry + product2銇搞伄銈偍銉伄Where鍙ャ仹浣跨敤銇欍倠
-    List<Id> productIds = null;
-
-    // ----------------------------------------------------------------------------------------
-    // 瑭插綋銇欍倠銈汇儍銉堝搧鏄庣窗銇儸銈炽兗銉夈倰鍙栧緱
-    // ----------------------------------------------------------------------------------------
-    system.debug('-----:Product_Set_Detail__c select start');
-    //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 Start 澧炲姞瀛楁&&澧炲姞妫�绱㈤樋瑗胯禌澶� start
-    List<Product_Set_Detail__c> productSetDetails = [SELECT Id, Product__c, Quantity__c, Product_Set__r.Name,Product__r.VenderName__c,Product__r.CanNotCancelledGurantee__c,Product__r.Is_DangerousChemicals__c FROM Product_Set_Detail__c Where Product_Set__c in :productIDLIST];
-    //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 end 澧炲姞瀛楁
-    system.debug('-----:Product_Set_Detail__c select end');
-    if (productSetDetails.size() == 0) {
-      PageArrange();
-      return null;
-    } else {
-      productIds = new List<Id>();
-      for (Product_Set_Detail__c local : productSetDetails) {
-        productIds.add(local.Product__c);
-      }
-    }
-
-    //=======Temporary=====
-    tmpactivities = activities;
-
-    //=======Initialize=========
-    activities = new List<QELine>();
-
-    boolean lineflg = false;
-
-    // ----------------------------------------------------------------------------------------
-    // Product2銇搞伄銈偍銉倰瀹熻
-    // 涓�搴ist銇х祼鏋溿倰鍙椼亼銇熷緦銇�丳roduct2Id銇� Map銇仚銈�
-    // ----------------------------------------------------------------------------------------
-    system.debug('-----:Product2 select start');
-    Map<Id, Product2> items = new Map<Id, Product2>();
-    List<Product2> products = [select Id, Name, ProductCode,
-                               Foreign_Trade_Cost_US__c, Foreign_Trade_List_US__c, Intra_Trade_Cost_RMB__c, Intra_Trade_List_RMB__c,
-                               //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 Start 澧炲姞瀛楁
-                               Asset_Model_No__c, Sales_Possibility__c, Estimation_Entry_Possibility__c,VenderName__c,
-                               //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 end 澧炲姞瀛楁
-                               SFDA_Status__c, Qty_Unit__c, BSSCategory__c, Packing_list_manual__c, StorageStatus__c
-                               // 澶氬勾淇濅慨 start
-                               , Entend_gurantee_period_all__c
-                               , Intra_Trade_Gurantee_RMB__c
-                               , Intra_Trade_Service_RMB__c
-                               , GuranteeType__c
-                               // 缁翠慨鍚堝悓浠锋牸
-                               , Maintenance_Price_Year__c
-                               // 澶氬勾淇濅慨 end
-                               //澧炲姞妫�绱� 涓嶅彲鍙栨秷澶氬勾淇� 2020/08/27
-                               ,CanNotCancelledGurantee__c
-                               //澧炲姞妫�绱� 闃胯タ璧涘 2020/09/10 start
-                               ,Is_DangerousChemicals__c
-                               //澶栬锤澶氬勾淇� 2021/01/04 绮剧悽鎶�鏈� wql start
-                               //缁翠慨鍚堝悓鎶ヤ环锛圲SD锛�
-                               ,Repair_Contract_USD__c
-                               //璁℃彁閲戦锛堜笉鍚◣锛孶SD锛�
-                               ,Intra_Trade_Foreign_RMB__c
-                               //NoDiscount 閲戦锛圲SD锛�
-                               ,NoDiscount_Foreign__c
-                               //澶栬锤澶氬勾淇� 2021/01/04 绮剧悽鎶�鏈� wql end
-
-                              //SFDC鍋滄棰勮 lt 20211009 start
-                              ,Estimated_ConsumptionDueDate__c
-                              //SFDC鍋滄棰勮 lt 20211009 end
-
-                               FROM Product2 Where Id IN :productIds
-                               And Manual_Entry__c = false];
-    for (Product2 product : products) {
-      items.put(product.Id, product);
-    }
-    system.debug('-----:Product2 select end');
-    system.debug('-----:PricebookEntry select start');
-    Map<Id, PricebookEntry> entries = new Map<Id, PricebookEntry>();
-    List<PricebookEntry> workEntries = [
-                                         SELECT Id, Product2Id
-                                         FROM PricebookEntry Where Product2Id IN :productIds
-                                         AND CurrencyIsoCode = :(opp.Trade__c == '澶栬部' ? 'USD' : 'CNY')
-                                             AND IsActive = true
-                                       ];
-    for (PricebookEntry workEntry : workEntries) {
-      entries.put(workEntry.Product2Id, workEntry);
-    }
-    system.debug('-----:PricebookEntry select end');
-
-    // ----------------------------------------------------------------------------------------
-    // 鐢婚潰銇槑绱拌銇儷銉笺儣
-    // ----------------------------------------------------------------------------------------
-    Integer i = 0;
-    Integer rightcnt = 0; // 鎴愬姛銇椼仧鏁般倰銈偊銉炽儓
-    for (QELine t : tmpactivities) {
-
-      QELine a = New QELine(i);
-
-      system.debug('-----:i=' + i + ', currentDetailNumber=' + currentDetailNumber);
-
-      if (i == currentDetailNumber) {
-        // ----------------------------------------------------------------------------------------
-        // 涓�鍥炪仩銇戝疅琛屻仌銈屻倠銈炽兗銉�
-        // ----------------------------------------------------------------------------------------
-        system.debug('-----:items.size()=' + items.size());
-        if (items.size() > 0) {
-          // ----------------------------------------------------------------------------------------
-          // 銈汇儍銉堝搧鏄庣窗銇儷銉笺儣
-          // ----------------------------------------------------------------------------------------
-          system.debug('-----:銈汇儍銉堝搧鏄庣窗銇儷銉笺儣銈广偪銉笺儓');
-          for (Integer l = 0; l < productSetDetails.size(); l++) {
-            Product_Set_Detail__c nowDetail = productSetDetails[l];
-            Product2 prd = items.get(nowDetail.product__c);
-            PricebookEntry pbe = entries.get(nowDetail.product__c);
-
-            if (pbe == null) {
-              system.debug('This Productid(' + nowDetail.product__c +  ') is not exist PricebookEntry');
-              // ----------------------------------------------------------------------------------------
-              // 鍙栧緱娓堛伩銇� Product2銇儶銈广儓銇腑銇�併偦銉冦儓鍝佹槑绱般伄鎯呭牨銇屻伩銇ゃ亱銈夈仾銇勫牬鍚�
-              // 銇伀銈傘仐銇亜銇с偣銉兗銇欍倠
-              // ----------------------------------------------------------------------------------------
-            } else {
-              // ----------------------------------------------------------------------------------------
-              // 鍙栧緱娓堛伩銇� Product2銇儶銈广儓銇腑銇�併偦銉冦儓鍝佹槑绱般伄鎯呭牨銇屻伩銇ゃ亱銇c仧
-              // 鏄庣窗銇仢銇� Product2銇儏鍫便倰銈汇儍銉堛仚銈嬶紵
-              // ----------------------------------------------------------------------------------------
-              QELine c = null;
-              Integer Quantity_c = nowDetail.Quantity__c > 0 ? Integer.valueOf(nowDetail.Quantity__c) : 1;
-              if (opp.Trade__c == '澶栬部') {
-                if (prd.Foreign_Trade_List_US__c > 0 && prd.Foreign_Trade_Cost_US__c > 0) {
-                  //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 Start 澧炲姞瀛楁&& 澧炲姞妫�绱㈤樋瑗胯禌澶�
-                  c = new QELine(i, prd.Is_DangerousChemicals__c,prd.CanNotCancelledGurantee__c,prd.VenderName__c,
-                                prd.Estimated_ConsumptionDueDate__c, //20211009 lt add   ('',)
-                                pbe.Id, prd.Asset_Model_No__c, prd.StorageStatus__c,
-                    //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 end 澧炲姞瀛楁
-                                 prd.ProductCode, nowDetail.product__c, prd.SFDA_Status__c,
-                                 prd.Sales_Possibility__c, prd.Name, prd.BSSCategory__c,
-                                 Quantity_c, prd.Foreign_Trade_List_US__c,
-                                 prd.Foreign_Trade_List_US__c, prd.Foreign_Trade_Cost_US__c,
-                                 prd.Packing_list_manual__c
-                                 // 澶氬勾淇濅慨 start
-                                 , prd.Entend_gurantee_period_all__c
-                                 //澶栬锤澶氬勾淇� 鍙栦骇鍝佷富鏁版嵁涓婄殑閲戦鍙婄淮淇悎鍚屾姤浠� 绮剧悽鎶�鏈� wql 2021/01/04 start
-                                 , prd.Intra_Trade_Foreign_RMB__c
-                                 , prd.GuranteeType__c
-                                 , prd.NoDiscount_Foreign__c, prd.Repair_Contract_USD__c
-                                 //澶栬锤澶氬勾淇� 鍙栦骇鍝佷富鏁版嵁涓婄殑閲戦鍙婄淮淇悎鍚屾姤浠� 绮剧悽鎶�鏈� wql 2021/01/04 end
-                                 // 澶氬勾淇濅慨 end
-                                );
-
-                } else {
-                  continue;
-                }
-              } else if (opp.Trade__c == '鍐呰部') {
-                if (prd.Intra_Trade_List_RMB__c > 0 && prd.Intra_Trade_Cost_RMB__c > 0) {
-                  //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 Start 澧炲姞瀛楁&&澧炲姞妫�绱㈤樋瑗胯禌澶�
-                  c = new QELine(i,prd.Is_DangerousChemicals__c,prd.CanNotCancelledGurantee__c,prd.VenderName__c, 
-                                prd.Estimated_ConsumptionDueDate__c,   //20211009 lt add
-                                pbe.Id, prd.Asset_Model_No__c, prd.StorageStatus__c,
-                    //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 end 澧炲姞瀛楁
-                                 prd.ProductCode, nowDetail.product__c, prd.SFDA_Status__c,
-                                 prd.Sales_Possibility__c, prd.Name, prd.BSSCategory__c,
-                                 Quantity_c, prd.Intra_Trade_List_RMB__c,
-                                 prd.Intra_Trade_List_RMB__c, prd.Intra_Trade_Cost_RMB__c,
-                                 prd.Packing_list_manual__c
-                                 // 澶氬勾淇濅慨 start
-                                 , prd.Entend_gurantee_period_all__c
-                                 , prd.Intra_Trade_Gurantee_RMB__c
-                                 , prd.GuranteeType__c
-                                 , prd.Intra_Trade_Service_RMB__c
-                                 //缁翠慨鍚堝悓鎶ヤ环
-                                 , prd.Maintenance_Price_Year__c
-                                 // 澶氬勾淇濅慨 end
-                                );
-
-                } else {
-                  continue;
-                }
-              } else {
-                continue;
-                // c = new QELine(i, pbe.Id, prd.Asset_Model_No__c, prd.ProductCode, nowDetail.product__c, prd.SFDA_Status__c, prd.Sales_Possibility__c, prd.Name, prd.BSSCategory__c,
-                //        Quantity_c, 0, 0, 0);
-              }
-              activities.add(c);
-
-              if (i == 149) {
-                // 鏄庣窗琛屻伄鏈�澶у�ゃ伀閬斻仐銇熴倝銆佸嚘鐞嗐倰绲備簡銇欍倠
-                PageArrange();
-                system.debug('-----:寮峰埗绲備簡:98');
-                return null;
-              }
-
-              i++;
-              rightcnt++;
-              lineflg = true;
-            }
-          }
-          system.debug('-----:銈汇儍銉堝搧鏄庣窗銇儷銉笺儣绲備簡');
-          if (lineflg == true) {
-            i--;
-          }
-        } else {
-          // ----------------------------------------------------------------------------------------
-          // Product2銇搞伄銈偍銉亴绲愭灉銈掕繑銇曘仾銇嬨仯銇熸檪銇疅琛屻仌銈屻倠銈炽兗銉�
-          // ----------------------------------------------------------------------------------------
-          a = t;
-          a.lineNo = i;
-          activities.add(a);
-        }
-      } else {
-        // ----------------------------------------------------------------------------------------
-        // Product2銇搞偗銈ㄣ儶銈掓姇銇掋仾銇勬檪銇疅琛屻仌銈屻倠銈炽兗銉�
-        // ----------------------------------------------------------------------------------------
-        a = t;
-        a.lineNo = i;
-        activities.add(a);
-      }
-
-      i++;
-      if (i > 149) {
-        break;
-      }
-    }
-
-    PageArrange();
-    if (productSetDetails.size() > 0) {
-      errorflg = true;
-      errormessage = productSetDetails[0].Product_Set__r.Name + ' 瀵煎叆缁撴潫锛屽鍏� ' + productSetDetails.size() + ' 浠讹紝鎴愬姛' + rightcnt + ' 浠�';
-    }
-    system.debug('-----:绲備簡:' + errormessage);
-    return null;
-  }
-
-  // xudan 20140626 琛岃拷鍔犮儹銈搞儍銈疅瑁�
-  public void addRow() {
-    List<QELine> tmpQELine = new List<QELine>();
-    system.debug('娣诲姞琛宻ize锛�'+activities.size());
-    system.debug('闇�瑕佹坊鍔犺锛�'+rowIdx);
-    for (Integer i = 0; i < activities.size(); i++) {
-      if (i < rowIdx) {
-        tmpQELine.add(activities[i]);
-      } else if ( i == rowIdx) {
-        tmpQELine.add(new QELine(i));
-      } else {
-        tmpQELine.add(activities[i - 1]);
-        tmpQELine[tmpQELine.size() - 1].lineNo = i;
-      }
-    }
-    activities = new List<QELine>();
-    activities.addAll(tmpQELine);
-    PageArrange();
-  }
-  //娣诲姞琛�
-  public void addMultipleRow() {
-    List<QELine> tmpQELine = new List<QELine>();
-    //椤甸潰涓婄殑杈撳叆妗嗚拷鍔� (鍙兘鍦ㄦ湯灏捐拷鍔�)
-    
-    Integer lineRows  = activities.size() + rowIdx;
-    if(lineRows>0 && lineRows>activities.size()&&activities.size()>0){
-        //椤甸潰杈撳叆0鎴栬礋鏁伴兘涓嶅簲璇ョ户缁墽琛�
-        for (Integer i = 0; i < lineRows; i++) {
-            if (i < activities.size()) {
-                tmpQELine.add(activities[i]);
-            } else{
-                tmpQELine.add(new QELine(i));
-            } 
-        }
-        system.debug('tmpQELine:'+tmpQELine);
-        //濡傛灉鍙戠敓琛屾暟鍙樺寲 鍒欏悗鍙版渶澶ф姤浠疯涔熸洿鏂�
-        if(quoteEntryMaxLine < lineRows){
-            quoteEntryMaxLine = lineRows;
+        //system.debug('profileId_20190517_' + profileId);
+        String userid = UserInfo.getUserId();
+        User loginUser = [select id, CanCancelDecideQuote__c from user where Id = :userid];
+        if (new_profileId == System.Label.SystemAdmin || new_profileId == System.Label.SystemAdmin2 
+            || new_profileId == System.Label.SystemAdmin || new_profileId == System.Label.SystemAdmin2
+            || loginUser.CanCancelDecideQuote__c == true) {
+            isAdmin = true;
         }
 
+        openType = System.currentPageReference().getParameters().get('openType');
+        isService = openType == 'service' ? true : false;
+        is_Parts_direct = false;
+        is_Parts_dealer = false;
+        is_hidden_user = false;
+
+        if (profileId == System.Label.RT_BS_No_Price || new_profileId == System.Label.RT_BS_No_Price) {// || profileId == System.Label.SystemAdmin) {
+            is_hidden_user = true;
+            //system.debug('is_hidden_user_1_1_1_1_' + is_hidden_user);
+        }
+        is_dealer_user = false;
+        //system.debug('UserInfo.getUserType()__20190517_'+UserInfo.getUserType());
+        //system.debug('UserInfo.getUserId()__20190517_1_'+UserInfo.getUserId().substring(0, 15));
+
+        if (UserInfo.getUserType() == 'PowerPartner' || UserInfo.getUserId().substring(0, 15) == '00528000002PBPf') {
+            is_dealer_user = true;
+            //system.debug('is_dealer_user_1_1_1_1_' + is_dealer_user);
+        }
+
+        is_hidden_all = false;
+        specialDealer = false;
+
+        //Quote
         
-        //閲嶇敾椤甸潰 閲嶇敾鏂板琛�
-        activities = new List<QELine>();
-        activities.addAll(tmpQELine);
-        PageArrange();
-    }
-    
-  }
-
-  //excelImport
-  public PageReference excelImport() {
-    system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼媁elcome to excelImport!!');
-    system.debug('鈻尖柤鈻尖柤鈻糴xcel_text:' + excel_text);
-    //opp銇敾闈€伄鍊ゃ倰瑷畾
-    setOppFromOppInfo();
-
-    errorflg = false;
-    errormessage = null;
-
-    //鏃㈠瓨銉囥兗銈挎暟銇⒑瑾�
-    Integer j = 0;
-    for (QELine s : activities) {
-      //銉囥兗銈垮垽瀹氥伀Asset_Model_No銈掍娇鐢�
-      if ((s.Asset_Model == null) || (s.Asset_Model == '')) {
-        break;
-      }
-      j++;
-    }
-
-    //=======Temporary=====
-    tmpactivities = activities;
-
-    //=======Initialize=========
-    activities = new List<QELine>();
-    //List<OpportunityLineItem> items = New List<OpportunityLineItem>();
-    Integer i = 0;
-    Integer xlscnt = 0;
-    Integer rightcnt = 0; // 鎴愬姛銇椼仧鏁般倰銈偊銉炽儓
-
-    string[] xlslists = excel_text.split('\n', -1);
-    List<string> xlslist = New list<string>();
-    List<string> codelist = New List<string>();
-    List<Integer> Quantitylist = New List<Integer>();
-    //String str ;
-
-    Map<String, Integer> mp = new Map<String, Integer>();
-    string xlscode;
-    Integer xlsQuantity;
-
-    try {
-      for (string xls : xlslists) {
-        if (xls == null || xls == '') {
-          //null
+        //system.debug('quo---cccc: '+quo);
+        quo = new Quote();
+        quo.Quote_Type__c = 'sales';
+        if (isService == true) {
+            quo.Quote_Type__c = 'service';
+        }
+        quo.Comment__c  = '1)  The payment terms are - .\n';
+        quo.Comment__c += '浠樻鏂瑰紡 - 銆俓n';
+        quo.Comment__c += '2)  Quoation valid until - .\n';
+        quo.Comment__c += '鎶ヤ环鏈夋晥鏈熷埌 - 銆俓n';
+        quo.Comment__c += '3)  All the commodoties come with - year\'s manufacturer warranty.\n';
+        quo.Comment__c += '鎵�鏈夊晢鍝佸惈 - 骞村巶瀹朵繚淇�俓n';
+        if (isService == false) {
+            quo.Comment__c += '4)  The above quotations are - prices, Commodoties shipped to the clien\'s requirements.\n';
+            quo.Comment__c += '涓婅堪鎶ヤ环涓� - 浠凤紝鍟嗗搧閫佽嚦瀹㈡埛鎸囧畾鍦扮偣銆俓n';
+            quo.Comment__c += '5)  The above quotations are all - .\n';
+            quo.Comment__c += '涓婅堪鎶ヤ环鍧囦负 - 浠枫�俓n';
+            quo.Comment__c += '6)  Configuration as per attached.\n';
+            quo.Comment__c += '閰嶇疆娓呭崟璇﹁闄勪欢銆�';
         } else {
-          xlscode = null;
-          xlsQuantity = null;
-          xlslist = xls.split('\t', -1);
-          for (String s : xlslist) {
-            //odd number or even number
-            if (math.mod(i, 2) != 0) {
-              //odd number
-              if (s == '' || s == null) {
-                errorflg = true;
-                errormessage = System.Label.Error_Message31;
-                activities = tmpactivities;
-                pageArrange();
-                return null;
-              } else {
-                s = s.trim();
-                xlsQuantity = Integer.valueOf(s);
-                Quantitylist.add(xlsQuantity);
-              }
-            } else {
-              //even number
-              if (s == '' || s == null) {
-                errorflg = true;
-                errormessage = System.Label.Error_Message31;
-                activities = tmpactivities;
-                pageArrange();
-                return null;
-              } else {
-                s = s.trim();
-                codelist.add(s);
-                xlscode = s;
-              }
+            quo.Comment__c += '4)  The above quotations are all - .\n';
+            quo.Comment__c += '涓婅堪鎶ヤ环鍧囦负 - 浠枫�俓n';
+            quo.Comment__c += '5)  Configuration as per attached.\n';
+            quo.Comment__c += '閰嶇疆娓呭崟璇﹁闄勪欢銆�';
+        }
+
+        if (isService == true) {
+            quo.SetName1__c = '闆朵欢璐圭敤';
+            quo.SetQty1__c = 1;
+            quo.SetName2__c = '缁翠慨璐�';
+            quo.SetQty2__c = 1;
+            quo.SetName3__c = '鍏朵粬璐圭敤';
+            quo.SetQty3__c = 1;
+        }
+       
+        quo = new Quote();
+        quo.Quote_Type__c = 'sales';
+        if (isService == true) {
+            quo.Quote_Type__c = 'service';
+        }
+        quo.Comment__c  = '1)  The payment terms are - .\n';
+        quo.Comment__c += '浠樻鏂瑰紡 - 銆俓n';
+        quo.Comment__c += '2)  Quoation valid until - .\n';
+        quo.Comment__c += '鎶ヤ环鏈夋晥鏈熷埌 - 銆俓n';
+        quo.Comment__c += '3)  All the commodoties come with - year\'s manufacturer warranty.\n';
+        quo.Comment__c += '鎵�鏈夊晢鍝佸惈 - 骞村巶瀹朵繚淇�俓n';
+        if (isService == false) {
+            quo.Comment__c += '4)  The above quotations are - prices, Commodoties shipped to the clien\'s requirements.\n';
+            quo.Comment__c += '涓婅堪鎶ヤ环涓� - 浠凤紝鍟嗗搧閫佽嚦瀹㈡埛鎸囧畾鍦扮偣銆俓n';
+            quo.Comment__c += '5)  The above quotations are all - .\n';
+            quo.Comment__c += '涓婅堪鎶ヤ环鍧囦负 - 浠枫�俓n';
+            quo.Comment__c += '6)  Configuration as per attached.\n';
+            quo.Comment__c += '閰嶇疆娓呭崟璇﹁闄勪欢銆�';
+        } else {
+            quo.Comment__c += '4)  The above quotations are all - .\n';
+            quo.Comment__c += '涓婅堪鎶ヤ环鍧囦负 - 浠枫�俓n';
+            quo.Comment__c += '5)  Configuration as per attached.\n';
+            quo.Comment__c += '閰嶇疆娓呭崟璇﹁闄勪欢銆�';
+        }
+
+        if (isService == true) {
+            quo.SetName1__c = '闆朵欢璐圭敤';
+            quo.SetQty1__c = 1;
+            quo.SetName2__c = '缁翠慨璐�';
+            quo.SetQty2__c = 1;
+            quo.SetName3__c = '鍏朵粬璐圭敤';
+            quo.SetQty3__c = 1;
+        }
+
+        //Opportunityid
+        Opportunity oppRecord = null;
+        if (oppId==null) {
+            oppId = System.currentPageReference().getParameters().get('oppid');
+
+            if (oppId==Null) {
+                quoId = System.currentPageReference().getParameters().get('Id');
+
+                List<Quote> ql = New List<Quote>();
+                ql = [select Id,OpportunityId From Quote Where Id =:quoId];
+                if (ql.size()>0) {
+                    oppId = ql[0].OpportunityId;
+                }
+            } 
+
+            List<Opportunity> oppList = New List<Opportunity>();
+            oppList = [select Id,Pricebook2Id,CurrencyIsoCode,AccountId,Is_Decided__c,ProductSegment__c,Machine_Parts__c,SalesChannel__c,Dealer__r.DummyDealer__c,
+                              IE_Discount_Normal__c,Subuse__c,IE_Discount_Special__c,Dealer_Code__c,Province__c,Dealer_Rank__c,Dealer__r.ParentId,Account.MarketVerticals__c,Trade_Type_D__c,
+                              DealerId__c 
+                         From Opportunity Where Id =:oppId];
+
+            if (oppList.size()>0) {
+                opp = oppList[0];
+                oppRecord = oppList[0];
+                pricebook2Id = oppList[0].Pricebook2Id;
+                currencyIsoCode = oppList[0].CurrencyIsoCode;
+                accountId = oppList[0].AccountId;
+                decideFlg = oppList[0].Is_Decided__c;
+                productSegment = oppList[0].ProductSegment__c;
+                if (oppList[0].Machine_Parts__c == 'Parts' && oppList[0].SalesChannel__c == 'direct') {
+                    is_Parts_direct = true;
+                } else if (oppList[0].Machine_Parts__c == 'Parts' && oppList[0].SalesChannel__c == 'dealer') {
+                    is_Parts_dealer = true;
+                }
+               
+                //if(specialdealer == true){
+                   //is_hidden_all = true;
+                //}
             }
-            i++;
-          }
-          //mp.put(xlscode, xlsQuantity);
-          xlscnt++;
         }
-      }
-    } catch (Exception ex) {
-      activities = tmpactivities;
-      errorflg = true;
-      errormessage = System.Label.Error_Message31;
-      pageArrange();
-      return null;
-    }
-
-    system.debug(j);
-    system.debug('xlscnt:::::' + xlscnt);
-
-    if (codelist.size() == 0 || Quantitylist.size() == 0) {
-      activities = tmpactivities;
-      errorflg = true;
-      errormessage = System.Label.Error_Message31;
-      pageArrange();
-      return null;
-    }
-
-    xlscnt = j + xlscnt;
-    if (xlscnt > quoteEntryMaxLine) {
-      activities = tmpactivities;
-      errorflg = true;
-      errormessage = System.Label.Error_Message32;
-      pageArrange();
-      return null;
-    }
-
-    i = 0;
-    boolean lineflg = false;
-    for (QELine t : tmpactivities) {
-      if (i == j) {
-        Map<String, Product2> mpProduct2 = new Map<String, Product2>();                     // key銇孭roductCode銇с仚銆�
-        List<Product2> items = [select Id, Name, ProductCode,
-                                Foreign_Trade_Cost_US__c, Foreign_Trade_List_US__c, Intra_Trade_Cost_RMB__c, Intra_Trade_List_RMB__c,
-                                //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 Start 澧炲姞瀛楁
-                                Asset_Model_No__c, Sales_Possibility__c, Estimation_Entry_Possibility__c,VenderName__c,
-                                //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 end 澧炲姞瀛楁
-                                SFDA_Status__c, Qty_Unit__c, BSSCategory__c, Packing_list_manual__c, StorageStatus__c
-                                // 澶氬勾淇濅慨 start
-                                , Entend_gurantee_period_all__c
-                                , Intra_Trade_Gurantee_RMB__c
-                                , Intra_Trade_Service_RMB__c
-                                , GuranteeType__c
-                                // 缁翠慨鍚堝悓鎶ヤ环
-                                ,  Maintenance_Price_Year__c
-                                // 澶氬勾淇濅慨 end
-                                //澧炲姞妫�绱� 涓嶅彲鍙栨秷澶氬勾淇� 2020/08/27
-                               ,CanNotCancelledGurantee__c
-                               //澧炲姞妫�绱� 闃胯タ璧涘 2020/09/10
-                               ,Is_DangerousChemicals__c
-                               //澶栬锤澶氬勾淇� 2021/01/04 绮剧悽鎶�鏈� wql start
-                               //缁翠慨鍚堝悓鎶ヤ环锛圲SD锛�
-                               ,Repair_Contract_USD__c
-                               //璁℃彁閲戦锛堜笉鍚◣锛孶SD锛�
-                               ,Intra_Trade_Foreign_RMB__c
-                               //NoDiscount 閲戦锛圲SD锛�
-                               ,NoDiscount_Foreign__c
-                               //澶栬锤澶氬勾淇� 2021/01/04 绮剧悽鎶�鏈� wql end  
-
-                              //SFDC鍋滄棰勮 lt 20211009 start
-                              ,Estimated_ConsumptionDueDate__c
-                              //SFDC鍋滄棰勮 lt 20211009 end
-
-                                FROM Product2 Where ProductCode In :codelist
-                                And Manual_Entry__c = false];
-        for (Product2 prd : items) {
-          system.debug('prd.ProductCode:::::' + prd.ProductCode);
-          mpProduct2.put(prd.ProductCode, prd);
+        //specialDealer = StaticParameter.specialDealerMap.containsKey(((String)opp.DealerId__c).substring(0,15));
+        //specialDealer = IfspecialDealer(opp.DealerId__c);
+        if (opp != null) {
+            specialDealer = IfspecialDealer(opp.DealerId__c);
+            if(specialDealer == true){
+                is_hidden_all = true;
+            }
         }
-        Map<String, PricebookEntry> entries = new Map<String, PricebookEntry>();            // key銇孭roductCode銇с仚銆�
+        Boolean updateOrCopy = false;
+        quoId = System.currentPageReference().getParameters().get('Id');
+
+        if (quoId==null){
+            quoId = System.currentPageReference().getParameters().get('copyid');
+            if (quoId!=null){ 
+                updateOrCopy = true;
+            }
+        } else {
+            updateOrCopy = false;
+        }
+
+        Integer i;
+        
+        if (quoId==null){
+
+            List<Quote> qlCk = New List<Quote>();
+                qlCk = [select Id,OpportunityId,Opportunity.DealerId__c,OrderIsChange__c From Quote Where OpportunityId =:oppId];
+            if (qlCk.size()>0) {
+                //specialDealer =  StaticParameter.specialDealerMap.containsKey(qlCk[0].Opportunity.DealerId__c);
+                specialDealer = IfspecialDealer(qlCk[0].Opportunity.DealerId__c);
+                if(specialDealer == true){
+                    is_hidden_all = true;
+                }
+                if (activities==null){
+                    activities = new List<QELine>();
+                    for (i=0;i<quoteEntryMaxLine;i++){
+                        QELine active_activity = new QELine(i);
+                        activities.add(active_activity);
+                    }
+                }
+
+            } else {
+                Integer k;
+                List<OpportunityLineItem> oppItemList = New List<OpportunityLineItem>();
+                oppItemList = [select Id,Product2Id,ProductCode,Product2.Product_ECCode__c,Product2.Name,Quantity,UnitPrice,Description,PricebookEntryId,
+                                      PricebookEntry.SalesPrice__c,PricebookEntry.SalesPriceA__c,PricebookEntry.SalesPriceB__c,
+                                      PricebookEntry.SalesPriceC__c,Product2.ProductModels__c,PricebookEntry.Hidden_flag__c,
+                                      Opportunity.DealerId__c
+                                 From OpportunityLineItem
+                                Where OpportunityId =:oppId];
+                if (oppItemList.size()>0) {
+                    k = oppItemList.size();
+                } else {
+                    k = 0;
+                }
+                //鏂拌銉偣銉堛偝銉炽儓銉兗銉┿伄鍙栧緱
+                if (activities==null){
+                    activities = new List<QELine>();
+                    for (i=0;i<quoteEntryMaxLine;i++){
+                        QELine active_activity = new QELine(i);
+                        if (i<k) {
+                            active_activity.productName = oppItemList[i].Product2.Name;
+                            active_activity.productCode = oppItemList[i].ProductCode;
+                            active_activity.productEC = oppItemList[i].Product2.Product_ECCode__c;
+                            active_activity.pageObject.Quantity = oppItemList[i].Quantity;
+                            active_activity.pageObject.UnitPrice = oppItemList[i].UnitPrice;
+                            active_activity.pageObject.Description = oppItemList[i].Description;
+                            active_activity.totalPrice = oppItemList[i].Quantity * oppItemList[i].UnitPrice;
+                            if (isService == true) {
+                                active_activity.setName = '闆朵欢璐圭敤';
+                            } else {
+                                active_activity.setName = '鍗曞搧';
+                            }
+                            active_activity.pageObject.Set__c = '鍗曞搧';
+                            active_activity.pageObject.SingleProduct__c = true;
+                            active_activity.pageObject.PricebookEntryId = oppItemList[i].PricebookEntryId;
+                            active_activity.salesPrice = oppItemList[i].PricebookEntry.SalesPrice__c;
+                            active_activity.salesPriceA = oppItemList[i].PricebookEntry.SalesPriceA__c;
+                            active_activity.salesPriceB = oppItemList[i].PricebookEntry.SalesPriceB__c;
+                            active_activity.salesPriceC = oppItemList[i].PricebookEntry.SalesPriceC__c;
+
+                            active_activity.isProductModel = oppItemList[i].Product2.ProductModels__c;
+
+                            active_activity.hiddenflg = oppItemList[i].PricebookEntry.Hidden_flag__c;
+                            //StaticParameter.specialGroupMap.
+                            //specialDealer =  StaticParameter.specialDealerMap.containsKey(oppItemList[i].Opportunity.DealerId__c);
+                            specialDealer = IfspecialDealer(oppItemList[i].Opportunity.DealerId__c);
+                            if(specialDealer == true){
+                                is_hidden_all = true;
+                            }
+                            //system.debug();
+                            //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '璇烽�夋嫨鐩爣瀹㈡埛---->'+oppItemList[i].Opportunity.DealerId__c));
+                            if (specialDealer || is_hidden_user == true || is_dealer_user == true && oppItemList[i].PricebookEntry.Hidden_flag__c == true) {
+                                active_activity.pageObject.UnitPrice = 0;
+                                active_activity.totalPrice = 0;
+                                system.debug('<---is_hidden_all--->03' + is_hidden_all);
+                                is_hidden_all = true;
+                                discount = 0;
+                            }
+                        }
+                        activities.add(active_activity);
+                    }
+                }
+            }
+            
+        } else {
+            system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆Welcome to edit class!!鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆');
+
+            String accountid;
+
+            List<Quote> quoList = 
+                [ SELECT Id,Name,QuoteNumber,Account.Name,ExpirationDate,Subtotal,Discount,TotalPrice,GrandTotal,PrintPrice__c,ShippingHandling,
+                    DeliveryLeadTime__c,PaymentTerms__c,ValidDate__c,Warranty__c,SetName1__c,Is_Decided__c,Shipment_Term__c,Shipment_Term2__c,
+                    SetName2__c,SetName3__c,SetName4__c,SetName5__c,SetName6__c,SetName7__c,SetName8__c,SetName9__c,SetName10__c,
+                    SetName11__c,SetName12__c,SetName13__c,SetName14__c,SetName15__c,SetName16__c,SetName17__c,SetName18__c,SetName19__c,
+                    SetName20__c,SetName21__c,SetName22__c,SetName23__c,SetName24__c,SetName25__c,SetName26__c,SetName27__c,SetName28__c,SetName29__c,
+                    SetName30__c,SetQty1__c,SetQty2__c,SetQty3__c,SetQty4__c,SetQty5__c,SetQty6__c,SetQty7__c,SetQty8__c,SetQty9__c,SetQty10__c,SetQty11__c,
+                    SetQty12__c,SetQty13__c,SetQty14__c,SetQty15__c,SetQty16__c,SetQty17__c,SetQty18__c,SetQty19__c,SetQty20__c,SetQty21__c,SetQty22__c,SetQty23__c,
+                    SetQty24__c,SetQty25__c,SetQty26__c,SetQty27__c,SetQty28__c,SetQty29__c,SetQty30__c,Comment__c,Custom_Price_Total__c,Custom_Price_Total_Text__c,Quote_Type__c,
+                    Main_Model__c,Main_Serial_Number__c,Service_Type__c,Contract_Number__c,Service_Date__c,Service_Finish_Date__c,Service_Engineer_Sign__c,
+                    Service_Pickup_Sign__c,Service_Check_Sign__c,Service_Location__c,Service_Status__c,Service_Content__c, Is_upload__c, Total_Price_Text__c,
+                    Discount_Normal__c,Discount_Special__c,OrderIsChange__c 
+                    FROM Quote Where Id =:quoId];
+            List<QuoteLineItem> items = 
+                [Select Id,Product2Id,Product2.Name,Product2.ProductCode,Product2.Product_ECCode__c,Quantity,Subtotal,Discount,TotalPrice,PricebookEntryId,UnitPrice,Description,Set__c,Custom_Price__c,
+                        PricebookEntry.SalesPrice__c,PricebookEntry.SalesPriceA__c,PricebookEntry.SalesPriceB__c,PricebookEntry.SalesPriceC__c,Product2.ProductModels__c,PricebookEntry.Hidden_flag__c,
+                        SingleProduct__c,SetName__c,
+                        Quote.Opportunity.DealerId__c
+                   From QuoteLineItem where Quoteid = :quoId Order by Id];
+
+            //system.debug('quoList==========>'+quoList);
+            //system.debug('items==========>'+items);
+
+            if (quoList.size() > 0) {
+                if (updateOrCopy) {
+
+                    quo = quoList[0];
+                    quo.Id = null;
+                    quo.name = null;
+                    quo.Is_Decided__c = false;
+                    quo.Is_upload__c = false;
+                } else {
+                    quo = quoList[0];
+                }
+                isdecide = quo.Is_Decided__c;
+            }
+
+            if (updateOrCopy) {
+                quoId = null;
+            }
+            quoteLineSetNameDiscountMap = new Map<String,String>();
+            activities = new List<QELine>();
+            i=0;
+            QELine c = new QELine(i);
+
+            if (items.size()>0) {
+                for (QuoteLineItem o:items) {
+
+                    if (String.isNotBlank(o.SetName__c)) {
+                        quoteLineSetNameDiscountMap.put(o.SetName__c,String.valueOf(o.Discount));
+                    }
+                    String setName = o.Set__c;
+                    Integer qty = 1;
+                    if (setName != null) {
+                        //XHL-20190426-UpdateStart
+                        if (!o.SingleProduct__c) {
+                            
+                            String fieldName = setName.substring(3);
+                            fieldName = fieldName.indexOf('0') == 0 ? fieldName.substring(1) : fieldName;
+                            Decimal d_qty = (Decimal) quo.get('SetQty' + fieldName + '__c');
+                            qty = d_qty == null ? 1 : d_qty.intValue();
+                        }
+                        //XHL-20190426-UpdateEnd 
+                        
+                    }
+                    c = new QELine(isService,o,i,o.Product2.Name,o.Product2.ProductCode,o.Product2.Product_ECCode__c,qty,o.Product2.ProductModels__c,o.SingleProduct__c,o.SetName__c);
+                    //specialDealer =  StaticParameter.specialDealerMap.containsKey(o.Quote.Opportunity.DealerId__c);
+                    specialDealer = IfspecialDealer(o.Quote.Opportunity.DealerId__c);
+                    if(specialDealer == true){
+                        is_hidden_all = true;
+                    }
+                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '璇烽�夋嫨鐩爣瀹㈡埛----2>'+o.Quote.Opportunity.DealerId__c));
+                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '璇烽�夋嫨鐩爣瀹㈡埛----n>'+specialDealer));
+
+                    if ( specialDealer || is_hidden_user == true || is_dealer_user == true && c.hiddenflg == true) {
+                        c.pageObject.UnitPrice = 0;
+                        c.totalPrice = 0;
+                        c.customPrice = 0;
+                        system.debug('<---is_hidden_all---04>' + is_hidden_all);
+                        is_hidden_all = true;
+                        discount = 0;
+                    }
+                    activities.add(c);
+                    i++;
+
+                    if (quo.OrderIsChange__c) {
+                        String productCode = o.Product2.ProductCode;
+                        if (String.isNotBlank(productCode)) {
+                             
+                            initStringConcatenation += productCode + '|' + o.Quantity;
+                        }
+                        
+                    }
+                }
+
+                for (integer j=i;j<quoteEntryMaxLine;j++) {
+                    c = new QELine(j);
+                    activities.add(c);
+                }
+                quoteLineSetNameDiscountJson(quoteLineSetNameDiscountMap);
+                
+            } else {
+                activities = new List<QELine>();
+                for (i=0;i<quoteEntryMaxLine;i++) {
+                    QELine active_activity = new QELine(i);
+                    activities.add(active_activity);
+                }
+            }
+
+system.debug('=====is_hidden_all:' + is_hidden_all);
+            if (is_hidden_all) {
+                discount = quo.totalPrice.setScale(2, System.RoundingMode.HALF_UP);
+            } else {
+                discount = quo.Discount == null ? 0 : quo.Discount;
+
+                discount = discount.setScale(2, System.RoundingMode.HALF_UP);
+            }
+system.debug('=====discount:' + discount);
+
+            if (quoId != null) {
+                printFlg = true;
+            }
+
+            system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆 edit class  End!!鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆');
+        }
+
+        Map<String, Decimal> ddMap = new Map<String, Decimal>();
+        String key1 = '';
+        String key2 = '';
+        List<Dealer_Discount__c> ddList = [select id, Dealer_Rank_F__c,Product_Segment__c, DimensionField1__c, DimensionField2__c, DimensionValue1__c, DimensionValue2__c, Dealer_Rank__c from Dealer_Discount__c where Product_Segment__c = :productSegment];
+        for (Dealer_Discount__c dd : ddList) {
+            ddMap.put(dd.DimensionValue1__c + '|' + dd.DimensionValue2__c, dd.Dealer_Rank_F__c);
+            key1 = dd.DimensionField1__c == null ? '' : dd.DimensionField1__c;
+            key2 = dd.DimensionField2__c == null ? '' : dd.DimensionField2__c;
+        }
+
+        String keyF = ((key1 == '' || oppRecord.get(key1) == null) ? 'null' : oppRecord.get(key1)) + '|' + ((key2 == '' || oppRecord.get(key2) == null) ? 'null' : oppRecord.get(key2));
+
+        quo.Discount_Normal__c = 100 - (ddMap.get(keyF) == null ? 100.0 : ddMap.get(keyF));
+        dealer_coefficient = quo.Discount_Normal__c;
+system.debug('=====keyF:' + keyF);
+system.debug('=====Discount_Normal__c:' + quo.Discount_Normal__c);
+        activitiesSize = activities.size();
+
+        system.debug(specialDealer);
+    }
+
+    public PageReference Refresh() {
+
+        List<Id> Idlist = New List<Id>();
+        for (QELine t:activities) {
+            Idlist.add(t.pageObject.PricebookEntryId);
+        }
+
+        if (Idlist.size()==0) {
+            errorflg = true;
+            errormessage = System.Label.Error_Message01;
+            return null;
+        }
+
+        //List<PricebookEntry> pbes = [
+        //            select Id,Product2Id,ProductCode,Product2.Product_ECCode__c,SalesPrice__c,SalesPriceA__c,SalesPriceB__c,SalesPriceC__c,Hidden_flag__c,Product2.ProductStatus__c
+        //            FROM PricebookEntry where Id in :Idlist];
+        //20191113-XHL---Start-灏嗕骇鍝佺姸鎬佺敤浜у搧鐘舵��(鍏紡)鏇挎崲
         List<PricebookEntry> pbes = [
-                                      select Id, PricebookEntry.Product2.ProductCode
-                                      FROM PricebookEntry Where PricebookEntry.Product2.ProductCode IN :codelist
-                                      AND CurrencyIsoCode = :(opp.Trade__c == '澶栬部' ? 'USD' : 'CNY')
-                                          AND IsActive = true];
-        for (PricebookEntry pbe : pbes) {
-          system.debug('pbe.Product2.ProductCode:::::' + pbe.Product2.ProductCode);
-          entries.put(pbe.Product2.ProductCode, pbe);
-        }
-
-        for (Integer l = 0; l < codelist.size(); l++) {
-          system.debug('codelist[l]:::::' + codelist[l]);
-          Product2 prd = mpProduct2.get(codelist[l]);
-          if (prd != null) {
-            PricebookEntry pbe = entries.get(codelist[l]);
-            QELine c = null;
-            if (pbe != null && (opp.Trade__c == '澶栬部' || opp.Trade__c == '鍐呰部')) {
-              if (opp.Trade__c == '澶栬部') {
-                if (prd.Foreign_Trade_List_US__c > 0 && prd.Foreign_Trade_Cost_US__c > 0) {
-                  //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 Start 澧炲姞瀛楁&&澧炲姞闃胯タ璧涘
-                  c = new QELine(i,prd.Is_DangerousChemicals__c,prd.CanNotCancelledGurantee__c, prd.VenderName__c,
-                                  prd.Estimated_ConsumptionDueDate__c,//20211009 lt add  ('',)
-                                  pbe.Id, prd.Asset_Model_No__c, prd.StorageStatus__c, prd.ProductCode, prd.Id, prd.SFDA_Status__c, prd.Sales_Possibility__c, prd.Name, prd.BSSCategory__c,
-                    //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 end 澧炲姞瀛楁
-                                 Quantitylist[l], prd.Foreign_Trade_List_US__c, prd.Foreign_Trade_List_US__c, prd.Foreign_Trade_Cost_US__c, prd.Packing_list_manual__c
-                                 // 澶氬勾淇濅慨 start
-                                 //澶栬锤澶氬勾淇� 鍙栦骇鍝佷富鏁版嵁涓婄殑閲戦鍙婄淮淇悎鍚屾姤浠� 绮剧悽鎶�鏈� wql 2021/01/04 start
-                                 , prd.Entend_gurantee_period_all__c
-                                 , prd.Intra_Trade_Foreign_RMB__c
-                                 , prd.GuranteeType__c
-                                 , prd.NoDiscount_Foreign__c,
-                                 prd.Repair_Contract_USD__c
-                                 //澶栬锤澶氬勾淇� 鍙栦骇鍝佷富鏁版嵁涓婄殑閲戦鍙婄淮淇悎鍚屾姤浠� 绮剧悽鎶�鏈� wql 2021/01/04 end
-                                 // 澶氬勾淇濅慨 end
-                                );
-
-                } else {
-                  continue;
-                }
-              } else {
-                if (prd.Intra_Trade_List_RMB__c > 0 && prd.Intra_Trade_Cost_RMB__c > 0) {
-                  //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 Start 澧炲姞瀛楁&&澧炲姞妫�绱㈤樋瑗胯禌澶�
-                  c = new QELine(i,prd.Is_DangerousChemicals__c,prd.CanNotCancelledGurantee__c,prd.VenderName__c, 
-                                prd.Estimated_ConsumptionDueDate__c,//20211009 lt add
-                                pbe.Id, prd.Asset_Model_No__c, prd.StorageStatus__c, prd.ProductCode, prd.Id, prd.SFDA_Status__c, prd.Sales_Possibility__c, prd.Name, prd.BSSCategory__c,
-                    //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 end 澧炲姞瀛楁
-                                 Quantitylist[l], prd.Intra_Trade_List_RMB__c, prd.Intra_Trade_List_RMB__c, prd.Intra_Trade_Cost_RMB__c, prd.Packing_list_manual__c
-                                 // 澶氬勾淇濅慨 start
-                                 , prd.Entend_gurantee_period_all__c
-                                 , prd.Intra_Trade_Gurantee_RMB__c
-                                 , prd.GuranteeType__c
-                                 , prd.Intra_Trade_Service_RMB__c
-                                 , prd.Maintenance_Price_Year__c
-                                 // 澶氬勾淇濅慨 end
-                                );
-
-                } else {
-                  continue;
-                }
-              }
-            } else {
-              continue;
-              // c = new QELine(i, pbe.Id, prd.Asset_Model_No__c, prd.ProductCode, prd.Id, prd.SFDA_Status__c, prd.Sales_Possibility__c, prd.Name, prd.BSSCategory__c,
-              //        Quantitylist[l], 0, 0, 0);              // pbe 銇亜鏅傘倐杩藉姞銇欍倠銆乻etProductEntry() 銇儹銈搞儍銈仺閬曘亜銇俱仚銆�
-            }
-            activities.add(c);
-            i++;
-            rightcnt++;
-            lineflg = true;
-          }
-        }
-        if (lineflg == true) {
-          i--;
-        } else {
-          // 20140507,LW淇敼銆�
-          // 褰撳鍏ョ殑鎵�鏈夊晢鍝侀兘涓嶆垚鍔熸椂锛屽綋鍓嶆槑缁嗚浠�涔堥兘娌℃湁鍋氾紝骞朵笖i鍔犱竴銆傚鑷翠笅闈㈠惊鐜疦ew QELine(t, i)涓璱閿欒銆�
-          // 淇敼涓猴細褰撳鍏ョ殑鎵�鏈夊晢鍝侀兘涓嶆垚鍔熸椂锛屽綋鍓嶆槑缁嗚鎻掑叆涓�涓┖琛岋紝涔嬪悗i鍔犱竴銆�
-          QELine a = New QELine(t, i);
-          activities.add(a);
-        }
-      } else {
-        QELine a = New QELine(t, i);
-        activities.add(a);
-      }
-      i++;
-      if (i > 149) {
-        break;
-      }
-    }
-    // message銈掑嚭銇�
-    errorflg = true;
-    errormessage = '鏁版嵁瀵煎叆缁撴潫锛屽鍏� ' + codelist.size() + ' 浠讹紝鎴愬姛' + rightcnt + ' 浠�';
-    pageArrange();
-
-    return null;
-
-  }
-
-  //璨╁2搴�1
-  public void getSalesId1() {
-    system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼媁elcome to getSalesId1!!');
-    system.debug('鈻尖柤鈻尖柤鈻糞alesId1锛�' + SalesId1);
-    //opp銇敾闈€伄鍊ゃ倰瑷畾
-    setOppFromOppInfo();
-
-    errorflg = false;
-    errormessage = null;
-
-    List<Account> accs = New List<Account>();
-    accs = [select Id, Name, Sales_Shop_Class__c From Account Where Id = :SalesId1];
-    If (accs.size() > 0) {
-      SalesShopClass1 = accs[0].Sales_Shop_Class__c;
-      opp.Agency1__c = accs[0].Id;
-    }
-    pageArrange();
-  }
-
-  //璨╁2搴�2
-  public void getSalesId2() {
-    system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼媁elcome to getSalesId2!!');
-    system.debug('鈻尖柤鈻尖柤鈻糞alesId2锛�' + SalesId2);
-    //opp銇敾闈€伄鍊ゃ倰瑷畾
-    setOppFromOppInfo();
-
-    errorflg = false;
-    errormessage = null;
-
-    List<Account> accs = New List<Account>();
-    accs = [select Id, Name, Sales_Shop_Class__c From Account Where Id = :SalesId2];
-    If (accs.size() > 0) {
-      SalesShopClass2 = accs[0].Sales_Shop_Class__c;
-      opp.Agency2__c = accs[0].Id;
-    }
-    pageArrange();
-  }
-
-
-  //Button Ivents============================================================
-
-  //cancel button
-  public void cancel() {
-    system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼媁elcome to CancelButton!!');
-    system.debug('selection_hp' + selection_hp);
-  }
-
-  //PriceStatusUpdate button銆乀ODO productCompare(js銇仺銇撱倣)锛戜欢銇氥仱妞滅储銇椼仸銇勩伨銇欍亴銆佷粖寰屻�亀ebservice銈掍娇銇c仸涓�鎷亱楂橀�熴亱銇с亶銇俱仚銆�
-  public void PriceStatusUpdate() {
-    system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼媁elcome to PriceStatusUpdate!!');
-    //opp銇敾闈€伄鍊ゃ倰瑷畾
-    setOppFromOppInfo();
-
-    errorflg = false;
-    errormessage = null;
-
-    //鍏ㄤ欢娲椼亜鏇裤亪銇椼伨銇欍��
-    if (activities.size() > 0) {
-      for (QELine a : activities) {
-        if ((a.Asset_Model != null) && (a.Asset_Model != '')) {
-          // CHAN-AVG3PW 璇环鎶ヤ环鐢婚潰瑙勫垯鍙樻洿
-          // 鍙鏇存柊锛屽氨鐢熸垚鏂版姤浠风紪鐮�
-          if (a.PageObject.SFDA_Status__c != a.latestInfo.SFDA_Status ||
-              a.PageObject.Name__c != a.latestInfo.ProductName ||
-              a.ListPrice_Page != a.latestInfo.ListPrice ||
-              a.PageObject.Cost__c != a.latestInfo.Cost ||
-              a.Cost_c != a.latestInfo.Cost
-              // 澶氬勾淇濅慨 start
-              //璁℃彁閲戦
-              || a.ProductGuranteePrice != a.latestInfo.Intra_Trade_Gurantee
-              || a.PageObject.productServicePrice__c  != a.latestInfo.Intra_Trade_Service
-              // 缁翠慨鍚堝悓鎶ヤ环
-              || a.Maintenance_Price_Year != a.latestInfo.Maintenance_Price_Year
-              // 澶氬勾淇濅慨 end
-             ) {
-            system.debug('qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq:');
-            system.debug('涓婃SFDA鐘舵�侊細'+a.PageObject.SFDA_Status__c);
-            system.debug('鏈�鏂扮殑SFDA鐘舵�侊細'+a.latestInfo.SFDA_Status);
-            system.debug('涓婃Name__c锛�'+a.PageObject.Name__c);
-            system.debug('鏈�鏂扮殑ProductName锛�'+a.latestInfo.ProductName);
-            system.debug('涓婃ListPrice锛�'+a.ListPrice_Page);
-            system.debug('鏈�鏂扮殑涓婃ListPrice锛�'+a.latestInfo.ListPrice);
-            system.debug('涓婃Cost__c锛�'+a.Cost_c);
-            system.debug('鏈�鏂扮殑Cost锛�'+a.latestInfo.Cost);
-            system.debug('涓婃Cost__c锛�'+a.Cost_c);
-            system.debug('鏈�鏂扮殑Cost锛�'+a.latestInfo.Cost);
-            system.debug('涓婃璁℃彁閲戦锛�'+a.ProductGuranteePrice);
-            system.debug('鏈�鏂扮殑璁℃彁閲戦锛�'+a.latestInfo.Intra_Trade_Gurantee);
-            system.debug('涓婃nodis锛�'+a.PageObject.productServicePrice__c);
-            system.debug('鏈�鏂扮殑nodis锛�'+a.latestInfo.Intra_Trade_Service);
-            system.debug('涓婃缁翠慨鍚堝悓鎶ヤ环锛�'+a.Maintenance_Price_Year);
-            system.debug('鏈�鏂扮殑缁翠慨鍚堝悓鎶ヤ环锛�'+a.latestInfo.Maintenance_Price_Year);
-            system.debug('newQuoteFlag6:'+newQuoteFlag);
-            newQuoteFlag = true;
-          }
-          if (a.pageObject.Name__c != a.latestInfo.ProductName) {
-            a.changed_name = true;
-          }
-          if (a.pageObject.SFDA_Status__c != a.latestInfo.SFDA_Status) {
-            a.changed_sfda = true;
-          }
-          if (a.ListPrice_Page != a.latestInfo.ListPrice) {
-            a.changed_list = true;
-          }
-          if (a.pageObject.Cost__c != a.latestInfo.Cost) {
-            a.changed_cost = true;
-          }
-          // TODO katsu SFDA銈广儐銉笺偪銈广伄纰鸿獚銇仼銇勩倝銇亜銇с仚銇嬶紙鏈�鏂板晢鍝乆XX銇爡鐩倐锛�
-          a.PageObject.SFDA_Status__c = a.latestInfo.SFDA_Status;
-          a.PageObject.Name__c = a.latestInfo.ProductName;
-          a.ListPrice_Page = a.latestInfo.ListPrice;
-          a.PageObject.Cost__c = a.latestInfo.Cost;
-          a.Cost_c = a.latestInfo.Cost;
-          //澶氬勾淇濅慨 start
-          a.PageObject.ProductGuranteePrice__c =  a.latestInfo.Intra_Trade_Gurantee;
-          a.PageObject.GuranteeType__c = a.latestInfo.GuranteeType;
-          // 璁℃彁閲戦
-          a.PageObject.productServicePrice__c = a.latestInfo.Intra_Trade_Service;
-          // 澶氬勾淇濅慨骞撮檺
-          a.PageObject.ProductEntend_gurantee_period_all__c
-            = a.latestInfo.ProductEntend_gurantee_period_all;
-          // 缁翠慨鍚堝悓鎶ヤ环
-          a.Maintenance_Price_Year = a.latestInfo.Maintenance_Price_Year;
-          //澶氬勾淇濅慨 end
-        }
-      }
-      productStatusUpdated = true;
-    }
-    pageArrange();
-  }
-
-  //Save button
-  public PageReference Save() {
-    // Boolean ifdecide=false;
-    // List<Opportunity> oppsde = [Select Id, Estimation_Decision__c From Opportunity Where Id = : oppId];
-    // if (oppsde.size() > 0) {
-    //   if(oppsde[0].Estimation_Decision__c){
-    //     ifdecide=true;
-    //   }else{
-    //     ifdecide=false;
-    //   }
-    // }
-    // system.debug('oppsde:::::::1' + oppsde );
-    // if(!ifdecide){
-      setOppFromOppInfo();
-      System.debug('Save() start at: ' + System.currentTimeMillis());
-      system.debug('WinOrDecideAlert:::::::3' + WinOrDecideAlert );
-      errorflg = false;
-      errormessage = null;
-      errorMessagechack = null;
-      Savepoint sp = Database.setSavepoint();
-      try {
-        // CHAN-AVG3PW 璇环鎶ヤ环鐢婚潰瑙勫垯鍙樻洿
-        // 鎶ヤ环鍒涘缓鏃ヨ秴杩囦笁涓湀鏃讹紝鐐逛繚瀛樻椂寮哄埗鏇存柊
-        // CHAN-AZG864 涓嶇鍦ㄤ笉鍦ㄦ姤浠锋湁鏁堟湡鍐咃紝CFDA涓嶅彲閿�鍞殑鏃跺�欙紝閮芥槸鎶ラ敊鐨勶紝鍏朵腑涓嶅彲閿�鍞骇鍝佹樉绀虹孩瀛楋紝涓嶅簲璇ヤ繚瀛樸��
-        if (WinOrDecideAlert && (!productStatusUpdated)) {
-          errorflg = true;
-          errorMessage = '浜у搧鐘舵�佸彂鐢熷彉鍖栵紝璇锋洿鏂�';
-          return null;
-        }
-        if (checkSFDAStatus1(false) == false) {
-          errorflg = true;
-          errormessage = '璇锋洿鏂颁笉鍙攢鍞殑浜у搧銆�';
-          return null;
-        }
-
-        System.debug('checkSFDAStatus1 finished at: ' + System.currentTimeMillis());
-
-        //銉囥兗銈裤儊銈с儍銈�
-        if (dataCheck() == false) {
-          return null;
-        }
-
-        System.debug('dataCheck finished at: ' + System.currentTimeMillis());
-
-        // LHJ 鎺堟潈check Start
-        if (enableSales == true && opp.Trade__c == '鍐呰部') {
-
-          //缁忛攢鍟嗕骇鍝佹敞鍐岃瘉鍖归厤
-          Map<Id, String> proMap = new Map<Id, String>();
-          
-          if (activities.size() > 0) {
-            for (QELine qli : activities) {
-              if (qli.Asset_Model != null && qli.Asset_Model != '') {
-                proMap.put(qli.pageObject.Id__c, qli.PageObject.Name__c);
-              }
-            }
-          }
-          
-          // GZW 鐢婚潰鍑洪敊璇秷鎭�
-          Map<String, String> chkMap = OpportunityWebService.MapCheckProRegisterDecide(proMap, opp.Agency1__c, '');
-          //this.haveno_Register 娌℃湁娉ㄥ唽璇� 鐘舵�佺孩鑹�
-          //this.wrong_Register  鍖归厤涓嶄笂  鍚嶅瓧绾㈣壊
-          if (chkMap.size() > 0) {
+                    select Id,Product2Id,ProductCode,Product2.Product_ECCode__c,SalesPrice__c,SalesPriceA__c,SalesPriceB__c,SalesPriceC__c,Hidden_flag__c,Product2.ProductStatus__c,Product2.ProductStatusFormula__c
+                    FROM PricebookEntry where Id in :Idlist];
+        //20191113-XHL---End-灏嗕骇鍝佺姸鎬佺敤浜у搧鐘舵��(鍏紡)鏇挎崲
+        if (pbes.size()==0) {
             errorflg = true;
-            //闃胯タ濉炲 鍙栨秷璇ユ鏌�
-            if (chkMap.containsKey('agency')&&!opp.Is_Corrosion__c) {
-              ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,  '绗竴缁忛攢鍟嗘病鏈夋湁鏁堢殑鍖荤枟鍣ㄦ缁忚惀璁稿彲璇併��'));
-            }
-            Integer inerr = 0;
-            if (activities.size() > 0) {
-              for (QELine s : activities) {
-                if (s.Asset_Model != null && s.Asset_Model != '') {
-                  s.haveno_Register = false;
-                  s.wrong_Register = false;
-                  if (chkMap.containsKey(s.PageObject.Id__c)) {
-                    if (chkMap.get(s.PageObject.Id__c) == '1') {
-                      s.haveno_Register = true;
-                      inerr ++;
-                    } else if (chkMap.get(s.PageObject.Id__c) == '2') {
-                      s.wrong_Register = true;
-                      inerr ++;
-                    }
-                  }
+            errormessage = System.Label.Error_Message01;
+            return null;
+        }
+
+        Map<String, PricebookEntry> tempMap = new Map<String, PricebookEntry>();
+
+        for (PricebookEntry pbe:pbes) {
+            tempMap.put(pbe.Id, pbe);
+        }
+        system.debug('<---is_hidden_all---05>' + is_hidden_all);
+        is_hidden_all = false;
+        for (QELine t:activities) {
+            PricebookEntry tmpPbe = tempMap.get(t.pageObject.PricebookEntryId);
+            if (tmpPbe != null) {
+                if (tmpPbe.SalesPrice__c != null && tmpPbe.Product2.ProductStatus__c == '1' && ( specialDealer == false && is_hidden_user == false && (is_dealer_user == false || tmpPbe.Hidden_flag__c == false))) {
+                //20191113-XHL---灏嗕骇鍝佺姸鎬佺敤浜у搧鐘舵��(鍏紡)鏇挎崲
+                //if (tmpPbe.SalesPrice__c != null && tmpPbe.Product2.ProductStatusFormula__c == '1' && (is_hidden_user == false && (is_dealer_user == false || tmpPbe.Hidden_flag__c == false))) {
+                    t.pageObject.UnitPrice = tmpPbe.SalesPrice__c;
+                    t.salesPrice = tmpPbe.SalesPrice__c;
+                    t.salesPriceA = tmpPbe.SalesPriceA__c;
+                    t.salesPriceB = tmpPbe.SalesPriceB__c;
+                    t.salesPriceC = tmpPbe.SalesPriceC__c;
+                } else if (tmpPbe.SalesPrice__c != null && tmpPbe.Product2.ProductStatus__c == '0' && ( specialDealer == false && is_hidden_user == false && (is_dealer_user == false || tmpPbe.Hidden_flag__c == false))) {
+                //20191113-XHL---灏嗕骇鍝佺姸鎬佺敤浜у搧鐘舵��(鍏紡)鏇挎崲
+                //} else if (tmpPbe.SalesPrice__c != null && tmpPbe.Product2.ProductStatusFormula__c == '0' && (is_hidden_user == false && (is_dealer_user == false || tmpPbe.Hidden_flag__c == false))) {
+                    t.pageObject.UnitPrice = 0;
+                    t.salesPrice = 0;
+                    t.salesPriceA = 0;
+                    t.salesPriceB = 0;
+                    t.salesPriceC = 0;
+                } else {
+                    t.pageObject.UnitPrice = 0;
+                    t.salesPrice = 0;
+                    t.salesPriceA = 0;
+                    t.salesPriceB = 0;
+                    t.salesPriceC = 0;
+
+                    is_hidden_all = true;
+                    discount = 0;
                 }
-              }
             }
-            if (inerr > 0) {
-              errorMessagechack = '璇锋鏌ョ孩瀛楀唴瀹癸紙NMPA鐘舵�佺孩瀛楋紝涓嶅彲閿�鍞骇鍝侊紱浜у搧鍚嶇О绾㈠瓧锛岃秴杩囩粡閿�鍟嗙粡钀ヨ寖鍥达級銆�';
-            }
-          }
-          //闃胯タ璧涘 鏄惁鍗遍櫓鍖栧鍝佺粡钀ヨ鍙瘉 淇濆瓨鎻愮ず鍙互淇濆瓨 decide鎻愮ず涓嶅彲decide 绮剧悽鎶�鏈� wql 2020/12/30 start
-
-          //璇环鏄樋瑗胯禌澶� 鍒ゆ柇鏍囪瘑
-          Boolean isDangerError = false;
-          //璇环涓嶆槸闃胯タ璧涘 鍒ゆ柇鏍囪瘑
-          Boolean isNotDangerError = false;
-
-          //鏉′欢鏄� 鍐呰锤 && 缁忛攢鍟�  && 鏄惁鏄樋瑗胯禌澶� 涓簍rue
-          //娌℃湁鍚堝苟鍦ㄤ笂闈㈢殑for寰幆鐨勫師鍥犳槸锛屾�曟湁鍐茬獊灏嗘爣璇嗙疆涓篺alse
-          if (activities.size() > 0) {
-            for (QELine qli : activities) {
-              if (qli.Asset_Model != null && qli.Asset_Model != '') {
-                  //闃胯タ璧涘 椤甸潰鎻愮ず鎶ラ敊淇℃伅 2020/12/30 start
-                  //濡傛灉璇环鏄樋瑗胯禌澶� 鍒欓�夋嫨涓�鑸骇鍝佺殑鏍囩孩
-                  system.debug('鏄惁闃胯タ璧涘璇环');
-                  system.debug(opp.Is_Corrosion__c);
-                  if (opp.Is_Corrosion__c) {
-                      //涓嶆槸鍗卞寲鍝�
-                      if(!qli.Is_DangerousChemicals){
-                        //鎻愮ず鎶ラ敊
-                        isNotDangerError =true;
-                        //鍚嶇О鎶ョ孩
-                        qli.wrong_Register = true;
-
-                      }
-
-                  }else{
-                    //濡傛灉璇环涓嶆槸闃胯タ璧涘锛屽垯閫夋嫨鍗卞寲鍝佺殑鏍囩孩
-                    if(qli.Is_DangerousChemicals){
-                        //鎻愮ず鎶ラ敊
-                        isDangerError =true;
-                        //鍚嶇О鎶ョ孩
-                        qli.wrong_Register = true;
-                    }
-                  }
-                  //闃胯タ璧涘 椤甸潰鎻愮ず鎶ラ敊淇℃伅 wql 2020/12/30 end
-                
-              }
-              
-              
-            }
-          }
-
-          
-          if (opp.Is_Corrosion__c) {
-            String str = OpportunityWebService.checkDangerItem(opp.agency1__c);
-            if (str != 'OK') {
-              ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,  str));
-            } 
-            system.debug('涓嶆槸鍗卞寲鍝佹爣璇嗭細'+isNotDangerError);
-              //浠h〃琛岄」鐩湁涓嶆槸鍗卞寲鍝佺殑
-              if(isNotDangerError){
-                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,  '褰撻樋瑗垮澶氭椂锛岃椤圭洰鐨勪骇鍝佸繀椤诲叏閫夋嫨鍗卞寲鍝併��'));
-                errorflg = true;
-                errormessage = '褰撻樋瑗垮澶氭椂锛岃椤圭洰鐨勪骇鍝佸繀椤诲叏閫夋嫨鍗卞寲鍝併��';
-                return null;
-              }
-              
-            
-          }else{
-        
-            system.debug('鍗卞寲鍝佹爣璇嗭細'+isDangerError);
-              //浠h〃琛岄」鐩湁鍗卞寲鍝�
-              if(isDangerError){
-                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,  '褰撹浠蜂笉鏄樋瑗垮澶氭椂锛岃椤圭洰鐨勪骇鍝佷笉鑳介�夋嫨鍗卞寲鍝併��'));
-                errorflg = true;
-                errormessage = '褰撹浠蜂笉鏄樋瑗垮澶氭椂锛岃椤圭洰鐨勪骇鍝佷笉鑳介�夋嫨鍗卞寲鍝併��';
-                return null;
-              }
-          }
-          system.debug('闃胯タ璧涘~~~~~end');
-          //闃胯タ璧涘 鏄惁鍗遍櫓鍖栧鍝佺粡钀ヨ鍙瘉 淇濆瓨鎻愮ず鍙互淇濆瓨 decide鎻愮ず涓嶅彲decide 绮剧悽鎶�鏈� wql 2020/12/30 end
-
         }
-        // LHJ End
 
-        System.debug('pageCheck finished at: ' + System.currentTimeMillis());
-
-        PageReference pageRef = new PageReference('/' + oppid);
-        if (dataEntry() == false) {
-          //msg
-          return null;
-        } else {
-          System.debug('data save finished at: ' + System.currentTimeMillis());
-          //msg
-          errorflg = true;
-          errorMessage = System.Label.Message_002;
-          return null;
-        }
-      } catch (DmlException de) {
-        Database.rollback(sp);
-        errorflg = true;
-        errormessage = de.getDmlMessage(0);           // 锛戜欢鐩伄銈ㄣ儵銉笺伄銇胯〃绀�
-        system.debug(Logginglevel.ERROR, de.getMessage());
-        system.debug(Logginglevel.ERROR, de.getStackTraceString());
-      } catch (Exception e) {
-        Database.rollback(sp);
-        errorflg = true;
-        errormessage = e.getMessage();
-        system.debug(Logginglevel.ERROR, e.getMessage());
-        system.debug(Logginglevel.ERROR, e.getStackTraceString());
-      }
-      
-    // }
-    // else{
-    //   errorflg = true;
-    //   errormessage = '璇ヨ浠峰凡缁廳ecide锛屼笉鍙啀淇敼';
-    //   return null;
-    // }
-
-    return null;
-  }
-
-  //OppReflection button
-  public PageReference OppReflection() {
-    //opp銇敾闈€伄鍊ゃ倰瑷畾
-    setOppFromOppInfo();
-    Savepoint sp = Database.setSavepoint();
-    try {
-      errorflg = false;
-      errormessage = null;
-
-      // CHAN-AVG3PW 璇环鎶ヤ环鐢婚潰瑙勫垯鍙樻洿
-      // 鎶ヤ环鍒涘缓鏃ヨ秴杩囦笁涓湀鏃讹紝鐐逛繚瀛樻椂寮哄埗鏇存柊
-      // CHAN-AZG864 涓嶇鍦ㄤ笉鍦ㄦ姤浠锋湁鏁堟湡鍐咃紝CFDA涓嶅彲閿�鍞殑鏃跺�欙紝閮芥槸鎶ラ敊鐨勶紝鍏朵腑涓嶅彲閿�鍞骇鍝佹樉绀虹孩瀛楋紝涓嶅簲璇ヤ繚瀛樸��
-
-      if (WinOrDecideAlert && (!productStatusUpdated)) {
-        errorflg = true;
-        errorMessage = '浜у搧鐘舵�佸彂鐢熷彉鍖栵紝璇锋洿鏂�';
         return null;
-      }
-      if (checkSFDAStatus1(false) == false) {
-        errorflg = true;
-        errormessage = '璇锋洿鏂颁笉鍙攢鍞殑浜у搧銆�';
-        return null;
-      }
-
-      //銉囥兗銈裤儊銈с儍銈�
-      if (dataCheck() == false) {
-        return null;
-      }
-
-      PageReference pageRef = new PageReference('/' + oppid);
-      if (dataEntry() == false) {
-        //msg
-        return null;
-      } else {
-        //msg
-        return pageRef;
-      }
-    } catch (DmlException de) {
-      Database.rollback(sp);
-      errorflg = true;
-      errormessage = de.getDmlMessage(0);           // 锛戜欢鐩伄銈ㄣ儵銉笺伄銇胯〃绀�
-      system.debug(Logginglevel.ERROR, de.getMessage());
-      system.debug(Logginglevel.ERROR, de.getStackTraceString());
-    } catch (Exception e) {
-      Database.rollback(sp);
-      errorflg = true;
-      errormessage = e.getMessage();
-      system.debug(Logginglevel.ERROR, e.getMessage());
-      system.debug(Logginglevel.ERROR, e.getStackTraceString());
     }
 
-    return null;
-  }
+    //excelImport
+    public PageReference excelImport() {
+/*        system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼媁elcome to excelImport!!');
+        system.debug('鈻尖柤鈻尖柤鈻糴xcel_text:' + excel_text);
+        //opp銇敾闈€伄鍊ゃ倰瑷畾
+        setOppFromOppInfo();
 
-  //QuoteDecisionButton
-  public PageReference QuoteDecision() {
-    system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼媁elcome to QuoteDecision!!');
-    Savepoint sp = Database.setSavepoint();
-    try {
-      //opp銇敾闈€伄鍊ゃ倰瑷畾
-      setOppFromOppInfo();
-      if (WinOrDecideAlert && (!productStatusUpdated)) {
-        errorflg = true;
-        errorMessage = '浜у搧鐘舵�佸彂鐢熷彉鍖栵紝璇锋洿鏂�';
-        return null;
-      }
+        errorflg = false;
+        errormessage = null;
 
-      errorflg = false;
-      errormessage = null;
-      //20220214 fy lastbuy start 
-      if(!ReservedProductVerification()){
-        errorflg = true;
-        errormessage =  '浜у搧鏁伴噺涓嶅彲瓒呰繃浜у搧棰勭暀鏁伴噺' ;
-        return null;
-      }
-      //20220214 fy lastbuy end
-      // 2022-01-12 ssm 鎶ヤ环璁$畻check
-      if (checkIsQuoteTrial()) {
-        errorflg = true;
-        return null;
-      }
-
-      if (enableSales == true) {
-        //璨╁2搴楃姸鎱嬨儊銈с儍銈�
-        if (dataCheckDecide() == false) {
-          return null;
-        }
-      }
-      system.debug('zzzzzzzz2:');
-      // CHAN-AVG3PW 璇环鎶ヤ环鐢婚潰瑙勫垯鍙樻洿
-      if (checkSFDAStatus2(true) == false) {
-        errorflg = true;
-        errormessage = '璇锋洿鏂颁笉鍙攢鍞殑浜у搧銆�';
-        return null;
-      }
-
-      PageReference pageRef = new PageReference('/' + oppid);
-      if (dataCheck() == false) {
-        return null;
-      }
-
-      if (dataEntry() == false) {
-        return null;
-      } else {
-        //寮曞悎銇绌嶆焙瀹氥倰銈兂
-        if (oppId == null) {
-          system.debug('Error is Opportunityid null!!!');
-        } else {
-          List<Opportunity> opps = [Select Id, Estimation_Decision__c From Opportunity Where Id = : oppId];
-          if (opps.size() > 0) {
-            opps[0].Estimation_Decision__c = true;
-            /*鈫撯啌鈫撹绌嶅悓鏈熲啌鈫撯啌2012/11/28 鏈娇鐢�
-            opps[0].SyncedQuoteId = quoId;
-            鈫戔啈鈫戙��銆�銆�銆�鈫戔啈鈫�*/
-            ControllerUtil.updOpp(opps[0]);
-          }
-
-          errorflg = true;
-          errorMessage = System.Label.Message_002;
-
-          // cic 134906 start
-          Quote q = [select Id from Quote where Id = :quoId];
-          q.Quote_Decision_Date__c = date.Today();
-          update q;
-          // cic 134906 end
-
-          QuoteDecision = true;
-          enableContract = true;
-          //--Savebutton
-          Save_button = true;
-          //--Decisionbutton鍒ゅ畾
-          if (verified == true) {
-            Decision_button = false;
-          } else if (QuoteCorrect == false) {
-            Decision_button = true;
-          } else if (QuoteDecision == true) {
-            Decision_button = true;
-          } else {
-            Decision_button = false;
-          }
-          //--SAPButton
-          if (QuoteDecision == false) {
-            sap_button = true;
-          } else if (specialAuthority == false) {
-            sap_button = true;
-          } else {
-            sap_button = false;
-          }
-          //--姹哄畾銉溿偪銉充娇銇堛仾銇勩倛銇嗐伀銇欍倠
-          Decision_button = true;
-
-          pageArrange();
-        }
-      }
-    } catch (DmlException de) {
-      Database.rollback(sp);
-      errorflg = true;
-      errormessage = de.getDmlMessage(0);           // 锛戜欢鐩伄銈ㄣ儵銉笺伄銇胯〃绀�
-      system.debug(Logginglevel.ERROR, de.getMessage());
-      system.debug(Logginglevel.ERROR, de.getStackTraceString());
-    } catch (Exception e) {
-      Database.rollback(sp);
-      errorflg = true;
-      errormessage = e.getMessage();
-      system.debug(Logginglevel.ERROR, e.getMessage());
-      system.debug(Logginglevel.ERROR, e.getStackTraceString());
-    }
-
-    //return pageRef;
-    return null;
-  }
-
-  //PrintButton
-  public PageReference Print() {
-    Savepoint sp = Database.setSavepoint();
-    try {
-      //opp銇敾闈€伄鍊ゃ倰瑷畾
-      setOppFromOppInfo();
-
-      errorflg = false;
-      errormessage = null;
-
-      system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼媁elcome to Print!!');
-      PageReference pageRef;
-
-      //Decide鍓峯r寰�
-      if (QuoteDecision == true) {
-        //NoSave
-      } else {
-        // CHAN-AVG3PW 璇环鎶ヤ环鐢婚潰瑙勫垯鍙樻洿
-        // 鎶ヤ环鍒涘缓鏃ヨ秴杩囦笁涓湀鏃讹紝鐐逛繚瀛樻椂寮哄埗鏇存柊
-        // CHAN-AZG864 涓嶇鍦ㄤ笉鍦ㄦ姤浠锋湁鏁堟湡鍐咃紝CFDA涓嶅彲閿�鍞殑鏃跺�欙紝閮芥槸鎶ラ敊鐨勶紝鍏朵腑涓嶅彲閿�鍞骇鍝佹樉绀虹孩瀛楋紝涓嶅簲璇ヤ繚瀛樸��
-        if (WinOrDecideAlert && (!productStatusUpdated)) {
-          errorflg = true;
-          errorMessage = '浜у搧鐘舵�佸彂鐢熷彉鍖栵紝璇锋洿鏂�';
-          return null;
-        }
-
-
-        //銉囥兗銈裤儊銈с儍銈�
-        if (dataCheck() == false ) {
-          return null;
-        }
-
-        if (dataEntry() == false) {
-          //msg
-          return null;
-        }
-      }
-
-      //寮曞悎銇绌嶆彁鍑烘棩銈掍繚瀛�
-      List<Opportunity> opps = New List<Opportunity>();
-      if (oppId == null) {
-      } else {
-          // 鎵撳嵃鏃讹紝涓嶅啀鏇存柊鍐冲畾鎶ヤ环
-        opps = [Select Id
-                //, Estimation_Decision__c
-                From Opportunity Where Id = : oppId];
-        if (opps.size() > 0) {
-          //瑕嬬銇绌嶅嵃鍒锋棩銈掍繚瀛�
-          List<Quote> quos = New List<Quote>();
-          if (quoId == null) {
-            //鍗板埛銇曘仜銇亜锛�
-          } else {
-              // 鎵撳嵃鏃讹紝涓嶅啀鏇存柊鍐冲畾鎶ヤ环
-            quos = [Select Id, 
-                    //Quote_Decision__c, 
-                    Quote_Print_Date__c, Quote_Date__c From Quote Where Id = : quoId];
-            if (quos.size() > 0) {
-              //浼樻儬鎴愪氦浠�
-              quos[0].Preferential_Trading_Price__c = quo.Preferential_Trading_Price__c;
-              //浼樻儬鎶樻墸
-              quos[0].Discount__c = quo.Discount__c;
-              //浼樻儬浠锋牸
-              quos[0].Pricing__c = quo.Pricing__c;
-              //鍗曚环
-              quos[0].Unit_Price__c = quo.Unit_Price__c;
-              //鎶ヤ环閲戦
-              quos[0].Offer_Amount__c = quo.Offer_Amount__c;
-              //Total
-              quos[0].TOTAL__c = quo.TOTAL__c;
-              //濂戠磩鍐呭
-              quos[0].Contract__c = quo.Contract__c;
-              //澶氬勾淇濅慨 start
-              quos[0].Preferential_Gurantee_Period__c = quo.Preferential_Gurantee_Period__c;
-              //澶氬勾淇濅慨 end
-              if (quos[0].Quote_Date__c == null) {
-                quos[0].Quote_Date__c = date.Today();
-                opps[0].Estimation_Proposal_Date__c = date.Today();
-                ControllerUtil.updOpp(opps[0]);
-              }
-              quos[0].Quote_Print_Date__c = date.Today();
-              ControllerUtil.updQuote(quos[0]);
-            }
-          }
-        }
-      }
-      pageArrange();
-    } catch (DmlException de) {
-      Database.rollback(sp);
-      errorflg = true;
-      errormessage = de.getDmlMessage(0);           // 锛戜欢鐩伄銈ㄣ儵銉笺伄銇胯〃绀�
-      system.debug(Logginglevel.ERROR, de.getMessage());
-      system.debug(Logginglevel.ERROR, de.getStackTraceString());
-    } catch (Exception e) {
-      Database.rollback(sp);
-      errorflg = true;
-      errormessage = e.getMessage();
-      system.debug(Logginglevel.ERROR, e.getMessage());
-      system.debug(Logginglevel.ERROR, e.getStackTraceString());
-    }
-
-    return null;
-
-  }
-
-  //BackButton
-  public PageReference Back() {
-    return new Pagereference('/' + oppid);
-  }
-  public PageReference Jump() {
-    System.debug('鎶ヤ环id1锛�'+quoId);
-    //SWAG-C9JCS8 銆愬鎵樸�戙�愮揣鎬ャ�戣浠稧Z-SP-GD0757135鎶ヤ环鍗曢棶棰� fy start
-    Boolean isDecide = checkIsDecide();
-    System.debug('璇环锛�' + oppid + '|鏄惁decide: ' + isDecide);
-    //SWAG-C9JCS8 銆愬鎵樸�戙�愮揣鎬ャ�戣浠稧Z-SP-GD0757135鎶ヤ环鍗曢棶棰� fy end
-    // LHJ 鎺堟潈check Start
-    if (opp.If_Need_Authorize__c == true) {
-      ID tmpid = opp.Agency2__c == null ? opp.Agency1__c : opp.Agency2__c;
-      List<Account> accName = [select name from Account where id = : tmpid];
-      //鎺堟潈鍓嶅厑璁歌繘琛屾姤浠疯瘯绠�  绮剧悽鎶�鏈� thh 2021-09-30 
-      // if (accName[0].name != opp.Authorized_Finish_Sales__c) {
-      //   ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,  '璇峰厛鎺堟潈鍚庯紝鍐嶈繘琛屾姤浠疯瘯绠椼��'));
-      // }else{
-        //鎶ヤ环璇曠畻鐐瑰嚮鏃讹紝淇濆瓨琛岄」鐩� 绮剧悽鎶�鏈� wql 2021/05/07 start
-        if (!isDecide) {
-          Save();
-        } else {
-          errorflg = true;
-          errorMessage = System.Label.Message_002;
-        }
-        //鎶ヤ环璇曠畻鐐瑰嚮鏃讹紝淇濆瓨琛岄」鐩� 绮剧悽鎶�鏈� wql 2021/05/07  end
-        //鎶ヤ环璇曠畻鐐瑰嚮鏃�,濡傛灉淇濆瓨浜嗕細鐢熸垚鏂扮殑鎶ヤ环,杩涘叆鏂版姤浠风殑鎶ヤ环璇曠畻椤甸潰  绮剧悽鎶�鏈� thh 2021-09-30 start
-        Quote jump = [select id from Quote where Quote_No__c = :quo.Quote_No__c];
-        System.debug('鎶ヤ环id2锛�'+jump.Id);
-        if(errorMessage == System.Label.Message_002){
-          return new Pagereference('/apex/QuoteTrial?Id=' + jump.Id);
-        }
-        return null;
-        //鎶ヤ环璇曠畻鐐瑰嚮鏃�,濡傛灉淇濆瓨浜嗕細鐢熸垚鏂扮殑鎶ヤ环,杩涘叆鏂版姤浠风殑鎶ヤ环璇曠畻椤甸潰  绮剧悽鎶�鏈� thh 2021-09-30 end
-      // }
-    }else{
-      //鎶ヤ环璇曠畻鐐瑰嚮鏃讹紝淇濆瓨琛岄」鐩� 绮剧悽鎶�鏈� wql 2021/05/07 start
-      if (!isDecide) {
-        Save();
-      }
-      //鎶ヤ环璇曠畻鐐瑰嚮鏃讹紝淇濆瓨琛岄」鐩� 绮剧悽鎶�鏈� wql 2021/05/07  end
-      System.debug('鎶ヤ环id2锛�'+quoId);
-      return new Pagereference('/apex/QuoteTrial?Id=' + quoId);
-    }
-    return null;
-  }
-  // 0琛ㄧず 瀵剧瓥
-  private void pageArrange() {
-    if (activities.size() > 0) {
-      for (QELine a : activities) {
-        if ((a.Asset_Model == null) || (a.Asset_Model == '')) {
-          system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆Welcome to pageArrange Asset_Model is 鈻�');
-          a.pageobject.subtotal__c = null;
-          a.ListPrice_Page = null;
-        } else {
-          system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆Welcome to pageArrange Asset_Model=[' + a.Asset_Model + ']');
-        }
-      }
-    }
-    if (quo.OCM_Agent1_Price_Page__c == null) {
-      Salesprofit1 = null;
-      qb.SalesCalculation1 = null;
-    }
-    if (quo.Agent1_Agent2_Price_Page__c == null) {
-      Salesprofit2 = null;
-      qb.SalesCalculation2 = null;
-    }
-  }
-
-  public boolean dataCheck() {
-    //WinOrDecideAlert = false;
-    system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆Welcome to dataCheck class!!鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆');
-    errorflg = false;
-    errormessage = null;
-    Boolean error = false;
-    integer Gcnt = 0;
-    List<String> product2Ids = New List<String>();
-
-    if (activities.size() > 0) {
-      system.debug('save:::'+activities);
-      for (QELine a : activities) {
-        if (String.isBlank(a.PageObject.Id__c) == false) {
-          product2Ids.add(a.PageObject.Id__c);
-        }
-      }
-      Map<String, String> loopMap = new Map<String, String>();
-      if (CheckItem != null) {
-        Gcnt = CheckItem.size();
-        if (CheckItem.size() > 0) {
-          for (QuoteLineItem qli : CheckItem) {
-            loopMap.put(qli.PricebookEntry.Product2Id, qli.SFDA_Status__c);
-          }
-        }
-      }
-      //
-      // 銇撱亾銈掍慨姝c仐銇熴倝銆丯FM007.trigger銈傝纰鸿獚
-      prd2LatestValMap = new Map<Id, Product2>();
-      integer cntPrd2 = 0;
-      for (Product2 prd2 : [Select Id, Estimation_Entry_Possibility__c, SFDA_Status__c, Packing_list_manual__c
-                            From Product2 Where Id IN :product2Ids]) {
-        cntPrd2 = cntPrd2   +   1;
-        if (prd2.Estimation_Entry_Possibility__c != '鈼�') {
-          error = true;
-        }
-        if (prd2.Estimation_Entry_Possibility__c == 'M') {
-
-          error = false;
-        }
-        if (prd2.SFDA_Status__c != loopMap.get(prd2.Id)) {
-          //
-          WinOrDecideAlert    =   true;
-        }
-
-        prd2LatestValMap.put(prd2.Id, prd2);
-      }
-      if (cntPrd2  !=  Gcnt) {
-        WinOrDecideAlert    =   false;
-      }
-
-    }
-
-    if (error == true && WinOrDecideAlert == false) {
-      PageArrange();
-      errorflg = true;
-      errorMessage = System.Label.Error_Message37;
-      return false;
-    }
-
-    if (checkAgentsDeleteFlag() == false) {
-      return false;
-    }
-
-
-    PageArrange();
-    errorflg = false;
-    errorMessage = null;
-    return true;
-  }
-
-  private boolean checkIsQuoteTrial() {
-    Boolean error = false;
-    errorflg = false;
-    errormessage = null;
-    //璇环涓婄殑銆愭槸鍚﹂渶瑕佷环鏍肩敵璇枫�戜负鏄殑鍦哄悎,鎵嶈妫�鏌ュ仛娌″仛杩囨姤浠疯瘯绠� thh 2021-11-03 start
-    if(opp.If_Need_PriceApply__c){
-      //wql 鎶ヤ环璇曠畻 鍒ゆ柇鏄惁杩涜杩囨姤浠疯瘯绠� start
-      if(!quo.IsQuoteTrial__c){
-        //娌℃湁鎶ヤ环璇曠畻杩囪繘鍏�
-        error = true;
-        errormessage =  'decide鎶ヤ环杩樻病杩涜鎶ヤ环璇曠畻锛岃鍏堟姤浠疯瘯绠楋紒' ;   
-      }
-      //wql 鎶ヤ环璇曠畻 鍒ゆ柇鏄惁杩涜杩囨姤浠疯瘯绠� end
-      //wql 鎶ヤ环璇曠畻 妫�绱績閿�鏀跨瓥鏄惁鏈夋晥 start
-      //1.鑾峰彇鎶ヤ环id
-      //2.鏍规嵁鎶ヤ环id 妫�绱㈠嚭鎵�鏈夋姤浠疯瘯绠楄锛屽苟甯﹀嚭姣忎竴琛岋紝閫夋嫨鐨勬斂绛栫殑鏈夋晥鏈�  3涓〃
-      //3.寰幆閬嶅巻 鏄惁鎵�鏈夐�夋嫨鐨勬斂绛栨湁鏁堟湡閮戒负true 鍙湁鏈変竴涓负false 灏辫繑鍥瀟rue 鐩存帴璺冲嚭寰幆
-      //濡傛灉鎶ヤ环id涓嶄负绌虹殑璇�
-      if(quoId !=null){
-        boolean IsActivePsp = true;
-        String errorPsp ='';
-        //鏍规嵁id 妫�绱� 鎵�鏈夌殑璇曠畻琛屼笂闈㈤�夋嫨鏀跨瓥鐨勬湁鏁堟湡
-        List<PromotionSalesProducts__c> promotionSalesProductsList =[select id,PromotionSales__c,QuantityId__c,PromotionSales__r.name,PromotionSales__r.IsPolicyEffective__c,recordTypeName__c from PromotionSalesProducts__c where QuantityId__c=:  quoId];
-        //濡傛灉鏈夋姤浠疯瘯绠楁暟鎹� 璇存槑閫夋嫨浜嗕績閿�鏀跨瓥
-        if(promotionSalesProductsList.size()>0){
-          for(PromotionSalesProducts__c psp :promotionSalesProductsList){
-            if(psp.PromotionSales__r.IsPolicyEffective__c == '鏃犳晥'&&psp.recordTypeName__c!='NormalProduct'){
-                IsActivePsp =false;
-                errorPsp = psp.PromotionSales__r.name;
+        //鏃㈠瓨銉囥兗銈挎暟銇⒑瑾�
+        Integer j = 0;
+        for (QELine s:activities) {
+            if ((s.productName==null) || (s.productName=='')) {
                 break;
             }
-          }
+            j++;
         }
 
-        if(!IsActivePsp){
-          error = true;
-          errormessage =  '鎶ヤ环璇曠畻涓紝閫夋嫨鐨勪績閿�鏀跨瓥:'+errorPsp+',涓嶅湪鏈夋晥鏈熷唴锛岃妫�鏌ワ紒' ;
-        }
-      }
-      //wql 鎶ヤ环璇曠畻 妫�绱績閿�鏀跨瓥鏄惁鏈夋晥 end
-    }
-    //璇环涓婄殑銆愭槸鍚﹂渶瑕佷环鏍肩敵璇枫�戜负鏄殑鍦哄悎,鎵嶈妫�鏌ュ仛娌″仛杩囨姤浠疯瘯绠� thh 2021-11-03 end
-    return error;
-  }
+        //=======Temporary=====
+        tmpactivities = activities;
 
-  private boolean dataCheckDecide() {
-    Boolean error = false;
-    errorflg = false;
-    errormessage = null;
+        //=======Initialize=========
+        activities = new List<QELine>();
+        Integer i = 0;
+        Integer xlscnt = 0;
+        Integer rightcnt = 0; // 鎴愬姛銇椼仧鏁般倰銈偊銉炽儓
 
-    if (checkAgentsDeleteFlag() == false) {
-      return false;
-    }
-    if (WinOrDecideAlert && (!productStatusUpdated)) {
-      //    error = true;
-      //    // CHAN-AVG3PW 璇环鎶ヤ环鐢婚潰瑙勫垯鍙樻洿
-      //    //errorMessage = '浜у搧鐘舵�佸彂鐢熷彉鍖栵紝璇锋洿鏂�';
-      PriceStatusUpdate();
-      //    errorMessage = '浜у搧鐘舵�佸彂鐢熷彉鍖栵紝宸茬粡鏇存柊锛岃纭鍚庡啀娆$偣鍑诲喅瀹氥��';
-    }
-    if (opp.Agency1__c == null) {
-      opp.Agency1__c.addError(System.Label.Error_Message3);
-      error = true;
-      errormessage = System.Label.Error_Message3;
-    }
-    if (quo.OCM_Agent1_Price_Page__c == null || quo.OCM_Agent1_Price_Page__c == 0) {
-      quo.OCM_Agent1_Price__c.addError(System.Label.Error_Message3);
-      error = true;
-      errormessage = System.Label.Error_Message3;
-    }
-    if (opp.Agency2__c == null && quo.Agent1_Agent2_Price_Page__c != null) {
-      opp.Agency2__c.addError(System.Label.Error_Message3);
-      error = true;
-      errormessage = System.Label.Error_Message3;
-    }
-    if (opp.Agency2__c != null && quo.Agent1_Agent2_Price_Page__c == null) {
-      quo.Agent1_Agent2_Price__c.addError(System.Label.Error_Message3);
-      error = true;
-      errormessage = System.Label.Error_Message3;
-    }
+        string[] xlslists = excel_text.split('\n',-1);
+        List<string> xlslist = New list<string>();
+        List<string> codelist = New List<string>();
+        List<Integer> Quantitylist = New List<Integer>();
+        List<string> setlist = New List<string>();
 
-    // LHJ 鎺堟潈check Start
-    if (opp.If_Need_Authorize__c == true) {
-      ID tmpid = opp.Agency2__c == null ? opp.Agency1__c : opp.Agency2__c;
-      System.debug('tmpid==='+tmpid);
-      List<Account> accName = [select name from Account where id = : tmpid];
-      System.debug('accName==='+accName);
-      System.debug('Authorized_Finish_Sales__c==='+opp.Authorized_Finish_Sales__c);
-      if (accName[0].name != opp.Authorized_Finish_Sales__c) {
-        error = true;
-        errormessage =  '缁忛攢鍟嗘湭鎺堟潈鎴栨巿鏉冩湭瀹屾垚锛岃鍏堟巿鏉冦��' ;
-      }
-    }
+        Map<String, Integer> mp = new Map<String, Integer>();
+        string xlscode;
+        Integer xlsQuantity;
+        string xlset;
 
-    if (opp.Trade__c == '鍐呰部') {
-      // //缁忛攢鍟嗕骇鍝佹敞鍐岃瘉鍖归厤
-      Map<Id, String> proMap = new Map<Id, String>();
-      if (activities.size() > 0) {
-        for (QELine qli : activities) {
-          if (qli.Asset_Model != null && qli.Asset_Model != '') {
-            proMap.put(qli.pageObject.Id__c, qli.PageObject.Name__c);
-          }
-        }
-      }
-      //闃胯タ璧涘 鍙栨秷鏌ヨ鍖荤枟鍣ㄦ缁忚惀璁稿彲璇� 绮剧悽鎶�鏈� wql  2021/01/14 start 
-      Map<String, String> chkMap = new Map<String, String>();
-      if(!opp.Is_Corrosion__c){
-        // GZW 鐢婚潰鍑洪敊璇秷鎭�
-        chkMap = OpportunityWebService.MapCheckProRegisterDecide(proMap, opp.Agency1__c, '');
-      }
-      //闃胯タ璧涘 鍙栨秷鏌ヨ鍖荤枟鍣ㄦ缁忚惀璁稿彲璇� 绮剧悽鎶�鏈� wql  2021/01/14 end
-      //this.haveno_Register 娌℃湁娉ㄥ唽璇� 鐘舵�佺孩鑹�
-      //this.wrong_Register  鍖归厤涓嶄笂  鍚嶅瓧绾㈣壊
-      if (chkMap.size() > 0) {
-        errorflg = true;
-        error = true;
-        //errormessage = '璇锋鏌ョ孩瀛楀唴瀹癸紙NMPA鐘舵�佺孩瀛楋紝涓嶅彲閿�鍞骇鍝侊紱浜у搧鍚嶇О绾㈠瓧锛岃秴杩囩粡閿�鍟嗙粡钀ヨ寖鍥达級銆�';
-        if (chkMap.containsKey('agency')) {
-          ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,  '绗竴缁忛攢鍟嗘病鏈夋湁鏁堢殑鍖荤枟鍣ㄦ缁忚惀璁稿彲璇併��'));
-        }
-        Integer inerr = 0;
-        if (activities.size() > 0) {
-          for (QELine s : activities) {
-            if (s.Asset_Model != null && s.Asset_Model != '') {
-              if (chkMap.containsKey(s.PageObject.Id__c)) {
-                if (chkMap.get(s.PageObject.Id__c) == '1') {
-                  s.haveno_Register = true;
-                  inerr ++;
-                } else if (chkMap.get(s.PageObject.Id__c) == '2') {
-                  s.wrong_Register = true;
-                  inerr ++;
-                }
-              }
-            }
-          }
-        }
-        if (inerr > 0) {
-          errormessage = '璇锋鏌ョ孩瀛楀唴瀹癸紙NMPA鐘舵�佺孩瀛楋紝涓嶅彲閿�鍞骇鍝侊紱浜у搧鍚嶇О绾㈠瓧锛岃秴杩囩粡閿�鍟嗙粡钀ヨ寖鍥达級銆�';
-        }
-        return false;
-      }
-      //闃胯タ璧涘 鏄惁鍗遍櫓鍖栧鍝佺粡钀ヨ鍙瘉 淇濆瓨鎻愮ず鍙互淇濆瓨 decide鎻愮ず涓嶅彲decide 绮剧悽鎶�鏈� wql 2020/12/30 start
-
-      //璇环鏄樋瑗胯禌澶� 鍒ゆ柇鏍囪瘑
-      Boolean isDangerError = false;
-      //璇环涓嶆槸闃胯タ璧涘 鍒ゆ柇鏍囪瘑
-      Boolean isNotDangerError = false;
-      
-      //鏉′欢鏄� 鍐呰锤 && 缁忛攢鍟�  && 鏄惁鏄樋瑗胯禌澶� 涓簍rue
-      //娌℃湁鍚堝苟鍦ㄤ笂闈㈢殑for寰幆鐨勫師鍥犳槸锛屾�曟湁鍐茬獊灏嗘爣璇嗙疆涓篺alse
-      if (activities.size() > 0) {
-        for (QELine qli : activities) {
-          if (qli.Asset_Model != null && qli.Asset_Model != '') {
-              //闃胯タ璧涘 椤甸潰鎻愮ず鎶ラ敊淇℃伅 2020/12/30 start
-              //濡傛灉璇环鏄樋瑗胯禌澶� 鍒欓�夋嫨涓�鑸骇鍝佺殑鏍囩孩
-              system.debug('鏄惁闃胯タ璧涘璇环');
-              system.debug(opp.Is_Corrosion__c);
-              if (opp.Is_Corrosion__c) {
-                  //涓嶆槸鍗卞寲鍝�
-                  if(!qli.Is_DangerousChemicals){
-                    //鎻愮ず鎶ラ敊
-                    isNotDangerError =true;
-                    //鍚嶇О鎶ョ孩
-                    qli.wrong_Register = true;
-
-                  }
-
-              }else{
-                //濡傛灉璇环涓嶆槸闃胯タ璧涘锛屽垯閫夋嫨鍗卞寲鍝佺殑鏍囩孩
-                if(qli.Is_DangerousChemicals){
-                    //鎻愮ず鎶ラ敊
-                    isDangerError =true;
-                    //鍚嶇О鎶ョ孩
-                    qli.wrong_Register = true;
-                }
-              }
-              //闃胯タ璧涘 椤甸潰鎻愮ず鎶ラ敊淇℃伅 wql 2020/12/30 end
-            
-          }
-          
-          
-        }
-      }
-      //闃胯タ璧涘 鏄惁鍗遍櫓鍖栧鍝佺粡钀ヨ鍙瘉 淇濆瓨鎻愮ず鍙互淇濆瓨 decide鎻愮ず涓嶅彲decide 绮剧悽鎶�鏈� wql 2020/09/10 start
-      
-      if (enableSales == true&&opp.Is_Corrosion__c&&opp.Trade__c == '鍐呰部') {
-        //鏉′欢鏄� 鍐呰锤  && 缁忛攢鍟�  && 鏄惁鏄樋瑗胯禌澶� 涓簍rue
-        String str = OpportunityWebService.checkDangerItem(opp.agency1__c);
-        if (str != 'OK') {
-          error = true;
-          errormessage = str;
-        }
-
-        //浠h〃琛岄」鐩湁涓嶆槸鍗卞寲鍝佺殑
-        if(isNotDangerError){
-          error = true;
-          errormessage = '褰撻樋瑗垮澶氭椂锛岃椤圭洰鐨勪骇鍝佸繀椤诲叏閫夋嫨鍗卞寲鍝併��';
-        }
-      }else if(!opp.Is_Corrosion__c){
-        //浠h〃琛岄」鐩湁鍗卞寲鍝�
-        if(isDangerError){
-          error = true;
-          errormessage = '褰撹浠蜂笉鏄樋瑗垮澶氭椂锛岃椤圭洰鐨勪骇鍝佷笉鑳介�夋嫨鍗卞寲鍝併��';
-        }
-      }
-      //闃胯タ璧涘 鏄惁鍗遍櫓鍖栧鍝佺粡钀ヨ鍙瘉 淇濆瓨鎻愮ず鍙互淇濆瓨 decide鎻愮ず涓嶅彲decide 绮剧悽鎶�鏈� wql 2020/09/10 end
-
-
-    }
-    // LHJ End
-
-    if (error == true) {
-      PageArrange();
-      errorflg = true;
-      return false;
-    } else {
-      return true;
-    }
-  }
-
-  private Boolean checkAgentsDeleteFlag() {
-    // Check Agents
-    List<Id> accIds = new List<Id>();
-    if (opp.Agency1__c != null) {
-      accIds.add(opp.Agency1__c);
-    }
-    if (opp.Agency2__c != null) {
-      accIds.add(opp.Agency2__c);
-    }
-    if (accIds.size() > 0) {
-      List<Account> agentAccs = [SELECT Id, Delete_Flag__c, Is_Active_Formula__c, Sales_Shop_Class__c FROM Account WHERE Id IN :accIds];
-      //Boolean deleteFlag1 = false, deleteFlag2 = false;
-      String activeFormula1 = null, activeFormula2 = null;
-      for (Account local : agentAccs) {
-        if (local.Sales_Shop_Class__c == '鍖荤枟淇悊缁忛攢鍟�') {
-          PageArrange();
-          errorflg = true;
-          //-------CHAN-B9TBG4; 20190301----------UpdateStart----------------------------------------
-          if (local.Id == opp.Agency1__c) {
-            errorMessage = '璇风‘璁ょ涓�缁忛攢鍟嗙殑缁忛攢鍟嗚祫璐�';
-            return false;
-          }
-          //else {
-          //    errorMessage = '璇风‘璁ょ浜岀粡閿�鍟嗙殑缁忛攢鍟嗚祫璐�';
-          //}
-          //return false;
-          //-------CHAN-B9TBG4; 20190301----------UpdateStop----------------------------------------
-        }
-
-        if (local.Id == opp.Agency1__c) {
-          activeFormula1 = local.Is_Active_Formula__c;
-        }
-      }
-      for (Account local : agentAccs) {
-        if (local.Id == opp.Agency2__c) {
-          activeFormula2 = local.Is_Active_Formula__c;
-        }
-      }
-
-      if (activeFormula1 == '鏃犳晥' && activeFormula2 == '鏃犳晥') {
-        PageArrange();
-        errorflg = true;
-        errorMessage = System.Label.Agent1_and_Agent2_were_Deleted;
-        return false;
-      } else if (activeFormula1 == '鏃犳晥') {
-        PageArrange();
-        errorflg = true;
-        errorMessage = System.Label.Agent1_was_Deleted;
-        return false;
-      } else if (activeFormula2 == '鏃犳晥') {
-        PageArrange();
-        errorflg = true;
-        errorMessage = System.Label.Agent2_was_Deleted;
-        return false;
-      }
-    }
-
-    // 鍐呰部銇牬鍚圕heck Agency1
-    if (opp.Agency1__c != null && opp.Trade__c == '鍐呰部') {
-      Account acc = [select Sales_Shop_Class__c, Business_Authorization_No__c, Business_Paper_Expiration_Date__c,
-                     Tax_Practice_No__c, Tax_Practice_Expiration_Date__c, Medical_Equipment_Num__c, Is_Active_Formula__c,
-                     Medical_Equipment_Expiration_Date__c from Account where Id = :opp.Agency1__c];
-      //缁忛攢鍟嗗垎绫诲彧鏈夌壒绾︺�佷竴绾ф垨鑰呴泦涓噰璐墠鍙互杩涜鎶ヤ环
-      List<String> salesClazz = new List<String> {'鐗圭磩璨╁2搴楋紙鍖哄煙锛�', '鐗圭磩璨╁2搴楋紙瑁藉搧锛�', '鐗圭磩璨╁2搴楋紙瑁藉搧+鍖哄煙锛�', '涓�绱氳博澹插簵', '闆嗛噰缁忛攢鍟�'};
-      // 鏈夋晥/鏃犳晥锛堝叕寮忥級!= 鏈夋晥
-      if (acc.Is_Active_Formula__c != '鏈夋晥') {
-        PageArrange();
-        errorflg = true;
-        errorMessage = '璇烽�夋嫨鏈夋晥鐨勭粡閿�鍟�';
-        return false;
-      }
-      // 缁忛攢鍟嗗垎绫� 鏄� 浜岀骇 鎴� 鍏朵粬
-      //else if (acc.Sales_Shop_Class__c == '浜岀礆璨╁2搴�' || acc.Sales_Shop_Class__c == '銇濄伄浠�') {
-      //CHAN-BQE6LA  銆愬鎵樸�戙�愰噸瑕併�戣浠风粡閿�鍟�1鍒ゆ柇閫昏緫 绮剧悽鎶�鏈� wql 2020/06/10 start
-      //娉ㄩ噴鍘熸潵閫昏緫
-      // else if (acc.Sales_Shop_Class__c == '浜岀礆璨╁2搴�') {
-      //   PageArrange();
-      //   errorflg = true;
-      //   errorMessage = '璇风‘璁ょ涓�缁忛攢鍟嗙殑缁忛攢鍟嗚祫璐�';
-      //   return false;
-      // }
-      else if(!salesClazz.contains(acc.Sales_Shop_Class__c)){
-        PageArrange();
-        errorflg = true;
-        errorMessage = '缁忛攢鍟�1鐨勭粡閿�鍟嗗垎绫讳负锛氱壒绾︼紝涓�绾э紝闆嗕腑閲囪喘鎵嶅彲浠ユ姤浠�';
-        return false;
-      }
-      //CHAN-BQE6LA  銆愬鎵樸�戙�愰噸瑕併�戣浠风粡閿�鍟�1鍒ゆ柇閫昏緫 绮剧悽鎶�鏈� wql 2020/06/10 end
-      // 钀ヤ笟鎵х収鏈夋晥鏈熼檺鈥� 鎴栤�滅◣鍔$櫥璁拌瘉鏈夋晥鏈熼檺鈥� 鎴栤�滃尰鐤楀櫒姊扮粡钀ヤ紒涓氳鍙瘉鏈夋晥鏈熼檺鈥� 鍏朵腑涓�涓瘉瓒呰繃鏈夋晥鏈熺殑璇�
-      //鍘绘帀钀ヤ笟璁稿彲璇佺殑妫�鏌� 鍥犱负闃胯タ璧涘涓嶇敤妫�鏌� 涓�鑸骇鍝佷笂闈㈡鏌ヨ繃  绮剧悽鎶�鏈� wql 2021/01/15 start
-      //&& String.isBlank(acc.Medical_Equipment_Num__c) == false
-      //       && acc.Medical_Equipment_Expiration_Date__c != null && acc.Medical_Equipment_Expiration_Date__c >= Date.today()
-      else if (!
-               // 婊¤冻濡備笅鍏釜瀛楁鏉′欢涓烘湁鏁堬紝鍚﹀垯鏃犳晥
-               (String.isBlank(acc.Tax_Practice_No__c) == false
-                && (acc.Tax_Practice_Expiration_Date__c == null || acc.Tax_Practice_Expiration_Date__c >= Date.today())
-                
-                && String.isBlank(acc.Business_Authorization_No__c) == false
-                && acc.Business_Paper_Expiration_Date__c != null && acc.Business_Paper_Expiration_Date__c >= Date.today())
-              ) {
-        PageArrange();
-        errorflg = true;
-        errorMessage = '璇风‘璁ょ涓�缁忛攢鍟嗙殑缁忛攢鍟嗚祫璐�';
-        return false;
-      } 
-      //鍘绘帀钀ヤ笟璁稿彲璇佺殑妫�鏌� 鍥犱负闃胯タ璧涘涓嶇敤妫�鏌� 涓�鑸骇鍝佷笂闈㈡鏌ヨ繃  绮剧悽鎶�鏈� wql 2021/01/15 end
-      else {}
-      /*
-      if (acc.Sales_Shop_Class__c == '浜岀礆璨╁2搴�' || acc.Sales_Shop_Class__c == '銇濄伄浠�') {
-          if (!
-              (!String.isBlank(acc.Tax_Practice_No__c)
-                  && (acc.Tax_Practice_Expiration_Date__c == null || acc.Tax_Practice_Expiration_Date__c >= Date.today())
-                  && !String.isBlank(acc.Medical_Equipment_Num__c)
-                  && (acc.Medical_Equipment_Expiration_Date__c != null && acc.Medical_Equipment_Expiration_Date__c >= Date.today())
-                  && !String.isBlank(acc.Business_Authorization_No__c)
-                  && (acc.Business_Paper_Expiration_Date__c != null && acc.Business_Paper_Expiration_Date__c >= Date.today()))) {
-              PageArrange();
-              errorflg = true;
-              errorMessage = '璇风‘璁ょ涓�缁忛攢鍟嗙殑缁忛攢鍟嗚祫璐�';
-              return false;
-          }
-      }
-      */
-    }
-
-    return true;
-  }
-
-  // CHAN-AVG3PW 璇环鎶ヤ环鐢婚潰瑙勫垯鍙樻洿
-  // 鎶ヤ环鍒涘缓鏃ヨ秴杩囦笁涓湀鏃讹紝濡備骇鍝佸仠浜ф垨CFDA澶辨晥锛屼笉鍙互淇濆瓨锛屾彁绀衡�滆鏇存柊鍋滄閿�鍞殑浜у搧鈥�
-  //             鍋欴ECIDE鏃讹紝濡備骇鍝佸仠浜ф垨CFDA澶辨晥锛屼笉鍙互淇濆瓨锛屾彁绀衡�滆鏇存柊鍋滄閿�鍞殑浜у搧鈥�
-  private boolean checkSFDAStatus2(boolean dodecide) {
-    // CHAN-AZG864 涓嶇鍦ㄤ笉鍦ㄦ姤浠锋湁鏁堟湡鍐咃紝CFDA涓嶅彲閿�鍞殑鏃跺�欙紝閮芥槸鎶ラ敊鐨勶紝鍏朵腑涓嶅彲閿�鍞骇鍝佹樉绀虹孩瀛楋紝涓嶅簲璇ヤ繚瀛樸��
-    //if (over3month == false && dodecide == false) {
-    //    return true;
-    //}
-
-    for (QELine a : activities) {
-      if ((a.Asset_Model != null) && (a.Asset_Model != '')) {
-        system.debug('zzzzzzzz1:'+a.PageObject.SFDA_Status__c);
-        if (a.PageObject.SFDA_Status__c != '鏈夊姽' &&
-            a.PageObject.SFDA_Status__c != '鏈夊姽锛堝啀鐢宠珛涓級' &&
-            a.PageObject.SFDA_Status__c != '涓嶈' &&
-            // LHJ 20181221 CBPR Start
-            a.PageObject.SFDA_Status__c != '鏆傚仠鍑哄簱锛堢煭鏈燂級' &&
-            // LHJ 20181221 CBPR End
-            a.PageObject.SFDA_Status__c != '澶卞姽锛堟湡闄愬唴鐢熺敚娓堝湪搴蹇滐級'
-            /*&&
-            (a.PageObject.SFDA_Status__c != '澶卞姽锛堝啀鐢宠珛涓級' || dodecide != false)*/
-           ) {
-          return false;
-        }
-      }
-    }
-    return true;
-  }
-
-  private boolean checkSFDAStatus1(boolean dodecide) {
-    // CHAN-AZG864 涓嶇鍦ㄤ笉鍦ㄦ姤浠锋湁鏁堟湡鍐咃紝CFDA涓嶅彲閿�鍞殑鏃跺�欙紝閮芥槸鎶ラ敊鐨勶紝鍏朵腑涓嶅彲閿�鍞骇鍝佹樉绀虹孩瀛楋紝涓嶅簲璇ヤ繚瀛樸��
-    //if (over3month == false && dodecide == false) {
-    //    return true;
-    //}
-    for (QELine a : activities) {
-      if ((a.Asset_Model != null) && (a.Asset_Model != '')) {
-        if (a.PageObject.SFDA_Status__c != '鏈夊姽' &&
-            a.PageObject.SFDA_Status__c != '鏈夊姽锛堝啀鐢宠珛涓級' &&
-            a.PageObject.SFDA_Status__c != '涓嶈' &&
-            a.PageObject.SFDA_Status__c != '澶卞姽锛堟湡闄愬唴鐢熺敚娓堝湪搴蹇滐級' &&
-            // LHJ CBPR 20181221 Start
-            (a.PageObject.SFDA_Status__c != '鏆傚仠鍑哄簱锛堥暱鏈燂級') &&
-            (a.PageObject.SFDA_Status__c != '鏆傚仠鍑哄簱锛堢煭鏈燂級') &&
-            // LHJ CBPR 20181221 End
-            (a.PageObject.SFDA_Status__c != '澶卞姽锛堝啀鐢宠珛涓級' || dodecide != false)
-           ) {
-          return false;
-        }
-      }
-    }
-    return true;
-  }
-
-  //SWAG-C9JCS8 銆愬鎵樸�戙�愮揣鎬ャ�戣浠稧Z-SP-GD0757135鎶ヤ环鍗曢棶棰� fy start
-  private boolean checkIsDecide() {
-    List<Opportunity> oppsde = [Select Id, Estimation_Decision__c From Opportunity Where Id = : oppId];
-    if (oppsde.size() > 0) {
-      if(oppsde[0].Estimation_Decision__c){
-        return true;
-      }
-    }
-    return false;
-  }
-  //SWAG-C9JCS8 銆愬鎵樸�戙�愮揣鎬ャ�戣浠稧Z-SP-GD0757135鎶ヤ环鍗曢棶棰� fy end
-
-  public boolean dataEntry() {
-    system.debug('activities++++----****3'+activities);
-    //SWAG-C9JCS8 銆愬鎵樸�戙�愮揣鎬ャ�戣浠稧Z-SP-GD0757135鎶ヤ环鍗曢棶棰� fy start
-    // Boolean ifdecide=false;
-    // List<Opportunity> oppsde = [Select Id, Estimation_Decision__c From Opportunity Where Id = : oppId];
-    // if (oppsde.size() > 0) {
-    //   if(oppsde[0].Estimation_Decision__c){
-    //     ifdecide=true;
-    //   }else{
-    //     ifdecide=false;
-    //   }
-    // }
-    System.debug('start checkIsDecide at: ' + System.currentTimeMillis());
-    Boolean ifdecide=checkIsDecide();
-    System.debug('finished checkIsDecide at: ' + System.currentTimeMillis());
-    if(!ifdecide){
-      //SWAG-C9JCS8 銆愬鎵樸�戙�愮揣鎬ャ�戣浠稧Z-SP-GD0757135鎶ヤ环鍗曢棶棰� fy end
-      system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆Welcome to dataEntry class!!鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆');
-      Boolean error = false;
-      Boolean detail = false;
-      if ((quo.QuoteName__c == null) || (quo.QuoteName__c == '')) {
-        quo.QuoteName__c.addError(System.Label.Error_Message3);
-        error = true;
-        errormessage = System.Label.Error_Message3;
-      }
-      if (quo.Dealer_Final_Price_Page__c == null) {
-        quo.Dealer_Final_Price__c.addError(System.Label.Error_Message3);
-        error = true;
-        errormessage = System.Label.Error_Message3;
-      }
-      if (qb.Quote_Adjust_Calculate == null) {
-        quo.Quote_Adjust_Calculate__c.addError(System.Label.Error_Message3);
-        error = true;
-        errormessage = System.Label.Error_Message3;
-      }
-      if (quo.Quote_Adjust_Amount_Page__c == null) {
-        quo.Quote_Adjust_Amount__c.addError(System.Label.Error_Message3);
-        error = true;
-        errormessage = System.Label.Error_Message3;
-      }
-      if (quo.Quote_Expiration_Date__c == null) {
-        quo.Quote_Expiration_Date__c.addError(System.Label.Error_Message3);
-        error = true;
-        errormessage = System.Label.Error_Message3;
-      }
-      //decimal temSalesAmount1 = 0; // 2018/09/28 CHAN-B4YAB8 缁忛攢鍟嗗皬璁″悎璁� end
-      system.debug('activities++++----****2'+activities);
-      for (QELine a : activities) {
-        if ((a.Asset_Model != null) && (a.Asset_Model != '')) {
-          if (a.PageObject.Quantity__c == null || a.PageObject.Quantity__c == 0) {
-            a.PageObject.Quantity__c.addError(System.Label.Error_Message3);
-            error = true;
-            errormessage = System.Label.Error_Message3;
-          }
-          if (a.PageObject.UnitPrice_Page__c == null) {
-            a.PageObject.UnitPrice__c.addError(System.Label.Error_Message3);
-            error = true;
-            errormessage = System.Label.Error_Message3;
-          }
-          if (a.PageObject.AgencyUnitPrice__c == null) {
-            a.PageObject.AgencyUnitPrice__c.addError(System.Label.Error_Message3);
-            error = true;
-            errormessage = System.Label.Error_Message3;
-          }
-          //temSalesAmount1 = temSalesAmount1 + a.PageObject.AgencySubtotal__c; // 2018/09/29 CHAN-B4YAB8 缁忛攢鍟嗗皬璁$疮鍔�
-          if (a.PageObject.PricebookEntryId == null) {
-            error = true;
-            errormessage = System.Label.Error_Message27;
-          }
-          detail = true;
-        }
-      }
-      if (enableSales == true) {
-        // LHJ Start
-        if (quo.Agency1__c == null) {
-          quo.Agency1__c.addError(System.Label.Error_Message3);
-          error = true;
-          errormessage = System.Label.Error_Message3;
-        }
-        // LHJ End
-        if (quo.OCM_Agent1_Price_Page__c == null) {
-          quo.OCM_Agent1_Price__c.addError(System.Label.Error_Message3);
-          error = true;
-          errormessage = System.Label.Error_Message3;
-        } else {
-
-        }
-      } else {
-
-        if (opp.Agency1__c != null) {
-          opp.Agency1__c.addError(System.Label.Error_Message30);
-          error = true;
-          errormessage = System.Label.Error_Message30;
-        }
-        if (quo.OCM_Agent1_Price_Page__c != null) {
-          quo.OCM_Agent1_Price__c.addError(System.Label.Error_Message30);
-          error = true;
-          errormessage = System.Label.Error_Message30;
-        }
-        if (opp.Agency2__c != null) {
-          opp.Agency2__c.addError(System.Label.Error_Message30);
-          error = true;
-          errormessage = System.Label.Error_Message30;
-        }
-        if (quo.Agent1_Agent2_Price_Page__c != null) {
-          quo.Agent1_Agent2_Price__c.addError(System.Label.Error_Message30);
-          error = true;
-          errormessage = System.Label.Error_Message30;
-        }
-
-      }
-
-      if (DisCalculation >= 1000 || DisCalculation <= -1000) {
-        error = true;
-        errormessage = System.Label.Error_Message38;
-      }
-      if (qb.SalesCalculation1 >= 1000 || qb.SalesCalculation1 <= -1000) {
-        error = true;
-        errormessage = System.Label.Error_Message38;
-      }
-      if (qb.SalesCalculation2 >= 1000 || qb.SalesCalculation2 <= -1000) {
-        error = true;
-        errormessage = System.Label.Error_Message38;
-      }
-
-      if (error == true) {
-        PageArrange();
-
-        errorflg = true;
-        return false;
-      }
-
-      //Quote-------------------------------------------------------------
-      //鍟嗚珖Id銆佷尽鏍艰〃Id
-      //瑕嬬鍚嶇О銆佹婧栧畾渚″悎瑷堛�佽绌嶉噾椤嶅悎瑷�(绌嶄笂)銆佺梾闄€伄濂戠磩閲戦銆佸師渚°��
-      //鍊ゅ紩閲戦瑷堢畻銆佸�ゅ紩銇嶉噾椤嶉噾椤嶃�佽绌嶈鏁撮噾椤嶈▓绠椼�佽绌嶈鏁撮噾椤嶉噾椤�
-      //绗竴璨╁2搴楀悕绉般�侀噾椤嶃�佸埄鐩娿�侊紖銆佺浜岃博澹插簵鍚嶇О銆侀噾椤嶃�佸埄鐩娿�侊紖
-      //浼樻儬鎴愪氦浠枫�佷紭鎯犳姌鎵c�佷紭鎯犱环鏍笺�佸崟浠枫�佹姤浠烽噾棰濄�乀otal
-      //濂戠磩鍐呰ǔ銆佸嵃鍒风梾闄㈠悕绉般�佽绌嶆湁鍔规湡闄愭棩銆佽绌嶈〃瑷樸偝銉°兂銉�
-
-      //寮曞悎鍗樹綅銇绌峃o銇屽繀瑕�
-      List<Quote> maxQuote_No = [select Quote_No__c From Quote Where OpportunityId = :oppid and (not Quote_No__c like '%Old') order by Quote_No_last2__c desc NULLS LAST limit 1];
-      String oppNo;
-      Integer l = 1;
-      if (maxQuote_No.size() > 0) {
         try {
-          oppNo = maxQuote_No[0].Quote_No__c;
-          l = Integer.valueOf(oppNo.substring(oppNo.length() - 2)) + 1;
-        } catch (System.TypeException e) {
-          system.debug('maxQuote_No Error: quote.id=' + maxQuote_No[0].id);
-        }
-      } else {
-        system.debug('first Quote');
-      }
-      oppNo = '00' + String.valueof(l);
-      oppNo = oppNo.substring(oppNo.length() - 2);
+            for (string xls:xlslists) {
+                if (xls==null || xls=='') {
+                    //null
+                } else {
+                    xlscode = null;
+                    xlsQuantity = null;
+                    xlset = null;
+                    xlslist = xls.split('\t',-1);
+                    Integer iCount = 0;
+                    for (String s:xlslist) {
+                        if (iCount== 1) {
+                            if (s=='' || s==null) {
+                                errorflg = true;
+                                errormessage = System.Label.Error_Message02;
+                                activities = tmpactivities;
+                                return null;
+                            } else {
+                                s = s.trim();
+                                xlsQuantity = Integer.valueOf(s);
+                                Quantitylist.add(xlsQuantity);
+                            }
+                        } else if (iCount== 2) {
+                            if (s=='' || s==null) {
+                                errorflg = true;
+                                errormessage = System.Label.Error_Message02;
+                                activities = tmpactivities;
+                                return null;
+                            } else {
+                                s = s.trim();
+                                setlist.add(s);
+                                xlset = s;
+                            }
 
-      Quote q = New Quote();
-      if (changedAfterPrint) {
-        system.debug('id绌�1锛�');
-        quoId = null;
-      }
-      // false浼濈エ銇嬨倝鏂拌浣滄垚
-      if (changedAfterBid) {
-        system.debug('id绌�2锛�');
-        quoId = null;
-      }
-      // CHAN-AVG3PW 璇环鎶ヤ环鐢婚潰瑙勫垯鍙樻洿
-      if (newQuoteFlag) {
-        system.debug('id绌�3锛�');
-        quoId = null;
-      }
-      // 澶氬勾淇濅慨 start
-      //鎶ヤ环璇曠畻 澧炲姞缁忛攢鍟嗗墠鍚庡姣� 绮剧悽鎶�鏈� wql 20210508 start
-      if ((quoteGurantee_Period != null &&
-          !quoteGurantee_Period.equals(quo.Gurantee_Period__c))
-          ||
-          (quotemultiYearWarranty != null &&
-          !quotemultiYearWarranty.equals('' + quo.multiYearWarranty__c))
-          ||
-          (agency1Name !=null &&!agency1Name.equals(quo.Agency1__c))
-          ||
-          (agency2Name !=null &&!agency2Name.equals(quo.Agency2__c))
-        ) {
-        quoId = null;
-      }
-      agency1Name = quo.Agency1__c;
-      agency2Name = quo.Agency2__c;
-      //鎶ヤ环璇曠畻 澧炲姞缁忛攢鍟嗗墠鍚庡姣� 绮剧悽鎶�鏈� wql 20210508 end
-      quoteGurantee_Period = quo.Gurantee_Period__c;
-      quotemultiYearWarranty = '' + quo.multiYearWarranty__c;
-      // 澶氬勾淇濅慨 end
-      if (quoId == null) {
-        q = New Quote();
-        q.OpportunityId = oppId;
-
-        if (detail == true) {
-          if (standardPricebook == null) {
-            errormessage = System.Label.Error_Message27;
+                        } else {
+                            if (s=='' || s==null) {
+                                errorflg = true;
+                                errormessage = System.Label.Error_Message02;
+                                activities = tmpactivities;
+                                return null;
+                            } else {
+                                s = s.trim();
+                                codelist.add(s);
+                                xlscode = s;
+                            }
+                        }
+                        iCount++;
+                        if (iCount == 3) {
+                            iCount = 0;
+                        }
+                    }
+                    //mp.put(xlscode, xlsQuantity);
+                    xlscnt++;
+                }
+            }
+        } catch(Exception ex) {
+            activities = tmpactivities;
             errorflg = true;
-            return false;
-          } else {
-            q.Pricebook2Id = standardPricebook.Id;
-          }
+            errormessage = System.Label.Error_Message02;
+            return null;
         }
 
-      } else {
-        List<Quote> qs = New List<Quote>();
-        qs = [select Id, OpportunityId, CreatedDate, Pricebook2Id, Name, Estimation_List_Price__c, Dealer_Final_Price__c,
-              Stocking_Price__c, Discount_Amount__c, Discount_Amount_Calculate__c, Quote_Adjust_Amount__c, Quote_Adjust_Calculate__c,
-              Agency1__c, OCM_Agent1_Price__c, Agency1_Profit__c, Agency1_Profit_Rate__c, Quote_No__c,
-              Agency2__c, Agent1_Agent2_Price__c, Agency2_Profit__c, Agency2_Profit_Rate__c,
-              Preferential_Trading_Price__c, Discount__c, Pricing__c, Unit_Price__c, Offer_Amount__c, TOTAL__c,
-              Contract__c, Print_HP_Name__c, Quote_Expiration_Date__c, Quote_Comment__c, OCM_Sales_Forecast__c, Installation_location__c, HasType3Machine__c
-              // 澶氬勾淇濅慨 start
-              , Gurantee_Period__c , multiYearWarranty__c, MultiYearWarrantyTotalPrice__c
-              , Preferential_Gurantee_Period__c
-              // 澶氬勾淇濅慨 end
-              //鎶ヤ环璇曠畻 start
-              ,IsQuoteTrial__c 
-              //鎶ヤ环璇曠畻 end
-              From Quote Where Id = :quoId];
-        if (qs.size() > 0) {
-          q = qs[0];
+system.debug('codelist:::::'+codelist.size());
+system.debug('xlscnt:::::' + xlscnt);
+
+        if (codelist.size()==0 || Quantitylist.size()==0 || setlist.size()==0) {
+            activities = tmpactivities;
+            errorflg = true;
+            errormessage = System.Label.Error_Message02;
+            return null;
         }
-        if (q.Pricebook2Id == null) {
-          if (detail == true) {
-            if (standardPricebook == null) {
-              errormessage = System.Label.Error_Message27;
-              errorflg = true;
-              return false;
+
+        xlscnt = j + xlscnt;
+        if (xlscnt>quoteEntryMaxLine) {
+            activities = tmpactivities;
+            errorflg = true;
+            errormessage = System.Label.Error_Message03;
+            return null;
+        }
+
+        i = 0;
+        boolean lineflg = false;
+        for (QELine t:tmpactivities) {
+            if (i==j) {
+                Map<String, Product_Search__c> mpProduct2 = new Map<String, Product_Search__c>();                     // key銇孭roductCode銇с仚銆�
+                //List<Product_Search__c> items = [select Id,Name,ProductCode__c,
+                //      ProductDescription__c,ProductStatus__c,Pricebook__c,Product__c 
+                //      FROM Product_Search__c Where Pricebook__c = :pricebook2Id and ProductCode__c In :codelist];
+                List<Product_Search__c> items = [select Id,Name,ProductCode__c,
+                        ProductDescription__c,ProductStatus__c,Product__c 
+                        FROM Product_Search__c Where ProductCode__c In :codelist];
+                List<String> forSelect = new List<String>();
+                for (Product_Search__c prd:items) {
+                    mpProduct2.put(prd.ProductCode__c, prd);
+                    forSelect.add(prd.Product__c);
+                }
+
+                Map<String, PricebookEntry> entries = new Map<String, PricebookEntry>();            // key銇孭roductCode銇с仚銆�
+                List<PricebookEntry> pbes = [
+                    select Id,Product2Id,ProductCode,SalesPrice__c,SalesPriceA__c,SalesPriceB__c,SalesPriceC__c
+                      FROM PricebookEntry where Pricebook2Id = :pricebook2Id
+                       and CurrencyIsoCode =:currencyIsoCode and Product2Id in : forSelect];
+
+                Map<String, String> tempMap = new Map<String, String>();
+
+                for (PricebookEntry pbe:pbes) {
+                    entries.put(pbe.ProductCode, pbe);
+                    tempMap.put(pbe.Product2Id,pbe.Id);
+                }
+
+                for (Integer l=0;l<codelist.size();l++) {
+                    Product_Search__c prd = mpProduct2.get(codelist[l]);
+                    if (prd != null) {
+                        PricebookEntry pbe = entries.get(codelist[l]);
+                        QELine c = null;
+                        if (pbe != null) {
+                            Decimal sp0 = pbe.SalesPrice__c;
+                            Decimal sp1 = pbe.SalesPriceA__c;
+                            Decimal sp2 = pbe.SalesPriceB__c;
+                            Decimal sp3 = pbe.SalesPriceC__c;
+                            c = new QELine(isService, i, prd.Name, prd.ProductCode__c, pbe.Id, pbe.Product2Id, Quantitylist[l],setlist[l], sp0, sp1, sp2, sp3);
+                        } else {
+                            continue;
+                        }
+                        activities.add(c);
+                        i++;
+                        rightcnt++;
+                        lineflg = true;
+                    }
+                }
+                if (lineflg==true) {
+                    i--;
+                } else {
+                    QELine a = New QELine(t, i);
+                    activities.add(a);
+                }
             } else {
-              q.Pricebook2Id = standardPricebook.Id;
+                QELine a = New QELine(t, i);
+                activities.add(a);
             }
-          }
-        }
-      }
-
-      if (quoId == null) {
-        q.Quote_No__c = opp.Opportunity_No__c + '-' + oppNo;
-        q.PriceRefreshDate__c = Date.today();
-      }
-      if (productStatusUpdated) {
-        q.PriceRefreshDate__c = Date.today();
-      }
-
-      // 20150302 jo 瑕嬬銇富鏈哄畨瑁呭湴鐐广倰瑷畾
-      List<String> pIds = new List<String>();
-      system.debug('activities++++----****1'+activities);
-      for (QELine s : activities) {
-        if (String.isBlank(s.PageObject.Id__c) == false) {
-          pIds.add(s.PageObject.Id__c);
-        }
-      }
-      List<Product2> pList = [select Id from Product2 where Id in :pids and Category3__c = '涓绘満'];
-      if (pList.size() > 0) q.HasType3Machine__c = true;
-
-      q.Name = quo.QuoteName__c;
-      // TODO katsu 鏂拌銇樸們銇亜鍫村悎銈汇儍銉堛仚銈嬪繀瑕併仹銇欍亱锛�
-      q.Estimation_List_Price__c = qb.Estimation_List_Price;
-      //q.TotalPrice = quo.TotalPrice; ===============-Field is not writeable: Quote.TotalPrice
-      q.Dealer_Final_Price__c =  quo.Dealer_Final_Price_Page__c;
-      q.OCM_Sales_Forecast__c = opp.Wholesale_Price__c;
-      q.Stocking_Price__c = quoStocking_Price_c;
-      quo.Stocking_Price__c = quoStocking_Price_c;
-
-      q.Quote_Adjust_Amount__c = quo.Quote_Adjust_Amount_Page__c;
-      q.Quote_Adjust_Calculate__c = qb.Quote_Adjust_Calculate;
-      q.Discount_Amount__c = DisAmount;
-      q.Discount_Amount_Calculate__c = DisCalculation;
-      q.Agency1__c = opp.Agency1__c;
-      q.OCM_Agent1_Price__c = quo.OCM_Agent1_Price_Page__c;
-      q.Agency1_Profit__c = Salesprofit1;
-      q.AgencyDiscount__c  = AgencyDiscount; // 2018/09/28 CHAN-B4YAB8 缁忛攢鍟嗘姌鎵�
-
-      //澶氬勾淇濅慨 start
-      q.Gurantee_Period__c = quo.Gurantee_Period__c;
-      q.multiYearWarranty__c = quo.multiYearWarranty__c;
-      q.MultiYearWarrantyTotalPrice__c = quo.MultiYearWarrantyTotalPrice__c;
-      q.quoteSavedDate__c = Date.today();
-      //澶氬勾淇濅慨 end
-
-      q.Agency1_Profit_Rate__c = qb.SalesCalculation1;
-      q.Agency2__c = opp.Agency2__c;
-      q.Agent1_Agent2_Price__c = quo.Agent1_Agent2_Price_Page__c;
-      q.Agency2_Profit__c = Salesprofit2;
-      q.Agency2_Profit_Rate__c = qb.SalesCalculation2;
-
-      //----checkbox 銇嵃鍒风洿鍓嶃伀淇濆瓨
-      q.Print_HP_Name__c = selection_hp;
-      q.Quote_Expiration_Date__c = quo.Quote_Expiration_Date__c;
-      q.Quote_Comment__c = quo.Quote_Comment__c;
-
-      q.Installation_location__c = quo.Installation_location__c;
-      /*
-      if (hasType3Machine) {
-          q.Installation_location__c = '';
-      }
-      */
-      System.debug('start save quote at: ' + System.currentTimeMillis());
-      if (quoId == null) {
-        insert q;
-        quo.Quote_No__c = q.Quote_No__c;
-      } else {
-        update q;
-      }
-      System.debug('finished save quote at: ' + System.currentTimeMillis());
-
-      system.debug('鈼嬧棆鈼嬧棆鈼婼ave1鈼嬧棆鈼嬧棆鈼�');
-
-      //QuoteLineItem;
-      List<QuoteLineItem> qlist = New List<QuoteLineItem>();
-      qlist = [Select Id From QuoteLineItem Where QuoteId = :quoId];
-      if (qlist.size() > 0) {
-        //delete
-        delete qlist;
-      }
-
-      //QuoteLineItem--------------------------------------------
-      //瑁藉搧鍨嬬暘銆佸搧鐩偝銉笺儔銆丼FDA銈广儐銉笺偪銈广�佸搧鐩悕銆丩istPrice銆佹暟閲�
-      //渚℃牸銆佸崢浣嶃�佸皬瑷堛�丱CM澹蹭笂浜堟脯閲戦锛堢◣鎶滐級銆佷尽鏍艰〃
-      qlist = New List<QuoteLineItem>();
-      //Sap閫佷俊,Print銇悎銈忋仜銇�1锝�
-      Integer i = 1;
-      if (activities.size() > 0) {
-        system.debug('activities++++----****'+activities);
-        for (QELine s : activities) {
-          if (s.Asset_Model != null && s.Asset_Model != '') {
-            if (s.pageObject.PricebookEntryId != null) {
-              // TODO katsu 銇仠clone()銇椼伨銇欍亱锛熸剰鍛充笉鏄庛��
-              QuoteLineItem ql = s.pageObject.clone();
-              ql.Quantity = ql.Quantity__c;
-              ql.UnitPrice = 0;                        // UnitPrice銈掍娇銈忋仾銇勩亼銇┿�佸繀闋堛仾銇仹銆�0銈掑叆銈屻倠
-              ql.QuoteId = q.Id;
-              ql.Name__c = s.PageObject.Name__c;
-              ql.Cost__c = s.Cost_c;
-              ql.Cost_Subtotal__c = s.Cost_Subtotal_c;
-              s.pageObject.Cost__c = s.Cost_c;
-              s.pageObject.Cost_Subtotal__c = s.Cost_Subtotal_c;
-              ql.UnitPrice__c = ql.UnitPrice_Page__c;
-              ql.UnitPrice_Page__c = 0;
-              ql.ListPrice__c = s.ListPrice_Page;
-              // 澶氬勾淇濅慨  start
-              // 璁℃彁閲戦
-              ql.GuranteePrice__c        = s.GuranteePrice;
-              ql.ProductGuranteePrice__c = s.ProductGuranteePrice;
-              // 缁翠慨鍚堝悓鎶ヤ环
-              ql.Maintenance_Price_Year__c = s.Maintenance_Price_Year;
-              // 澶氬勾淇濅慨  end
-              //CHAN-BWH2WP 绮剧悽鎶�鏈� wql 2020/12/22 start 
-              //濡傛灉浜у搧涓轰笉鍙彇娑堝骞翠繚 鍒欐墦涓婃爣璇�
-              system.debug(s.CanNotCancelledGurantee);
-              ql.CanNotCancelFlag__c = s.CanNotCancelledGurantee;
-              
-              //CHAN-BWH2WP 绮剧悽鎶�鏈� wql 2020/12/22 end
-              // CHAN-AVG3PW 璇环鎶ヤ环鐢婚潰瑙勫垯鍙樻洿
-              //ql.SFDA_Status__c = prd2LatestValMap.get(s.pageObject.Id__c).SFDA_Status__c;
-              //涓︺伋闋�
-              ql.Item_Order__c = i;
-              //OCM澹蹭笂浜堟脯閲戦(绋庤炯) = OCM鎴愮磩浜堟脯閲戦(绋庤炯銇�) * (灏忚▓ / 瑕嬬鍚堣▓)
-              if (s.PageObject.Subtotal__c != null && opp.Wholesale_Price__c != null && quo.QuoteTotal_Page__c != null) {
-                if (s.PageObject.Subtotal__c > 0 && quo.QuoteTotal_Page__c > 0) {
-                  ql.OCM_Sales_Forecast__c =  opp.Wholesale_Price__c * (s.PageObject.Subtotal__c / quo.QuoteTotal_Page__c);
-                }
-              }
-              qlist.add(ql);
-              i++;
-            }
-          }
-        }
-        System.debug('start save quote lines at: ' + System.currentTimeMillis());
-        system.debug('qlist+++---+++'+qlist);
-        insert qlist;
-        System.debug('finished save quote lines at: ' + System.currentTimeMillis());
-
-      }
-      system.debug('鈼嬧棆鈼嬧棆鈼婼ave2鈼嬧棆鈼嬧棆鈼�');
-
-      //Opportunity--------------------------------------------
-      //妯欐簴瀹氫尽鍚堣▓渚℃牸銆佽绌嶉噾椤嶇窂鍚堣▓锛堢◣鎶溿亶锛夈�佺梾闄㈠绱勯噾椤嶃��
-      //1娆¤博澹插簵銆�1娆¤博澹插簵鍒╃泭閲戦銆�1娆¤博澹插簵鍒╃泭鐜囥��
-      //2娆¤博澹插簵銆�2娆¤博澹插簵鍒╃泭閲戦銆�2娆¤博澹插簵鍒╃泭鐜�
-      //瑕嬬鐣彿銆佽绌嶅悕
-      Opportunity o = New Opportunity();
-      List<Opportunity> os = New List<Opportunity>();
-      
-      os = [select Id, Estimation_List_Price__c, Dealer_Final_Price__c, Estimation_List_Price_Without_Tax__c,
-            Agency1__c, OCM_Agent1_Price__c, Agency1_Profit__c, Agency1_Profit_Rate__c, Stocking_Price__c,
-            Agency2__c, Agent1_Agent2_Price__c, Agency2_Profit__c, Agency2_Profit_Rate__c, Quote_Update_Sum__c , Hospital__c,Is_Corrosion__c 
-            From Opportunity Where Id = :oppid];
-      if (os.size() > 0) {
-        o = os[0];
-        o.Estimation_List_Price__c = qb.Estimation_List_Price;
-        o.Wholesale_Price__c = opp.Wholesale_Price__c;
-        o.Dealer_Final_Price__c = quo.Dealer_Final_Price_Page__c;
-        o.Agency1__c = opp.Agency1__c;
-        o.OCM_Agent1_Price__c = quo.OCM_Agent1_Price_Page__c;
-        o.Agency1_Profit__c = Salesprofit1;
-        o.Agency1_Profit_Rate__c = qb.SalesCalculation1;
-        //            o.Agency1_Profit_Rate__c = quo.Agency1_Profit_Rate__c;
-        o.Agency2__c = opp.Agency2__c;
-        o.Agent1_Agent2_Price__c = quo.Agent1_Agent2_Price_Page__c;
-        o.Agency2_Profit__c = Salesprofit2;
-        o.Agency2_Profit_Rate__c = qb.SalesCalculation2;
-        //            o.Agency2_Profit_Rate__c = quo.Agency2_Profit_Rate__c;
-
-        o.Stocking_Price__c = quo.Stocking_Price__c;
-
-        o.Estimation_No__c = quo.Quote_No__c;
-        //o.Estimation_Name__c = quo.Name;
-        o.Estimation_Name__c = q.Name;
-        o.Estimation_Id__c = q.Id;
-        o.Installation_location__c = q.Installation_location__c;
-        o.HasType3Machine__c = q.HasType3Machine__c;
-        // 2018/09/29 CHAN-B4YAB8 缁忛攢鍟嗘姌鎵� start
-        o.AgencyDiscount__c  = AgencyDiscount;
-        // 2018/09/29 CHAN-B4YAB8 缁忛攢鍟嗘姌鎵� end
-        // 澶氬勾淇濅慨 start
-        o.Gurantee_Period__c              = quo.Gurantee_Period__c ;
-        o.multiYearWarranty__c            = quo.multiYearWarranty__c ;
-        o.MultiYearWarrantyTotalPrice__c  = quo.MultiYearWarrantyTotalPrice__c ;
-        o.quoteSavedDate__c = Date.today();
-        // 澶氬勾淇濅慨 end
-
-
-        if (o.Quote_Update_Sum__c == null) {
-          o.Quote_Update_Sum__c = 1;
-        } else {
-          o.Quote_Update_Sum__c = o.Quote_Update_Sum__c + 1;
-        }
-        System.debug('start 1st save Opportunity at: ' + System.currentTimeMillis());
-        ControllerUtil.updOpp(o);
-        System.debug('finished 1st save Opportunity at: ' + System.currentTimeMillis());
-
-        system.debug('鈼嬧棆鈼嬧棆鈼婼ave3鈼嬧棆鈼嬧棆鈼�');
-
-        //OpportunityLineItem--------------------------------------------
-        //瑁藉搧鍨嬬暘銆佸搧鐩偝銉笺儔銆丼FDA銈广儐銉笺偪銈广�佸搧鐩悕銆丩istPrice銆佹暟閲�
-        //渚℃牸銆佸崢浣嶃�佸皬瑷堛�丱CM澹蹭笂浜堟脯閲戦锛堢◣鎶滐級銆佷尽鏍艰〃
-        List<OpportunityLineItem> ols = New List<OpportunityLineItem>();
-        OpportunityLineItem ol = New OpportunityLineItem();
-        ols = [select Id from OpportunityLineItem Where OpportunityId = :oppid];
-        if (ols.size() > 0) {
-          //delete
-          ControllerUtil.delOppLine(ols);
-          system.debug('鈼嬧棆鈼嬧棆鈼婼ave4鈼嬧棆鈼嬧棆鈼�');
-        }
-        //Sap閫佷俊,Print銇悎銈忋仜銇�1锝�
-        i = 1;
-        ols = New List<OpportunityLineItem>();
-        if (activities.size() > 0) {
-          for (QELine s : activities) {
-            if (s.Asset_Model != null && s.Asset_Model != '') {
-              if (s.PageObject.PricebookEntryId != null) {
-                ol = New OpportunityLineItem();
-                ol.OpportunityId = oppid;
-                ol.Id__c = s.PageObject.Id__c;
-                // CHAN-AVG3PW 璇环鎶ヤ环鐢婚潰瑙勫垯鍙樻洿
-                ol.SFDA_Status__c = s.PageObject.SFDA_Status__c;
-                //ol.SFDA_Status__c = prd2LatestValMap.get(s.pageObject.Id__c).SFDA_Status__c;
-                ol.Name__c = s.PageObject.Name__c;
-                ol.ListPrice__c = s.ListPrice_Page;
-                ol.Quantity = s.PageObject.Quantity__c;
-                ol.UnitPrice = 0;
-                ol.UnitPrice__c = s.PageObject.UnitPrice_Page__c;
-                // 2018-10-31 CHAN-B4YAB8 璧犻�併�佺粡閿�鍟嗗崟浠峰拰灏忚 start
-                ol.AgencyUnitPrice__c =  s.PageObject.AgencyUnitPrice__c;
-                ol.Present__c =  s.PageObject.Present__c;
-                ol.AgencySubtotal__c =  s.PageObject.AgencySubtotal__c;
-                // 2018-10-31 CHAN-B4YAB8 璧犻�併�佺粡閿�鍟嗗崟浠峰拰灏忚 start
-                // 澶氬勾淇濅慨 start
-                ol.GuaranteePeriod__c =  s.PageObject.GuaranteePeriod__c;
-                //澶栬锤澶氬勾淇� 鍙栨秷CNY 鐨勫垽鏂� &&  oppInfo.CurrencyIsoCode.equals('CNY')
-                //澶栬锤澶氬勾淇� 绮剧悽鎶�鏈� wql 2021/01/18 start 
-                if (oppInfo.CurrencyIsoCode != null ) {
-                  ol.multiYearWarranty__c =  s.PageObject.multiYearWarranty__c;
-                  ol.ServicePrice__c =  s.PageObject.ServicePrice__c;
-                  ol.If_Cancel_Guarantee__c =  s.PageObject.If_Cancel_Guarantee__c;
-                  ol.ProductEntend_gurantee_period_all__c
-                    =  s.PageObject.ProductEntend_gurantee_period_all__c;
-                  ol.GuranteeType__c =  s.PageObject.GuranteeType__c;
-                  ol.NoDiscountTotal__c =  s.PageObject.NoDiscountTotal__c;
-                  ol.warrantyType__c =  s.PageObject.warrantyType__c;
-                  ol.productServicePrice__c =  s.PageObject.productServicePrice__c;
-                  // 璁℃彁閲戦
-                  ol.GuranteePrice__c        = s.GuranteePrice;
-                  ol.ProductGuranteePrice__c = s.ProductGuranteePrice;
-                  // 缁翠慨鍚堝悓鎶ヤ环
-                  ol.Maintenance_Price_Year__c = s.Maintenance_Price_Year;
-
-                  ol.provistonPeriod__c = s.PageObject.provistonPeriod__c;
-
-                }
-                //澶栬锤澶氬勾淇� 绮剧悽鎶�鏈� wql 2021/01/18 end
-                // 澶氬勾淇濅慨 end
-                ol.Qty_Unit__c = s.PageObject.Qty_Unit__c;
-                //銈炽偣銉堛伅灏忚▓娓堛倰鐧婚尣
-                ol.Cost__c = s.PageObject.Cost__c;
-                ol.BSS_Category__c = s.PageObject.BSS_Category__c;
-                //CHAN-BWH2WP 绮剧悽鎶�鏈� wql 2020/12/22 start 
-                //濡傛灉浜у搧涓轰笉鍙彇娑堝骞翠繚 鍒欐墦涓婃爣璇�
-                system.debug(s.CanNotCancelledGurantee);
-                ol.CanNotCancelFlag__c = s.CanNotCancelledGurantee;
-                //CHAN-BWH2WP 绮剧悽鎶�鏈� wql 2020/12/22 end
-                //OCM澹蹭笂浜堟脯閲戦 * (灏忚▓/瑕嬬鍚堣▓)
-                if (s.PageObject.Subtotal__c != null && opp.Wholesale_Price__c != null && quo.QuoteTotal_Page__c != null) {
-                  if (s.PageObject.Subtotal__c > 0 && quo.QuoteTotal_Page__c > 0) {
-                    ol.OCM_Sales_Forecast__c =  opp.Wholesale_Price__c * (s.PageObject.Subtotal__c / quo.QuoteTotal_Page__c);
-                  }
-                }
-                //渚℃牸琛�
-                ol.PricebookEntryId = s.PageObject.PricebookEntryId;
-                //涓︺伋闋�
-                ol.Item_Order__c = i;
-                ols.add(ol);
-                i++;
-              }
-            }
-          }
-          // CHAN-BEN5UC   [濮旀墭]璇环锛氬垱寤烘姤浠峰悗锛屽垽鏂浠蜂竴瀹氭湡闂村唴锛屾槸鍚﹀嚭鍊熷鍝� by vivek start
-          // CHAN-C9Y3HL 銆愬鎵樸�戙�愯瘎浼伴渶姹傘�戣浠烽噷鎶ヤ环鐢婚潰閫熷害浼樺寲 2022-02-09 
-          // 鏌ヨ鍑哄�熷鍝侀�昏緫浠庝繚瀛橀�昏緫涓Щ闄わ紝鐢盉atch杩涜缁熶竴鎿嶄綔锛屼互鎻愬崌淇濆瓨閫熷害鍙婄粺璁℃暟鎹噯纭�с��
-          // Date createdDateStr;
-          // if (quoId != null && quo.CreatedDate != null ) {
-          //   // createdDateStr = [select id,CreatedDate from Quote where id = :quoId][0].CreatedDate.date();
-          //   createdDateStr = quo.CreatedDate.date();
-          // } else {
-          //   createdDateStr = Date.today();
-          // }
-          // // 涓�骞村墠鐨勬棩鏈�
-          // Date createdDateYear = createdDateStr.addYears(-1);
-          // List<Rental_Apply_Equipment_Set_Detail__c> raesdList = [select id, product__c, Bollow_Date__c, Rental_Apply__r.Hospital__c from Rental_Apply_Equipment_Set_Detail__c where Rental_Apply__r.Strategic_dept__c = : opp.Department_Class__c and Key_product__c != null and Bollow_Date__c >= :createdDateYear order by Bollow_Date__c ];
-
-          // Map<String, Date> ProOfDate = new Map<String, Date>();
-          // for (Rental_Apply_Equipment_Set_Detail__c raesd : raesdList) {
-          //   ProOfDate.put(raesd.product__c, raesd.Bollow_Date__c);
-          // }
-
-          // o.WhetherTrySpareParts_3m__c = false;
-          // o.WhetherTrySpareParts_6m__c = false;
-          // o.WhetherTrySpareParts_1y__c = false;
-          // for (OpportunityLineItem oppitem : ols) {
-          //   if (ProOfDate.containsKey(((String)oppitem.Id__c).substring(0, 15))) {
-          //     Date bollDate = ProOfDate.get(((String)oppitem.Id__c).substring(0, 15));
-          //     if (bollDate != null && bollDate.addMonths(3) > createdDateStr) {
-          //       o.WhetherTrySpareParts_3m__c = true;
-          //     }
-          //     if (bollDate != null && bollDate.addMonths(6) > createdDateStr && bollDate.addMonths(3) < createdDateStr) {
-          //       o.WhetherTrySpareParts_6m__c = true;
-          //     }
-          //     if (bollDate != null && bollDate.addYears(1) > createdDateStr && bollDate.addMonths(6) < createdDateStr) {
-          //       o.WhetherTrySpareParts_1y__c = true;
-          //     }
-
-          //   }
-          // }
-
-          
-          // System.debug('start 2nd save Opportunity at: ' + System.currentTimeMillis());
-          // ControllerUtil.updOpp(o);
-          // System.debug('finished 2nd save Opportunity at: ' + System.currentTimeMillis());
-          // CHAN-BEN5UC   [濮旀墭]璇环锛氬垱寤烘姤浠峰悗锛屽垽鏂浠蜂竴瀹氭湡闂村唴锛屾槸鍚﹀嚭鍊熷鍝� by vivek end
-          System.debug('start save Opportunity item lines at: ' + System.currentTimeMillis());
-          ControllerUtil.insOppLine(ols);
-          System.debug('finished save Opportunity item lines at: ' + System.currentTimeMillis());
-        }
-
-      } else {
-        system.debug('*****SystemError OpportunityId is Null*****');
-      }
-      //淇濆瓨鏅傚紩鍚圥age銇埢銈夈仾銇勫嚘鐞嗐仺銇椼仧鐐恒伀QuoteId銈掋亾銇撱仹銈汇儍銉�
-      if (quoId == null) {
-        quoId = q.Id;
-        newQuoteFlag = false;
-      } 
-    }else{
-      errorflg = true;
-      errormessage = '璇ヨ浠峰凡缁廳ecide锛屼笉鍙啀淇敼';
-      return false;
-    }
-    return true;
-  }
-  //lastbuy  2022/2/9 fy start
-  public boolean ReservedProductVerification() {
-    filg=true;
-    Map<string,QuoteLineItem> quotlinitMap = new Map<string,QuoteLineItem>();
-    List<Id> lastProductFLGList = new List<Id>();
-    for(QELine qli : activities){
-      lastProductFLGList.add(qli.pageObject.PricebookEntry.Product2Id);
-      quotlinitMap.put(qli.pageObject.PricebookEntry.Product2Id,qli.pageObject);
-    }
-    System.debug('activities!!!'+activities);
-    System.debug('oppId!!!'+oppId);
-    System.debug('lastProductFLGList!!!'+lastProductFLGList);
-    if(lastProductFLGList!=null){
-        List<LastbuyProduct__c> LastbuyObjList=[select id,LastbuyQuantity__c,InquiryCode__c,ProductName__c,effectiveFLG__c from LastbuyProduct__c where InquiryCode__c= : oppId and ProductName__c in :lastProductFLGList and effectiveFLG__c = true];
-        if(LastbuyObjList!=null){
-            for(LastbuyProduct__c lastbuypr :LastbuyObjList){
-              Decimal quoteLItemNum=0;
-              if(quotlinitMap.containsKey(lastbuypr.ProductName__c)){
-                  quoteLItemNum=quotlinitMap.get(lastbuypr.ProductName__c).Quantity__c;
-              }else{
-                  continue;
-              }
-              if(lastbuypr.LastbuyQuantity__c<quoteLItemNum){
-                filg=false;
+            i++;
+            if (i>149) {
                 break;
-              }
             }
         }
-    }
-    system.debug('filg====='+filg);
-    return filg;
-  }
-  //lastbuy  2022/2/9 fy end
-  //opp銇敾闈€伄鍊ゃ倰瑷畾
-  private void setOppFromOppInfo() {
-    opp.Wholesale_Price__c = oppInfo.Wholesale_Price;
-    opp.Agency1__c = quo.Agency1__c;
-    opp.Agency2__c = quo.Agency2__c;
-  }
-
-  public class OppInfo {
-    public String Account_RecordType_DeveloperName { get; set; }
-    public String Direct_Separate { get; set; }
-    public String Trade { get; set; }
-    public Decimal Wholesale_Price { get; set; }
-    public String CurrencyIsoCode { get; set; }
-    public String HP_Name { get; set; }
-    public String Department_Name { get; set; }
-    public String Sales_Root { get; set; }
-    // LHJ Start
-    public boolean If_Need_Authorize { get; set; }
-    public String Authorized_DB_No { get; set; }
-    // LHJ End
-
-    public OppInfo(Opportunity opp) {
-      Account_RecordType_DeveloperName = opp.Account.RecordType.DeveloperName;
-      Direct_Separate = opp.Direct_Separate__c;
-      Trade = opp.Trade__c;
-      Wholesale_Price = opp.Wholesale_Price__c;
-      CurrencyIsoCode = opp.CurrencyIsoCode;
-      HP_Name = opp.HP_Name__c;
-      Department_Name = opp.Department_Name__c;
-      Sales_Root = opp.Sales_Root__c;
-      // LHJ Start
-      If_Need_Authorize = opp.If_Need_Authorize__c;
-      Authorized_DB_No = opp.Authorized_DB_No__c;
-      // LHJ End
-    }
-  }
-  //TODO 1.Quote銈儢銈搞偋銈儓杩藉姞
-  //TODO 2.銈炽兂銈广儓銉┿偗銈裤倰杩藉姞
-  public class QuoteBean {
-    public Decimal Estimation_List_Price { get; set; }
-    //TODO 999.99浠ヤ笅銇椼亱鍏ュ姏銇с亶銇亜銆�
-    public Decimal Quote_Adjust_Calculate { get; set; }
-    public Decimal SalesCalculation1 { get; set; }
-    public Decimal SalesCalculation2 { get; set; }
-    public Integer PriceRefreshPeriod { get; set; }
-    public void setPriceRefreshPeriodByDate(Date PriceRefreshDate) {
-      this.PriceRefreshPeriod = PriceRefreshDate.daysBetween(Date.today());
-    }
-  }
-
-  public class QELinelatestInfo {
-    public String ProductCode { get; set; }
-    public String ProductName { get; set; }
-    public String SFDA_Status { get; set; }
-    public String Sales_Possibility { get; set; }
-    public Decimal ListPrice { get; set; }              // 鏈�鏂�
-    public Decimal Cost { get; set; }                    // 鏈�鏂�
-    public Integer Specifications {get; set;}
-
-    // 澶氬勾淇濅慨 start
-    public string GuranteeType {get; set;}
-    public Decimal Intra_Trade_Gurantee {get; set;}
-    public Decimal ProductEntend_gurantee_period_all {get; set;}
-    public Decimal Intra_Trade_Service {get; set;}
-    // 缁翠慨鍚堝悓鎶ヤ环
-    public Decimal Maintenance_Price_Year {get; set;}
-    // 澶氬勾淇濅慨 end
-    // 缁翠慨鍚堝悓鎶ヤ环
-    //涓嶅彲鍙栨秷澶氬勾淇�
-    public Boolean CanNotCancelledGurantee {get; set;}
-    // 澶氬勾淇濅慨 end
-
-    //闃胯タ璧涘
-    public Boolean Is_DangerousChemicals {get; set;}
-    //闃胯タ璧涘
-
-  }
-  public class QELine {
-    public Integer lineNo { get; set; }                                // 鐢婚潰銇爢搴�
-    public String Asset_Model { get; set; }
-    public String Sales_Possibility { get; set; }                         // 璨╁2鍙惁鈼嬅楀垽鏂敤銆佷娇銇c仸銇亜銈堛亞銇с仚銆俆ODO 鍓婇櫎
-    public QuoteLineItem pageObject { get; set; }                      // Id__c銇┖琛屽垽鏂敤銆丼FDA_Status__c 銇仼銆佺炕瑷炽仌銈屻倠闋呯洰琛ㄧず銇欍倠銇熴倎浣裤亞蹇呰銇屻亗銈娿伨銇�
-    public Decimal Cost_c { get; set; }
-    public Decimal Cost_Subtotal_c { get; set; }
-    public Decimal ListPrice_Page { get; set; }
-    //*******************************liukun******************//
-    public String StorageStatus { get; set; }
-    //********************Insert [OLY_OCM-228] [20160706] [璧靛痉鑺砞 Start********************//
-    public Integer Specifications {get; set;}
-    //********************Insert [OLY_OCM-228] [20160706] [璧靛痉鑺砞 End**********************//
-    //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 Start
-    public String VenderName { get; set; }
-    //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 end
-
-    //涓嶅彲鍙栨秷澶氬勾淇�
-    public Boolean CanNotCancelledGurantee {get;set;}
-    //闃胯タ璧涘
-    public Boolean Is_DangerousChemicals {get;set;}
-
-    // PriceStatusUpdate() 鐢ㄣ伄闋呯洰銆乀ODO 鍒濇湡鍊ゃ伄瑷畾
-    public QELinelatestInfo latestInfo { get; set; }
-
-    public boolean changed_name { get; set; }
-    public boolean changed_sfda { get; set; }
-    public boolean changed_list { get; set; }
-    public boolean changed_cost { get; set; }
-    public boolean haveno_Register { get; set; }
-    public boolean wrong_Register { get; set; }
-
-    //SFDC鍋滄棰勮 lt 20211009 start
-    public String Estimated_ConsumptionDueDate { get; set; }
-    //SFDC鍋滄棰勮 lt 20211009 end
-
-    // 澶氬勾淇濅慨 start
-    //璁℃彁閲戦
-    public Decimal GuranteePrice { get; set; }
-    public Decimal ProductGuranteePrice { get; set; }
-    // 缁翠慨鍚堝悓鎶ヤ环
-    public decimal Maintenance_Price_Year {get; set;}
-    // 澶氬勾淇濅慨 end
-
-    // TODO 銇汇倱銇ㄣ亞銇亜銈夈仾銇勩�佷娇銇嗐仺銇撱倣銇儹銈搞儍銈倰淇銇椼仾銇戙倢銇般亜銇戙仾銇勩�佸墛闄ゃ仚銈嬨倛銇嗐伀銇椼仧銇勩仹銇欍��
-    public QELine(Integer i) {
-      pageObject = New QuoteLineItem();
-      latestInfo = New QELinelatestInfo();
-      this.lineNo = i;
-    }
-    // tmp 鐩存帴浣裤亞鍫村悎銇儜銈裤兗銉�
-    public QELine(QELine tmp, Integer i) {
-      pageObject = tmp.pageObject;
-      this.lineNo = i;
-      this.Asset_Model = tmp.Asset_Model;
-      this.Sales_Possibility = tmp.Sales_Possibility;
-      this.latestInfo = tmp.latestInfo;
-      this.Cost_Subtotal_c = tmp.Cost_Subtotal_c;
-      this.Cost_c = tmp.Cost_c;
-      this.ListPrice_Page = tmp.ListPrice_Page;
-      this.StorageStatus = tmp.StorageStatus;
-      // 澶氬勾淇濅慨  start
-      // 璁℃彁閲戦
-      this.GuranteePrice          = tmp.GuranteePrice;
-      this.ProductGuranteePrice   = tmp.ProductGuranteePrice;
-      //缁翠慨鍚堝悓鎶ヤ环
-      this.Maintenance_Price_Year = tmp.Maintenance_Price_Year;
-      // 澶氬勾淇濅慨 璁℃彁閲戦 end
-
-      this.changed_name = tmp.changed_name;
-      this.changed_sfda = tmp.changed_sfda;
-      this.changed_list = tmp.changed_list;
-      this.changed_cost = tmp.changed_cost;
-      this.haveno_Register = false;
-      this.wrong_Register  = false;
-      //涓嶅彲鍙栨秷澶氬勾淇�
-      this.CanNotCancelledGurantee = tmp.CanNotCancelledGurantee;
-      //渚涘簲鍟嗗悕绉�
-      this.VenderName = tmp.VenderName;
-
-      //SFDC鍋滄棰勮 lt 20211009 start
-      this.Estimated_ConsumptionDueDate = tmp.Estimated_ConsumptionDueDate;
-      //SFDC鍋滄棰勮 lt 20211009 end
+        // message銈掑嚭銇�
+        errorflg = true;
+        errormessage = '鏁版嵁瀵煎叆缁撴潫锛屽鍏� ' + codelist.size() + ' 浠讹紝鎴愬姛' + rightcnt + ' 浠�';
+*/
+        return null;
 
     }
-    public QELine(OpportunityLineItem oli, Integer i) {
-      pageObject = New QuoteLineItem();
-      pageObject.Quantity__c = oli.Quantity;
 
-      this.lineNo = i;
-      this.Asset_Model = oli.Asset_Model_No__c;
-      this.Sales_Possibility = oli.PricebookEntry.Product2.Sales_Possibility__c;
-      this.StorageStatus = oli.PricebookEntry.Product2.StorageStatus__c;
-      //********************Insert [OLY_OCM-228] [20160706] [璧靛痉鑺砞 Start********************//
-      if (oli.PricebookEntry.Product2.Packing_list_manual__c != null) {
-        this.Specifications = integer.valueof(oli.PricebookEntry.Product2.Packing_list_manual__c + '');
-      }
-      //********************Insert [OLY_OCM-228] [20160706] [璧靛痉鑺砞 End**********************//
-      PageObject.Id__c = oli.PricebookEntry.Product2Id;
-      PageObject.UnitPrice_Page__c = oli.UnitPrice__c;
-      //CHAN-B4YAB8 2018/9/28 灏忚缁忛攢鍟嗗崟浠峰拰灏忚
-      PageObject.AgencySubtotal__c = oli.AgencySubtotal__c;
-      PageObject.AgencyUnitPrice__c = oli.AgencyUnitPrice__c;
-      // CHAN-B4YAB8 2018/9/28 缁忛攢鍟嗗崟浠峰拰灏忚
+     //BackButton
+    public PageReference BackBtn() {
+        String url = baseUrl;
+        if (rtUrl != null && rtUrl.length() > 0) {
+            url += rtUrl.replace('/production', '');
+        } else {
+            url += '\\' + oppid;
+        }
+        return new Pagereference(url);
+    }
 
-      //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 Start
-      this.VenderName = oli.PricebookEntry.Product2.VenderName__c;
+    public PageReference Save() {
 
-      //SFDC鍋滄棰勮 lt 20211009  鈶犱笉鑳藉畾涔塪ate鍙橀噺 鍥犱负鍓嶅彴杩斿洖鐨勬槸String鏃ユ湡  鈶″皢util閲岀殑鏂规硶杞负鏃ユ湡鏍煎紡 start
-      if(oli.PricebookEntry.Product2.Estimated_ConsumptionDueDate__c != null){
-        this.Estimated_ConsumptionDueDate = NFMUtil.formatDate2StrSpo(oli.PricebookEntry.Product2.Estimated_ConsumptionDueDate__c).replaceAll('-','/');
-      }else{
-        this.Estimated_ConsumptionDueDate = '';
-      }
-      //SFDC鍋滄棰勮 lt 20211009 end
+        system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆Welcome to Save class!!鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆');
+        //system.debug('=====save discount:' + discount);
 
-      if(VenderName==null||VenderName==''){
-          this.VenderName =' 鏃� ';
-      }else{
-          this.VenderName = oli.PricebookEntry.Product2.VenderName__c;
-      }
-      //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 end
-      //涓嶅彲鍙栨秷澶氬勾淇�
-      this.CanNotCancelledGurantee = oli.PricebookEntry.Product2.CanNotCancelledGurantee__c;
-      //闃胯タ璧涘
-      this.Is_DangerousChemicals = oli.PricebookEntry.Product2.Is_DangerousChemicals__c;
-      // 澶氬勾淇濅慨 start
-      PageObject.multiYearWarranty__c = oli.multiYearWarranty__c;
-      PageObject.GuaranteePeriod__c = oli.GuaranteePeriod__c;
-      PageObject.ServicePrice__c = oli.ServicePrice__c;
-      PageObject.If_Cancel_Guarantee__c = oli.If_Cancel_Guarantee__c;
-      PageObject.warrantyType__c = oli.warrantyType__c;
+        errorflg = false;
+        errormessage = null;
+        Savepoint sp = Database.setSavepoint();
 
-      PageObject.NoDiscountTotal__c = oli.NoDiscountTotal__c;
-      // 璁℃彁閲戦
-      this.GuranteePrice          = oli.GuranteePrice__c;
-      // 缁翠慨鍚堝悓鎶ヤ环
-      this.Maintenance_Price_Year = oli.Maintenance_Price_Year__c;
-      PageObject.provistonPeriod__c = oli.provistonPeriod__c;
+        try {
 
-      PageObject.ProductEntend_gurantee_period_all__c =  oli.PricebookEntry.Product2.Entend_gurantee_period_all__c;
-      PageObject.GuranteeType__c = oli.PricebookEntry.Product2.GuranteeType__c;
-      
-      
-      // 澶氬勾淇濅慨 end
-      PageObject.SFDA_Status__c = oli.PricebookEntry.Product2.SFDA_Status__c;
-      //涓嶅彲鍙栨秷澶氬勾淇�
-//      PageObject.CanNotCancelledGurantee__c = oli.PricebookEntry.Product2.CanNotCancelledGurantee__c;
+            //銉囥兗銈裤儊銈с儍銈�
+            if (dataCheck() ==false) {
+                return null;
+            }
+
+            String url = baseUrl;
+            if (rtUrl != null && rtUrl.length() > 0) {
+                url += rtUrl.replace('/production', '');
+            } else {
+                url += '\\' + oppid;
+            }
+            system.debug('url++++++' + url);
+            PageReference pageRef = new Pagereference(url);
+
+            if (dataEntry()==false) {
+                //msg
+                return null;
+            } else {
+                errorflg = true;
+                if (specialerrorflg) {
+                    errorMessage = String.isBlank(errorMessage) ?System.Label.Info_Message01:System.Label.Info_Message01 +errorMessage;
+                } else {
+                    // errorMessage = System.Label.Info_Message01 ;
+
+                    errorMessage = String.isBlank(errorMessage) ?System.Label.Info_Message01:System.Label.Info_Message01 +errorMessage;
+                    // ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, '娉ㄦ剰锛侊紒锛�'+errorMessage));
+                }
+                //system.debug('errorMessage20190524' + errorMessage);
+                
+                return null;
+            }
+
+        } catch (DmlException de) {
+            Database.rollback(sp);
+            errorflg = true;
+            errormessage = de.getDmlMessage(0);           // 锛戜欢鐩伄銈ㄣ儵銉笺伄銇胯〃绀�
+            system.debug(Logginglevel.ERROR, de.getMessage());
+            system.debug(Logginglevel.ERROR, de.getStackTraceString());
+        } catch (Exception e) {
+            Database.rollback(sp);
+            errorflg = true;
+            errormessage = e.getMessage();
+            system.debug(Logginglevel.ERROR, e.getMessage());
+            system.debug(Logginglevel.ERROR, e.getStackTraceString());
+        }
+
+        return null;
+
+    }
+
+    //OppReflection button
+    public PageReference OppReflection() {
+        //opp銇敾闈€伄鍊ゃ倰瑷畾
+        setOppFromOppInfo();
+        Savepoint sp = Database.setSavepoint();
+        try {
+            errorflg = false;
+            errormessage = null;
+
+            //銉囥兗銈裤儊銈с儍銈�
+            if (dataCheck() ==false) {
+                return null;
+            }
+
+            String url = baseUrl;
+            if (rtUrl != null && rtUrl.length() > 0) {
+                url += rtUrl.replace('/production', '');
+            } else {
+                url += '\\' + oppid;
+            }
+            PageReference pageRef = new Pagereference(url);
+            if (dataEntry()==false) {
+                //msg
+                return null;
+            } else {
+                //msg
+                return pageRef;
+            }
+        } catch (DmlException de) {
+            Database.rollback(sp);
+            errorflg = true;
+            errormessage = de.getDmlMessage(0);        
+            system.debug(Logginglevel.ERROR, de.getMessage());
+            system.debug(Logginglevel.ERROR, de.getStackTraceString());
+        } catch (Exception e) {
+            Database.rollback(sp);
+            errorflg = true;
+            errormessage = e.getMessage();
+            system.debug(Logginglevel.ERROR, e.getMessage());
+            system.debug(Logginglevel.ERROR, e.getStackTraceString());
+        }
+        
+        return null;
+    }
+
+    public PageReference Decide() {
+        system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆Welcome to Decide class!!鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆');
+
+        if (quo.Is_upload__c == true) {
+            errorflg = true;
+            errorMessage = '鎶ヤ环宸茬粡涓婁紶锛屼笉鑳藉啀娆″喅瀹氥�傝鍐嶆姤浠峰悗锛屽喅瀹氬苟涓婁紶鏂扮殑鎶ヤ环銆�';
+            return null;
+        }
+
+        boolean hasDetail = false;
+        if (activities.size()>0) {
+            for (QELine s:activities) {
+                if (s.pageObject.PricebookEntryId != null && s.productName != null && s.productName != '') {
+                    hasDetail = true;
+                    break;
+                }
+            }
+        }
+
+        if (hasDetail == false) {
+            errorflg = true;
+            errorMessage = '涓嶈兘鍐冲畾娌℃湁浜у搧鏄庣粏鐨勬姤浠枫��';
+            return null;
+        }
+        doDecide = true;
+        Save();
+        decideORundecideQuote(quo.Id,true);
+        
+        String url = baseUrl + '/apex/NewQuoteDevide?Id=' + quoId + '&retURL=' + rtUrl;
+        PageReference pageRef = new Pagereference(url);
+
+        if (errorflg == false || errorMessage.startsWith(System.Label.Info_Message01)) {
+            return pageRef;
+        }
+        
+        return null;
+    }
+
+    public PageReference UnDecide() {
+        system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆Welcome to unDecide class!!鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆');
+        errorflg = false;
+        errormessage = null;
+        Savepoint sp = Database.setSavepoint();
+
+        try {
+            Quote q = New Quote();
+            q.Id = quo.Id;
+            q.Is_Decided__c = false;
+
+            Opportunity o = New Opportunity();
+            List<Opportunity> os = [select Id From Opportunity Where Id =:oppid];
+            if (os.size()>0) {
+                o = os[0];
+                o.Is_Decided__c = false;
+                o.Quote_Decide_User__c = null;
+            }
+
+            update q;
+            update o;
+            decideORundecideQuote(q.Id,true);
+            String url = baseUrl + '/apex/NewQuoteDevide?Id=' + quoId + '&retURL=' + rtUrl;
+            PageReference pageRef = new Pagereference(url);
+            if (errorflg == false) {
+                return pageRef;
+            }
+        } catch (DmlException de) {
+            Database.rollback(sp);
+            errorflg = true;
+            errormessage = de.getDmlMessage(0);           // 锛戜欢鐩伄銈ㄣ儵銉笺伄銇胯〃绀�
+            system.debug(Logginglevel.ERROR, de.getMessage());
+            system.debug(Logginglevel.ERROR, de.getStackTraceString());
+        } catch (Exception e) {
+            Database.rollback(sp);
+            errorflg = true;
+            errormessage = e.getMessage();
+            system.debug(Logginglevel.ERROR, e.getMessage());
+            system.debug(Logginglevel.ERROR, e.getStackTraceString());
+        }
+
+        return null;
+    }
+
+    public boolean dataEntry() {
+
+        system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆Welcome to dataEntry class!!鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆');
+
+        Boolean error = false;
+        Boolean detail = true;
+
+        //Quote-------------------------------------------------------------
+        //List<Quote> maxQuote_No = [select QuoteNumber From Quote Where OpportunityId = :oppid order by QuoteNumber desc NULLS LAST limit 1];
+        //String oppNo;
+        //Integer l = 1;
+        //if (maxQuote_No.size()>0) {
+        //    try {
+        //        oppNo = maxQuote_No[0].QuoteNumber;
+        //        l = Integer.valueOf(oppNo) + 1;
+        //    } catch (System.TypeException e) {
+        //        system.debug('maxQuote_No Error: quote.id=' + maxQuote_No[0].id);
+        //    }
+        //} else {
+        //    system.debug('first Quote');
+        //}
+        //oppNo = String.valueof(l);
+
+        //while (oppNo.length() < 8){
+        //    oppNo = '0' + oppNo;
+        //}
+
+        Quote q = New Quote();
+
+        if (quoId==null) {
+            q = quo.clone();
+            q.OpportunityId = oppId;
+
+            if (detail == true) {
+                if (pricebook2Id==null) {
+                    errormessage = System.Label.Error_Message04;
+                    errorflg = true;
+                    return false;
+                } else {
+                    q.Pricebook2Id = pricebook2Id;
+                }
+            }
+            
+        } else {
+
+            q = quo.clone();
+            q.Id = quoId;
+            if (q.Pricebook2Id ==null) {
+                if (detail == true) {
+                    if (pricebook2Id==null) {
+                        errormessage = System.Label.Error_Message04;
+                        errorflg = true;
+                         return false;
+                    } else {
+                        q.Pricebook2Id = pricebook2Id;
+                    }
+                }
+            }
+        }
+
+        if (quoId==null) {
+            //q.PriceRefreshDate__c = Date.today();
+        }
+        if (productStatusUpdated) {
+            //q.PriceRefreshDate__c = Date.today();
+        }
+        
+        q.Name = quo.name;
+        system.debug(opp.Account.MarketVerticals__c +'@@@@@@@@'+opp.Trade_Type_D__c);
+        if (doDecide == true) {
+            List<Quote> decideQuote = new List<Quote>();
+            //涓嶈兘鍐冲畾澶氫釜鎶ヤ环锛屾埓瀹�
+            decideQuote=[SELECT id FROM Quote WHERE OpportunityId = :opp.Id AND Is_Decided__c = true];
+            if(decideQuote.size() > 0){
+                errorflg = true;
+                errorMessage = '宸插瓨鍦ㄥ喅瀹氱殑鎶ヤ环锛屼笉鑳藉喅瀹氭柊鐨勬姤浠�';
+                return false;
+            }
+            q.Is_Decided__c = true;
+            if(opp.Account.MarketVerticals__c == 'Clinical'&&opp.Trade_Type_D__c == 'Taxation'){
+                if(opp.Dealer__r.DummyDealer__c == true){
+                    String backStr = LicenseCheckUtil.LicenseCheck(opp.AccountId);
+                    system.debug('DummyDealer__c ' + backStr);
+                    if(backStr != '1'){
+                        errorflg = true;
+                        errorMessage = backStr + '锛屼笉鑳藉喅瀹氭姤浠枫��';
+                        return false;
+                    }
+                }else{
+                    String backStr = LicenseCheckUtil.LicenseCheck(opp.Dealer__r.ParentID);
+                    system.debug('Parent' + backStr);
+                    if(backStr != '1'){
+                        errorflg = true;
+                        errorMessage = backStr + '锛屼笉鑳藉喅瀹氭姤浠枫��';
+                        return false;
+                    }
+                }
+            }
+        }else{
+             if(opp.Account.MarketVerticals__c == 'Clinical'&&opp.Trade_Type_D__c == 'Taxation'){
+                if(opp.Dealer__r.DummyDealer__c == true){
+                    String backStr = LicenseCheckUtil.LicenseCheck(opp.AccountId);
+                    system.debug('DummyDealer__c' + backStr);
+                    if(backStr != '1'){
+                        errorMessage = backStr;
+                        specialerrorflg = true;
+
+                    }
+                }else{
+                    String backStr = LicenseCheckUtil.LicenseCheck(opp.Dealer__r.ParentID);
+                    system.debug('Parent' + backStr);
+                    if(backStr != '1'){
+                        errorMessage = backStr;
+                        specialerrorflg = true;
+
+                    }
+                }
+            }
+        }
+        String quoId1 = '';
+        if (quoId==null) {
+            insert q;
+            quoId1 = q.Id;
+            printFlg = true;
+        } else {
+            
+            update q;
+            quoId1 = q.Id;
+        }
+
+        List<QuoteLineItem> qlist = New List<QuoteLineItem>();
+        qlist=[Select Id From QuoteLineItem Where QuoteId =:quoId1];
+        if (qlist.size()>0) {
+            delete qlist;
+        }
+
+        qlist = New List<QuoteLineItem>();
+        List<QuoteLineItem> singleProductList = new List<QuoteLineItem>();
+        Integer i=1;
+
+        if (activities.size()>0) {
+            Decimal all_price = 0.0;
+            Decimal all_discount = 0.0;
+            for (QELine s:activities) {
+                if (is_hidden_all || is_hidden_user == true || is_dealer_user == true && s.hiddenflg == true) {
+                    if (s.pageObject.PricebookEntryId != null &&  s.productName != null && s.productName != '') {
+                        if (String.isBlank(s.pageObject.PricebookEntryId) == false) {
+                            String setName = s.pageObject.Set__c;
+                            Integer qty = 1 ;
+                            //XHL-20190426-UpdateStart
+                            if (!s.pageObject.SingleProduct__c ){
+
+                                String fieldName = setName.substring(3);
+                                fieldName = fieldName.indexOf('0') == 0 ? fieldName.substring(1) : fieldName;
+                                Decimal d_qty = (Decimal) quo.get('SetQty' + fieldName + '__c');
+                                // qty = d_qty == null ? 1 : d_qty.intValue();
+                            }
+                            //XHL-20190426-UpdateEnd
+                            
+                            all_price += s.salesPrice * s.pageObject.Quantity * qty;
+                        }
+                    }
+                }
+
+                if (quo.OrderIsChange__c) {
+                    String productCode = s.pageObject.Product2.ProductCode;
+                    if (String.isNotBlank(productCode)) {
+                         
+                        saveStringConcatenation += productCode + '|' +s.pageObject.Quantity;
+                    }
+                    
+                }
+            }
 
 
-      PageObject.Name__c = oli.PricebookEntry.Product2.Name;
+            if (all_price > 0) {
+                system.debug('all_price---->'+all_price);
+                all_discount = (all_price - quo.Total_Price_Text__c) * 100 / all_price;
+                system.debug('all_discount---->'+all_discount);
+            }
 
-      Decimal cost;
-      if (oli.Opportunity.Trade__c == '鍐呰部') {
-        this.ListPrice_Page = oli.PricebookEntry.Product2.Intra_Trade_List_RMB__c;
-        cost = oli.PricebookEntry.Product2.Intra_Trade_Cost_RMB__c;
-        this.ProductGuranteePrice   = oli.PricebookEntry.Product2.Intra_Trade_Gurantee_RMB__c;
-        PageObject.productServicePrice__c = oli.PricebookEntry.Product2.Intra_Trade_Service_RMB__c;
-      } else if (oli.Opportunity.Trade__c == '澶栬部') {
-        this.ListPrice_Page = oli.PricebookEntry.Product2.Foreign_Trade_List_US__c;
-        cost = oli.PricebookEntry.Product2.Foreign_Trade_Cost_US__c;
-        this.ProductGuranteePrice   = oli.PricebookEntry.Product2.Intra_Trade_Foreign_RMB__c;
-        PageObject.productServicePrice__c = oli.PricebookEntry.Product2.NoDiscount_Foreign__c;
-      }
-      if (cost > 0 && oli.Quantity > 0) {
-        this.Cost_Subtotal_c = cost * oli.Quantity;
-      }
-      this.Cost_c = cost;
-      if (oli.UnitPrice__c > 0 && oli.Quantity > 0) {
-        oli.TotalPrice__c = oli.UnitPrice__c * oli.Quantity;
-      }
+            if (quo.OrderIsChange__c) {
+                if (initStringConcatenation != saveStringConcatenation) {
+                    verifyProductValidFlag = true;
+                }
+            }
 
-      PageObject.BSS_Category__c = oli.BSS_Category__c;
-      pageObject.Subtotal__c = oli.TotalPrice__c;
-      pageObject.PricebookEntryId = oli.PricebookEntryId;
-      latestInfo = New QELinelatestInfo();
-      latestInfo.ProductCode = oli.ProductCode__c;
-      latestInfo.ProductName = oli.PricebookEntry.Product2.Name;
-      latestInfo.SFDA_Status = oli.PricebookEntry.Product2.SFDA_Status__c;
-      latestInfo.Sales_Possibility = oli.PricebookEntry.Product2.Sales_Possibility__c;
-      // 澶氬勾淇濅慨 start
-      //澶栬锤澶氬勾淇� 鍙栦骇鍝佷富鏁版嵁鐨勫璐搁噾棰� 浠ュ強 鎶ヤ环 绮剧悽鎶�鏈� wql 2021/01/04 start 
-      latestInfo.ProductEntend_gurantee_period_all    =  oli.PricebookEntry.Product2.Entend_gurantee_period_all__c;
-      if (oli.Opportunity.Trade__c == '鍐呰部') {
-        latestInfo.Intra_Trade_Gurantee             =  oli.PricebookEntry.Product2.Intra_Trade_Gurantee_RMB__c;
-        latestInfo.Intra_Trade_Service              =  oli.PricebookEntry.Product2.Intra_Trade_Service_RMB__c;
+            // 浜у搧棣栬惀鐘舵�乑5(鍋滀骇) ---XHL 2021/02/07 Start
+            Map<String,Decimal> productIdQuantityMap = new  Map<String,Decimal>();
+            List<String> productIdList = new List<String>();
+            String productSegmentZ5 = opp.ProductSegment__c == 'BS' ? 'LS':opp.ProductSegment__c;
+            // String productSegment = opp.ProductSegment__c == 'BS' ? 'LS':opp.ProductSegment__c;
 
-        // 缁翠慨鍚堝悓鎶ヤ环
-        latestInfo.Maintenance_Price_Year = oli.PricebookEntry.Product2.Maintenance_Price_Year__c;
-      } else if (oli.Opportunity.Trade__c == '澶栬部') {
-        latestInfo.Intra_Trade_Gurantee             =  oli.PricebookEntry.Product2.Intra_Trade_Foreign_RMB__c;
-        latestInfo.Intra_Trade_Service              =  oli.PricebookEntry.Product2.NoDiscount_Foreign__c;
+            String FGSPStr = 'Machine'.equals(opp.Machine_Parts__c) ? 'FG':'SP';
+            // 浜у搧棣栬惀鐘舵�乑5(鍋滀骇) ---XHL 2021/02/07 End
+            for (QELine s:activities) {
+                if (s.pageObject.PricebookEntryId != null &&  s.productName != null && s.productName != '') {
+                    if (String.isBlank(s.pageObject.PricebookEntryId) == false) {
+                        String setName = s.pageObject.Set__c;
+                        Integer qty = 1;
+                        //XHL-20190426-UpdateStart
+                        if (!s.pageObject.SingleProduct__c && String.isNotBlank(setName)){
+                            String fieldName = setName.substring(3);
+                            fieldName = fieldName.indexOf('0') == 0 ? fieldName.substring(1) : fieldName;
+                            Decimal d_qty = (Decimal) quo.get('SetQty' + fieldName + '__c');
+                            qty = d_qty == null ? 1 : d_qty.intValue();
+                        } 
+                        //XHL-20190426-UpdateEnd
+                        QuoteLineItem ql = s.pageObject.clone();
+                        ql.QuoteId = q.Id;
+                        ql.Quantity = ql.Quantity ;
+                        if (is_hidden_all || is_hidden_user == true || is_dealer_user == true && s.hiddenflg == true) {
+                            ql.UnitPrice = s.salesPrice;
+                            ql.Discount = all_discount;
+                            if (s.customPrice != 0) {
+                                ql.Custom_Price__c = s.customPrice;
+                            }
+                        }
+                        ql.Custom_Price__c = ql.Custom_Price__c == null ? 0 : ql.Custom_Price__c;// * qty;
+                        ql.quoLiVerifyProductValid__c = verifyProductValidFlag;
+                        if (s.pageObject.SingleProduct__c) {
+                            singleProductList.add(ql);
+                        } else {
+                            qlist.add(ql);  
+                        }                        
+                        productIdList.add(s.pageObject.Product2Id);
+                        // 浜у搧棣栬惀鐘舵�乑5(鍋滀骇) ---XHL 2021/02/07 Start
+                        Decimal quantity = ql.Quantity;
+                        if (productIdQuantityMap.containsKey(s.pageObject.Product2Id)) {
+                            quantity += productIdQuantityMap.get(s.pageObject.Product2Id);
+                        }
+                        productIdQuantityMap.put(s.pageObject.Product2Id,quantity);
+                        // 浜у搧棣栬惀鐘舵�乑5(鍋滀骇) ---XHL 2021/02/07 End
+
+                        i++;
+                    }
+                }
+            }
+            if (productIdList.size() > 0) {
+                // 浜у搧棣栬惀鐘舵�乑5(鍋滀骇) ---XHL 2021/02/07 Start
+                Map<String,Decimal> productQuantityMap = new  Map<String,Decimal>();
+                List<Product2> getProductList = [SELECT Id,Name,ProductCode,NMPAStatus__c,ProductStatusFormula__c FROM Product2 WHERE Id IN:productIdList AND NMPAStatus__c = '鍋滀骇' AND ProductStatusFormula__c = '1'];
+
+                for (Product2 pro:getProductList) {
+
+                    Decimal productQuantity = productIdQuantityMap.get(pro.Id);
+                    String key = pro.ProductCode +'_'+ productSegmentZ5 +'_'+ FGSPStr;
+                    // String key = pro.ProductCode +'_'+ productSegment +'_'+ FGSPStr;
+                    
+
+                    productQuantityMap.put(key, productQuantity);
+                }
+                if (productQuantityMap.size() > 0) {
+                    String result = OrderWebService.ProductInventoryCheck(productQuantityMap);
+                    if (result != '1') {
+                        if (String.isBlank(errorMessage)) {
+                            errorMessage = '娉ㄦ剰锛侊紒锛� '+ result;
+                        } else {
+                            errorMessage += result; 
+                        }
+                    }    
+                }
+                // 浜у搧棣栬惀鐘舵�乑5(鍋滀骇) ---XHL 2021/02/07 End
+                
+            }
+            if (singleProductList.size() >0 ){
+                insert singleProductList;
+            }
+
+            if (qlist.size()>0) {
+                insert qlist;
+            }
+            
+            Quote quoUpd = [select id, Discount, Discount_Normal__c, Discount_Special__c,OrderIsChange__c from Quote where Id = : quoId1];
+            Decimal quoDis = quoUpd.Discount == null ? 0 : quoUpd.Discount;
+            Decimal quoDisN = quoUpd.Discount_Normal__c == null ? 0 : quoUpd.Discount_Normal__c;
+            if (productSegment == 'BS') {
+                system.debug('quoDis---->'+quoDis);
+                system.debug('quoDisN---->'+quoDisN);
+                quoUpd.Discount_Special__c = quoDis - quoDisN;
+                system.debug('quoUpd.Discount_Special__c---->'+quoUpd.Discount_Special__c);
+            } else {
+                quoUpd.Discount_Special__c = (quoDis - quoDisN) / (1 - quoDisN / 100);
+            }
+
+            quoUpd.QuoVerifyProductValid__c = verifyProductValidFlag;
+
+            update quoUpd;
+
+            List<QuoteLineItem> itemsRe = 
+                [Select Id,Product2Id,Product2.Name,Product2.ProductCode,Product2.Product_ECCode__c,Quantity,Subtotal,Discount,TotalPrice,PricebookEntryId,UnitPrice,Description,Set__c,Custom_Price__c,
+                        PricebookEntry.SalesPrice__c,PricebookEntry.SalesPriceA__c,PricebookEntry.SalesPriceB__c,PricebookEntry.SalesPriceC__c,Product2.ProductModels__c,PricebookEntry.Hidden_flag__c,
+                        Quote.Discount_Normal__c,SingleProduct__c,SetName__c,DontSingleProduct__c,
+                        Quote.Opportunity.DealerId__c
+                   From QuoteLineItem where Quoteid = :quoId1 Order by Id];
+            activities = new List<QELine>();
+            i=0;
+            QELine c = new QELine(i);
+
+            String includeEspecialProduct = '';
+            is_hidden_all = false;
+            if (itemsRe.size()>0) {
+                for (QuoteLineItem o:itemsRe) {
+
+                    if (o.DontSingleProduct__c != '1') {
+                        if (String.isBlank(includeEspecialProduct)) {
+
+                            includeEspecialProduct = o.DontSingleProduct__c;
+                        } else {
+                            includeEspecialProduct += ',' + o.DontSingleProduct__c;
+                        }
+                        specialerrorflg = true;
+                    }
+                    String setName = o.Set__c;
+                    Integer qty = 1;
+                    //XHL-20190426-UpdateStart
+                    if (!o.SingleProduct__c && String.isNotBlank(setName)) {
+                        String fieldName = setName.substring(3);
+                        fieldName = fieldName.indexOf('0') == 0 ? fieldName.substring(1) : fieldName;
+                        Decimal d_qty = (Decimal) quo.get('SetQty' + fieldName + '__c');
+                        qty = d_qty == null ? 1 : d_qty.intValue();
+                    } 
+                    //XHL-20190426-UpdateEnd
+                    c = new QELine(isService, o,i,o.Product2.Name,o.Product2.ProductCode,o.Product2.Product_ECCode__c,qty,o.Product2.ProductModels__c,o.SingleProduct__c,o.SetName__c);
+                    //c = new QELine(isService, o,i,o.Product2.Name,o.Product2.ProductCode,o.Product2.Product_ECCode__c,qty,o.Product2.ProductModels__c,quo.Discount_Normal__c);
+                    //specialDealer =  StaticParameter.specialDealerMap.containsKey(o.Quote.Opportunity.DealerId__c);
+                    specialDealer = IfspecialDealer(o.Quote.Opportunity.DealerId__c);
+                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '璇烽�夋嫨鐩爣瀹㈡埛----3>'+o.Quote.Opportunity.DealerId__c));
+                    if (specialDealer || is_hidden_user == true || is_dealer_user == true && c.hiddenflg == true) {
+                        c.pageObject.UnitPrice = 0;
+                        c.totalPrice = 0;
+                        c.customPrice = 0;
+                        system.debug('<---is_hidden_all---01>' + is_hidden_all);
+                        is_hidden_all = true;
+                        discount = 0;
+                    }
+                    activities.add(c);
+                    i++;
+
+                }
+            }
+            if (String.isNotBlank(includeEspecialProduct) && specialerrorflg) {
+                if(!StaticParameter.specialDealerMap1.containsKey(opp.DealerId__c)) {
+                    errormessage += '娉ㄦ剰锛侊紒锛� 鎶ヤ环浜у搧涓寘鍚壒娈婄殑鍗曞搧浜у搧[ ' +includeEspecialProduct+ ' ]';
+                }
+                //system.debug('errormessage__20190523__' + errormessage);
+            }
+
+            for (integer j=i;j<quoteEntryMaxLine;j++) {
+                c = new QELine(j);
+                activities.add(c);
+            }
+
+        }
+        if (quo.OrderIsChange__c) {
+            if (initStringConcatenation != saveStringConcatenation) {
+                verifyProductValidFlag = true;
+            }
+        }
+
+        List<Quote> quoListRe = 
+                [ SELECT Id,Name,QuoteNumber,Account.name,ExpirationDate,Subtotal,Discount,TotalPrice,GrandTotal,PrintPrice__c,ShippingHandling,
+                    DeliveryLeadTime__c,PaymentTerms__c,ValidDate__c,Warranty__c,SetName1__c,Shipment_Term__c,Shipment_Term2__c,
+                    SetName2__c,SetName3__c,SetName4__c,SetName5__c,SetName6__c,SetName7__c,SetName8__c,SetName9__c,SetName10__c,
+                    SetName11__c,SetName12__c,SetName13__c,SetName14__c,SetName15__c,SetName16__c,SetName17__c,SetName18__c,SetName19__c,
+                    SetName20__c,SetName21__c,SetName22__c,SetName23__c,SetName24__c,SetName25__c,SetName26__c,SetName27__c,SetName28__c,SetName29__c,
+                    SetName30__c,SetQty1__c,SetQty2__c,SetQty3__c,SetQty4__c,SetQty5__c,SetQty6__c,SetQty7__c,SetQty8__c,SetQty9__c,SetQty10__c,SetQty11__c,
+                    SetQty12__c,SetQty13__c,SetQty14__c,SetQty15__c,SetQty16__c,SetQty17__c,SetQty18__c,SetQty19__c,SetQty20__c,SetQty21__c,SetQty22__c,SetQty23__c,
+                    SetQty24__c,SetQty25__c,SetQty26__c,SetQty27__c,SetQty28__c,SetQty29__c,SetQty30__c,Comment__c,Custom_Price_Total__c,Custom_Price_Total_Text__c,Quote_Type__c,
+                    Main_Model__c,Main_Serial_Number__c,Service_Type__c,Contract_Number__c,Service_Date__c,Service_Finish_Date__c,Service_Engineer_Sign__c,
+                    Service_Pickup_Sign__c,Service_Check_Sign__c,Service_Location__c,Service_Status__c,Service_Content__c, Is_upload__c, Total_Price_Text__c,
+                    Discount_Normal__c,Discount_Special__c,OrderIsChange__c
+                    FROM Quote Where Id =:quoId1];
+        if (quoListRe.size() > 0) {
+            quo = quoListRe[0];
+        }
+
+system.debug('=====is_hidden_all:' + is_hidden_all);
+        if (is_hidden_all) {
+            discount = quo.totalPrice.setScale(2, System.RoundingMode.HALF_UP);
+        } else {
+            discount = quo.Discount == null ? 0 : quo.Discount;
+            //discount = quo.Discount_Special__c == null ? 0 : quo.Discount_Special__c;
+            discount = discount.setScale(2, System.RoundingMode.HALF_UP);
+        }
+
+system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆Welcome Opportunity class!!鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆');
+
+        //Opportunity--------------------------------------------
+        Opportunity o = New Opportunity();
+        List<Opportunity> os = New List<Opportunity>();
+        os = [select Id From Opportunity Where Id =:oppid];
+        if (os.size()>0) {
+            o = os[0];
+            if (decideFlg == false) {
+                o.SyncedQuoteId = quoId1;
+                o.Quote_PaymentTerms_Text__c = paymentTermsMap.get(quo.PaymentTerms__c);
+                o.is_hidden__c = is_hidden_all || specialDealer;
+                if (doDecide == true) {
+                    o.Is_Decided__c = true;
+                    o.Quote_Decide_User__c = UserInfo.getUserId();
+                }
+                o.IE_Discount_Normal__c = quo.Discount_Normal__c;
+                o.IE_Discount_Special__c = quo.Discount_Special__c;
+                system.debug('IE_Discount_Special__c--->'+o.IE_Discount_Special__c);
+                update o;
+            }
+       
+        }
+if (quoId == null) {
+    quoId = quoId1;//q.Id;
+}
+        return true;
+    }
+
+    //opp銇敾闈€伄鍊ゃ倰瑷畾
+    private void setOppFromOppInfo() {
+
+    }
+
+    public PageReference csvExport() {
+        if (fileName == null || fileName == '') {
+            errorflg = true;
+            errormessage = '璇疯緭鍏ラ厤缃鍑烘枃浠跺悕銆�';
+            return null;
+        }
+        Date dExpirationDate = quo.ExpirationDate;
+        strExpirationDate = dExpirationDate == null ? '' : dExpirationDate.format();
+        csv_activities = new List<QELine>();
+        for (QELine s : activities) {
+            if (s.pageObject.PricebookEntryId != null &&  s.productName != null && s.productName != '') {
+                csv_activities.add(s);
+            }
+        }
+        PageReference pr = page.QuoteCSVExport;
+        return pr;
+    }
+
+    public PageReference csvRead() {
+
+        String strFile = '';
+        List<String> listFile = new List<String>();
+        errorflg = false;
+        errormessage = null;
+try {
+        if (contentFile != null) {
+            strFile = contentFile.toString();
+            listFile = strFile.split('\n');
+system.debug('=====strFile:' + strFile);
+        } else {
+            errorflg = true;
+            errormessage = '璇诲彇鍐呭涓虹┖銆�';
+            return null;
+        }
+} catch (Exception ex) {
+    errorflg = true;
+    errormessage = System.Label.Error_Message02;
+    return null;
+}
+for (Integer i = 0; i < listFile.size(); i++) {
+    system.debug('=====listFile_' + i + ':' + listFile[i]);
+}
+        List<String[]> arrayFile = new List<String[]>();
+        String firstline = listFile[0];
+        if (firstline.indexOf('濂楄/鍗曞搧') < 0) {
+            errorflg = true;
+            errormessage = '璇诲彇鍐呭鏍煎紡涓嶆纭��';
+            return null;
+        } else {
+            String strReplace = '';
+            List<String> temp = strFile.split('"');
+            for (Integer i = 0; i < temp.size(); i++) {
+                if (math.mod(i, 2) == 1) {
+                    temp[i] = temp[i].replace(',', '#%&');
+                }
+                strReplace += temp[i];
+            }
+system.debug('=====strReplace:' + strReplace);
+            List<String> listReplace = strReplace.split('\n');
+            for (String replace : listReplace) {
+system.debug('=====replace:' + replace);
+                if (replace != '\r' && replace.length() > 0) {
+                    replace = replace.replace('\r', '');
+                    String[] a = replace.split(',', -1);
+                    for (Integer i = 0; i < a.size(); i++) {
+                        if (a[i].indexOf('#%&') > 0) {
+                            a[i] = a[i].replace('#%&', ',');
+                        }
+                    }
+                    if (specialDealer) {
+                        if (a.size() != 4) {
+                            errorflg = true;
+                            errormessage = '璇诲彇鍐呭鏍煎紡涓嶆纭�侺ine:' + arrayFile.size();
+                            return null;
+                        }
+                    }  else {
+                        if (a.size() != 5) {
+                            errorflg = true;
+                            errormessage = '璇诲彇鍐呭鏍煎紡涓嶆纭�侺ine:' + arrayFile.size();
+                            return null;
+                        }
+
+                    }
+                    //if (a.size() != 5) {
+                    //    errorflg = true;
+                    //    errormessage = '璇诲彇鍐呭鏍煎紡涓嶆纭�侺ine:' + arrayFile.size();
+                    //    return null;
+                    //}
+                    arrayFile.add(a);
+                }
+            }
+        }
+
+        List<String> prdCodeList = new List<String>();
+
+        //XHL-20190426-UpdateStart
+        Map<String,String> productSetCodeMap = new Map<String,String>();
+
+        for (Integer i = 1; i < arrayFile.size(); i++) {
+
+            if (arrayFile[i] != null && arrayFile[i].size() > 1 && arrayFile[i][0] != '') {
+                try {
+                    if (String.isNotBlank(arrayFile[i][3])) {
+                        Decimal quantity1 = Decimal.valueOf(arrayFile[i][3]);
+                    }
+                    if (!specialDealer) {
+                        if (String.isNotBlank(arrayFile[i][4])) {
+                            Decimal discount1 = Decimal.valueOf(arrayFile[i][4]);
+                        }
+                    }
+
+                } catch (Exception e) {
+                    errorflg = true;
+                    if (arrayFile[i][0] != singleProduct ) {
+                        errorMap.put(arrayFile[i][1],'[' + arrayFile[i][1] +']閰嶅鐨勬暟閲忔垨鎶樻墸瀛樺湪闈炴暟瀛楋紝璇风‘璁�;');    
+                    } else {
+                        errorMap.put(arrayFile[i][1],'[' + arrayFile[i][1] +']浜у搧鐨勬暟閲忔垨鎶樻墸瀛樺湪闈炴暟瀛楋紝璇风‘璁�;');
+                    } 
+                    continue;
+                }
+                
+                if (arrayFile[i][0] != singleProduct ) {
+
+                    productSetCodeMap.put(arrayFile[i][1], arrayFile[i][3] + ';'+arrayFile[i][4]);    
+                } else {
+
+                    String tmp = '00000000000' + arrayFile[i][1];
+                    prdCodeList.add(tmp);
+                    prdCodeList.add(arrayFile[i][1]);
+                }
+                
+            }
+        }
+
+        activities = new List<QELine>();
+        Integer no =0;
+        emptyData();
+        if (productSetCodeMap.size() > 0) {
+            
+            acquireProductSetId(productSetCodeMap);
+            no =  singleNo == null ? 0 : singleNo;
+        } 
+        //XHL-20190426-UpdateEnd
         
 
-        // 缁翠慨鍚堝悓鎶ヤ环
-        latestInfo.Maintenance_Price_Year = oli.PricebookEntry.Product2.Repair_Contract_USD__c;
-      }
-      //澶栬锤澶氬勾淇� 鍙栦骇鍝佷富鏁版嵁鐨勫璐搁噾棰� 浠ュ強 鎶ヤ环 绮剧悽鎶�鏈� wql 2021/01/04 end
-        latestInfo.GuranteeType                        =  oli.PricebookEntry.Product2.GuranteeType__c;
-      // 澶氬勾淇濅慨 end
-      if (oli.PricebookEntry.Product2.Packing_list_manual__c != null) {
-        latestInfo.Specifications = integer.valueof(oli.PricebookEntry.Product2.Packing_list_manual__c + '');
-      }
-      latestInfo.ListPrice = oli.Product_ListPrice__c;
-      latestInfo.Cost = oli.Product_Cost__c;
-      //涓嶅彲鍙栨秷澶氬勾淇� 
-      latestInfo.CanNotCancelledGurantee  = oli.PricebookEntry.Product2.CanNotCancelledGurantee__c;
-      this.changed_name = false;
-      this.changed_sfda = false;
-      this.changed_list = false;
-      this.changed_cost = false;
-      this.haveno_Register = false;
-      this.wrong_Register  = false;
-    }
-    public QELine(QuoteLineItem qli, Integer i, String copyQuoId) {
-      //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, ' qli Id__c=' + qli.PricebookEntry.Product2Id));
-      pageObject = qli.clone();
-      pageObject.Id__c = qli.PricebookEntry.Product2Id;
-      pageObject.Quantity__c = qli.Quantity;
-      //ET淇冮攢鏍囪 start
-      // pageObject.ETPromotionalFlag__c = qli.ETPromotionalFlag__c;
-      //ET淇冮攢鏍囪 end
-      if (copyQuoId != null) {
-        pageObject.SFDA_Status__c = qli.PricebookEntry.Product2.SFDA_Status__c;
-        pageObject.Name__c = qli.PricebookEntry.Product2.Name;
-        //PageObject.PricebookEntry.Product2.Packing_list_manual__c = qli.PricebookEntry.Product2.Packing_list_manual__c;
-      }
-      this.lineNo = i;
-      this.Asset_Model = qli.Asset_Model_No__c;
-      if (qli.Cost__c > 0 && qli.Quantity > 0) {
-        this.Cost_Subtotal_c = qli.Cost__c * qli.Quantity;
-      }
-      //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 Start
-      this.VenderName = qli.PricebookEntry.Product2.VenderName__c;
+        
 
-      //SFDC鍋滄棰勮 lt 20211009  鈶犱笉鑳藉畾涔塪ate鍙橀噺 鍥犱负鍓嶅彴杩斿洖鐨勬槸String鏃ユ湡  鈶″皢util閲岀殑鏂规硶杞负鏃ユ湡鏍煎紡 start
-      if(qli.PricebookEntry.Product2.Estimated_ConsumptionDueDate__c != null){
-        this.Estimated_ConsumptionDueDate = NFMUtil.formatDate2StrSpo(qli.PricebookEntry.Product2.Estimated_ConsumptionDueDate__c).replaceAll('-','/');
-      }else{
-        this.Estimated_ConsumptionDueDate = '';
-      }
-      //SFDC鍋滄棰勮 lt 20211009 end
-
-            if(VenderName==null||VenderName==''){
-                this.VenderName =' 鏃� ';
-            }else{
-                //this.VenderName = qli.PricebookEntry.Product2.VenderName__c;
+system.debug('=====prdCodeList:' + prdCodeList);
+        //return null;
+        Map<String, Product_Search__c> psMap = new Map<String, Product_Search__c>(); // key銇孭roductCode銇с仚銆�
+        List<String> forSelect = new List<String>();
+        List<Product_Search__c> psList = [
+            select Id, Name, ProductCode__c, Product_ECCode__c, ProductDescription__c, ProductStatus__c, Product__c, ProductModels1__c
+              from Product_Search__c
+             where ProductCode__c in :prdCodeList];
+        String errProduct = '';
+        Map<String,String> errProductMap = new Map<String,String>();
+        for (Product_Search__c ps : psList) {
+            String pc = ps.ProductCode__c;
+            if (pc.startsWith('00000000000')) {
+                pc = pc.substring(11);
+                psMap.put(pc, ps);
             }
-      //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 Start
-      //涓嶅彲鍙栨秷澶氬勾淇�
-      this.CanNotCancelledGurantee = qli.PricebookEntry.Product2.CanNotCancelledGurantee__c;
-      //闃胯タ璧涘
-      this.Is_DangerousChemicals = qli.PricebookEntry.Product2.Is_DangerousChemicals__c;
-      //************************************liukun*****************************************************//
-      this.StorageStatus = qli.PricebookEntry.Product2.StorageStatus__c;
-
-      this.ListPrice_Page = qli.ListPrice__c;
-      this.Cost_c = qli.Cost__c;
-      pageObject.Subtotal__c = qli.TotalPrice__c;
-      pageObject.UnitPrice_Page__c = qli.UnitPrice__c;
-      latestInfo = New QELinelatestInfo();
-      latestInfo.ProductCode = qli.ProductCode__c;
-      latestInfo.ProductName = qli.PricebookEntry.Product2.Name;
-
-      latestInfo.SFDA_Status = qli.PricebookEntry.Product2.SFDA_Status__c;
-      // 澶氬勾淇濅慨 start
-
-      latestInfo.ProductEntend_gurantee_period_all    =  qli.PricebookEntry.Product2.Entend_gurantee_period_all__c;
-      //澶栬锤澶氬勾淇� 鍙栦骇鍝佷富鏁版嵁涓婄殑閲戦鍙婃姤浠� 绮剧悽鎶�鏈� wql start
-      if(qli.Quote.Opportunity.Trade__c == '鍐呰部'){
-        latestInfo.Intra_Trade_Gurantee             =  qli.PricebookEntry.Product2.Intra_Trade_Gurantee_RMB__c;
-        latestInfo.Intra_Trade_Service             =  qli.PricebookEntry.Product2.Intra_Trade_Service_RMB__c;
-        //缁翠慨鍚堝悓鎶ヤ环
-        //HWAG-BLDE4M decide鍚庢垚鏈负绌� 绮剧悽鎶�鏈� 20200227 start
-        if(qli.PricebookEntry.Product2.Maintenance_Price_Year__c == null){
-          latestInfo.Maintenance_Price_Year = 0;
-        }else{
-          latestInfo.Maintenance_Price_Year = qli.PricebookEntry.Product2.Maintenance_Price_Year__c;
+            psMap.put(ps.ProductCode__c, ps);
+            forSelect.add(ps.Product__c);
+            //system.debug(ps.ProductCode__c + ps.ProductStatus__c+'@@@@@@@->>>');
+            if(ps.ProductStatus__c == '0'){
+                system.debug(ps.ProductCode__c + ps.ProductStatus__c+'@@@@@@@');
+                errorflg = true;
+                errProduct += ps.ProductCode__c + ',';
+                errProductMap.put(ps.ProductCode__c,ps.ProductCode__c);
+            }
         }
-        //HWAG-BLDE4M decide鍚庢垚鏈负绌� 绮剧悽鎶�鏈� 20200227 end
-      }else if(qli.Quote.Opportunity.Trade__c == '澶栬部'){
-          latestInfo.Intra_Trade_Gurantee             =  qli.PricebookEntry.Product2.Intra_Trade_Foreign_RMB__c;
-          latestInfo.Intra_Trade_Service              =  qli.PricebookEntry.Product2.NoDiscount_Foreign__c;
-          //缁翠慨鍚堝悓鎶ヤ环
-          //HWAG-BLDE4M decide鍚庢垚鏈负绌� 绮剧悽鎶�鏈� 20200227 start
-          if(qli.PricebookEntry.Product2.Maintenance_Price_Year__c == null){
-            latestInfo.Maintenance_Price_Year = 0;
-          }else{
-            latestInfo.Maintenance_Price_Year = qli.PricebookEntry.Product2.Repair_Contract_USD__c;
-          }
-          //HWAG-BLDE4M decide鍚庢垚鏈负绌� 绮剧悽鎶�鏈� 20200227 end
-      }
-      //澶栬锤澶氬勾淇� 鍙栦骇鍝佷富鏁版嵁涓婄殑閲戦鍙婃姤浠� 绮剧悽鎶�鏈� wql end
-      
-      latestInfo.GuranteeType                         =  qli.PricebookEntry.Product2.GuranteeType__c;
-      //涓嶅彲鍙栨秷澶氬勾淇� 
-      latestInfo.CanNotCancelledGurantee  = qli.PricebookEntry.Product2.CanNotCancelledGurantee__c;
-      // 璁℃彁閲戦
-      this.Maintenance_Price_Year                     = qli.Maintenance_Price_Year__c;
-      this.GuranteePrice                              =  qli.GuranteePrice__c;
-      this.ProductGuranteePrice                       =  qli.ProductGuranteePrice__c;
-      // 澶氬勾淇濅慨 end
-      latestInfo.Sales_Possibility = qli.PricebookEntry.Product2.Sales_Possibility__c;
-      if (qli.PricebookEntry.Product2.Packing_list_manual__c != null) {
-        latestInfo.Specifications = integer.valueof(qli.PricebookEntry.Product2.Packing_list_manual__c + '');
-      }
-      latestInfo.ListPrice = qli.Product_ListPrice__c;
-      latestInfo.Cost = qli.Product_Cost__c;
-      //********************Insert [OLY_OCM-228] [20160706] [璧靛痉鑺砞 Start********************//
-      if (qli.PricebookEntry.Product2.Packing_list_manual__c != null) {
-        this.Specifications = integer.valueof(qli.PricebookEntry.Product2.Packing_list_manual__c + '');
-      }
-      //********************Insert [OLY_OCM-228] [20160706] [璧靛痉鑺砞 End**********************//
-      this.changed_name = false;
-      this.changed_sfda = false;
-      this.changed_list = false;
-      this.changed_cost = false;
-      this.haveno_Register = false;
-      this.wrong_Register  = false;
+
+        if (errorflg == true && errProduct != '') {
+            errProduct = errProduct.substring(0, errProduct.length() - 1);
+            errorMessage = '浜у搧鐘舵�佷负鏃犳晥锛屼笉鑳戒娇鐢ㄣ�備骇鍝侊細' + errProduct + '璇风‘璁�;';
+            errorMap.put(errorMessage,errorMessage);
+            //return null;
+        }
+        system.debug('errorflg---->11111'+errorMessage);
+        Map<String, PricebookEntry> pbeMap = new Map<String, PricebookEntry>(); // key銇孭roductCode銇с仚銆�
+        List<PricebookEntry> pbeList = [
+            select Id, Product2Id, ProductCode, Product2.Product_ECCode__c, Product2.Dummy__c, CostPrice__c, SalesPrice__c, SalesPriceA__c, SalesPriceB__c, SalesPriceC__c, Hidden_flag__c
+              from PricebookEntry
+             where Pricebook2Id = :pricebook2Id
+               and CurrencyIsoCode = :currencyIsoCode
+               and Product2.ManualHidden__c = false
+               and Product2Id in :forSelect];
+        system.debug('forSelect_1_1_1_1_1_' + forSelect);
+        system.debug('pbeList_2_2_2_2_2_2_2_' + pbeList);
+        
+        for (PricebookEntry pbe : pbeList) {
+            String pc = pbe.ProductCode;
+            if ((pbe.CostPrice__c == 0 && pbe.Product2.Dummy__c == false) || pbe.SalesPrice__c == 0) {
+                errorflg = true;
+                errProduct += pbe.productCode + ',';
+            } else {
+                if (pc.startsWith('00000000000')) {
+                    pc = pc.substring(11);
+                    pbeMap.put(pc, pbe);
+                }
+                pbeMap.put(pbe.ProductCode, pbe);
+            }
+        }
+
+        if (arrayFile.size() > 1) {
+            //XHL-20190426-UpdateStart
+            for (Integer line = 1; line < arrayFile.size(); line++) {
+                
+                if (arrayFile[line][0] == singleProduct) {
+
+                    Product_Search__c ps = psMap.get(arrayFile[line][1]);
+                    PricebookEntry pbe = pbeMap.get(arrayFile[line][1]);
+                    if (ps == null || pbe == null) {
+                        errorflg = true;
+                        errProduct += arrayFile[line][1] + ',';
+                        errorMap.put(arrayFile[line][2],errProduct);
+                    }    
+                }
+                
+            }
+            
+            if (errorflg) {
+                system.debug('errorflg---->22222'+errorMessage);
+                errorMessage = '';
+                String intermediateVariable = '';
+
+                for (String errorKey :errorMap.keySet()) {
+
+                    errProduct = errorMap.get(errorKey).substring(0, errorMap.get(errorKey).length()-1);
+                    system.debug('ceshi------>' + errProduct);
+                    if (errProduct.endsWith('!!!')) {
+                        errorMessage += errorMap.get(errorKey);
+                    } else if(errProduct.startsWith('error')){
+                        errorMessage += errorMap.get(errorKey);
+                    }else if(errProduct.endsWith('璇风‘璁�')){
+                        errorMessage += errorMap.get(errorKey);
+                    }else {
+                        if (String.isBlank(intermediateVariable)) {
+                            intermediateVariable = errorKey;
+                        } else {
+                            intermediateVariable += ',' + errorKey;
+                        }
+                        
+                    }
+                       
+                }
+                if (String.isNotBlank(intermediateVariable)) {
+                    errorMessage += '[' + intermediateVariable + ']鐨勪骇鍝佷环鏍间俊鎭笉姝g‘锛屼笉鑳戒娇鐢�;'; 
+                }
+                //return null ;
+            }
+            
+            QELine c = new QELine(no);
+            is_hidden_all = false;
+            boolean isSingleProduct = false;
+            for (Integer line = 1; line < arrayFile.size(); line++) {
+                if (arrayFile[line][0] == singleProduct ){
+                    if (errorMap.containsKey(arrayFile[line][2])) {
+                        continue;
+                    }
+
+                    isSingleProduct = true;
+                    Product_Search__c ps = psMap.get(arrayFile[line][1]);
+                    PricebookEntry pbe = pbeMap.get(arrayFile[line][1]);
+                    system.debug('=====key:' + arrayFile[line][1]);
+                    system.debug('=====ps:' + ps);
+                    system.debug('=====pbe:' + pbe);
+                    system.debug('ps.ProductCode__c--->'+ps.ProductCode__c );
+                    system.debug('ps.Product__c--->'+ps.Product__c);
+                    //c = new QELine(isService, no, arrayFile[line][0], ps.Name, ps.ProductCode__c, ps.Product_ECCode__c, ps.Product__c, pbe, arrayFile[line][3], arrayFile[line][4], ps.ProductModels1__c, quo.Discount_Normal__c);
+                    if (errProductMap != null && errProductMap.size() > 0) {
+                        if (errProductMap.containsKey(arrayFile[line][1])) {
+                            continue;
+                        }
+                    }
+                    if (specialDealer) {
+                        c = new QELine(isService, no, singleProduct, ps.Name, ps.ProductCode__c, ps.Product_ECCode__c, ps.Product__c, pbe, arrayFile[line][3],'', ps.ProductModels1__c, isSingleProduct, ps.ProductDescription__c, '');
+                    } else {
+                        c = new QELine(isService, no, singleProduct, ps.Name, ps.ProductCode__c, ps.Product_ECCode__c, ps.Product__c, pbe, arrayFile[line][3], arrayFile[line][4], ps.ProductModels1__c, isSingleProduct, ps.ProductDescription__c, '');
+                    }
+                    //c = new QELine(isService, no, singleProduct, ps.Name, ps.ProductCode__c, ps.Product_ECCode__c, ps.Product__c, pbe, arrayFile[line][3], arrayFile[line][4], ps.ProductModels1__c,isSingleProduct,ps.ProductDescription__c,'');
+                    if (specialDealer || is_hidden_user == true || is_dealer_user == true && c.hiddenflg == true) {
+                        c.pageObject.UnitPrice = 0;
+                        c.totalPrice = 0;
+                        system.debug('<---is_hidden_all--->02' + is_hidden_all);
+                        is_hidden_all = true;
+                        discount = 0;
+                    }
+                    activities.add(c);
+                    
+                    no++;  
+
+                }
+                
+            }
+            //XHL-20190426-UpdateEnd
+            for (integer j = no; j < quoteEntryMaxLine; j++) {
+                c = new QELine(j);
+                activities.add(c);
+            }
+
+        } else {
+            for (no = 0; no < quoteEntryMaxLine; no++) {
+                QELine active_activity = new QELine(no);
+                activities.add(active_activity);
+            }
+        }
+        system.debug('quoName: '+quo.Name);
+        return null;
     }
 
-    // TODO Subtotal__c銆佷互鍓嶃伄銉偢銉冦偗銈掔⒑瑾�
-    /*public QELine(Integer i, String PricebookEntryId,
-                  String Asset_Model, String StorageStatus,
-                  String ProductCode, String Id_c,
-                  String SFDA_Status_c, String Sales_Possibility_c,
-                  String Name_c, String BSS_Category_c,
-                  Integer Quantity, Decimal ListPrice_c,
-                  Decimal UnitPrice_c, Decimal Cost_c,
-                  Decimal Packing_list_manual
-                 ) {
-        pageObject = New QuoteLineItem();
-        pageObject.Quantity__c = Quantity;
-        this.lineNo = i;
-        this.Asset_Model = Asset_Model;
-        this.Sales_Possibility = Sales_Possibility_c;
+    public boolean dataCheck() {
+        system.debug('鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆Welcome to dataCheck class!!鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆鈼嬧棆');
+        errorflg = false;
+        errormessage = null;
+        Boolean error = false;
+        List<String> product2Ids = New List<String>();
+        Map<String,String> mapSet = new Map<String,String> ();
+        Map<Id, Product_Search__c> prd2LatestValMap = new Map<Id, Product_Search__c>();
 
-        this.StorageStatus = StorageStatus;
-
-        pageObject.Id__c = Id_c;
-        pageObject.SFDA_Status__c = SFDA_Status_c;
-        pageObject.Name__c = Name_c;
-        pageObject.BSS_Category__c = BSS_Category_c;
-        this.ListPrice_Page = ListPrice_c;
-        pageObject.UnitPrice_Page__c = UnitPrice_c;
-        pageObject.Subtotal__c = UnitPrice_c * Quantity;
-        //PageObject.PricebookEntry.Product2.Packing_list_manual__c = Packing_list_manual;
-        this.Cost_c = Cost_c;
-        // TODO katsu 銇仠銇撱亾 > 0 銇垽鏂伅銇勩倝銇亜锛�
-        this.Cost_Subtotal_c = Cost_c * Quantity;
-        pageObject.PricebookEntryId = PricebookEntryId;
-        latestInfo = New QELinelatestInfo();
-        latestInfo.ProductCode = ProductCode;
-        latestInfo.ProductName = Name_c;
-        latestInfo.SFDA_Status = SFDA_Status_c;
-        latestInfo.Sales_Possibility = Sales_Possibility_c;
-        latestInfo.ListPrice = this.ListPrice_Page;
-        latestInfo.Cost = pageObject.Cost__c;
-        if (Packing_list_manual != null) {
-            latestInfo.Specifications = integer.valueof('' + Packing_list_manual);
+        //鎶ヤ环浼樺寲 2021-05-08 start
+        String shter = quo.Shipment_Term__c;
+        if(String.isBlank(shter) && opp.Trade_Type_D__c =='Tax Exemption'){
+            errorflg = true;
+            errorMessage = '鍥介檯璐告槗鏉′欢涓嶈兘涓虹┖锛�';
+            return false;
         }
-        this.changed_name = false;
-        this.changed_sfda = false;
-        this.changed_list = false;
-        this.changed_cost = false;
-        this.haveno_Register = false;
-        this.wrong_Register  = false;
-    }
-    */
 
-    //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 Start 澧炲姞瀛楁
-    // 澶氬勾淇濅慨 start
-    public QELine(Integer i,Boolean Is_DangerousChemicals,Boolean CanNotCancelledGurantee,String VenderName,
-                  Date Estimated_ConsumptionDueDate,   //20211009 lt add
-                  String PricebookEntryId,
-      //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 end 澧炲姞瀛楁
-                  String Asset_Model, String StorageStatus,
-                  String ProductCode, String Id_c,
-                  String SFDA_Status_c, String Sales_Possibility_c,
-                  String Name_c, String BSS_Category_c,
-                  Integer Quantity, Decimal ListPrice_c,
-                  Decimal UnitPrice_c, Decimal Cost_c,
-                  Decimal Packing_list_manual
-                  , Decimal Entend_gurantee_period_all
-                  , decimal ProductGuranteePrice
-                  , string GuranteeType
-                  , Decimal productServicePrice
-                  , Decimal productMaintenance_Price_Year
-                 ) {
-      pageObject = New QuoteLineItem();
-      pageObject.Quantity__c = Quantity;
-      this.lineNo = i;
-      this.Asset_Model = Asset_Model;
-      this.Sales_Possibility = Sales_Possibility_c;
-
-      //SFDC鍋滄棰勮 lt 20211009  鈶犱笉鑳藉畾涔塪ate鍙橀噺 鍥犱负鍓嶅彴杩斿洖鐨勬槸String鏃ユ湡  鈶″皢util閲岀殑鏂规硶杞负鏃ユ湡鏍煎紡 start
-      if(Estimated_ConsumptionDueDate != null){
-        this.Estimated_ConsumptionDueDate = NFMUtil.formatDate2StrSpo(Estimated_ConsumptionDueDate).replaceAll('-','/');
-      }else{
-        this.Estimated_ConsumptionDueDate = '';
-      }
-      //SFDC鍋滄棰勮 lt 20211009 end
-
-      this.StorageStatus = StorageStatus;
-
-      pageObject.Id__c = Id_c;
-      pageObject.SFDA_Status__c = SFDA_Status_c;
-      pageObject.Name__c = Name_c;
-      pageObject.BSS_Category__c = BSS_Category_c;
-      this.ListPrice_Page = ListPrice_c;
-      pageObject.UnitPrice_Page__c = UnitPrice_c;
-      pageObject.Subtotal__c = UnitPrice_c * Quantity;
-
-      //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 Start
-       system.debug('VenderName=========='+VenderName);
-        if(VenderName==null||VenderName==''){
-            this.VenderName =' 鏃� ';
-        }else{
-            this.VenderName = VenderName;
+        String shter2 = quo.Shipment_Term2__c;
+        if(String.isBlank(shter2) && opp.Trade_Type_D__c =='Tax Exemption'){
+            errorflg = true;
+            errorMessage = '鍥介檯璐告槗鏉′欢2涓嶈兘涓虹┖锛�';
+            return false;
         }
-      //涓嶅彲鍙栨秷澶氬勾淇�
-      this.CanNotCancelledGurantee = CanNotCancelledGurantee;
-      //闃胯タ璧涘
-      this.Is_DangerousChemicals = Is_DangerousChemicals;
-      //CHAN-BKU3XH 妫�鏌ユ槸鍚﹀瓨鍦ㄤ笉鏄悓涓�涓緵閿�鍟嗗悕绉� 绮剧悽鎶�鏈� 2020/02/17 end
-      // 澶氬勾淇濅慨 start
-      pageObject.ProductEntend_gurantee_period_all__c = Entend_gurantee_period_all;
-      pageObject.productServicePrice__c               = productServicePrice;
-      pageObject.GuranteeType__c                      = GuranteeType;
-      // 璁℃彁閲戦
-      this.ProductGuranteePrice                       =  ProductGuranteePrice;
-      // 缁翠慨鍚堝悓鎶ヤ环
-      this.Maintenance_Price_Year                     = productMaintenance_Price_Year;
-      // 澶氬勾淇濅慨 end
-      //PageObject.PricebookEntry.Product2.Packing_list_manual__c = Packing_list_manual;
-      this.Cost_c = Cost_c;
-      // TODO katsu 銇仠銇撱亾 > 0 銇垽鏂伅銇勩倝銇亜锛�
-      this.Cost_Subtotal_c = Cost_c * Quantity;
-      pageObject.PricebookEntryId = PricebookEntryId;
-      latestInfo = New QELinelatestInfo();
-      latestInfo.ProductCode = ProductCode;
-      latestInfo.ProductName = Name_c;
+        //鎶ヤ环浼樺寲 2021-05-08 end
 
-      latestInfo.SFDA_Status = SFDA_Status_c;
-      latestInfo.Sales_Possibility = Sales_Possibility_c;
-      latestInfo.ListPrice = this.ListPrice_Page;
-      latestInfo.Cost = pageObject.Cost__c;
-      // 澶氬勾淇濅慨 start
-      latestInfo.ProductEntend_gurantee_period_all    =  Entend_gurantee_period_all;
-      latestInfo.Intra_Trade_Gurantee             =  ProductGuranteePrice;
-      latestInfo.Intra_Trade_Service              =  productServicePrice;
-      latestInfo.GuranteeType                         =  GuranteeType;
-      latestInfo.Maintenance_Price_Year               =  productMaintenance_Price_Year;
-      //涓嶅彲鍙栨秷澶氬勾淇�
-      latestInfo.CanNotCancelledGurantee = CanNotCancelledGurantee;
-      //闃胯タ璧涘
-      latestInfo.Is_DangerousChemicals = Is_DangerousChemicals;
-      // 澶氬勾淇濅慨 end
+        String qname = quo.Name;
+        if (qname == null || qname.trim().length() == 0) {
+            errorflg = true;
+            errorMessage = '璇疯緭鍏ユ姤浠峰悕绉帮紒';
+            return false;
+        }
+        String qpaymentTerms = quo.PaymentTerms__c;
+        if (qpaymentTerms == null || qpaymentTerms.trim().length() == 0) {
+            errorflg = true;
+            errorMessage = '璇疯緭鍏ヤ粯娆炬潯浠讹紒';
+            return false;
+        }
+        Decimal qdeliveryLeadTime = quo.DeliveryLeadTime__c;
+        if (qdeliveryLeadTime == null || qdeliveryLeadTime <= 0) {
+            errorflg = true;
+            errorMessage = '璇疯緭鍏ヤ氦璐у懆鏈燂紒';
+            return false;
+        }
+        Decimal qwarranty = quo.Warranty__c;
+        if (qwarranty == null || qwarranty <= 0) {
+            errorflg = true;
+            errorMessage = '璇疯緭鍏ヤ繚淇湡锛�';
+            return false;
+        }
+        Date qexpirationDate = quo.ExpirationDate;
+        if (qexpirationDate == null) {
+            errorflg = true;
+            errorMessage = '璇疯緭鍏ユ姤浠峰埌鏈熸棩鏈燂紒';
+            return false;
+        }
+        Decimal qcustomPriceTotal = quo.Custom_Price_Total_Text__c;
+        if (qcustomPriceTotal == null || qcustomPriceTotal == 0) {
+            errorflg = true;
+            errorMessage = '璇疯緭鍏ュ鎴锋�讳环';
+            return false;
+        }
+
+        if (is_hidden_all) {
+            quo.Total_Price_Text__c = discount;
+            system.debug('discount----->123'+discount);
+        }
+system.debug('=====quo.Total_Price_Text__c:' + quo.Total_Price_Text__c);
+        if (is_hidden_all && (quo.Total_Price_Text__c == null || quo.Total_Price_Text__c <= 0)) {
+            errorflg = true;
+            errorMessage = '鎬讳环涓嶆纭紝璇风‘璁わ紒';
+            return false;
+        }
+
+        if (activities.size()>0) {
+            for (QELine a:activities){
+                if (String.isBlank(a.pageObject.Product2Id) == false) {
+                    product2Ids.add(a.pageObject.Product2Id);
+                }
+                String tmpSet = a.pageObject.Set__c;
+                if (tmpSet != null && tmpSet != '') {
+                    String tmpSetId = tmpSet.substring(2);
+                    if (!mapSet.containsKey(tmpSetId)) {
+                        mapSet.put(tmpSetId,tmpSet);
+                    }
+                }
+            }
+
+            Map<String,String> mapHeaderSet = new Map<String,String> ();
+            Map<String,Decimal> mapHeaderQty = new Map<String,Decimal> ();
+            for (Integer i = 1; i <= 30; i++) {
+                String field = String.valueOf(i);
+                field = '00' + field;
+                field = field.substring(field.length() - 2);
+                mapHeaderSet.put('set' + field, (String) quo.get('SetName' + i + '__c'));
+                mapHeaderQty.put('set' + field, (Decimal) quo.get('SetQty' + i + '__c'));
+            }
+
+            system.debug('mapSet class========>' + mapSet);
+            system.debug('mapSet class========>' + mapSet.size());
+            system.debug('mapHeaderSet class========>' + mapHeaderSet);
+            system.debug('mapHeaderQty class========>' + mapHeaderQty);
+
+            Map<String,String> mapErrSet = new Map<String,String> ();
 
 
-      if (Packing_list_manual != null) {
-        latestInfo.Specifications = integer.valueof('' + Packing_list_manual);
-      }
-      this.changed_name = false;
-      this.changed_sfda = false;
-      this.changed_list = false;
-      this.changed_cost = false;
-      this.haveno_Register = false;
-      this.wrong_Register  = false;
+        }
+        
+        if (error==true) {
+            errorflg = true;
+            return false;
+        }
+
+        errorflg = false;
+        errorMessage = null;
+        return true;
     }
-    // 澶氬勾淇濅慨 end
-  }
 
-  @TestVisible private void testI() {
-    integer i = 0;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-    i++;
-  }
+    public PageReference reloadPage() {
+        if (is_hidden_all) {
+            discount = 0;
+        } else {
+            discount = quo.Discount == null ? 0 : quo.Discount;
+            discount = discount.setScale(2, System.RoundingMode.HALF_UP);
+        }
+        return null;
+    }
+
+
+    //瀵煎叆鏁版嵁鏃讹紝鏍规嵁浜у搧閰嶅鐨凜ode鏌ユ壘浜у搧閰嶅
+    public void acquireProductSetId(Map<String,String> productSetCodeMap) {
+        errorflg = false;
+        errormessage = null;
+        system.debug('<---productSetCodeMap--->' + productSetCodeMap );
+        Map<String,Integer> productSetID_QuantityMap = new Map<String,Integer>();
+        List<productSet__c> productSetList;  //= new List<productSet__c>();
+        Map<String,String> codeMap = new Map<String,String>();
+
+        if (productSetCodeMap.size() > 0 ) {
+
+            productSetList = [select Id,Name,Code__c from productSet__c where Code__c in: productSetCodeMap.keyset()];
+        }
+        system.debug('<---productSetList--->' + productSetList.size() );
+        if (productSetList.size() > 0) {
+
+            for (productSet__c productSet :productSetList) {
+
+                codeMap.put(productSet.Code__c, productSet.Code__c);
+                Integer quantity = Integer.valueOf(productSetCodeMap.get(productSet.Code__c).split(';')[0]);
+                productSetID_QuantityMap.put(productSet.Id,quantity);
+
+            }
+
+            queSetNameSetQty(productSetID_QuantityMap,productSetCodeMap);
+            
+        } else {
+
+            for (String keyset : productSetCodeMap.keyset()) { 
+                
+                errorflg = true;    
+                errorMap.put(keyset,'[' + keyset +']閰嶅涓嶅瓨鍦紝璇风‘璁�!!!!;');
+            }
+        }
+        String errorInformation = '';
+
+        for (String keyset : productSetCodeMap.keyset()) { 
+
+            if (!codeMap.containsKey(keyset)) {
+                
+                errorMap.put(keyset,'[' + keyset +']閰嶅涓嶅瓨鍦紝璇风‘璁�!!!!;');
+
+            }
+        }
+         
+    }
+
+    //閫夋嫨浜у搧閰嶅
+    public PageReference setProductEntry () {
+
+        errorflg = false;
+        errormessage = null;
+
+        Map<String,Integer> productSetID_QuantityMap = new Map<String,Integer>();
+        Map<String,String> productSetID_DiscountMap = new Map<String,String>();
+        //褰搒etProduct_text涓虹┖鏃讹紝璁や负鍒犻櫎璇ユ姤浠锋墍鏈夌殑浜у搧閰嶅
+        if (String.isBlank(setProduct_text)) {
+
+            List<QELine> singleProductSuitList = new List<QELine>();
+            for (QELine q :activities) {
+                
+                if ( String.isBlank(q.pageObject.Product2Id) == false && q.pageObject.SingleProduct__c  == true) {
+
+                    singleProductSuitList.add(q);
+                } 
+                
+            }
+
+            activities = new List<QELine>();
+
+            emptyData();
+
+            //灏嗗崟鍝佸瑁呮斁鍦ㄤ骇鍝侀厤濂楀瑁呯殑涓嬮潰
+            Integer singleNo = 0;
+            QELine qeline = new QELine(singleNo);
+
+            for (QELine q :singleProductSuitList) {
+                
+                q.lineNo = singleNo;
+                activities.add(q);
+                singleNo++;
+            }
+            
+            for (integer j = singleNo; j < quoteEntryMaxLine; j++) {
+
+                qeline = new QELine(j);
+                activities.add(qeline);
+            }
+
+            return null;
+        } else {
+            List<String> productSetIdList = new List<String>();
+            Map<String,String> productSetMap = new Map<String,String>();
+            for (String str : setProduct_text.split(';')) {
+                productSetIdList.add(str.split(',')[0]);
+            }
+            if (productSetIdList.size() > 0) {
+                for (productSet__c proSet  :[select Id,Name,Code__c from productSet__c where Id in :productSetIdList]) {
+                    productSetMap.put(proSet.Id, proSet.Code__c);
+                }
+            }
+            for (String str : setProduct_text.split(';')) {
+
+                if (String.isBlank(str.split(',')[1]) == false) {
+
+                    productSetID_QuantityMap.put(str.split(',')[0], Integer.valueOf(str.split(',')[1]));
+                    productSetID_DiscountMap.put(productSetMap.get(str.split(',')[0]), str.split(',')[1]+';'+str.split(',')[2]);
+                    system.debug('productSetID_DiscountMap____' + productSetID_DiscountMap);
+
+                }
+                
+            }
+        }
+
+       //queSetNameSetQty(productSetID_QuantityMap,null);
+       queSetNameSetQty(productSetID_QuantityMap,productSetID_DiscountMap);
+        
+        for (integer j = singleNo; j < quoteEntryMaxLine; j++) {
+
+            QELine qeline = new QELine(j);
+            activities.add(qeline);
+        }
+
+        return null;
+    }
+
+    
+
+    public class QELine {
+        public Integer lineNo { get; set; }
+        public String productName { get; set; }
+        public String productCode { get; set; }
+        public String productEC { get; set; }
+        public QuoteLineItem pageObject { get; set; }
+        public String setName { get; set; }
+        public String productSetNameReference { get; set; }
+        public Double totalPrice { get; set; }
+
+        public Decimal salesPrice { get; set; }
+        public Decimal salesPriceA { get; set; }
+        public Decimal salesPriceB { get; set; }
+        public Decimal salesPriceC { get; set; }
+
+        public boolean isProductModel { get; set; }
+
+        public boolean hiddenflg { get; set; }
+        public Decimal customPrice { get; set; }
+
+        //public Decimal discount { get; set; }
+        private Map<String, String> setNameMap;
+        private void setMap() {
+            Integer quoteEntryMaxSet = Integer.valueOf(System.Label.QuoteEntryMaxSet);
+            String singleProduct  = System.Label.SingleProduct;
+            setNameMap = new Map<String, String>();
+            for (Integer i = 0; i < quoteEntryMaxSet; i++) {
+                if (i < 9) {
+                    setNameMap.put('set0'+ String.valueOf(i+1),'濂楄0'+ String.valueOf(i+1));
+                } else {
+                    setNameMap.put('set'+ String.valueOf(i+1),'濂楄'+ String.valueOf(i+1));
+                }
+            }
+           
+            setNameMap.put(singleProduct,singleProduct);
+        }
+        private void setMap2() {
+            setNameMap = new Map<String, String>();
+            setNameMap.put('set01','闆朵欢璐圭敤');
+            setNameMap.put('set02','鏈嶅姟璐�');
+            setNameMap.put('set03','鍏朵粬璐圭敤');
+        }
+
+        public QELine(Integer i) {
+            this.pageObject = New QuoteLineItem();
+            this.lineNo = i;
+            this.totalPrice = 0;
+
+            this.salesPrice = 0;
+            this.salesPriceA = 0;
+            this.salesPriceB = 0;
+            this.salesPriceC = 0;
+
+            this.isProductModel = true;
+
+            this.hiddenflg = false;
+        }
+
+        //public QELine(boolean isService, QuoteLineItem tmp, Integer i, String pdtName, String pdtCode, String pdtEC, Integer sQty, boolean ispm, Decimal discount_n) {
+        //XHL-20190428-Update isSingleProduct,鍦ㄦ姤浠疯椤圭洰涓婂鍔燬ingleProduct__c瀛楁锛屽尯鍒嗘槸濂楄杩樻槸鍗曞搧
+        public QELine(boolean isService, QuoteLineItem tmp, Integer i, String pdtName, String pdtCode, String pdtEC, Integer sQty, boolean ispm, boolean isSingleProduct,String productSetName) {
+            //system.debug('1234567_____');
+            this.pageObject = tmp;
+            //this.pageObject.Quantity = tmp.quantity / sQty;
+            this.pageObject.Quantity = tmp.quantity ;
+            this.pageObject.Custom_Price__c = tmp.Custom_Price__c == null ? 0 : tmp.Custom_Price__c;// / sQty;
+            this.pageObject.SetName__c = productSetName;
+            //this.totalPrice = tmp.TotalPrice / sQty;
+            this.totalPrice = tmp.TotalPrice ;
+            this.lineNo = i;
+            this.productName = pdtName;
+            this.productCode = pdtCode.startsWith('0000000000') ? pdtCode.substring(10) : pdtCode;
+            this.productEC = pdtEC;
+            if (isService == true) {
+                setMap2();
+            } else {
+                setMap();
+            }
+            this.setName = setNameMap.get(tmp.Set__c);
+            //this.setName = tmp.Set__c;
+
+            this.salesPrice = tmp.PriceBookEntry.SalesPrice__c;
+            this.salesPriceA = tmp.PriceBookEntry.SalesPriceA__c;
+            this.salesPriceB = tmp.PriceBookEntry.SalesPriceB__c;
+            this.salesPriceC = tmp.PriceBookEntry.SalesPriceC__c;
+
+            this.isProductModel = ispm;
+
+            this.hiddenflg = tmp.PricebookEntry.Hidden_flag__c;
+            system.debug('hiddenflg__'+i+'__'+hiddenflg);
+            this.customPrice = this.pageObject.Custom_Price__c;
+            this.pageObject.SingleProduct__c  = isSingleProduct;
+        }
+
+        //XHL-20190428-Update isSingleProduct,鍦ㄦ姤浠疯椤圭洰涓婂鍔燬ingleProduct__c瀛楁锛屽尯鍒嗘槸濂楄杩樻槸鍗曞搧
+        public QELine(boolean isService, Integer i, String setStr, String strName, String strCode, String strEC, String strId, PricebookEntry pbe, String quantity, String discount, boolean ispm, boolean isSingleProduct,String description,String productSetName) {
+            this.lineNo = i;
+            this.productSetNameReference = productSetName;
+            if (isService == true) {
+                setMap2();
+            } else {
+                setMap();
+            }
+            this.setName = setNameMap.get(setStr);
+            this.productName = strName;
+            String pCode = strCode;
+            this.productCode = pCode.startsWith('0000000000') ? pCode.substring(10) : pCode;
+            this.productEC = strEC;
+
+            pageObject = new QuoteLineItem();
+            this.pageObject.Product2Id = strId;
+            this.pageObject.PricebookEntryId = pbe.Id;
+            this.pageObject.Set__c = setStr;
+            this.pageObject.UnitPrice = pbe.SalesPrice__c;
+            this.pageObject.Quantity = quantity == '' ? 0 : Decimal.valueOf(quantity);
+            this.pageObject.Discount = discount == '' ? 0 : Decimal.valueOf(discount);
+            system.debug('this.pageObject.Discount---->'+this.pageObject.Discount);
+            this.pageObject.SingleProduct__c = isSingleProduct;
+            this.pageObject.Description = description;
+            this.pageObject.SetName__c = productSetName;
+/*            this.discount = discount == '' ? 0 : Decimal.valueOf(discount);
+            this.discount = this.discount.setScale(2, System.RoundingMode.HALF_UP);
+            discount_n = discount_n == null ? 0 : discou;nt_n;
+            this.pageObject.Discount = discount_n + (100 - discount_n) * this.discount / 100;*/
+            //this.pageObject.Custom_Price__c = customPrice == '' ? 0 : Decimal.valueOf(customPrice);
+            //this.pageObject.Description = description;
+            Decimal discount2 =  100-this.pageObject.Discount;
+            //this.totalPrice = discount2 * this.pageObject.Quantity * this.pageObject.UnitPrice/100;
+            this.totalPrice = this.pageObject.Quantity * this.pageObject.UnitPrice * (1 - this.pageObject.Discount / 100);
+            system.debug('this.totalPrice----><'+this.totalPrice);
+            this.salesPrice = pbe.SalesPrice__c;
+            this.salesPriceA = pbe.SalesPriceA__c;
+            this.salesPriceB = pbe.SalesPriceB__c;
+            this.salesPriceC = pbe.SalesPriceC__c;
+
+            this.isProductModel = ispm;
+
+            this.hiddenflg = pbe.Hidden_flag__c;
+        }
+        
+
+    }
+    public void quoteLineSetNameDiscountJson(Map<String,String> quoteLineSetNameDiscountMap){
+        if (quoteLineSetNameDiscountMap.size() > 0) {
+            quoteLineSetNameDiscountJson =  JSON.serializePretty(quoteLineSetNameDiscountMap);
+        }
+    }
+    //鍐冲畾鎶ヤ环涓庡彇娑堟姤浠锋椂澧炲姞鍜屽垹闄ょ浉鍏崇殑"鍐冲畾鎶ヤ环浜у搧閰嶅"
+    public void decideORundecideQuote(String quoteId,Boolean flag){
+
+        if (String.isBlank(quoteId)) {
+            return;
+        } 
+
+        if (flag) {
+            
+            List<DecideQuoteProductSet__c> undecideList = new List<DecideQuoteProductSet__c>();
+            undecideList = [select Id from DecideQuoteProductSet__c where DecideOpportunity__c = :oppId];
+            
+            if(undecideList.size() > 0 ){
+
+                delete undecideList;
+            }
+        }
+
+        system.debug('quoteId_1_2_3_4_' + quoteId);
+        List<Quote>  decideQuoteList = [select Id,Name,QuoteNumber,Is_Decided__c,OpportunityId,
+                                            SetName1__c,SetQty1__c,SetName2__c,SetQty2__c,SetName3__c,SetQty3__c,
+                                            SetName4__c,SetQty4__c,SetName5__c,SetQty5__c,SetName6__c,SetQty6__c,
+                                            SetName7__c,SetQty7__c,SetName8__c,SetQty8__c,SetName9__c,SetQty9__c,
+                                            SetName10__c,SetQty10__c,
+                                            SetName11__c,SetQty11__c,SetName12__c,SetQty12__c,SetName13__c,SetQty13__c,
+                                            SetName14__c,SetQty14__c,SetName15__c,SetQty15__c,SetName16__c,SetQty16__c,
+                                            SetName17__c,SetQty17__c,SetName18__c,SetQty18__c,SetName19__c,SetQty19__c,
+                                            SetName20__c,SetQty20__c,
+                                            SetName21__c,SetQty21__c,SetName22__c,SetQty22__c,SetName23__c,SetQty23__c,
+                                            SetName24__c,SetQty24__c,SetName25__c,SetQty25__c,SetName26__c,SetQty26__c,
+                                            SetName27__c,SetQty27__c,SetName28__c,SetQty28__c,SetName29__c,SetQty29__c,
+                                            SetName30__c,SetQty30__c,OrderIsChange__c
+                                             
+                                        from Quote
+                                        where Id = :quoteId]; 
+
+        if (decideQuoteList[0].Is_Decided__c) {
+
+            Map<String,Integer> quoteProductSetMap = new Map<String,Integer>();
+            List<DecideQuoteProductSet__c> decideList = new List<DecideQuoteProductSet__c>();
+
+            for (Integer i = 1; i <= 30; i++) {
+
+                String setName = String.valueOf(decideQuoteList[0].get('SetName'+i+'__c')) ;
+                Integer setQty =  Integer.valueOf(decideQuoteList[0].get('SetQty'+i+'__c')) ;
+
+                if(setName != null && setName != ''){
+
+                    quoteProductSetMap.put(setName, setQty);
+                }
+            }
+            system.debug('quoteProductSetMap__0522__' + quoteProductSetMap);
+            List<productSet__c> productSetList = [select Id,Name,Code__c
+                                                  from productSet__c 
+                                                  where Name in : quoteProductSetMap.keyset()];
+
+                                              
+            List<QuoteLineItem> items = 
+                [Select Id,Product2Id,Product2.Name,Product2.ProductCode,Product2.Product_ECCode__c,Quantity,Subtotal,Discount,TotalPrice,PricebookEntryId,UnitPrice,Description,Set__c,Custom_Price__c,
+                        PricebookEntry.SalesPrice__c,PricebookEntry.SalesPriceA__c,PricebookEntry.SalesPriceB__c,PricebookEntry.SalesPriceC__c,Product2.ProductModels__c,PricebookEntry.Hidden_flag__c,
+                        SingleProduct__c,SetName__c ,QuoteId
+                   From QuoteLineItem where SetName__c in: quoteProductSetMap.keyset() and QuoteId = :quoteId  Order by Id];
+            List<Order> ordList = [Select id from Order where OpportunityId = : oppId and Status__c = 'Active'];
+
+            system.debug('items11111_22222' + items);
+            Decimal unitPrice = 0;
+            Map<String,Decimal>  unitPriceMap  = new  Map<String,Decimal>();
+            Map<String,Decimal>  discountMap  = new  Map<String,Decimal>();
+            for (QuoteLineItem item :items) {
+
+                if(unitPriceMap.containsKey(item.SetName__c)) {
+                   unitPriceMap.put(item.SetName__c,unitPriceMap.get(item.SetName__c)+item.UnitPrice * item.Quantity);
+                } else {
+                    unitPriceMap.put(item.SetName__c, item.UnitPrice * item.Quantity);
+                }
+                system.debug('Discount_1_1_1_' + item.Discount + '(-)' + item.SetName__c);
+                discountMap.put(item.SetName__c, item.Discount);
+                //unitPriceMap.put(item.SetName__c, ANY value)
+            }
+            system.debug('20190531____'+discountMap);
+            for (productSet__c productSet : productSetList) {
+                system.debug('20190531__1__'+discountMap);
+                DecideQuoteProductSet__c  decideProductSet = new  DecideQuoteProductSet__c();
+                decideProductSet.DecideProductSetName__c = productSet.Name;
+                decideProductSet.DecideProductSetCode__c = productSet.Code__c;
+                decideProductSet.DecideProductSetCount__c = quoteProductSetMap.get(productSet.Name);
+                decideProductSet.DecideProductSet__c = productSet.Id;
+                decideProductSet.DecideOpportunity__c = decideQuoteList[0].OpportunityId;
+                decideProductSet.DecideQuote__c = quoteId;
+                decideProductSet.DecideProductSetUnivalence__c = unitPriceMap.get(productSet.Name) / quoteProductSetMap.get(productSet.Name);
+                decideProductSet.DecideProductSetTotalprice__c = unitPriceMap.get(productSet.Name);
+                //decideProductSet.DecideProductSetDiscount__c = 56;
+                decideProductSet.DecideProductSetDiscount__c = discountMap.get(productSet.Name);
+                if( ordList.size() > 0 ){
+                    
+                    decideProductSet.DecideOrder__c = ordList[0].id;
+                }
+                decideList.add(decideProductSet);
+            }
+            system.debug('items11111_3333' + items);
+            if (decideList.size() > 0) {
+
+                Insert decideList;
+            }
+        } 
+        //else {
+
+        //    List<DecideQuoteProductSet__c> undecideList = new List<DecideQuoteProductSet__c>();
+        //    undecideList = [select Id from DecideQuoteProductSet__c where DecideQuote__c = :quoteId];
+            
+        //    if(undecideList.size() > 0 ){
+
+        //        delete undecideList;
+        //    }
+        //}
+        
+
+        
+    }
+
+    //缁欐姤浠风殑鐩稿叧濂楄瀛楁杩涜璧嬪��
+    public void queSetNameSetQty(Map<String,Integer> productSetID_QuantityMap,Map<String,String> productSetCodeMap){
+
+        if (ProductSetCodeMap == null ){
+            errorMap.clear();
+        } 
+        
+        List<productSet__c> ListProductSet = new List<productSet__c>();
+        List<productSetItem__c> ListproductSetItem = new List<productSetItem__c>();
+        List<String> productSetCodeList = new  List<String>();
+
+        //鑾峰彇"浜у搧閰嶅"鐨勫悕绉�
+        ListProductSet = [select Id,Name,Code__c
+                          from productSet__c 
+                          where Id in :productSetID_QuantityMap.keyset() 
+                          order by Name];
+
+        //鑾峰彇"浜у搧閰嶅鏄庣粏"涓骇鍝佺殑Id
+        ListproductSetItem = [select Id,Name,product__c,productSet__c,
+                                product__r.Name,product__r.ProductCode,
+                                product__r.Product_ECCode__c,productSet__r.Name,
+                                Count__c,productSet__r.Code__c
+                              from productSetItem__c 
+                              where productSet__c in :productSetID_QuantityMap.keyset() 
+                              order by productSet__r.Name];
+          
+        system.debug('ListproductSetItem___++++__' + ListproductSetItem);                    
+        for (productSetItem__c productSetItem : ListproductSetItem) {
+
+            productSetCodeList.add(productSetItem.product__r.ProductCode);
+        }
+
+       
+        Map<String, Product_Search__c> psMap = new Map<String, Product_Search__c>(); // key銇孭roductCode銇с仚銆�
+        List<String> forSelect = new List<String>();
+        
+        //鏌ユ壘"浜у搧妫�绱�"
+        List<Product_Search__c> psList = [
+            select Id, Name, ProductCode__c, Product_ECCode__c, ProductDescription__c,
+                     ProductStatus__c, Product__c, ProductModels1__c
+              from Product_Search__c
+             where ProductCode__c in :productSetCodeList];
+        
+        for (Product_Search__c ps : psList) {
+
+            String pc = ps.ProductCode__c;
+            if (pc.startsWith('00000000000')) {
+
+                pc = pc.substring(11);
+                psMap.put(pc, ps);
+            }
+
+            psMap.put(ps.ProductCode__c, ps);
+            forSelect.add(ps.Product__c);
+        }
+
+        //鏍规嵁璇环鐨勪环鏍兼墜鍐岀殑Id鍜屼骇鍝両d鏌ユ壘浠锋牸鎵嬪唽鏉$洰
+        List<PricebookEntry> pbeList = [
+            select Id, Product2Id, ProductCode, Product2.Product_ECCode__c, Product2.Dummy__c, 
+                    CostPrice__c, SalesPrice__c, SalesPriceA__c, SalesPriceB__c, SalesPriceC__c,
+                    Hidden_flag__c
+              from PricebookEntry
+             where Pricebook2Id = :pricebook2Id
+               and CurrencyIsoCode = :currencyIsoCode
+               and Product2.ManualHidden__c = false
+               and Product2Id in :forSelect];
+        
+        Map<String, PricebookEntry> pbeMap = new Map<String, PricebookEntry>();
+        String errProduct = '';
+        
+        for (PricebookEntry pbe : pbeList) {
+
+            String pc = pbe.ProductCode;
+
+            if ((pbe.CostPrice__c == 0 && pbe.Product2.Dummy__c == false) || pbe.SalesPrice__c == 0) {
+                
+                errorflg = true;
+                errProduct += pbe.productCode + ',';
+            } else {
+
+                if (pc.startsWith('00000000000')) {
+
+                    pc = pc.substring(11);
+                    pbeMap.put(pc, pbe);
+                }
+                pbeMap.put(pbe.ProductCode, pbe);
+            }
+        }
+
+        Integer no = 0 ;    String productSetName;  PricebookEntry pbe;     
+        String setNames;
+        String errorProductSetName = '';
+        
+        Map<String,QELine> existQELineMap = new Map<String,QELine>();
+        List<QELine> singleProductSuitList = new List<QELine>();
+        QELine qeline = new QELine(no);
+
+        //灏嗘姤浠疯椤圭洰涓崟鍝佽幏鍙栧嚭鏉ユ斁鍏ingleProductSuitList涓�
+        for (QELine q :activities) {
+            
+            if ( String.isBlank(q.pageObject.Product2Id) == false && q.pageObject.SingleProduct__c == true) {
+
+                singleProductSuitList.add(q);
+            } 
+            
+        }
+
+        activities = new List<QELine>();
+
+        //鎵惧嚭"浜у搧閰嶅"涓�
+        Map<String,String> errorproductSetMap = new Map<String,String>();
+        for (productSetItem__c productSetItem : ListproductSetItem) {
+
+            Product_Search__c ps = psMap.get(productSetItem.product__r.ProductCode);
+            pbe = pbeMap.get(productSetItem.product__r.ProductCode);
+
+            if (ps == null || pbe == null) {
+
+                errorProductSetName = productSetItem.productSet__r.Name ;
+                errorproductSetMap.put(errorProductSetName, errorProductSetName);
+                errorflg = true;
+                
+                errProduct += productSetItem.product__r.ProductCode + ',';
+                errorMap.put(errorProductSetName, 'error['+errorProductSetName+']浜у搧閰嶅鍐呭惈鏈変骇鍝佷环鏍间俊鎭笉姝g‘锛岃浜у搧閰嶅涓嶈兘浣跨敤銆備骇鍝侊細' + errProduct);
+
+                continue;
+            }
+
+        }
+
+        Map<String,String> matchingProductSetItemMap = new  Map<String,String>();
+        Map<String,String> productsetNameMap = new  Map<String,String>();
+        Integer productSetNo = 1;
+
+        //system.debug('errorMap____' + errorMap);
+        for (productSet__c productSet : ListProductSet) {
+
+            if (errorMap.containsKey(productSet.Name)) {
+
+                continue;
+            }
+
+            if (!matchingProductSetItemMap.containsKey(productSet.Code__c)) {
+
+                if (!errorproductSetMap.containsKey(productSet.Name)) {
+
+                    matchingProductSetItemMap.put(productSet.Code__c, 'set0' + productSetNo);
+                    productsetNameMap.put(productSet.Code__c, productSet.Name);
+                    productSetNo++;
+                }
+                
+            } 
+
+        }
+
+        //system.debug('matchingProductSetItemMap_1111___' + matchingProductSetItemMap);
+        
+
+        //system.debug('errorMap20190521__' + errorMap);
+        for (productSetItem__c productSetItem : ListproductSetItem) {
+
+            errorProductSetName = productSetItem.productSet__r.Name ;
+            //system.debug('errorproductSetMap_2061_' + errorproductSetMap);
+            //system.debug('errorProductSetName_2062_' + errorProductSetName);
+            if (errorproductSetMap.containsKey(errorProductSetName)) {
+
+                continue;
+            }
+            
+            Product_Search__c ps = psMap.get(productSetItem.product__r.ProductCode);
+            pbe = pbeMap.get(productSetItem.product__r.ProductCode);
+            //quantity1 = String.valueOf(productSetID_QuantityMap.get(productSetItem.productSet__c) * productSetItem.Count__c);
+            String quantity = String.valueOf(productSetID_QuantityMap.get(productSetItem.productSet__c) * productSetItem.Count__c);
+            //String quantity = String.valueOf(productSetItem.Count__c);
+            String productSetCode =productSetItem.productSet__r.Code__c;
+            String qty = '0';
+            boolean isSingleProduct = false;
+
+            if (ps == null || pbe == null) {
+
+                errorflg = true;
+                errProduct += productSetItem.product__r.ProductCode + ',';
+                errorMap.put(errorProductSetName, errProduct);
+
+                continue;
+            }
+            if (matchingProductSetItemMap.containsKey(productSetItem.productSet__r.Code__c)) {
+
+                setNames = matchingProductSetItemMap.get(productSetItem.productSet__r.Code__c); 
+                productSetName = productsetNameMap.get(productSetItem.productSet__r.Code__c);       
+            } else {
+                continue;    
+            }
+            
+            
+            if (productSetCodeMap != null && productSetCodeMap.containsKey(productSetCode)) {
+                qty = productSetCodeMap.get(productSetCode).split(';')[1];
+            } 
+
+            qeline = new QELine(isService,no,setNames,ps.Name,ps.ProductCode__c,ps.Product_ECCode__c,ps.Product__c,pbe,quantity, qty, ps.ProductModels1__c,isSingleProduct,ps.ProductDescription__c,productSetName);
+            if (String.isNotBlank(qeline.pageObject.SetName__c)) {
+                quoteLineSetNameDiscountMap.put(qeline.pageObject.SetName__c,String.valueOf(qeline.pageObject.Discount));
+            }
+            quoteLineSetNameDiscountJson(quoteLineSetNameDiscountMap);
+            //quoteLineSetNameDiscountJson =  JSON.serializePretty(quoteLineSetNameDiscountMap);
+            activities.add(qeline);
+            no++;
+            //productSetNo++;
+            
+        }
+        
+        //灏嗗崟鍝佸瑁呮斁鍦ㄤ骇鍝侀厤濂楀瑁呯殑涓嬮潰
+        singleNo = no;
+
+        for (QELine q :singleProductSuitList) {
+
+            q.lineNo = singleNo;
+            activities.add(q);
+            singleNo++;
+        }
+                
+        emptyData();
+        
+        for (productSet__c productSet : ListProductSet) {
+
+            if (errorMap.containsKey(productSet.Name)) {
+                continue;
+            }
+
+            if (errorproductSetMap.containsKey(productSet.Name)) {
+                continue;
+            }
+
+            Boolean flag = productSetID_QuantityMap.containsKey(productSet.Id);
+            Integer quantity ;
+            if (flag) {
+
+                quantity = productSetID_QuantityMap.get(productSet.Id);
+            }
+            
+            if (flag && quo.SetName1__c == null ) {
+
+                quo.SetName1__c = productSet.Name ;
+                quo.SetQty1__c = quantity;
+            } else if (flag && quo.SetName2__c == null){
+
+                quo.SetName2__c = productSet.Name ;
+                quo.SetQty2__c = quantity;
+            } else if (flag && quo.SetName3__c == null){
+
+                quo.SetName3__c = productSet.Name ;
+                quo.SetQty3__c = quantity;
+            } else if (flag && quo.SetName4__c == null){
+
+                quo.SetName4__c = productSet.Name ;
+                quo.SetQty4__c = quantity;
+            } else if (flag && quo.SetName5__c == null){
+
+                quo.SetName5__c = productSet.Name ;
+                quo.SetQty5__c = quantity;
+            } else if (flag && quo.SetName6__c == null){
+
+                quo.SetName6__c = productSet.Name ;
+                quo.SetQty6__c = quantity;
+            } else if (flag && quo.SetName7__c == null){
+
+                quo.SetName7__c = productSet.Name ;
+                quo.SetQty7__c = quantity;
+            } else if (flag && quo.SetName8__c == null){
+
+                quo.SetName8__c = productSet.Name ;
+                quo.SetQty8__c = quantity;
+            } else if (flag && quo.SetName9__c == null){
+
+                quo.SetName9__c = productSet.Name ;
+                quo.SetQty9__c = quantity;
+            } else if (flag && quo.SetName10__c == null){
+
+                quo.SetName10__c = productSet.Name ;
+                quo.SetQty10__c = quantity;
+            } else if (flag && quo.SetName11__c == null){
+
+                quo.SetName11__c = productSet.Name ;
+                quo.SetQty11__c = quantity;
+            } else if (flag && quo.SetName12__c == null){
+
+                quo.SetName12__c = productSet.Name ;
+                quo.SetQty12__c = quantity;
+            } else if (flag && quo.SetName13__c == null){
+
+                quo.SetName13__c = productSet.Name ;
+                quo.SetQty13__c = quantity;
+            } else if (flag && quo.SetName14__c == null){
+
+                quo.SetName14__c = productSet.Name ;
+                quo.SetQty14__c = quantity;
+            } else if (flag && quo.SetName15__c == null){
+
+                quo.SetName15__c = productSet.Name ;
+                quo.SetQty15__c = quantity;
+            } else if (flag && quo.SetName16__c == null){
+
+                quo.SetName16__c = productSet.Name ;
+                quo.SetQty16__c = quantity;
+            } else if (flag && quo.SetName17__c == null){
+
+                quo.SetName17__c = productSet.Name ;
+                quo.SetQty17__c = quantity;
+            } else if (flag && quo.SetName18__c == null){
+
+                quo.SetName18__c = productSet.Name ;
+                quo.SetQty18__c = quantity;
+            } else if (flag && quo.SetName19__c == null){
+
+                quo.SetName19__c = productSet.Name ;
+                quo.SetQty19__c = quantity;
+            } else if (flag && quo.SetName20__c == null){
+
+                quo.SetName20__c = productSet.Name ;
+                quo.SetQty20__c = quantity;
+            } else if (flag && quo.SetName21__c == null){
+
+                quo.SetName21__c = productSet.Name ;
+                quo.SetQty21__c = quantity;
+            } else if (flag && quo.SetName22__c == null){
+
+                quo.SetName22__c = productSet.Name ;
+                quo.SetQty22__c = quantity;
+            } else if (flag && quo.SetName23__c == null){
+
+                quo.SetName23__c = productSet.Name ;
+                quo.SetQty23__c = quantity;
+            } else if (flag && quo.SetName24__c == null){
+
+                quo.SetName24__c = productSet.Name ;
+                quo.SetQty24__c = quantity;
+            } else if (flag && quo.SetName25__c == null){
+
+                quo.SetName25__c = productSet.Name ;
+                quo.SetQty25__c = quantity;
+            } else if (flag && quo.SetName26__c == null){
+
+                quo.SetName26__c = productSet.Name ;
+                quo.SetQty26__c = quantity;
+            } else if (flag && quo.SetName27__c == null){
+
+                quo.SetName27__c = productSet.Name ;
+                quo.SetQty27__c = quantity;
+            } else if (flag && quo.SetName28__c == null){
+
+                quo.SetName28__c = productSet.Name ;
+                quo.SetQty28__c = quantity;
+            } else if (flag && quo.SetName29__c == null){
+
+                quo.SetName29__c = productSet.Name ;
+                quo.SetQty29__c = quantity;
+            } else if (flag && quo.SetName30__c == null){
+                
+                quo.SetName30__c = productSet.Name ;
+                quo.SetQty30__c = quantity;
+            }
+            
+            
+        } 
+        //system.debug('errorMap1231111_'+errorMap);
+        if (errorflg) {
+            errorMessage = '';
+            for (String errorKey :errorMap.keySet()) {
+                errProduct = errorMap.get(errorKey).substring(0, errorMap.get(errorKey).length()-1);
+                errorMessage += errProduct + ';';  
+            }
+        
+        }
+
+             
+    }
+
+    //娓呯┖椤甸潰濂楄鍚嶇О鍜屾暟閲�
+    public void emptyData(){
+
+        quo.SetName1__c = null ;
+        quo.SetQty1__c = null;
+        quo.SetName2__c = null ;
+        quo.SetQty2__c = null;
+        quo.SetName3__c = null;
+        quo.SetQty3__c = null;
+        quo.SetName4__c = null ;
+        quo.SetQty4__c = null;
+        quo.SetName5__c = null ;
+        quo.SetQty5__c = null;
+        quo.SetName6__c = null ;
+        quo.SetQty6__c = null;
+        quo.SetName7__c = null;
+        quo.SetQty7__c = null;
+        quo.SetName8__c = null ;
+        quo.SetQty8__c = null;
+        quo.SetName9__c = null ;
+        quo.SetQty9__c = null;
+        quo.SetName10__c = null ;
+        quo.SetQty10__c = null;
+        quo.SetName11__c = null;
+        quo.SetQty11__c = null;
+        quo.SetName12__c = null ;
+        quo.SetQty12__c = null;
+        quo.SetName13__c = null ;
+        quo.SetQty13__c = null;
+        quo.SetName14__c = null ;
+        quo.SetQty14__c = null;
+        quo.SetName15__c = null ;
+        quo.SetQty15__c = null;
+        quo.SetName16__c = null ;
+        quo.SetQty16__c = null;
+        quo.SetName17__c = null ;
+        quo.SetQty17__c = null;
+        quo.SetName18__c = null ;
+        quo.SetQty18__c = null;
+        quo.SetName19__c = null ;
+        quo.SetQty19__c = null;
+        quo.SetName20__c = null ;
+        quo.SetQty20__c = null;
+        quo.SetName21__c = null ;
+        quo.SetQty21__c = null;
+        quo.SetName22__c = null ;
+        quo.SetQty22__c = null;
+        quo.SetName23__c = null ;
+        quo.SetQty23__c = null;
+        quo.SetName24__c = null ;
+        quo.SetQty24__c = null;
+        quo.SetName25__c = null ;
+        quo.SetQty25__c = null;
+        quo.SetName26__c = null ;
+        quo.SetQty26__c = null;
+        quo.SetName27__c = null ;
+        quo.SetQty27__c = null;
+        quo.SetName28__c = null ;
+        quo.SetQty28__c = null;
+        quo.SetName29__c = null ;
+        quo.SetQty29__c = null;
+        quo.SetName30__c = null ;
+        quo.SetQty30__c = null;
+    
+    }
+    public static Boolean IfspecialDealer(String oppDealerId){
+        if ( String.isBlank(oppDealerId)) {
+            return false;
+        }
+        return StaticParameter.specialDealerMap.containsKey(oppDealerId.substring(0,15));
+    }
+
+    public void dummy2(){
+        
+    }
+
+    @TestVisible private void testI() {
+        integer i = 0;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+         i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+         i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+         i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+    }
+
+
 }
\ No newline at end of file

--
Gitblit v1.9.1