编辑代码

/*
名称:fnCreatInvoice
功能:
参数:    {      
        'nResId': 0,
        'nAccId': 0,               //
        'nClientId': 0,          //以上fnGetReservationData().nResId/nAccId/nClientId -done
        'nPropertyId': 0,        //fnGetPropertyId()            -done
        'nAccountType': 0,           //menu pop-up window
        'nKeyRmNumber': 0,              //menu pop-up window

        'objReceipt':{
            'strCreditCard': ' ',           //wndMenu
            'nReceiptType':0,               //wndMenu 1.ASR-poits 2.cash 3.cheque 4.credit-card 
            'strDate': '',                  //fnGetDateInDDMMMYYYY      -done   -checked
            'nCreditCardId': 0,             //fnGetCreditCardId         -done   -checked
            'nAmount': 0,            //wndMenu
            'strComments': '',              //wndMenu
            'nInvoiceNo': 0,                //problem--how to get invoiceNo and how to invoice multiple items at same time
            'dateTime': new Date()
        }  
    } 

返回:
问题:
*/
function fnCreatInvoice(objReservationDetails) {
    let objLocal = JSON.parse(window.sessionStorage.getItem('RMS-INOUTMOVEMENTS'));
    let xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", "https://app9.rmscloud.cn/api/TaxInvoice/ProcessTaxInvoice", true);
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            //to do
            console.log(xmlhttp.responseText);

            let objLocal = JSON.parse(window.sessionStorage.getItem('RMS-INOUTMOVEMENTS'));
            let xmlhttpInner = new XMLHttpRequest();
            xmlhttpInner.open("POST", "https://app9.rmscloud.cn/api/Report/Token/Accounting/TaxInvoice", true);
            xmlhttpInner.onreadystatechange = function () {
                if (xmlhttpInner.readyState == 4 && xmlhttpInner.status == 200) {
                    console.log(xmlhttpInner.responseText);
                    let xmlhttp1 = new XMLHttpRequest();
                    xmlhttp1.open("POST", "https://app9.rmscloud.cn/api/ReportService/ReportPathPost?ReportId=40231&ReportName=Tax+Invoice&ReportType=1&ScheduleId=0", true);
                    xmlhttp1.onreadystatechange = function () {
                        if (xmlhttp1.readyState == 4 && xmlhttp1.status == 200) {
                            console.log(xmlhttp1.responseText);
                            window.open(JSON.parse(xmlhttp1.responseText).PostPath + "?Token=" + JSON.parse(xmlhttp1.responseText).PostToken + "&parameters=" + JSON.parse(xmlhttp1.responseText).PostData);
                        }
                    }

                    let aryParam = [
                        JSON.parse(xmlhttp.response).TaxInvoices[0].TaxInvoiceNo,
                        true,
                        "TI10305CHINA",
                        JSON.parse(window.localStorage.getItem('RM_Property')).data.split('_')[0],
                        0,
                        false,
                        window.objGlobalParam.objReservationDetails.ResScreenData.AccountId,
                        "1,2,4,5,6,12",
                        "¥",
                        "/shareddata/14910/RMSWIN/",
                        null,
                        "false",
                        window.objGlobalParam.objReservationDetails.ResScreenData.ResId,
                        "",
                        false,
                        new Date().getFullYear() + '-' + (parseInt(new Date().getMonth()) + 1) + '-' + new Date().getDate() + "T00:00:00",
                        new Date().getFullYear() + '-' + (parseInt(new Date().getMonth()) + 1) + '-' + new Date().getDate() + "T00:00:00",
                        false,
                        1,
                        "",
                        false,
                        false,
                        new Date().getFullYear() + '-' + (parseInt(new Date().getMonth()) + 1) + '-' + new Date().getDate() + "T00:00:00",
                        false,
                        new Date().getFullYear() + '-' + (parseInt(new Date().getMonth()) + 1) + '-' + new Date().getDate() + "T00:00:00",
                        false,
                        "",
                        JSON.parse(window.sessionStorage.getItem('InitData')).data.VersionNo,     //JSON.parse(window.sessionStorage.getItem('InitData')).data.VersionNo
                        44,
                        JSON.parse(window.localStorage.getItem('RM_Property')).data.split('_')[0],
                        false,
                        "",
                        "",
                        "0001-01-01T00:00:00"
                    ]

                    xmlhttp1.setRequestHeader('content-Type', 'application/json; charset=utf-8');
                    xmlhttp1.send(JSON.stringify(aryParam));
                }
            }

            //continue
            let dateYYYYMMDD = new Date().getFullYear() + '-' + (parseInt(new Date().getMonth()) + 1) + '-' + new Date().getDate();

            let objParam = {
                "ReportId": 40231,
                "ScheduleId": 0,
                "TaxInvoiceNos": JSON.parse(xmlhttp.response).TaxInvoices[0].TaxInvoiceNo,        //
                "IsReprint": false,
                "AltTaxInvoice": "TI10305CHINA",
                "PropertyId": JSON.parse(window.localStorage.getItem('RM_Property')).data.split('_')[0],               //
                "SortById": 0,
                "IsTaxInvoiceProforma": false,
                "AccountId": JSON.parse(xmlhttp.response).TaxInvoices[0].AccountNo,           //
                "AccountTypeIDs": "1,2,4,5,6,12",
                "CurrencySymbol": "¥",
                "SharedDataPath": "/shareddata/14910/RMSWIN/",
                "EmailTo": "",
                "IsThermalPrint": false,
                "ResId": window.objGlobalParam.objReservationDetails.ResScreenData.ResId,                //
                "FromEmail": "",
                "ProformaUseDateRange": false,
                "ProformaStartDate": dateYYYYMMDD,       //
                "ProformaEndDate": dateYYYYMMDD,         //
                "IsEmailOverride": false,
                "ReportType": 1,
                "LetterHistoryIds": "",
                "IsRestrictedUser": false,
                "InvoiceDueDateEnabled": false,
                "InvoiceDueDate": dateYYYYMMDD,          //
                "DirectDebitDateEnabled": false,
                "DirectDebitDate": dateYYYYMMDD,         //
                "RePrint_Nos": "",
                "UseGovInvoiceAudit": false,
                "NinePlusVersionNo": "",
                "CountryRunningFrom": 44,
                "CurrencyView": 0
            }

            xmlhttpInner.setRequestHeader('content-Type', 'application/json; charset=utf-8');
            xmlhttpInner.send(JSON.stringify(objParam));
        }
    }

    let objParam = {
        "GroupedInvoice": false,
        "PropertyId": JSON.parse(window.localStorage.getItem('RM_Property')).data.split('_')[0],
        "lstOfAccountsToProcess": [
            {
                "AccNo": window.objGlobalParam.objReservationDetails.ResScreenData.AccountId,       //to do
                "AccType": window.objGlobalParam.nAccountType,            //to do
                "TransIds": []
            }
        ],
        "DueDateOverride": "1990-01-01T00:00:00"
    }
    xmlhttp.setRequestHeader('content-Type', 'application/json; charset=utf-8');
    xmlhttp.send(JSON.stringify(objParam));
}