编辑代码


/**/
function fnCheckOut(nResId) {
    let xmlhttp = new XMLHttpRequest();
    let objParam = {
        "ResStatus": 3,
        "Reservations": [nResId]
    };
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            alert('退房成功');
            console.log(xmlhttp.responseText);
            let objParam = {
                "strName": "fnCallBackCheckOut",
                "objValue": null,
                "bIfContinue": true,
                "strErrorDescription": "多余一个账单号,请手动操作"
            }
            window.postMessage(objParam);
        }
        else if (xmlhttp.status == 500) {
            let objParam = {
                "strName": "fnCallBackCheckOut",
                "objValue": null,
                "bIfContinue": false,
                "strErrorDescription": xmlhttp.responseText
            }
            window.postMessage(objParam);
        }
    }

    xmlhttp.open("POST", "https://app9.rmscloud.cn/api/Reservation/ResStatus/ChangeStatus");
    xmlhttp.setRequestHeader('content-Type', 'application/json; charset=utf-8');
    xmlhttp.send(JSON.stringify(objParam));
}

/*
名称:fnCreateInvoice
功能:
参数:    {      
            '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()
            }  
    } 

返回:
问题:other than credit card payment
*/
function fnCreateInvoice(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);
                            let objParam={
                                "strName": "fnCallBackCreateInvoice",
                                "bIfContinue":true
                            }
                            window.postMessage(objParam);
                            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));
}
/*
Name: fnAutoReceipt
Function: post receipt to the account only 
Param: Window.objGlobalParam.objReservationDetails/fAryAccountBalance
Return: -1 for error
        reservation details
Future: cheque
        cash
 */
function fnAutoReceipt(objReservationDetails, fAryAccountBalance) {
    /*  let objBuffer = 
        {      
            '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()
            }  
        }
     */
    let bIfContinue = true;
    let dateDeparture = new Date(objReservationDetails.ResScreenData.ResRows[5].ValueText);
    let dateToday = new Date();
    let nCreditCardId = 0;

    dateToday.setHours(0, 0, 0, 0);
    dateDeparture.setHours(0, 0, 0, 0);

    if (dateDeparture.getTime() !== dateToday.getTime()) {
        console.log('continue');
        bIfContinue = false;
    }



    if (bIfContinue) {

        //DD MMM YYYY
        let strDate = new Date(objReservationDetails.ResScreenData.ResRows[5].ValueText);

        let strAryMonth = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

        if (strDate != 'undefined') {

            let strCreditCard = prompt('Please enter the credit card type \n AC: Alicredit \n WC: Wechatcredit \n GC: Great Wall Card \n UC: UnionPay ', 'WC');
            strCreditCard = strCreditCard.toUpperCase();

            if (strCreditCard.match('AC'))
                strCreditCard = 'Alicredit';
            else if (strCreditCard.match('WC'))
                strCreditCard = 'Wechatcredit';
            else if (strCreditCard.match('GC'))
                strCreditCard = 'Great Wall Card';
            else if (strCreditCard.match('UC'))
                strCreditCard = 'UnionPay';
            else {
                strCreditCard = 'undefined'
                alert('无法识别信用卡类别,仅支持AC(ali),WC(Wechatcredit),GC(Great Wall Card),UC(UnionPay)');
                bIfContinue = false;

            }


            let objAryCCList = JSON.parse(window.localStorage.getItem('CreditCardList'));

            //get card id
            for (let nCounter = 0; nCounter < objAryCCList.length; nCounter++) {
                if (objAryCCList[nCounter].CreditCard == strCreditCard) {
                    nCreditCardId = objAryCCList[nCounter].CardId;
                }
            }
            if (nCreditCardId == 0) {
                alert('无法识别信用卡类别,请重试');
                bIfContinue = false;
            }
        }
        if (bIfContinue) {
            let nAmount = fAryAccountBalance[5];

            nAmount = prompt('Please Check the amount of receipt', nAmount);

            let jobj = {
                "ReceiptType": 4,       //guess sort by ASR-poits cash cheque credit-card
                "Source": 3000,
                "DateOfReceiptOverride": strDate.getDate() + ' ' + strAryMonth[strDate.getMonth()] + ' ' + strDate.getFullYear(),      //变量-DONE
                "CreditCardNumber": "",
                "CreditCardExpiry": "",
                "NameOnCreditCard": " ",
                "CreditCardId": nCreditCardId,                              //DONE
                "CreditCardCCVNo": "",
                "lstOfAccountsToPay":
                    [{
                        "AccountType": 1,                          //'Accomm','Incidentals','Folio 3','Tom will be better!','Bonds','Folio 5','A/R'
                        "ReceiptAmount": nAmount,                       //wndMenu
                        "SecondCurrency": 0,
                        "AccountNo": objReservationDetails.ResScreenData.AccountId,                       //fnGetReservationData
                        "ManualChargeAllocationTransIds": [],
                        "InvoiceNo": 0,                              //bool?
                        "ExchangeRateOverridden": 0
                    }],
                "Tip": 0,
                "Comment": '',
                "JournalId": "",
                "DateBanked": strDate.getDate() + ' ' + strAryMonth[strDate.getMonth()] + ' ' + strDate.getFullYear(),                 //same data?
                "Drawer": "",
                "Tendered": 0,
                "ChequeNo": "",
                "Bank": "",
                "CreditCardTransactionFeeType": 0,
                "Branch": "",
                "PostCode": "",
                "State": "",
                "StreetNo": null,
                "Authorization": "",
                "PropertyId": JSON.parse(window.localStorage.getItem('RM_Property')).data.split('_')[0],                           //fnGetPropertyId();
                "EFTPOSStationNo": "",
                "EftposTerminalId": 0,
                "TokenId": 0,
                "DemoOrInternal": false,
                "ExcludeOnlinePayment": false,
                "IgnoreARAllocationCheck": false,
                "SecurityDeposit": false,
                "CurrencyCode": "¥",
                "Addr1": "",
                "Addr2": "",
                "ClientResidence": 0,
                "ExchangeRateId": 0,
                "GatewayProvider": 13,
                "ClientId": objReservationDetails.ResScreenData.ClientId,                        //fnGetReservationData
                "CreditCardFee": 0,
                "UsingEFTPOSTerminal": false,
                "Token": "",
                "ResId": objReservationDetails.ResScreenData.ResId,                               //fnGetReservationData
                "CompId": 0,
                "AgentId": 0,
                "PayByLinkOption": 0,
                "PayByLinkFrom": "",
                "PayByLinkTo": "",
                "PayByLinkEntityId": "",
                "PayByLinkEntityType": "",
                "PayByLinkLetterId": 0
            }
            console.log(jobj);
            if (1) {
                let xmlhttp = new XMLHttpRequest();
                xmlhttp.open("POST", "https://app9.rmscloud.cn/api/Receipt/ProcessReceiptOnAccountScreen", true);
                xmlhttp.onreadystatechange = function () {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                        let objParam = {
                            "strName": "fnCallBackAutoReceipt",
                            "objValue": null,
                            "bIfContinue": true,
                            "strErrorDescription": ""
                        }
                        window.postMessage(objParam);
                    }
                }

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

            }
        }
    }

}
/*
Name: fnCancelInvoiceNumber
Function: get reservation details by reservation number
Param: invoice number
Return: -1 for error
        reservation details
*/
function fnCancelInvoiceNumber(nInvoiceNumber) {
    let xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", "https://app9.rmscloud.cn/api/TaxInvoice/CancelTaxInvoice", true);
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

            console.log('账单号已清理');
            console.log(xmlhttp.responseText);
            let objParam = {
                "strName": "fnCallBackCancelInvoiceNumber",
                "objValue": null,
                "bIfContinue": true,
                "strErrorDescription": null
            }
            window.postMessage(objParam);
        }
    }

    let objParam = {
        "InvoiceNo": nInvoiceNumber,
        "PropertyId": JSON.parse(window.localStorage.getItem('RM_Property')).data.split('_')[0],
        "ReasonId": 47
    }
    xmlhttp.setRequestHeader('content-Type', 'application/json; charset=utf-8');
    xmlhttp.send(JSON.stringify(objParam));
    console.log('fnCancelInvoice is going');
}




/*
Name: fnGetInvoiceNumber
Function: get the invoice of the 
Param: window.objGlobalParam.objReservationDetails
Return: 
        if there are over 1 invoice , post the message with error description
future: be able to cancel all the invoices in the account
 */

function fnGetInvoiceNumber( objReservationDetails)
{
    let xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST","https://app9.rmscloud.cn/api/TaxInvoice/TaxInvoiceScreenData",true);
    xmlhttp.onreadystatechange=function()
      {
        if (xmlhttp.readyState==4)
            {
                if(xmlhttp.status==200){
                    console.log(xmlhttp.responseText);

                    if(JSON.parse(xmlhttp.responseText).TaxInvoiceScreenData.TaxInvoices.length ==1)
                    {
                        let objParam = {
                            "strName": "fnCallBackGetInvoiceNumber",
                            "objValue": '',
                            "bIfContinue":true
                        }
                        window.objGlobalParam.nInvoiceNumber= JSON.parse(xmlhttp.responseText).TaxInvoiceScreenData.TaxInvoices[0].InvoiceNo;
                        window.postMessage(objParam);
                    }
                    else if(JSON.parse(xmlhttp.responseText).TaxInvoiceScreenData.TaxInvoices.length >1 )
                    {
                    //JSON.parse(xmlhttp.responseText).TaxInvoiceScreenData.TaxInvoices[0].InvoiceNo;
                    

                        let objParam = {
                            "strName": "fnCallBackGetInvoiceNumber",
                            "objValue": null,
                            "bIfContinue":true,
                            "strErrorDescription":"多余一个账单号,请手动操作"
                        }
                        window.postMessage(objParam);
                    }
                    else if(JSON.parse(xmlhttp.responseText).TaxInvoiceScreenData.TaxInvoices.length ==0 )
                    {
                    //JSON.parse(xmlhttp.responseText).TaxInvoiceScreenData.TaxInvoices[0].InvoiceNo;
                    

                        let objParam = {
                            "strName": "fnCallBackGetInvoiceNumber",
                            "objValue": null,
                            "bIfContinue":true,
                            "strErrorDescription":"无账单号"
                        }
                        window.postMessage(objParam);
                    }
                }
                

            }
            
    }

    let objParam = {
        "AccNo": objReservationDetails.ResScreenData.AccountId,
        "AccType":1,
        "PropertyId":JSON.parse(window.localStorage.getItem('RM_Property')).data.split('_')[0],
        "ResId":objReservationDetails.ResScreenData.ResId
    };
    xmlhttp.setRequestHeader('content-Type','application/json; charset=utf-8');
    xmlhttp.send(JSON.stringify(objParam));  

}










/*
Name: fnGetAccountBalance
Function: check if accom balance is zero
Param: object of reservation details
Return:     
        fAryAccountBalance= new Array(6);
    let ACCOMM= 0;
    let INCIDENTALS= 1;
    let FOLIO3= 2;
    let BONDS= 3;
    let FOLIO5= 4;
    let SUM= 5;

future:
 */

function fnGetAccountBalance( objReservationDetails)
{
    let objAryAccountRows= objReservationDetails.ResScreenData.AccountRows;

    let ACCOMM= 0;
    let INCIDENTALS= 1;
    let FOLIO3= 2;
    let BONDS= 3;
    let FOLIO5= 4;
    let SUM= 5;
    let fAryAccountBalance= new Array(6);
    fAryAccountBalance[SUM]= 0.00;

    


    for(let nCounter= 0; nCounter< objAryAccountRows.length; nCounter++)
    {
        if( objAryAccountRows[nCounter].Identifier== "Acc_General")
            {
                if(objAryAccountRows[nCounter].ValueText.match(','))
                objAryAccountRows[nCounter].ValueText= objAryAccountRows[nCounter].ValueText.replace(',','')

                fAryAccountBalance[ACCOMM]= parseFloat(objAryAccountRows[nCounter].ValueText);
                fAryAccountBalance[SUM] += parseFloat(objAryAccountRows[nCounter].ValueText)
            }
        else if( objAryAccountRows[nCounter].Identifier== "Acc_Extras")
            {
                if(objAryAccountRows[nCounter].ValueText.match(','))
                objAryAccountRows[nCounter].ValueText= objAryAccountRows[nCounter].ValueText.replace(',','')

                fAryAccountBalance[INCIDENTALS]= parseFloat(objAryAccountRows[nCounter].ValueText);
                fAryAccountBalance[SUM] += parseFloat(objAryAccountRows[nCounter].ValueText)
            }
        else if( objAryAccountRows[nCounter].Identifier== "Acc_Gas")
            {
                if(objAryAccountRows[nCounter].ValueText.match(','))
                objAryAccountRows[nCounter].ValueText= objAryAccountRows[nCounter].ValueText.replace(',','')

                fAryAccountBalance[FOLIO3]= parseFloat(objAryAccountRows[nCounter].ValueText);
                fAryAccountBalance[SUM] += parseFloat(objAryAccountRows[nCounter].ValueText)
            }
        else if( objAryAccountRows[nCounter].Identifier== "Acc_Electricity")
            {
                if(objAryAccountRows[nCounter].ValueText.match(','))
                objAryAccountRows[nCounter].ValueText= objAryAccountRows[nCounter].ValueText.replace(',','')

                fAryAccountBalance[BONDS]= parseFloat(objAryAccountRows[nCounter].ValueText);
                fAryAccountBalance[SUM] += parseFloat(objAryAccountRows[nCounter].ValueText)
            }
        else if( objAryAccountRows[nCounter].Identifier== "Acc_Water")
            {
                if(objAryAccountRows[nCounter].ValueText.match(','))
                objAryAccountRows[nCounter].ValueText= objAryAccountRows[nCounter].ValueText.replace(',','')
                
                fAryAccountBalance[FOLIO5]= parseFloat(objAryAccountRows[nCounter].ValueText);
                fAryAccountBalance[SUM] += parseFloat(objAryAccountRows[nCounter].ValueText)
            }
    }
    

    console.log("get account balance");
    window.objGlobalParam.fAryAccountBalance = fAryAccountBalance;

    return fAryAccountBalance;

}








/*
Name: fnParseFromRmNum2ResNum
Function: get reservation number by room number
Param: room number,In-House reservation list
Return: -1 for error
        reservation number
 */
function fnParseFromRmNum2ResNum(nRmNum, AryObjInhouseReservationList) {
    let objCurrentRes = new Object();

    while (AryObjInhouseReservationList.length) {
        objCurrentRes = AryObjInhouseReservationList.pop();


        if (parseInt(objCurrentRes.Area.split(" ")[0]) == parseInt(nRmNum)) {
            window.objGlobalParam.nReservationId = objCurrentRes.ResId;
            return objCurrentRes.ResId;
        }

    };

    return -1;
}


//arrived number
/*
Name: fnGetInhouseReservationList
Function: Get In-House reservation list
Param: null
Return: In-House reservation list
future: property need to update
 */

function fnGetInhouseReservationList() {
    let date = new Date();
    let strSymble1;
    let strSymble2;

    //如果月或者日小于10,strSymble '-'或者‘-0’
    if (parseInt(date.getMonth()) < 9) {
        strSymble1 = '-0';
    }
    else
        strSymble1 = '-';
    if (parseInt(date.getDate()) < 10) {
        strSymble2 = '-0';
    }
    else
        strSymble2 = '-';
    let objParam = {
        "FromDate": date.getFullYear() + strSymble1
            + parseInt(date.getMonth() + 1) + strSymble2
            + date.getDate(),
        "ToDate": date.getFullYear() + strSymble1
            + parseInt(date.getMonth() + 1) + strSymble2
            + date.getDate(),
        "OnlyShowPrimaryClient": true,
        "ShowGroupMasterOnly": false,
        "Properties": [254],
        "BookingTypeId": 0,
        "ReportView": 3,
        "ResView": 0,
        "CatGrpIds": [],
        "CatIds": []
    }
    let xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            console.log("fnGetInhouseReservationList: ");
            console.log(xmlhttp.responseText);
            //objParam.objReservationDetails= rtn.responseJSON.ResScreenData.ResRows;
            //fnTasksLoop("fnGetReservationDetails",xmlhttp.responseText);
            window.objParam = null;
            window.objParam = (xmlhttp.responseText);

            let objParam = {
                "strName": "fnCallBackGetInhouseReservationList",
                "objValue": JSON.parse(xmlhttp.responseText).InOutData,
                "bIfContinue": true
            }
            window.objGlobalParam.objAryInOutData = JSON.parse(xmlhttp.responseText).InOutData;
            window.postMessage(objParam);
        }
    }

    xmlhttp.open("POST", "https://app9.rmscloud.cn/api/Reservation/InOutScreen/RetrieveScreenData");
    xmlhttp.setRequestHeader('content-Type', 'application/json; charset=utf-8');
    xmlhttp.send(JSON.stringify(objParam));

}


console.log("get reservation list");



/*
Name: fnGetReservationDetails
Function: get reservation details by reservation number
Param: reservation number
Return: -1 for error
        reservation details
 */
function fnGetReservationDetails(nResNumber) {
    let xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            console.log("fnGetReservationDetails: ");
            console.log(xmlhttp.responseText);
            //objParam.objReservationDetails= rtn.responseJSON.ResScreenData.ResRows;
            //fnTasksLoop("fnGetReservationDetails",xmlhttp.responseText);
            let objParam = {
                "strName": "fnCallBackGetReservationDetails",
                "objValue": JSON.parse(xmlhttp.responseText),
                "bIfContinue": 1
            }
            window.objGlobalParam.objReservationDetails = JSON.parse(xmlhttp.responseText);
            window.postMessage(objParam);
        }
    }

    xmlhttp.open("POST", "https://app9.rmscloud.cn/api/ReservationService/ReservationScreenData" +
        "?bEventBooking=false&bShowCancelled=true&bUsePreviousTypeOfBooking=false&nGrpResId=0&nResId=" + nResNumber);
    xmlhttp.setRequestHeader('content-Type', 'application/json; charset=utf-8');
    xmlhttp.send();
}




/*
*名称:fnOnMsg
*功能:1.执行原有的消息机制
        2.视情况执行对应的函数
*参数:msg.data
*返回:无
*问题:是否需要增加函数执行后的响应
*/
function fnOnMsg(msg) {

    //if(!msg.data.bIfContinue)
    if (!msg.data.bIfContinue) {
        alert(msg.strErrorDescription);
        window.onmessage = window.fnOldOnmessage;
        window.sessionStorage.removeItem('aryStrTaskName');
        window.fnOldOnmessage = null;
        window.objGlobalParam = null;
    }
    else if (msg.data.strName.match('fnCallBackGetInhouseReservationList') ||
        msg.data.strName.match('fnCallBackGetAccountBalance') ||
        msg.data.strName.match('fnCallBackParseFromRmNum2ResNum') ||
        msg.data.strName.match('fnCallBackGetInvoiceNumber') ||
        msg.data.strName.match('fnCallBackCancelInvoiceNumber') ||
        msg.data.strName.match('fnCallBackAutoReceipt') ||
        msg.data.strName.match('fnCallBackCreateInvoice') ||
        msg.data.strName.match('start') ||
        msg.data.strName.match('fnCallBackCheckOut') ||
        msg.data.strName.match('fnCallBackGetReservationDetails')
        ) {
        let aryStrTaskName = window.sessionStorage.getItem('aryStrTaskName').split(',');

        switch (aryStrTaskName.pop())
        /*
            "End,"+
            "fnCheckOut,"+
            "fnCreateInvoice,"+
            "fnAutoReceipt,"+
            "fnCancelInvoiceNumber,"+
            "fnGetInoiceNumber,"+
            "fnGetAccountBalance," +            1
            "fnGetReservationDetails,"+
            "fnParseFromRmNum2ResNum,"+
            "fnGetInhouseReservationList") */ {
            case "End":
                window.onmessage = window.fnOldMainOnmessage;
                window.sessionStorage.removeItem('aryStrTaskName');
                window.fnOldMainOnmessage = null;
                objParam = null;
                objMsg = null;
                window.objGlobalParam= null;
                break;
            case "fnGetInhouseReservationList":
                fnGetInhouseReservationList(msg.data);
                window.sessionStorage.setItem('aryStrTaskName', aryStrTaskName);
                break;
            case "fnParseFromRmNum2ResNum":
                msg.data.name = "fnCallBackParseFromRmNum2ResNum"

                fnParseFromRmNum2ResNum(parseInt(prompt("请输入房间号", "")), window.objGlobalParam.objAryInOutData);
                window.sessionStorage.setItem('aryStrTaskName', aryStrTaskName);
                window.postMessage(msg.data);
                break;
            case "fnGetReservationDetails":
                fnGetReservationDetails(window.objGlobalParam.nReservationId);
                window.sessionStorage.setItem('aryStrTaskName', aryStrTaskName);
                break;
            case "fnGetAccountBalance":
                msg.data.strName = "fnCallBackGetAccountBalance";
                msg.data.bIfContinue = true;

                fnGetAccountBalance(window.objGlobalParam.objReservationDetails);

                window.sessionStorage.setItem('aryStrTaskName', aryStrTaskName);
                window.postMessage(msg.data);

                break;
            case "fnGetInvoiceNumber":
                if(window.objGlobalParam.fAryAccountBalance[5]!= 0)
                fnGetInvoiceNumber(window.objGlobalParam.objReservationDetails);
                else
                {
                    msg.data.name= "fnCallBackGetInvoiceNumber";
                    msg.data.bIfContinue= true;

                    postMessage(msg.data);
                }

                window.sessionStorage.setItem('aryStrTaskName', aryStrTaskName);
                break;
            case "fnCancelInvoiceNumber":
                if (window.objGlobalParam.nInvoiceNumber)
                    fnCancelInvoiceNumber(window.objGlobalParam.nInvoiceNumber);
                else
                {
                    msg.data.name= "fnCallBackCancelInvoiceNumber";
                    msg.data.bIfContinue= true;

                    postMessage(msg.data);
                }
                window.sessionStorage.setItem('aryStrTaskName', aryStrTaskName);
                break;
            case "fnAutoReceipt":
                if(window.objGlobalParam.fAryAccountBalance[5]!= 0)
                fnAutoReceipt(window.objGlobalParam.objReservationDetails,window.objGlobalParam.fAryAccountBalance);
                else
                {
                    msg.data.name= "fnCallBackAutoReceipt";
                    msg.data.bIfContinue= true;

                    postMessage(msg.data);
                }
                window.sessionStorage.setItem('aryStrTaskName', aryStrTaskName);
            break;
            case "fnCreateInvoice":
                if(window.objGlobalParam.fAryAccountBalance[5]!= 0)
                fnCreateInvoice(window.objGlobalParam.objReservationDetails);
                else
                {
                    msg.data.name= "fnCallBackCreateInvoice";
                    msg.data.bIfContinue= true;

                    postMessage(msg.data);
                }
                window.sessionStorage.setItem('aryStrTaskName', aryStrTaskName);
            break;

            case "fnCheckOut":

                if (msg.data.nValue != -1)
                    fnCheckOut(window.objGlobalParam.nReservationId);
                    //alert('fnCheckOut');
                else {

                    let objParam = {
                        "strName": "fnCallBackCheckOut",
                        "objValue": null,
                        "bIfContinue": false,
                        "strErrorDescription": "未找到房间"
                    }
                    window.sessionStorage.setItem('aryStrTaskName', aryStrTaskName);
                    window.postMessage(objParam);
                }

                window.sessionStorage.setItem('aryStrTaskName', aryStrTaskName);
                break;

        }
    }
    //old onmessage
    else if (window.fnOldMainOnmessage != null)
        window.fnOldMainOnmessage(msg);



}

//fnMain-->fnOnMsg<==>fnFuntionN
//1.set the string array of task queue name into sessionStorage 
//2.set param if necessary
//3.run the fnMain

//include initialization
function fnMain() {
    //initialization
    window.fnOldMainOnmessage = window.onmessage;
    window.onmessage = fnOnMsg;

    //set tasks
    window.sessionStorage.setItem('aryStrTaskName',
        "End," +
        "fnCheckOut," +
        "fnCreateInvoice," +
        "fnAutoReceipt," +
        "fnCancelInvoiceNumber," +
        "fnGetInvoiceNumber," +
        "fnGetAccountBalance," +
        "fnGetReservationDetails," +
        "fnParseFromRmNum2ResNum," +
        "fnGetInhouseReservationList");
    //let nRoomNumber = parseInt(prompt("请输入房间号",""))
    let objMainMsg = {
        "objParam": '',
        "bIfContinue": 1,
        "strErrorDescription": '',
        "strName": 'start'
    }
    objMainMsg.objParam.nParam = 0;
    window.objGlobalParam = new Object();
    window.objGlobalParam.nAccountType = 1;

    //Entrance
    window.postMessage(objMainMsg);

}

fnMain();

//# sourceURL=my-script.js