UNPKG

flexbiz-server

Version:

Flexible Server

39 lines (38 loc) 19.7 kB
'use strict';const PostBook=require("../../libs/post-book"),PostSocai=require("../../libs/post-socai"),Tdttno=global.getModel("tdttno"),Tdttno_tt=global.getModel("tdttno_tt"),Vatra=global.getModel("vatra"),dvcs=global.getModel("dvcs"),account=global.getModel("account"),customer=global.getModel("customer"),dmnv=global.getModel("dmnv"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),salecontract=global.getModel("sale_contract"),model=global.getModel("hd1"), controller=require("../../controllers/controller"),trangthai=global.getModel("trangthai"),utils=require("../../libs/utils"),async=require("async"),ma_ct="HD1",App=global.getModel("app"),axios=require("axios"),Moment=require("moment"); module.exports=function($router$$){const $contr$$=new controller($router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,kiem_tra_han_muc_cong_no:!0,sort:{ngay_ct:-1,so_ct:-1}});$contr$$.route();$contr$$.post=function($obj$$,$fn$$,$_options$$={}){$fn$$||($fn$$=function(){});async.series({post_socai:function($callback$$){const $details_sc$$=[];$obj$$.details.forEach(function($d_detail$$){$d_detail$$={...$d_detail$$};$d_detail$$.tk_co=$d_detail$$.tk_dt;$d_detail$$.ma_kh||($d_detail$$.ma_kh=$obj$$.ma_kh); $d_detail$$.tk_no=$obj$$.tk_no;$details_sc$$.push($d_detail$$)});$obj$$.details.forEach(function($d$jscomp$1_detail$$){$d$jscomp$1_detail$$={...$d$jscomp$1_detail$$};$d$jscomp$1_detail$$.tk_no=$d$jscomp$1_detail$$.tk_ck;$d$jscomp$1_detail$$.ma_kh||($d$jscomp$1_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$1_detail$$.tk_co=$obj$$.tk_no;$d$jscomp$1_detail$$.tien_nt=$d$jscomp$1_detail$$.tien_ck_nt;$d$jscomp$1_detail$$.tien=$d$jscomp$1_detail$$.tien_ck;$d$jscomp$1_detail$$.check_balance=!1;$details_sc$$.push($d$jscomp$1_detail$$)}); const $o$$={...$obj$$};$o$$.tk_co=$o$$.tk_thue_co;$o$$.tien_nt=$obj$$.details.csum("tien_thue_nt");$o$$.tien=$obj$$.details.csum("tien_thue");$o$$.dien_giai_thue&&($o$$.dien_giai=$o$$.dien_giai_thue);$details_sc$$.push($o$$);(new PostSocai($obj$$,$details_sc$$,void 0,void 0,$_options$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},post_tdttno:function($callback$jscomp$0$$){account.findOne({tk:$obj$$.tk_no,id_app:$obj$$.id_app},{tk_cn:1},function($error$jscomp$0$$,$tk$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$); $tk$$&&!0===$tk$$.tk_cn?(new PostBook($obj$$,[{...$obj$$}],Tdttno,function($detail$$,$callback$$){try{$detail$$.so_hd||($detail$$.so_hd=$obj$$.so_ct),$detail$$.ngay_hd||($detail$$.ngay_hd=$obj$$.ngay_ct),$detail$$.tien_nt=$obj$$.details.csum("tien_nt")-$obj$$.details.csum("tien_ck_nt")-($obj$$.tien_ck_hd||0)+$obj$$.details.csum("tien_thue_nt"),$detail$$.tien=$obj$$.details.csum("tien")-$obj$$.details.csum("tien_ck")-($obj$$.tien_ck_hd||0)*($obj$$.ty_gia||1)+$obj$$.details.csum("tien_thue")}catch($e$$){console.error($e$$, $obj$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)}):Tdttno.deleteMany({id_ct:$obj$$._id},function($error$$){$callback$jscomp$0$$($error$$)})})},post_vatra:function($callback$jscomp$0$$){$obj$$.ngay_hd?$obj$$.details.map($detail$$=>({...$detail$$,thue_suat:($detail$$.ma_thue?$detail$$.thue_suat:$obj$$.thue_suat)||0,ma_thue:$detail$$.ma_thue||$obj$$.ma_thue})).filter($d$$=>$d$$.ma_thue).asyncGroupBy(["ma_thue","thue_suat","ten_vt_vat"],"tien_nt tien tien_ck tien_ck_nt tien_thue tien_thue_nt".split(" ")).then($ds$$=> {if(1==$ds$$.length){let $tien_thue_nt$$=$ds$$.map($d$$=>$d$$.tien_thue_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$tien_thue$$=$ds$$.map($d$$=>$d$$.tien_thue||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);0==$tien_thue_nt$$&&0==$tien_thue$$&&($tien_thue_nt$$=$obj$$.t_thue_nt||0,$tien_thue$$=$obj$$.t_thue||0);$ds$$[0].tien_thue_nt=$tien_thue_nt$$;$ds$$[0].tien_thue=$tien_thue$$}(new PostBook($obj$$,$ds$$,Vatra,function($detail$$,$callback$$){try{$detail$$.tk_du_thue=$obj$$.tk_no,$detail$$.t_tien_nt=$detail$$.tien_nt- $detail$$.tien_ck_nt,$detail$$.t_tien=$detail$$.tien-$detail$$.tien_ck,$detail$$.t_thue_nt=$detail$$.tien_thue_nt,$detail$$.t_thue=$detail$$.tien_thue,$detail$$.ten_vt=$detail$$.ten_vt_vat||$obj$$.ten_vt||$obj$$.dien_giai}catch($e$$){console.error($e$$,$obj$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})}):$callback$jscomp$0$$()}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};const $valid$$=function($i_t_thue_nt_user$$,$obj$$,$next$$){for($i_t_thue_nt_user$$=0;$i_t_thue_nt_user$$< $obj$$.details.length;$i_t_thue_nt_user$$++){var $detail$jscomp$0$$=$obj$$.details[$i_t_thue_nt_user$$];$detail$jscomp$0$$.line=$i_t_thue_nt_user$$;"VND"===$obj$$.ma_nt&&($detail$jscomp$0$$.tien=$detail$jscomp$0$$.tien_nt,$detail$jscomp$0$$.tien_ck=$detail$jscomp$0$$.tien_ck_nt);$detail$jscomp$0$$.tien_ck=$detail$jscomp$0$$.tien_ck||0;$detail$jscomp$0$$.tien_ck_nt=$detail$jscomp$0$$.tien_ck_nt||0;$detail$jscomp$0$$.tien=$detail$jscomp$0$$.tien||0;$detail$jscomp$0$$.tien_nt=$detail$jscomp$0$$.tien_nt|| 0}let $f_tien_nt$$="VND"===$obj$$.ma_nt?0:2;$obj$$.thue_suat=$obj$$.thue_suat||0;$obj$$.details.forEach($detail$$=>{let $thue_suat$$=($detail$$.ma_thue?$detail$$.thue_suat:$obj$$.thue_suat)||0;$detail$$.tien_thue=utils.round(($detail$$.tien-$detail$$.tien_ck)*$thue_suat$$/100,0);$detail$$.tien_thue_nt=utils.round(($detail$$.tien_nt-$detail$$.tien_ck_nt)*$thue_suat$$/100,$f_tien_nt$$)});if(!$obj$$.details.find($r$$=>$r$$.ma_thue)&&void 0!=$obj$$.thue_suat&&($obj$$.t_thue_nt=utils.round(($obj$$.details.csum("tien_nt")- $obj$$.details.csum("tien_ck_nt"))*$obj$$.thue_suat/100,$f_tien_nt$$),$obj$$.t_thue=utils.round($obj$$.t_thue_nt*($obj$$.ty_gia||1),0),$i_t_thue_nt_user$$=$obj$$.details.csum("tien_thue_nt"),$detail$jscomp$0$$=$obj$$.details.csum("tien_thue"),($i_t_thue_nt_user$$!==$obj$$.t_thue_nt||$detail$jscomp$0$$!==$obj$$.t_thue)&&0<$obj$$.details.length)){let $row_dieu_chinh$$=$obj$$.details[$obj$$.details.length-1];$row_dieu_chinh$$.tien_thue_nt+=$obj$$.t_thue_nt-$i_t_thue_nt_user$$;$row_dieu_chinh$$.tien_thue+= $obj$$.t_thue-$detail$jscomp$0$$}$obj$$.id_contract?salecontract.findOne({_id:$obj$$.id_contract}).lean().exec(($e$$,$c$$)=>{$c$$&&($obj$$.ma_hd=$c$$.ma_hd);$next$$(null,$obj$$)}):$next$$(null,$obj$$)};$contr$$.creating=function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$valid$$($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$obj$$.result_export_einvoice=null;$next$$(null,$obj$$)})};$contr$$.updating=function($user$$,$data$$,$obj$$,$next$$){Tdttno_tt.findOne({id_hd:$obj$$._id}, function($error$jscomp$0$$,$ct_tt$$){if($error$jscomp$0$$)return $next$$($error$jscomp$0$$);$ct_tt$$?$next$$(`Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt phi\u1ebfu n\u00e0y do \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n b\u1edfi ${$ct_tt$$.ma_ct||"ch\u1ee9ng t\u1eeb"}: ${$ct_tt$$.so_ct}, ng\u00e0y ${Moment($ct_tt$$.ngay_ct).format("DD/MM/YYYY")}`):$valid$$($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})})};$contr$$.deleting=function($user$$, $obj$$,$next$$){Tdttno_tt.findOne({id_hd:$obj$$._id},function($error$$,$ct_tt$$){if($error$$)return $next$$($error$$);$ct_tt$$?$next$$(`Kh\u00f4ng th\u1ec3 xo\u00e1 phi\u1ebfu n\u00e0y do \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n b\u1edfi ${$ct_tt$$.ma_ct||"ch\u1ee9ng t\u1eeb"}: ${$ct_tt$$.so_ct}, ng\u00e0y ${Moment($ct_tt$$.ngay_ct).format("DD/MM/YYYY")}`):$next$$(null,$obj$$)})};$contr$$.view=function($user$$,$items$$,$fn$$){const $id_app$$=$user$$.current_id_app;async.series({dv:function($callback$$){$items$$.filter($item$$=> $item$$.ma_dvcs).joinModel($id_app$$,dvcs,[{akey:"ma_dvcs",bkey:"_id",fields:[{name:"ten_dvcs",value:"ten_dvcs"}]}],function(){$callback$$()})},tk:function($callback$$){$items$$.filter($item$$=>$item$$.tk_no).joinModel($id_app$$,account,[{akey:"tk_no",bkey:"tk",fields:[{name:"ten_tk_no",value:"ten_tk"}]}],function(){$callback$$()})},dt:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dt).joinModel($id_app$$,dmdt,[{akey:"ma_dt",bkey:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback$$()})}, kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:["ten_kh","email","nh_kh"]}],function(){$callback$$()})},nv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_nv).joinModel($id_app$$,dmnv,[{akey:"ma_nv",bkey:"ma_nv",fields:[{name:"ten_nv",value:"ten_nv"}]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai", ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},contract:function($callback$$){$items$$.filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},fields:["ten_hd","ten_hd"]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.details&&($r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tien_nt=$r$$.details.csum("tien_nt"),$r$$.t_ck=$r$$.details.csum("tien_ck"),$r$$.t_ck_nt=$r$$.details.csum("tien_ck_nt"), $r$$.t_thue=$r$$.details.csum("tien_thue"),$r$$.t_thue_nt=$r$$.details.csum("tien_thue_nt"),$r$$.t_tt=$r$$.t_tien-$r$$.t_ck+$r$$.t_thue,$r$$.t_tt_nt=$r$$.t_tien_nt-$r$$.t_ck_nt+$r$$.t_thue_nt,$r$$.details.forEach($detail$$=>{$detail$$.dien_giai||($detail$$.dien_giai=$r$$.dien_giai)}))});$callback$$()},details_tk:function($callback$$){async.each($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel($id_app$$,account,[{akey:"tk_dt",bkey:"tk",fields:[{name:"ten_tk_dt",value:"ten_tk"}]},{akey:"tk_ck", bkey:"tk",fields:[{name:"ten_tk_ck",value:"ten_tk"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_dt).joinModel($id_app$$,dmdt,[{akey:"ma_dt",bkey:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details|| []).filter($item$$=>$item$$.ma_hd).joinModel($id_app$$,contract,[{akey:"ma_hd",bkey:"so_hd",fields:[{name:"ten_hd",value:"ten_hd"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_phi).joinModel($id_app$$,dmphi,[{akey:"ma_phi",bkey:"ma_phi",fields:[{name:"ten_phi",value:"ten_phi"}]}],function(){$callback1$$()})},function(){$callback$$()})}},function(){$fn$$(null, $items$$)})};$contr$$.createRoute("export2viettel/:id_ct",async($req$$,$next$$)=>{try{console.log("Export to viettel....");const $id_app$$=$req$$.user.current_id_app,$app$$=await App.findOne({_id:$id_app$$});if(!$app$$)return console.log("Kh\u00f4ng tim th\u1ea5y th\u00f4ng tin coogn ty"),$next$$("Kh\u00f4ng t\u00ecm th\u1ea5y c\u00f4ng ty n\u00e0y");if(!$app$$.viettel_url_service||!$app$$.viettel_user||!$app$$.viettel_password)return console.log("Chua khai bao thong tin ket noi viettel"),$next$$("Th\u00f4ng tin xu\u1ea5t ho\u00e1 \u0111\u01a1n Viettel ch\u01b0a \u0111\u01b0\u1ee3c khai b\u00e1o \u0111\u1ea7y \u0111\u1ee7"); if(!$app$$.ma_so_thue)return console.log("Chua nhap ma so thue cua cong ty"),$next$$("B\u1ea1n ch\u01b0a nh\u1eadp m\u00e3 s\u1ed1 thu\u1ebf c\u1ee7a c\u00f4ng ty");const $ct$$=await model.findOne({id_app:$id_app$$,_id:$req$$.params.id_ct}).lean();if(!$ct$$)return console.log("Khong tim thay chung tu"),$next$$("Ch\u1ee9ng t\u1eeb kh\u00f4ng h\u1ee3p l\u1ec7");let $transactionUuid$$=$ct$$._id.toString();try{let $result_export_einvoice$$=await utils.getInvoice($app$$,$transactionUuid$$);if($result_export_einvoice$$){if($result_export_einvoice$$.errorCode)return $next$$($result_export_einvoice$$.data|| $result_export_einvoice$$.description);console.log("\u0110\u1ed3ng b\u1ed9 hoa \u0111\u01a1n viettel");$ct$$.result_export_einvoice=$result_export_einvoice$$;await utils.updateInvoice($contr$$,$ct$$);return $next$$(null,$result_export_einvoice$$)}}catch($e$$){return console.error("error export to viettel",$e$$),$next$$($e$$)}if($ct$$.result_export_einvoice&&$ct$$.result_export_einvoice.result&&$ct$$.result_export_einvoice.result.invoiceNo)return $next$$(null,$ct$$.result_export_einvoice);const $kh$$= await customer.findOne({id_app:$id_app$$,ma_kh:$ct$$.ma_kh})||{},$t_tien_hang$$=Math.abs($ct$$.details.map($d$$=>$d$$.tien_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0)),$t_ck$$=Math.abs($ct$$.details.map($d$$=>$d$$.tien_ck_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0)),$t_tien$$=Math.abs($ct$$.details.map($d$$=>$d$$.tien_nt-$d$$.tien_ck_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0)),$t_thue$$=Math.abs($ct$$.details.map($d$$=>$d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0)),$tien_ck_hd$$=$ct$$.tien_ck_hd||0;let $taxBreakdowns$$= $ct$$.details.map($detail$$=>({...$detail$$,ma_thue:$detail$$.ma_thue||$ct$$.ma_thue,thue_suat:($detail$$.ma_thue?$detail$$.thue_suat:$ct$$.thue_suat)||0})).filter($d$$=>$d$$.ma_thue);if(0===$taxBreakdowns$$.length)return $next$$("B\u1ea1n ch\u01b0a khai b\u00e1o thu\u1ebf");$taxBreakdowns$$=$taxBreakdowns$$.filter($d$$=>"KT"!=$d$$.ma_thue&&"KK"!=$d$$.ma_thue).map($detail$$=>({taxPercentage:$detail$$.thue_suat,taxableAmount:Math.abs($detail$$.tien_nt-$detail$$.tien_ck_nt),taxAmount:Math.abs($detail$$.tien_thue_nt)})); $taxBreakdowns$$=await $taxBreakdowns$$.asyncGroupBy("taxPercentage",["taxableAmount","taxAmount"]);const $data$jscomp$0$$={generalInvoiceInfo:{invoiceType:$ct$$.ma_hoa_don||$app$$.ma_hoa_don||"1",templateCode:$ct$$.ky_hieu_hoa_don||$app$$.ky_hieu_hoa_don||"1/001",invoiceSeries:$ct$$.so_seri,transactionUuid:$transactionUuid$$,currencyCode:"VND",adjustmentType:"1",paymentStatus:!0,cusGetInvoiceRight:!0,userName:$ct$$.user_created},buyerInfo:{buyerName:$ct$$.ong_ba||"",buyerLegalName:$ct$$.ten_kh|| $kh$$.ten_kh||"",buyerTaxCode:$ct$$.ma_so_thue||$kh$$.ma_so_thue||"",buyerAddressLine:$ct$$.dia_chi||$kh$$.dia_chi||"",buyerPostalCode:"",buyerDistrictName:"",buyerCityName:"",buyerCountryCode:"",buyerPhoneNumber:$ct$$.dien_thoai||$kh$$.dien_thoai||"",buyerFaxNumber:"",buyerEmail:$kh$$.email||"",buyerBankName:"",buyerBankAccount:"",buyerIdType:"",buyerIdNo:"",buyerCode:"",buyerBirthDay:""},sellerInfo:{sellerLegalName:$app$$.name,sellerTaxCode:$app$$.ma_so_thue,sellerAddressLine:$app$$.dia_chi_xuat_hoa_don|| $app$$.address,sellerPhoneNumber:$app$$.phone||"",sellerEmail:$app$$.email||"",sellerBankName:$app$$.ten_ngan_hang||"",sellerBankAccount:$app$$.tai_khoan_ngan_hang||""},itemInfo:$ct$$.details.map(($detail$$,$index$$)=>{var $JSCompiler_inline_result$jscomp$10_thue_suat$$=($detail$$.ma_thue?$detail$$.thue_suat:$ct$$.thue_suat)||0,$JSCompiler_temp_const$$=0>$detail$$.tien_nt?3:1,$JSCompiler_temp_const$jscomp$9$$=($index$$+1).toString(),$JSCompiler_temp_const$jscomp$8$$=$detail$$.dien_giai,$JSCompiler_temp_const$jscomp$7$$= 0>$detail$$.tien_nt?"":$detail$$.ma_dvt,$JSCompiler_temp_const$jscomp$6$$=0>$detail$$.tien_nt?void 0:$detail$$.gia_ban_nt,$JSCompiler_temp_const$jscomp$5$$=0>$detail$$.tien_nt?void 0:$detail$$.sl_xuat,$JSCompiler_temp_const$jscomp$4$$=Math.abs($detail$$.tien_nt),$JSCompiler_temp_const$jscomp$3$$=$detail$$.ty_le_ck,$JSCompiler_temp_const$jscomp$2$$=Math.abs($detail$$.tien_ck_nt),$JSCompiler_temp_const$jscomp$1$$=Math.abs($detail$$.tien_nt-$detail$$.tien_ck_nt);a:{var $tien_ct_nt$$=$detail$$.tien_nt; switch($detail$$.ma_thue||$ct$$.ma_thue){case "KT":$JSCompiler_inline_result$jscomp$10_thue_suat$$=0>$tien_ct_nt$$?void 0:-2;break a;case "KK":$JSCompiler_inline_result$jscomp$10_thue_suat$$=0>$tien_ct_nt$$?void 0:-1}}return{lineNumber:$index$$+1,selection:$JSCompiler_temp_const$$,itemCode:$JSCompiler_temp_const$jscomp$9$$,itemName:$JSCompiler_temp_const$jscomp$8$$,unitName:$JSCompiler_temp_const$jscomp$7$$,itemNote:"",unitPrice:$JSCompiler_temp_const$jscomp$6$$,quantity:$JSCompiler_temp_const$jscomp$5$$, itemTotalAmountWithoutTax:$JSCompiler_temp_const$jscomp$4$$,discount:$JSCompiler_temp_const$jscomp$3$$,itemDiscount:$JSCompiler_temp_const$jscomp$2$$,itemTotalAmountAfterDiscount:$JSCompiler_temp_const$jscomp$1$$,taxPercentage:$JSCompiler_inline_result$jscomp$10_thue_suat$$,taxAmount:Math.abs($detail$$.tien_thue_nt),itemTotalAmountWithTax:Math.abs($detail$$.tien_nt-$detail$$.tien_ck_nt+$detail$$.tien_thue_nt),customTaxAmount:"0",batchNo:"",expDate:""}}),summarizeInfo:{sumOfTotalLineAmountWithoutTax:$t_tien_hang$$, discountAmount:$t_ck$$,settlementDiscountAmount:$tien_ck_hd$$,totalAmountWithoutTax:$t_tien$$,totalTaxAmount:$t_thue$$,totalAmountWithTax:$t_tien$$+$t_thue$$},taxBreakdowns:$taxBreakdowns$$,payments:[{paymentMethodName:$ct$$.hinh_thuc_tt||"TM"}],extAttribute:[],deliveryInfo:{},metadata:[]};$ct$$.ngay_hd||($ct$$.ngay_hd=new Date);let $headers$$,$url$$,$viettel_token$$,$auth$$={username:$app$$.viettel_user.trim(),password:$app$$.viettel_password.trim()};if("1"!=$app$$.viettel_version){$data$jscomp$0$$.generalInvoiceInfo.invoiceIssuedDate= (new Date($ct$$.ngay_hd)).getTime();let $url_token$$=`${$app$$.viettel_url_service.trim()}/auth/login`;$url$$=$app$$.viettel_direct_issue?`${$app$$.viettel_url_service.trim()}/services/einvoiceapplication/api/InvoiceAPI/InvoiceWS/createInvoice/${$app$$.ma_so_thue.trim()}`:`${$app$$.viettel_url_service.trim()}/services/einvoiceapplication/api/InvoiceAPI/InvoiceWS/createOrUpdateInvoiceDraft/${$app$$.ma_so_thue.trim()}`;try{$viettel_token$$=(await axios({method:"post",url:$url_token$$,data:$auth$$})).data.access_token}catch($e$$){console.error("error when get token viettel", $auth$$,$url_token$$);let $msg_e$$=$e$$.response?$e$$.response.data:$e$$.message;$msg_e$$&&$msg_e$$.detail&&($msg_e$$.message=$msg_e$$.detail);return $next$$($msg_e$$||$e$$.message||$e$$.error||$e$$)}$headers$$={Cookie:`"access_token":"${$viettel_token$$}"; access_token=${$viettel_token$$}; session_token=${$viettel_token$$}`,"Content-Type":"application/json"};$auth$$=void 0}else $data$jscomp$0$$.generalInvoiceInfo.invoiceIssuedDate=Moment($ct$$.ngay_hd).format("YYYY-MM-DD"),$url$$=$app$$.viettel_direct_issue? `${$app$$.viettel_url_service.trim()}/InvoiceAPI/InvoiceWS/createInvoice/${$app$$.ma_so_thue.trim()}`:`${$app$$.viettel_url_service.trim()}/InvoiceAPI/InvoiceWS/createOrUpdateInvoiceDraft/${$app$$.ma_so_thue.trim()}`;console.log("post to viettel...");axios({method:"post",url:$url$$,data:"1"!=$app$$.viettel_version?JSON.stringify($data$jscomp$0$$):$data$jscomp$0$$,auth:$auth$$,headers:$headers$$}).then(async $data$$=>{$data$$=$data$$.data;console.error("result data",$data$$);if(!$data$$)return $next$$("Kh\u00f4ng th\u1ec3 xu\u1ea5t ho\u00e1 \u0111\u01a1n"); if($data$$.errorCode)return $next$$($data$$.description);$ct$$.result_export_einvoice=$data$$;$ct$$.so_hd=$ct$$.result_export_einvoice.result.invoiceNo;await model.findOneAndUpdate({_id:$ct$$._id},$ct$$);$ct$$.so_hd&&await Tdttno.updateMany({id_ct:$ct$$._id.toString()},{so_hd:$ct$$.so_hd});$ct$$.so_hd&&await Tdttno_tt.updateMany({id_hd:$ct$$._id.toString()},{so_hd:$ct$$.so_hd});$ct$$.so_hd&&await Vatra.updateMany({id_ct:$ct$$._id.toString()},{so_hd:$ct$$.so_hd});controller.postData($ct$$,$contr$$, $e$$=>{if($e$$)return console.error($e$$);controller.pushNotification($contr$$,$ct$$)});$next$$(null,$data$$)}).catch($e$$=>{console.error("error when export invocie viettel",$e$$.response);let $msg_e$$=$e$$.response?$e$$.response.data:$e$$.message;$msg_e$$.data&&($msg_e$$.message=$msg_e$$.data);$msg_e$$.detail&&($msg_e$$.message=$msg_e$$.detail);$next$$($msg_e$$||$e$$.message||$e$$.error||$e$$)})}catch($e$$){console.log($e$$),$next$$($e$$.message)}},{method:"GET"})};