From c6e651446bf356eb44197053e3d57bf5a0d9a50c Mon Sep 17 00:00:00 2001
From: 李彤 <litong@prec-tech.com>
Date: 星期三, 14 九月 2022 15:14:24 +0800
Subject: [PATCH] XLIU-CHY4KW

---
 force-app/main/default/classes/NewQuoteIraiController.cls |  344 +++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 295 insertions(+), 49 deletions(-)

diff --git a/force-app/main/default/classes/NewQuoteIraiController.cls b/force-app/main/default/classes/NewQuoteIraiController.cls
index 173ae57..359a7ce 100644
--- a/force-app/main/default/classes/NewQuoteIraiController.cls
+++ b/force-app/main/default/classes/NewQuoteIraiController.cls
@@ -5,6 +5,7 @@
     public Integer quoteEntryMaxLine {get; private set;}
     public Id quoId {get;set;}
     public String oppid;
+    public String leadid;
     public Boolean productStatusUpdated {get;set;}               // 鐘舵厠鏇存柊銆亄!$Label.Status_Update} 銈掓娂涓嬨仐銇熴亱銇┿亞銇�
     public Boolean changedAfterPrint {get;set;}                  // true 銇牬鍚堛�佺敾闈€伀 confirm 銉°儍銈汇兗銈搞亴琛ㄧず銇椼伨銇欍�俼uoId銈掓柊銇椼亜insert銆傚垽瀹氥伅js銇仸瀹熸柦
 
@@ -12,6 +13,7 @@
     public Boolean filg { get; set; }
     public Integer flglastbuy { get; set; }
     public String errorProductmodel { get; set; }
+    public Boolean is_changed_opp { get; set; }
     //lastbuy  2022/3/10 fy end
 
     public String excel_text {get;set;}
@@ -42,6 +44,11 @@
     public User loginUser {get;set;}
     
     private Map<Id, Product2> prd2LatestValMap;
+    //obsap 鏂板缁忛攢鍟�1瀛楁 fy satrt
+    public Decimal Salesprofit1 { get; set; }
+    public Decimal SalesCalculation1 { get; set; }
+    public Boolean displayFlg { get; set; }
+    //obsap 鏂板缁忛攢鍟�1瀛楁 fy end
 
     // CHAN-BJQ4VZ 绮剧悽鎶�鏈� 2019/12/11 Start
     public QuoteBean qb { get; set; }
@@ -50,7 +57,24 @@
     // 缁忛攢鍟嗚浠锋姤浠峰鎵� 2020-02-28 update by vivek start
     public Map<Id,Id> userProfileId;
     // 缁忛攢鍟嗚浠锋姤浠峰鎵� 2020-02-28 update by vivek end
-    
+
+    // obsap瀵瑰簲 obsap浜哄憳妫�绱� 2022-04-27 ssm start
+    public class UserSelect {
+        public String user_name { get; set; }
+        public User user { get; set; }
+        public UserSelect(User u) {
+            this.user_name = u.Alias;
+            this.user = u;
+        }
+    } 
+    public String obsap_mail { get; set; }
+    //obsap obsap浜哄憳妫�绱� fy satrt
+    // public String selectObsapUsers { get; set; }
+    public List<SelectOption> ObsapUsers { get; set; }
+    public boolean obsflag { get; set; }
+    //obsap obsap浜哄憳妫�绱� fy end
+    // obsap瀵瑰簲 obsap浜哄憳妫�绱� 2022-04-27 ssm end
+
     public NewQuoteIraiController() {
         quoteEntryMaxLine = Integer.valueOf(System.Label.QuoteEntryMaxLine);
         baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
@@ -69,13 +93,48 @@
 
     public PageReference init() {
         system.debug('============start init==============');
+        obsap_mail = System.Label.OBSAP_Group_Mail;
         errorflg = false;
         pdf_button = true;
+        obsflag = false;
         //loginUser
-        loginUser = [select Id, ProfileId, State_Hospital__c from User where Id = :UserInfo.getUserId()];
+        loginUser = [select Id, ProfileId, State_Hospital__c, Salesdepartment_text__c from User where Id = :UserInfo.getUserId()];
         if (loginUser.ProfileId == System.Label.ProfileId_SystemAdmin) {
             pdf_button = false;
         }
+        String obsap_Login_area=System.Label.obsap_Login_area;
+        List<String> obsaplogareaList =obsap_Login_area.split(',');
+        if(obsaplogareaList.contains(loginUser.Salesdepartment_text__c)){
+            obsflag = true;
+        }
+        // obsap瀵瑰簲 obsap浜哄憳妫�绱� 2022-04-27 ssm start
+        // if (loginUser != null && String.isNotBlank(loginUser.Salesdepartment_text__c) && (loginUser.Salesdepartment_text__c == '5.鍗庝笢' || loginUser.Salesdepartment_text__c == '6.鍗庡崡')) {
+        //fy 20220512
+        if (loginUser != null && String.isNotBlank(loginUser.Salesdepartment_text__c) && obsflag) {
+
+            // obsflag = true;
+            // 杩欓噷鍋氫簡涓瘮杈�2鐨勪慨鏀�
+            // 鐢变簬瀹㈡埛涓嶆兂缁欏叕鍏卞皬缁勭殑姣忎釜浜洪兘鍒涘缓涓�涓换鍔★紝鍙兘鐢ㄩ槦鍒�
+            // 杩欐牱鎵嶈兘瀹炵幇涓�涓换鍔★紝灏忕粍鎴愬憳閮借兘鐪嬪埌锛岃皝瀹屾垚閮界畻瀹屾垚
+            // 鍙堢敱浜庨渶瑕佸彂閫侀偖浠讹紝宸ヤ綔娴侀噷鍙戦�侀偖浠跺彧鑳藉埌鍏叡灏忕粍锛屼笉鑳藉彂缁欓槦鍒�
+            // 鎵�浠ユ妸鍏叡灏忕粍褰撲綔闃熷垪鎴愬憳鎵旇繘鍘�
+            // 杩欓噷鍙兘鍙栦袱娆℃墠鑳藉彇鍒板皬缁勯噷鐨勬煇涓�涓汉
+            String obsap_group_id = System.Label.obsap_group_opp;
+            List<GroupMember> queue =  [SELECT Id, GroupId, UserOrGroupId FROM GroupMember where GroupId = :obsap_group_id];
+            system.debug('queue++'+queue);
+            if (queue != null && queue.size() > 0) {
+                List<GroupMember> members =  [SELECT Id, GroupId, UserOrGroupId FROM GroupMember where GroupId = :queue[0].UserOrGroupId];
+                GroupMember member = members != null && members.size() > 0 ? members[0] : new GroupMember();
+                User obsap_user = [SELECT Id, Name, Alias FROM User WHERE Id =: member.UserOrGroupId];
+                ObsapUsers = new List<SelectOption>();
+                // ObsapUsers.add(new SelectOption('',''));
+                // for (User u : obsaps) {
+                //     ObsapUsers.add(new SelectOption(u.Id,u.Alias));
+                // }
+                ObsapUsers.add(new SelectOption(obsap_user.Id, 'OBSAP灏忕粍'));
+            }
+        }
+        // obsap瀵瑰簲 obsap浜哄憳妫�绱� 2022-04-27 ssm end
         //Quote
         quo = new QuoteIrai__c();
         // CHAN-BJQ4VZ 绮剧悽鎶�鏈� 2019/12/11 Start
@@ -91,7 +150,10 @@
         }
         
         // 娼滃湪瀹㈡埛id
-        String leadid = System.currentPageReference().getParameters().get('leadid');
+        // String leadid = System.currentPageReference().getParameters().get('leadid');
+        //SWAG-CF589P銆愬鎵樸�戙�怭:OBSAP銆戞姤浠峰鎵樼浉鍏虫柊闇�姹傝瘎浼� fy start
+        leadid = System.currentPageReference().getParameters().get('leadid');
+        //SWAG-CF589P銆愬鎵樸�戙�怭:OBSAP銆戞姤浠峰鎵樼浉鍏虫柊闇�姹傝瘎浼� fy end
         // 缁忛攢鍟嗚浠锋姤浠峰鎵� 2020-02-28 update by vivek start
         // 缁忛攢鍟嗚浠�
         String agencyoppid = System.currentPageReference().getParameters().get('agencyoppid');
@@ -104,22 +166,27 @@
 
         // 璇环id
         oppid = System.currentPageReference().getParameters().get('oppid');
-        //lastbuy  2022/3/10 fy start
         QuoteIrai__c quoteiraiobj = new QuoteIrai__c();
         if(oppid==null&&tenderid==null&&quoId!=null&&leadid==null&&agencyoppid==null){
-            quoteiraiobj = [select id,Note__c from QuoteIrai__c where id=:quoId];
+            //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy  Noteplus__c
+            quoteiraiobj = [select id,Note__c,Noteplus__c from QuoteIrai__c where id=:quoId];
             if(quoteiraiobj.Note__c!=null){
                 String[] quosub=quoteiraiobj.Note__c.split('/');
-                oppid=quosub[quosub.size()-1];
+                //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy start
+                oppid=quosub[quosub.size()-1].substring(0,15);
+                //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy end
+                // oppid=quosub[quosub.size()-1];
             }
         }
-        //lastbuy  2022/3/10 fy start
         system.debug('oppid:++++'+oppid);
         // 鎶ヤ环id
         String oppquoid = System.currentPageReference().getParameters().get('oppquoid');
         //灏嗘姤浠峰鎵樼殑甯佺涓庡璐稿竵绉嶄竴鑷� 闃叉鍚庣画澶栬锤鏈夐渶瑕佺敤USD鍒ゆ柇鏄剧ず鐨勫湴鏂� 绮剧悽鎶�鏈� wql 2021/01/06 start
-        List<Opportunity> oppList = [Select id,CurrencyIsoCode from Opportunity where id =:oppid];
-
+        List<Opportunity> oppList = [Select id,CurrencyIsoCode, If_Account_Change__c from Opportunity where id =:oppid];
+        // lastbuy鍙樻洿鐢ㄦ埛璇环鍒ゆ柇
+        // 濡傛灉鍙栧緱浜嗚浠凤紝鍒欏彇璇环涓婄殑鏄惁鍙樻洿鐢ㄦ埛锛屽惁鍒檉alse
+        is_changed_opp = oppList != null && oppList.size() > 0 ? oppList[0].If_Account_Change__c : false;
+        
         //Quote
         Integer i;
         if (quoId==null){
@@ -147,6 +214,9 @@
             if (String.isNotBlank(oppid)) {
                 quo.Note__c = Opportunity.sObjectType.getDescribe().getLabel() + '锛�' + baseUrl + '/' + oppid;
             }
+            //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy start
+            quo.Noteplus__c = quo.Note__c;
+            //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy end
             //鏂拌銉偣銉堛偝銉炽儓銉兗銉┿伄鍙栧緱
             if (activities==null){
                 activities = new List<QELine>();
@@ -333,9 +403,11 @@
             // 鎷涙姇鏍囨姤浠峰鎵� 2021-06-21 update by gzw end
         }else{
             // CHAN-BJQ4VZ 绮剧悽鎶�鏈� 2019/12/11 Start
-            List<QuoteIrai__c> quoList = 
-                [ SELECT Id,Name,Cancel_Decide__c,Agency_Hospital_Link__c,CreatedDate, PriceRefreshDate__c,Quote_Print_Date__c,
-                        Quote_Date__c,QuoteToName__c,Quote_Expiration_Date__c,Quote_Comment__c,Tender_information__c,
+            //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy  Noteplus__c
+            //SWAG-CF589P銆愬鎵樸�戙�怭:OBSAP銆戞姤浠峰鎵樼浉鍏虫柊闇�姹傝瘎浼� fy Lead__c,Opportunity__c,
+            List<QuoteIrai__c> quoList = //obsap 鏂板缁忛攢鍟�1瀛楁 fy satrt Agency1_entrust__c ,
+                [ SELECT Id,Name,Cancel_Decide__c,Agency_Hospital_Link__c,CreatedDate, PriceRefreshDate__c,Quote_Print_Date__c,Agency1_entrust__c,
+                        Quote_Date__c,QuoteToName__c,Quote_Expiration_Date__c,Quote_Comment__c,Tender_information__c,Noteplus__c,Lead__c,Opportunity__c,
                         TOTAL__c,Discount__c,Pricing__c,Preferential_Trading_Price__c,Contract__c,LastIraiUser__c,MultiYearWarrantyTotalPrice__c,QuoteTotal_Page__c,Estimation_List_Price__c,
                         Print_HP_Name__c,Account__c,IraiUser__c,IraiSubject__c,CurrencyIsoCode,IraiName__c,QuoteIrai_Status__c,QuoteProportion__c,Note__c,IraiComment__c
                         FROM QuoteIrai__c Where Id =:quoId];
@@ -426,9 +498,20 @@
         if (quo.Quote_Expiration_Date__c==null){
             quo.Quote_Expiration_Date__c = Date.today() + 30;
         }
-
         //--Savebutton
         Save_button=true;
+        //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy start
+        // if( quo.Note__c!=''){
+        if(String.isNotBlank(quo.Note__c)){
+            system.debug('===111==='+quo.Note__c.split('\r\n'));
+            List<String> str=quo.Note__c.split('\r\n');
+            if(str.size()==1){
+                quo.Note__c=''; 
+            }else{
+                quo.Note__c=str[1]; 
+            }
+        }
+        //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy end
         system.debug('===000==='+quo);
         return null;
      }
@@ -939,8 +1022,31 @@
                 }
                 i += 1;
             }
-            if (!String.isBlank(quo.Note__c)) {
-                description += '\r\n' + quo.Note__c;
+            //obsap 鏂板缁忛攢鍟�1瀛楁 fy start
+            if (!String.isBlank(quo.Agency1_entrust__c)) {
+                Account  quoteAeName = [select Id,Name from Account where Id =:quo.Agency1_entrust__c];
+                description += '\r\n' + '绗竴缁忛攢鍟嗗悕绉�' + '锛�' + quoteAeName.Name;
+            }
+            if (quo.QuoteProportion__c!=null) {
+                description += '\r\n' + '鎶ヤ环姣斾緥' + '锛�' + quo.QuoteProportion__c;
+            }
+            if (!String.isBlank(quo.IraiComment__c)) {
+                description += '\r\n' + '鎶ヤ环澶囨敞' + '锛�' + quo.IraiComment__c;
+            }
+            //obsap 鏂板缁忛攢鍟�1瀛楁 fy end
+            //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy start
+            String node;
+            if(!String.isBlank(quo.Note__c)){
+                node=quo.Noteplus__c+'\r\n'+quo.Note__c;
+            }else{
+                node=quo.Noteplus__c;
+            }
+            //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy end
+            if (!String.isBlank(node)) {
+                //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy start
+                description += '\r\n' + node;
+                //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy end
+                // description += '\r\n' + quo.Note__c;
             }
             if (!String.isBlank(quo.Account__c)) {
                 description += '\r\n' + Account.sObjectType.getDescribe().getLabel() + '锛�' + baseUrl + '/' + quo.Account__c;
@@ -950,15 +1056,51 @@
                 description += '\r\n' + Agency_Hospital_Link__c.sObjectType.getDescribe().getLabel() + '锛�' + baseUrl + '/' + quo.Agency_Hospital_Link__c;
             }
             // 缁忛攢鍟嗚浠锋姤浠峰鎵� 2020-02-28 update by vivek end
-
+            //obsap 鏂板缁忛攢鍟�1瀛楁 fy start
+            if (!String.isBlank(quo.Agency1_entrust__c)) {
+                description += '\r\n' + '绗竴缁忛攢鍟�' + '锛�' + baseUrl + '/' + quo.Agency1_entrust__c;
+            }
+            //obsap 鏂板缁忛攢鍟�1瀛楁 fy end
             // 鎷涙姇鏍囨姤浠峰鎵� 2020-06-21 update by gzw start
             // if (!String.isBlank(quo.Tender_information__c)) {
             //     description += '\r\n' + Tender_information__c.sObjectType.getDescribe().getLabel() + '锛�' + baseUrl + '/' + quo.Tender_information__c;
             // }
             // 鎷涙姇鏍囨姤浠峰鎵� 2020-06-21 update by gzw end
+            // obsap 濮旀墭浜烘寜鍏叡灏忕粍鍖哄垎锛屾绱㈡暟閲忓鍔� 2022-05-09 ssm start
+            List<String> irai_userids = new List<String>();
+            // if (loginUser != null && String.isNotBlank(loginUser.Salesdepartment_text__c) && (loginUser.Salesdepartment_text__c == '5.鍗庝笢' || loginUser.Salesdepartment_text__c == '6.鍗庡崡')) {
+            //fy 20220512
+            if (loginUser != null && String.isNotBlank(loginUser.Salesdepartment_text__c) && obsflag) {
+
+                // obsflag = true;
+                // String obsap_group_id = System.Label.obsap_group_opp;
+                // List<GroupMember> members =  [SELECT Id, GroupId, UserOrGroupId FROM GroupMember where GroupId = :obsap_group_id];
+                // system.debug('members++'+members);
+                // if (members != null && members.size() > 0) {
+                //     for (GroupMember member : members) {
+                        // irai_userids.add(member.UserOrGroupId);
+                //     }
+                // }
+                irai_userids.add(System.Label.obsap_group_opp);
+            }else{
+                irai_userids.add(quo.IraiUser__c);
+            }
+            // 鎶婂鎵樹笂缁戝畾鐨勪汉鍔犲埌list閲�
+            //20220512 lt add
+            // Map<String,String> iuMap = new Map<String,String>();
+            // for(String iu : irai_userids){
+            //     iuMap.put(iu,iu);
+            // }
+            // if(!iuMap.containsKey(quo.IraiUser__c)){
+            //     irai_userids.add(quo.IraiUser__c);
+            // } 
+            //irai_userids.add(quo.IraiUser__c);
+            // Task[] tasks = [select Id,Subject,OwnerId,Description,ActivityDate,QuoteIraiId__c
+            //                 from Task
+            //                 where QuoteIraiId__c = :quoId and OwnerId = :quo.IraiUser__c];
             Task[] tasks = [select Id,Subject,OwnerId,Description,ActivityDate,QuoteIraiId__c
                             from Task
-                            where QuoteIraiId__c = :quoId and OwnerId = :quo.IraiUser__c];
+                            where QuoteIraiId__c = :quoId and OwnerId in :irai_userids];
             String todoSubject = '鎶ヤ环濮旀墭锛�' + quo.IraiSubject__c;
             if (!String.isBlank(quo.IraiName__c)) {
                 todoSubject += '锛� ' + quo.IraiName__c;
@@ -969,30 +1111,74 @@
             if (quo.QuoteProportion__c != null) {
                 todoSubject += '锛� ' + quo.QuoteProportion__c + '%';
             }
-            String taskid = '';
+            // String taskid = '';
+            // 鏀规垚瀵瑰浜虹殑
+            // if (tasks.size() > 0) {
+            //     Task task = tasks[0];
+            //     task.Subject = todoSubject;
+            //     task.Description = description;
+            //     task.ActivityDate = Date.today();
+                
+            //     Database.DMLOptions dmlo = new Database.DMLOptions();
+            //     dmlo.EmailHeader.triggerUserEmail = true;
+            //     Database.update(task, dmlo);
+            //     taskid = task.Id;
+            // } else {
+            //     Task task = new Task();
+            //     task.Subject = todoSubject;
+            //     task.OwnerId = quo.IraiUser__c;
+            //     task.Description = description;
+            //     task.ActivityDate = Date.today();
+            //     task.QuoteIraiId__c = quoId;
+                
+            //     Database.DMLOptions dmlo = new Database.DMLOptions();
+            //     dmlo.EmailHeader.triggerUserEmail = true;
+            //     Database.insert(task, dmlo);
+            //     taskid = task.Id;
+            // }
+            List<String> new_task_users = new List<String>();
             if (tasks.size() > 0) {
-                Task task = tasks[0];
-                task.Subject = todoSubject;
-                task.Description = description;
-                task.ActivityDate = Date.today();
-                
+                List<String> task_users = new List<String>();
+                for (Task task : tasks) {
+                    task_users.add(task.OwnerId);
+
+                    task.Subject = todoSubject;
+                    task.Description = description;
+                    task.ActivityDate = Date.today();
+                }
                 Database.DMLOptions dmlo = new Database.DMLOptions();
                 dmlo.EmailHeader.triggerUserEmail = true;
-                Database.update(task, dmlo);
-                taskid = task.Id;
+                Database.update(tasks, dmlo);
+                // update tasks;
+
+                for (String uid : irai_userids) {
+                    if (!task_users.contains(uid)) {
+                        new_task_users.add(uid);
+                    }
+                }
+
             } else {
-                Task task = new Task();
-                task.Subject = todoSubject;
-                task.OwnerId = quo.IraiUser__c;
-                task.Description = description;
-                task.ActivityDate = Date.today();
-                task.QuoteIraiId__c = quoId;
-                
+                new_task_users = irai_userids;
+            }
+            if (new_task_users.size() > 0) {
+                List<Task> new_tasks = new List<Task>();
+                for (String uid : new_task_users) {
+                    Task new_task = new Task();
+                    new_task.Subject = todoSubject;
+                    new_task.OwnerId = uid;
+                    new_task.Description = description;
+                    new_task.ActivityDate = Date.today();
+                    new_task.QuoteIraiId__c = quoId;
+
+                    new_tasks.add(new_task);
+                }
+                system.debug('new_tasks++'+new_tasks);
                 Database.DMLOptions dmlo = new Database.DMLOptions();
                 dmlo.EmailHeader.triggerUserEmail = true;
-                Database.insert(task, dmlo);
-                taskid = task.Id;
+                Database.insert(new_tasks, dmlo);
+                // insert new_tasks;
             }
+            // obsap 濮旀墭浜烘寜鍏叡灏忕粍鍖哄垎锛屾绱㈡暟閲忓鍔� 2022-05-09 ssm end
             
             User u = [select Id,Name from user where Id = :quo.IraiUser__c];
             quo.LastIraiUser__c = u.Name;
@@ -1003,8 +1189,10 @@
             update qi;
             if(String.isNotBlank(quoId)){
                 // CHAN-BJQ4VZ 绮剧悽鎶�鏈� 2019/12/11 Start
-                quo =[ SELECT Id,Name,Cancel_Decide__c,CreatedDate, PriceRefreshDate__c,Quote_Print_Date__c,
-                        Quote_Date__c,QuoteToName__c,Quote_Expiration_Date__c,Quote_Comment__c,Tender_information__c,
+            //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy  Noteplus__c
+            //SWAG-CF589P銆愬鎵樸�戙�怭:OBSAP銆戞姤浠峰鎵樼浉鍏虫柊闇�姹傝瘎浼� fy Lead__c,Opportunity__c,
+                quo =[ SELECT Id,Name,Cancel_Decide__c,CreatedDate, PriceRefreshDate__c,Quote_Print_Date__c,//obsap 鏂板缁忛攢鍟�1瀛楁 fy satrt Agency1_entrust__c,
+                        Quote_Date__c,QuoteToName__c,Quote_Expiration_Date__c,Quote_Comment__c,Tender_information__c,Agency1_entrust__c,Noteplus__c,Lead__c,Opportunity__c,
                         TOTAL__c,Discount__c,Pricing__c,Preferential_Trading_Price__c,Contract__c,LastIraiUser__c,MultiYearWarrantyTotalPrice__c,QuoteTotal_Page__c,Estimation_List_Price__c,
                         Print_HP_Name__c,Account__c,Agency_Hospital_Link__c,IraiUser__c,IraiSubject__c,CurrencyIsoCode,IraiName__c,QuoteIrai_Status__c,QuoteProportion__c,Note__c,IraiComment__c
                         FROM QuoteIrai__c Where Id =:quoId];
@@ -1019,7 +1207,29 @@
             // 鎷涙姇鏍囨姤浠峰鎵� 2020-06-21 update by gzw end
             errorflg = true;
             errorMessage = '閭欢鍙戦�佸畬鎴愩��';
+
+            //XLIU-CHY4KW 20220907 lt start  --- 鎶ヤ环濮旀墭鍙戦�侀偖浠舵垚鍔熶箣鍚� 鍙嶅悜鏇存柊鎰忓悜  鎶ヤ环濮旀墭瀛楁涓�1
+            Lead lea = new Lead();
+            if(String.isNotBlank(leadid)){
+                lea.Id = leadid;
+                lea.OfferToEntrust__c = 1;
+                update lea;
+            }
+            //XLIU-CHY4KW 20220907 lt end  
+
             pageArrange();
+            //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy start
+            // if(quo.Note__c!=''){
+            if(String.isNotBlank(quo.Note__c)){
+                system.debug('===555==='+quo.Note__c.split('\r\n'));
+                List<String> str=quo.Note__c.split('\r\n');
+                if(str.size()==1){
+                    quo.Note__c=''; 
+                }else{
+                    quo.Note__c=str[1]; 
+                }
+            }
+            //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy end
             return null;
             //鎶ヤ环濮旀墭鐘舵�佹洿鏂�  宸茬粡濮旀墭
         } catch (DmlException de) {
@@ -1038,10 +1248,13 @@
         
         return null;
     }
+
     public String getoppId(){
         String opptext = null;
         if(String.isNotBlank(quoId)){
-            QuoteIrai__c getnote = [ SELECT Id,Name,Note__c FROM QuoteIrai__c Where Id =:quoId];
+            //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy  Noteplus__c
+            //SWAG-CF589P銆愬鎵樸�戙�怭:OBSAP銆戞姤浠峰鎵樼浉鍏虫柊闇�姹傝瘎浼� fy Lead__c,Opportunity__c,
+            QuoteIrai__c getnote = [ SELECT Id,Name,Note__c,Noteplus__c,Lead__c,Opportunity__c FROM QuoteIrai__c Where Id =:quoId];
             if(String.isNotBlank(getnote.Note__c) && getnote.Note__c.indexOf( 'com/') > 0){
                 opptext = getnote.Note__c.SubString(getnote.Note__c.LastIndexOf('/')+1,getnote.Note__c.LastIndexOf('/')+16);
             }
@@ -1176,8 +1389,10 @@
     }
 
     public boolean dataCheck(){
-         //20220310 fy lastbuy start 
-         if (quoId!=null){
+        //20220310 fy lastbuy start 
+        // 澧炲姞鍙樻洿鐢ㄦ埛璇环鍒ゆ柇
+        // if (quoId!=null){
+        if (String.isNotBlank(this.oppid) && !is_changed_opp){
             if(!ReservedProductVerification()){
                 if(flglastbuy==1){
                   errorflg = true;
@@ -1197,7 +1412,7 @@
                 //     errormessage =  '璇ユ姤浠峰鎵樺瓨鍦ㄩ鐣欎骇鍝�';
                 //     return false;
                 // }
-              }
+            }
         }
       
       //20220310 fy lastbuy end
@@ -1327,8 +1542,10 @@
             q = New QuoteIrai__c();
         }else{
             // CHAN-BJQ4VZ 绮剧悽鎶�鏈� 2019/12/11 Start
-            List<QuoteIrai__c> qs = New List<QuoteIrai__c>();
-            qs = [select Id,Account__c,Agency_Hospital_Link__c,Name,IraiUser__c,IraiSubject__c,Tender_information__c,
+            List<QuoteIrai__c> qs = New List<QuoteIrai__c>();//obsap 鏂板缁忛攢鍟�1瀛楁 fy satrt Agency1_entrust__c,
+            //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy  Noteplus__c
+            //SWAG-CF589P銆愬鎵樸�戙�怭:OBSAP銆戞姤浠峰鎵樼浉鍏虫柊闇�姹傝瘎浼� fy Lead__c,Opportunity__c,
+            qs = [select Id,Account__c,Agency_Hospital_Link__c,Name,IraiUser__c,IraiSubject__c,Tender_information__c,Agency1_entrust__c,Noteplus__c,Lead__c,Opportunity__c,
                 Preferential_Trading_Price__c,Discount__c,Pricing__c,Unit_Price__c,Offer_Amount__c,TOTAL__c,MultiYearWarrantyTotalPrice__c,QuoteTotal_Page__c,Estimation_List_Price__c,
                 Contract__c,Print_HP_Name__c,Quote_Expiration_Date__c,Quote_Comment__c,IraiName__c,QuoteIrai_Status__c,QuoteProportion__c,Note__c,IraiComment__c
                 From QuoteIrai__c Where Id =:quoId];
@@ -1354,9 +1571,22 @@
         // 鎷涙姇鏍囨姤浠峰鎵� 2020-06-21 update by gzw end
         q.IraiUser__c = quo.IraiUser__c;
         q.IraiName__c = quo.IraiName__c;
+        //obsap 鏂板缁忛攢鍟�1瀛楁 fy staty
+        q.Agency1_entrust__c = quo.Agency1_entrust__c;
+        //obsap 鏂板缁忛攢鍟�1瀛楁 fy staty
         q.QuoteProportion__c = quo.QuoteProportion__c;
         q.CurrencyIsoCode = quo.CurrencyIsoCode;
-        q.Note__c = quo.Note__c;
+        //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy start
+        q.Noteplus__c=quo.Noteplus__c;
+        if(!String.isBlank(quo.Note__c)){
+            q.Note__c = quo.Noteplus__c+'\r\n'+quo.Note__c;
+        }else {
+            q.Note__c = quo.Noteplus__c;
+        }
+        
+        System.debug('===222==='+quo.Noteplus__c+'  ===333===   '+q.Note__c);
+        //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy end
+        // q.Note__c = quo.Note__c;
         q.IraiComment__c = quo.IraiComment__c;
         //----checkbox 銇嵃鍒风洿鍓嶃伀淇濆瓨
         q.Quote_Expiration_Date__c = quo.Quote_Expiration_Date__c;
@@ -1368,15 +1598,19 @@
          q.MultiYearWarrantyTotalPrice__c = qb.MultiYearWarrantyTotalPrice;
          q.QuoteTotal_Page__c = qb.QuoteTotal_Page;
         // CHAN-BJQ4VZ 绮剧悽鎶�鏈� 2019/12/10 END
-
-
+        //SWAG-CF589P銆愬鎵樸�戙�怭:OBSAP銆戞姤浠峰鎵樼浉鍏虫柊闇�姹傝瘎浼� fy start
+        q.Lead__c=leadid;
+        q.Opportunity__c=oppid;
+        //SWAG-CF589P銆愬鎵樸�戙�怭:OBSAP銆戞姤浠峰鎵樼浉鍏虫柊闇�姹傝瘎浼� fy end
         if (quoId==null){
             insert q;
         }else{
             update q;
         }
-        quo =[ SELECT Id,Name,Cancel_Decide__c,CreatedDate, PriceRefreshDate__c,Quote_Print_Date__c,
-                    Quote_Date__c,QuoteToName__c,Quote_Expiration_Date__c,Quote_Comment__c,Tender_information__c,
+        //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy  Noteplus__c
+        //SWAG-CF589P銆愬鎵樸�戙�怭:OBSAP銆戞姤浠峰鎵樼浉鍏虫柊闇�姹傝瘎浼� fy Lead__c,Opportunity__c,
+        quo =[ SELECT Id,Name,Cancel_Decide__c,CreatedDate, PriceRefreshDate__c,Quote_Print_Date__c,//obsap 鏂板缁忛攢鍟�1瀛楁 fy satrt Agency1_entrust__c,
+                    Quote_Date__c,QuoteToName__c,Quote_Expiration_Date__c,Quote_Comment__c,Tender_information__c,Agency1_entrust__c,Noteplus__c,Lead__c,Opportunity__c,
                     TOTAL__c,Discount__c,Pricing__c,Preferential_Trading_Price__c,Contract__c,LastIraiUser__c,MultiYearWarrantyTotalPrice__c,QuoteTotal_Page__c,Estimation_List_Price__c,
                     Print_HP_Name__c,Account__c,Agency_Hospital_Link__c,IraiUser__c,IraiSubject__c,CurrencyIsoCode,IraiName__c,QuoteIrai_Status__c,QuoteProportion__c,Note__c,IraiComment__c
                     FROM QuoteIrai__c Where Id =:q.Id];
@@ -1437,7 +1671,18 @@
             quoId = q.Id;
             
         }
-
+        //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy start
+        // if(quo.Note__c!=''){
+        if(String.isNotBlank(quo.Note__c)){
+            system.debug('===444==='+quo.Note__c.split('\r\n'));
+            List<String> str=quo.Note__c.split('\r\n');
+            if(str.size()==1){
+                quo.Note__c=''; 
+            }else{
+                quo.Note__c=str[1]; 
+            }
+        }
+        //XLIU-CFE8M7 銆愬鎵樸�戙�怭-OBSAP銆戞姤浠峰鎵樹换鍔℃敼鍠� fy end
         return true;
     }
      //lastbuy  2022/3/10 fy start
@@ -1549,7 +1794,8 @@
     public Decimal QuoteTotal_Page { get; set; }
     //NoDiscount price 鍚堣
     public Decimal MultiYearWarrantyTotalPrice { get; set; }
-    
+    //obsap 鏂板缁忛攢鍟�1瀛楁 fy
+    public Decimal SalesCalculation1 { get; set; }
     }
     // CHAN-BJQ4VZ 绮剧悽鎶�鏈� 2019/12/11 End
     

--
Gitblit v1.9.1