From 51831e72a5780b9f590026e7352f9f6a81edda92 Mon Sep 17 00:00:00 2001
From: chenjingwu <chenjingwu@prec-tech.com>
Date: 星期二, 23 四月 2024 18:10:59 +0800
Subject: [PATCH] 123

---
 force-app/main/default/classes/MaintenanceProductDataController.cls |  111 +++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 94 insertions(+), 17 deletions(-)

diff --git a/force-app/main/default/classes/MaintenanceProductDataController.cls b/force-app/main/default/classes/MaintenanceProductDataController.cls
index e667e98..be8c6dd 100644
--- a/force-app/main/default/classes/MaintenanceProductDataController.cls
+++ b/force-app/main/default/classes/MaintenanceProductDataController.cls
@@ -53,6 +53,7 @@
     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,List<ExMpdDetailsInfo>>  exmpdDetailsRecordsMap { get; set; }
     // chenjingwu 3+2澶氬勾淇濅慨 end
 
      /*****************鐢婚潰琛ㄧずBean******************/
@@ -535,27 +536,22 @@
                     idList.add(mp.mpded.ProductsID__c);
                 }
                 // chenjingwu 3+2澶氬勾淇濅慨 20240417 end
-                // chenjingwu 3+2澶氬勾淇濅慨 20240417 start 
+                // chenjingwu 3+2澶氬勾淇濅慨 20240417 start
+                exmpdDetailsRecordsMap = new Map<String,List<ExMpdDetailsInfo>>(); 
                 muCountMap = new Map<String,Integer>();
-                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];
-                  for(AggregateResult  objAgr: [select ProductName__c,COUNT(Id) total from MultiYearWarranty__c where ProductName__c in:idList group by ProductName__c]){
-                    muCountMap.put((String)objAgr.get('ProductName__c'), (Integer)objAgr.get('total') + 1);
-                  }
-                  muMap = new Map<String,List<MultiYearWarranty__c>>();
-                for(String id: idList){
-                    List<MultiYearWarranty__c> mus = new List<MultiYearWarranty__c>();
-                    for(MultiYearWarranty__c mu: muList){
-                        if(id == mu.ProductName__c){
-                            mus.add(mu);
+                List<Maintenance_Product_Data_Details__c> exDetailList = [select Id,MultiYearWarranty__c,AgeLimit__c,AgeLimit_Old__c,MultiOneYearWarrantyPrice__c,MultiOneYearWarrantyPrice_Old__c,AmountWithheld__c,AmountWithheld_Old__c,ProductsID__c from Maintenance_Product_Data_Details__c where ProductsID__c in:idList and RecordTypeName = 'GuranteeExtend'];
+                if(exDetailList.size() > 0){
+                    for(String id: idList){
+                        List<ExMpdDetailsInfo> exList = new List<ExMpdDetailsInfo>();
+                        for(Maintenance_Product_Data_Details__c mpdd: exDetailList){
+                            if(id == mpdd.ProductsID__c){
+                                exList.add(new ExMpdDetailsInfo(mpdd));
+                            }
                         }
+                        exList.add(new ExMpdDetailsInfo());
+                        exmpdDetailsRecordsMap.put(id,exList);
                     }
-                    mus.add(new MultiYearWarranty__c(ProductName__c = id));
-                    muMap.put(id,mus);
                 }
-                System.debug('chenjingwu=>' + muCountMap);
-                System.debug('chenjingwu=>' + muMap);
-                System.debug('chenjingwu=>' + mpdDetailsRecordsView);
-                
                 // chenjingwu 3+2澶氬勾淇濅慨   20240417 end
             } 
         }    
@@ -892,11 +888,61 @@
                         Ins.add(InsAfterDel);     
                     }
                 }
+                List<Maintenance_Product_Data_Details__c> exIntList = new List<Maintenance_Product_Data_Details__c>();
+                if(mpdDetailsRecords.size() > 0 && RecordTypeName.equals('GuranteeMain')){
+                    if(exmpdDetailsRecordsMap == null){
+                        
+                        // chenjingwu 3+2澶氬勾淇濅慨 20240417 start 
+                        List<String> idList = new List<String>();
+                        for(MaintenanceProductDataDetailsInfo ass :mpdDetailsRecordsView){
+                            if(ass.check == true){
+                                idList.add(ass.Prod.id);
+                            }
+                        }
+                        // chenjingwu 3+2澶氬勾淇濅慨 20240417 end
+                        // 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];
+                        for(MultiYearWarranty__c mu: muList){
+                            Maintenance_Product_Data_Details__c insmpdd = new Maintenance_Product_Data_Details__c();
+                            insmpdd.AgeLimit__c = mu.AgeLimit__c;
+                            insmpdd.MultiYearWarranty__c = mu.MultiYearWarranty__c;
+                            insmpdd.MultiOneYearWarrantyPrice__c = mu.MultiOneYearWarrantyPrice__c;
+                            insmpdd.AmountWithheld__c = mu.AmountWithheld__c;
+
+
+                            insmpdd.AgeLimit_Old__c = mu.AgeLimit__c;
+                            insmpdd.MultiOneYearWarrantyPrice_Old__c = mu.MultiOneYearWarrantyPrice__c;
+                            insmpdd.AmountWithheld_Old__c = mu.AmountWithheld__c;
+                            insmpdd.RecordTypeId = '012C50000000jefIAA';
+                            exIntList.add(insmpdd);
+
+                        }
+                    } else{
+                        for(List<ExMpdDetailsInfo> list: exmpdDetailsRecordsMap.values()){
+                            for(ExMpdDetailsInfo ex: list){
+                                Maintenance_Product_Data_Details__c InsAfterDel = new Maintenance_Product_Data_Details__c();
+                                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.AgeLimit_Old__c = mu.Prod.AgeLimit__c;
+                                InsAfterDel.MultiOneYearWarrantyPrice_Old__c = mu.Prod.MultiOneYearWarrantyPrice__c;
+                                InsAfterDel.AmountWithheld_Old__c = mu.Prod.AmountWithheld__c;
+                                InsAfterDel.RecordTypeId = '012C50000000jefIAA';
+                                exIntList.add(insmpdd);
+                            }
+                        }
+                    }
+                    // chenjingwu 3+2澶氬勾淇濅慨   20240417 end
+                }
                 if(isWarning){
                     return null;
                 }else{
                     if(Ins.size()>0){
                         upsert Ins;
+                        upsert exIntList;
                         return setEditAble();
                     }else{
                         return null;
@@ -1489,4 +1535,35 @@
         }
     }
 
+
+    class ExMpdDetailsInfo  {
+        public Boolean check { get; set; }
+        public Boolean oldCheck { get; set; }
+        public Boolean canSelect { get; set; }
+        public MultiYearWarranty__c Prod { get; set; }
+        public Maintenance_Product_Data_Details__c mpdrdd {get; set;}
+
+        public ExMpdDetailsInfo(Maintenance_Product_Data_Details__c e) {
+            check = true;
+            oldCheck = true;
+            mpdrdd = e;
+            Prod = e.MultiYearWarranty__r;
+            canSelect = true;
+        }
+        public ExMpdDetailsInfo(MultiYearWarranty__c e) {
+            check = false;
+            oldCheck = false;
+            mpdrdd = new Maintenance_Product_Data_Details__c();
+            Prod = e;
+            canSelect = true;
+        }
+        public ExMpdDetailsInfo() {
+            check = false;
+            oldCheck = false;
+            mpdrdd = new Maintenance_Product_Data_Details__c();
+            Prod = new MultiYearWarranty__c();
+            canSelect = true;
+        }
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.9.1