public without sharing class otherButtonMaintenanceContractCtl { @AuraEnabled public static InitData init(String recordId){ InitData res = new initData(); String reportId = ''; List reportTmpt = [select Id,DeveloperName from Report where DeveloperName = 'SLAReportDetail']; if(reportTmpt.size()>0) { reportId = reportTmpt[0].Id; } try{ RecordType re = [select id from RecordType where name = '服务合同']; res.newMcRecordType = re.Id; Maintenance_Contract__c report = [SELECT Hospital__c,Department_Class__c,Department__c,Service_Contract_Staff__c, Service_contract_target_number__c, PB_Contrant_Cnt__c, PA_Contrant_Cnt__c, Contract_Conclusion_Date__c, Contract_Start_Date__c, Estimate_Trial_Money__c, Contract_End_Date__c, Receipt_Date__c, Recycling_Predetermined_Day__c, Contract_Amount__c, Collect_Date__c, Recoverable_Amount__c, Not_collect_money__c, Sum_repair_price__c, invoice_amount__c, Total_not_collect_amount__c, Description__c, OCM_Print_request__c, HP_Dealer_print__c, // Contract_print_completed__c, Submit_contract_to_Financial_dept__c, Received_Date__c, Repair_Cost_Sum__c, // Maintenance_Contract_No__c, Last_year_service_contract__c, UserType__c, MaintanceContractPack__c,Decided_Estimation__c,Estimation_Id__c,URF_Contract__c,RecordTypeId,Is_RecognitionModel__c,Status__c,MC_approval_status__c,Payment_Plan_Sum_First__c, Contract_quotation_or_not__c,Name,notRenew__c,Contract_print_completed__c,Maintenance_Contract_No__c, upload_to_sap_time__c,old_Is_RecognitionModel__c,upload_to_RM_time__c,Is_Recognition_Model_True__c, Id,URF_Contract_F__c,RecordType_DeveloperName__c,Estimate_Target__c,AccDealerBlacklist__c FROM Maintenance_Contract__c WHERE Id =: recordId LIMIT 1]; System.debug(LoggingLevel.INFO, '*** opp: ' + report); res.EstimationIdIdC = report.Estimation_Id__c; res.DecidedEstimationC = report.Decided_Estimation__c; res.StatusC = report.Status__c; res.IsRecognitionModelC = report.Is_RecognitionModel__c; res.RecordTypeId = report.RecordTypeId; res.URFContractC = report.URF_Contract__c; res.MCApprovalStatusC = report.MC_approval_status__c; res.MaintenanceContractNoC = report.Maintenance_Contract_No__c; res.uploadToSapTimeC = report.upload_to_sap_time__c; res.oldIsRecognitionModelC = report.old_Is_RecognitionModel__c; res.uploadToRMTimeC = report.upload_to_RM_time__c; res.IsRecognitionModelTrueC = report.Is_Recognition_Model_True__c; res.Id = report.Id; res.URFContractFC = report.URF_Contract_F__c; res.RecordTypeDeveloperNameC = report.RecordType_DeveloperName__c; res.EstimateTargetC = report.Estimate_Target__c; res.ContractprintCompletedC = report.Contract_print_completed__c; res.notRenewC = report.notRenew__c; res.Name = report.Name; res.ContractQuotationOrNotC = report.Contract_quotation_or_not__c; res.PaymentPlanSumFirstC = report.Payment_Plan_Sum_First__c; res.reportId = reportId; //zzm 230816 报价合并 start --打包合同下的小合同只能去打包合同上进行合同复核 res.MaintanceContractPackC = report.MaintanceContractPack__c; //zzm 230816 报价合并 end --打包合同下的小合同只能去打包合同上进行合同复核 //贸易合规 zzm 230829 start res.accDealerBlacklist = report.AccDealerBlacklist__c; //贸易合规 zzm 230829 end res.hospital = report.Hospital__c; res.department_Class = report.Department_Class__c; res.department = report.Department__c; res.service_Contract_Staff = report.Service_Contract_Staff__c; res.Service_contract_target_number = report.Service_contract_target_number__c; res.PB_Contrant_Cnt = report.PB_Contrant_Cnt__c; res.PA_Contrant_Cnt = report.PA_Contrant_Cnt__c; res.Contract_Conclusion_Date = report.Contract_Conclusion_Date__c; res.Contract_Start_Date = report.Contract_Start_Date__c; res.Estimate_Trial_Money = report.Estimate_Trial_Money__c; res.Contract_End_Date = report.Contract_End_Date__c; res.Receipt_Date = report.Receipt_Date__c; res.Recycling_Predetermined_Day = report.Recycling_Predetermined_Day__c; res.Contract_Amount = report.Contract_Amount__c; res.Collect_Date = report.Collect_Date__c; res.Recoverable_Amount = report.Recoverable_Amount__c; res.Not_collect_money = report.Not_collect_money__c; res.Sum_repair_price = report.Sum_repair_price__c; res.invoice_amount = report.invoice_amount__c; res.Total_not_collect_amount = report.Total_not_collect_amount__c; res.Description = report.Description__c; res.OCM_Print_request = report.OCM_Print_request__c; res.HP_Dealer_print = report.HP_Dealer_print__c; res.Contract_print_completed = report.Contract_print_completed__c; res.Submit_contract_to_Financial_dept = report.Submit_contract_to_Financial_dept__c; res.Received_Date = report.Received_Date__c; res.Repair_Cost_Sum = report.Repair_Cost_Sum__c; res.Maintenance_Contract_No = report.Maintenance_Contract_No__c; res.Last_year_service_contract = report.Last_year_service_contract__c; res.UserType = report.UserType__c; //20231120 sx add 贸易合规二期 start // res.hosTradeComplianceStatus = report.Hospital__r.TradeComplianceStatus__c; // res.dealTradeComplianceStatus = report.Dealer__r.TradeComplianceStatus__c; List mcaListtemp = [SELECT Id, Asset__r.product2.CountryOfOrigin__c, Asset__r.product2.USRatio_US__c, Asset__r.product2.ProTradeComplianceStatus__c,Asset__r.product2.Asset_Model_No__c FROM Maintenance_Contract_Asset__c WHERE Maintenance_Contract__c = :recordId]; String violationName = ''; if(mcaListtemp.size() > 0){ for(Maintenance_Contract_Asset__c mac : mcaListtemp){ if(mac.Asset__r.product2.ProTradeComplianceStatus__c == '0'){ res.proTradeComplianceStatus = '0'; violationName += mac.Asset__r.product2.Asset_Model_No__c+','; } } }else{ res.proTradeComplianceStatus = '1'; } res.violationName = violationName; //20231120 sx add 贸易合规二期 end System.debug(LoggingLevel.INFO, '*** res: ' + res); }catch(Exception e){ System.debug(LoggingLevel.INFO, '*** e: ' + e); } return res; } @AuraEnabled public static String updateFirstContract(String mcid ){ List mcList = [select id, Effective_Status__c,Status__c,upload_to_sap_time__c from Maintenance_Contract__c where id = :mcid ]; if (mcList.size() == 0) { return '维修合同不存在,请确认维修合同ID。'; } try{ Maintenance_Contract__c mc = mcList[0]; List mcaList = [select id,Maintenance_Contract__r.Contract_Start_Date__c,Maintenance_Contract__r.Contract_End_Date__c,Maintenance_Contract__r.Maintenance_Contract_No__c,Asset__r.name,Asset__r.id,asset__r.First_Service_number__c,asset__r.First_Service_Start_Day__c,asset__r.First_Service_End_Day__c from Maintenance_Contract_Asset__c where Maintenance_Contract__c = :mc.id]; List assList = new List(); if (mc.Effective_Status__c =='有效' && mc.Status__c =='契約'&&mc.upload_to_sap_time__c==null && mcaList!= null) { for (Maintenance_Contract_Asset__c mca:mcaList) { Asset ass = new Asset(); ass.id = mca.asset__r.id; if (mca.asset__r.First_Service_number__c == null) { ass.First_Service_number__c = mca.Maintenance_Contract__r.Maintenance_Contract_No__c; } if (mca.asset__r.First_Service_End_Day__c == null) { ass.First_Service_End_Day__c = mca.Maintenance_Contract__r.Contract_End_Date__c; } if (mca.asset__r.First_Service_Start_Day__c == null) { ass.First_Service_Start_Day__c = mca.Maintenance_Contract__r.Contract_Start_Date__c; } assList.add(ass); } } if (assList.size()>0 && !Test.isRunningTest()) { update assList; } }catch(Exception e){ return e.getMessage(); // return e.getDmlMessage(0); } return '1'; } // 维修合同失单报告 @AuraEnabled public static List selectRecords(String mcId){ List res = new List(); try{ res = [SELECT Id,Status__c,Other_Reasons__c,Other__c,Third_Party_Company__c,Third_Party_Contract_Price__c,To_Where__c,Specific_Reasons__c,Maintenance_Contract__c from Lost_Report__c where Maintenance_Contract__c =: mcId ]; }catch(Exception e){ System.debug(LoggingLevel.INFO, '*** e: ' + e); } return res; } // 查找维修合同报价 @AuraEnabled public static List selectMaintenanceContractEstimate(String recordId){ List res = new List(); try{ res = [SELECT Id from Maintenance_Contract_Estimate__c where Maintenance_Contract__c=:recordId]; }catch(Exception e){ System.debug(LoggingLevel.INFO, '*** e: ' + e); } return res; } // 工作流状态 @AuraEnabled public static String processResults(String recordId){ try{ Approval.ProcessSubmitRequest psr = new Approval.ProcessSubmitRequest(); psr.setobjectid(recordId); Approval.ProcessResult submitResult = Approval.process(psr); return '1'; } catch(Exception e) { return e.getMessage(); // return e.getDmlMessage(0); } } //1.要求: 将当前合同信息更新到当前合同下的`上一期维修合同`中的`来年合同`中 ///实现 ///1.获取当前合同信息 1).记录类型 2)保有设备 ///2.获取当前合同下的保有设备下的`上一期维修合同`信息 条件1`空白期小于等于365天,条件2`上一期维修合同不为空 ///3.设置该`上一期维修合同`的`来年合同`为当前合同 条件1` 如果当前合同的记录类型为`服务合同`,则更新`上一期维修合同`中的来年服务合同字段,(维修合同同上 //用户点击上传SAP按钮,更新'来年服务合同'/'来年维修合同' @AuraEnabled public static String updateColunm(String mcid ){ //当前维修合同 Maintenance_Contract__c newMcc = [select id,name,RecordTypeId,Contract_Start_Date__c from Maintenance_Contract__c where Id = :mcid]; //1. 获取当前合同的记录类型 RecordType rt = [select Name from RecordType where id = :newMcc.RecordTypeId]; //1. 获取当前合同下的所有符合更改条件的保有设备 List temp = [ select Id,LastMContract__c,LastMContract_Gap__c from Maintenance_Contract_Asset__c where Maintenance_Contract__c = :mcid ]; if (temp.size() == 0) { return '1'; } //1. 获取保有设备下的合同信息 List lastMcIds = new List(); for(Maintenance_Contract_Asset__c mcac : temp){ if (mcac.LastMContract__c != null) { if (mcac.LastMContract_Gap__c <= 365) { lastMcIds.add(mcac.LastMContract__c); } } } List lastMcc = [select id,name,RecordTypeId,Contract_Start_Date__c,serviceContractNextYear_new__c,contractNextYear_new__c from Maintenance_Contract__c where Id in :lastMcIds]; Map mmap = new Map(); if (rt.Name.equals('服务合同')) { for(Maintenance_Contract__c mcc : lastMcc){ Maintenance_Contract__c mc = new Maintenance_Contract__c(); mc.Id = mcc.Id; mc.serviceContractNextYear_new__c = mcid; mmap.put(mcc.Id,mc); } }else if (rt.Name.equals('维修合同')) { for(Maintenance_Contract__c mcc : lastMcc){ Maintenance_Contract__c mc = new Maintenance_Contract__c(); mc.Id = mcc.Id; mc.serviceContractNextYear_new__c = mcid; mc.contractNextYear_new__c = mcid; mmap.put(mcc.Id,mc); } } try { if (!Test.isRunningTest()) { update mmap.values(); } } catch (Exception e) { return E.getMessage(); // return e.getDmlMessage(0); } return '1'; } /* @AuraEnabled public static String initCustomNewCopy2(String recordId){ String s=''; try { String objectName = 'Maintenance_Contract__c'; // 要获取字段的对象名 Map globalDescribe = Schema.getGlobalDescribe(); Schema.SObjectType objType = globalDescribe.get(objectName); if (objType != null) { Schema.DescribeSObjectResult objDescribe = objType.getDescribe(); Map fieldMap = objDescribe.fields.getMap(); s+='SELECT '; // 现在,fieldMap中包含了对象的所有字段信息 for (String fieldName : fieldMap.keySet()) { if(!fieldName.equals('id') &&!fieldName.equals('Id')) s+=fieldName+','; } s=s.removeEnd(','); s+=' FROM Maintenance_Contract__c where id=\''+recordId+'\''; system.debug('SQL:'+s); List opportunitys = Database.query(s); s=''; if(opportunitys.size()>0){ system.debug('in!'); for (String fieldName : fieldMap.keySet()) { String formaF=fieldMap.get(fieldName).getDescribe().getName(); if(opportunitys.get(0).get(fieldName)!=null&&!opportunitys.get(0).get(fieldName).equals('null')){ if(formaF.equals('Id') ||formaF.equals('OwnerId') ||formaF.equals('CreatedDate') ||formaF.equals('CreatedById') ) { continue; } Object val=opportunitys.get(0).get(fieldName); if(val instanceof Date ){ String str=String.valueOf(val); str=str.replace(' ','T'); str+='.000Z'; s+=formaF+'='+str+','; }else if (val instanceof DateTime){ String str=String.valueOf(val); str=str.replace(' ','T'); str+='.000Z'; s+=formaF+'='+str+','; }else{ s+=formaF+'='+opportunitys.get(0).get(fieldName)+','; } } } s=s.removeEnd(','); return s; } } return s; } catch (Exception e) { System.debug('lexCopyToBaseController init error:'+e.getMessage()); } return s; }*/ public class InitData{ @AuraEnabled public String DecidedEstimationC; @AuraEnabled public String EstimationIdIdC; @AuraEnabled public String MCApprovalStatusC; @AuraEnabled public String MaintenanceContractNoC; @AuraEnabled public Datetime uploadToSapTimeC; @AuraEnabled public Boolean oldIsRecognitionModelC; @AuraEnabled public Datetime uploadToRMTimeC; @AuraEnabled public Boolean IsRecognitionModelTrueC; @AuraEnabled public String Id; @AuraEnabled public String URFContractFC; @AuraEnabled public String RecordTypeDeveloperNameC; @AuraEnabled public String EstimateTargetC; @AuraEnabled public Datetime ContractprintCompletedC; @AuraEnabled public Boolean notRenewC; @AuraEnabled public String Name; @AuraEnabled public String ContractQuotationOrNotC; @AuraEnabled public Double PaymentPlanSumFirstC; @AuraEnabled public String StatusC; @AuraEnabled public Boolean IsRecognitionModelC; @AuraEnabled public String RecordTypeId; @AuraEnabled public Boolean URFContractC; @AuraEnabled public ID RecordTypeId1; @AuraEnabled public String reportId; @AuraEnabled public String MaintanceContractPackC; @AuraEnabled public String accDealerBlacklist; @AuraEnabled public Id hospital; @AuraEnabled public Id department_Class; @AuraEnabled public Id department; @AuraEnabled public Id service_Contract_Staff; @AuraEnabled public String newMcRecordType; @AuraEnabled public Decimal Service_contract_target_number; @AuraEnabled public Decimal PB_Contrant_Cnt; @AuraEnabled public Decimal PA_Contrant_Cnt; @AuraEnabled public Date Contract_Conclusion_Date; @AuraEnabled public Date Contract_Start_Date; @AuraEnabled public Decimal Estimate_Trial_Money; @AuraEnabled public Date Contract_End_Date; @AuraEnabled public Date Receipt_Date; @AuraEnabled public Date Recycling_Predetermined_Day; @AuraEnabled public Decimal Contract_Amount; @AuraEnabled public Date Collect_Date; @AuraEnabled public Decimal Recoverable_Amount; @AuraEnabled public Decimal Not_collect_money; @AuraEnabled public Decimal Sum_repair_price; @AuraEnabled public Decimal invoice_amount; @AuraEnabled public Decimal Total_not_collect_amount; @AuraEnabled public String Description; @AuraEnabled public Date OCM_Print_request; @AuraEnabled public Date HP_Dealer_print; @AuraEnabled public Date Contract_print_completed; @AuraEnabled public Date Submit_contract_to_Financial_dept; @AuraEnabled public Date Received_Date; @AuraEnabled public Decimal Repair_Cost_Sum; @AuraEnabled public String Maintenance_Contract_No; @AuraEnabled public String Last_year_service_contract; @AuraEnabled public String UserType; @AuraEnabled public Boolean agree_Upper_limit; @AuraEnabled public Boolean URF_Contract; //20231211 sx 贸易合规二期add start @AuraEnabled public String proTradeComplianceStatus; @AuraEnabled public String hosTradeComplianceStatus; @AuraEnabled public String dealTradeComplianceStatus; @AuraEnabled public String violationName; } }