19626
2023-09-13 196df4d4bf1941546d349cadbf343655578ec280
force-app/main/default/classes/PCLLostReportController.cls
@@ -20,6 +20,8 @@
   public integer secondNum {get; set;}
   // add tcm 20211122 end
   public Decimal InclusionUltrasound {get; set;}     //20230506 lt DB202304618804  包含超声 add
   // 竞争对手对照关系表,key是品牌名字,value是ID
   public map<string,id> CompetitionMap;
@@ -97,6 +99,9 @@
          Lost_reason_main__c,
          Lost_Reason_Sub__c,Lost_By_Company__c,
          LostTotalAmount__c,LostType__c,
       TotalAmountLost__c, //20230215 lt DB202302247719
       InclusionUltrasound__c, //20230506 lt DB202304618804  包含超声
       ModifyAfterApproval__c,Approved_Day__c,//20230814 lt DB202308068183 失单报告审批节点增加助理审批节点 add
          Report_Status__c,Sales_assistant__c,
          Opportunity__c, Opportunity__r.Sales_assistant_ID__c,
          Opportunity__r.Sales_manager_departmentID__c,
@@ -109,6 +114,9 @@
            pageStatus = null;
            return;
         }
      InclusionUltrasound = lostReportList[0].InclusionUltrasound__c; //20230506 lt DB202304618804  包含超声
         lostReportList[0].Sales_assistant__c =
            lostReportList[0].Opportunity__r.Sales_assistant_ID__c;
         lostReportList[0].Manager_sales__c =
@@ -120,7 +128,16 @@
            lostReportList[0].LostType__c ='部分失单';
         }
         // 权限,如果当前状态不是草案中,那么需要跳转到只读页面
         if(!'草案'.equals(lostReportList[0].Report_Status__c) && userinfo.getProfileId() != (ID) '00e10000000Y3o5AAC') {
      // 20230814 lt DB202308068183 失单报告审批节点增加助理审批节点 strat 改if条件
      //原:!'草案'.equals(lostReportList[0].Report_Status__c) && userinfo.getProfileId() != (ID) '00e10000000Y3o5AAC'
      if(
         !('草案'.equals(lostReportList[0].Report_Status__c)
         || userinfo.getProfileId() == (ID) '00e10000000Y3o5AAC'
         ||('批准'.equals(lostReportList[0].Report_Status__c) &&
            System.Label.PCLReportProfileId.contains(userinfo.getProfileId()))
         )
        ) {
      // 20230814 lt DB202308068183 失单报告审批节点增加助理审批节点 end 改if条件
            pageStatus = 'View';
         }
         oppId = lostReportList[0].Opportunity__c;
@@ -128,6 +145,7 @@
         list<PCLLostBrand__c> selectlostBrandList =
         [
            select id, LostPrice__c, Lost_By_Company__c,
        LostPrices_ThousandY__c,  //20230215 lt DB202302247719
            Lost_reason_main__c,Lost_Reason_Sub__c,Name,Agency__c, AgencyMannual__c,
            // ProductCategory__c,ProductClass__c,
            Lost_cancel_report__c,Lost_By_Company_Mannual__c,
@@ -152,7 +170,6 @@
               system.debug('check products:'+ (templostBrand.PCLLostBrandProduct__r != null) + '|' + (templostBrand.PCLLostBrandProduct__r.size() > 0));
               if (templostBrand.PCLLostBrandProduct__r != null && templostBrand.PCLLostBrandProduct__r.size() > 0) {
                  for( PCLLostProduct__c tempProduct: templostBrand.PCLLostBrandProduct__r) {
                     tempProductList.add(new PCLLostProducts(productCount,tempProduct));
                     productCount++;
                  }
@@ -188,9 +205,14 @@
   }
   // 编辑 只有系统管理员或者草案中可以编辑
   public PageReference edit2(){
     //20230814 lt DB202308068183 失单报告审批节点增加助理审批节点 start
      if( userinfo.getProfileId() == (ID) '00e10000000Y3o5AAC' ||
          '草案'.equals(LostReport.LostReport.Report_Status__c)
        '草案'.equals(LostReport.LostReport.Report_Status__c) ||
        ('批准'.equals(LostReport.LostReport.Report_Status__c) &&
         System.Label.PCLReportProfileId.contains(userinfo.getProfileId())
        )
          ) {
      //20230814 lt DB202308068183 失单报告审批节点增加助理审批节点 end
         pageStatus = 'Edit';
         init();
      }
@@ -335,6 +357,15 @@
            }
            // 当失单品牌名为其他时,报错字段为失单对手型号(手动) thh 2022-01-17 end
            // update tcm 20211123 end
        // 20230418 ljh DB202304320022 start
        String LostBrandNameS = tempLostBrand.lostBrand.Lost_By_Company__c != '其他'?tempLostBrand.lostBrand.Lost_By_Company__c:tempLostBrand.lostBrand.Lost_By_Company_Mannual__c;
        String LostBrandName = temlostProduct.LostProductss.LostBrandName__c;
        if(LostBrandNameS != LostBrandName){
         temlostProduct.LostProductss.LostBrandName__c.addError('失单品牌名不一致,请确认');
         dataCheck = false;
        }
        // 20230418 ljh DB202304320022 end
         }
         // 当失单品牌名为其他时,报错字段为失单对手型号(手动) thh 2022-01-17 start
         if (productCount == 0 && tempLostBrand.LostProducts != null && tempLostBrand.LostProducts.size() > 0) {
@@ -374,13 +405,30 @@
         // 设置记录类型
         LostReport.lostReport.recordTypeID  =  LostReport.lostReport.LostType__c== '失单'?Schema.SObjectType.Lost_cancel_report__c.getRecordTypeInfosByDeveloperName().get('PCL_Lost_report').getRecordTypeId() : Schema.SObjectType.Lost_cancel_report__c.getRecordTypeInfosByDeveloperName().get('PCL_PartLost_report').getRecordTypeId();
         LostReport.lostReport.LostTotalAmount__c    = 0;
      LostReport.lostReport.TotalAmountLost__c    = 0;  //20230215 lt DB202302247719
         LostReport.lostReport.of_lost_system_processor__c   = 0;
         LostReport.lostReport.Lost_reason_main__c = null;
         LostReport.lostReport.Lost_Reason_Sub__c  = null;
         LostReport.lostReport.Lost_By_Company__c = null;
      //20230814 lt DB202308068183 失单报告审批节点增加助理审批节点 start
      //批准日不为空时给修改后再批准赋值
      if(LostReport.lostReport.Approved_Day__c != null){
         LostReport.lostReport.ModifyAfterApproval__c = true;
      }
      //20230814 lt DB202308068183 失单报告审批节点增加助理审批节点 end
         for(LostBrand tempLostBrand : LostReport.LostBrands) {
            if(string.isNotBlank(tempLostBrand.lostBrand.Lost_By_Company__c)) {
               LostReport.lostReport.LostTotalAmount__c += tempLostBrand.lostBrand.LostPrice__c;
         //20230215 lt DB202302247719  start
         Decimal med = tempLostBrand.lostBrand.LostPrice__c/1.13/1000;
         Decimal med1 = med.setScale(2);
         // System.debug('---lt123不含税数值(人工)Decimal---'+med);
         // System.debug('---lt123不含税数值(人工)Decimal两位小数---'+med1);
         LostReport.lostReport.TotalAmountLost__c += med1;
         //LostReport.lostReport.TotalAmountLost__c += tempLostBrand.lostBrand.LostPrices_ThousandY__c;  //20230215 lt DB202302247719
         // LostReport.lostReport.TotalAmountLost__c += tempLostBrand.lostBrand.LostPrice__c/1.13/1000;  //20230215 lt DB202302247719
         //20230215 lt DB202302247719  en
               LostReport.lostReport.Lost_reason_main__c =
                  LostReport.lostReport.Lost_reason_main__c == null
                  ? tempLostBrand.lostBrand.Lost_reason_main__c
@@ -489,6 +537,7 @@
         LostReport.lostReport = templostReport;
         LostReport.LostBrands = tempBrands;
         // 这里需要写一些报错信息
      System.debug('---lt123---'+ex.getLineNumber());
         ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,ex.getMessage()));
         return false;
      }
@@ -503,18 +552,34 @@
   }
   // 提交
   public PageReference submit(){
      if(!'草案'.equals(LostReport.LostReport.Report_Status__c) ) {
     //20230814 lt DB202308068183 失单报告审批节点增加助理审批节点  update
     //&& LostReport.LostReport.ModifyAfterApproval__c == false
     if(!'草案'.equals(LostReport.LostReport.Report_Status__c) && LostReport.LostReport.ModifyAfterApproval__c == false) {
         ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '只有在草案中才能提交申请!'));
         return null;
      }
     // 20230629 wkx DB202306242764  start
     //20230814 lt DB202308068183 失单报告审批节点增加助理审批节点 add lcrlist1
     //DB202308068183 add (不等于当前失单报告,批准后再修改用)
     list<Lost_cancel_report__c> lcrlist1=[select id,Opportunity__c from Lost_cancel_report__c where Opportunity__c=:oppid and id!=:lostReportId limit 1];
     list<opportunity> opplist1=[select id,cnt_lost_cancel_report__c,cnt_lost_cancel_draft__c from Opportunity where id=:oppid limit 1];
     if (opplist1[0].cnt_lost_cancel_report__c - opplist1[0].cnt_lost_cancel_draft__c > 0  && lcrlist1.size() > 0) {
        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '已存在 询价失单/取消 报告!'));
        return null;
     }
     // 20230629 wkx DB202306242764  end
      Savepoint sp = Database.setSavepoint();
      try{
         LostReport.lostReport.Report_Status__c = '提交';
         update LostReport.lostReport;
         Approval.ProcessSubmitRequest psr = new Approval.ProcessSubmitRequest();
         psr.setObjectId(lostReportId);
         Approval.ProcessResult submitResult = Approval.process(psr);
      //20230814 lt DB202308068183 失单报告审批节点增加助理审批节点 start 注释
      //DB202308068183 进 进程生成器
      // Approval.ProcessSubmitRequest psr = new Approval.ProcessSubmitRequest();
      // psr.setObjectId(lostReportId);
      // Approval.ProcessResult submitResult = Approval.process(psr);
      //20230814 lt DB202308068183 失单报告审批节点增加助理审批节点 end 注释
         PageReference page = new PageReference('/apex/PCLLostReportPage');
         page.getParameters().put('Id', lostReportId);
         page.getParameters().put('pageStatus', 'View');
@@ -561,7 +626,10 @@
      system.debug('brandNo:'+brandNo);
      LostBrand tempLostBrand = LostReport.LostBrands.get(brandNo);
      // PCLLostProduct__c plp = new PCLLostProduct__c(Competitor__c=CompetitionMap.get(LostReport.LostBrands[brandNo].lostBrand.Lost_By_Company__c));
      string brandName = tempLostBrand.lostBrand.Lost_By_Company__c;
     // 20230418 ljh DB202304320022 start
     // string brandName = tempLostBrand.lostBrand.Lost_By_Company__c;
     string brandName = tempLostBrand.lostBrand.Lost_By_Company__c != '其他'?tempLostBrand.lostBrand.Lost_By_Company__c:tempLostBrand.lostBrand.Lost_By_Company_Mannual__c;
     // 20230418 ljh DB202304320022 end
      PCLLostProduct__c plp = new PCLLostProduct__c();
      plp.LostBrandName__c = brandName;
      tempLostBrand.LostProducts.add(new PCLLostProducts(tempLostBrand.LostProducts.size(),plp));