binxie
2024-01-22 102afa21c115e8c8b9333a326c3d1af08fe76faf
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
<?xml version="1.0" encoding="UTF-8"?>
<WebLink xmlns="http://soap.sforce.com/2006/04/metadata">
    <fullName>Contract_Authorize</fullName>
    <availability>online</availability>
    <displayType>button</displayType>
    <linkType>javascript</linkType>
    <masterLabel>合同申请</masterLabel>
    <openType>onClickJavaScript</openType>
    <protected>false</protected>
    <url>var btns = document.getElementsByName(&quot;contract_authorize&quot;);
for (var i=0; i&lt;btns.length; i++) {
       btns[i].disabled = true;
       btns[i].className = &apos;btnDisabled&apos;;
}
 
{!REQUIRESCRIPT(&quot;/soap/ajax/51.0/connection.js&quot;)}; 
{!REQUIRESCRIPT(&quot;/soap/ajax/51.0/apex.js&quot;)};
{!RequireScript(&quot;/resource/CommonUtilJs&quot;)};
//2021-10-21 gwy 版本更改为51.0
 
 
var foo = function() {  
  var oppid = &apos;{!Opportunity.Id}&apos;;
  var decide_quote = &apos;{!Opportunity.Estimation_Decision__c}&apos;;
  var complete_day = &apos;{!Opportunity.Contract_DB_complite_day__c}&apos;;
  var if_contract_auth = &apos;{!Opportunity.Contract_Authorize__c}&apos;;
  var if_contract_lock = &apos;{!Opportunity.Contract_Authorize_Lock__c}&apos;;
  var If_Need_Authorize = &apos;{!Opportunity.If_Need_Authorize__c}&apos;;
  var Authorized_DB_No = &apos;{!Opportunity.Authorized_DB_No__c}&apos;;
  var profileId = &apos;{!$User.ProfileId}&apos;; 
  var spoURL = &apos;{!Opportunity.SPO_URL__c}&apos;;
//SWAG-CG88AG【委托】提出价格申请是在协议有效期内,允许WIN fy start 
  var DecidedQuoteNo = &apos;{!Opportunity.Estimation_No__c}&apos;;
//SWAG-CG88AG【委托】提出价格申请是在协议有效期内,允许WIN fy end
//2022-03-22 yjk SWAG-CCL6R7
  var Closing_Bid_Date = &apos;{!Opportunity.Closing_Bid_Date__c}&apos;;//13.中标日
  var Closing_Bid_Date_Bid = &apos;{!Opportunity.Closing_Bid_Date_Bid__c}&apos;;
        
        var AccDealerBlacklist = &apos;{!Opportunity.AccDealerBlacklist__c}&apos;;//判断客户/经销商是否为黑名单
var angency1 = &apos;{!Opportunity.Agency1__c}&apos;;
var angency2 = &apos;{!Opportunity.Agency2__c}&apos;;
var accname = &apos;{!Opportunity.Hospital__c}&apos;;
var ownerids = &apos;{!Opportunity.OwnerId}&apos;;
var ddid = &apos;{!Opportunity.Sales_assistant_name_textId__c}&apos;;
 
  if (profileId != &apos;00e10000000Y3o5&apos; &amp;&amp; profileId != &apos;00e10000000Nab7&apos; &amp;&amp; 
profileId != &apos;00e10000000xnpR&apos; &amp;&amp; profileId != &apos;00e10000000xyK6&apos; &amp;&amp; profileId != &apos;00e10000000xnpW&apos; &amp;&amp; profileId != &apos;00e10000000NbCE&apos; &amp;&amp; profileId != &apos;00e10000000Nb7i&apos; 
&amp;&amp; profileId != &apos;00e10000000xyK6&apos;) { 
        alert(&quot;您没有合同申请的权限。请联系系统管理员。&quot;); 
        return; 
}
//贸易合规 you
var TradeComplianceStatusFlag = &quot;{!$Label.TradeComplianceStatusFlag}&quot;;//贸易合规开关
var IFTradeComplianceAlert = &quot;{!$Label.IFTradeComplianceAlert}&quot;;//贸易合规提醒
if(TradeComplianceStatusFlag==&apos;true&apos;){
//拦截+邮件提醒
var oppflag=false;
if (AccDealerBlacklist==&apos;123&apos;) {
alert(&apos;客户,经销商1,经销商2都为黑名单,不能做合同申请,&apos;+IFTradeComplianceAlert);
oppflag=true;
 
}else if(AccDealerBlacklist==&apos;12&apos;){
alert(&apos;客户,经销商1都为黑名单,不能做合同申请,&apos;+IFTradeComplianceAlert);
oppflag=true;
}else if(AccDealerBlacklist==&apos;23&apos;){
alert(&apos;经销商1,经销商2都为黑名单,不能做合同申请,&apos;+IFTradeComplianceAlert);
oppflag=true;
}else if(AccDealerBlacklist==&apos;13&apos;){
alert(&apos;客户,经销商2都为黑名单,不能做合同申请,&apos;+IFTradeComplianceAlert);
oppflag=true;
}else if(AccDealerBlacklist==&apos;1&apos;){
alert(&apos;客户为黑名单,不能做合同申请,&apos;+IFTradeComplianceAlert);
oppflag=true;
}else if(AccDealerBlacklist==&apos;2&apos;){
alert(&apos;经销商1为黑名单,不能做合同申请,&apos;+IFTradeComplianceAlert);
oppflag=true;
}else if(AccDealerBlacklist==&apos;3&apos;){
alert(&apos;经销商2为黑名单,不能做合同申请,&apos;+IFTradeComplianceAlert);
oppflag=true;
}
if(oppflag){
var opprtn = sforce.apex.execute(&quot;OpportunityWebService&quot;, &quot;accSendEmail&quot;,{&quot;AccDealerBlacklist&quot;:AccDealerBlacklist,&quot;accname&quot;:accname,&quot;angency1&quot;:angency1,&quot;angency2&quot;:angency2,&quot;ownerids&quot;:ownerids,&quot;ddid&quot;:ddid,&quot;oppid&quot;:oppid});
if (opprtn = true) {
return;
}
}
//警示提醒
if (AccDealerBlacklist==&apos;567&apos;) {
if(!confirm(&apos;您所选择的客户,经销商1,经销商2存在贸易合规警示风险,不建议做合同申请,请您确认是否继续申请,&apos;+IFTradeComplianceAlert)){
return;
}
}else if(AccDealerBlacklist==&apos;56&apos;){
if(!confirm(&apos;您所选择的客户,经销商1存在贸易合规警示风险,不建议做合同申请,请您确认是否继续申请,&apos;+IFTradeComplianceAlert)){
return;
}
}else if(AccDealerBlacklist==&apos;67&apos;){
if(!confirm(&apos;您所选择的经销商1,经销商2存在贸易合规警示风险,不建议做合同申请,请您确认是否继续申请,&apos;+IFTradeComplianceAlert)){
return;
}
}else if(AccDealerBlacklist==&apos;57&apos;){
if(!confirm(&apos;您所选择的客户,经销商2存在贸易合规警示风险,不建议做合同申请,请您确认是否继续申请,&apos;+IFTradeComplianceAlert)){
return;
}
}else if(AccDealerBlacklist==&apos;5&apos;){
if(!confirm(&apos;您所选择的客户存在贸易合规警示风险,不建议做合同申请,请您确认是否继续申请,&apos;+IFTradeComplianceAlert)){
return;
}
}else if(AccDealerBlacklist==&apos;6&apos;){
if(!confirm(&apos;您所选择的经销商1存在贸易合规警示风险,不建议做合同申请,请您确认是否继续申请,&apos;+IFTradeComplianceAlert)){
return;
}
}else if(AccDealerBlacklist==&apos;7&apos;){
if(!confirm(&apos;您所选择的经销商2存在贸易合规警示风险,不建议做合同申请,请您确认是否继续申请,&apos;+IFTradeComplianceAlert)){
return;
}
}
}
//贸易合规 you
 
  if(!Closing_Bid_Date){
      alert(&quot;请填写13.中标日。&quot;);
      return;
  }
  
  if (decide_quote != &apos;1&apos;) {
    alert(&apos;请先决定报价。&apos;);
    return;
  }
//SWAG-CG88AG【委托】提出价格申请是在协议有效期内,允许WIN fy start 
  if (DecidedQuoteNo !=&quot;&quot;) {
    var judg=sforce.apex.execute(&quot;OpportunityWebService&quot;,&quot;judgeIsAssistantAppliedOutTime&quot;,{Quoteid:DecidedQuoteNo});
    // alert(&apos;judg得值:&apos;+judg);
    // return;
    if(judg == &apos;false&apos;){
        alert(&apos;经销商协议已过期,请重新做报价计算。&apos;);
        return;
    }
  }
//SWAG-CG88AG【委托】提出价格申请是在协议有效期内,允许WIN fy end
    // 20221009 ljh SWAG-CK29AJ start 
    var ClosingBidDate = &apos;{!Opportunity.Closing_Bid_Date__c}&apos;;
    var BidDate = &apos;{!Opportunity.Bid_Date__c}&apos;;
    if( ClosingBidDate &lt; BidDate){
        alert(&apos;13.中标日不能早于12.招标日&apos;);
        return;
    }
    // 20221009 ljh SWAG-CK29AJ end 
 
  if(If_Need_Authorize == &apos;1&apos; &amp;&amp; (Authorized_DB_No == null || Authorized_DB_No == &apos;&apos;)){
    alert(&apos;请先做授权申请。&apos;);
    return;
  }
 
  if (&apos;{!Opportunity.Cnt_Lost_cancel_Draft__c}&apos; &gt; 0) { 
    if(!confirm(&apos;询价有草案中的取消/失单报告,是否继续?&apos;)){ 
        return ; 
        }
  } else if (&apos;{!Opportunity.Cnt_Lost_cancel_report__c}&apos; - &apos;{!Opportunity.Cnt_Lost_cancel_Draft__c}&apos; &gt; 0) { 
    alert(&apos;询价有已提交的取消/失单报告。&apos;);
    return;
  }
 
 
 
// 2022-03-31 新财年价格调整 start
  var decide_date = &apos;{!Opportunity.DecideQuoteDate__c}&apos;;
  if (decide_date != null &amp;&amp; decide_date &lt; {!DATE(2022,4,1)}) {
    alert(&apos;报价变更,请重新做Decide。&apos;);
    return;
  }
 
// 2022-03-31 新财年价格调整 end
  var sql = &quot;select Id,Contract_Authorize_Lock__c from Opportunity where Id =&apos;&quot; + oppid + &quot;&apos;&quot;;
  var sqlResult = sforce.connection.query(sql);
  var records = sqlResult.getArray(&quot;records&quot;); 
 
  if ((complete_day != null &amp;&amp; complete_day != &apos;&apos;) &amp;&amp; records[0].Contract_Authorize_Lock__c== &apos;true&apos;) {
    alert(&apos;合同申请已经完成,请不要重复提交。&apos;);
    return;
  }
  // if (&apos;{!Opportunity.AcecideCntCheck__c}&apos; != &apos;1&apos;) {
  //   alert(&apos;阿西赛多询价只能包含危化品,或者,普通询价不能包含危化品。&apos;); 
  //   return; 
  // }
  if ((complete_day == null || complete_day == &apos;&apos;) &amp;&amp; records[0].Contract_Authorize_Lock__c== &apos;true&apos;) {
    alert(&apos;合同正在申请中,请不要重复提交。&apos;);
    return;
  }
 
  if (&apos;{!Opportunity.IF_Submit__c }&apos; == &apos;1&apos;) { 
    alert(&apos;上传失败,请联系系统管理员!&apos;);
        return;
  }
 
var angency = &apos;{!Opportunity.Agency1Id__c}&apos;;
if(&apos;{!Opportunity.Trade__c}&apos; == &apos;外貿&apos; || &apos;{!Opportunity.Sales_Root__c}&apos; == &apos;OCM直接販売&apos;){
    var rtn = sforce.apex.execute(&quot;OpportunityWebService&quot;, &quot;updReg&quot;,{oppid:oppid});
} else {
    if(&apos;{!Opportunity.Is_Corrosion__c}&apos; == &apos;1&apos;){
          var rtn1 = sforce.apex.execute(&quot;OpportunityWebService&quot;, &quot;checkDangerItem&quot;,{agency1:angency });    
          if (rtn1 != &apos;OK&apos;) {
            alert(rtn1);
            return;
          }
      }else{
          var rtn = sforce.apex.execute(&quot;OpportunityWebService&quot;, &quot;oppCheck&quot;,{oppid:oppid, saveFlg:&apos;1&apos;});
 
        if (rtn != &apos;OK&apos;) {
              alert(rtn);
              return;
          }
    }
    
      
}
 
  var opp = new sforce.SObject(&apos;Opportunity&apos;); 
  opp.Id = &apos;{!Opportunity.Id}&apos;; 
  opp.Contract_Authorize__c = &apos;1&apos;; 
  opp.if_Interface_Lock__c = &apos;1&apos;; 
  opp.IF_Submit__c = &apos;1&apos;;
  var result = sforce.connection.update([opp]); 
  var messages = getConnectDMLErrorMessages(result); 
  if (messages.length &gt; 0) { 
    alert(messages.join(&quot;\n&quot;)); 
    return; 
  } 
  alert(&apos;提交成功!请在SPO系统中完成合同申请。&apos;);
  
  //window.location.reload();
  window.open(spoURL);  
}; 
foo();</url>
</WebLink>