From 00e147ec892cb1e89d0698787a8c60da1014cdb7 Mon Sep 17 00:00:00 2001
From: binxie <137736985@qq.com>
Date: 星期一, 26 六月 2023 17:42:22 +0800
Subject: [PATCH] Community升级

---
 force-app/main/default/classes/LexSummonsCreatController.cls | 2640 ++++++++++++++++++++++++++++++++---------------------------
 1 files changed, 1,446 insertions(+), 1,194 deletions(-)

diff --git a/force-app/main/default/classes/LexSummonsCreatController.cls b/force-app/main/default/classes/LexSummonsCreatController.cls
index bc47bb8..f5fb177 100644
--- a/force-app/main/default/classes/LexSummonsCreatController.cls
+++ b/force-app/main/default/classes/LexSummonsCreatController.cls
@@ -105,31 +105,42 @@
     public static Boolean EditDelCommitBtnDisabled { get; private set; }
     public static Boolean saveBtnDisabled { get; private set; }
     public static Boolean SorderBtnDisabled { get; private set; }
+
+    // page
+    public static Integer pagesize { get; set; }
+    public static Integer pageToken { get; set; }
+    //public static String sortField { get; set; }
+    //public static String sortOrder { get; set; }
+    public static Integer totalcount { get; set; }
+    public static Integer addSize { get; set; }
+    //List<ConsumableorderdetailsInfoLwc> reSetLwc
+    public static List<ConsumableorderdetailsInfo> addData { get; set; }
+    public static Map<String, String> skipData { get; set; }
     // 淇濆瓨鍚庡姩浣滐細 1.妫�绱� 2.鎺掑簭
-    public static String sortKey { get; set; }
-    public static String preSortKey { get; private set; }
-    public static Boolean sortOrderAsc { get; private set; }
-    public static String[] sortOrder { get; private set; }
-    private static String[] columus = new List<String>{
-        'Consumable_Product__r.Name',
-        'Consumable_Product__r.Asset_Model_No__c',
-        'Consumable_Product__r.Intra_Trade_List_RMB__c',
-        '',
-        '',
-        'Consumable_Product__r.Category3__c',
-        'Consumable_Product__r.Category4__c',
-        'Consumable_Product__r.Category5__c'
-    };
-    private static String[] columus_no = new List<String>{
-        'Product2__c.Name',
-        'Product2__c.Asset_Model_No__c',
-        'Product2__c.Intra_Trade_List_RMB__c',
-        '',
-        '',
-        'Category3__c',
-        'Category4__c',
-        'Category5__c'
-    };
+    // public static String sortKey { get; set; }
+    // public static String preSortKey { get; private set; }
+    // public static Boolean sortOrderAsc { get; private set; }
+    // public static String[] sortOrder { get; private set; }
+    // private static String[] columus = new List<String>{
+    //     'Consumable_Product__r.Name',
+    //     'Consumable_Product__r.Asset_Model_No__c',
+    //     'Consumable_Product__r.Intra_Trade_List_RMB__c',
+    //     '',
+    //     '',
+    //     'Consumable_Product__r.Category3__c',
+    //     'Consumable_Product__r.Category4__c',
+    //     'Consumable_Product__r.Category5__c'
+    // };
+    // private static String[] columus_no = new List<String>{
+    //     'Product2__c.Name',
+    //     'Product2__c.Asset_Model_No__c',
+    //     'Product2__c.Intra_Trade_List_RMB__c',
+    //     '',
+    //     '',
+    //     'Category3__c',
+    //     'Category4__c',
+    //     'Category5__c'
+    // };
 
     //鍒拌揣鍗曟槑缁�1
     private static List<Consumable_Orderdetails__c> consumableorderdetailsSelected = new List<Consumable_Orderdetails__c>();
@@ -234,255 +245,510 @@
 
     // 鐢婚潰鍒濆鍖�
     @AuraEnabled
-    public static ResponseBodyLWC init(String ESetidJs,String statusEdit) {
-        // try {
-        firstInit(ESetidJs);
-        statusEdit = statusEdit;
-        arriveorder = '';
-        HospitalName = '';
-        provinceOpts = new List<SelectOption>();
-        provinceOptsMap = new Map<String, String>();
-        ResponseBodyLWC res = new ResponseBodyLWC();
-        Map<String, object> data = new Map<String, object>();
-        res.entity = data;
+    public static ResponseBodyLWC init(
+        String ESetidJs,
+        String statusEdit,
+        Integer pageSizeLWC,
+        Integer pageTokenLWC,
+        String arriveorderLWC
+    ) {
+        try {
+            firstInit(ESetidJs);
+            statusEdit = statusEdit;
+            arriveorder = arriveorderLWC;
+            HospitalName = '';
+            provinceOpts = new List<SelectOption>();
+            provinceOptsMap = new Map<String, String>();
+            ResponseBodyLWC res = new ResponseBodyLWC();
+            Map<String, object> data = new Map<String, object>();
+            res.entity = data;
+            // public static Integer pagesize { get; set; }
+            // public static Integer pageToken { get; set; }
+            // public static String sortField { get; set; }
+            // public static String sortOrder { get; set; }
+            pagesize = pageSizeLWC;
+            pageToken = pageTokenLWC > 2000 ? 2000 : pageTokenLWC;
 
-        sortKey = '1';
-        preSortKey = '1';
-        sortOrderAsc = false;
-        sortOrder = new List<String>(8);
-        sortOrder = new List<String>{ ' ', ' ', ' ', ' ', '鈫�', '', '', '' };
-        //cate1ForSort = '';
-        sumPrice = 0;
-        IdCheck = EsetId;
-        if (ESetId != null && ESetId != '' && (statusEdit == '' || statusEdit == null)) {
-            editAble = false;
-        } else if ((ESetId == null || ESetId == '') && (statusEdit == '' || statusEdit == null)) {
-            editAble = true;
-        } else if (ESetId != null && ESetId != '' && statusEdit != '' && statusEdit != null) {
-            editAble = true;
-        }
-        userId = UserInfo.getUserId();
-        localuser = [SELECT id, State_Hospital__c FROM User WHERE id = :UserInfo.getUserId()];
-        //userId = '00510000005QO75';
-        user Useracc = [SELECT accountid, Work_Location__c, UserPro_Type__c FROM user WHERE id = :userId];
-        accountid = Useracc.accountid;
-        userWorkLocation = Useracc.Work_Location__c;
-        agencyProType = Useracc.UserPro_Type__c;
-        if (String.isBlank(Useracc.UserPro_Type__c)) {
-            agencyProType = 'ET';
-        }
-        Account accountInfo = [SELECT Name FROM account WHERE id = :accountid];
-        accountName = accountInfo.Name;
-        //coc.Order_date__c = Date.today();
-        list<Dealer_elationship__c> Dealerelationship = new List<Dealer_elationship__c>();
-        Dealerelationship = [
-            SELECT Dealer_subordinate__c, Dealer_subordinate__r.Name
-            FROM Dealer_elationship__c
-            WHERE Dealer_principal__c = :accountid
-        ];
-
-        List<Agency_Hospital_Link__c> AgencyHospitalLink = new List<Agency_Hospital_Link__c>();
-        AgencyHospitalLink = [SELECT Id, Hospital__c, Hospital__r.Name FROM Agency_Hospital_Link__c WHERE Agency__c = :accountid];
-
-        //add by rentx 2021-3-1 start
-        //鍒ゆ柇褰撳墠缁忛攢鍟嗕笅鏄惁鏈夌壒浠峰尰闄�
-        List<hospitalprice__c> hlist = [SELECT id, product__c FROM hospitalprice__c WHERE account__c = :accountid];
-        if (hlist == null || hlist.size() == 0) {
-            hasHos = false;
-        } else {
-            for (hospitalprice__c hp : hlist) {
-                HosProMap.put(hp.product__c, '');
+            // sortKey = '1';
+            // preSortKey = '1';
+            // sortOrderAsc = false;
+            // sortOrder = new List<String>(8);
+            // sortOrder = new List<String>{ ' ', ' ', ' ', ' ', '鈫�', '', '', '' };
+            //cate1ForSort = '';
+            sumPrice = 0;
+            IdCheck = EsetId;
+            if (ESetId != null && ESetId != '' && (statusEdit == '' || statusEdit == null)) {
+                editAble = false;
+            } else if ((ESetId == null || ESetId == '') && (statusEdit == '' || statusEdit == null)) {
+                editAble = true;
+            } else if (ESetId != null && ESetId != '' && statusEdit != '' && statusEdit != null) {
+                editAble = true;
             }
-            hasHos = true;
-        }
-        //add by rentx 2021-3-1 end
+            userId = UserInfo.getUserId();
+            localuser = [SELECT id, State_Hospital__c FROM User WHERE id = :UserInfo.getUserId()];
+            //userId = '00510000005QO75';
+            user Useracc = [SELECT accountid, Work_Location__c, UserPro_Type__c FROM user WHERE id = :userId];
+            accountid = Useracc.accountid;
+            userWorkLocation = Useracc.Work_Location__c;
+            agencyProType = Useracc.UserPro_Type__c;
+            if (String.isBlank(Useracc.UserPro_Type__c)) {
+                agencyProType = 'ET';
+            }
+            Account accountInfo = [SELECT Name FROM account WHERE id = :accountid];
+            accountName = accountInfo.Name;
+            //coc.Order_date__c = Date.today();
+            list<Dealer_elationship__c> Dealerelationship = new List<Dealer_elationship__c>();
+            Dealerelationship = [
+                SELECT Dealer_subordinate__c, Dealer_subordinate__r.Name
+                FROM Dealer_elationship__c
+                WHERE Dealer_principal__c = :accountid
+            ];
 
-        saveBtnDisabled = false;
-        SorderBtnDisabled = false;
-        String sqlagencyProType = '%' + agencyProType + '%';
-        coc = new Consumable_order__c();
-        consumableorderdetailsSelectRecords = new List<ConsumableorderdetailsInfo>();
-        Map<String, ConsumableorderdetailsInfo> MidMap = new Map<String, ConsumableorderdetailsInfo>();
-        //add by rentx 2021-01-29
-        Map<String, ConsumableorderdetailsInfo> MidMap2 = new Map<String, ConsumableorderdetailsInfo>();
-        //add by rentx 2021-01-29
+            List<Agency_Hospital_Link__c> AgencyHospitalLink = new List<Agency_Hospital_Link__c>();
+            AgencyHospitalLink = [SELECT Id, Hospital__c, Hospital__r.Name FROM Agency_Hospital_Link__c WHERE Agency__c = :accountid];
 
-        List<AggregateResult> orderdetailCount = [
-            SELECT count(id), Consumable_Product__c cpc, Box_Piece__c
-            FROM Consumable_order_details2__c
-            WHERE
-                Dealer_Arrive__c = TRUE
-                AND Dealer_Shipment__c = FALSE
-                AND Dealer_Saled__c = FALSE
-                AND Lose_Flag__c = FALSE
-                AND Cancellation_Flag__c = FALSE
-                AND Bar_Code__c != NULL
-                AND Isoverdue__c = 1
-                AND Product_Type__c LIKE :sqlagencyProType
-                AND Dealer_Info_text__c = :accountName
-                AND Arrive_Owner_Work_Location__c = :userWorkLocation
-            GROUP BY Consumable_Product__c, Box_Piece__c
-        ];
-        for (AggregateResult orderdetail : orderdetailCount) {
-            zaikuId.add(String.valueOf(orderdetail.get('cpc')));
-        }
-        List<Consumable_order_details2__c> CountDel = [
-            SELECT
-                Id,
-                Bar_Code__c,
-                Name,
-                Inventory_date__c,
-                Consumable_Product__c,
-                Consumable_Product__r.Asset_Model_No__c,
-                Recordtypeid,
-                Box_Piece__c,
-                ProductPacking_list_manual__c,
-                //add by rentx 2020-11-27 start
-                hospitalSpecialOffer__c
-            //add by rentx 2020-11-27 end
-            FROM Consumable_order_details2__c
-            WHERE
-                Dealer_Arrive__c = TRUE
-                AND Dealer_Shipment__c = FALSE
-                AND Dealer_Saled__c = FALSE
-                AND Dealer_Returned__c = FALSE
-                AND Lose_Flag__c = FALSE
-                AND Cancellation_Flag__c = FALSE
-                AND Bar_Code__c != NULL
-                AND Isoverdue__c = 1
-                AND Product_Type__c LIKE :sqlagencyProType
-                AND Arrive_Owner_Work_Location__c = :userWorkLocation
-                AND Dealer_Info_text__c = :accountName
-        ];
-        // 鏂拌
-        if (ESetId == null || ESetId == '') {
-            SummonsFlag = 'hidden';
-            String msoql = makeSoqlinventory();
-            initStandardController(msoql);
-            product2Selected = Database.query(msoql);
-            //product2Selected = product2s();
-            if (String.isBlank(arriveorder)) {
-                EditDelCommitBtnDisabled = true;
-                for (Integer i = 0; i < product2Selected.size(); i++) {
-                    MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
+            //add by rentx 2021-3-1 start
+            //鍒ゆ柇褰撳墠缁忛攢鍟嗕笅鏄惁鏈夌壒浠峰尰闄�
+            List<hospitalprice__c> hlist = [SELECT id, product__c FROM hospitalprice__c WHERE account__c = :accountid];
+            if (hlist == null || hlist.size() == 0) {
+                hasHos = false;
+            } else {
+                for (hospitalprice__c hp : hlist) {
+                    HosProMap.put(hp.product__c, '');
                 }
-                for (Integer i = 0; i < CountDel.size(); i++) {
-                    String str = '';
-                    if (CountDel[i].hospitalSpecialOffer__c) {
-                        str = 'isHos';
-                    } else {
-                        str = 'notHos';
+                hasHos = true;
+            }
+            //add by rentx 2021-3-1 end
+
+            saveBtnDisabled = false;
+            SorderBtnDisabled = false;
+            String sqlagencyProType = '%' + agencyProType + '%';
+            coc = new Consumable_order__c();
+            consumableorderdetailsSelectRecords = new List<ConsumableorderdetailsInfo>();
+            Map<String, ConsumableorderdetailsInfo> MidMap = new Map<String, ConsumableorderdetailsInfo>();
+            //add by rentx 2021-01-29
+            Map<String, ConsumableorderdetailsInfo> MidMap2 = new Map<String, ConsumableorderdetailsInfo>();
+            //add by rentx 2021-01-29
+
+            List<AggregateResult> orderdetailCount = [
+                SELECT count(id), Consumable_Product__c cpc, Box_Piece__c
+                FROM Consumable_order_details2__c
+                WHERE
+                    Dealer_Arrive__c = TRUE
+                    AND Dealer_Shipment__c = FALSE
+                    AND Dealer_Saled__c = FALSE
+                    AND Lose_Flag__c = FALSE
+                    AND Cancellation_Flag__c = FALSE
+                    AND Bar_Code__c != NULL
+                    AND Isoverdue__c = 1
+                    AND Product_Type__c LIKE :sqlagencyProType
+                    AND Dealer_Info_text__c = :accountName
+                    AND Arrive_Owner_Work_Location__c = :userWorkLocation
+                GROUP BY Consumable_Product__c, Box_Piece__c
+            ];
+            for (AggregateResult orderdetail : orderdetailCount) {
+                zaikuId.add(String.valueOf(orderdetail.get('cpc')));
+            }
+            System.debug('sqlagencyProType = ' + sqlagencyProType);
+            System.debug('userWorkLocation = ' + userWorkLocation);
+            System.debug('accountName = ' + accountName);
+            List<Consumable_order_details2__c> CountDel = [
+                SELECT
+                    Id,
+                    Bar_Code__c,
+                    Name,
+                    Inventory_date__c,
+                    Consumable_Product__c,
+                    Consumable_Product__r.Asset_Model_No__c,
+                    Recordtypeid,
+                    Box_Piece__c,
+                    ProductPacking_list_manual__c,
+                    //add by rentx 2020-11-27 start
+                    hospitalSpecialOffer__c
+                //add by rentx 2020-11-27 end
+                FROM Consumable_order_details2__c
+                WHERE
+                    Dealer_Arrive__c = TRUE
+                    AND Dealer_Shipment__c = FALSE
+                    AND Dealer_Saled__c = FALSE
+                    AND Dealer_Returned__c = FALSE
+                    AND Lose_Flag__c = FALSE
+                    AND Cancellation_Flag__c = FALSE
+                    AND Bar_Code__c != NULL
+                    AND Isoverdue__c = 1
+                    AND Product_Type__c LIKE :sqlagencyProType
+                    AND Arrive_Owner_Work_Location__c = :userWorkLocation
+                    AND Dealer_Info_text__c = :accountName
+            ];
+            // 鏂拌
+            if (ESetId == null || ESetId == '') {
+                SummonsFlag = 'hidden';
+                String msoql = makeSoqlinventory();
+                initStandardController(msoql);
+                System.debug('msoql = ' + msoql);
+                product2Selected = Database.query(msoql);
+                if (String.isBlank(arriveorder)) {
+                    EditDelCommitBtnDisabled = true;
+                    for (Integer i = 0; i < product2Selected.size(); i++) {
+                        MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
                     }
-                    //鏄庣粏2瀵瑰簲鐨勪骇鍝佸瓨鍦ㄤ簬MidMap涓�
-                    if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
-                        //璁剧疆map涓璳ey鐨勫悗缂� 鐢ㄤ簬鍖哄垎鍖婚櫌鐗逛环鍜岄潪鍖婚櫌鐗逛环
-                        if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
-                            ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c + str);
-                            Jstage.allnumber = Jstage.allnumber + 1;
-                            if (CountDel[i].Box_Piece__c == '鐩�') {
-                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
-                            } else if (CountDel[i].Box_Piece__c == '涓�') {
-                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
-                            }
-                            if (CountDel[i].hospitalSpecialOffer__c) {
-                                Jstage.hospitalSpecialOffer = true;
-                            } else {
-                                Jstage.hospitalSpecialOffer = false;
-                            }
-                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
-                                Jstage.hosPro = true;
-                            }
-                            MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
+                    for (Integer i = 0; i < CountDel.size(); i++) {
+                        String str = '';
+                        if (CountDel[i].hospitalSpecialOffer__c) {
+                            str = 'isHos';
                         } else {
-                            //midmap2涓病鏈夊搴旂殑浜у搧
-                            ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
-                            Jstage.allnumber = Jstage.allnumber + 1;
-                            if (CountDel[i].Box_Piece__c == '鐩�') {
-                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
-                            } else if (CountDel[i].Box_Piece__c == '涓�') {
-                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
-                            }
-                            if (CountDel[i].hospitalSpecialOffer__c) {
-                                Jstage.hospitalSpecialOffer = true;
+                            str = 'notHos';
+                        }
+                        //鏄庣粏2瀵瑰簲鐨勪骇鍝佸瓨鍦ㄤ簬MidMap涓�
+                        if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
+                            //璁剧疆map涓璳ey鐨勫悗缂� 鐢ㄤ簬鍖哄垎鍖婚櫌鐗逛环鍜岄潪鍖婚櫌鐗逛环
+                            if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
+                                ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c + str);
+                                Jstage.allnumber = Jstage.allnumber + 1;
+                                if (CountDel[i].Box_Piece__c == '鐩�') {
+                                    Jstage.Boxnumber = Jstage.Boxnumber + 1;
+                                } else if (CountDel[i].Box_Piece__c == '涓�') {
+                                    Jstage.Piecenumber = Jstage.Piecenumber + 1;
+                                }
+                                if (CountDel[i].hospitalSpecialOffer__c) {
+                                    Jstage.hospitalSpecialOffer = true;
+                                } else {
+                                    Jstage.hospitalSpecialOffer = false;
+                                }
+                                if (HosProMap.containsKey(Jstage.Prod.Id)) {
+                                    Jstage.hosPro = true;
+                                }
+                                MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
                             } else {
-                                Jstage.hospitalSpecialOffer = false;
+                                //midmap2涓病鏈夊搴旂殑浜у搧
+                                ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
+                                Jstage.allnumber = Jstage.allnumber + 1;
+                                if (CountDel[i].Box_Piece__c == '鐩�') {
+                                    Jstage.Boxnumber = Jstage.Boxnumber + 1;
+                                } else if (CountDel[i].Box_Piece__c == '涓�') {
+                                    Jstage.Piecenumber = Jstage.Piecenumber + 1;
+                                }
+                                if (CountDel[i].hospitalSpecialOffer__c) {
+                                    Jstage.hospitalSpecialOffer = true;
+                                } else {
+                                    Jstage.hospitalSpecialOffer = false;
+                                }
+                                if (HosProMap.containsKey(Jstage.Prod.Id)) {
+                                    Jstage.hosPro = true;
+                                }
+                                //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
+                                MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
                             }
-                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
-                                Jstage.hosPro = true;
-                            }
-                            //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
-                            MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
+                        }
+                        System.debug('MidMap2.size() = ' + MidMap2.size());
+                        /*//鐒跺悗寰幆CountDel鍘讳慨鏀筸ap閲岀殑allnumber
+                            if(MidMap.containsKey(CountDel[i].Consumable_Product__c)){
+                                ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c);
+                                Jstage.allnumber = Jstage.allnumber+1 ;
+                                if(CountDel[i].Box_Piece__c == '鐩�'){
+                                    Jstage.Boxnumber = Jstage.Boxnumber + 1;
+                                }else if(CountDel[i].Box_Piece__c == '涓�'){
+                                    Jstage.Piecenumber = Jstage.Piecenumber + 1;
+                                }
+                                if (CountDel[i].hospitalSpecialOffer__c) {
+                                    Jstage.hospitalSpecialOffer = true;
+                                }else{
+                                    Jstage.hospitalSpecialOffer = false;
+                                }
+                                //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
+                                MidMap.put(CountDel[i].Consumable_Product__c+str, Jstage);
+                            }*/
+                    }
+
+                    //update by rentx 2021-01-29 end
+
+                    //鍐嶆妸map閲岀殑鍊间粠鏂拌祴缁機onsumableorderdetailsRecords
+                    //update by rentx 2021-01-29
+                    // for(ConsumableorderdetailsInfo bss : MidMap.values()){
+                    for (ConsumableorderdetailsInfo bss : MidMap2.values()) {
+                        //update by rentx 2021-01-29
+                        //if(bss.allnumber>0){
+                        bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
+                        bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
+                        bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
+                        consumableorderdetailsSelectRecords.add(bss);
+                        //}
+                    }
+
+                    Integer ishosnum = 0;
+                    for (ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords) {
+                        //ass.sortBy = sortOrderAsc;
+                        //add by rentx 2021-3-10
+                        if (ass.hospitalSpecialOffer) {
+                            ishosnum = ishosnum + 1;
                         }
                     }
-                    /*//鐒跺悗寰幆CountDel鍘讳慨鏀筸ap閲岀殑allnumber
-                        if(MidMap.containsKey(CountDel[i].Consumable_Product__c)){
-                            ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c);
-                            Jstage.allnumber = Jstage.allnumber+1 ;
-                            if(CountDel[i].Box_Piece__c == '鐩�'){
-                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
-                            }else if(CountDel[i].Box_Piece__c == '涓�'){
-                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
-                            }
-                            if (CountDel[i].hospitalSpecialOffer__c) {
-                                Jstage.hospitalSpecialOffer = true;
-                            }else{
-                                Jstage.hospitalSpecialOffer = false;
-                            }
-                            //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
-                            MidMap.put(CountDel[i].Consumable_Product__c+str, Jstage);
-                        }*/
-                }
-
-                //update by rentx 2021-01-29 end
-
-                //鍐嶆妸map閲岀殑鍊间粠鏂拌祴缁機onsumableorderdetailsRecords
-                //update by rentx 2021-01-29
-                // for(ConsumableorderdetailsInfo bss : MidMap.values()){
-                for (ConsumableorderdetailsInfo bss : MidMap2.values()) {
+                    if (ishosnum > 0) {
+                        hasHosPro = true;
+                    } else {
+                        hasHosPro = false;
+                    }
+                    consumableorderdetailsSelectRecords.sort();
+                    //add by rentx
+                    noOfRecords = consumableorderdetailsSelectRecords.size();
+                    //add by rentx
+                    System.debug('makepagerecords1');
+                    makepagerecords();
+                    //listCut();
+                } else {
+                    if (statusEdit == '' || statusEdit == null) {
+                        editAble = false;
+                    } else if (statusEdit != '' && statusEdit != null) {
+                        editAble = true;
+                    }
+                    // upadte start by vivek 2019-7-15
+                    // coc = [SELECT Id,Name,Summons_Order_type__c,SummonsStatus_c__c,Order_ForDealerText__c,
+                    //             Dealer_Info__c,Order_ForDealer__c,Order_ForDealer__r.Name,Order_ForDealerTextID__c,
+                    //             Order_ForHospital__c,SummonsForDirction__c,Order_date__c,Arrive_Order__c,
+                    //             Order_status__c,Shipment_total_amount__c,Offers_Price__c,
+                    //             Billed_Status__c,ShipmentAccount__c,Order_Dealer_Info__c,Order_ForCustomerText__c,ConInvoice_Code__c,Onchange_order__c
+                    //         FROM Consumable_order__c
+                    //         WHERE Id =:arriveorder AND Order_Owner_WorkLocal__c =: userWorkLocation
+                    //         AND recordtypeid = :System.Label.RT_ConOrder_Arrive];
+                    coc = [
+                        SELECT
+                            Id,
+                            Name,
+                            Summons_Order_type__c,
+                            NoConfirmedPrice__c,
+                            SummonsStatus_c__c,
+                            Order_ForDealerText__c,
+                            Dealer_Info__c,
+                            Order_ForDealer__c,
+                            Order_ForDealer__r.Name,
+                            Order_ForDealerTextID__c,
+                            Order_ForHospital__c,
+                            SummonsForDirction__c,
+                            Order_date__c,
+                            Arrive_Order__c,
+                            Order_status__c,
+                            Shipment_total_amount__c,
+                            Offers_Price__c,
+                            Billed_Status__c,
+                            ShipmentAccount__c,
+                            Order_Dealer_Info__c,
+                            Order_ForCustomerText__c,
+                            ConInvoice_Code__c,
+                            Onchange_order__c,
+                            OutPattern__c
+                        FROM Consumable_order__c
+                        WHERE
+                            Id = :arriveorder
+                            AND Order_Owner_WorkLocal__c = :userWorkLocation
+                            AND recordtypeid = :System.Label.RT_ConOrder_Arrive
+                    ];
+                    // update end by vivek 2019-7-15
+                    //鏄庣粏1鑾峰彇
+                    consumableorderdetailsSelected = [
+                        SELECT
+                            Id,
+                            Dealer_Custom_Price__c,
+                            Delivery_List_RMB__c,
+                            Consumable_Product__r.Name__c,
+                            Name,
+                            Consumable_order__c,
+                            Consumable_Product__c,
+                            Consumable_Product__r.Name,
+                            Consumable_Product__r.Category3__c,
+                            Consumable_Product__r.Category4__c,
+                            Consumable_Product__r.Category5__c,
+                            Shipment_Count__c,
+                            Consumable_Product__r.Intra_Trade_List_RMB__c,
+                            Consumable_Product__r.Asset_Model_No__c,
+                            Sum_of_money__c,
+                            Box_Piece__c,
+                            ProductPacking_list_manual__c,
+                            Consumable_Product__r.SFDA_Status__c,
+                            Consumable_count__c,
+                            Invoiced_Procount__c,
+                            RrturnPro_count__c,
+                            InvoiceProNot_count__c,
+                            //Unitprice_To_agency__c,
+                            Consumable_Product__r.Product2__r.SFDA_Approbation_No__c,
+                            Consumable_Product__r.Product2__r.SFDA_Expiration_Date__c
+                        FROM Consumable_Orderdetails__c
+                        WHERE Consumable_order__c = :coc.Arrive_Order__c
+                        ORDER BY Name
+                    ];
+                    for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
+                        orderzaikuId.add(cdc1.Consumable_Product__c);
+                    }
+                    msoql = makeSoqlorderdet();
+                    product2Selected = Database.query(msoql);
+                    size = product2Selected.size();
+                    initStandardController(msoql);
+                    for (Integer i = 0; i < product2Selected.size(); i++) {
+                        MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
+                    }
                     //update by rentx 2021-01-29
-                    //if(bss.allnumber>0){
-                    bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
-                    bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
-                    bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
-                    consumableorderdetailsSelectRecords.add(bss);
-                    //}
-                }
+                    /*for(Integer i = 0 ; i< CountDel.size();i++){
+                            //鐒跺悗寰幆CountDel鍘讳慨鏀筸ap閲岀殑allnumber
+                            if(MidMap.containsKey(CountDel[i].Consumable_Product__c)){
+                                ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c);
+                                Jstage.allnumber = Jstage.allnumber+1 ;
+                                if(CountDel[i].Box_Piece__c == '鐩�'){
+                                    Jstage.Boxnumber = Jstage.Boxnumber + 1;
+                                }else if(CountDel[i].Box_Piece__c == '涓�'){
+                                    Jstage.Piecenumber = Jstage.Piecenumber + 1;
+                                }
+                                //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
+                                MidMap.put(CountDel[i].Consumable_Product__c, Jstage);
+                            }
 
-                Integer ishosnum = 0;
-                for (ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords) {
-                    ass.sortBy = sortOrderAsc;
-                    //add by rentx 2021-3-10
-                    if (ass.hospitalSpecialOffer) {
-                        ishosnum = ishosnum + 1;
+                        }*/
+                    for (Integer i = 0; i < CountDel.size(); i++) {
+                        String str = '';
+                        if (CountDel[i].hospitalSpecialOffer__c) {
+                            str = 'isHos';
+                        } else {
+                            str = 'notHos';
+                        }
+                        //鏄庣粏2瀵瑰簲鐨勪骇鍝佸瓨鍦ㄤ簬MidMap涓�
+                        if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
+                            //璁剧疆map涓璳ey鐨勫悗缂� 鐢ㄤ簬鍖哄垎鍖婚櫌鐗逛环鍜岄潪鍖婚櫌鐗逛环
+                            if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
+                                ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c + str);
+                                Jstage.allnumber = Jstage.allnumber + 1;
+                                if (CountDel[i].Box_Piece__c == '鐩�') {
+                                    Jstage.Boxnumber = Jstage.Boxnumber + 1;
+                                } else if (CountDel[i].Box_Piece__c == '涓�') {
+                                    Jstage.Piecenumber = Jstage.Piecenumber + 1;
+                                }
+                                if (CountDel[i].hospitalSpecialOffer__c) {
+                                    Jstage.hospitalSpecialOffer = true;
+                                } else {
+                                    Jstage.hospitalSpecialOffer = false;
+                                }
+
+                                if (HosProMap.containsKey(Jstage.Prod.Id)) {
+                                    Jstage.hosPro = true;
+                                }
+                                MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
+                            } else {
+                                //midmap2涓病鏈夊搴旂殑浜у搧
+                                ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
+                                Jstage.allnumber = Jstage.allnumber + 1;
+                                if (CountDel[i].Box_Piece__c == '鐩�') {
+                                    Jstage.Boxnumber = Jstage.Boxnumber + 1;
+                                } else if (CountDel[i].Box_Piece__c == '涓�') {
+                                    Jstage.Piecenumber = Jstage.Piecenumber + 1;
+                                }
+                                if (CountDel[i].hospitalSpecialOffer__c) {
+                                    Jstage.hospitalSpecialOffer = true;
+                                } else {
+                                    Jstage.hospitalSpecialOffer = false;
+                                }
+
+                                if (HosProMap.containsKey(Jstage.Prod.Id)) {
+                                    Jstage.hosPro = true;
+                                }
+                                //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
+                                MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
+                            }
+                        }
+                    }
+
+                    //鍐嶆妸map閲岀殑鍊间粠鏂拌祴缁機onsumableorderdetailsRecords
+                    //update by rentx 2021-01-29
+                    // for(ConsumableorderdetailsInfo bss : MidMap.values()){
+                    for (ConsumableorderdetailsInfo bss : MidMap2.values()) {
+                        //update by rentx 2021-01-29
+                        bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
+                        bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
+                        bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
+                        consumableorderdetailsSelectRecords.add(bss);
+                    }
+                    //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'test11111' + consumableorderdetailsSelected.size()));
+                    //return;
+
+                    Integer ishosnum = 0;
+                    for (ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords) {
+                        //ass.sortBy = sortOrderAsc;
+                        for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
+                            cdc1.Shipment_Count__c = cdc1.Consumable_count__c;
+                            if (ass.prod.Id == cdc1.Consumable_Product__c) {
+                                ass.check = true;
+                                ass.orderdetails1 = cdc1;
+                            }
+                        }
+                        if (ass.hospitalSpecialOffer == true) {
+                            ishosnum = ishosnum + 1;
+                        }
+                    }
+                    if (ishosnum > 0) {
+                        hasHosPro = true;
+                    } else {
+                        hasHosPro = false;
+                    }
+
+                    consumableorderdetailsSelectRecords.sort();
+                    //add by rentx
+                    noOfRecords = consumableorderdetailsSelectRecords.size();
+                    //add by rentx
+                    System.debug('makepagerecords2');
+                    makepagerecords();
+                    consumablearriveproductdetailsSelected = [
+                        SELECT
+                            Id,
+                            Name,
+                            Intra_Trade_List_RMB__c,
+                            Asset_Model_No__c,
+                            Consumable_Product__c,
+                            Consumable_Product__r.Name,
+                            Consumable_Product__r.Name__c,
+                            Consumable_Product__r.Category3__c,
+                            Consumable_Product__r.Category4__c,
+                            Consumable_Product__r.Category5__c,
+                            Sterilization_limit__c,
+                            Deliver_date__c,
+                            Bar_Code__c,
+                            Arrive_date__c,
+                            Send_Date__c,
+                            Consumable_order_minor__r.Name,
+                            Consumable_order_minor__c,
+                            Dealer_Arrive__c,
+                            Delivery_List_RMB__c,
+                            Box_Piece__c,
+                            ProductPacking_list_manual__c,
+                            //add by rentx start
+                            hospitalSpecialOffer__c
+                        //add by rentx end
+                        FROM Consumable_order_details2__c
+                        WHERE
+                            Consumable_order_minor__c = :coc.Arrive_Order__c
+                            AND recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery
+                            AND Dealer_Arrive__c = TRUE
+                        ORDER BY Name
+                    ];
+                    for (Integer i = 0; i < consumablearriveproductdetailsSelected.size(); i++) {
+                        if (
+                            consumablearriveproductdetailsSelected[i].hospitalSpecialOffer__c &&
+                            HosProMap.containsKey(consumablearriveproductdetailsSelected[i].Consumable_product__c)
+                        ) {
+                            coc.OutPattern__c = true;
+                        }
+                        consumableproductdetailsRecords.add(new ConsumableorderdetailsInfo(consumablearriveproductdetailsSelected[i]));
                     }
                 }
-                if (ishosnum > 0) {
-                    hasHosPro = true;
-                } else {
-                    hasHosPro = false;
-                }
-                consumableorderdetailsSelectRecords.sort();
-                //add by rentx
-                noOfRecords = consumableorderdetailsSelectRecords.size();
-                //add by rentx
-                System.debug('makepagerecords1');
-                makepagerecords();
-                //listCut();
             } else {
-                if (statusEdit == '' || statusEdit == null) {
-                    editAble = false;
-                } else if (statusEdit != '' && statusEdit != null) {
-                    editAble = true;
-                }
-                // upadte start by vivek 2019-7-15
-                // coc = [SELECT Id,Name,Summons_Order_type__c,SummonsStatus_c__c,Order_ForDealerText__c,
-                //             Dealer_Info__c,Order_ForDealer__c,Order_ForDealer__r.Name,Order_ForDealerTextID__c,
-                //             Order_ForHospital__c,SummonsForDirction__c,Order_date__c,Arrive_Order__c,
-                //             Order_status__c,Shipment_total_amount__c,Offers_Price__c,
-                //             Billed_Status__c,ShipmentAccount__c,Order_Dealer_Info__c,Order_ForCustomerText__c,ConInvoice_Code__c,Onchange_order__c
-                //         FROM Consumable_order__c
-                //         WHERE Id =:arriveorder AND Order_Owner_WorkLocal__c =: userWorkLocation
-                //         AND recordtypeid = :System.Label.RT_ConOrder_Arrive];
+                // 鏇存柊銆�
+                SummonsFlag = 'visible';
+                // update start by vivek 2019-7-15 add 鈥淣oConfirmedPrice__c鈥� in select
+                consumableInvoiceRecords = [
+                    SELECT Id, Name, Invoice_Date__c, NoConfirmedPrice__c, Invoice_total_amount__c, Invoice_status__c
+                    FROM Consumable_order__c
+                    WHERE
+                        Id IN (SELECT Invoice_Code_link__c FROM Consumable_order_LinkTable__c WHERE Outboundorder_Code_link__c = :ESetId)
+                        AND Invoice_status__c != '鑽夋涓�'
+                ];
+
+                System.debug('coc ESetId = ' + ESetId);
+                System.debug('coc userWorkLocation = ' + userWorkLocation);
                 coc = [
                     SELECT
                         Id,
@@ -510,841 +776,632 @@
                         Onchange_order__c,
                         OutPattern__c
                     FROM Consumable_order__c
-                    WHERE
-                        Id = :arriveorder
-                        AND Order_Owner_WorkLocal__c = :userWorkLocation
-                        AND recordtypeid = :System.Label.RT_ConOrder_Arrive
+                    WHERE Id = :ESetId AND Order_Owner_WorkLocal__c = :userWorkLocation AND Order_type__c = '浼犵エ'
                 ];
-                // update end by vivek 2019-7-15
-                //鏄庣粏1鑾峰彇
-                consumableorderdetailsSelected = [
-                    SELECT
-                        Id,
-                        Dealer_Custom_Price__c,
-                        Delivery_List_RMB__c,
-                        Consumable_Product__r.Name__c,
-                        Name,
-                        Consumable_order__c,
-                        Consumable_Product__c,
-                        Consumable_Product__r.Name,
-                        Consumable_Product__r.Category3__c,
-                        Consumable_Product__r.Category4__c,
-                        Consumable_Product__r.Category5__c,
-                        Shipment_Count__c,
-                        Consumable_Product__r.Intra_Trade_List_RMB__c,
-                        Consumable_Product__r.Asset_Model_No__c,
-                        Sum_of_money__c,
-                        Box_Piece__c,
-                        ProductPacking_list_manual__c,
-                        Consumable_Product__r.SFDA_Status__c,
-                        Consumable_count__c,
-                        Invoiced_Procount__c,
-                        RrturnPro_count__c,
-                        InvoiceProNot_count__c,
-                        //Unitprice_To_agency__c,
-                        Consumable_Product__r.Product2__r.SFDA_Approbation_No__c,
-                        Consumable_Product__r.Product2__r.SFDA_Expiration_Date__c
-                    FROM Consumable_Orderdetails__c
-                    WHERE Consumable_order__c = :coc.Arrive_Order__c
-                    ORDER BY Name
-                ];
-                for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
-                    orderzaikuId.add(cdc1.Consumable_Product__c);
+                // update start by vivek 2019-7-15
+                if (getExistarrive()) {
+                    arriveorder = coc.Arrive_Order__c;
                 }
-                msoql = makeSoqlorderdet();
-                product2Selected = Database.query(msoql);
-                size = product2Selected.size();
-                initStandardController(msoql);
-                for (Integer i = 0; i < product2Selected.size(); i++) {
-                    MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
-                }
-                //update by rentx 2021-01-29
-                /*for(Integer i = 0 ; i< CountDel.size();i++){
-                        //鐒跺悗寰幆CountDel鍘讳慨鏀筸ap閲岀殑allnumber
-                        if(MidMap.containsKey(CountDel[i].Consumable_Product__c)){
-                            ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c);
-                            Jstage.allnumber = Jstage.allnumber+1 ;
-                            if(CountDel[i].Box_Piece__c == '鐩�'){
-                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
-                            }else if(CountDel[i].Box_Piece__c == '涓�'){
-                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
-                            }
-                            //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
-                            MidMap.put(CountDel[i].Consumable_Product__c, Jstage);
-                        }
-
-                    }*/
-                for (Integer i = 0; i < CountDel.size(); i++) {
-                    String str = '';
-                    if (CountDel[i].hospitalSpecialOffer__c) {
-                        str = 'isHos';
-                    } else {
-                        str = 'notHos';
+                // 鍒拌揣璁㈠崟鏉ョ殑鏃跺��
+                if (getExistarrive()) {
+                    if (editAble) {
+                        alertMessage = '鍒拌揣璁㈠崟鐩存帴鍑哄簱锛屽嚭搴撳崟鏄庣粏涓嶅彲缂栬緫';
                     }
-                    //鏄庣粏2瀵瑰簲鐨勪骇鍝佸瓨鍦ㄤ簬MidMap涓�
-                    if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
-                        //璁剧疆map涓璳ey鐨勫悗缂� 鐢ㄤ簬鍖哄垎鍖婚櫌鐗逛环鍜岄潪鍖婚櫌鐗逛环
-                        if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
-                            ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c + str);
-                            Jstage.allnumber = Jstage.allnumber + 1;
-                            if (CountDel[i].Box_Piece__c == '鐩�') {
-                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
-                            } else if (CountDel[i].Box_Piece__c == '涓�') {
-                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
-                            }
-                            if (CountDel[i].hospitalSpecialOffer__c) {
-                                Jstage.hospitalSpecialOffer = true;
-                            } else {
-                                Jstage.hospitalSpecialOffer = false;
-                            }
-
-                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
-                                Jstage.hosPro = true;
-                            }
-                            MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
-                        } else {
-                            //midmap2涓病鏈夊搴旂殑浜у搧
-                            ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
-                            Jstage.allnumber = Jstage.allnumber + 1;
-                            if (CountDel[i].Box_Piece__c == '鐩�') {
-                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
-                            } else if (CountDel[i].Box_Piece__c == '涓�') {
-                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
-                            }
-                            if (CountDel[i].hospitalSpecialOffer__c) {
-                                Jstage.hospitalSpecialOffer = true;
-                            } else {
-                                Jstage.hospitalSpecialOffer = false;
-                            }
-
-                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
-                                Jstage.hosPro = true;
-                            }
-                            //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
-                            MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
-                        }
+                    if (coc.SummonsStatus_c__c == '宸叉彁浜�' || coc.SummonsStatus_c__c == '鎵瑰噯') {
+                        system.debug('coc.SummonsStatus_c__c : ' + coc.SummonsStatus_c__c);
+                        saveBtnDisabled = true;
+                        SorderBtnDisabled = true;
+                        EditDelCommitBtnDisabled = false;
                     }
-                }
+                    //鍖婚櫌浜岀骇缁忛攢鍟嗗垎绫�
+                    Integer io = 0;
+                    while (io < Dealerelationship.size()) {
+                        if (coc.Order_ForDealer__c == Dealerelationship[io].Dealer_subordinate__c) {
+                            SecondDealer = Dealerelationship[io].Dealer_subordinate__c;
+                            coc.Order_ForDealer__c = null;
+                            io = io + Dealerelationship.size();
+                        }
+                        io++;
+                    }
 
-                //鍐嶆妸map閲岀殑鍊间粠鏂拌祴缁機onsumableorderdetailsRecords
-                //update by rentx 2021-01-29
-                // for(ConsumableorderdetailsInfo bss : MidMap.values()){
-                for (ConsumableorderdetailsInfo bss : MidMap2.values()) {
-                    //update by rentx 2021-01-29
-                    bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
-                    bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
-                    bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
-                    consumableorderdetailsSelectRecords.add(bss);
-                }
-                //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'test11111' + consumableorderdetailsSelected.size()));
-                //return;
+                    Integer ik = 0;
+                    while (ik < AgencyHospitalLink.size()) {
+                        if (coc.Order_ForHospital__c == AgencyHospitalLink[ik].Hospital__c) {
+                            HospitalInfo = AgencyHospitalLink[ik].Hospital__c;
+                            HospitalName = AgencyHospitalLink[ik].Hospital__r.Name;
+                            coc.Order_ForHospital__c = null;
+                            ik = ik + AgencyHospitalLink.size();
+                        }
+                        ik++;
+                    }
+                    //鍑哄簱鍗曟槑缁�1鍙栧緱
+                    consumableorderdetailsSelected = [
+                        SELECT
+                            Id,
+                            Dealer_Custom_Price__c,
+                            Delivery_List_RMB__c,
+                            Consumable_Product__r.Name__c,
+                            Consumable_Product__r.SFDA_Status__c,
+                            Name,
+                            Consumable_order__c,
+                            Consumable_Product__c,
+                            Consumable_Product__r.Name,
+                            Shipment_Count__c,
+                            Consumable_Product__r.Intra_Trade_List_RMB__c,
+                            Consumable_Product__r.Asset_Model_No__c,
+                            Consumable_Product__r.Category3__c,
+                            Consumable_Product__r.Category4__c,
+                            Consumable_Product__r.Category5__c,
+                            Shipment_amount__c,
+                            //Unitprice_To_agency__c,
+                            Box_Piece__c,
+                            ProductPacking_list_manual__c,
+                            Invoiced_Procount__c,
+                            RrturnPro_count__c,
+                            InvoiceProNot_count__c,
+                            Consumable_Product__r.Product2__r.SFDA_Approbation_No__c,
+                            Consumable_Product__r.Product2__r.SFDA_Expiration_Date__c,
+                            isOutPattern__c
+                        FROM Consumable_orderdetails__c
+                        WHERE Consumable_order__c = :ESetId AND Consumable_order__r.Order_Owner_WorkLocal__c = :userWorkLocation
+                        ORDER BY Name
+                    ];
+                    Map<String, Consumable_Orderdetails__c> cocMap = new Map<String, Consumable_Orderdetails__c>();
 
-                Integer ishosnum = 0;
-                for (ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords) {
-                    ass.sortBy = sortOrderAsc;
                     for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
-                        cdc1.Shipment_Count__c = cdc1.Consumable_count__c;
-                        if (ass.prod.Id == cdc1.Consumable_Product__c) {
-                            ass.check = true;
-                            ass.orderdetails1 = cdc1;
+                        sumPrice += cdc1.Shipment_amount__c;
+                        orderzaikuId.add(cdc1.Consumable_Product__c);
+                        //add by rentx 2021-2-26
+                        String tempId = cdc1.Consumable_product__c;
+                        if (cdc1.isOutPattern__c) {
+                            cocMap.put(tempId + 'ishos', cdc1);
+                        } else {
+                            cocMap.put(tempId + 'nothos', cdc1);
+                        }
+                        //add by rentx 2021-2-26
+                    }
+                    String msoql = makeSoqlorderdet();
+                    product2Selected = Database.query(msoql);
+                    size = product2Selected.size();
+                    initStandardController(msoql);
+
+                    for (Integer i = 0; i < product2Selected.size(); i++) {
+                        MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
+                    }
+                    //update by rentx 2021-01-29
+                    /*for(Integer i = 0 ; i< CountDel.size();i++){
+                            //鐒跺悗寰幆CountDel鍘讳慨鏀筸ap閲岀殑allnumber
+                            if(MidMap.containsKey(CountDel[i].Consumable_Product__c)){
+                                ConsumableorderdetailsInfo Jstage =  MidMap.get(CountDel[i].Consumable_Product__c);
+                                Jstage.allnumber = Jstage.allnumber+1 ;
+                                if(CountDel[i].Box_Piece__c == '鐩�'){
+                                    Jstage.Boxnumber = Jstage.Boxnumber + 1;
+                                }else if(CountDel[i].Box_Piece__c == '涓�'){
+                                    Jstage.Piecenumber = Jstage.Piecenumber + 1;
+                                }
+                                //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
+                                MidMap.put(CountDel[i].Consumable_Product__c, Jstage);
+                            }
+                        }*/
+
+                    for (Integer i = 0; i < CountDel.size(); i++) {
+                        String str = '';
+                        if (CountDel[i].hospitalSpecialOffer__c) {
+                            str = 'isHos';
+                        } else {
+                            str = 'notHos';
+                        }
+                        //鏄庣粏2瀵瑰簲鐨勪骇鍝佸瓨鍦ㄤ簬MidMap涓�
+                        if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
+                            //璁剧疆map涓璳ey鐨勫悗缂� 鐢ㄤ簬鍖哄垎鍖婚櫌鐗逛环鍜岄潪鍖婚櫌鐗逛环
+                            if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
+                                ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c + str);
+                                Jstage.allnumber = Jstage.allnumber + 1;
+                                if (CountDel[i].Box_Piece__c == '鐩�') {
+                                    Jstage.Boxnumber = Jstage.Boxnumber + 1;
+                                } else if (CountDel[i].Box_Piece__c == '涓�') {
+                                    Jstage.Piecenumber = Jstage.Piecenumber + 1;
+                                }
+                                if (CountDel[i].hospitalSpecialOffer__c) {
+                                    Jstage.hospitalSpecialOffer = true;
+                                } else {
+                                    Jstage.hospitalSpecialOffer = false;
+                                }
+
+                                if (HosProMap.containsKey(Jstage.Prod.Id)) {
+                                    Jstage.hosPro = true;
+                                }
+                                MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
+                            } else {
+                                //midmap2涓病鏈夊搴旂殑浜у搧
+                                ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
+                                Jstage.allnumber = Jstage.allnumber + 1;
+                                if (CountDel[i].Box_Piece__c == '鐩�') {
+                                    Jstage.Boxnumber = Jstage.Boxnumber + 1;
+                                } else if (CountDel[i].Box_Piece__c == '涓�') {
+                                    Jstage.Piecenumber = Jstage.Piecenumber + 1;
+                                }
+                                if (CountDel[i].hospitalSpecialOffer__c) {
+                                    Jstage.hospitalSpecialOffer = true;
+                                } else {
+                                    Jstage.hospitalSpecialOffer = false;
+                                }
+                                if (HosProMap.containsKey(Jstage.Prod.Id)) {
+                                    Jstage.hosPro = true;
+                                }
+                                //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
+                                MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
+                            }
                         }
                     }
-                    if (ass.hospitalSpecialOffer == true) {
-                        ishosnum = ishosnum + 1;
-                    }
-                }
-                if (ishosnum > 0) {
-                    hasHosPro = true;
-                } else {
-                    hasHosPro = false;
-                }
+                    //update by rentx 2021-01-29
+                    consumableorderdetailsSelectRecords = new List<ConsumableorderdetailsInfo>();
+                    //鍐嶆妸map閲岀殑鍊间粠鏂拌祴缁機onsumableorderdetailsRecords
+                    //update by rentx 2021-01-29
+                    // for(ConsumableorderdetailsInfo bss : MidMap.values()){
+                    for (ConsumableorderdetailsInfo bss : MidMap2.values()) {
+                        //update by rentx 2021-01-29
 
-                consumableorderdetailsSelectRecords.sort();
-                //add by rentx
-                noOfRecords = consumableorderdetailsSelectRecords.size();
-                //add by rentx
-                System.debug('makepagerecords2');
-                makepagerecords();
-                consumablearriveproductdetailsSelected = [
-                    SELECT
-                        Id,
-                        Name,
-                        Intra_Trade_List_RMB__c,
-                        Asset_Model_No__c,
-                        Consumable_Product__c,
-                        Consumable_Product__r.Name,
-                        Consumable_Product__r.Name__c,
-                        Consumable_Product__r.Category3__c,
-                        Consumable_Product__r.Category4__c,
-                        Consumable_Product__r.Category5__c,
-                        Sterilization_limit__c,
-                        Deliver_date__c,
-                        Bar_Code__c,
-                        Arrive_date__c,
-                        Send_Date__c,
-                        Consumable_order_minor__r.Name,
-                        Consumable_order_minor__c,
-                        Dealer_Arrive__c,
-                        Delivery_List_RMB__c,
-                        Box_Piece__c,
-                        ProductPacking_list_manual__c,
-                        //add by rentx start
-                        hospitalSpecialOffer__c
-                    //add by rentx end
-                    FROM Consumable_order_details2__c
-                    WHERE
-                        Consumable_order_minor__c = :coc.Arrive_Order__c
-                        AND recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery
-                        AND Dealer_Arrive__c = TRUE
-                    ORDER BY Name
-                ];
-                for (Integer i = 0; i < consumablearriveproductdetailsSelected.size(); i++) {
-                    if (
-                        consumablearriveproductdetailsSelected[i].hospitalSpecialOffer__c &&
-                        HosProMap.containsKey(consumablearriveproductdetailsSelected[i].Consumable_product__c)
-                    ) {
-                        coc.OutPattern__c = true;
+                        //if(bss.allnumber > 0){
+                        //bss.UnitpriceToagency = bss.orderdetails1.Unitprice_To_agency__c == null  || bss.orderdetails1.Unitprice_To_agency__c == 0 ? '' :bss.orderdetails1.Unitprice_To_agency__c.format();
+                        bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
+                        bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
+                        bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
+
+                        //update by rentx 2021-2-26 start
+                        if (cocMap.containsKey(bss.Prod.Id + 'ishos') && bss.hospitalSpecialOffer == true) {
+                            consumableorderdetailsSelectRecords.add(bss);
+                        } else if (cocMap.containsKey(bss.Prod.Id + 'nothos') && bss.hospitalSpecialOffer == false) {
+                            consumableorderdetailsSelectRecords.add(bss);
+                        }
+                        //update by rentx 2021-2-26 end
+                        // consumableorderdetailsSelectRecords.add(bss);
+                        //}
                     }
-                    consumableproductdetailsRecords.add(new ConsumableorderdetailsInfo(consumablearriveproductdetailsSelected[i]));
+                    Integer ishosnum = 0;
+                    for (ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords) {
+                        for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
+                            //update by rentx 2012-3-1 start
+                            // if(ass.prod.Id == cdc1.Consumable_Product__c){
+                            //     ass.check = true;
+                            //     ass.orderdetails1 = cdc1;
+                            // }
+                            if (ass.Prod.Id == cdc1.Consumable_Product__c && ass.hospitalSpecialOffer == cdc1.isOutPattern__c) {
+                                ass.check = true;
+                                ass.orderdetails1 = cdc1;
+                            }
+                            //update by rentx 2012-3-1 end
+                        }
+                        if (ass.hospitalSpecialOffer == true) {
+                            ishosnum = ishosnum + 1;
+                        }
+                    }
+                    if (ishosnum > 0) {
+                        hasHosPro = true;
+                    } else {
+                        hasHosPro = false;
+                    }
+
+                    //add by rentx
+                    noOfRecords = consumableorderdetailsSelectRecords.size();
+                    //add by rentx
+                    System.debug('makepagerecords3');
+                    makepagerecords();
+                    //listCut();
+                    // 娑堣�楀搧鏄庣粏2銈掑彇寰�
+                    consumableorderdetails2RecordsList = [
+                        SELECT
+                            Id,
+                            Name,
+                            SerialLotNo__c,
+                            Consumable_Product__r.Name__c,
+                            TracingCode__c,
+                            Sterilization_limit__c,
+                            Consumable_Product__c,
+                            Consumable_Product__r.Name,
+                            Consumable_Product__r.Category3__c,
+                            Consumable_Product__r.Category4__c,
+                            Consumable_Product__r.Category5__c,
+                            Return_date__c,
+                            Invoice_Date__c,
+                            Box_Piece__c,
+                            ProductPacking_list_manual__c,
+                            //add by rentx start
+                            hospitalSpecialOffer__c
+                        //add by rentx end
+                        FROM Consumable_order_details2__c
+                        WHERE Consumable_ZS_order__c = :ESetId
+                        ORDER BY Name
+                    ];
+                    for (Integer i = 0; i < consumableorderdetails2RecordsList.size(); i++) {
+                        consumableorderdetails2Records.add(new ConsumableorderdetailsInfo(consumableorderdetails2RecordsList[i]));
+                    }
+                    //浜у搧鏄庣粏鍙栧緱
+                    consumablearriveproductdetailsSelected = [
+                        SELECT
+                            Id,
+                            Delivery_List_RMB__c,
+                            Consumable_Product__r.Name__c,
+                            Name,
+                            Consumable_Product__r.SFDA_Status__c,
+                            Consumable_Product__r.Category3__c,
+                            Consumable_Product__r.Category4__c,
+                            Consumable_Product__r.Category5__c,
+                            Consumable_Product__c,
+                            Consumable_Product__r.Name,
+                            Sterilization_limit__c,
+                            Consumable_Product__r.Intra_Trade_List_RMB__c,
+                            Consumable_Product__r.Asset_Model_No__c,
+                            Box_Piece__c,
+                            ProductPacking_list_manual__c,
+                            //add by rentx start
+                            hospitalSpecialOffer__c
+                        //add by rentx end
+                        FROM Consumable_order_details2__c
+                        WHERE Consumable_ZS_order__c = :ESetId
+                        ORDER BY Name
+                    ];
+                    for (Integer i = 0; i < consumablearriveproductdetailsSelected.size(); i++) {
+                        consumableproductdetailsRecords.add(new ConsumableorderdetailsInfo(consumablearriveproductdetailsSelected[i]));
+                    }
+                } else {
+                    // 涓嶆槸鍒拌揣璁㈠崟鏉ョ殑鏃跺��
+                    if (coc.SummonsStatus_c__c == '宸叉彁浜�' || coc.SummonsStatus_c__c == '鎵瑰噯') {
+                        system.debug('coc.SummonsStatus_c__c : ' + coc.SummonsStatus_c__c);
+                        saveBtnDisabled = true;
+                        SorderBtnDisabled = true;
+                        EditDelCommitBtnDisabled = false;
+                    }
+                    //鍖婚櫌浜岀骇缁忛攢鍟嗗垎绫�
+                    Integer io = 0;
+                    while (io < Dealerelationship.size()) {
+                        if (coc.Order_ForDealer__c == Dealerelationship[io].Dealer_subordinate__c) {
+                            SecondDealer = Dealerelationship[io].Dealer_subordinate__c;
+                            coc.Order_ForDealer__c = null;
+                            io = io + Dealerelationship.size();
+                        }
+                        io++;
+                    }
+                    Integer ik = 0;
+                    while (ik < AgencyHospitalLink.size()) {
+                        if (coc.Order_ForHospital__c == AgencyHospitalLink[ik].Hospital__c) {
+                            HospitalInfo = AgencyHospitalLink[ik].Hospital__c;
+                            HospitalName = AgencyHospitalLink[ik].Hospital__r.Name;
+                            coc.Order_ForHospital__c = null;
+                            ik = ik + AgencyHospitalLink.size();
+                        }
+                        ik++;
+                    }
+                    // 娑堣�楀搧鏄庣粏1銈掑彇寰�
+                    consumableorderdetailsSelected = [
+                        SELECT
+                            Id,
+                            Dealer_Custom_Price__c,
+                            Delivery_List_RMB__c,
+                            Consumable_Product__r.Name__c,
+                            Consumable_Product__r.SFDA_Status__c,
+                            Name,
+                            Consumable_order__c,
+                            Consumable_Product__c,
+                            Consumable_Product__r.Name,
+                            Shipment_Count__c,
+                            Consumable_Product__r.Intra_Trade_List_RMB__c,
+                            Consumable_Product__r.Asset_Model_No__c,
+                            Shipment_amount__c,
+                            Box_Piece__c,
+                            ProductPacking_list_manual__c,
+                            Invoiced_Procount__c,
+                            RrturnPro_count__c,
+                            //Unitprice_To_agency__c,
+                            InvoiceProNot_count__c,
+                            Consumable_Product__r.Category3__c,
+                            Consumable_Product__r.Category4__c,
+                            Consumable_Product__r.Category5__c,
+                            Consumable_Product__r.Product2__r.SFDA_Approbation_No__c,
+                            Consumable_Product__r.Product2__r.SFDA_Expiration_Date__c,
+                            isOutPattern__c
+                        FROM Consumable_orderdetails__c
+                        WHERE Consumable_order__c = :ESetId AND Consumable_order__r.Order_Owner_WorkLocal__c = :userWorkLocation
+                        ORDER BY Name
+                    ];
+                    //add by rentx 202-2-26
+                    Map<String, Consumable_Orderdetails__c> cocMap = new Map<String, Consumable_Orderdetails__c>();
+
+                    for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
+                        sumPrice += cdc1.Shipment_amount__c;
+                        orderzaikuId.add(cdc1.Consumable_Product__c);
+                        //add by rentx 2021-2-26
+                        String tempId = cdc1.Consumable_product__c;
+                        if (cdc1.isOutPattern__c) {
+                            cocMap.put(tempId + 'ishos', cdc1);
+                        } else {
+                            cocMap.put(tempId + 'nothos', cdc1);
+                        }
+                        //add by rentx 2021-2-26
+                    }
+
+                    String msoql = makeSoqlorderdet();
+                    product2Selected = Database.query(msoql);
+                    size = product2Selected.size();
+                    initStandardController(msoql);
+                    for (Integer i = 0; i < product2Selected.size(); i++) {
+                        MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
+                    }
+
+                    for (Integer i = 0; i < CountDel.size(); i++) {
+                        String str = '';
+                        if (CountDel[i].hospitalSpecialOffer__c) {
+                            str = 'isHos';
+                        } else {
+                            str = 'notHos';
+                        }
+                        //鏄庣粏2瀵瑰簲鐨勪骇鍝佸瓨鍦ㄤ簬MidMap涓�
+                        if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
+                            //璁剧疆map涓璳ey鐨勫悗缂� 鐢ㄤ簬鍖哄垎鍖婚櫌鐗逛环鍜岄潪鍖婚櫌鐗逛环
+                            if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
+                                ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c + str);
+                                Jstage.allnumber = Jstage.allnumber + 1;
+                                if (CountDel[i].Box_Piece__c == '鐩�') {
+                                    Jstage.Boxnumber = Jstage.Boxnumber + 1;
+                                } else if (CountDel[i].Box_Piece__c == '涓�') {
+                                    Jstage.Piecenumber = Jstage.Piecenumber + 1;
+                                }
+                                if (CountDel[i].hospitalSpecialOffer__c) {
+                                    Jstage.hospitalSpecialOffer = true;
+                                } else {
+                                    Jstage.hospitalSpecialOffer = false;
+                                }
+                                if (HosProMap.containsKey(Jstage.Prod.Id)) {
+                                    Jstage.hosPro = true;
+                                }
+                                MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
+                            } else {
+                                //midmap2涓病鏈夊搴旂殑浜у搧
+                                ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
+                                Jstage.allnumber = Jstage.allnumber + 1;
+                                if (CountDel[i].Box_Piece__c == '鐩�') {
+                                    Jstage.Boxnumber = Jstage.Boxnumber + 1;
+                                } else if (CountDel[i].Box_Piece__c == '涓�') {
+                                    Jstage.Piecenumber = Jstage.Piecenumber + 1;
+                                }
+
+                                if (CountDel[i].hospitalSpecialOffer__c) {
+                                    Jstage.hospitalSpecialOffer = true;
+                                } else {
+                                    Jstage.hospitalSpecialOffer = false;
+                                }
+                                if (HosProMap.containsKey(Jstage.Prod.Id)) {
+                                    Jstage.hosPro = true;
+                                }
+                                Jstage.BoxPiece = CountDel[i].Box_Piece__c;
+                                MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
+                            }
+                        }
+                    }
+
+                    //鍐嶆妸map閲岀殑鍊间粠鏂拌祴缁機onsumableorderdetailsRecords
+                    //update by rentx 2021-01-29
+                    // for(ConsumableorderdetailsInfo bss : MidMap.values()){
+                    for (ConsumableorderdetailsInfo bss : MidMap2.values()) {
+                        //update by rentx 2021-01-29
+
+                        //if(bss.allnumber>0){
+                        bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
+                        bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
+                        bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
+
+                        //update by rentx 2021-2-26 start
+                        if (cocMap.containsKey(bss.Prod.Id + 'ishos') && bss.hospitalSpecialOffer == true) {
+                            consumableorderdetailsSelectRecords.add(bss);
+                        } else if (cocMap.containsKey(bss.Prod.Id + 'nothos') && bss.hospitalSpecialOffer == false) {
+                            consumableorderdetailsSelectRecords.add(bss);
+                        }
+                        // consumableorderdetailsSelectRecords.add(bss);
+                        //}
+                    }
+                    // return null;
+                    Integer ishosnum = 0;
+                    for (ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords) {
+                        //ass.sortBy = sortOrderAsc;
+                        for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
+                            //update by rentx 2012-3-1 start
+                            // if(ass.prod.Id == cdc1.Consumable_Product__c){
+                            //     ass.check = true;
+                            //     ass.orderdetails1 = cdc1;
+                            // }
+                            if (ass.Prod.Id == cdc1.Consumable_Product__c && ass.hospitalSpecialOffer == cdc1.isOutPattern__c) {
+                                ass.check = true;
+                                ass.orderdetails1 = cdc1;
+                            }
+                            //update by rentx 2012-3-1 end
+                        }
+
+                        if (ass.hospitalSpecialOffer == true) {
+                            ishosnum = ishosnum + 1;
+                        }
+                    }
+
+                    if (ishosnum > 0) {
+                        hasHosPro = true;
+                    } else {
+                        hasHosPro = false;
+                    }
+
+                    consumableorderdetailsSelectRecords.sort();
+                    //add by rentx
+                    noOfRecords = consumableorderdetailsSelectRecords.size();
+                    //add by rentx
+                    System.debug('makepagerecords4');
+                    makepagerecords();
+
+                    // 娑堣�楀搧鏄庣粏2銈掑彇寰�
+                    consumableorderdetails2RecordsList = [
+                        SELECT
+                            Id,
+                            Name,
+                            SerialLotNo__c,
+                            Consumable_Product__r.Name__c,
+                            TracingCode__c,
+                            Sterilization_limit__c,
+                            Consumable_Product__c,
+                            Consumable_Product__r.Name,
+                            Consumable_Product__r.Category3__c,
+                            Consumable_Product__r.Category4__c,
+                            Consumable_Product__r.Category5__c,
+                            Return_date__c,
+                            Invoice_Date__c,
+                            Box_Piece__c,
+                            ProductPacking_list_manual__c,
+                            //add by rentx start
+                            hospitalSpecialOffer__c
+                        //add by rentx end
+
+                        FROM Consumable_order_details2__c
+                        WHERE Consumable_ZS_order__c = :ESetId
+                        ORDER BY Name
+                    ];
+                    for (Integer i = 0; i < consumableorderdetails2RecordsList.size(); i++) {
+                        consumableorderdetails2Records.add(new ConsumableorderdetailsInfo(consumableorderdetails2RecordsList[i]));
+                    }
                 }
             }
-        } else {
-            // 鏇存柊銆�
-            SummonsFlag = 'visible';
-            // update start by vivek 2019-7-15 add 鈥淣oConfirmedPrice__c鈥� in select
-            consumableInvoiceRecords = [
-                SELECT Id, Name, Invoice_Date__c, NoConfirmedPrice__c, Invoice_total_amount__c, Invoice_status__c
-                FROM Consumable_order__c
-                WHERE
-                    Id IN (SELECT Invoice_Code_link__c FROM Consumable_order_LinkTable__c WHERE Outboundorder_Code_link__c = :ESetId)
-                    AND Invoice_status__c != '鑽夋涓�'
-            ];
-
-            coc = [
-                SELECT
-                    Id,
-                    Name,
-                    Summons_Order_type__c,
-                    NoConfirmedPrice__c,
-                    SummonsStatus_c__c,
-                    Order_ForDealerText__c,
-                    Dealer_Info__c,
-                    Order_ForDealer__c,
-                    Order_ForDealer__r.Name,
-                    Order_ForDealerTextID__c,
-                    Order_ForHospital__c,
-                    SummonsForDirction__c,
-                    Order_date__c,
-                    Arrive_Order__c,
-                    Order_status__c,
-                    Shipment_total_amount__c,
-                    Offers_Price__c,
-                    Billed_Status__c,
-                    ShipmentAccount__c,
-                    Order_Dealer_Info__c,
-                    Order_ForCustomerText__c,
-                    ConInvoice_Code__c,
-                    Onchange_order__c,
-                    OutPattern__c
-                FROM Consumable_order__c
-                WHERE Id = :ESetId AND Order_Owner_WorkLocal__c = :userWorkLocation AND Order_type__c = '浼犵エ'
-            ];
-            // update start by vivek 2019-7-15
-            if (getExistarrive()) {
-                arriveorder = coc.Arrive_Order__c;
-            }
-            // 鍒拌揣璁㈠崟鏉ョ殑鏃跺��
-            if (getExistarrive()) {
-                if (editAble) {
-                    alertMessage = '鍒拌揣璁㈠崟鐩存帴鍑哄簱锛屽嚭搴撳崟鏄庣粏涓嶅彲缂栬緫銆�';
-                }
-                if (coc.SummonsStatus_c__c == '宸叉彁浜�' || coc.SummonsStatus_c__c == '鎵瑰噯') {
-                    system.debug('coc.SummonsStatus_c__c : ' + coc.SummonsStatus_c__c);
-                    saveBtnDisabled = true;
-                    SorderBtnDisabled = true;
-                    EditDelCommitBtnDisabled = false;
-                }
-                //鍖婚櫌浜岀骇缁忛攢鍟嗗垎绫�
-                Integer io = 0;
-                while (io < Dealerelationship.size()) {
-                    if (coc.Order_ForDealer__c == Dealerelationship[io].Dealer_subordinate__c) {
-                        SecondDealer = Dealerelationship[io].Dealer_subordinate__c;
-                        coc.Order_ForDealer__c = null;
-                        io = io + Dealerelationship.size();
-                    }
-                    io++;
-                }
-
-                Integer ik = 0;
-                while (ik < AgencyHospitalLink.size()) {
-                    if (coc.Order_ForHospital__c == AgencyHospitalLink[ik].Hospital__c) {
-                        HospitalInfo = AgencyHospitalLink[ik].Hospital__c;
-                        HospitalName = AgencyHospitalLink[ik].Hospital__r.Name;
-                        coc.Order_ForHospital__c = null;
-                        ik = ik + AgencyHospitalLink.size();
-                    }
-                    ik++;
-                }
-                //鍑哄簱鍗曟槑缁�1鍙栧緱
-                consumableorderdetailsSelected = [
-                    SELECT
-                        Id,
-                        Dealer_Custom_Price__c,
-                        Delivery_List_RMB__c,
-                        Consumable_Product__r.Name__c,
-                        Consumable_Product__r.SFDA_Status__c,
-                        Name,
-                        Consumable_order__c,
-                        Consumable_Product__c,
-                        Consumable_Product__r.Name,
-                        Shipment_Count__c,
-                        Consumable_Product__r.Intra_Trade_List_RMB__c,
-                        Consumable_Product__r.Asset_Model_No__c,
-                        Consumable_Product__r.Category3__c,
-                        Consumable_Product__r.Category4__c,
-                        Consumable_Product__r.Category5__c,
-                        Shipment_amount__c,
-                        //Unitprice_To_agency__c,
-                        Box_Piece__c,
-                        ProductPacking_list_manual__c,
-                        Invoiced_Procount__c,
-                        RrturnPro_count__c,
-                        InvoiceProNot_count__c,
-                        Consumable_Product__r.Product2__r.SFDA_Approbation_No__c,
-                        Consumable_Product__r.Product2__r.SFDA_Expiration_Date__c,
-                        isOutPattern__c
-                    FROM Consumable_orderdetails__c
-                    WHERE Consumable_order__c = :ESetId AND Consumable_order__r.Order_Owner_WorkLocal__c = :userWorkLocation
-                    ORDER BY Name
-                ];
-                Map<String, Consumable_Orderdetails__c> cocMap = new Map<String, Consumable_Orderdetails__c>();
-
-                for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
-                    sumPrice += cdc1.Shipment_amount__c;
-                    orderzaikuId.add(cdc1.Consumable_Product__c);
-                    //add by rentx 2021-2-26
-                    String tempId = cdc1.Consumable_product__c;
-                    if (cdc1.isOutPattern__c) {
-                        cocMap.put(tempId + 'ishos', cdc1);
-                    } else {
-                        cocMap.put(tempId + 'nothos', cdc1);
-                    }
-                    //add by rentx 2021-2-26
-                }
-                String msoql = makeSoqlorderdet();
-                product2Selected = Database.query(msoql);
-                size = product2Selected.size();
-                initStandardController(msoql);
-
-                for (Integer i = 0; i < product2Selected.size(); i++) {
-                    MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
-                }
-                //update by rentx 2021-01-29
-                /*for(Integer i = 0 ; i< CountDel.size();i++){
-                        //鐒跺悗寰幆CountDel鍘讳慨鏀筸ap閲岀殑allnumber
-                        if(MidMap.containsKey(CountDel[i].Consumable_Product__c)){
-                            ConsumableorderdetailsInfo Jstage =  MidMap.get(CountDel[i].Consumable_Product__c);
-                            Jstage.allnumber = Jstage.allnumber+1 ;
-                            if(CountDel[i].Box_Piece__c == '鐩�'){
-                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
-                            }else if(CountDel[i].Box_Piece__c == '涓�'){
-                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
-                            }
-                            //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
-                            MidMap.put(CountDel[i].Consumable_Product__c, Jstage);
-                        }
-                    }*/
-
-                for (Integer i = 0; i < CountDel.size(); i++) {
-                    String str = '';
-                    if (CountDel[i].hospitalSpecialOffer__c) {
-                        str = 'isHos';
-                    } else {
-                        str = 'notHos';
-                    }
-                    //鏄庣粏2瀵瑰簲鐨勪骇鍝佸瓨鍦ㄤ簬MidMap涓�
-                    if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
-                        //璁剧疆map涓璳ey鐨勫悗缂� 鐢ㄤ簬鍖哄垎鍖婚櫌鐗逛环鍜岄潪鍖婚櫌鐗逛环
-                        if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
-                            ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c + str);
-                            Jstage.allnumber = Jstage.allnumber + 1;
-                            if (CountDel[i].Box_Piece__c == '鐩�') {
-                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
-                            } else if (CountDel[i].Box_Piece__c == '涓�') {
-                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
-                            }
-                            if (CountDel[i].hospitalSpecialOffer__c) {
-                                Jstage.hospitalSpecialOffer = true;
-                            } else {
-                                Jstage.hospitalSpecialOffer = false;
-                            }
-
-                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
-                                Jstage.hosPro = true;
-                            }
-                            MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
-                        } else {
-                            //midmap2涓病鏈夊搴旂殑浜у搧
-                            ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
-                            Jstage.allnumber = Jstage.allnumber + 1;
-                            if (CountDel[i].Box_Piece__c == '鐩�') {
-                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
-                            } else if (CountDel[i].Box_Piece__c == '涓�') {
-                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
-                            }
-                            if (CountDel[i].hospitalSpecialOffer__c) {
-                                Jstage.hospitalSpecialOffer = true;
-                            } else {
-                                Jstage.hospitalSpecialOffer = false;
-                            }
-                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
-                                Jstage.hosPro = true;
-                            }
-                            //Jstage.BoxPiece = CountDel[i].Box_Piece__c;
-                            MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
-                        }
-                    }
-                }
-                //update by rentx 2021-01-29
-                consumableorderdetailsSelectRecords = new List<ConsumableorderdetailsInfo>();
-                //鍐嶆妸map閲岀殑鍊间粠鏂拌祴缁機onsumableorderdetailsRecords
-                //update by rentx 2021-01-29
-                // for(ConsumableorderdetailsInfo bss : MidMap.values()){
-                for (ConsumableorderdetailsInfo bss : MidMap2.values()) {
-                    //update by rentx 2021-01-29
-
-                    //if(bss.allnumber > 0){
-                    //bss.UnitpriceToagency = bss.orderdetails1.Unitprice_To_agency__c == null  || bss.orderdetails1.Unitprice_To_agency__c == 0 ? '' :bss.orderdetails1.Unitprice_To_agency__c.format();
-                    bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
-                    bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
-                    bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
-
-                    //update by rentx 2021-2-26 start
-                    if (cocMap.containsKey(bss.Prod.Id + 'ishos') && bss.hospitalSpecialOffer == true) {
-                        consumableorderdetailsSelectRecords.add(bss);
-                    } else if (cocMap.containsKey(bss.Prod.Id + 'nothos') && bss.hospitalSpecialOffer == false) {
-                        consumableorderdetailsSelectRecords.add(bss);
-                    }
-                    //update by rentx 2021-2-26 end
-                    // consumableorderdetailsSelectRecords.add(bss);
-                    //}
-                }
-                Integer ishosnum = 0;
-                for (ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords) {
-                    for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
-                        //update by rentx 2012-3-1 start
-                        // if(ass.prod.Id == cdc1.Consumable_Product__c){
-                        //     ass.check = true;
-                        //     ass.orderdetails1 = cdc1;
-                        // }
-                        if (ass.Prod.Id == cdc1.Consumable_Product__c && ass.hospitalSpecialOffer == cdc1.isOutPattern__c) {
-                            ass.check = true;
-                            ass.orderdetails1 = cdc1;
-                        }
-                        //update by rentx 2012-3-1 end
-                    }
-                    if (ass.hospitalSpecialOffer == true) {
-                        ishosnum = ishosnum + 1;
-                    }
-                }
-                if (ishosnum > 0) {
-                    hasHosPro = true;
-                } else {
-                    hasHosPro = false;
-                }
-
-                //add by rentx
-                noOfRecords = consumableorderdetailsSelectRecords.size();
-                //add by rentx
-                System.debug('makepagerecords3');
-                makepagerecords();
-                //listCut();
-                // 娑堣�楀搧鏄庣粏2銈掑彇寰�
-                consumableorderdetails2RecordsList = [
-                    SELECT
-                        Id,
-                        Name,
-                        SerialLotNo__c,
-                        Consumable_Product__r.Name__c,
-                        TracingCode__c,
-                        Sterilization_limit__c,
-                        Consumable_Product__c,
-                        Consumable_Product__r.Name,
-                        Consumable_Product__r.Category3__c,
-                        Consumable_Product__r.Category4__c,
-                        Consumable_Product__r.Category5__c,
-                        Return_date__c,
-                        Invoice_Date__c,
-                        Box_Piece__c,
-                        ProductPacking_list_manual__c,
-                        //add by rentx start
-                        hospitalSpecialOffer__c
-                    //add by rentx end
-                    FROM Consumable_order_details2__c
-                    WHERE Consumable_ZS_order__c = :ESetId
-                    ORDER BY Name
-                ];
-                for (Integer i = 0; i < consumableorderdetails2RecordsList.size(); i++) {
-                    consumableorderdetails2Records.add(new ConsumableorderdetailsInfo(consumableorderdetails2RecordsList[i]));
-                }
-                //浜у搧鏄庣粏鍙栧緱
-                consumablearriveproductdetailsSelected = [
-                    SELECT
-                        Id,
-                        Delivery_List_RMB__c,
-                        Consumable_Product__r.Name__c,
-                        Name,
-                        Consumable_Product__r.SFDA_Status__c,
-                        Consumable_Product__r.Category3__c,
-                        Consumable_Product__r.Category4__c,
-                        Consumable_Product__r.Category5__c,
-                        Consumable_Product__c,
-                        Consumable_Product__r.Name,
-                        Sterilization_limit__c,
-                        Consumable_Product__r.Intra_Trade_List_RMB__c,
-                        Consumable_Product__r.Asset_Model_No__c,
-                        Box_Piece__c,
-                        ProductPacking_list_manual__c,
-                        //add by rentx start
-                        hospitalSpecialOffer__c
-                    //add by rentx end
-                    FROM Consumable_order_details2__c
-                    WHERE Consumable_ZS_order__c = :ESetId
-                    ORDER BY Name
-                ];
-                for (Integer i = 0; i < consumablearriveproductdetailsSelected.size(); i++) {
-                    consumableproductdetailsRecords.add(new ConsumableorderdetailsInfo(consumablearriveproductdetailsSelected[i]));
+            //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'test++++++' + SecondDealer));
+            if (SecondDealer == null || SecondDealer == '') {
+                provinceOpts.add(new SelectOption('', '-鏃�-'));
+                provinceOptsMap.put('', '-鏃�-');
+                for (Integer i = 0; i < Dealerelationship.size(); i++) {
+                    provinceOpts.add(
+                        new SelectOption(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name)
+                    );
+                    provinceOptsMap.put(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name);
                 }
             } else {
-                // 涓嶆槸鍒拌揣璁㈠崟鏉ョ殑鏃跺��
-                if (coc.SummonsStatus_c__c == '宸叉彁浜�' || coc.SummonsStatus_c__c == '鎵瑰噯') {
-                    system.debug('coc.SummonsStatus_c__c : ' + coc.SummonsStatus_c__c);
-                    saveBtnDisabled = true;
-                    SorderBtnDisabled = true;
-                    EditDelCommitBtnDisabled = false;
-                }
-                //鍖婚櫌浜岀骇缁忛攢鍟嗗垎绫�
-                Integer io = 0;
-                while (io < Dealerelationship.size()) {
-                    if (coc.Order_ForDealer__c == Dealerelationship[io].Dealer_subordinate__c) {
-                        SecondDealer = Dealerelationship[io].Dealer_subordinate__c;
-                        coc.Order_ForDealer__c = null;
-                        io = io + Dealerelationship.size();
-                    }
-                    io++;
-                }
-                Integer ik = 0;
-                while (ik < AgencyHospitalLink.size()) {
-                    if (coc.Order_ForHospital__c == AgencyHospitalLink[ik].Hospital__c) {
-                        HospitalInfo = AgencyHospitalLink[ik].Hospital__c;
-                        HospitalName = AgencyHospitalLink[ik].Hospital__r.Name;
-                        coc.Order_ForHospital__c = null;
-                        ik = ik + AgencyHospitalLink.size();
-                    }
-                    ik++;
-                }
-                // 娑堣�楀搧鏄庣粏1銈掑彇寰�
-                consumableorderdetailsSelected = [
-                    SELECT
-                        Id,
-                        Dealer_Custom_Price__c,
-                        Delivery_List_RMB__c,
-                        Consumable_Product__r.Name__c,
-                        Consumable_Product__r.SFDA_Status__c,
-                        Name,
-                        Consumable_order__c,
-                        Consumable_Product__c,
-                        Consumable_Product__r.Name,
-                        Shipment_Count__c,
-                        Consumable_Product__r.Intra_Trade_List_RMB__c,
-                        Consumable_Product__r.Asset_Model_No__c,
-                        Shipment_amount__c,
-                        Box_Piece__c,
-                        ProductPacking_list_manual__c,
-                        Invoiced_Procount__c,
-                        RrturnPro_count__c,
-                        //Unitprice_To_agency__c,
-                        InvoiceProNot_count__c,
-                        Consumable_Product__r.Category3__c,
-                        Consumable_Product__r.Category4__c,
-                        Consumable_Product__r.Category5__c,
-                        Consumable_Product__r.Product2__r.SFDA_Approbation_No__c,
-                        Consumable_Product__r.Product2__r.SFDA_Expiration_Date__c,
-                        isOutPattern__c
-                    FROM Consumable_orderdetails__c
-                    WHERE Consumable_order__c = :ESetId AND Consumable_order__r.Order_Owner_WorkLocal__c = :userWorkLocation
-                    ORDER BY Name
-                ];
-                //add by rentx 202-2-26
-                Map<String, Consumable_Orderdetails__c> cocMap = new Map<String, Consumable_Orderdetails__c>();
-
-                for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
-                    sumPrice += cdc1.Shipment_amount__c;
-                    orderzaikuId.add(cdc1.Consumable_Product__c);
-                    //add by rentx 2021-2-26
-                    String tempId = cdc1.Consumable_product__c;
-                    if (cdc1.isOutPattern__c) {
-                        cocMap.put(tempId + 'ishos', cdc1);
-                    } else {
-                        cocMap.put(tempId + 'nothos', cdc1);
-                    }
-                    //add by rentx 2021-2-26
-                }
-
-                String msoql = makeSoqlorderdet();
-                product2Selected = Database.query(msoql);
-                size = product2Selected.size();
-                initStandardController(msoql);
-                for (Integer i = 0; i < product2Selected.size(); i++) {
-                    MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
-                }
-
-                for (Integer i = 0; i < CountDel.size(); i++) {
-                    String str = '';
-                    if (CountDel[i].hospitalSpecialOffer__c) {
-                        str = 'isHos';
-                    } else {
-                        str = 'notHos';
-                    }
-                    //鏄庣粏2瀵瑰簲鐨勪骇鍝佸瓨鍦ㄤ簬MidMap涓�
-                    if (MidMap.containsKey(CountDel[i].Consumable_Product__c)) {
-                        //璁剧疆map涓璳ey鐨勫悗缂� 鐢ㄤ簬鍖哄垎鍖婚櫌鐗逛环鍜岄潪鍖婚櫌鐗逛环
-                        if (MidMap2.containsKey(CountDel[i].Consumable_Product__c + str)) {
-                            ConsumableorderdetailsInfo Jstage = MidMap2.get(CountDel[i].Consumable_Product__c + str);
-                            Jstage.allnumber = Jstage.allnumber + 1;
-                            if (CountDel[i].Box_Piece__c == '鐩�') {
-                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
-                            } else if (CountDel[i].Box_Piece__c == '涓�') {
-                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
-                            }
-                            if (CountDel[i].hospitalSpecialOffer__c) {
-                                Jstage.hospitalSpecialOffer = true;
-                            } else {
-                                Jstage.hospitalSpecialOffer = false;
-                            }
-                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
-                                Jstage.hosPro = true;
-                            }
-                            MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
-                        } else {
-                            //midmap2涓病鏈夊搴旂殑浜у搧
-                            ConsumableorderdetailsInfo Jstage = MidMap.get(CountDel[i].Consumable_Product__c).clone();
-                            Jstage.allnumber = Jstage.allnumber + 1;
-                            if (CountDel[i].Box_Piece__c == '鐩�') {
-                                Jstage.Boxnumber = Jstage.Boxnumber + 1;
-                            } else if (CountDel[i].Box_Piece__c == '涓�') {
-                                Jstage.Piecenumber = Jstage.Piecenumber + 1;
-                            }
-
-                            if (CountDel[i].hospitalSpecialOffer__c) {
-                                Jstage.hospitalSpecialOffer = true;
-                            } else {
-                                Jstage.hospitalSpecialOffer = false;
-                            }
-                            if (HosProMap.containsKey(Jstage.Prod.Id)) {
-                                Jstage.hosPro = true;
-                            }
-                            Jstage.BoxPiece = CountDel[i].Box_Piece__c;
-                            MidMap2.put(CountDel[i].Consumable_Product__c + str, Jstage);
-                        }
+                provinceOpts.add(new SelectOption('', '-鏃�-'));
+                provinceOptsMap.put('', '-鏃�-');
+                for (Integer i = 0; i < Dealerelationship.size(); i++) {
+                    if (Dealerelationship[i].Dealer_subordinate__c == SecondDealer) {
+                        provinceOpts.add(
+                            new SelectOption(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name)
+                        );
+                        provinceOptsMap.put(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name);
                     }
                 }
-
-                //鍐嶆妸map閲岀殑鍊间粠鏂拌祴缁機onsumableorderdetailsRecords
-                //update by rentx 2021-01-29
-                // for(ConsumableorderdetailsInfo bss : MidMap.values()){
-                for (ConsumableorderdetailsInfo bss : MidMap2.values()) {
-                    //update by rentx 2021-01-29
-
-                    //if(bss.allnumber>0){
-                    bss.packinglist = Integer.valueOf(bss.Prod.Product2__r.Packing_list_manual__c);
-                    bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
-                    bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
-
-                    //update by rentx 2021-2-26 start
-                    if (cocMap.containsKey(bss.Prod.Id + 'ishos') && bss.hospitalSpecialOffer == true) {
-                        consumableorderdetailsSelectRecords.add(bss);
-                    } else if (cocMap.containsKey(bss.Prod.Id + 'nothos') && bss.hospitalSpecialOffer == false) {
-                        consumableorderdetailsSelectRecords.add(bss);
+                for (Integer i = 0; i < Dealerelationship.size(); i++) {
+                    if (Dealerelationship[i].Dealer_subordinate__c != SecondDealer) {
+                        provinceOpts.add(
+                            new SelectOption(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name)
+                        );
+                        provinceOptsMap.put(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name);
                     }
-                    // consumableorderdetailsSelectRecords.add(bss);
-                    //}
-                }
-                // return null;
-                Integer ishosnum = 0;
-                for (ConsumableorderdetailsInfo ass : consumableorderdetailsSelectRecords) {
-                    ass.sortBy = sortOrderAsc;
-                    for (Consumable_Orderdetails__c cdc1 : consumableorderdetailsSelected) {
-                        //update by rentx 2012-3-1 start
-                        // if(ass.prod.Id == cdc1.Consumable_Product__c){
-                        //     ass.check = true;
-                        //     ass.orderdetails1 = cdc1;
-                        // }
-                        if (ass.Prod.Id == cdc1.Consumable_Product__c && ass.hospitalSpecialOffer == cdc1.isOutPattern__c) {
-                            ass.check = true;
-                            ass.orderdetails1 = cdc1;
-                        }
-                        //update by rentx 2012-3-1 end
-                    }
-
-                    if (ass.hospitalSpecialOffer == true) {
-                        ishosnum = ishosnum + 1;
-                    }
-                }
-
-                if (ishosnum > 0) {
-                    hasHosPro = true;
-                } else {
-                    hasHosPro = false;
-                }
-
-                consumableorderdetailsSelectRecords.sort();
-                //add by rentx
-                noOfRecords = consumableorderdetailsSelectRecords.size();
-                //add by rentx
-                System.debug('makepagerecords4');
-                makepagerecords();
-
-                // 娑堣�楀搧鏄庣粏2銈掑彇寰�
-                consumableorderdetails2RecordsList = [
-                    SELECT
-                        Id,
-                        Name,
-                        SerialLotNo__c,
-                        Consumable_Product__r.Name__c,
-                        TracingCode__c,
-                        Sterilization_limit__c,
-                        Consumable_Product__c,
-                        Consumable_Product__r.Name,
-                        Consumable_Product__r.Category3__c,
-                        Consumable_Product__r.Category4__c,
-                        Consumable_Product__r.Category5__c,
-                        Return_date__c,
-                        Invoice_Date__c,
-                        Box_Piece__c,
-                        ProductPacking_list_manual__c,
-                        //add by rentx start
-                        hospitalSpecialOffer__c
-                    //add by rentx end
-
-                    FROM Consumable_order_details2__c
-                    WHERE Consumable_ZS_order__c = :ESetId
-                    ORDER BY Name
-                ];
-                for (Integer i = 0; i < consumableorderdetails2RecordsList.size(); i++) {
-                    consumableorderdetails2Records.add(new ConsumableorderdetailsInfo(consumableorderdetails2RecordsList[i]));
                 }
             }
+
+            Schema.DescribeFieldResult dfr = Product2__c.Intra_Trade_List_RMB__c.getDescribe();
+            cansee = dfr.isAccessible();
+            Schema.DescribeFieldResult dealerPrice = Consumable_orderdetails__c.Dealer_Custom_Price__c.getDescribe();
+            dealerPricesee = dealerPrice.isAccessible();
+            // 鏄剧ず鏁版嵁鏉℃暟淇℃伅
+            //    makeMessage();
+            //闄勪欢
+            attachmentinfo = [SELECT Id, Name, OwnerId FROM Attachment WHERE parentid = :ESetId];
+            if (attachmentinfo.size() > 0) {
+                for (Integer i = 0; i < attachmentinfo.size(); i++) {
+                    attachmentRecoeds.add(new ConsumableorderdetailsInfo(attachmentinfo[i]));
+                }
+            }
+            AggregateResult[] categoryList = [
+                SELECT Count(id), Category3_text__c c3c
+                FROM Product2__c
+                WHERE Category3_text__c != NULL
+                GROUP BY Category3_text__c
+            ];
+
+            categoryOptionList = new List<SelectOption>();
+            categoryOptionList.add(new SelectOption('', '-鏃�-'));
+            categoryOptionMap = new Map<String, String>();
+            categoryOptionMap.put('', '-鏃�-');
+            for (AggregateResult category3Search : categoryList) {
+                String deliverycnt = String.valueOf(category3Search.get('c3c'));
+                categoryOptionList.add(new SelectOption(deliverycnt, deliverycnt));
+                categoryOptionMap.put(deliverycnt, deliverycnt);
+            }
+
+            category4OptionList = new List<SelectOption>();
+            category4OptionList.add(new SelectOption('', '-鏃�-'));
+            category4OptionMap = new Map<String, String>();
+            category4OptionMap.put('', '-鏃�-');
+            /*for(AggregateResult category4Search : category4List) {
+                    String deliverycnt4 = String.valueOf(category4Search.get('c4c'));
+                    category4OptionList.add(new SelectOption(deliverycnt4,deliverycnt4));
+                }*/
+
+            category5OptionList = new List<SelectOption>();
+            category5OptionList.add(new SelectOption('', '-鏃�-'));
+            category5OptionMap = new Map<String, String>();
+            category5OptionMap.put('', '-鏃�-');
+
+            //鍒嗛〉
+            PaginatedAccounts paginatedAccounts = new PaginatedAccounts();
+            totalCount = pageRecords.size();
+            System.debug('pageToken = ' + pageToken);
+            System.debug('pageSize = ' + pageSize);
+            System.debug('totalCount = ' + totalCount);
+            paginatedAccounts.nextPageToken = (pageToken + pageSize < totalCount) ? pageToken + pageSize : null;
+            System.debug('paginatedAccounts.nextPageToken = ' + paginatedAccounts.nextPageToken);
+            paginatedAccounts.recordStart = pageToken + 1;
+            paginatedAccounts.pageNumber = pageToken / pageSize + 1;
+            Integer recordEnd = pageSize * paginatedAccounts.pageNumber;
+            paginatedAccounts.recordEnd = totalCount >= recordEnd ? recordEnd : totalCount;
+            paginatedAccounts.totalRecords = totalCount;
+
+            Integer startIdx;
+            Integer endIdx;
+            startIdx = pageToken;
+            endIdx = pageToken + pageSize;
+            List<ConsumableorderdetailsInfo> pageRecordsTemp = new List<ConsumableorderdetailsInfo>();
+            if (endIdx > pageRecords.size()) {
+                endIdx = pageRecords.size();
+            }
+            for (Integer i = startIdx; i < endIdx; i++) {
+                pageRecordsTemp.add(pageRecords.get(i));
+            }
+
+            Boolean Existarrive = (coc.Arrive_Order__c != null);
+            String ConsumableOut_report = System.Label.ConsumableOut_report;
+            System.debug('consumableproductdetailsRecords = ' + consumableproductdetailsRecords);
+
+            data.put('paginatedAccounts', paginatedAccounts);
+            data.put('ConsumableOut_report', ConsumableOut_report);
+            data.put('accountid', accountid);
+            data.put('consumableproductdetailsRecords', consumableproductdetailsRecords);
+            data.put('agencyProType', agencyProType);
+            data.put('accountName', accountName);
+            data.put('userWorkLocation', userWorkLocation);
+            data.put('categoryOptionMap', categoryOptionMap);
+            data.put('category4OptionMap', category4OptionMap);
+            data.put('category5OptionMap', category5OptionMap);
+            data.put('outOutPatternOptionMap', outOutPatternOptionMap);
+            data.put('hasHosPro', hasHosPro);
+            data.put('Existarrive', Existarrive);
+            data.put('sumPrice', sumPrice);
+            data.put('HospitalName', HospitalName);
+            data.put('provinceOptsMap', provinceOptsMap);
+            data.put('SummonsFlag', SummonsFlag);
+            data.put('EditDelCommitBtnDisabled', EditDelCommitBtnDisabled);
+            data.put('EditAble', EditAble);
+            data.put('coc', coc);
+            data.put('pageRecords', pageRecordsTemp);
+            data.put('arriveorder', arriveorder);
+            data.put('consumableorderdetails2Count', consumableorderdetails2Count);
+            data.put('consumableorderdetails2Records', consumableorderdetails2Records);
+            data.put('HospitalInfo', HospitalInfo);
+            res.status = 'Success';
+            res.code = 200;
+            System.debug('res = ' + res);
+            return res;
+        } catch (Exception e) {
+            return new ResponseBodyLWC('Error', 500, e.getMessage() + e.getLineNumber(), '');
         }
-        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'test++++++' + SecondDealer));
-        if (SecondDealer == null || SecondDealer == '') {
-            provinceOpts.add(new SelectOption('', '-鏃�-'));
-            provinceOptsMap.put('', '-鏃�-');
-            for (Integer i = 0; i < Dealerelationship.size(); i++) {
-                provinceOpts.add(
-                    new SelectOption(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name)
-                );
-                provinceOptsMap.put(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name);
-            }
-        } else {
-            provinceOpts.add(new SelectOption('', '-鏃�-'));
-            provinceOptsMap.put('', '-鏃�-');
-            for (Integer i = 0; i < Dealerelationship.size(); i++) {
-                if (Dealerelationship[i].Dealer_subordinate__c == SecondDealer) {
-                    provinceOpts.add(
-                        new SelectOption(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name)
-                    );
-                    provinceOptsMap.put(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name);
-                }
-            }
-            for (Integer i = 0; i < Dealerelationship.size(); i++) {
-                if (Dealerelationship[i].Dealer_subordinate__c != SecondDealer) {
-                    provinceOpts.add(
-                        new SelectOption(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name)
-                    );
-                    provinceOptsMap.put(Dealerelationship[i].Dealer_subordinate__c, Dealerelationship[i].Dealer_subordinate__r.Name);
-                }
-            }
-        }
-
-        Schema.DescribeFieldResult dfr = Product2__c.Intra_Trade_List_RMB__c.getDescribe();
-        cansee = dfr.isAccessible();
-        Schema.DescribeFieldResult dealerPrice = Consumable_orderdetails__c.Dealer_Custom_Price__c.getDescribe();
-        dealerPricesee = dealerPrice.isAccessible();
-        // 鏄剧ず鏁版嵁鏉℃暟淇℃伅
-        //    makeMessage();
-        //闄勪欢
-        attachmentinfo = [SELECT Id, Name, OwnerId FROM Attachment WHERE parentid = :ESetId];
-        if (attachmentinfo.size() > 0) {
-            for (Integer i = 0; i < attachmentinfo.size(); i++) {
-                attachmentRecoeds.add(new ConsumableorderdetailsInfo(attachmentinfo[i]));
-            }
-        }
-        AggregateResult[] categoryList = [
-            SELECT Count(id), Category3_text__c c3c
-            FROM Product2__c
-            WHERE Category3_text__c != NULL
-            GROUP BY Category3_text__c
-        ];
-
-        categoryOptionList = new List<SelectOption>();
-        categoryOptionList.add(new SelectOption('', '-鏃�-'));
-        categoryOptionMap = new Map<String, String>();
-        categoryOptionMap.put('', '-鏃�-');
-        for (AggregateResult category3Search : categoryList) {
-            String deliverycnt = String.valueOf(category3Search.get('c3c'));
-            categoryOptionList.add(new SelectOption(deliverycnt, deliverycnt));
-            categoryOptionMap.put(deliverycnt, deliverycnt);
-        }
-
-        category4OptionList = new List<SelectOption>();
-        category4OptionList.add(new SelectOption('', '-鏃�-'));
-        category4OptionMap = new Map<String, String>();
-        category4OptionMap.put('', '-鏃�-');
-        /*for(AggregateResult category4Search : category4List) {
-                String deliverycnt4 = String.valueOf(category4Search.get('c4c'));
-                category4OptionList.add(new SelectOption(deliverycnt4,deliverycnt4));
-            }*/
-
-        category5OptionList = new List<SelectOption>();
-        category5OptionList.add(new SelectOption('', '-鏃�-'));
-        category5OptionMap = new Map<String, String>();
-        category5OptionMap.put('', '-鏃�-');
-
-        Boolean Existarrive = (coc.Arrive_Order__c != null);
-        String ConsumableOut_report = System.Label.ConsumableOut_report;
-        System.debug('consumableproductdetailsRecords = ' + consumableproductdetailsRecords);
-        data.put('ConsumableOut_report', 'ConsumableOut_report');
-        data.put('accountid', accountid);
-        data.put('consumableproductdetailsRecords', consumableproductdetailsRecords);
-        data.put('agencyProType', agencyProType);
-        data.put('accountName', accountName);
-        data.put('userWorkLocation', userWorkLocation);
-        data.put('categoryOptionMap', categoryOptionMap);
-        data.put('category4OptionMap', category4OptionMap);
-        data.put('category5OptionMap', category5OptionMap);
-        data.put('outOutPatternOptionMap', outOutPatternOptionMap);
-        data.put('hasHosPro', hasHosPro);
-        data.put('Existarrive', Existarrive);
-        data.put('sumPrice', sumPrice);
-        data.put('HospitalName', HospitalName);
-        data.put('provinceOptsMap', provinceOptsMap);
-        data.put('SummonsFlag', SummonsFlag);
-        data.put('EditDelCommitBtnDisabled', EditDelCommitBtnDisabled);
-        data.put('EditAble', EditAble);
-        data.put('coc', coc);
-        data.put('pageRecords', pageRecords);
-        data.put('arriveorder', arriveorder);
-        data.put('consumableorderdetails2Count', consumableorderdetails2Count);
-        data.put('consumableorderdetails2Records', consumableorderdetails2Records);
-        data.put('HospitalInfo', HospitalInfo);
-        res.status = 'Success';
-        res.code = 200;
-        System.debug('res = ' + res);
-        return res;
-        // } catch (Exception e) {
-        //     return new ResponseBodyLWC('Error',500, e.getMessage(), '');
-        // }
     }
 
     @AuraEnabled
@@ -1362,7 +1419,7 @@
         ];
         category4OptionList = new List<SelectOption>();
         category4OptionList.add(new SelectOption('', '-鏃�-'));
-        category4OptionMap = new Map<String,String>();
+        category4OptionMap = new Map<String, String>();
         category4OptionMap.put('', '-鏃�-');
         for (AggregateResult category4Search : category4List) {
             String deliverycnt4 = String.valueOf(category4Search.get('c4c'));
@@ -1379,15 +1436,15 @@
 
         category5OptionList = new List<SelectOption>();
         category5OptionList.add(new SelectOption('', '-鏃�-'));
-        category5OptionMap = new Map<String,String>();
+        category5OptionMap = new Map<String, String>();
         category5OptionMap.put('', '-鏃�-');
         for (AggregateResult category5Search : category5List) {
             String deliverycnt5 = String.valueOf(category5Search.get('c5c'));
             category5OptionList.add(new SelectOption(deliverycnt5, deliverycnt5));
             category5OptionMap.put(deliverycnt5, deliverycnt5);
         }
-        data.put('category4OptionMap',category4OptionMap);
-        data.put('category5OptionMap',category5OptionMap);
+        data.put('category4OptionMap', category4OptionMap);
+        data.put('category5OptionMap', category5OptionMap);
         res.status = 'Success';
         res.code = 200;
         System.debug('res = ' + res);
@@ -1395,7 +1452,7 @@
     }
 
     @AuraEnabled
-    public static ResponseBodyLWC categoryload(String category3Lwc,String category4Lwc) {
+    public static ResponseBodyLWC categoryload(String category3Lwc, String category4Lwc) {
         ResponseBodyLWC res = new ResponseBodyLWC();
         Map<String, object> data = new Map<String, object>();
         res.entity = data;
@@ -1410,7 +1467,7 @@
         ];
         category4OptionList = new List<SelectOption>();
         category4OptionList.add(new SelectOption('', '-鏃�-'));
-        category4OptionMap = new Map<String,String>();
+        category4OptionMap = new Map<String, String>();
         category4OptionMap.put('', '-鏃�-');
         for (AggregateResult category4Search : category4List) {
             String deliverycnt4 = String.valueOf(category4Search.get('c4c'));
@@ -1427,15 +1484,15 @@
 
         category5OptionList = new List<SelectOption>();
         category5OptionList.add(new SelectOption('', '-鏃�-'));
-        category5OptionMap = new Map<String,String>();
+        category5OptionMap = new Map<String, String>();
         category5OptionMap.put('', '-鏃�-');
         for (AggregateResult category5Search : category5List) {
             String deliverycnt5 = String.valueOf(category5Search.get('c5c'));
             category5OptionList.add(new SelectOption(deliverycnt5, deliverycnt5));
             category5OptionMap.put(deliverycnt5, deliverycnt5);
         }
-        data.put('category4OptionMap',category4OptionMap);
-        data.put('category5OptionMap',category5OptionMap);
+        data.put('category4OptionMap', category4OptionMap);
+        data.put('category5OptionMap', category5OptionMap);
         res.status = 'Success';
         res.code = 200;
         System.debug('res = ' + res);
@@ -1456,7 +1513,9 @@
         Boolean editAbleLwc,
         List<ConsumableorderdetailsInfoLwc> pageRecordsLwcLwc,
         List<ConsumableorderdetailsInfo> consumableproductdetailsRecordsLwc,
-        String arriveorderLwc
+        String arriveorderLwc,
+        Integer pageSizeLWC,
+        Integer pageTokenLWC
     ) {
         consumableproductdetailsRecords = consumableproductdetailsRecordsLwc;
         pageRecordsLwc = pageRecordsLwcLwc;
@@ -1465,6 +1524,14 @@
         accountName = accountNameLwc;
         userWorkLocation = userWorkLocationLwc;
         agencyProType = agencyProTypeLwc;
+        product2Selected = new List<Product2__c>();
+        pagesize = pageSizeLWC;
+        pageToken = pageTokenLWC > 2000 ? 2000 : pageTokenLWC;
+        addSize = 0;
+        addData = new List<ConsumableorderdetailsInfo>();
+        System.debug('start addData = ' + addData);
+        System.debug('accountName = ' + accountName);
+        System.debug('userWorkLocation = ' + userWorkLocation);
         String sqlagencyProType = '%' + agencyProTypeLwc + '%';
         List<AggregateResult> orderdetailCount = [
             SELECT count(id), Consumable_Product__c cpc, Box_Piece__c
@@ -1509,9 +1576,9 @@
         consumableorderdetailsSelectRecords = new List<ConsumableorderdetailsInfo>();
         //consumableorderdetailsSelectRecords = reSet;
         String soql = makeSoql(category1, category3, category4, category5);
-        System.debug('soql = ' + soql);
         size = Integer.valueOf(System.Label.orderdetLimitsize);
         initStandardController(soql);
+        System.debug('soql = ' + soql);
         product2Selected = Database.query(soql);
         for (Integer i = 0; i < product2Selected.size(); i++) {
             MidMap.put(product2Selected[i].Id, new ConsumableorderdetailsInfo(product2Selected[i]));
@@ -1591,18 +1658,53 @@
         }
 
         consumableorderdetailsSelectRecords.sort();
-        //add by rentx
-        //noOfRecords = consumableorderdetailsSelectRecords.size();
-        //add by rentx
-        //makepagerecords();
         makepagerecordsLwc();
-        // this.sortKey = '1';
-        // this.preSortKey = '1';
-        // this.sortOrderAsc = false;
-        // this.sortOrder = new String[8];
-        // this.sortOrder = new String[]{' ',' ',' ',' ','鈫�','','',''};
-        data.put('pageRecords', pageRecords);
-        data.put('test', 'test');
+        //鍒嗛〉
+        PaginatedAccounts paginatedAccounts = new PaginatedAccounts();
+        totalCount = pageRecords.size();
+        paginatedAccounts.nextPageToken = (pageToken + pageSize < totalCount) ? pageToken + pageSize : null;
+        paginatedAccounts.recordStart = pageToken + 1;
+        paginatedAccounts.pageNumber = pageToken / pageSize + 1;
+        Integer recordEnd = pageSize * paginatedAccounts.pageNumber;
+        paginatedAccounts.recordEnd = totalCount >= recordEnd ? recordEnd : totalCount;
+        paginatedAccounts.totalRecords = totalCount;
+
+        System.debug('addSize = ' + addSize);
+        Integer startIdx;
+        Integer endIdx;
+        startIdx = pageToken;
+        endIdx = pageToken + pageSize;
+        List<ConsumableorderdetailsInfo> pageRecordsTemp = new List<ConsumableorderdetailsInfo>();
+        if (endIdx > pageRecords.size()) {
+            endIdx = pageRecords.size();
+        }
+
+        System.debug('addData.size() = ' + addData.size());
+        for (ConsumableorderdetailsInfo ci : addData) {
+            pageRecordsTemp.add(ci);
+        }
+        System.debug('startIdx = ' + startIdx);
+        System.debug('endIdx = ' + endIdx);
+        System.debug('skipData = ' + skipData);
+        System.debug('pageRecords = ' + pageRecords.size());
+        String hos = '';
+        for (Integer i = startIdx; i < endIdx; i++) {
+            System.debug('skipData.get(pageRecords.get(i).Prod.Id) = ' + skipData.get(pageRecords.get(i).Prod.Id));
+            if (pageRecords.get(i).hospitalSpecialOffer == true) {
+                hos = 'ishos';
+            } else {
+                hos = 'nothos';
+            }
+            if (skipData.get(pageRecords.get(i).Prod.Id + hos) == null) {
+                pageRecordsTemp.add(pageRecords.get(i));
+            }
+        }
+
+        System.debug('pageRecordsTemp = ' + pageRecordsTemp.size());
+        data.put('paginatedAccounts', paginatedAccounts);
+        data.put('pageRecords', pageRecordsTemp);
+        data.put('SearchDone', SearchDone);
+        data.put('hasHosPro', hasHosPro);
         res.status = 'Success';
         res.code = 200;
         System.debug('res = ' + res);
@@ -1612,10 +1714,12 @@
     private static String makeSoql(String CateName, String Category3, String Category4, String Category5) {
         String sqlTail1 = '(\'';
         for (Integer i = 0; i < zaikuId.size(); i++) {
-            if (i < zaikuId.size() - 1) {
-                sqlTail1 += zaikuId[i] + '\',\'';
-            } else {
-                sqlTail1 += zaikuId[i];
+            if (zaikuId[i] != null) {
+                if (i < zaikuId.size() - 1) {
+                    sqlTail1 += zaikuId[i] + '\',\'';
+                } else {
+                    sqlTail1 += zaikuId[i];
+                }
             }
         }
         sqlTail1 += '\')';
@@ -1659,10 +1763,12 @@
     public static String makeSoqlinventory() {
         String sqlTail = '(\'';
         for (Integer i = 0; i < zaikuId.size(); i++) {
-            if (i < zaikuId.size() - 1) {
-                sqlTail += zaikuId[i] + '\',\'';
-            } else {
-                sqlTail += zaikuId[i];
+            if (zaikuId[i] != null) {
+                if (i < zaikuId.size() - 1) {
+                    sqlTail += zaikuId[i] + '\',\'';
+                } else {
+                    sqlTail += zaikuId[i];
+                }
             }
         }
         sqlTail += '\')';
@@ -1701,6 +1807,7 @@
         }
         System.debug('zhj3');
         pageRecords = new List<ConsumableorderdetailsInfo>();
+        System.debug('reSet.size() = ' + reSet.size());
         if (editAble && String.isBlank(arriveorder)) {
             pageRecords = reSet;
         }
@@ -1708,7 +1815,7 @@
         //Integer pageendNo = (setCon.getPageNumber() * size)>noOfRecords ? noOfRecords :(setCon.getPageNumber() * size-1);
         Integer addNo = 0;
         //update by rentx 2021-2-26 start
-        System.debug('consumableorderdetailsSelectRecords = ' + consumableorderdetailsSelectRecords);
+        System.debug('consumableorderdetailsSelectRecords.size() = ' + consumableorderdetailsSelectRecords.size());
         for (ConsumableorderdetailsInfo info : consumableorderdetailsSelectRecords) {
             Consumable_Orderdetails__c orderdetails1 = new Consumable_Orderdetails__c();
             if (
@@ -1733,6 +1840,7 @@
     public static List<ConsumableorderdetailsInfo> makepagerecordsLwc() {
         List<ConsumableorderdetailsInfoLwc> reSetLwc = new List<ConsumableorderdetailsInfoLwc>();
         Map<String, String> selectedIdMap = new Map<String, String>();
+        skipData = new Map<String, String>();
         System.debug('makepagerecordsLwc pageRecordsLwc = ' + pageRecordsLwc);
         //鍙栧嚭閫夋嫨鐨勪骇鍝�
         if (pageRecordsLwc != null) {
@@ -1741,18 +1849,20 @@
                 if (ass.check == true) {
                     if (ass.hospitalSpecialOffer == true) {
                         selectedIdMap.put(ass.Prod.Id + 'ishos', ass.Prod.Id);
+                        skipData.put(ass.Prod.Id + 'ishos', ass.Prod.Id);
                     } else {
                         selectedIdMap.put(ass.Prod.Id + 'nothos', ass.Prod.Id);
+                        skipData.put(ass.Prod.Id + 'nothos', ass.Prod.Id);
                     }
                     reSetLwc.add(ass);
                 }
             }
         }
-        System.debug('reSetLwc = ' + reSetLwc);
         System.debug('selectedIdMap = ' + selectedIdMap);
         pageRecords = new List<ConsumableorderdetailsInfo>();
         if (editAble && String.isBlank(arriveorder)) {
             List<ConsumableorderdetailsInfo> reSet = new List<ConsumableorderdetailsInfo>();
+            System.debug('reSetLwc = ' + reSetLwc);
             for (ConsumableorderdetailsInfoLwc assLwc : reSetLwc) {
                 ConsumableorderdetailsInfo ci = new ConsumableorderdetailsInfo();
                 ci.check = assLwc.check;
@@ -1779,19 +1889,24 @@
                 reSet.add(ci);
             }
             pageRecords = reSet;
+            System.debug('reSet = ' + reSet);
+            addData = reSet.clone();
+            System.debug('addData = reSet = ' + addData);
         }
         //Integer pagestartNo = (setCon.getPageNumber() * size)-size;
         //Integer pageendNo = (setCon.getPageNumber() * size)>noOfRecords ? noOfRecords :(setCon.getPageNumber() * size-1);
         Integer addNo = 0;
         //update by rentx 2021-2-26 start
-        System.debug('consumableorderdetailsSelectRecords = ' + consumableorderdetailsSelectRecords);
+        System.debug('consumableorderdetailsSelectRecords.size() = ' + consumableorderdetailsSelectRecords.size());
         for (ConsumableorderdetailsInfo info : consumableorderdetailsSelectRecords) {
             Consumable_Orderdetails__c orderdetails1 = new Consumable_Orderdetails__c();
             if (
                 (info.hospitalSpecialOffer && selectedIdMap.containsKey(info.Prod.Id + 'ishos')) ||
                 (info.hospitalSpecialOffer == false && selectedIdMap.containsKey(info.Prod.Id + 'nothos'))
             ) {
+                System.debug('鍘绘帀鐨刬d : ' + info.Prod.Id);
                 addNo++;
+                addSize++;
             } else {
                 if (info.check == false) {
                     info.orderdetails1 = orderdetails1;
@@ -1800,7 +1915,8 @@
                 addNo++;
             }
         }
-        System.debug('pageRecords = ' + pageRecords);
+        System.debug('pageRecords.size() = ' + pageRecords.size());
+        System.debug('end  addData = ' + addData);
         return pageRecords;
     }
 
@@ -1810,84 +1926,98 @@
         Consumable_order__c cocLwc,
         String hospitalInfoLwc,
         String hospitalNameLwc,
-        String secondaryDistributor,
+        String secondaryDistributorLwc,
         List<ConsumableorderdetailsInfoLwc> pageRecordsLwc,
-        String accountid,
-        String ESetId,
-        List<ConsumableorderdetailsInfo> consumableproductdetailsRecordsLwc
+        String accountidLwc,
+        String ESetIdLwc,
+        List<ConsumableorderdetailsInfo> consumableproductdetailsRecordsLwc,
+        String agencyProTypeLwc,
+        String userWorkLocationLwc
     ) {
-        System.debug('cocLwc = ' + cocLwc);
         coc = cocLwc;
         HospitalInfo = hospitalInfoLwc;
         HospitalName = hospitalNameLwc;
-        SecondDealer = secondaryDistributor;
+        SecondDealer = secondaryDistributorLwc;
         pageRecordsLwc = pageRecordsLwc;
+        accountid = accountidLwc;
         consumableproductdetailsRecords = consumableproductdetailsRecordsLwc;
+        ESetId = ESetIdLwc;
+        agencyProType = agencyProTypeLwc;
+        userWorkLocation = userWorkLocationLwc;
+
+        System.debug('coc = ' + coc);
+        System.debug('HospitalInfo = ' + HospitalInfo);
+        System.debug('HospitalName = ' + HospitalName);
+        System.debug('SecondDealer = ' + SecondDealer);
+        System.debug('pageRecordsLwc = ' + pageRecordsLwc);
+        System.debug('accountid = ' + accountid);
+        System.debug('consumableproductdetailsRecords = ' + consumableproductdetailsRecords);
+        System.debug('ESetId = ' + ESetId);
         ResponseBodyLWC res = new ResponseBodyLWC();
         Map<String, object> data = new Map<String, object>();
         res.entity = data;
         //璁㈠崟淇℃伅纭
         if (coc.SummonsForDirction__c == '' || coc.SummonsForDirction__c == null) {
-            // coc.SummonsForDirction__c.addError('璇疯緭鍏ユ寚绀哄崟鐩殑銆�');
+            // coc.SummonsForDirction__c.addError('璇疯緭鍏ユ寚绀哄崟鐩殑');
             // return null;
-            return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ユ寚绀哄崟鐩殑銆�', '');
+            return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ユ寚绀哄崟鐩殑', '');
         } else if (coc.SummonsForDirction__c == '鐩存帴閿�鍞粰鍖婚櫌') {
             if (String.isBlank(HospitalInfo) || String.isBlank(HospitalName)) {
-                // coc.addError('璇疯緭鍏ュ尰闄€��');
+                // coc.addError('璇疯緭鍏ュ尰闄�');
                 // return null;
-                return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ尰闄€��', '');
+                return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ尰闄�', '');
             }
             if (String.isBlank(coc.Order_ForCustomerText__c)) {
-                // coc.Order_ForCustomerText__c.addError('璇疯緭鍏ョ瀹ゃ��');
+                // coc.Order_ForCustomerText__c.addError('璇疯緭鍏ョ瀹�');
                 // return null;
-                return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ョ瀹ゃ��', '');
+                return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ョ瀹�', '');
             } else if (String.isNotBlank(SecondDealer) || String.isNotBlank(coc.Order_ForDealerText__c)) {
-                // coc.addError('涓嶉渶瑕佷簩绾х粡閿�鍟嗗拰缁忛攢鍟�(褰曞叆)淇℃伅銆�' );
+                // coc.addError('涓嶉渶瑕佷簩绾х粡閿�鍟嗗拰缁忛攢鍟�(褰曞叆)淇℃伅' );
                 // return null;
-                return new ResponseBodyLWC('Error', 500, '涓嶉渶瑕佷簩绾х粡閿�鍟嗗拰缁忛攢鍟�(褰曞叆)淇℃伅銆�', '');
+                return new ResponseBodyLWC('Error', 500, '涓嶉渶瑕佷簩绾х粡閿�鍟嗗拰缁忛攢鍟�(褰曞叆)淇℃伅', '');
             }
         } else if (coc.SummonsForDirction__c == '鍖婚櫌璇曠敤') {
             if (String.isBlank(HospitalInfo) || String.isBlank(HospitalName)) {
-                // coc.addError('璇疯緭鍏ュ尰闄€��');
+                // coc.addError('璇疯緭鍏ュ尰闄�');
                 // return null;
-                return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ尰闄€��', '');
+                return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ尰闄�', '');
             }
             if (String.isBlank(coc.Order_ForCustomerText__c)) {
-                // coc.Order_ForCustomerText__c.addError('璇疯緭鍏ョ瀹ゃ��');
+                // coc.Order_ForCustomerText__c.addError('璇疯緭鍏ョ瀹�');
                 // return null;
-                return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ョ瀹ゃ��', '');
+                return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ョ瀹�', '');
             }
         } else if (coc.SummonsForDirction__c == '閿�鍞粰浜岀骇缁忛攢鍟�') {
             if (String.isBlank(SecondDealer) && String.isBlank(coc.Order_ForDealerText__c)) {
-                // coc.addError('蹇呴』杈撳叆浜岀骇缁忛攢鍟嗘垨缁忛攢鍟�(褰曞叆)銆�');
+                // coc.addError('蹇呴』杈撳叆浜岀骇缁忛攢鍟嗘垨缁忛攢鍟�(褰曞叆)');
                 // return null;
-                return new ResponseBodyLWC('Error', 500, '蹇呴』杈撳叆浜岀骇缁忛攢鍟嗘垨缁忛攢鍟�(褰曞叆)銆�', '');
+                return new ResponseBodyLWC('Error', 500, '蹇呴』杈撳叆浜岀骇缁忛攢鍟嗘垨缁忛攢鍟�(褰曞叆)', '');
             }
             if (String.isBlank(HospitalInfo) || String.isBlank(HospitalName)) {
-                // coc.addError('璇疯緭鍏ュ尰闄€��');
+                // coc.addError('璇疯緭鍏ュ尰闄�');
                 // return null;
-                return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ尰闄€��', '');
+                return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ尰闄�', '');
             }
             if (String.isBlank(coc.Order_ForCustomerText__c)) {
-                // coc.Order_ForCustomerText__c.addError('璇疯緭鍏ョ瀹ゃ��');
+                // coc.Order_ForCustomerText__c.addError('璇疯緭鍏ョ瀹�');
                 // return null;
-                return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ョ瀹ゃ��', '');
+                return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ョ瀹�', '');
             }
         } else if (coc.SummonsForDirction__c == '浜掔浉璋冭揣') {
             if (String.isNotBlank(HospitalInfo) || String.isNotBlank(HospitalName)) {
-                // coc.addError('涓嶉渶瑕佽緭鍏ュ尰闄€��');
+                // coc.addError('涓嶉渶瑕佽緭鍏ュ尰闄�');
                 // return null;
-                return new ResponseBodyLWC('Error', 500, '涓嶉渶瑕佽緭鍏ュ尰闄€��', '');
+                return new ResponseBodyLWC('Error', 500, '涓嶉渶瑕佽緭鍏ュ尰闄�', '');
             }
             if (String.isNotBlank(coc.Order_ForCustomerText__c)) {
-                // coc.Order_ForCustomerText__c.addError('涓嶉渶瑕佽緭鍏ョ瀹ゃ��');
+                // coc.Order_ForCustomerText__c.addError('涓嶉渶瑕佽緭鍏ョ瀹�');
                 // return null;
-                return new ResponseBodyLWC('Error', 500, '涓嶉渶瑕佽緭鍏ョ瀹ゃ��', '');
+                return new ResponseBodyLWC('Error', 500, '涓嶉渶瑕佽緭鍏ョ瀹�', '');
             }
             if (String.isBlank(SecondDealer) && String.isBlank(coc.Order_ForDealerText__c)) {
-                // coc.addError('蹇呴』杈撳叆浜岀骇缁忛攢鍟嗘垨缁忛攢鍟�(褰曞叆)銆�');
+                // coc.addError('蹇呴』杈撳叆浜岀骇缁忛攢鍟嗘垨缁忛攢鍟�(褰曞叆)');
                 // return null;
-                return new ResponseBodyLWC('Error', 500, '蹇呴』杈撳叆浜岀骇缁忛攢鍟嗘垨缁忛攢鍟�(褰曞叆)銆�', '');
+                return new ResponseBodyLWC('Error', 500, '蹇呴』杈撳叆浜岀骇缁忛攢鍟嗘垨缁忛攢鍟�(褰曞叆)', '');
             }
         }
 
@@ -1998,11 +2128,7 @@
                     return new ResponseBodyLWC(
                         'Error',
                         500,
-                        '缁忛攢鍟�:' +
-                        coc.Order_ForDealerText__c +
-                        ' 娌℃湁娑堣�楀搧:' +
-                        proStr.substring(0, proStr.length() - 1) +
-                        ' 鐨勭壒浠�',
+                        '缁忛攢鍟�:' + coc.Order_ForDealerText__c + ' 娌℃湁娑堣�楀搧:' + proStr.substring(0, proStr.length() - 1) + ' 鐨勭壒浠�',
                         ''
                     );
                 }
@@ -2054,34 +2180,34 @@
             for (ConsumableorderdetailsInfoLwc ass : pageRecordsLwc) {
                 if (ass.check == true) {
                     if (ass.orderdetails1.Delivery_List_RMB__c < 0) {
-                        // ass.orderdetails1.Delivery_List_RMB__c.addError('璇疯緭鍏ユ纭殑鍑鸿揣鍗曚环 (鍏�)銆�');
-                        // return null;
-                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ユ纭殑鍑鸿揣鍗曚环 (鍏�)銆�', '');
+                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ユ纭殑鍑鸿揣鍗曚环 (鍏�)', '');
                     }
                     if (ass.orderdetails1.Delivery_List_RMB__c == null && coc.SummonsForDirction__c != '鍖婚櫌璇曠敤') {
-                        // ass.orderdetails1.Delivery_List_RMB__c.addError('璇疯緭鍏ュ嚭璐у崟浠� (鍏�)銆�');
-                        // return null;
-                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ユ纭殑鍑鸿揣鍗曚环 (鍏�)銆�', '');
+                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ユ纭殑鍑鸿揣鍗曚环 (鍏�)', '');
+                    }
+                    if (
+                        (ass.orderdetails1.Delivery_List_RMB__c == null || ass.orderdetails1.Delivery_List_RMB__c == 0) &&
+                        coc.SummonsForDirction__c != '鍖婚櫌璇曠敤'
+                    ) {
+                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ嚭璐у崟浠� (鍏�)', '');
                     }
                     if (
                         ass.orderdetails1.Delivery_List_RMB__c == 0 &&
                         (coc.SummonsForDirction__c == '閿�鍞粰浜岀骇缁忛攢鍟�' ||
                         coc.SummonsForDirction__c == '鐩存帴閿�鍞粰鍖婚櫌')
                     ) {
-                        // ass.orderdetails1.Delivery_List_RMB__c.addError('璇疯緭鍏ュ嚭璐у崟浠� (鍏�)銆�');
-                        // return null;
-                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ嚭璐у崟浠� (鍏�)銆�', '');
+                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ嚭璐у崟浠� (鍏�)', '');
                     }
                     if (ass.orderdetails1.Shipment_Count__c == null || ass.orderdetails1.Shipment_Count__c == 0) {
-                        // ass.orderdetails1.Shipment_Count__c.addError('璇疯緭鍏ュ嚭璐ф暟閲忋��');
+                        // ass.orderdetails1.Shipment_Count__c.addError('璇疯緭鍏ュ嚭璐ф暟閲�');
                         // return null;
-                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ嚭璐ф暟閲忋��', '');
+                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ嚭璐ф暟閲�', '');
                     }
 
                     if (ass.orderdetails1.Box_Piece__c == null || ass.orderdetails1.Box_Piece__c == '') {
-                        // ass.orderdetails1.Box_Piece__c.addError('璇疯緭鍏ュ崟浣嶃��');
+                        // ass.orderdetails1.Box_Piece__c.addError('璇疯緭鍏ュ崟浣�');
                         // return null;
-                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ崟浣嶃��', '');
+                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ崟浣�', '');
                     }
                     if (ass.orderdetails1.Box_Piece__c == '鐩�') {
                         if (ass.orderdetails1.Shipment_Count__c > ass.Boxnumber) {
@@ -2094,9 +2220,7 @@
                                 return new ResponseBodyLWC(
                                     'Error',
                                     500,
-                                    '娑堣�楀搧' +
-                                    ass.orderdetails1.Consumable_Product__r.Name__c +
-                                    '搴撳瓨涓嶈冻',
+                                    '娑堣�楀搧' + ass.orderdetails1.Consumable_Product__r.Name__c + '搴撳瓨涓嶈冻',
                                     ''
                                 );
                             }
@@ -2112,9 +2236,7 @@
                                 return new ResponseBodyLWC(
                                     'Error',
                                     500,
-                                    '娑堣�楀搧' +
-                                    ass.orderdetails1.Consumable_Product__r.Name__c +
-                                    '搴撳瓨涓嶈冻',
+                                    '娑堣�楀搧' + ass.orderdetails1.Consumable_Product__r.Name__c + '搴撳瓨涓嶈冻',
                                     ''
                                 );
                             }
@@ -2217,29 +2339,26 @@
             for (ConsumableorderdetailsInfoLwc ass : pageRecordsLwc) {
                 if (ass.check == true) {
                     if (ass.orderdetails1.Delivery_List_RMB__c < 0) {
-                        // ass.orderdetails1.Delivery_List_RMB__c.addError('璇疯緭鍏ユ纭殑鍑鸿揣鍗曚环 (鍏�)銆�');
-                        // return null;
-                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ユ纭殑鍑鸿揣鍗曚环 (鍏�)銆�', '');
+                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ユ纭殑鍑鸿揣鍗曚环 (鍏�)', '');
                     }
                     Consumable_orderdetails__c InsAfterDel = new Consumable_orderdetails__c();
-                    if (ass.orderdetails1.Delivery_List_RMB__c == null && coc.SummonsForDirction__c != '鍖婚櫌璇曠敤') {
-                        // ass.orderdetails1.Delivery_List_RMB__c.addError('璇疯緭鍏ュ嚭璐у崟浠� (鍏�)銆�');
-                        // return null;
-                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ嚭璐у崟浠� (鍏�)銆�', '');
+                    if (
+                        (ass.orderdetails1.Delivery_List_RMB__c == null || ass.orderdetails1.Delivery_List_RMB__c == 0) &&
+                        coc.SummonsForDirction__c != '鍖婚櫌璇曠敤'
+                    ) {
+                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ嚭璐у崟浠� (鍏�)', '');
                     }
                     if (
                         ass.orderdetails1.Delivery_List_RMB__c == 0 &&
                         (coc.SummonsForDirction__c == '閿�鍞粰浜岀骇缁忛攢鍟�' ||
                         coc.SummonsForDirction__c == '鐩存帴閿�鍞粰鍖婚櫌')
                     ) {
-                        // ass.orderdetails1.Delivery_List_RMB__c.addError('璇疯緭鍏ュ嚭璐у崟浠� (鍏�)銆�');
-                        // return null;
-                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ嚭璐у崟浠� (鍏�)銆�', '');
+                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ嚭璐у崟浠� (鍏�)', '');
                     }
                     if (ass.orderdetails1.Box_Piece__c == null || ass.orderdetails1.Box_Piece__c == '') {
-                        // ass.orderdetails1.Box_Piece__c.addError('璇疯緭鍏ュ崟浣嶃��');
+                        // ass.orderdetails1.Box_Piece__c.addError('璇疯緭鍏ュ崟浣�');
                         // return null;
-                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ崟浣嶃��', '');
+                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ崟浣�', '');
                     }
                     if (ass.orderdetails1.Box_Piece__c == '鐩�') {
                         if (ass.orderdetails1.Shipment_Count__c > ass.Boxnumber) {
@@ -2252,9 +2371,7 @@
                                 return new ResponseBodyLWC(
                                     'Error',
                                     500,
-                                    '娑堣�楀搧' +
-                                    ass.orderdetails1.Consumable_Product__r.Name__c +
-                                    '搴撳瓨涓嶈冻',
+                                    '娑堣�楀搧' + ass.orderdetails1.Consumable_Product__r.Name__c + '搴撳瓨涓嶈冻',
                                     ''
                                 );
                             }
@@ -2269,18 +2386,16 @@
                                 return new ResponseBodyLWC(
                                     'Error',
                                     500,
-                                    '娑堣�楀搧' +
-                                    ass.orderdetails1.Consumable_Product__r.Name__c +
-                                    '搴撳瓨涓嶈冻',
+                                    '娑堣�楀搧' + ass.orderdetails1.Consumable_Product__r.Name__c + '搴撳瓨涓嶈冻',
                                     ''
                                 );
                             }
                         }
                     }
                     if (ass.orderdetails1.Shipment_Count__c == null || ass.orderdetails1.Shipment_Count__c == 0) {
-                        // ass.orderdetails1.Shipment_Count__c.addError('璇疯緭鍏ュ嚭璐ф暟閲忋��');
+                        // ass.orderdetails1.Shipment_Count__c.addError('璇疯緭鍏ュ嚭璐ф暟閲�');
                         // return null;
-                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ嚭璐ф暟閲忋��', '');
+                        return new ResponseBodyLWC('Error', 500, '璇疯緭鍏ュ嚭璐ф暟閲�', '');
                     } else {
                         String str = string.valueOf(i);
                         if (str.length() == 1) {
@@ -2390,23 +2505,104 @@
     public static List<LookupSearchResult> search(String searchTerm) {
         System.debug('searchTerm = ' + searchTerm);
         String nameCondition = '';
-        nameCondition += '%' + String.escapeSingleQuotes(''.replaceAll('%', '\\%')) + '%';
-        List<Account> accs;
+        nameCondition += '%' + String.escapeSingleQuotes(searchTerm.replaceAll('%', '\\%')) + '%';
+        List<Account> accs = new List<Account>();
         System.debug('nameCondition = ' + nameCondition);
-        accs = [
-            SELECT id, Parentid
-            FROM Account
-            WHERE
-                Parent.Name LIKE :nameCondition
-                AND Contract_Decide_Start_Date__c <= :Date.Today()
-                AND Contract_Decide_End_Date__c >= :Date.Today()
-        ];
+        //鏌ヨ鏉′欢淇敼
+        //绛涢�夊垽鏂潯浠讹細褰撳墠璐㈠勾鐨�4/1 ~ 绗簩骞寸殑6/30 聽& ET or ENG绫诲瀷 & 褰撳墠鐢ㄦ埛绫诲瀷
+        //1 and 2
+        //1. Integer year 2022/4/1 ~ 2023/6/30
+        //寮�濮嬫棩鏈� + 缁撴潫鏃ユ湡
+        //Contract_Decide_Start_Date__c>=寮�濮嬫棩鏈�  and Contract_Decide_End_Date__c<缁撴潫鏃ユ湡
+        //2. 娣诲姞缁忛攢鍟嗗厑閿�绫诲瀷锛欵T缁忛攢鍟嗗崗璁紱ENG鑰楁潗缁忛攢鍟嗗崗璁�
+        //鍙栧綋鍓嶇敤鎴风殑绫诲瀷锛屽鏋滅敤鎴风被鍨嬫槸ET,ET缁忛攢鍟嗗崗璁� = true
+        // Date today = Date.today();
+        // Integer thisYear = today.year();
+        // Integer nextYear = today.year() + 1;
+        // Date thisDatetime = Date.newInstance(thisYear, 4, 1);
+        // Date nextDatetime = Date.newInstance(nextYear, 6, 30);
+        // System.debug('thisDatetime = ' + thisDatetime);
+        // System.debug('nextDatetime = ' + nextDatetime);
 
+        // User UserProTypecTemp = [select UserPro_Type__c from User where id =: UserInfo.getUserId()];
+        // System.debug('UserInfo.getUserId() = ' + UserInfo.getUserId());
+        // System.debug('UserProTypecTemp = ' + UserProTypecTemp);
+        // System.debug('UserProTypecTemp.UserPro_Type__c = ' + UserProTypecTemp.UserPro_Type__c);
+        // if (UserProTypecTemp.UserPro_Type__c == 'ENG') {
+        //     accs = [
+        //         SELECT Id, Name, Department_Class__c, Department_Class__r.Name, Hospital__c, Hospital__r.Name, BillingCity
+        //         FROM Account
+        //         WHERE
+        //             // Name = '濂ユ灄宸存柉锛堝寳浜級閿�鍞湇鍔℃湁闄愬叕鍙�'
+        //             // AND
+        //             Name LIKE :nameCondition
+        //             AND RecordType.DeveloperName = 'AgencyContract'
+        //             AND Contract_Decide_Start_Date__c >= :thisDatetime
+        //             AND Contract_Decide_End_Date__c <= :nextDatetime
+        //             AND ENG_Dealer__c = true
+        //         ORDER BY Name
+        //         LIMIT 49
+        //     ];
+        // }
+        // if (UserProTypecTemp.UserPro_Type__c == 'ET') {
+        //     accs = [
+        //         SELECT Id, Name, Department_Class__c, Department_Class__r.Name, Hospital__c, Hospital__r.Name, BillingCity
+        //         FROM Account
+        //         WHERE
+        //             // Name = '濂ユ灄宸存柉锛堝寳浜級閿�鍞湇鍔℃湁闄愬叕鍙�'
+        //             // AND
+        //             Name LIKE :nameCondition
+        //             AND RecordType.DeveloperName = 'AgencyContract'
+        //             AND Contract_Decide_Start_Date__c >= :thisDatetime
+        //             AND Contract_Decide_End_Date__c <= :nextDatetime
+        //             AND ET_SP_Dealer__c = true
+        //         ORDER BY Name
+        //         LIMIT 49
+        //     ];
+        // }
+
+        Date today = Date.today();
+        //Date today = Date.newInstance(2023, 3, 1);
+        Integer thisMonth = today.month();
+        System.debug('thisMonth = ' + thisMonth);
+
+        Integer lastYear = today.year() - 1;
+        Integer thisYear = today.year();
+        Integer nextYear = today.year() + 1;
+
+        Date lastDatetime = Date.newInstance(lastYear, 4, 1);
+        Date thisDatetime = Date.newInstance(thisYear, 4, 1);
+        Date thisDatetime2 = Date.newInstance(thisYear, 7, 1);
+        Date nextDatetime = Date.newInstance(nextYear, 7, 1);
+        System.debug('lastDatetime = ' + lastDatetime);
+        System.debug('thisDatetime = ' + thisDatetime);
+        System.debug('thisDatetime2 = ' + thisDatetime2);
+        System.debug('nextDatetime = ' + nextDatetime);
+        System.debug('UserInfo.getUserId() = ' + UserInfo.getUserId());
+        User UserProTypecTemp = [SELECT UserPro_Type__c FROM User WHERE id = :UserInfo.getUserId()];
+
+        String sql = 'SELECT id, Parentid FROM Account WHERE Parent.Name LIKE :nameCondition ';
+        if (thisMonth < 4) {
+            sql += 'AND Contract_Decide_Start_Date__c >= :lastDatetime AND Contract_Decide_End_Date__c < :thisDatetime2 ';
+        } else if (thisMonth >= 4 && thisMonth <= 6) {
+            sql += 'AND Contract_Decide_Start_Date__c >= :lastDatetime AND Contract_Decide_End_Date__c < :nextDatetime ';
+        } else {
+            sql += 'AND Contract_Decide_Start_Date__c >= :thisDatetime AND Contract_Decide_End_Date__c < :nextDatetime ';
+        }
+        if (UserProTypecTemp.UserPro_Type__c == 'ENG') {
+            sql += 'AND ENG_Dealer__c = true';
+        }
+        if (UserProTypecTemp.UserPro_Type__c == 'ET') {
+            sql += 'AND ET_SP_Dealer__c = true';
+        }
+        System.debug('sql = ' + sql);
+        accs = Database.query(sql);
         // 鐢ㄤ簬淇濆瓨鐗圭害缁忛攢鍟嗗尮閰嶅埌鐨勫叾鐖剁被鐨刬d
         Set<String> pids = new Set<String>();
         for (Account acc : accs) {
             pids.add(acc.Parentid);
         }
+
         accs = [
             SELECT Id, Name, Department_Class__c, Department_Class__r.Name, Hospital__c, Hospital__r.Name, BillingCity
             FROM Account
@@ -2415,11 +2611,37 @@
                 OR (Name = '濂ユ灄宸存柉锛堝寳浜級閿�鍞湇鍔℃湁闄愬叕鍙�'
                 AND Name LIKE :nameCondition))
                 AND RecordType.DeveloperName = 'Agency'
-                AND Is_Active__c != '鐒″姽'
             ORDER BY Name
-            LIMIT 5
+            LIMIT 49
         ];
 
+        // accs = [
+        //     SELECT id, Parentid
+        //     FROM Account
+        //     WHERE
+        //         Parent.Name LIKE :nameCondition
+        //         AND Contract_Decide_Start_Date__c <= :Date.Today()
+        //         AND Contract_Decide_End_Date__c >= :Date.Today()
+        // ];
+
+        // 鐢ㄤ簬淇濆瓨鐗圭害缁忛攢鍟嗗尮閰嶅埌鐨勫叾鐖剁被鐨刬d
+        // Set<String> pids = new Set<String>();
+        // for (Account acc : accs) {
+        //     pids.add(acc.Parentid);
+        // }
+        // accs = [
+        //     SELECT Id, Name, Department_Class__c, Department_Class__r.Name, Hospital__c, Hospital__r.Name, BillingCity
+        //     FROM Account
+        //     WHERE
+        //         (Id IN :pids
+        //         OR (Name = '濂ユ灄宸存柉锛堝寳浜級閿�鍞湇鍔℃湁闄愬叕鍙�'
+        //         AND Name LIKE :nameCondition))
+        //         AND RecordType.DeveloperName = 'Agency'
+        //         AND Is_Active__c != '鐒″姽'
+        //     ORDER BY Name
+        //     LIMIT 5
+        // ];
+        System.debug('accs = ' + accs);
         List<LookupSearchResult> results = new List<LookupSearchResult>();
         String accountIcon = 'standard:account';
         for (Account account : accs) {
@@ -2453,7 +2675,7 @@
         Map<String, object> data = new Map<String, object>();
         res.entity = data;
         List<ContentVersion> cvList = [
-            SELECT id, Title, CreatedBy.Name, PathOnClient,CreatedDate
+            SELECT id, Title, CreatedBy.Name, PathOnClient, CreatedDate, ContentDocumentId
             FROM ContentVersion
             WHERE FirstPublishLocationId = :recordId
         ];
@@ -2462,6 +2684,20 @@
         res.code = 200;
         System.debug('res = ' + res);
         return res;
+    }
+
+    //鍒犻櫎闄勪欢
+    @AuraEnabled
+    public static ResponseBodyLWC deleteAtt(String contentVersionId) {
+        try {
+            ContentVersion conVersion = [SELECT ContentDocumentId FROM ContentVersion WHERE Id = :contentVersionId];
+            String contentDocumentId = conVersion.ContentDocumentId;
+            ContentDocument conDocument = [SELECT Id FROM ContentDocument WHERE Id = :contentDocumentId];
+            delete conDocument;
+            return new ResponseBodyLWC('Success', 200, '', '');
+        } catch (Exception e) {
+            return new ResponseBodyLWC('Error', 500, e.getMessage() + e.getLineNumber(), '');
+        }
     }
 
     //璺宠浆鍑鸿揣/閿�鍞�
@@ -2518,7 +2754,7 @@
         ESetId = ESetId;
 
         Savepoint sp = Database.setSavepoint();
-        try{
+        try {
             List<Consumable_order__c> qs = new List<Consumable_order__c>();
             List<Consumable_orderdetails__c> Dqs = new List<Consumable_orderdetails__c>();
             Dqs = [SELECT Id FROM Consumable_orderdetails__c WHERE Consumable_order__c = :ESetId];
@@ -2527,7 +2763,7 @@
                 delete Dqs;
                 delete qs;
             }
-        }catch(Exception e){
+        } catch (Exception e) {
             Database.rollback(sp);
             System.debug(e.getMessage() + e.getLineNumber());
             return new ResponseBodyLWC('Error', 500, e.getMessage(), '');
@@ -2539,6 +2775,7 @@
     }
 
     // Data Bean
+    @TestVisible
     class ConsumableorderdetailsInfo implements Comparable {
         @AuraEnabled
         public Boolean check { get; set; }
@@ -2679,6 +2916,7 @@
         }
     }
 
+    @TestVisible
     class ConsumableorderdetailsInfoLwc {
         @AuraEnabled
         public Boolean check { get; set; }
@@ -2742,4 +2980,18 @@
         @AuraEnabled
         public String Category5 { get; set; }
     }
+
+    //鍒嗛〉Bean
+    public class PaginatedAccounts {
+        @AuraEnabled
+        public Integer nextPageToken;
+        @AuraEnabled
+        public Integer pageNumber { get; set; }
+        @AuraEnabled
+        public Integer totalRecords { get; set; }
+        @AuraEnabled
+        public Integer recordStart { get; set; }
+        @AuraEnabled
+        public Integer recordEnd { get; set; }
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.1