From a44ccad425f1fbfd932b76b289c7abe36d2234b3 Mon Sep 17 00:00:00 2001
From: chenjingwu <chenjingwu@prec-tech.com>
Date: 星期四, 25 四月 2024 10:19:13 +0800
Subject: [PATCH] 123

---
 force-app/main/default/classes/MaintenanceProductDataController.cls |   51 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/force-app/main/default/classes/MaintenanceProductDataController.cls b/force-app/main/default/classes/MaintenanceProductDataController.cls
index 721e92d..29c1d73 100644
--- a/force-app/main/default/classes/MaintenanceProductDataController.cls
+++ b/force-app/main/default/classes/MaintenanceProductDataController.cls
@@ -53,7 +53,9 @@
     public List<MultiYearWarranty__c> muList { get; set; }
     public Map<String,List<MultiYearWarranty__c>> muMap { get; set; }
     public Map<String,Integer> muCountMap {get; set; }
+    public Map<String,Integer> muCountViewMap {get; set; }
     public Map<String,List<ExMpdDetailsInfo>>  exmpdDetailsRecordsMap { get; set; }
+    public Map<String,List<ExMpdDetailsInfo>>  exmpdDetailsRecordsViewMap { get; set; }
     // chenjingwu 3+2澶氬勾淇濅慨 end
 
      /*****************鐢婚潰琛ㄧずBean******************/
@@ -537,19 +539,28 @@
                 }
                 // chenjingwu 3+2澶氬勾淇濅慨 20240417 end
                 // chenjingwu 3+2澶氬勾淇濅慨 20240417 start
-                exmpdDetailsRecordsMap = new Map<String,List<ExMpdDetailsInfo>>(); 
+                exmpdDetailsRecordsMap = new Map<String,List<ExMpdDetailsInfo>>();
+                exmpdDetailsRecordsViewMap = new Map<String,List<ExMpdDetailsInfo>>(); 
                 muCountMap = new Map<String,Integer>();
+                muCountViewMap = new Map<String,Integer>();
                 List<Maintenance_Product_Data_Details__c> exDetailList = [select Id,MultiYearWarranty__c,MultiYearWarranty__r.AgeLimit__c,MultiYearWarranty__r.MultiOneYearWarrantyPrice__c,MultiYearWarranty__r.AmountWithheld__c,AgeLimit__c,AgeLimit_Old__c,MultiOneYearWarrantyPrice__c,MultiOneYearWarrantyPrice_Old__c,AmountWithheld__c,AmountWithheld_Old__c,ProductsID__c,ProductsID__r.Name from Maintenance_Product_Data_Details__c where ProductsID__c in:idList and RecordTypeId = '012C50000000jefIAA'];
                     for(String id: idList){
                         List<ExMpdDetailsInfo> exList = new List<ExMpdDetailsInfo>();
+                        List<ExMpdDetailsInfo> exViewList = new List<ExMpdDetailsInfo>();
                         for(Maintenance_Product_Data_Details__c mpdd: exDetailList){
                             if(id == mpdd.ProductsID__c){
                                 exList.add(new ExMpdDetailsInfo(mpdd));
+                                exViewList.add(new ExMpdDetailsInfo(mpdd));
                             }
+                        }
+                        if(exList.size() <= 0){
+                            exViewList.add(new ExMpdDetailsInfo());
                         }
                         exList.add(new ExMpdDetailsInfo());
                         muCountMap.put(id,exList.size());
+                        muCountViewMap.put(id,exViewList.size());
                         exmpdDetailsRecordsMap.put(id,exList);
+                        exmpdDetailsRecordsViewMap.put(id,exViewList);
                     }
                 System.debug('chenjingwu=>' + idList);
                 System.debug('chenjingwu=>' + muCountMap);
@@ -903,7 +914,7 @@
                      }
                      // chenjingwu 3+2澶氬勾淇濅慨 20240417 end
                     List<Maintenance_Product_Data_Details__c> exDetailList = [select Id,MultiYearWarranty__c,MultiYearWarranty__r.AgeLimit__c,MultiYearWarranty__r.MultiOneYearWarrantyPrice__c,MultiYearWarranty__r.AmountWithheld__c,AgeLimit__c,AgeLimit_Old__c,MultiOneYearWarrantyPrice__c,MultiOneYearWarrantyPrice_Old__c,AmountWithheld__c,AmountWithheld_Old__c,ProductsID__c,ProductsID__r.Name from Maintenance_Product_Data_Details__c where ProductsID__c in:idList and RecordTypeId = '012C50000000jefIAA'];
-                    if(exDetailList.size() > 0){
+                    if(exDetailList.size() <= 0){
                         // chenjingwu 3+2澶氬勾淇濅慨 20240417 start 
                         muList = [select Id,AgeLimit__c,MultiOneYearWarrantyPrice__c,AmountWithheld__c,ProductName__r.Name,ProductName__c from MultiYearWarranty__c where ProductName__c in: idList order By ProductName__c];
                         Integer str = 0;
@@ -952,8 +963,6 @@
                     }
                     // chenjingwu 3+2澶氬勾淇濅慨   20240417 end
                 }
-                System.debug('chenjingwu1==>' + idList);
-                System.debug('chenjingwu1==>' + muList);
                 if(isWarning){
                     return null;
                 }else{
@@ -1162,11 +1171,45 @@
                         }
                         Ins.add(upMpd);    
                     }
+                    List<Maintenance_Product_Data_Details__c> exIntList = new List<Maintenance_Product_Data_Details__c>();
+                    List<Maintenance_Product_Data_Details__c> exDetailList = new List<Maintenance_Product_Data_Details__c>();
+                    if(RecordTypeName.equals('GuranteeMain')){
+                        List<Maintenance_Product_Data__c> mpd_Name = new List<Maintenance_Product_Data__c>();
+                        mpd_Name = [SELECT id,Name FROM Maintenance_Product_Data__c WHERE id =:id];
+                        exDetailList = [SELECT id,Name FROM Maintenance_Product_Data_Details__c where Maintenance_Product_Data__c =:id and RecordTypeId = '012C50000000jefIAA'];
+                        Integer str = 0;
+                        for(List<ExMpdDetailsInfo> li: exmpdDetailsRecordsMap.values()){
+                            for(ExMpdDetailsInfo ex: li){
+                                if(ex.mpdrdd.AgeLimit__c > 0){
+                                    Maintenance_Product_Data_Details__c InsAfterDel = new Maintenance_Product_Data_Details__c();
+                                    InsAfterDel.Maintenance_Product_Data__c = mpd_Name[0].id;
+                                    InsAfterDel.Name = mpd_Name[0].Name + '-ex'+ str;
+                                    InsAfterDel.AgeLimit__c = ex.mpdrdd.AgeLimit__c;
+                                    InsAfterDel.MultiYearWarranty__c = ex.mpdrdd.MultiYearWarranty__c;
+                                    InsAfterDel.MultiOneYearWarrantyPrice__c = ex.mpdrdd.MultiOneYearWarrantyPrice__c;
+                                    InsAfterDel.AmountWithheld__c = ex.mpdrdd.AmountWithheld__c;
+                                    InsAfterDel.ProductsID__c = ex.mpdrdd.ProductsID__c;
+
+                                    InsAfterDel.AgeLimit_Old__c = ex.Prod.AgeLimit__c;
+                                    InsAfterDel.MultiOneYearWarrantyPrice_Old__c = ex.Prod.MultiOneYearWarrantyPrice__c;
+                                    InsAfterDel.AmountWithheld_Old__c = ex.Prod.AmountWithheld__c;
+                                    InsAfterDel.RecordTypeId = '012C50000000jefIAA';
+                                    exIntList.add(InsAfterDel);
+                                    str++;
+                                }
+                            }
+                        }
+                    // chenjingwu 3+2澶氬勾淇濅慨   20240417 end
+                   }
                     if(isWarning){
                         return null;
                     }else{
                         if(Ins.size()>0){
                             update Ins;
+                            if(exIntList.size() > 0){
+                                delete exDetailList;
+                                upsert exIntList;
+                            }
                             return UnabletoEdit();
                         }
                         else{ 

--
Gitblit v1.9.1