hls_paperinv_makeinv.lsc 7 KB
Newer Older
Spencer Chang's avatar
Spencer Chang committed
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
<?xml version="1.0" encoding="UTF-8"?>
<!--
        $Author:zhuxianfei
        $Date:2018年08月16日 17:37:51
        $Revision:1.0
        $Purpose:金税纸质发票开票接口
        -->
<a:service xmlns:p="uncertain.proc" xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script"
           trace="true">
    <a:init-procedure>
        <s:server-script><![CDATA[
            importPackage(Packages.com.hand.hls.hlcm.jinsui.service);

            var iService = $spring(IMakeInvService);
            var successCode = '4011'; //成功返回code

            var invoiceHdId = $ctx.parameter.invoiceHdId;

            //开票行信息
            //var query_invoiceLn_bm = $bm('acr.ACR515.acr515_invoice_ln_lv');
            //var query_invoiceLn = query_invoiceLn_bm.queryAsMap({
            //    "invoice_hd_id": $ctx.parameter.invoiceHdId
            //});
            //var list_query_invoiceLn = query_invoiceLn.getChildren();

            var query_invoiceLn_change_bm = $bm('acr.ACR515.acr515_invoice_ln_lv_change');
            var query_invoiceLn_change = query_invoiceLn_change_bm.queryAsMap({
                "invoice_hd_id": $ctx.parameter.invoiceHdId
            });
            var list_query_invoiceLn_change = query_invoiceLn_change.getChildren();

            //封装数据
            var param = {};
            var Data_list = [];

            println(list_query_invoiceLn_change.length);

            //行表有多条数据
            for (var i = 0;i < list_query_invoiceLn_change.length;i++) {
                    param = {
                    ProdName: list_query_invoiceLn_change[i].product_name,
                    TaxItem: list_query_invoiceLn_change[i].line_type_n,
                    Spec: '',
                    Unit: '',
                    Quantity: list_query_invoiceLn_change[i].quantity,
                    Price: list_query_invoiceLn_change[i].total_amount,
                    Amount: list_query_invoiceLn_change[i].total_amount,
                    TaxAmount: ((list_query_invoiceLn_change[i].total_amount)*(list_query_invoiceLn_change[i].tax_type_rate))/100,
                    DisAmount: '0',
                    DisTaxAmount: '0',
                    TaxRate: list_query_invoiceLn_change[i].tax_type_rate,
                    GoodsNoVer: '12.0',
                    GoodsTaxNo: '10301020101',
                    TaxPre: '',
                    TaxPreCon: '',
                    ZeroTax: '',
                    TaxDeduction: ''
                };
                Data_list.push(param);
            }
            //开票头信息
            var query_invoiceHd_bm = $bm('acr.ACR515.acr515_invoice_hd_lv');
            var query_invoiceHd = query_invoiceHd_bm.queryAsMap({
                "invoice_hd_id": $ctx.parameter.invoiceHdId
            });
            var list_query_invoiceHd = query_invoiceHd.getChildren();

            var bp_class =  list_query_invoiceHd[0].bp_class;

            if(bp_class == 'NP'){
                var Json = {
                    //客户名称
                    CustName: list_query_invoiceHd[0].bp_name,
                    //客户税号
                    CustTaxNr: '',
                    //客户地址电话
                    CustAddrTel: '',
                    //客户银行及帐号
                    CustBankAcct: '',
                    //销方地址电话
                    SellerBankAcct: "",
                    //销方银行及帐号
                    SellerAddrTel: "",
                    //开票人
                    KPR: list_query_invoiceHd[0].created_by_name,
                    //复核人
                    FHR: list_query_invoiceHd[0].confirmed_by_name,
                    //收款人
                    SKR: '',
                    //发票类型
                    InvKind: list_query_invoiceHd[0].invoice_kind,
                    //备注
                    Memo: list_query_invoiceHd[0].description,

                    DetailList: Data_list
                };
            }
            else{
                var Json = {
                    //客户名称
                    CustName: list_query_invoiceHd[0].bp_name,
                    //客户税号
                    CustTaxNr: list_query_invoiceHd[0].bp_tax_registry_num,
                    //客户地址电话
                    CustAddrTel: list_query_invoiceHd[0].bp_address_phone_num,
                    //客户银行及帐号
                    CustBankAcct: list_query_invoiceHd[0].bp_bank_account,
                    //销方地址电话
                    SellerBankAcct: "",
                    //销方银行及帐号
                    SellerAddrTel: "",
                    //开票人
                    KPR: list_query_invoiceHd[0].created_by_name,
                    //复核人
                    FHR: list_query_invoiceHd[0].confirmed_by_name,
                    //收款人
                    SKR: '',
                    //发票类型
                    InvKind: list_query_invoiceHd[0].invoice_kind,
                    //备注
                    Memo: list_query_invoiceHd[0].description,

                    DetailList: Data_list
                    };
                 }
            try {
                //将json数组转换成字符串
                var jsonString = JSON.stringify(Json);
                println('----------请求数据-----------');
                println(jsonString);
                println('----------请求数据-----------');

                //发起开票请求
                var resultString = iService.doMakeInv(jsonString);
                println('----------返回结果-----------');
                println(resultString);
                println('----------返回结果-----------');

                //转成Json数组
                var resData = JSON.parse(resultString);

                var InfoAmount = resData.InfoAmount;
                var InfoTaxAmount = resData.InfoTaxAmount;
                var InfoNumber = resData.InfoNumber;
                var InfoInvKind = resData.InfoInvKind;
                var RetCode = resData.RetCode;
                var RetMsg = resData.RetMsg;
                var InvStock = resData.InvStock;
                var InfoDate = resData.InfoDate;
                var InfoTypeCode = resData.InfoTypeCode;
                var TaxCode = resData.TaxCode;
                //println(RetCode);
                //println(RetMsg);

                $ctx.parameter.resCode = RetCode;

                if (RetCode != successCode) {
                    raise_app_error(RetMsg);
                }
            } catch (e) {
                //抛出异常
                raise_app_error(RetMsg);
            }

            //开票成功后回写发票号码以及金税状态
            $bm('acr.ACR515.acr515_invoice_hd_lv').update({
                invoice_number: InfoNumber,
                invoice_hd_id: $ctx.parameter.invoiceHdId,
                vat_interface_status: 'BACK'
            });


            ]]></s:server-script>
    </a:init-procedure>
    <a:service-output output="/parameter/@resCode"/>
</a:service>