binxie
2024-01-16 1b08402678deb31bba4a347bfd388eba8360cbc1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import { LightningElement,wire,track,api} from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
 
import  init  from '@salesforce/apex/lexToAddMaintenanceContractController.initUploadToRecognition';
import  updateColunm  from '@salesforce/apex/otherButtonMaintenanceContractCtl.updateColunm';
import  up2sap  from '@salesforce/apex/LexOtherButtonMc.up2sap';
 
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
import lexSendNfm103 from '@salesforce/resourceUrl/lexSendNfm103';  
 
export default class lexUploadToRecognition extends LightningElement {
    @api recordId;
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        if (currentPageReference) {
            const urlValue = currentPageReference.state.recordId;
            if (urlValue) {
                let str = `${urlValue}`;
                this.recordId = str;
            }
        }
    }
 
    connectedCallback(){
        Promise.all([
            loadStyle(this,lwcCSS),
            loadStyle(this, lexSendNfm103)
        ]);
        init({
            recordId: this.recordId
        }).then(returnData => {
            if(returnData) {
                console.log(returnData);
                this.dispatchEvent(new CloseActionScreenEvent());
                debugger
                this.IsLoading = false;
                var records = returnData
                var msg = '';
                var j =0;
                for(var i=0;i<records.length;i++) {
                    j = i+1;
                    var fooResult = this.foo(records[i]);
                    if(fooResult != '1') {
                        msg += '【'+j+'】'+records[i].Name+': ' + fooResult +'\n';
                        console.log(msg);
                        console.log('record'+i+records[i]);
                    }
 
                }
            }
            if(msg ) {
                this.showToast(msg,'error');
                return;
            }
 
            if(!confirm('请确认是否要上传认款合同。')){
                return;
            }
            for(var i=0;i<records.length;i++) {
                var rst = this.up2sapJs( records[i].Id);
                if(rst!='1') {
                    this.showToast('上传认款合同失败','error');
                    return;
                }
            }
            this.showToast('上传认款合同成功','success');
                        
        });    
    }
 
    foo(mc){
        var resultMsg = '';
    // var resultMsg = '【'+mc.Name+'】';
        if(mc.Contract_quotation_or_not__c == '还没做报价'){
            resultMsg +="您还没有做合同报价,不能上传认款合同。";
            return resultMsg ;
        }else if(!mc.Decided_Estimation__c) {
            resultMsg += '合同报价还没有decide,不能上传认款合同。';
            return resultMsg ;
        }else if (mc.Maintenance_Contract_No__c=='' || mc.Maintenance_Contract_No__c==null) {
            resultMsg +="合同号码为空,不能上传认款合同。";
            return resultMsg ;
        }else if (mc.upload_to_sap_time__c != '' && mc.upload_to_sap_time__c != null) {
            resultMsg +="已经上传SAP,不能再次上传认款合同。";
            return resultMsg ;
        }else if(mc.upload_to_RM_time__c != '' && mc.upload_to_RM_time__c != null){
            resultMsg +="已经上传认款合同,不能再次上传认款合同。";
            return resultMsg ;
        }else{
            if(mc.old_Is_RecognitionModel__c=='false' || mc.old_Is_RecognitionModel__c==false){
                resultMsg +="经销商为空或经销商不是先款对象,不需要上传认款合同。";
                return resultMsg ;
            }else if(mc.Payment_Plan_Sum_First__c == '' || mc.Payment_Plan_Sum_First__c == null ){
                resultMsg +="第一次计划付款金额不能为空。";
                return resultMsg ;
            }else{
                return '1';
 
 
            }
        }
        return resultMsg;
    }
    
    async up2sapJs (mcid) {
        var resultMsg = '1';
        await updateColunm({
            mcid: mcid
        }).then(result => {
            if (result != '1') {
                resultMsg = '2';
                return resultMsg ;
                // this.ShowToastEvent('上传认款合同失败,因为 来年合同相关信息修改失败', "error");
                // this.dispatchEvent(new CloseActionScreenEvent());
            }
        })
        await up2sap({
            mcid: mcid
        }).then(rtn => {
            if (rtn == '1') {
                resultMsg ="1";
            } else {
                resultMsg ='3';
            }
            return resultMsg ;
        })
    
    }
    showToast(msg,type) {
        if(type == 'success'){
            const event = new ShowToastEvent({
                message: msg,
                variant: type
            });
            this.dispatchEvent(event);
        }else{
            const event = new ShowToastEvent({
                message: msg,
                variant: type,
                mode: 'sticky'
            });
            this.dispatchEvent(event);
        }
    }
}
 
// old js 
//zhangzhengmei 2023/06/28 start
/*var executeFoo = function() {
 
    var mcpid = '{!MaintanceContractPack__c.Id}';
    console.log('mcpid ='+mcpid);
    var sql = "select Id,Name,Decided_Estimation__c,Contract_quotation_or_not__c,Maintenance_Contract_No__c,upload_to_sap_time__c,upload_to_RM_time__c,old_Is_RecognitionModel__c,Payment_Plan_Sum_First__c from Maintenance_Contract__c where MaintanceContractPack__c='" + mcpid + "'";
    var sqlResult = sforce.connection.query(sql);
    var records = sqlResult.getArray("records");
    var msg = '';
    for(var i=0;i<records.length;i++) {
        j = i+1;
        var fooResult = foo(records[i]);
        if(fooResult != '1') {
            msg += '【'+j+'】'+records[i].Name+': ' + foo(records[i]) +'\n';
            console.log(msg);
            console.log('record'+i+records[i]);
        }
 
    }
    if(msg ) {
        alert(msg);
        return;
    }
 
    if(!confirm('请确认是否要上传认款合同。')){
        return;
    }
    for(var i=0;i<records.length;i++) {
        var rst = up2sapJs( records[i].Id);
        if(rst!='1') {
            alert('上传认款合同失败');
            return;
        }
    }
    alert('上传认款合同成功');
 
}
executeFoo();
function foo(mc){
    var resultMsg = '';
// var resultMsg = '【'+mc.Name+'】';
    if(mc.Contract_quotation_or_not__c == '还没做报价'){
        resultMsg +="您还没有做合同报价,不能上传认款合同。";
        return resultMsg ;
    }else if(!mc.Decided_Estimation__c) {
        resultMsg += '合同报价还没有decide,不能上传认款合同。';
        return resultMsg ;
    }else if (mc.Maintenance_Contract_No__c=='' || mc.Maintenance_Contract_No__c==null) {
        resultMsg +="合同号码为空,不能上传认款合同。";
        return resultMsg ;
    }else if (mc.upload_to_sap_time__c != '' && mc.upload_to_sap_time__c != null) {
        resultMsg +="已经上传SAP,不能再次上传认款合同。";
        return resultMsg ;
    }else if(mc.upload_to_RM_time__c != '' && mc.upload_to_RM_time__c != null){
        resultMsg +="已经上传认款合同,不能再次上传认款合同。";
        return resultMsg ;
    }else{
        if(mc.old_Is_RecognitionModel__c=='false' || mc.old_Is_RecognitionModel__c==false){
            resultMsg +="经销商为空或经销商不是先款对象,不需要上传认款合同。";
            return resultMsg ;
        }else if(mc.Payment_Plan_Sum_First__c == '' || mc.Payment_Plan_Sum_First__c == null ){
            resultMsg +="第一次计划付款金额不能为空。";
            return resultMsg ;
        }else{
            return '1';
 
 
        }
    }
    return resultMsg;
}
function up2sapJs (mcid) {
    sforce.connection.sessionId = '{!$Api.Session_ID}';
    var resultMsg = '1';
    var result = sforce.apex.execute("MaintenanceContractSetColunmWebService","updateColunm",{mcid: mcid});
    if (result != '1'){
        resultMsg = '2';
        return resultMsg ;
//"上传认款合同失败,因为 来年合同相关信息修改失败";
    }
//上传认款合同
    var rtn = sforce.apex.execute("MaintenanceContractWebService", "up2sap", {mcid: mcid});
    if (rtn == '1') {
        resultMsg ="1";
    } else {
        resultMsg ='3';
    }
    return resultMsg ;
}*/
 
 
//zhangzhengmei 2023/06/28 end