<?xml version="1.0" encoding="UTF-8"?> 
 | 
<WebLink xmlns="http://soap.sforce.com/2006/04/metadata"> 
 | 
    <fullName>upload_To_Recognition_Model_new</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")} 
 | 
{!RequireScript("/resource/CommonUtilJs")} 
 | 
//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</url> 
 | 
</WebLink> 
 |