| <?xml version="1.0" encoding="UTF-8"?> | 
| <WebLink xmlns="http://soap.sforce.com/2006/04/metadata"> | 
|     <fullName>Loaner_arranged_e_mail</fullName> | 
|     <availability>online</availability> | 
|     <displayType>button</displayType> | 
|     <linkType>javascript</linkType> | 
|     <masterLabel>出库指示</masterLabel> | 
|     <openType>onClickJavaScript</openType> | 
|     <protected>false</protected> | 
|     <url>{!RequireScript("/soap/ajax/51.0/connection.js")}  | 
| {!RequireScript("/soap/ajax/51.0/apex.js")} | 
| var buttons = document.getElementsByName('loaner_arranged_e_mail'); | 
| for (var i=0; i<buttons.length; i++) | 
| { | 
|     buttons[i].className = "btnDisabled"; | 
|     buttons[i].disabled = true; | 
| } | 
|   | 
| var campaignStatus = '';   | 
| var records = null;  // 20220217 ljh  OBPM市场活动联动 | 
| var statusSting = "{!$Label.StatusProcessState}"; // 20220322 ljh add | 
| var statusList = statusSting.split(',');  | 
| var raliveryGood = new Array(); | 
| reliveryGood = sforce.connection.query("select Id,Campaign__c,Repair__c,Status__c, Demo_purpose1__c,Contract_pdf_updated__c,Repair_Final_Inspection_Date_F__c,RC_return_to_office__c from Rental_Apply__c where Name='{!Rental_Apply_Equipment_Set__c.Rental_Apply__c}'");  | 
| var rarecords= reliveryGood.getArray("records"); | 
| var RentalApply = rarecords[0]; | 
|   | 
| if(RentalApply.Campaign__c != '' && RentalApply.Campaign__c != null) {  | 
|     var DeliveryGood = new Array(); | 
|     // 20220217 ljh update OBPM市场活动联动 start | 
|     // DeliveryGood = sforce.connection.query("select Status, Rental_Apply_Flag__c from Campaign where id ='" + RentalApply.Campaign__c +  "'");  | 
|     // var records= DeliveryGood.getArray("records");  | 
|     DeliveryGood = sforce.connection.query("select Status, Rental_Apply_Flag__c,IF_Approved__c,Meeting_Approved_No__c,Approved_Status__c from Campaign where id ='" + RentalApply.Campaign__c +  "'");   | 
|     records = DeliveryGood.getArray("records");  | 
|     // 20220217 ljh update OBPM市场活动联动 end | 
|   | 
|     campaignStatus = records[0].Status;  | 
| } | 
|   | 
| if("{!Rental_Apply__c.Wei_Assigned_Cnt__c}" > "0") {  | 
|     alert("申请单内存在未分配的配套,请分配备品或分割申请单");  | 
| // 20230220 ljh DB202301265636 start | 
| // }else if(campaignStatus == '取消'){  | 
| //     alert("学会取消,不可出库指示");  | 
| }else if(campaignStatus == '取消' || campaignStatus == '取消申请中'){  | 
|     alert("学会取消申请中或者已取消,不可出库指示"); | 
| // 20230220 ljh DB202301265636 end   | 
| }else if ("{!Rental_Apply_Equipment_Set__c.Assigned_Not_Shipment__c}" == "0") { | 
|     alert("没有可以出库指示的明细"); | 
| } else if (RentalApply.Demo_purpose1__c == "长期借出" && RentalApply.Contract_pdf_updated__c == "0") { | 
|     alert("长期借出时,必须先上传契约书"); | 
| } else if(RentalApply.Repair__c != '' && RentalApply.Repair__c != null && (RentalApply.Repair_Final_Inspection_Date_F__c != null && RentalApply.Repair_Final_Inspection_Date_F__c != '') || (RentalApply.RC_return_to_office__c != null && RentalApply.RC_return_to_office__c != '')) {  | 
|     alert("修理有最终检测日或修理品返送日,不可出库指示"); | 
| // 20220217 ljh add OBPM市场活动联动 start | 
| } else if (records != null && records[0].IF_Approved__c == "true" && (records[0].Meeting_Approved_No__c == null || records[0].Meeting_Approved_No__c == "") ) { | 
|     alert("没有决裁号的,暂不能出借,请更新裁决信息。"); | 
| } else if (records != null && records[0].IF_Approved__c == "true" && records[0].Meeting_Approved_No__c != "" && statusList.indexOf(records[0].Approved_Status__c) != -1 ) { | 
|     alert("已申请决裁但决裁状态不符合条件。"); | 
| // 20220217 ljh add OBPM市场活动联动 end | 
| } else { | 
|     sforce.connection.sessionId = "{!GETSESSIONID()}";  | 
| //154p 1388 yc 20211020  | 
|     var raid = RentalApply.Id+";"+"{!Rental_Apply_Equipment_Set__c.Id}";  | 
|     var rs1 = sforce.apex.execute("RentalApplyWebService", "approvalCheck", {rentalApplyId: raid});  | 
|     if (rs1 != '1') { | 
|         alert(rs1); | 
|     } else { | 
| //bp2        var rs2 = sforce.apex.execute("RentalApplyWebService", "reserve", {rentalApplyId: raid});  | 
| //bp2        if (rs2 != '1') { | 
| //bp2            alert(rs2); | 
| //bp2        } else { | 
|   | 
|                sforce.apex.execute("RentalApplyWebService", "setRaesShipment_request", {raesid: "{!Rental_Apply_Equipment_Set__c.Id}"},function(res) { | 
|             if (res == "状态更新到已出库指示") { | 
|                 alert("状态更新到已出库指示"); | 
|                 print(); | 
|                 setTimeout(function() { | 
|                         location.href = "/{!Rental_Apply__c.Id}"; | 
|                     } | 
|                     , 100 | 
|                 ); | 
|             } else { | 
|                 alert(res); | 
|             } | 
|         }); | 
| //bp2        } | 
|     } | 
| } | 
| function print(){ | 
| var sql; | 
| if('{!Rental_Apply__c.Bollow_Date__c}' != ''){ | 
|     sql = "select Id from Rental_Apply_Equipment_Set__c where Rental_Apply__c = '" + RentalApply.Id +  "' and Shippment_loaner_time2__c != null and RAES_Status__c != '已分配' and RAES_Status__c != '取消分配'"; | 
| }else{ | 
|     sql = "select Id from Rental_Apply_Equipment_Set__c where Rental_Apply__c = '" + RentalApply.Id +  "' and RAES_Status__c != '已分配' and RAES_Status__c != '取消分配'"; | 
| } | 
| var sqlResult = sforce.connection.query(sql); | 
| var records = sqlResult.getArray("records"); | 
| var size =records.length; | 
| var length = size%10 ==0? size/10 : parseInt(size/10) +1; | 
| for(var i =0;i<length;i++){ | 
|     window.open('/apex/FixtureRentalPDF?raid=' + RentalApply.Id + '&page=' + i); | 
| } | 
| } | 
|   | 
|   | 
| function fixTime(time){ | 
|    if(time < 10) {time = "0" + time}; | 
|    return time; | 
| } | 
| function fixDate(date){ | 
|   var Month = fixTime(date.getMonth() + 1); | 
|   var Day = fixTime(date.getDate()); | 
|   var UTC = date.toUTCString(); | 
|   var Time = UTC.substring(UTC.indexOf(':')-2, UTC.indexOf(':')+6); | 
|   var Minutes = fixTime(date.getMinutes()); | 
|   var Seconds = fixTime(date.getSeconds()); | 
|   return date.getFullYear() + "-" +  Month + "-" + Day + "T" + Time;   | 
| }</url> | 
| </WebLink> |