From 8cb2c2c65e363b3d0fbb655261c54550b0f4bc9c Mon Sep 17 00:00:00 2001
From: unknown <sunxia@prec-tech.com>
Date: 星期四, 20 七月 2023 10:09:58 +0800
Subject: [PATCH] button-lexSelectSubstitute

---
 force-app/main/default/classes/LexSelectSubstituteControllerLWT.cls          |  686 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 force-app/main/default/classes/LexSelectSubstituteControllerLWT.cls-meta.xml |    5 
 force-app/main/default/lwc/lexSelectSubstitute/lexSelectSubstitute.js        |    6 
 3 files changed, 694 insertions(+), 3 deletions(-)

diff --git a/force-app/main/default/classes/LexSelectSubstituteControllerLWT.cls b/force-app/main/default/classes/LexSelectSubstituteControllerLWT.cls
new file mode 100644
index 0000000..2ff7860
--- /dev/null
+++ b/force-app/main/default/classes/LexSelectSubstituteControllerLWT.cls
@@ -0,0 +1,686 @@
+public with sharing class LexSelectSubstituteControllerLWT {
+    public LexSelectSubstituteControllerLWT() {
+        
+    }
+        @AuraEnabled
+    public static InitData initFromSelectSubstituteButton(String recordId){
+        InitData res = new InitData();
+        try{
+            Rental_Apply_Equipment_Set__c report=[select
+                Id,Rental_Apply__r.Status__c,Rental_Apply__r.Id
+             from Rental_Apply_Equipment_Set__c
+             where Id= :recordId];
+            res.id=report.Id;
+            res.RentalApplyId=report.Rental_Apply__r.Id;
+            res.Status=report.Rental_Apply__r.Status__c;
+        }catch(Exception e){
+            System.debug(LoggingLevel.INFO,'Rental_Apply_Equipment_Set__c Cancel Error : ' + e);
+        }
+        return res;
+    }
+
+
+    @AuraEnabled
+    public static List<String> getStatusList(){
+        String statusSting = Label.StatusProcessState;
+        List<String> status = statusSting.split(',');
+        return status;
+    }
+
+    @AuraEnabled
+    public static List<String> getUserIdByUserName(List<String> userNameList){
+        try{
+            List<User> userList=[select id,name from user where name in :userNameList];
+            List<String> res=new List<String>();
+            for (User u:userList ) {
+                res.add(u.id);
+            }
+            return res;
+        }catch(Exception e){
+            System.debug(LoggingLevel.INFO,'Rental_Apply_Equipment_Set__c Cancel Error : ' + e);
+        }
+        return null;
+    }
+
+    @AuraEnabled
+    public static Rental_Apply_Equipment_Set__c initFromCustomSubmitButton(String recordId){
+
+        try{
+            Rental_Apply_Equipment_Set__c report=[select
+                Id,Request_extend_day__c
+                ,Extend_request_reason__c
+                ,Rental_End_Date__c,
+                Rental_Apply__c
+             from Rental_Apply_Equipment_Set__c
+             where Id= :recordId];
+
+             return report;
+        }catch(Exception e){
+            System.debug(LoggingLevel.INFO,'Rental_Apply_Equipment_Set__c Cancel Error : ' + e);
+        }
+        return null;
+    }
+
+    @AuraEnabled
+    public static InitData initFromLoanerArrangedEmailLButton(String recordId){
+        String statusSting = Label.StatusProcessState;
+        List<String> status = statusSting.split(',');
+        InitData res = new InitData();
+        try{
+            Rental_Apply_Equipment_Set__c report=[select
+                Id,Rental_Apply__r.Status__c,Rental_Apply__c,Rental_Apply__r.Wei_Assigned_Cnt__c,
+                Assigned_Not_Shipment__c,Rental_Apply__r.Bollow_Date__c
+             from Rental_Apply_Equipment_Set__c
+             where Id= :recordId];
+            res.id=report.Id;
+            res.RentalApplyC=report.Rental_Apply__c;
+            res.Status=report.Rental_Apply__r.Status__c;
+            res.WeiAssignedCntC=report.Rental_Apply__r.Wei_Assigned_Cnt__c;
+            res.BollowDateC=report.Rental_Apply__r.Bollow_Date__c;
+            res.AssignedNotShipmentC=report.Assigned_Not_Shipment__c;
+            res.statusList = status;
+        }catch(Exception e){
+            System.debug(LoggingLevel.INFO,'Rental_Apply_Equipment_Set__c Cancel Error : ' + e);
+        }
+        return res;
+    }
+
+    @AuraEnabled
+    public static InitData initClearReturnDeliverySlipButton(String recordId){
+        InitData res = new InitData();
+        try{
+            Rental_Apply_Equipment_Set__c report=[select
+                Id,Rental_Apply__r.Status__c,Rental_Apply__c,Rental_Apply__r.Wei_Assigned_Cnt__c,
+                Assigned_Not_Shipment__c,Rental_Apply__r.Bollow_Date__c
+             from Rental_Apply_Equipment_Set__c
+             where Id= :recordId];
+            res.id=report.Id;
+            res.RentalApplyC=report.Rental_Apply__c;
+            res.Status=report.Rental_Apply__r.Status__c;
+            res.WeiAssignedCntC=report.Rental_Apply__r.Wei_Assigned_Cnt__c;
+            res.BollowDateC=report.Rental_Apply__r.Bollow_Date__c;
+            res.AssignedNotShipmentC=report.Assigned_Not_Shipment__c;
+        }catch(Exception e){
+            System.debug(LoggingLevel.INFO,'Rental_Apply_Equipment_Set__c Cancel Error : ' + e);
+        }
+        return res;
+    }
+
+    @AuraEnabled
+    public static Rental_Apply_Equipment_Set__c selectRentalApplyEquipmentSetByID(String recordId){
+        try{
+            Rental_Apply_Equipment_Set__c report=[select 
+             Cancel_Select__c,Irreplaceable_flag__c,RAES_Status__c,Shippment_loaner_time2__c 
+             from Rental_Apply_Equipment_Set__c 
+             where Id=:recordId];
+            return report;
+        }catch(Exception e){
+            System.debug(LoggingLevel.INFO,'Rental_Apply_Equipment_Set__c Cancel Error : ' + e);
+        }
+        return null;
+    }
+
+    @AuraEnabled
+    public static list<Rental_Apply_Equipment_Set_Detail__c> selectRentalApplyEquipmentSetByRACID(String recordId){
+        try{
+            list<Rental_Apply_Equipment_Set_Detail__c> report=[select Allow_Adjust_Queue_Flag__c 
+            from Rental_Apply_Equipment_Set_Detail__c 
+            where Rental_Apply__c = :recordId ];
+            return report;
+        }catch(Exception e){
+            System.debug(LoggingLevel.INFO,'Rental_Apply_Equipment_Set__c Cancel Error : ' + e);
+        }
+        return null;
+    }
+
+
+    @AuraEnabled
+    public static list<Rental_Apply__c> selectRentalApplyCByName(String recordId){
+        try{
+            list<Rental_Apply__c> report=[select 
+            Id,Campaign__c,Repair__c,Status__c,Bollow_Date__c, Demo_purpose1__c,Contract_pdf_updated__c,Repair_Final_Inspection_Date_F__c,RC_return_to_office__c,Wei_Assigned_Cnt__c 
+            from Rental_Apply__c 
+            where id=:recordId ];
+            return report;
+        }catch(Exception e){
+            System.debug(LoggingLevel.INFO,'Rental_Apply_Equipment_Set__c Cancel Error : ' + e);
+        }
+        return null;
+    }
+    @AuraEnabled
+    public static list<Campaign> selectCampaignById(String recordId){
+        try{
+            list<Campaign> report=[select
+              Status, Rental_Apply_Flag__c,IF_Approved__c,Meeting_Approved_No__c,Approved_Status__c
+              from Campaign
+              where id =:recordId ];
+            return report;
+        }catch(Exception e){
+            System.debug(LoggingLevel.INFO,'Rental_Apply_Equipment_Set__c Cancel Error : ' + e);
+        }
+        return null;
+    }
+    @AuraEnabled
+    public static String getSessionId(){
+        return UserInfo.getSessionId();
+    }
+
+
+    @AuraEnabled
+    public static list<Rental_Apply_Equipment_Set__c> selectRaesById1(String recordId1){
+        try{
+            list<Rental_Apply_Equipment_Set__c> report=[select Id 
+            from Rental_Apply_Equipment_Set__c 
+            where Rental_Apply__c = :recordId1 
+            and Shippment_loaner_time2__c != null 
+            and RAES_Status__c != '宸插垎閰�' 
+            and RAES_Status__c != '鍙栨秷鍒嗛厤'
+            ];
+            return report;
+        }catch(Exception e){
+            System.debug(LoggingLevel.INFO,'selectRaesById1 Error : ' + e);
+        }
+        return null;
+    }
+    @AuraEnabled
+    public static list<Rental_Apply_Equipment_Set__c> selectRaesById2(String recordId2){
+        try{
+            list<Rental_Apply_Equipment_Set__c> report=[select Id
+             from Rental_Apply_Equipment_Set__c
+              where Rental_Apply__c = :recordId2
+              and RAES_Status__c != '宸插垎閰�'
+              and RAES_Status__c != '鍙栨秷鍒嗛厤'
+           ];
+            return report;
+        }catch(Exception e){
+            System.debug(LoggingLevel.INFO,'selectRaesById1 Error : ' + e);
+        }
+        return null;
+    }
+
+    @AuraEnabled
+    public static list<Rental_Apply__c> selectRacById(String recordId){
+        try{
+            list<Rental_Apply__c> report=[SELECT 
+            Id, JingliApprovalManager__c, SalesManager__c
+            , BuchangApprovalManager__c
+            , BuchangApprovalManagerSales__c
+            , ZongjianApprovalManager__c 
+            FROM Rental_Apply__c 
+            WHERE Id = :recordId
+            ];
+            return report;
+        }catch(Exception e){
+            System.debug(LoggingLevel.INFO,'Rental_Apply_Equipment_Set__c Cancel Error : ' + e);
+        }
+        return null;
+    }
+
+    @AuraEnabled
+    public static UpdateResult updateRaesc(        
+        String recordId,
+        String JingliApprovalManagerc,
+        String SalesManagerc,
+        String BuchangApprovalManagerc,
+        String BuchangApprovalManagerSalesc,
+        String ZongjianApprovalManagerc,
+        String ExtendStatusc
+    ) {
+        UpdateResult result = new UpdateResult();
+        result.recordId = recordId;
+        try{
+            // 鏇存柊璁板綍骞惰幏鍙栫粨鏋�
+            if(recordId==null) return null;
+            Rental_Apply_Equipment_Set__c rac = new Rental_Apply_Equipment_Set__c( id=recordId);
+
+            if(JingliApprovalManagerc!=null&& JingliApprovalManagerc != ''){
+                rac.JingliApprovalManager__c=JingliApprovalManagerc;
+            }
+            if(SalesManagerc!=null&&SalesManagerc!=''){
+                rac.SalesManager__c=SalesManagerc;
+            }
+            if(BuchangApprovalManagerc!=null&&BuchangApprovalManagerc!=''){
+                rac.BuchangApprovalManager__c=BuchangApprovalManagerc;
+            }
+            if(BuchangApprovalManagerSalesc!=null&&BuchangApprovalManagerSalesc!=''){
+                rac.BuchangApprovalManagerSales__c=BuchangApprovalManagerSalesc;
+            }
+
+            if(ZongjianApprovalManagerc!=null&&ZongjianApprovalManagerc!=''){
+                rac.ZongjianApprovalManager__c=ZongjianApprovalManagerc;
+            }
+            if(ExtendStatusc!=null&&ExtendStatusc!=''){
+                rac.Extend_Status__c=ExtendStatusc;
+            }
+            if(rac.id==null)return null;
+            update rac;
+            result.success = true;
+            result.errors = new List<String>();
+            return result;
+        }catch(Exception e){
+            result.success = false;
+            result.errors = new List<String>();
+            result.errors.add(e.getMessage());
+            System.debug(LoggingLevel.INFO,'Rental_Apply__c update Error : ' + e);
+        }
+        return result;
+    }
+
+    @AuraEnabled
+    public static UpdateResult updateRaescList(        
+        list<Rental_Apply_Equipment_Set_Detail__c> updateList
+    ) {
+        UpdateResult result = new UpdateResult();
+        try{
+            for(Rental_Apply_Equipment_Set_Detail__c item : updateList) {
+                item.Return_DeliverySlip__c = null;
+                item.Asset_return_time__c = null;
+            }
+            update updateList;
+            result.success = true;
+            result.errors = new List<String>();
+            return result;
+        }catch(Exception e){
+            result.success = false;
+            result.errors = new List<String>();
+            result.errors.add(e.getMessage());
+            System.debug(LoggingLevel.INFO,'Rental_Apply__c update Error : ' + e);
+        }
+        return result;
+    }
+
+    @AuraEnabled
+    public static list<Rental_Apply_Equipment_Set_Detail__c> selectRaesdcId(String recordId){
+        try{
+            list<Rental_Apply_Equipment_Set_Detail__c> report=[Select 
+            Id 
+            From Rental_Apply_Equipment_Set_Detail__c 
+            Where Return_DeliverySlip__c != null 
+            AND Check_lost_Item_F__c = null 
+            AND Rental_Apply_Equipment_Set__c = :recordId AND Cancel_Select__c = false
+            ];
+            return report;
+        }catch(Exception e){
+            System.debug(LoggingLevel.INFO,'Rental_Apply_Equipment_Set__c Cancel Error : ' + e);
+        }
+        return null;
+    }   
+
+    @AuraEnabled
+    public static String approvalCheck(String rentalApplyId) {
+        // check缁撴灉
+        String returnStr = '';
+        
+        //1388 yc 20211021 璺ㄥ尯鍩熷垎閰嶄笉鑳藉嚭搴�  start
+        String rasdid = '';
+        system.debug(rentalApplyId+'==');
+        if(String.isNotBlank(rentalApplyId) && rentalApplyId.indexOf(';') >= 0){//璇存槑鏄粠涓�瑙堜笂瑙﹀彂鐨�
+           rasdid = rentalApplyId.subString(rentalApplyId.indexOf(';') + 1);
+           rentalApplyId = rentalApplyId.subString(0, rentalApplyId.indexOf(';'));
+        }
+        //1388 yc 20211021 璺ㄥ尯鍩熷垎閰嶄笉鑳藉嚭搴�  end
+        //澶囧搧鍊熷嚭鐢宠
+        Rental_Apply__c[] rentalApply = [select Id,repair__r.Repair_Final_Inspection_Date__c,Bollow_Date__c,repair__r.Return_Without_Repair_Date__c,
+                                        CreatedDate,Rental_Apply_Equipment_Set_Cnt__c,Prepare_Day__c,Cross_Region_Assign__c,
+                                        demo_purpose2__c,Follow_UP_Opp__r.Shipping_Finished_Day_Func__c,next_action__c,QIS_number__r.ReplaceDeliveryDate__c
+                                        from Rental_Apply__c 
+                                        where Id = :rentalApplyId];
+        if (rentalApply.size() == 0) {
+            returnStr = '娌℃湁澶囧搧鍊熷嚭鐢宠锛岃纭銆�';
+            return returnStr;
+        }
+        Rental_Apply__c ra = rentalApply[0];
+        if (ra.Rental_Apply_Equipment_Set_Cnt__c <= 0) {
+            returnStr = '娌℃湁鍊熷嚭澶囧搧set涓�瑙堬紝璇风‘璁ゃ��';
+            return returnStr;
+        }
+        //1822 yc 20211111 start
+        if(ra.demo_purpose2__c=='宸茶喘寰呰揣' && ra.Follow_UP_Opp__r.Shipping_Finished_Day_Func__c!= null){
+            returnStr = '宸茶喘寰呰揣鐩殑锛屾柊鍝佸凡鏈夊彂璐ф棩锛屼笉鍙嚭搴撴寚绀�';
+            return returnStr;
+        }
+        if(ra.demo_purpose2__c=='绱㈣禂QIS' && ra.next_action__c=='鏃犲伩鏇存崲' && ra.QIS_number__r.ReplaceDeliveryDate__c!= null){
+            returnStr = '绱㈣禂QIS鐩殑锛孮IS宸叉湁鏂板搧鍙戣揣鏃ワ紝涓嶅彲鍑哄簱鎸囩ず';
+            return returnStr;
+       }
+        //1822 yc 20211111 end
+
+//*************************Insert 20160826 SWAG-AD59Z6 瓒欏境鑺� Start*************************//
+        if(Ra.repair__r.Repair_Final_Inspection_Date__c != null) {
+            return '淇悊鏈�缁堟娴嬫棩涓嶄负绌猴紝涓嶈兘鍋氬嚭搴撴寚绀�';
+        }
+        if(Ra.repair__c!=null&&Ra.repair__r.Return_Without_Repair_Date__c != null) {
+            return '鏈慨鐞嗗綊杩樻棩涓嶄负绌猴紝涓嶈兘鍋氬嚭搴撴寚绀�';
+        }
+//*************************Insert 20160826 SWAG-AD59Z6 瓒欏境鑺� End***************************//
+
+        //1388 yc 20211021 璺ㄥ尯鍩熷垎閰嶄笉鑳藉嚭搴� start
+        if(String.isNotBlank(ra.Cross_Region_Assign__c)){
+            String soql = 'select Id, Name,Rental_Apply__c,Internal_asset_location_before__c';
+                   soql +=' from Rental_Apply_Equipment_Set_Detail__c';
+                   soql +=' where Rental_Apply__c = \'' + ra.Id +'\'';
+                   soql +=' and Internal_asset_location_before__c !=null and Internal_asset_location_before__c != \'' + ra.Cross_Region_Assign__c+ '\'';
+            
+            if(String.isNotBlank(rasdid)){
+                   soql +=' and Rental_Apply_Equipment_Set__c = :rasdid';            
+              }
+            List<Rental_Apply_Equipment_Set_Detail__c> raesd = Database.query(soql);
+            if(raesd.size()>0){
+                returnStr = '鍒嗛厤鐨勫鍝佷笉鏄偍鎵�灞炲鍝佷腑蹇冪殑澶囧搧锛屼笉鑳藉仛鍑哄簱鎸囩ず'; 
+                return returnStr;
+            }
+            
+        }
+        //1388 yc 20211021 璺ㄥ尯鍩熷垎閰嶄笉鑳藉嚭搴� end
+        // 20220211 ljh add 澶囧搧FY23璇鹃01 start
+        // AggregateResult[] resultsRas = [SELECT Rental_Start_Date__c,count(Id) cnt
+        //                              FROM Rental_Apply_Equipment_Set__c
+        //                              WHERE Rental_Apply__c = :rentalApplyId 
+        //                              AND Cancel_Select__c = false
+        //                              group by Rental_Start_Date__c];
+        // If(resultsRas.size() > 1){
+        //  returnStr = '鎵�鏈変竴瑙堝鍝侀璁″嚭璐ф棩搴斾竴鑷达紝涓嶄竴鑷翠笉鑳藉仛鍑哄簱鎸囩ず'; 
+        //     return returnStr;
+        // }
+        // 20220211 ljh add 澶囧搧FY23璇鹃01 end
+
+//bp2        // 澶囧搧鍊熷嚭鍘嗗彶鍙栧緱
+//        List<String> equipmentSetList = new List<String>();
+//        Rental_Apply_Equipment_Set__c[] raes = [
+//            select Id, Name, Equipment_Set__c, Equipment_Set__r.Name, Rental_Start_Date__c, Rental_End_Date__c, Rental_Apply__c 
+//              from Rental_Apply_Equipment_Set__c 
+//             where Rental_Apply__c = :rentalApplyId and Cancel_Select__c = false];
+//        // 鏃ュ巻鑼冨洿锛屾渶灏忕殑鍊熷嚭寮�濮嬫棩鍒版渶澶х殑鍊熷嚭缁堜簡鏃�
+//        Date startDate = Date.today();
+//        Date endDate = Date.today();
+//        for (Rental_Apply_Equipment_Set__c r : raes) {
+//            equipmentSetList.add(r.Equipment_Set__c);
+//            if (r.Rental_Start_Date__c != null && r.Rental_Start_Date__c < startDate) {
+//                startDate = r.Rental_Start_Date__c;
+//            }
+//            if (r.Rental_End_Date__c != null && r.Rental_End_Date__c > endDate) {
+//                endDate = r.Rental_End_Date__c;
+//            }
+//        }
+//        Integer prepareDay = ra.Prepare_Day__c == null ? Integer.valueOf(System.Label.EquipmentRentalPrepare) : ra.Prepare_Day__c.intValue();
+//        Date minDate = getWD_addday(startDate, -1 * prepareDay);
+//        Date maxDate = getWD_addday(endDate, prepareDay);
+//        // 鍏朵粬澶囧搧鍊熷嚭鐢宠鍘嗗彶
+//        Rental_Apply_Equipment_Set__c[] others = [
+//                    select Id, Name, Rental_Start_Date__c, Rental_End_Date__c, Equipment_Set__c, Rental_Apply__r.Status__c ,Rental_Apply__r.Prepare_Day__c 
+//                      from Rental_Apply_Equipment_Set__c
+//                     where Rental_Apply__c != :rentalApplyId
+//                       and Equipment_Set__c in :equipmentSetList
+//                       and Request_Status__c != '鍙栨秷'
+//                       and Request_Status__c != '鍒犻櫎'
+//                       and Cancel_Select__c = false
+//                       and ((Rental_Start_Date__c >= :minDate and Rental_Start_Date__c <= :maxDate)
+//                            or (Rental_End_Date__c >= :minDate and Rental_End_Date__c <= :maxDate)
+//                            or (Rental_Start_Date__c <= :startDate and Rental_End_Date__c >= :endDate))];
+        
+//        Map<String, List<Rental_Apply_Equipment_Set__c>> othersMap = new Map<String,List<Rental_Apply_Equipment_Set__c>>();
+//        for (Rental_Apply_Equipment_Set__c other : others) {
+//            if (othersMap.containsKey(other.Equipment_Set__c)) {
+//                othersMap.get(other.Equipment_Set__c).add(other);
+//            } else {
+//                List<Rental_Apply_Equipment_Set__c> l = new List<Rental_Apply_Equipment_Set__c>();
+//                l.add(other);
+//                othersMap.put(other.Equipment_Set__c, l);
+//            }
+//        }
+        
+//        for (Rental_Apply_Equipment_Set__c r : raes) {
+            
+//            List<Rental_Apply_Equipment_Set__c> other = othersMap.get(r.Equipment_Set__c);
+            
+//            Map<Date, Map<String, String>> dateMap= new Map<Date, Map<String, String>>();
+//            if (other != null) {
+//                Date sdate = startDate;
+//                Date edate = endDate;
+//                for (Rental_Apply_Equipment_Set__c o : other) {
+//                    if (o.Rental_Start_Date__c != null && (sdate == null || o.Rental_Start_Date__c < sdate)) {
+//                        sdate = o.Rental_Start_Date__c;
+//                    }
+//                    if (o.Rental_End_Date__c != null && (edate == null || o.Rental_End_Date__c > edate)) {
+//                        edate = o.Rental_End_Date__c;
+//                    }
+//                }
+//                if (sdate != null && edate != null) {
+//                    RentalApplyWebService raws = new RentalApplyWebService();
+//                    dateMap = raws.getDateMap(sdate, edate, prepareDay);
+//                }
+//            }
+            
+//            if (r.Rental_Start_Date__c == null && r.Rental_End_Date__c == null) {
+//                // 娓呯┖璇ュ�熷嚭鍘嗗彶鐨勫嚭搴撳拰鍥炴敹鏃堕棿
+//            } else if (other == null || other.size() == 0) {
+//                // 涓庡叾浠栧�熷嚭鍘嗗彶娌℃湁鍐茬獊
+//            } else {
+//                Date fromDate = r.Rental_Start_Date__c;
+//                Date toDate = r.Rental_End_Date__c;
+//                for (Rental_Apply_Equipment_Set__c o : other) {
+//                    if (o.Rental_Apply__r.Status__c != '鑽夋涓�' && o.Rental_Apply__r.Status__c != '鐢宠涓�' && o.Rental_Apply__r.Status__c != null) {
+//                        Date startD = o.Rental_Start_Date__c;
+//                        Date endD = o.Rental_End_Date__c;
+//                        Integer prepare = prepareDay; //>= o.Rental_Apply__r.Prepare_Day__c || o.Rental_Apply__r.Prepare_Day__c == null ? prepareDay : o.Rental_Apply__r.Prepare_Day__c.intValue();
+//                        if ((dateMap.containsKey(fromDate) && Date.valueOf(dateMap.get(fromDate).get('Next')) > startD && dateMap.containsKey(endD) && fromDate < Date.valueOf(dateMap.get(endD).get('Next'))) ||
+//                            (dateMap.containsKey(toDate) && Date.valueOf(dateMap.get(toDate).get('Next')) > startD && dateMap.containsKey(endD) && toDate < Date.valueOf(dateMap.get(endD).get('Next'))) ||
+//                            (dateMap.containsKey(fromDate) && Date.valueOf(dateMap.get(fromDate).get('Next')) <= startD && dateMap.containsKey(endD) && toDate >= Date.valueOf(dateMap.get(endD).get('Next')))) {
+//                            returnStr = '澶囧搧' + r.Equipment_Set__r.Name + '鐨勫�熷嚭鏃ヤ笌澶囧搧鍊熷嚭鍘嗗彶' + o.Name + '鏈夊啿绐侊紝璇风‘璁ゃ��';
+//                            return returnStr;
+//                        }
+//                    }
+//                }
+//            }
+//        }
+        return '1';
+    }
+    
+    @AuraEnabled
+    public static String setShipment_requests(String raid, String raesid) {
+      Savepoint sp = Database.setSavepoint();
+
+      try {
+        //涓�瑙堟儏鍐典笅妫�绱竴瑙堝搴旂殑鐢宠涔d锛宻oql瀛愭煡璇笉鑳藉拰涓绘煡璇㈡槸鍚屼竴涓〃锛屽崟鐙绱竴娆�
+        if (String.isBlank(raid)) {
+            List<Rental_Apply_Equipment_Set__c> raList = [select Id, Rental_Apply__c from Rental_Apply_Equipment_Set__c where id = :raesid];
+            if (raList.size() > 0) {
+                raid = raList[0].Rental_Apply__c;
+            } else {
+                //搴旇涓嶄細鍒拌繖閲�
+                return '娌℃湁鍙互鍑哄簱鎸囩ず鐨勪竴瑙�';
+            }
+        }
+        String soql = 'SELECT Id'
+                + ' FROM Rental_Apply_Equipment_Set__c '
+                + ' WHERE Shippment_loaner_time2__c <> null '
+                + ' AND Rental_Apply__c = :raid '
+                + ' ORDER BY Id' ;
+        List<Rental_Apply_Equipment_Set__c> shippedRaesList = Database.query(soql);
+        String raesStrShipped = '';
+        for (Rental_Apply_Equipment_Set__c raes : shippedRaesList) {
+            raesStrShipped += raes.Id;
+        }
+
+        //Srring soql = "SELECT Id FROM Rental_Apply_Equipment_Set_Detail__c WHERE Rental_Apply__c = '{!Rental_Apply__c.Id}' AND Cancel_Select__c = false AND Rental_Num__c > 0 AND Rental_Apply_Equipment_Set__r.Wei_Assigned_Cnt__c = 0 AND Rental_Apply_Equipment_Set__r.Yi_Assigned_Cnt__c > 0 AND Shipment_request__c  = false";
+        soql = 'SELECT Id, Rental_Apply__c, Rental_Apply_Equipment_Set__c'
+                + ' FROM Rental_Apply_Equipment_Set_Detail__c '
+                + ' WHERE ' + (String.isNotBlank(raesid) ? 'Rental_Apply_Equipment_Set__c = :raesid ' : 'Rental_Apply__c = :raid ')
+                + ' AND Cancel_Select__c = false '
+                + ' AND Rental_Num__c > 0 '
+                + ' AND Rental_Apply_Equipment_Set__r.Wei_Assigned_Cnt__c = 0 '
+                + ' AND Rental_Apply_Equipment_Set__r.Yi_Assigned_Cnt__c > 0 '
+                + ' AND Shipment_request__c  = false'
+                + ' ORDER BY Rental_Apply_Equipment_Set__c, Id';
+        List<Rental_Apply_Equipment_Set_Detail__c> raesds = Database.query(soql);
+
+        Map<Id, List<String>> rental_Asset_SerialNumberMap = new Map<Id, List<String>>();
+
+        if (raesds.size() < 1) {
+            return '娌℃湁鍙互鍑哄簱鎸囩ず鐨勪竴瑙�';
+        } else {
+            Set<Id> raesSet = new Set<Id>();
+            String raesStrRequest = '';
+            for (Rental_Apply_Equipment_Set_Detail__c raesd : raesds) {
+                if (false == raesSet.contains(raesd.Rental_Apply_Equipment_Set__c)) {
+                    raesSet.add(raesd.Rental_Apply_Equipment_Set__c);
+                    raesStrRequest += raesd.Rental_Apply_Equipment_Set__c;
+                }
+                raesd.Shipment_request_time2__c = Datetime.now();
+                raesd.Shipment_request__c = true;
+            }
+            // 鍑哄簱鍚�, 鍐嶆鍋氬嚭搴撴寚绀虹殑涓�瑙�, 涓�瀹氳涓嚭杩囧簱鐨勪竴瑙堜竴鏍�
+            if (false == String.isBlank(raesStrShipped) && raesStrRequest != raesStrShipped) {
+                return '涓嶈兘鍋氬嚭搴撴寚绀猴紝闇�瑕佸垎鍗曞悗鍐嶆搷浣�';
+            }
+        }
+
+        // add lc 20220927 SFDC-CJ48VE 澶囧搧棰勮鍑哄簱鏃ラ�昏緫璋冩暣 start
+        List<Rental_Apply_Equipment_Set__c> RAESRecords = [
+                SELECT Id,Rental_Start_Date__c 
+                FROM Rental_Apply_Equipment_Set__c 
+                WHERE Rental_Apply__c = :raid
+                AND Cancel_Select__c = False];
+
+        for (Integer i = 0; i < RAESRecords.size(); i++) {
+            // 澶囧搧棰勮鍑哄簱鏃ヤ笉涓�鑷达紝涓嶅彲鍑哄簱鎸囩ず
+            if (RAESRecords[i].Rental_Start_Date__c != RAESRecords[0].Rental_Start_Date__c) {
+                return '澶囧搧棰勮鍑鸿揣鏃ヤ笉涓�鑷达紝涓嶅彲鍑哄簱鎸囩ず';
+            }
+        }
+        // add lc 20220927 SFDC-CJ48VE 澶囧搧棰勮鍑哄簱鏃ラ�昏緫璋冩暣 end
+
+        Rental_Apply__c ra = new Rental_Apply__c(Id = raesds[0].Rental_Apply__c, Status__c = '宸插嚭搴撴寚绀�');
+        update ra;
+        Database.SaveResult[] results = Database.update(raesds);
+        Database.SaveResult dmlResult = results[0];
+        if (dmlResult.isSuccess()) {
+            //鏄庣粏鏇存柊鎴愬姛鍚庢墠鏇存柊涓�瑙堢殑Rental_Asset_SerialNumber__c
+            soql = 'SELECT Id, SerialNumber_text__c, Rental_Apply_Equipment_Set__c '
+                    +'FROM Rental_Apply_Equipment_Set_Detail__c '
+                    +'WHERE Rental_Apply__c = \'' + raesds[0].Rental_Apply__c + '\''
+                    +'AND Shipment_request_time2__c != null '
+                    +'AND Shipment_request__c = true '
+                    +'AND SerialNumber_text__c != null '
+                    +'ORDER BY Rental_Apply_Equipment_Set__c ';
+
+
+            List<Rental_Apply_Equipment_Set_Detail__c> raesdSerialNumbers = Database.query(soql);
+
+            for (Rental_Apply_Equipment_Set_Detail__c raesd : raesdSerialNumbers) {
+
+                if (!rental_Asset_SerialNumberMap.containsKey(raesd.Rental_Apply_Equipment_Set__c)) {
+                    // Asset__r.SerialNumber + ','
+                    rental_Asset_SerialNumberMap.put(raesd.Rental_Apply_Equipment_Set__c, new List<String>());
+                }
+                rental_Asset_SerialNumberMap.get(raesd.Rental_Apply_Equipment_Set__c).add(raesd.SerialNumber_text__c);
+            }
+
+            List<Rental_Apply_Equipment_Set__c> raess = new List<Rental_Apply_Equipment_Set__c>();
+            for (Id key : rental_Asset_SerialNumberMap.keySet()) {
+                raess.add(new Rental_Apply_Equipment_Set__c(Id = key,
+                        Rental_Asset_SerialNumber__c = ',' + String.join(rental_Asset_SerialNumberMap.get(key), ',') + ','));
+            }
+            if (!raess.isEmpty()) {
+                update raess;
+            }
+
+            return '鐘舵�佹洿鏂板埌宸插嚭搴撴寚绀�';
+        } else {
+            Database.rollback(sp);
+            Database.Error emsg = dmlResult.getErrors()[0];
+            return 'failed to update:' + emsg.getFields() +  ' ' + emsg.getMessage();
+        }
+      } catch (Exception ex) {
+        Database.rollback(sp);
+        return ex.getMessage();
+      }
+    }
+    
+    @AuraEnabled
+    public static String postponeCheck(String endDate, Integer i) {
+        Date d=Date.valueOf(endDate);
+        // return 'OK1';S
+        Date selectDate;
+        if (d == Date.valueOf('4000-12-31')) {
+            selectDate=d;
+        } else if (i >= 0) {
+            List<OlympusCalendar__c> workday = [
+                    select Id, Date__c, IsWorkDay__c 
+                      from OlympusCalendar__c 
+                     where Date__c >= :d 
+                       and IsWorkDay__c = 1
+                     order by Date__c
+                     limit :(i+1)];
+            selectDate = workday[i].Date__c;
+            return 'OK1';
+            // if (Date.today() > selectDate) {
+            //     return System.Label.EquipmentRentalPostponeOverDeadline;
+            // }
+        } else {
+            i = Math.abs(i);
+            List<OlympusCalendar__c> workday = [
+                    select Id, Date__c, IsWorkDay__c 
+                      from OlympusCalendar__c 
+                     where Date__c <= :d 
+                       and IsWorkDay__c = 1
+                     order by Date__c desc
+                     limit :(i+1)];
+            selectDate = workday[i].Date__c;
+        }
+
+        if (Date.today() > selectDate) {
+            return System.Label.EquipmentRentalPostponeOverDeadline;
+        }
+        return 'OK';
+
+        // Date before5day = getWD_addday(date.parse(endDate), d);
+        // return 'OK2';
+        // if (Date.today() > before5day) {
+        //     return System.Label.EquipmentRentalPostponeOverDeadline;
+        // }
+        // return 'OK';
+    }
+
+    // public static Date getWD_addday(Date d, Integer i) {
+        
+    // }
+
+    @AuraEnabled
+    public static String submitApprovalRequest(String recordId) {
+        try{
+           Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
+           req.setObjectId(recordId);
+           Approval.ProcessResult result = Approval.process(req);
+           if(result.getErrors()!=null&&result.getErrors().size()>0)return result.getErrors().get(0).getMessage();
+        }catch(Exception e){
+            System.debug(' submitApprovalRequest  error: '+e.getMessage());
+            return e.getMessage();
+        }
+        return null;
+    }
+
+    public class UpdateResult {
+        @AuraEnabled public String recordId {get;set;}
+        @AuraEnabled public Boolean success {get;set;}
+        @AuraEnabled public List<String> errors {get;set;}
+    }
+    public class InitData{
+        @AuraEnabled
+        public String id;
+        @AuraEnabled
+        public String RentalApplyId;
+        @AuraEnabled
+        public String Status;
+        @AuraEnabled
+        public String RentalApplyC;
+        @AuraEnabled
+        public Decimal WeiAssignedCntC;
+        @AuraEnabled
+        public Date BollowDateC;
+        @AuraEnabled
+        public Decimal AssignedNotShipmentC;
+        @AuraEnabled
+        public List<String> statusList;
+    }
+}
\ No newline at end of file
diff --git a/force-app/main/default/classes/LexSelectSubstituteControllerLWT.cls-meta.xml b/force-app/main/default/classes/LexSelectSubstituteControllerLWT.cls-meta.xml
new file mode 100644
index 0000000..9662499
--- /dev/null
+++ b/force-app/main/default/classes/LexSelectSubstituteControllerLWT.cls-meta.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
+    <apiVersion>50.0</apiVersion>
+    <status>Active</status>
+</ApexClass>
\ No newline at end of file
diff --git a/force-app/main/default/lwc/lexSelectSubstitute/lexSelectSubstitute.js b/force-app/main/default/lwc/lexSelectSubstitute/lexSelectSubstitute.js
index 37846be..d081272 100644
--- a/force-app/main/default/lwc/lexSelectSubstitute/lexSelectSubstitute.js
+++ b/force-app/main/default/lwc/lexSelectSubstitute/lexSelectSubstitute.js
@@ -1,9 +1,9 @@
 import { LightningElement,api, track, wire } from 'lwc';
 import {CurrentPageReference} from 'lightning/navigation';
 import { CloseActionScreenEvent } from 'lightning/actions';
-import init from '@salesforce/apex/SelectSubstituteControllerLWT.initFromSelectSubstituteButton';
-import selectRentalApplyEquipmentSetByID from '@salesforce/apex/SelectSubstituteControllerLWT.selectRentalApplyEquipmentSetByID';
-import selectRentalApplyCByName from '@salesforce/apex/SelectSubstituteControllerLWT.selectRentalApplyCByName';
+import init from '@salesforce/apex/LexSelectSubstituteControllerLWT.initFromSelectSubstituteButton';
+import selectRentalApplyEquipmentSetByID from '@salesforce/apex/LexSelectSubstituteControllerLWT.selectRentalApplyEquipmentSetByID';
+import selectRentalApplyCByName from '@salesforce/apex/LexSelectSubstituteControllerLWT.selectRentalApplyCByName';
 
 export default class selectSubstituteLWC extends LightningElement {
 

--
Gitblit v1.9.1