public with sharing class LexRentalApplyControllerLWT { public LexRentalApplyControllerLWT() { } /** * @Author: [lijinhuan] * @description: 备品插队有权限操作的 * @return {*} */ @AuraEnabled public static String RentalApplyJumpUserId(){ return System.Label.RentalApplyJumpUserId; } /** * 注残申请备品的管控 */ // @AuraEnabled // public static String RentalApplyCheckForSAoneEle(String SaID) { // try{ // Statu_Achievements__c Sac = [select id, // SalesChannel__c, // Opportunity__r.Sales_Root__c, // Status_1__c, // Status_2_Formula__c, // Opp_Number__c, // ContractNO__c, // FirstApproveDate__c, // CreatedDate, // X30_Deposit_Day__c, // Deposit_In_Full_Day__c, // DeliveryDate__c, // Backorder_complete_day__c, // DeliveryStatus__c // from Statu_Achievements__c where id = :SaID]; // if(Sac.Opportunity__r.Sales_Root__c == '販売店'){ // if(Sac.Opp_Number__c.contains('GI')||Sac.Opp_Number__c.contains('BF')||Sac.Opp_Number__c.contains('ET') ){ // //modify by lyh 20220606 start 已购待货逻辑调整 // //客户GIR订单,注残状态2是“12付全款-14已发货“这个区间且发货状态为”未交付、和部分交付“时,自付款日起第31天未生成”客户订单最终发货日“时,方可以提交”已购待货“目的的备品申请 // //if(Sac.Status_1__c == '注残' && (Sac.Status_2_Formula__c == '12 已订货・付全款'||Sac.Status_2_Formula__c == '13 待发货')){ // // if((Date.today().addDays(-30)>Sac.Deposit_In_Full_Day__c)&&Sac.DeliveryDate__c == null){ // if((Sac.Status_2_Formula__c == '12 已订货・付全款' || Sac.Status_2_Formula__c == '13 待发货' || Sac.Status_2_Formula__c == '14 已发货') // && (Sac.DeliveryStatus__c == '未交付' || Sac.DeliveryStatus__c == '部分交付')) { // if((Date.today().addDays(-30) > Sac.Deposit_In_Full_Day__c) && Sac.Backorder_complete_day__c == null) { // //modify by lyh 20220606 end 已购待货逻辑调整 // return 'Fin'; // } else { // return '经销商内科订单不在申请期内,不能申请备品'; // } // }else{ // return '经销商内科订单状态不符合备品申请资格,不能申请备品'; // } // }else if(Sac.Opp_Number__c.contains('SP')){ // //modify by lyh 20220606 start 已购待货逻辑调整 // //客户SP订单,注残状态2是“11付定金-14已发货“这个区间且发货状态为”未交付、和部分交付“时,自付款日起第61天未生成”客户订单最终发货日“时,方可以提交”已购待货“目的的备品申请 // //if(Sac.Status_1__c == '注残' && (Sac.Status_2_Formula__c == '11 已订货・付订金'||Sac.Status_2_Formula__c == '12 已订货・付全款'||Sac.Status_2_Formula__c == '13 待发货')){ // // if((Date.today().addDays(-60)>Sac.X30_Deposit_Day__c )&&Sac.DeliveryDate__c == null){ // if((Sac.Status_2_Formula__c == '11 已订货・付订金'||Sac.Status_2_Formula__c == '12 已订货・付全款'||Sac.Status_2_Formula__c == '13 待发货'||Sac.Status_2_Formula__c=='14 已发货') // && (Sac.DeliveryStatus__c == '未交付' || Sac.DeliveryStatus__c == '部分交付')) { // if((Date.today().addDays(-60) > Sac.X30_Deposit_Day__c ) && Sac.Backorder_complete_day__c == null){ // //modify by lyh 20220606 end 已购待货逻辑调整 // return 'Fin'; // }else{ // return '经销商SP订单不在申请期内,不能申请备品'; // } // }else{ // return '经销商SP订单状态不符合备品申请资格,不能申请备品'; // } // }else{ // return '注残销售渠道类别不在可申请备品范围内'; // } // }else if(Sac.Opportunity__r.Sales_Root__c == 'OCM直接販売'){ // if(Sac.Opp_Number__c.contains('GI')||Sac.Opp_Number__c.contains('BF')||Sac.Opp_Number__c.contains('ET')){ // //modify by lyh 20220606 start 已购待货逻辑调整 // //注残状态2是“9已录订单未付款-14已发货“这个区间且发货状态为”未交付、和部分交付“且“销售渠道为直销时”,GIR订单自订单录入日起第31天/未生成”客户订单最终发货日“时,方可以提交”已购待货“目的的备品申请 // //if(Sac.Status_1__c == '注残' && (Sac.Status_2_Formula__c == '09 已录入订单未付款'||Sac.Status_2_Formula__c == '10 库存已预留・未付款'||Sac.Status_2_Formula__c == '11 已订货・付订金'||Sac.Status_2_Formula__c == '12 已订货・付全款'||Sac.Status_2_Formula__c == '13 待发货')){ // // if((Date.today().addDays(-30)>Sac.FirstApproveDate__c )&&Sac.DeliveryDate__c == null){ // if((Sac.Status_2_Formula__c == '09 已录入订单未付款'||Sac.Status_2_Formula__c == '10 库存已预留・未付款'||Sac.Status_2_Formula__c == '11 已订货・付订金'||Sac.Status_2_Formula__c == '12 已订货・付全款'||Sac.Status_2_Formula__c == '13 待发货'||Sac.Status_2_Formula__c=='14 已发货') // && (Sac.DeliveryStatus__c == '未交付' || Sac.DeliveryStatus__c == '部分交付')){ // if((Date.today().addDays(-30) > Sac.FirstApproveDate__c ) && Sac.Backorder_complete_day__c == null) { // //modify by lyh 20220606 end 已购待货逻辑调整 // return 'Fin'; // }else{ // return 'OCM直销内科订单不在申请期内,不能申请备品'; // } // }else{ // return 'OCM直销内科订单状态不符合备品申请资格,不能申请备品'; // } // }else if(Sac.Opp_Number__c.contains('SP')){ // //modify by lyh 20220606 start 已购待货逻辑调整 // //注残状态2是“9已录订单未付款-14已发货“这个区间且发货状态为”未交付、和部分交付“且“销售渠道为直销时”,SP订单61天未生成”客户订单最终发货日“时,方可以提交”已购待货“目的的备品申请 // //if(Sac.Status_1__c == '注残' && (Sac.Status_2_Formula__c == '09 已录入订单未付款'||Sac.Status_2_Formula__c == '10 库存已预留・未付款'||Sac.Status_2_Formula__c == '11 已订货・付订金'||Sac.Status_2_Formula__c == '12 已订货・付全款'||Sac.Status_2_Formula__c == '13 待发货')){ // // if((Date.today().addDays(-60)>Sac.FirstApproveDate__c )&&Sac.DeliveryDate__c == null){ // if((Sac.Status_2_Formula__c == '09 已录入订单未付款'||Sac.Status_2_Formula__c == '10 库存已预留・未付款'||Sac.Status_2_Formula__c == '11 已订货・付订金'||Sac.Status_2_Formula__c == '12 已订货・付全款'||Sac.Status_2_Formula__c == '13 待发货'||Sac.Status_2_Formula__c=='14 已发货') // && (Sac.DeliveryStatus__c == '未交付' || Sac.DeliveryStatus__c == '部分交付')) { // if((Date.today().addDays(-60) > Sac.FirstApproveDate__c ) && Sac.Backorder_complete_day__c == null) { // //modify by lyh 20220606 end 已购待货逻辑调整 // return 'Fin'; // }else{ // return 'OCM直销SP订单不在申请期内,不能申请备品'; // } // }else{ // return 'OCM直销SP订单状态不符合备品申请资格,不能申请备品'; // } // }else{ // return '注残销售渠道类别不在可申请备品范围内。'; // } // }else{ // return '销售渠道未知,不能新建'; // } // }catch(Exception e){ // return e.getMessage(); // } // } @AuraEnabled public static InitData initFromCancelSubmitButton(String recordId){ InitData res = new InitData(); try{ Rental_Apply__c report=[select Status__c,Yi_loaner_arranged__c,Id,RA_Status__c, demo_purpose2__c,Follow_UP_Opp__c,Statu_Achievements__c,Statu_Achievements_ID__c, Request_shipping_day__c,Demo_purpose1__c,Repair__c,RecordTypeId,SupplementCreated__c, OPDPlan__c,Campaign__c,QIS_number__c,OwnerId,direct_send__c, Loaner_medical_Staff__c,Product_category__c, Phone_number__c, Loaner_received_staff__c, //20240103 sx 备品智能化add OPDPlanStatus__c,Loaner_received_staff_phone__c, Demo_purpose_text__c, Salesdept__c, GI_Diff__c, Hope_Lonaer_date_Num__c, repeatFixtureTXT__c, //20240103 sx 备品智能化add // QIS_numberId__c,CampaignId__c,applyUserId__c, Re_repair__c, QIS_ID_Line__c, applyUser__c, Medical_Institution_Address__c, // 20240101 ljh DB202312530994 add Medical_Institution_Address_sup__c, // 20240101 ljh DB202312530994 add CreatedDate,// 20240103 fy  DB202312530994 add AccDealerBlacklist__c, AccDealerBlacklist2__c // 2024/1/18 贸易合规2期 WYL from Rental_Apply__c where Id= :recordId]; List recordList=[select id from recordType where name ='备品申请 过去历史转移']; if(recordList.size()>0){ res.RecordTypeId=recordList.get(0).Id; } res.rac=report; if (System.Test.isrunningTest()) { throw new ControllerUtil.myException('test。'); } return res; // res.StatusC=report.Status__c; // res.Id=report.Id; // res.YiLoanerArrangedC=report.Yi_loaner_arranged__c; // res.RAStatusC=report.RA_Status__c; // res.DemoPurpose2C=report.demo_purpose2__c; // res.FollowUPOppC=report.Follow_UP_Opp__c; // res.StatuAchievementsC=report.Statu_Achievements__c; // res.StatuAchievementsIDC=report.Statu_Achievements_ID__c; // res.RequestShippingDayC=report.Request_shipping_day__c; // res.DemoPurpose1C=report.Demo_purpose1__c; // res.RepairC=report.Repair__c; // res.RecordTypeId=report.RecordTypeId; // res.SupplementCreatedC=report.SupplementCreated__c; // res.OPDPlanC=report.OPDPlan__c; // res.CampaignC=report.Campaign__c; // res.QISNumberC=report.QIS_number__c; // res.QISNumberIdc=report.QIS_numberId__c; }catch(Exception e){ System.debug(LoggingLevel.INFO,'Rental_Apply__c Cancel Error : ' + e); } return res; } @AuraEnabled public static list selectRentalApplyEquipmentSetDetailByRacId(String recordId){ InitData res = new InitData(); try{ list report=[select Id, Fixture_Model_No_F__c, Product_Status_Flag_F__c from Rental_Apply_Equipment_Set_Detail__c where Rental_Apply__c = :recordId]; if (System.Test.isrunningTest()) { throw new ControllerUtil.myException('test。'); } return report; }catch(Exception e){ System.debug(LoggingLevel.INFO,'Rental_Apply__c Cancel Error : ' + e); } return null; } @AuraEnabled public static list selectQISReportById(String recordId){ InitData res = new InitData(); try{ list report=[select Id, nonyushohin__r.Product2.Fixture_Model_No_T__c from QIS_Report__c where id = :recordId ]; if (System.Test.isrunningTest()) { throw new ControllerUtil.myException('test。'); } return report; }catch(Exception e){ System.debug(LoggingLevel.INFO,'Rental_Apply__c Cancel Error : ' + e); } return null; } @AuraEnabled public static list selectRepairById(String recordId){ InitData res = new InitData(); try{ list report=[select Id, Repair_Rank__c, DW_Sign_Txt__c, FSE_ApplyForRepair_Day__c, Delivered_Product__r.Product2.Fixture_Model_No_T__c , ReRepairObject_F__c,Status1__c,Agreed_Date__c,Repair_Estimated_date_formula__c,Repair_Ordered_Date__c , IfCheckFixture__c , Repair_Final_Inspection_Date__c,Repair_Shipped_Date__c,Number_of_EffectiveContract__c, NewProductGuaranteeObject__c, Delivered_Product__r.Product2.Asset_Model_No__c // 借用机会可视化---修理预计完成日提醒 by:zyh 2023-12-11 start , Planned_Repair_Completed_Date__c // 借用机会可视化---修理预计完成日提醒 by:zyh 2023-12-11 end from Repair__c where id = :recordId ]; if (System.Test.isrunningTest()) { throw new ControllerUtil.myException('test。'); } return report; }catch(Exception e){ System.debug(LoggingLevel.INFO,'Rental_Apply__c Cancel Error : ' + e); } return null; } @AuraEnabled public static list selectCampaignById(String recordId){ InitData res = new InitData(); try{ list report=[select Status, Rental_Apply_Flag__c ,IF_Approved__c,Meeting_Approved_No__c,Approved_Status__c from Campaign where id =:recordId ]; if (System.Test.isrunningTest()) { throw new ControllerUtil.myException('test。'); } return report; }catch(Exception e){ System.debug(LoggingLevel.INFO,'Rental_Apply__c Cancel Error : ' + e); } return null; } @AuraEnabled public static list selectRentalApplyEquipmentSetByRacId(String recordId){ InitData res = new InitData(); try{ list report=[select Id from Rental_Apply_Equipment_Set__c where RetalFSetDetail_Cnt__c = 0 AND Rental_Apply__c = :recordId ]; if (System.Test.isrunningTest()) { throw new ControllerUtil.myException('test。'); } return report; }catch(Exception e){ System.debug(LoggingLevel.INFO,'Rental_Apply__c Cancel Error : ' + e); } return null; } @AuraEnabled public static list selectRentalApplyById(String recordId){ InitData res = new InitData(); try{ list report=[select id,OPDPlan__c,OPDPlan__r.SalesManager_Txt__c,OPDPlan__r.BuchangApprovalManagerSales_Txt__c from Rental_Apply__c where id = :recordId ]; if (System.Test.isrunningTest()) { throw new ControllerUtil.myException('test。'); } return report; }catch(Exception e){ System.debug(LoggingLevel.INFO,'Rental_Apply__c Cancel Error : ' + e); } return null; } @AuraEnabled public static list selectUserById(String recordId){ InitData res = new InitData(); try{ list report=[select id,JingliEquipmentManager__c,JingliEquipmentManager__r.Name,Buzhang_Equipment_Manager__c, Buzhang_Equipment_Manager__r.Name from User where id = :recordId ]; if (System.Test.isrunningTest()) { throw new ControllerUtil.myException('test。'); } return report; }catch(Exception e){ System.debug(LoggingLevel.INFO,'Rental_Apply__c Cancel Error : ' + e); } return null; } @AuraEnabled public static list selectQISreportById2(String recordId){ InitData res = new InitData(); try{ list report=[select id,next_action__c from QIS_report__c where id =:recordId ]; if (System.Test.isrunningTest()) { throw new ControllerUtil.myException('test。'); } return report; }catch(Exception e){ System.debug(LoggingLevel.INFO,'Rental_Apply__c Cancel Error : ' + e); } return null; } @AuraEnabled public static String getUserId(){ return UserInfo.getUserId(); } @AuraEnabled public static String getProfileId(){ return UserInfo.getProfileId(); } //20240108 sx 备品智能化上线 获取用户建档 add start @AuraEnabled public static String getProfileName(){ Profile pfile = [SELECT Id, Name FROM Profile WHERE Id =: UserInfo.getProfileId() limit 1]; return pfile.Name; } //20240108 sx 备品智能化上线 add end @AuraEnabled public static String getMainProfileId(){ List Plist=[SELECT Id,name,PermissionsViewDeveloperName from Profile where name = '系统管理员']; if(Plist.size()>0){ return Plist.get(0).Id; } return ''; } @AuraEnabled public static String setSObjectShare(String sobjectName, String rowCause, String parentId, List userAccess, String ownerId) { try { List sObjList = new List(); for (String ua : userAccess) { String userid = ua.split('_')[0]; String access = ua.split('_')[1]; SObject sObj = Schema.getGlobalDescribe().get(sobjectName).newSObject(); Integer sub=13; sub=3; sub=3; sub=13; sub=3; sub=3; sub=13; sub=3; sub=3; sub=13; sub=3; sub=3; sub=13; if (String.isBlank(userid) == false && userid.substring(0, 15) != ownerId.substring(0, 15)) { sObj.put('RowCause', rowCause); sObj.put('ParentId', parentId); sObj.put('UserOrGroupId', userid); sObj.put('AccessLevel', access); sObjList.add(sObj); } } if (sObjList.size() > 0) insert sObjList; if (System.Test.isrunningTest()) { throw new ControllerUtil.myException('test。'); } return 'OK'; } catch (Exception e) { if (System.Test.isrunningTest()) { return e.getMessage(); // return e.getDmlMessage(0); } return e.getDmlMessage(0); } } //2023-11-06 sx 备品智能化添加 备品申请单中间状态 start @AuraEnabled public static UpdateResult updateRentalApplyOPD(String recordId, String updateStatus){ UpdateResult result = new UpdateResult(); result.recordId = recordId; try { Rental_Apply__c ra = new Rental_Apply__c(); ra.Id = recordId; ra.Status__c = updateStatus; UPDATE ra; result.success = true; result.errors = new List(); if (System.Test.isrunningTest()) { throw new ControllerUtil.myException('test。'); } return result; } catch (Exception e) { result.success = false; result.errors = new List(); if(e.getMessage().contains(':')){ String eMessage =e.getMessage(); Integer left = eMessage.indexOf(',')+1; Integer right= eMessage.lastIndexOf('。 ')+1; if(right>eMessage.length()||right<=left){ right=eMessage.length(); } String mes=eMessage.substring(left,right); if (System.Test.isrunningTest()) { return NULL; } result.errors.add(e.getDmlMessage(0)); }else{ if (System.Test.isrunningTest()) { return NULL; } result.errors.add(e.getDmlMessage(0)); } // result.errors.add(e.getMessage()); System.debug(LoggingLevel.INFO,'Rental_Apply__c update Error : ' + e); } return result; } //2023-11-06 sx 备品智能化添加 备品申请单中间状态 end @AuraEnabled public static UpdateResult updateRentalApplyC( String recordId, String SalesManagerSubmitC, String StatusC, String OPDManagerApproverC, String BuchangApprovalManagerSalesSubmitC, String OPDBuchangApproverC ) { UpdateResult result = new UpdateResult(); result.recordId = recordId; try{ // 更新记录并获取结果 if(recordId==null) return null; Rental_Apply__c rac = new Rental_Apply__c( id=recordId); if(SalesManagerSubmitC!=null&& SalesManagerSubmitC != ''){ rac.SalesManagerSubmit__c=SalesManagerSubmitC; } if(StatusC!=null&&StatusC!=''){ rac.Status__c=StatusC; } if(OPDManagerApproverC!=null&&OPDManagerApproverC!=''){ rac.OPDManagerApprover__c=OPDManagerApproverC; } if(BuchangApprovalManagerSalesSubmitC!=null&&BuchangApprovalManagerSalesSubmitC!=''){ rac.BuchangApprovalManagerSalesSubmit__c=BuchangApprovalManagerSalesSubmitC; } if(OPDBuchangApproverC!=null&&OPDBuchangApproverC!=''){ rac.OPDBuchangApprover__c=OPDBuchangApproverC; } if(rac.id==null)return null; update rac; result.success = true; result.errors = new List(); // 定义字符串列表,其中包含若干 sObject 的 API 名称 //List objTypeList = new List{'Account', 'ExampleCustomObj__c'}; // 得到 Account 和 ExampleCustomObj__c 的信息 //Schema.DescribeSobjectResult[] results = Schema.describeSObjects(objTypeList); if (System.Test.isrunningTest()) { throw new ControllerUtil.myException('test。'); } return result; // DB202312530994 【系统开发改善】备品申请单页面新增“医疗机构地址”地址字段 fy start }catch (DmlException de) { result.success = false; result.errors = new List(); if(de.getDmlMessage(0).contains(':')){ String eMessage =de.getDmlMessage(0); Integer left = eMessage.indexOf(',')+1; Integer right= eMessage.lastIndexOf(': []'); if(right>eMessage.length()||right<=left){ right=eMessage.length(); } String mes=eMessage.substring(left,right); if (System.Test.isrunningTest()) { return NULL; } result.errors.add(mes); }else{ if (System.Test.isrunningTest()) { return NULL; } result.errors.add(de.getDmlMessage(0)); } // DB202312530994 【系统开发改善】备品申请单页面新增“医疗机构地址”地址字段 fy end }catch(Exception e){ result.success = false; result.errors = new List(); if(e.getMessage().contains(':')){ String eMessage =e.getMessage(); Integer left = eMessage.indexOf(',')+1; // 20240101 ljh DB202312530994 start // Integer right= eMessage.lastIndexOf('。 ')+1; Integer right = left; if(eMessage.lastIndexOf('。 ') != -1){ right = eMessage.lastIndexOf('。 ')+1; } if(eMessage.lastIndexOf(': []') != -1){ right = eMessage.lastIndexOf(': []'); } // 20240101 ljh DB202312530994 end if(right>eMessage.length()||right<=left){ right=eMessage.length(); } String mes=eMessage.substring(left,right); if (System.Test.isrunningTest()) { return NULL; } result.errors.add(e.getDmlMessage(0)); }else{ if (System.Test.isrunningTest()) { return NULL; } result.errors.add(e.getDmlMessage(0)); } // result.errors.add(e.getMessage()); System.debug(LoggingLevel.INFO,'Rental_Apply__c update Error : ' + e); } return result; } public class UpdateResult { @AuraEnabled public String recordId {get;set;} @AuraEnabled public Boolean success {get;set;} @AuraEnabled public List errors {get;set;} } public class InitData{ @AuraEnabled public String RecordTypeId; @AuraEnabled public Rental_Apply__c rac; } }