UNPKG

flexbiz-server

Version:

Flexible Server

23 lines (22 loc) 6.18 kB
const axios=require("axios"),async=require("async"),moment=require("moment"),{xml2json,base64toJSON}=require("./utils"),exportInvoice=async($app$$,$ct$$,$check_data$$)=>{throw"Ch\u01b0a tri\u1ec3n khai";};exports.exportInvoice=exportInvoice;const getInvoice=async($app$$,$transactionUuid$$)=>{throw"Ch\u01b0a tri\u1ec3n khai";};exports.getInvoice=getInvoice; const getInvoices=async($app$jscomp$2_str$$,$condition_data$$={})=>{if(!$app$jscomp$2_str$$)throw"Thi\u1ebfu th\u00f4ng tin c\u00f4ng ty";if(!$app$jscomp$2_str$$.vnpt_url_service||!$app$jscomp$2_str$$.vnpt_user||!$app$jscomp$2_str$$.vnpt_password)throw"Ch\u01b0a khai b\u00e1o th\u00f4ng tin k\u1ebft n\u1ed1i VNPT invoice";if(!$app$jscomp$2_str$$.ma_so_thue)throw"Ch\u01b0a khai b\u00e1o m\u00e3 s\u1ed1 thu\u1ebf c\u00f4ng ty";if(!$condition_data$$.ky_hieu_hoa_don&&!$app$jscomp$2_str$$.vnpt_ky_hieu_hoa_don)throw"Ch\u01b0a khai b\u00e1o m\u1eabu ho\u00e1 \u0111\u01a1n"; if(!$condition_data$$.so_serial&&!$app$jscomp$2_str$$.so_serial)throw"Ch\u01b0a khai b\u00e1o k\u00ed hi\u1ec7u ho\u00e1 \u0111\u01a1n";if(!$condition_data$$.tu_ngay)throw"\u0110i\u1ec1u ki\u1ec7n thi\u1ebfu t\u1eeb ng\u00e0y (tu_ngay)";if(!$condition_data$$.den_ngay)throw"\u0110i\u1ec1u ki\u1ec7n thi\u1ebfu t\u1eeb ng\u00e0y (den_ngay)";const $ERRORS$$={"ERR:1":"T\u00e0i kho\u1ea3n \u0111\u0103ng nh\u1eadp sai ho\u1eb7c kh\u00f4ng c\u00f3 quy\u1ec1n ServiceRole","ERR:2":"Kh\u00f4ng t\u00ecm th\u1ea5y h\u00f3a \u0111\u01a1n", "ERR:3":"Sai \u0111\u1ecbnh d\u1ea1ng ng\u00e0y th\u00e1ng","ERR:4":"Kh\u00f4ng l\u1ea5y \u0111\u01b0\u1ee3c b\u1ea3ng h\u00f3a \u0111\u01a1n (sai m\u1eabu s\u1ed1)","ERR:6":"V\u01b0\u1ee3t qu\u00e1 gi\u1edbi h\u1ea1n s\u1ed1 l\u01b0\u1ee3ng h\u00f3a \u0111\u01a1n \u0111\u01b0\u1ee3c ph\u00e9p l\u1ea5y (500 h\u00f3a \u0111\u01a1n)","ERR:5":"C\u00f3 l\u1ed7i x\u1ea3y ra","ERR:7":"V\u01b0\u1ee3t qu\u00e1 gi\u1edbi h\u1ea1n 7 ng\u00e0y"};$condition_data$$=`<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetInvViewByDate xmlns="http://tempuri.org/"> <userName>${$app$jscomp$2_str$$.vnpt_user}</userName> <userPass>${$app$jscomp$2_str$$.vnpt_password}</userPass> <pattern>${$condition_data$$.ky_hieu_hoa_don||$app$jscomp$2_str$$.vnpt_ky_hieu_hoa_don}</pattern> <serial>${$condition_data$$.so_serial||$app$jscomp$2_str$$.so_serial}</serial> <fromDate>${moment($condition_data$$.tu_ngay).format("DD/MM/YYYY")}</fromDate> <toDate>${moment($condition_data$$.den_ngay).format("DD/MM/YYYY")}</toDate> </GetInvViewByDate> </soap:Body> </soap:Envelope>`;$app$jscomp$2_str$$=(await axios.request({method:"post",maxBodyLength:Infinity,url:$app$jscomp$2_str$$.vnpt_url_service,headers:{SOAPAction:"http://tempuri.org/GetInvViewByDate","Content-Type":"text/xml; charset=utf-8"},data:$condition_data$$})).data;let $rs$$=await xml2json($app$jscomp$2_str$$);return new Promise(($resolve$$,$reject$$)=>{try{let $GetInvViewByDateResult$$=($rs$$["soap:Envelope"]||{})["soap:Body"][0].GetInvViewByDateResponse[0].GetInvViewByDateResult;if($GetInvViewByDateResult$$.length>= 0&&$GetInvViewByDateResult$$[0].indexOf("ERR:")>=0)return $reject$$($ERRORS$$[$GetInvViewByDateResult$$[0]]);async.map($GetInvViewByDateResult$$,($d$$,$cb$$)=>{setImmediate(async()=>{try{var $bufferObj_rs$$=Buffer.from($d$$,"base64"),$hinh_thuc_tt_invs$$=(await xml2json($bufferObj_rs$$.toString("utf8"))).DSHDon.HDon;$bufferObj_rs$$=[];for(let $inv$$ of $hinh_thuc_tt_invs$$){let $dl$$=$inv$$.DLieu[0];$dl$$=(await base64toJSON($dl$$)).HDon.DLHDon[0];$dl$$.Fkey=$inv$$.Fkey[0];$dl$$.TTChung=$dl$$.TTChung[0]; $dl$$.NDHDon=$dl$$.NDHDon[0];$dl$$.NDHDon.NBan=$dl$$.NDHDon.NBan[0];$dl$$.NDHDon.NMua=$dl$$.NDHDon.NMua[0];$dl$$.NDHDon.TToan=$dl$$.NDHDon.TToan[0];delete $dl$$.$;$hinh_thuc_tt_invs$$="";$dl$$.TTChung.TTKhac&&$dl$$.TTChung.TTKhac.length>0&&$dl$$.TTChung.TTKhac[0].TTin&&$dl$$.TTChung.TTKhac[0].TTin.length>0&&$dl$$.TTChung.TTKhac[0].TTin[0].TTruong[0]=="HTTToan"&&($hinh_thuc_tt_invs$$=$dl$$.TTChung.TTKhac[0].TTin[0].DLieu[0]);let $fdata$$={id_invoice:$inv$$.Fkey[0],so_ct:$dl$$.TTChung.SHDon[0],ngay_ct:new Date($dl$$.TTChung.NLap[0]), so_hd:$dl$$.TTChung.SHDon[0],ngay_hd:new Date($dl$$.TTChung.NLap[0]),ky_hieu_hoa_don:$dl$$.TTChung.KHMSHDon[0],so_serial:$dl$$.TTChung.KHHDon[0],hinh_thuc_tt:$hinh_thuc_tt_invs$$,ma_nt:"VND",ty_gia:1,ten_kh:$dl$$.NDHDon.NMua.Ten[0],ma_so_thue:$dl$$.NDHDon.NMua.MST?$dl$$.NDHDon.NMua.MST[0]:void 0,dia_chi:$dl$$.NDHDon.NMua.DChi?$dl$$.NDHDon.NMua.DChi[0]:void 0,dien_thoai:$dl$$.NDHDon.NMua.SDThoai?$dl$$.NDHDon.NMua.SDThoai[0]:void 0,details:[]};for(let $dv$$ of $dl$$.NDHDon.DSHHDVu)for(let $hd$$ of $dv$$.HHDVu){let $detail$$= {ma_tc:$hd$$.TChat[0],ma_vt:$hd$$.MHHDVu[0],ten_vt:$hd$$.THHDVu[0],ma_dvt:$hd$$.DVTinh[0]||"",sl_xuat:Number($hd$$.SLuong[0]||0),gia_ban_ct:Number($hd$$.DGia[0]||0),gia_ban_ct_nt:Number($hd$$.DGia[0]||0),ty_le_ck:Number($hd$$.TLCKhau[0]||0),tien_ck:Number($hd$$.STCKhau[0]||0),tien_ck_nt:Number($hd$$.STCKhau[0]||0),ma_thue:($hd$$.TSuat[0]||"").replace("%","")};$detail$$.tien_ct=$detail$$.tien_ct_nt=Number($hd$$.ThTien[0]||0);$detail$$.thue_suat=Number($detail$$.ma_thue||0);$detail$$.tien_thue_nt=$detail$$.tien_thue= Math.round($detail$$.thue_suat*$detail$$.tien_ct_nt/100);$detail$$.tien=$detail$$.tien_nt=$detail$$.tien_ct_nt-$detail$$.tien_ck_nt+$detail$$.tien_thue_nt;$fdata$$.details.push($detail$$)}$fdata$$.t_tien_nt=$fdata$$.t_tien=$fdata$$.details.map($d$$=>$d$$.tien_ct_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$fdata$$.t_thue_nt=$fdata$$.t_thue=$fdata$$.details.map($d$$=>$d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$bufferObj_rs$$.push($fdata$$)}$cb$$(null,$bufferObj_rs$$)}catch($e$$){$cb$$($e$$)}})}, ($e$jscomp$1_invs$$,$rs$$)=>{if($e$jscomp$1_invs$$)return $reject$$($e$jscomp$1_invs$$);$e$jscomp$1_invs$$=$rs$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);$resolve$$($e$jscomp$1_invs$$)})}catch($e$$){$reject$$($e$$)}})};exports.getInvoices=getInvoices;