From 6ff8f16d48dea7dcc5980c7a6ce85b3393b25386 Mon Sep 17 00:00:00 2001
From: chenjingwu <chenjingwu@prec-tech.com>
Date: 星期五, 26 四月 2024 12:09:36 +0800
Subject: [PATCH] 123

---
 force-app/main/default/classes/MaintenanceProductDataController.cls |  158 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 121 insertions(+), 37 deletions(-)

diff --git a/force-app/main/default/classes/MaintenanceProductDataController.cls b/force-app/main/default/classes/MaintenanceProductDataController.cls
index be8c6dd..2fc31de 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******************/
@@ -437,7 +439,7 @@
             for (Integer i=0;i<column_Old.size();i++) {
                 mpdsoql += ',' + column_Old[i];
             }
-            mpdsoql += ' from Maintenance_Product_Data_Details__c  where Maintenance_Product_Data__c = \''+id+'\'';
+            mpdsoql += ' from Maintenance_Product_Data_Details__c  where RecordTypeId != \'012C50000000jefIAA\' and Maintenance_Product_Data__c = \''+id+'\'';
             // 閬告姙娓堛伩銇槑缁嗐倰鍙栧緱
             mpdDetailsSelected = Database.query(mpdsoql);      
             for (Maintenance_Product_Data_Details__c mpdd1 : mpdDetailsSelected) {
@@ -537,21 +539,37 @@
                 }
                 // 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>();
-                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){
+                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){
+                        Integer lineNo = 0;
                         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));
+                                exList.add(new ExMpdDetailsInfo(mpdd,lineNo));
+                                exViewList.add(new ExMpdDetailsInfo(mpdd,lineNo));
+                                lineNo++;
                             }
                         }
-                        exList.add(new ExMpdDetailsInfo());
+                        if(exList.size() <= 0){
+                            exViewList.add(new ExMpdDetailsInfo(lineNo));
+                        }
+                        ExMpdDetailsInfo exd = new ExMpdDetailsInfo(lineNo);
+                        exd.mpdrdd.ProductsID__c = id;
+                        exList.add(exd);
+                        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);
+                System.debug('chenjingwu=>' + exmpdDetailsRecordsMap);
+                System.debug('chenjingwu=>' + mpdDetailsRecords);
                 // chenjingwu 3+2澶氬勾淇濅慨   20240417 end
             } 
         }    
@@ -646,7 +664,8 @@
                 //鏇存柊
                 mpd_Name = [SELECT id,Name FROM Maintenance_Product_Data__c WHERE id =:id];
             }
-            List<Maintenance_Product_Data_Details__c> mpdd_Name = [SELECT id,Name FROM Maintenance_Product_Data_Details__c where Maintenance_Product_Data__c =:id order by Name desc Limit 1 ];
+            String str1 = '%ex%';
+            List<Maintenance_Product_Data_Details__c> mpdd_Name = [SELECT id,Name FROM Maintenance_Product_Data_Details__c where Maintenance_Product_Data__c =:id and (NOT Name like:str1) order by Name desc Limit 1 ];
             if(mpdd_Name.size()>0){
                 String[] nameI= mpdd_Name[0].Name.split('-');
                 i = Integer.valueOf(nameI[1])+1;
@@ -889,25 +908,29 @@
                     }
                 }
                 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
+                if(RecordTypeName.equals('GuranteeMain')){
+                     // 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
+                    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){
                         // 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;
                         for(MultiYearWarranty__c mu: muList){
                             Maintenance_Product_Data_Details__c insmpdd = new Maintenance_Product_Data_Details__c();
+                            insmpdd.Maintenance_Product_Data__c = mpd_Name[0].id;
+                            insmpdd.Name = mpd_Name[0].Name + '-ex'+ str;
                             insmpdd.AgeLimit__c = mu.AgeLimit__c;
-                            insmpdd.MultiYearWarranty__c = mu.MultiYearWarranty__c;
+                            insmpdd.MultiYearWarranty__c = mu.Id;
                             insmpdd.MultiOneYearWarrantyPrice__c = mu.MultiOneYearWarrantyPrice__c;
                             insmpdd.AmountWithheld__c = mu.AmountWithheld__c;
+                            insmpdd.ProductsID__c = mu.ProductName__c;
 
 
                             insmpdd.AgeLimit_Old__c = mu.AgeLimit__c;
@@ -915,23 +938,30 @@
                             insmpdd.AmountWithheld_Old__c = mu.AmountWithheld__c;
                             insmpdd.RecordTypeId = '012C50000000jefIAA';
                             exIntList.add(insmpdd);
-
+                            str++;
                         }
                     } 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;
+                        delete exDetailList;
+                        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 = 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);
+                                    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++;
+                                }
                             }
                         }
                     }
@@ -1145,11 +1175,46 @@
                         }
                         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
+                   }
+                   System.debug('chenjingwu=>' + exIntList);
                     if(isWarning){
                         return null;
                     }else{
                         if(Ins.size()>0){
                             update Ins;
+                            if(exIntList.size() > 0){
+                                delete exDetailList;
+                                upsert exIntList;
+                            }
                             return UnabletoEdit();
                         }
                         else{ 
@@ -1327,6 +1392,21 @@
         }
         ref.setRedirect(true);
         return ref;
+    }
+    public String ProId {get;set;}
+    public Integer index{get;set;}
+    public void addEx(){
+        ExMpdDetailsInfo ex = new ExMpdDetailsInfo(exmpdDetailsRecordsMap.get(ProId).size());
+        ex.mpdrdd.ProductsID__c = ProId;
+        exmpdDetailsRecordsMap.get(ProId).add(ex);
+        muCountMap.put(ProId,muCountMap.get(ProId) + 1); 
+    }
+    public void deleteEx(){
+        for(Integer i=index + 1;i < exmpdDetailsRecordsMap.get(ProId).size();i++){
+            exmpdDetailsRecordsMap.get(ProId)[i].lineNo -= 1;
+        }
+        exmpdDetailsRecordsMap.get(ProId).remove(index);
+        muCountMap.put(ProId,muCountMap.get(ProId) - 1); 
     }
     
     //鎼滅储鏃剁殑sql
@@ -1542,22 +1622,26 @@
         public Boolean canSelect { get; set; }
         public MultiYearWarranty__c Prod { get; set; }
         public Maintenance_Product_Data_Details__c mpdrdd {get; set;}
+        public Integer lineNo{get; set;}
 
-        public ExMpdDetailsInfo(Maintenance_Product_Data_Details__c e) {
+        public ExMpdDetailsInfo(Maintenance_Product_Data_Details__c e,Integer lineNo) {
+            lineNo = lineNo;
             check = true;
             oldCheck = true;
             mpdrdd = e;
             Prod = e.MultiYearWarranty__r;
             canSelect = true;
         }
-        public ExMpdDetailsInfo(MultiYearWarranty__c e) {
+        public ExMpdDetailsInfo(MultiYearWarranty__c e,Integer lineNo) {
+            lineNo = lineNo;
             check = false;
             oldCheck = false;
             mpdrdd = new Maintenance_Product_Data_Details__c();
             Prod = e;
             canSelect = true;
         }
-        public ExMpdDetailsInfo() {
+        public ExMpdDetailsInfo(Integer lineNo) {
+            lineNo = lineNo;
             check = false;
             oldCheck = false;
             mpdrdd = new Maintenance_Product_Data_Details__c();

--
Gitblit v1.9.1