flexbiz-server 12.3.2 → 12.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/server/app.js +4 -4
- package/server/cluster.js +2 -2
- package/server/controllers/controller.js +109 -107
- package/server/data/account.js +479 -0
- package/server/data/ckgtluong.js +65 -0
- package/server/data/currency.js +4 -0
- package/server/data/dmdvt.js +54 -0
- package/server/data/dmkho.js +3 -0
- package/server/data/dvcs.js +3 -0
- package/server/data/kbm_bcdkt.js +4843 -0
- package/server/data/kbm_kqhdkd.js +655 -0
- package/server/data/kbm_lcttgt.js +2386 -0
- package/server/data/kbm_lctttt.js +934 -0
- package/server/data/kbm_tkgtgt.js +560 -0
- package/server/data/parameter.js +178 -0
- package/server/data/ptthanhtoan.js +3 -0
- package/server/data/rpt.js +123 -0
- package/server/data/rptobject.js +2 -0
- package/server/data/sys/labelinfo.js +2 -0
- package/server/data/sys/listinfo.js +225430 -0
- package/server/data/sys/menuinfo.js +1 -0
- package/server/data/sys/moduleinfo.js +523 -0
- package/server/data/sys/quanhuyen.js +9928 -0
- package/server/data/sys/reportinfo.js +14045 -0
- package/server/data/sys/tableinfo.js +5873 -0
- package/server/data/sys/templatestore.js +1988 -0
- package/server/data/sys/tinhthanh.js +821 -0
- package/server/data/sys/trangthai.js +12301 -0
- package/server/data/sys/user.js +21 -0
- package/server/data/sys/vietqrbanks.js +1 -0
- package/server/data/tc.js +5 -0
- package/server/data/usergroup.js +47 -0
- package/server/data/vat.js +115 -0
- package/server/global.js +1 -1
- package/server/libs/databanle.js +12 -9
- package/server/libs/databanletheongay.js +1 -1
- package/server/libs/docs.js +304 -0
- package/server/libs/dtbanletheosp.js +2 -2
- package/server/libs/getGiaban.js +57 -53
- package/server/libs/htmlReport.js +6 -6
- package/server/libs/mongooseDeletePost.js +4 -3
- package/server/libs/permission.js +25 -20
- package/server/libs/post-socai.js +6 -5
- package/server/libs/post-sokho.js +1 -1
- package/server/libs/tuoinophaithu.js +10 -10
- package/server/libs/tuoinophaitra.js +11 -9
- package/server/libs/utils.js +29 -5
- package/server/libs/validator.js +3 -2
- package/server/models/app.js +4 -3
- package/server/models/bds_area.js +2 -2
- package/server/models/bds_block.js +2 -2
- package/server/models/bds_building.js +3 -3
- package/server/models/bds_floor.js +2 -2
- package/server/models/bds_floordetail.js +3 -3
- package/server/models/bds_nhadat.js +6 -4
- package/server/models/bds_nhomnhadat.js +3 -0
- package/server/models/bds_phanloainhadat.js +2 -0
- package/server/models/customer.js +5 -5
- package/server/models/dh2.js +5 -5
- package/server/models/ecomproductlines.js +2 -0
- package/server/models/hd2.js +17 -15
- package/server/models/hd4.js +12 -0
- package/server/models/listinfo.js +12 -1
- package/server/models/moduleinfo.js +3 -3
- package/server/models/pn3.js +4 -4
- package/server/models/so9.js +7 -7
- package/server/models/tdttco.js +9 -8
- package/server/models/tdttco_tt.js +1 -1
- package/server/models/tdttno.js +9 -8
- package/server/models/tdttno_tt.js +2 -2
- package/server/models/user.js +7 -7
- package/server/models/vatra.js +5 -5
- package/server/models/vatvao.js +5 -5
- package/server/modules/lists/bg-cddiem.js +6 -7
- package/server/modules/lists/bg-cddt.js +7 -8
- package/server/modules/lists/bg-cdkh.js +11 -10
- package/server/modules/lists/bg-cdnphep.js +6 -7
- package/server/modules/lists/bg-cdtk.js +9 -9
- package/server/modules/lists/bg-cdvt.js +8 -9
- package/server/modules/lists/bg-cdvtnpp.js +7 -8
- package/server/modules/lists/ls-account.js +4 -4
- package/server/modules/lists/ls-afflink.js +2 -2
- package/server/modules/lists/ls-bds_area.js +4 -3
- package/server/modules/lists/ls-bds_block.js +1 -1
- package/server/modules/lists/ls-bds_building.js +2 -2
- package/server/modules/lists/ls-bds_floor.js +2 -2
- package/server/modules/lists/ls-bds_floordetail.js +18 -18
- package/server/modules/lists/ls-bds_nhadat.js +16 -7
- package/server/modules/lists/ls-bds_nhomnhadat.js +1 -0
- package/server/modules/lists/ls-bds_phanloainhadat.js +1 -0
- package/server/modules/lists/ls-currency.js +1 -1
- package/server/modules/lists/ls-dknphep.js +1 -1
- package/server/modules/lists/ls-dmban.js +3 -3
- package/server/modules/lists/ls-dmca.js +1 -1
- package/server/modules/lists/ls-dmchucvu.js +2 -1
- package/server/modules/lists/ls-dmcpmh.js +1 -1
- package/server/modules/lists/ls-dmdvt.js +1 -1
- package/server/modules/lists/ls-dmhoahonghd.js +2 -1
- package/server/modules/lists/ls-dmhoahongnpp.js +2 -1
- package/server/modules/lists/ls-dmkhuyenmai.js +4 -4
- package/server/modules/lists/ls-dmkhuyenmaihd.js +2 -2
- package/server/modules/lists/ls-dmletet.js +1 -1
- package/server/modules/lists/ls-dmloaicong.js +1 -1
- package/server/modules/lists/ls-dmloaits.js +1 -1
- package/server/modules/lists/ls-dmnckkm.js +5 -5
- package/server/modules/lists/ls-dmnghiepvu.js +1 -1
- package/server/modules/lists/ls-dmnguonvon.js +1 -1
- package/server/modules/lists/ls-dmnhnv.js +5 -5
- package/server/modules/lists/ls-dmnhtask.js +5 -5
- package/server/modules/lists/ls-dmnkh.js +5 -5
- package/server/modules/lists/ls-dmntt.js +5 -5
- package/server/modules/lists/ls-dmnvt.js +4 -4
- package/server/modules/lists/ls-dmqddvt.js +2 -2
- package/server/modules/lists/ls-dmtanggiamts.js +1 -1
- package/server/modules/lists/ls-dmvt.js +20 -19
- package/server/modules/lists/ls-dvcs.js +1 -1
- package/server/modules/lists/ls-fbpage.js +1 -1
- package/server/modules/lists/ls-hlink.js +1 -1
- package/server/modules/lists/ls-hlinkvalue.js +1 -1
- package/server/modules/lists/ls-hmcn.js +2 -2
- package/server/modules/lists/ls-kbm-bcdkt.js +1 -1
- package/server/modules/lists/ls-kbm-bcqt.js +4 -4
- package/server/modules/lists/ls-kbm-kqhdkd.js +1 -1
- package/server/modules/lists/ls-kbm-lcttgt.js +1 -1
- package/server/modules/lists/ls-kbm-lctttt.js +1 -1
- package/server/modules/lists/ls-kbm-pttct.js +2 -2
- package/server/modules/lists/ls-kbm-tkgtgt.js +2 -1
- package/server/modules/lists/ls-kbm-tmbctc.js +2 -2
- package/server/modules/lists/ls-label.js +1 -1
- package/server/modules/lists/ls-like-module.js +2 -2
- package/server/modules/lists/ls-newsfeed.js +3 -3
- package/server/modules/lists/ls-participant.js +3 -3
- package/server/modules/lists/ls-ptthanhtoan.js +2 -2
- package/server/modules/lists/ls-rpt.js +4 -4
- package/server/modules/lists/ls-rptform.js +4 -4
- package/server/modules/lists/ls-tc.js +1 -1
- package/server/modules/lists/ls-templaterpt.js +4 -3
- package/server/modules/lists/ls-templatevoucher.js +1 -1
- package/server/modules/lists/ls-vat.js +1 -1
- package/server/modules/lists/ls-vatra.js +5 -0
- package/server/modules/lists/ls-vatvao.js +5 -0
- package/server/modules/reports/calc-tinhgiatb.js +6 -6
- package/server/modules/reports/calc-tinhgiathanh.js +6 -7
- package/server/modules/reports/calc-tinhkhauhaots.js +3 -4
- package/server/modules/reports/calc-tinhluong.js +17 -17
- package/server/modules/reports/rp-congnophaithutheotuoino.js +2 -2
- package/server/modules/reports/rp-congnophaitratheotuoino.js +2 -2
- package/server/modules/reports/rp-congnosapthu.js +4 -0
- package/server/modules/reports/rp-congnosaptra.js +4 -0
- package/server/modules/reports/rp-congviectheotimeline.js +2 -1
- package/server/modules/reports/rp-dtbanletheoct.js +15 -15
- package/server/modules/reports/rp-dtbanletheokh.js +5 -5
- package/server/modules/reports/rp-dtbanletheokho.js +1 -1
- package/server/modules/reports/rp-dtbanletheonv.js +3 -3
- package/server/modules/reports/rp-kcsns.js +16 -16
- package/server/modules/reports/rp-tongquancongty.js +3 -0
- package/server/modules/systems/sys-ecomproductlines.js +1 -0
- package/server/modules/vouchers/vo-dh2.js +25 -24
- package/server/modules/vouchers/vo-hd1.js +18 -18
- package/server/modules/vouchers/vo-hd2.js +12 -6
- package/server/modules/vouchers/vo-hd3.js +37 -33
- package/server/modules/vouchers/vo-hd4.js +15 -0
- package/server/modules/vouchers/vo-pn3.js +5 -4
- package/server/modules/vouchers/vo-pn5.js +18 -13
- package/server/route.js +6 -4
|
@@ -3,24 +3,24 @@ controller=require("../../controllers/controller"),trangthai=global.getModel("tr
|
|
|
3
3
|
module.exports=function($router$$){const $contr$$=new controller($router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,sort:{ngay_ct:-1,so_ct:-1}});$contr$$.route();$contr$$.post=function($obj$$,$fn$$){$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$$)});
|
|
4
4
|
$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;
|
|
5
5
|
$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$$)).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$$,
|
|
6
|
-
[{...$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$$.details.csum("tien_thue_nt"),$detail$$.tien=$obj$$.details.csum("tien")-$obj$$.details.csum("tien_ck")+$obj$$.details.csum("tien_thue")}catch($e$$){console.error($e$$,$obj$$)}$callback$$($detail$$)})).run(function($e
|
|
7
|
-
$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$$=>
|
|
8
|
-
$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
|
|
9
|
-
$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
|
|
10
|
-
$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||
|
|
11
|
-
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")
|
|
12
|
-
$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
|
|
13
|
-
$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},
|
|
14
|
-
$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
|
|
15
|
-
$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
|
|
16
|
-
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$$()})},
|
|
17
|
-
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",
|
|
18
|
-
$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")
|
|
19
|
-
$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",
|
|
20
|
-
|
|
21
|
-
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
|
|
22
|
-
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");
|
|
23
|
-
|
|
6
|
+
[{...$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$$,
|
|
7
|
+
$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$$=>
|
|
8
|
+
{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-
|
|
9
|
+
$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$$<
|
|
10
|
+
$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||
|
|
11
|
+
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")-
|
|
12
|
+
$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+=
|
|
13
|
+
$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},
|
|
14
|
+
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$$,
|
|
15
|
+
$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$$=>
|
|
16
|
+
$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$$()})},
|
|
17
|
+
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",
|
|
18
|
+
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"),
|
|
19
|
+
$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",
|
|
20
|
+
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||
|
|
21
|
+
[]).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,
|
|
22
|
+
$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");
|
|
23
|
+
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||
|
|
24
24
|
$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$$=
|
|
25
25
|
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$$=
|
|
26
26
|
$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)}));
|
|
@@ -10,7 +10,7 @@ $b$$)=>$a$$+$b$$,0));$d$$.tien_xuat_tmp=$d$$.sl_xuat*($d$$.gia_mua||0)});await t
|
|
|
10
10
|
user_npp:$cust_kho_npp$$.of_user,la_kho_npp:!0}).lean())&&($obj$$.ma_kho_npp=$cust_kho_npp$$.ma_kho,$obj$$.of_user=$cust_kho_npp$$.user_npp);$obj$$.user_created||($obj$$.user_created=$user$$.email);$obj$$.details.forEach($d$$=>{$d$$.sl_xuat=utils.round($d$$.sl_xuat,4);$d$$.tt_nt=$d$$.tien_ct_nt-$d$$.tien_ck_nt;$d$$.tt=$d$$.tien_ct-$d$$.tien_ck;$d$$.tien_xuat_tmp=$d$$.sl_xuat*($d$$.gia_mua||0)});await tinhhoahong($obj$$,$user$$)};$contr$$.post=async($obj$$,$fn$$)=>{$fn$$||($fn$$=function(){});$obj$$.details.forEach($detail$$=>
|
|
11
11
|
{void 0==$detail$$.gia_ban_ct_nt&&$obj$$.ma_nt&&(console.log("dieu chinh du lieu cu"),tinhGiaChuaThue($obj$$,$detail$$));$detail$$.tien_nt=$detail$$.tien_ct_nt-$detail$$.tien_ck_nt+$detail$$.tien_thue_nt;$detail$$.tien=Math.round($detail$$.tien_nt*$obj$$.ty_gia)});const $appInfo$$=await global.getModel("app").findOne({_id:$obj$$.id_app}).lean();let $kho$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean()||{},$options$$;try{$options$$=await Options.getInfo($obj$$.id_app,{id_func:$obj$$.ma_ct.toLowerCase()},
|
|
12
12
|
"option")}catch($e$$){console.log($e$$.message,{id_func:$obj$$.ma_ct})}$options$$||($options$$={});await $obj$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["gia_mua"]});let $product_details$$=$obj$$.details.map($detail$$=>{$detail$$.tien_nt=$detail$$.tien_nt||0;$detail$$.tien=$detail$$.tien||0;return $detail$$.combo&&0<$detail$$.combo.length?$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$detail$$.gia_ban_nt||($item$$.gia_ban_nt=0,$item$$.gia_nt=
|
|
13
|
-
0,$item$$.tien_nt=0,$item$$.tien=0,$item$$.tien_ck_nt=0,$item$$.tien_ck=0)
|
|
13
|
+
0,$item$$.tien_nt=0,$item$$.tien=0,$item$$.tien_ck_nt=0,$item$$.tien_ck=0);$item$$.ma_kho=$detail$$.ma_kho;delete $item$$.px_gia_dd;return $item$$}):[$detail$$]}).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);async.series({post_sokho:$callback$jscomp$1$$=>{let $details$$=[...$obj$$.details];$obj$$.details.forEach($d$$=>{$d$$.promotion&&$d$$.promotion.details_km&&$d$$.promotion.details_km.forEach($p$$=>{if($p$$.ma_vt&&$p$$.sl_km){let $_p$$={};underscore.extend($_p$$,$p$$,{sl_xuat:$p$$.sl_km});$details$$.push($_p$$)}})});
|
|
14
14
|
$obj$$.promotion&&$obj$$.promotion.forEach($p$$=>{if($p$$.ma_vt&&$p$$.sl_km){let $_p$$={};underscore.extend($_p$$,$p$$,{sl_xuat:$p$$.sl_km});$details$$.push($_p$$)}});async.series({kt:$callback$jscomp$0$$=>{$options$$.not_post_sokho?$callback$jscomp$0$$():(new PostBook($obj$$,$product_details$$,Sokho,async($detail$$,$callback$$)=>{$detail$$.nxt=2;$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,
|
|
15
15
|
$rs$$)})},tt:$callback$jscomp$0$$=>{$options$$.post_sokhott?(new PostBook($obj$$,$product_details$$,Sokhott,async($detail$$,$callback$$)=>{$detail$$.nxt=2;$detail$$.tk_no=$obj$$.tk_no;$detail$$.ma_kho=$detail$$.ma_kho||$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)}):$callback$jscomp$0$$()},npp:$callback$jscomp$0$$=>{setImmediate(async()=>{$obj$$.ma_kho_npp?(new PostBook($obj$$,$product_details$$,global.getModel("sokhonpp"),async($detail$$,$callback$$)=>
|
|
16
16
|
{$detail$$.nxt=1;$detail$$.sl_nhap=$detail$$.sl_xuat;$detail$$.gia_von_nt=$detail$$.gia_ban_nt;$detail$$.gia_von=$detail$$.gia_ban;$detail$$.tien_nhap_nt=$detail$$.tien_nt-($detail$$.tien_ck_nt||0);$detail$$.tien_nhap=$detail$$.tien-($detail$$.tien_ck||0);$detail$$.tk_co=$obj$$.tk_co;$detail$$.ma_kho=$obj$$.ma_kho_npp;$detail$$.sl_xuat=0;$detail$$.sl_xuat_qd=0;$detail$$.tien_xuat=$detail$$.tien_xuat_nt=0;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)}):$callback$jscomp$0$$()})}},
|
|
@@ -36,10 +36,10 @@ $tt$$.dien_giai="Hoa h\u1ed3ng cho \u0111i\u1ec1u h\u00e0nh kinh doanh";$tt$$.ma
|
|
|
36
36
|
$d$jscomp$11_detail$$.tk_vt;$d$jscomp$11_detail$$.tien_nt=$d$jscomp$11_detail$$.tien_xuat_nt;$d$jscomp$11_detail$$.tien=$d$jscomp$11_detail$$.tien_xuat;$details_giavon$$.push($d$jscomp$11_detail$$);$d$jscomp$11_detail$$.promotion&&$d$jscomp$11_detail$$.promotion.details_km&&$d$jscomp$11_detail$$.promotion.details_km.forEach($detail$$=>{$detail$$.ma_vt&&($detail$$.tk_no=$detail$$.tk_gv,$detail$$.ma_kh||($detail$$.ma_kh=$obj$$.ma_kh),$detail$$.tk_co=$detail$$.tk_vt,$detail$$.tien_nt=$detail$$.tien_xuat_nt||
|
|
37
37
|
0,$detail$$.tien=$detail$$.tien_xuat||0,$details_giavon$$.push($detail$$))})});$obj$$.promotion&&$obj$$.promotion.forEach(function($detail$$){$detail$$.ma_vt&&($detail$$.tk_no=$detail$$.tk_gv,$detail$$.ma_kh||($detail$$.ma_kh=$obj$$.ma_kh),$detail$$.tk_co=$detail$$.tk_vt,$detail$$.tien_nt=$detail$$.tien_xuat_nt||0,$detail$$.tien=$detail$$.tien_xuat||0,$details_giavon$$.push($detail$$))});async.series({xdtk:$callback$$=>{$details_giavon$$.joinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["tk_vt",
|
|
38
38
|
"gia_mua","tk_gv"]},()=>{$details_giavon$$.forEach($s$$=>{$s$$.tk_co||($s$$.tk_co=$s$$.tk_vt||$options$$.tk_vt);$s$$.tk_no||($s$$.tk_no=$s$$.tk_gv||$options$$.tk_gv);$s$$.ma_nt="VND";$s$$.ty_gia=1});$callback$$()})}},()=>{$details$$=$details$$.concat($details_giavon$$);(new PostSocai($obj$$,$details$$)).run(function($e$$,$rs$$){$callback$jscomp$0$$($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$$,
|
|
39
|
-
$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_ct_nt")-$obj$$.details.csum("tien_ck_nt")+($obj$$.tien_thue_dc_nt||$obj$$.details.csum("tien_thue_nt"))+($obj$$.tien_phi_vc_nt||0),$detail$$.tien=$detail$$.tien_nt
|
|
40
|
-
$obj$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)}):Tdttno.deleteMany({id_ct:$obj$$._id},function($error$$){$callback$jscomp$0$$($error$$)})})},thanhtoanhoahongnv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong||!$obj$$.tien_hoa_hong||!$obj$$.user_nv||!$obj$$.chuyen_ngay)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_nhan_vien$$=
|
|
41
|
-
username:$obj$$.user_nv,wallet_type:1});if(!$wallet_nhan_vien$$){$wallet_nhan_vien$$=(new global.getModel("asskey"))({user_created:$obj$$.user_nv,username:$obj$$.user_nv,id_app:$obj$$.id_app,wallet_type:1});const $wallet$$=await DirectSecp256k1HdWallet.generate(24,{prefix:configs.ADDRESS_PREFIX});let $accounts$$=await $wallet$$.getAccounts();$wallet_nhan_vien$$.address=$accounts$$[0].address;$wallet_nhan_vien$$.mnemonic=$wallet$$.mnemonic
|
|
42
|
-
await $wallet_nhan_vien$$.save()}let $amount$$=$obj$$.tien_hoa_hong,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_nhan_vien$$.address,$amount$$,$denom$$,$memo$$,"","2");$obj$$.da_chuyen_hoa_hong=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",
|
|
39
|
+
$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_ct_nt")-$obj$$.details.csum("tien_ck_nt")-($obj$$.tien_ck_hd||0)+($obj$$.tien_thue_dc_nt||$obj$$.details.csum("tien_thue_nt"))+($obj$$.tien_phi_vc_nt||0),$detail$$.tien=$detail$$.tien_nt*
|
|
40
|
+
$obj$$.ty_gia}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$$)})})},thanhtoanhoahongnv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong||!$obj$$.tien_hoa_hong||!$obj$$.user_nv||!$obj$$.chuyen_ngay)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_nhan_vien$$=
|
|
41
|
+
await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_nv,wallet_type:1});if(!$wallet_nhan_vien$$){$wallet_nhan_vien$$=(new global.getModel("asskey"))({user_created:$obj$$.user_nv,username:$obj$$.user_nv,id_app:$obj$$.id_app,wallet_type:1});const $wallet$$=await DirectSecp256k1HdWallet.generate(24,{prefix:configs.ADDRESS_PREFIX});let $accounts$$=await $wallet$$.getAccounts();$wallet_nhan_vien$$.address=$accounts$$[0].address;$wallet_nhan_vien$$.mnemonic=$wallet$$.mnemonic;
|
|
42
|
+
$wallet_nhan_vien$$.name="T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng";await $wallet_nhan_vien$$.save()}let $amount$$=$obj$$.tien_hoa_hong,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;await spend($appInfo$$,$obj$$.be_introduced,$wallet_nhan_vien$$.address,$amount$$,$denom$$,$memo$$,"","2");$obj$$.da_chuyen_hoa_hong=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",
|
|
43
43
|
$e$$)}$callback$$()})},thanhtoanhoahonggt:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_gt||!$obj$$.tien_hoa_hong_gt||!$obj$$.user_gt||!$obj$$.chuyen_ngay_gt)return $callback$$();setImmediate(async()=>{try{if($appInfo$$.wallet_address&&$appInfo$$.wallet_token&&$appInfo$$.tang_gioi_thieu_denom){let $wallet_gt$$=await global.getModel("asskey").findOne({id_app:$appInfo$$._id.toString(),username:$obj$$.user_gt,wallet_type:1});if(!$wallet_gt$$){$wallet_gt$$=(new global.getModel("asskey"))({user_created:$obj$$.user_gt,
|
|
44
44
|
username:$obj$$.user_gt,id_app:$obj$$.id_app,wallet_type:1});const $wallet$$=await DirectSecp256k1HdWallet.generate(24,{prefix:configs.ADDRESS_PREFIX});let $accounts$$=await $wallet$$.getAccounts();$wallet_gt$$.address=$accounts$$[0].address;$wallet_gt$$.mnemonic=$wallet$$.mnemonic;$wallet_gt$$.name="T\u00e0i kho\u1ea3n nh\u1eadn th\u01b0\u1edfng";await $wallet_gt$$.save()}let $amount$$=$obj$$.tien_hoa_hong_gt,$denom$$=$appInfo$$.tang_gioi_thieu_denom,$memo$$=`Hoa h\u1ed3ng cho \u0111\u01a1n h\u00e0ng s\u1ed1 ${$obj$$.so_ct}: ${numeral($amount$$).format()} ${$denom$$.toUpperCase()}`;
|
|
45
45
|
await spend($appInfo$$,$obj$$.be_introduced,$wallet_gt$$.address,$amount$$,$denom$$,$memo$$,$obj$$.introduce_code,"2");$obj$$.da_chuyen_hoa_hong_gt=!0;await model.updateOne({_id:$obj$$._id},{da_chuyen_hoa_hong_gt:!0})}}catch($e$$){console.error("Kh\u00f4ng th\u1ec3 thanh to\u00e1n ti\u1ec1n hoa h\u1ed3ng",$e$$)}$callback$$()})},thanhtoanhoahongctv:$callback$$=>{if($obj$$.da_chuyen_hoa_hong_ctv||!$obj$$.thu_nhap_ctv||!$obj$$.user_ctv||!$obj$$.chuyen_ngay_ctv)return $callback$$();setImmediate(async()=>
|
|
@@ -99,4 +99,10 @@ var $headers_url_token$$=`${$app$$.viettel_url_service.trim()}/auth/login`;try{$
|
|
|
99
99
|
"Content-Type":"application/json"};$auth_id_app$$=void 0}else $data$$.generalInvoiceInfo.invoiceIssuedDate=moment($ct$$.ngay_hd).format("YYYY-MM-DD"),$kh_result_export_einvoice_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()}`;if($msg_e_req$$.query.check_data)return $next$$(null,$data$$);axios({method:"post",
|
|
100
100
|
url:$kh_result_export_einvoice_url$$,data:"1"!=$app$$.viettel_version?JSON.stringify($data$$):$data$$,auth:$auth_id_app$$,headers:$headers_url_token$$}).then(async $data_rs_res$$=>{$data_rs_res$$=$data_rs_res$$.data;if(!$data_rs_res$$)return $next$$("Kh\u00f4ng th\u1ec3 xu\u1ea5t ho\u00e1 \u0111\u01a1n");if($data_rs_res$$.errorCode)return $next$$($data_rs_res$$.description);$ct$$.result_export_einvoice=$data_rs_res$$;$ct$$.so_hd=$ct$$.result_export_einvoice.result.invoiceNo;await model.updateOne({_id:$ct$$._id},
|
|
101
101
|
$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});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_rs_res$$)}).catch($e$$=>{console.error("error invocie viettel",$e$$.response);let $msg_e$$=$e$$.response?
|
|
102
|
-
$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$$)})},{method:"GET"})
|
|
102
|
+
$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$$)})},{method:"GET"});$contr$$.createRoute("import/invoice",async($req$$,$next$$)=>{var $invoices_tu_ngay$$=$req$$.query.tu_ngay;let $den_ngay$$=$req$$.query.den_ngay;if(!$invoices_tu_ngay$$||!$den_ngay$$)return $next$$("C\u1ea7n cung c\u1ea5p \u0111i\u1ec1u ki\u1ec7n tu_ngay,den_ngay");const $id_app$$=$req$$.user.current_id_app,
|
|
103
|
+
$app$$=await App.findOne({_id:$id_app$$});if(!$app$$)return $next$$("Kh\u00f4ng t\u00ecm th\u1ea5y c\u00f4ng ty n\u00e0y");const $voucher_options$$=(await global.getModel("options").findOne({id_app:$id_app$$,id_func:$contr$$.name},{option:1}).lean()||{}).option||{};if(!$voucher_options$$.ma_kho)return $next$$("B\u1ea1n c\u1ea7n c\u1eadp nh\u1eadt tu\u1ef3 ch\u1ecdn m\u00e3 kho m\u1eb7c \u0111\u1ecbnh trong tu\u1ef3 ch\u1ecdn c\u1ee7a ch\u1ee9ng t\u1eeb");if(!$voucher_options$$.tk_no)return $next$$("B\u1ea1n c\u1ea7n c\u1eadp nh\u1eadt tu\u1ef3 ch\u1ecdn t\u00e0i kho\u1ea3n n\u1ee3 m\u1eb7c \u0111\u1ecbnh trong tu\u1ef3 ch\u1ecdn c\u1ee7a ch\u1ee9ng t\u1eeb");
|
|
104
|
+
if(!$voucher_options$$.tk_vt)return $next$$("B\u1ea1n c\u1ea7n c\u1eadp nh\u1eadt tu\u1ef3 ch\u1ecdn t\u00e0i v\u1eadt t\u01b0 m\u1eb7c \u0111\u1ecbnh trong tu\u1ef3 ch\u1ecdn c\u1ee7a ch\u1ee9ng t\u1eeb");if(!$voucher_options$$.tk_gv)return $next$$("B\u1ea1n c\u1ea7n c\u1eadp nh\u1eadt tu\u1ef3 ch\u1ecdn t\u00e0i kho\u1ea3n gi\u00e1 v\u1ed1n m\u1eb7c \u0111\u1ecbnh trong tu\u1ef3 ch\u1ecdn c\u1ee7a ch\u1ee9ng t\u1eeb");if(!$voucher_options$$.tk_dt)return $next$$("B\u1ea1n c\u1ea7n c\u1eadp nh\u1eadt tu\u1ef3 ch\u1ecdn t\u00e0i kho\u1ea3n doanh thu m\u1eb7c \u0111\u1ecbnh trong tu\u1ef3 ch\u1ecdn c\u1ee7a ch\u1ee9ng t\u1eeb");
|
|
105
|
+
try{$invoices_tu_ngay$$=new Date($invoices_tu_ngay$$);$den_ngay$$=new Date($den_ngay$$);let $invoices_vnpt$$=await utils.getInvoices($app$$,{tu_ngay:$invoices_tu_ngay$$,den_ngay:$den_ngay$$});$invoices_tu_ngay$$=[];for(let $ivn$$ of $invoices_vnpt$$)await model.findOne({id_app:$id_app$$,id_invoice:$ivn$$.id_invoice}).lean()||($ivn$$.ma_kh=$ivn$$.ma_kh||$ivn$$.ten_kh.replace(/[^\w\s]/gi,"").split(" ").join("").toUpperCase().substring(0,32),$ivn$$.trang_thai="5",$invoices_tu_ngay$$.push($ivn$$));let $khs$$=
|
|
106
|
+
await $invoices_tu_ngay$$.asyncGroupBy(["ma_kh","ten_kh","dia_chi","ma_so_thue","dien_thoai"],[]);for(let $kh$$ of $khs$$)$kh$$.id_app=$id_app$$,$kh$$.ma_kh||($kh$$.ma_kh=$kh$$.ten_kh.replace(/[^\w\s]/gi,"").split(" ").join("").toUpperCase()),await global.getModel("customer").asyncCreateCustomer($kh$$);let $vts$$=await $invoices_tu_ngay$$.map($i$$=>$i$$.details||[]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]).asyncGroupBy(["ma_vt","ten_vt","ma_dvt"],[]),$dvts$$=await $vts$$.asyncGroupBy(["ma_dvt"],
|
|
107
|
+
[]);for(let $dvt$$ of $dvts$$)$dvt$$.id_app=$id_app$$,$dvt$$.ten_dvt=$dvt$$.ma_dvt,$dvt$$.status=!0,$dvt$$.user_created=$req$$.user.email,await global.getModel("dmdvt").findOne({ma_dvt:$dvt$$.ma_dvt,id_app:$dvt$$.id_app}).lean()||(console.log("create dvt",$dvt$$),await global.getModel("dmdvt").create($dvt$$));for(let $vt$$ of $vts$$)$vt$$.id_app=$id_app$$,$vt$$.status=!0,$vt$$.user_created=$req$$.user.email,$vt$$.tk_vt=$voucher_options$$.tk_vt,$vt$$.tk_dt=$voucher_options$$.tk_dt,$vt$$.tk_gv=$voucher_options$$.tk_gv,
|
|
108
|
+
await global.getModel("dmvt").findOne({ma_vt:$vt$$.ma_vt,id_app:$vt$$.id_app}).lean()||(console.log("create product",$vt$$),await global.getModel("dmvt").create($vt$$),await global.getModel("dmqddvt").create({id_app:$id_app$$,status:!0,ma_vt:$vt$$.ma_vt,ma_dvt:$vt$$.ma_dvt,tu:1,ma:1}));$contr$$.import($req$$.user,$id_app$$,$invoices_tu_ngay$$,($e$$,$rs$$)=>$next$$($e$$,$rs$$))}catch($e$$){return $next$$($e$$.error||$e$$.messate||$e$$)}},{method:"GET"})};
|
|
@@ -1,36 +1,40 @@
|
|
|
1
1
|
'use strict';const PostBook=require("../../libs/post-book"),PostSocai=require("../../libs/post-socai"),utils=require("../../libs/utils"),Sokho=global.getModel("sokho"),Sokhott=global.getModel("sokhott"),Vatra=global.getModel("vatra"),dmvt=global.getModel("dmvt"),dmkho=global.getModel("dmkho"),account=global.getModel("account"),customer=global.getModel("customer"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),model=global.getModel("hd3"),controller=
|
|
2
2
|
require("../../controllers/controller"),async=require("async"),ma_ct="HD3";
|
|
3
3
|
module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,check_stock:!1,sort:{ngay_ct:-1,so_ct:-1}});$contr_router$$.route();$contr_router$$.post=async function($obj$jscomp$0$$,$fn$$){$fn$$||($fn$$=function(){});$obj$jscomp$0$$.details.forEach($detail$$=>{$detail$$.tien_ct_nt||($detail$$.gia_ban_ct_nt=$detail$$.gia_ban_nt,$detail$$.tien_ct_nt=$detail$$.tien_nt,$detail$$.tien_ct=$detail$$.tien,$detail$$.tien_ck_nt=0,$detail$$.tien_ck=
|
|
4
|
-
0,$detail$$.thue_suat=$detail$$.thue_suat||0,$detail$$.tien_thue_nt=$detail$$.tien_thue_nt||0,$detail$$.gia_ban_nt=$detail$$.gia_ban_ct_nt*(1+$detail$$.thue_suat/100))});let $product_details$$=[...$obj$jscomp$0$$.details].map($detail$$=>$detail$$.combo&&0<$detail$$.combo.length?$detail$$.combo.map($item_combo
|
|
5
|
-
({...$detail$$,thue_suat:($detail$$.ma_thue?$detail$$.thue_suat:$obj$jscomp$0$$.thue_suat)||0,ma_thue:$detail$$.ma_thue||$obj$jscomp$0$$.ma_thue,tien_thue_nt:$detail$$.tien_thue_nt||0,tien_thue:$detail$$.tien_thue||0})).filter($d$$=>$d$$.ma_thue);await $details_thue$$.filter($r$$=>!$r$$.tk_thue_co&&$r$$.ma_thue).asyncJoinModel2($obj$jscomp$0$$.id_app,"vat",{where:"ma_thue",fields:["tk_thue_co"]});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
$obj$$.
|
|
9
|
-
|
|
10
|
-
$
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
$
|
|
15
|
-
|
|
16
|
-
$
|
|
17
|
-
$
|
|
18
|
-
$r$$.
|
|
19
|
-
$
|
|
20
|
-
$obj
|
|
21
|
-
|
|
22
|
-
1
|
|
23
|
-
|
|
24
|
-
$
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
$
|
|
29
|
-
|
|
30
|
-
$
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
value:"
|
|
4
|
+
0,$detail$$.thue_suat=$detail$$.thue_suat||0,$detail$$.tien_thue_nt=$detail$$.tien_thue_nt||0,$detail$$.gia_ban_nt=$detail$$.gia_ban_ct_nt*(1+$detail$$.thue_suat/100))});let $product_details$$=[...$obj$jscomp$0$$.details].map($detail$$=>$detail$$.combo&&0<$detail$$.combo.length?$detail$$.combo.map($item_combo$$=>{$item_combo$$=$item_combo$$.toObject?$item_combo$$.toObject():{...$item_combo$$};$item_combo$$.ma_kho=$detail$$.ma_kho;$item_combo$$.pn_gia_tb=$detail$$.pn_gia_tb;return $item_combo$$}):
|
|
5
|
+
[$detail$$]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]),$details_thue$$=$obj$jscomp$0$$.details.map($detail$$=>({...$detail$$,thue_suat:($detail$$.ma_thue?$detail$$.thue_suat:$obj$jscomp$0$$.thue_suat)||0,ma_thue:$detail$$.ma_thue||$obj$jscomp$0$$.ma_thue,tien_thue_nt:$detail$$.tien_thue_nt||0,tien_thue:$detail$$.tien_thue||0})).filter($d$$=>$d$$.ma_thue);await $details_thue$$.filter($r$$=>!$r$$.tk_thue_co&&$r$$.ma_thue).asyncJoinModel2($obj$jscomp$0$$.id_app,"vat",{where:"ma_thue",fields:["tk_thue_co"]});
|
|
6
|
+
async.series({post_tdttno:$callback$jscomp$0$$=>{setImmediate(async()=>{var $hds_tdttno_tt$$=[...(new Set(($obj$jscomp$0$$.details||[]).filter($d$$=>$d$$.id_hd).map($d$$=>$d$$.id_hd)))];if(0==$hds_tdttno_tt$$.length)return $callback$jscomp$0$$();$hds_tdttno_tt$$=(await global.getModel("tdttno").getBalance({id_app:$obj$jscomp$0$$.id_app,id_hd:{$in:$hds_tdttno_tt$$}})).filter($i$$=>0<$i$$.con_lai_nt).map($invoice$$=>{let $t_invoice$$={sel:!1,id_tdtt:$invoice$$._id,line:$invoice$$.line,id_hd:$invoice$$.id_ct,
|
|
7
|
+
so_hd:$invoice$$.so_hd||$invoice$$.so_ct,ngay_hd:$invoice$$.ngay_hd||$invoice$$.ngay_ct,tien_hd_nt:$invoice$$.tien_nt};$t_invoice$$.ma_nt_hd=$invoice$$.ma_nt;$t_invoice$$.ty_gia_hd=$invoice$$.ty_gia;$t_invoice$$.ma_kh=$invoice$$.ma_kh;$t_invoice$$.dien_giai=$invoice$$.dien_giai;$t_invoice$$.tk_co=$invoice$$.tk_no;$t_invoice$$.da_thanh_toan_nt=$invoice$$.da_thanh_toan_nt;$t_invoice$$.da_thanh_toan=$invoice$$.da_thanh_toan;$t_invoice$$.con_lai_nt=$invoice$$.con_lai_nt;$t_invoice$$.con_lai=$invoice$$.con_lai;
|
|
8
|
+
$t_invoice$$.tien_nt=$obj$jscomp$0$$.details.filter($d$$=>$d$$.id_hd===$t_invoice$$.id_hd).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$t_invoice$$.tien=$t_invoice$$.tien_nt*$obj$jscomp$0$$.ty_gia;$t_invoice$$.thanh_toan_qd=$t_invoice$$.tien/$t_invoice$$.ty_gia_hd;return $t_invoice$$});(new PostBook($obj$jscomp$0$$,$hds_tdttno_tt$$,global.getModel("tdttno_tt"),function($tdttno$$,$callback$$){$callback$$($tdttno$$)})).run(function($e$$,$details$$){if($e$$)return $callback$jscomp$0$$($e$$);
|
|
9
|
+
async.mapSeries($details$$,($detail$$,$callback$$)=>{$detail$$.con_lai_nt<=$detail$$.thanh_toan_qd?global.getModel("tdttno").findOneAndUpdate({_id:$detail$$.id_tdtt.toString()},{$set:{tat_toan:!0}},($error$$,$result$$)=>{$callback$$($error$$,$result$$)}):$callback$$(null,$detail$$)},($e$$,$rs$$)=>{$callback$jscomp$0$$($e$$,$rs$$)})})})},post_sokho:function($callback$jscomp$0$$){(new PostBook($obj$jscomp$0$$,$product_details$$,Sokho,async function($detail$$,$callback$$){$detail$$.nxt=1;$detail$$.tk_co=
|
|
10
|
+
$obj$jscomp$0$$.tk_co;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},post_sokhott:function($callback$jscomp$0$$){(new PostBook($obj$jscomp$0$$,$product_details$$,Sokhott,async function($detail$$,$callback$$){$detail$$.nxt=1;$detail$$.tk_co=$obj$jscomp$0$$.tk_co;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},post_vatra:function($callback$jscomp$0$$){(async()=>{$obj$jscomp$0$$.ngay_hd?0==$details_thue$$.length&&$obj$jscomp$0$$.so_hd&&
|
|
11
|
+
$obj$jscomp$0$$.ngay_hd&&$obj$jscomp$0$$.ma_thue&&$obj$jscomp$0$$.t_thue_nt?(new PostBook($obj$jscomp$0$$,[{...$obj$jscomp$0$$}],Vatra,function($obj$$,$callback$$){$obj$$.tk_du_thue=$obj$$.tk_co;$obj$$.t_tien_nt=-($obj$$.details.csum("tien_ct_nt")-$obj$$.details.csum("tien_ck_nt"));$obj$$.t_tien=-($obj$$.details.csum("tien_ct")-$obj$$.details.csum("tien_ck"));$obj$$.t_thue_nt=0-$obj$$.t_thue_nt;$obj$$.t_thue=0-$obj$$.t_thue;$obj$$.ten_vt||($obj$$.ten_vt=$obj$$.dien_giai);$callback$$($obj$$)})).run(function($e$$,
|
|
12
|
+
$rs$$){$callback$jscomp$0$$($e$$,$rs$$)}):$details_thue$$.asyncGroupBy(["ma_thue","thue_suat","ten_vt_vat","tk_thue_co"],"tien_ct_nt tien_ct tien_ck_nt tien_ck tien_thue tien_thue_nt tien_nt tien".split(" ")).then($ds$$=>{if(1==$ds$$.length){let $tien_thue_nt$$=$ds$$.map($d$$=>$d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$tien_thue$$=$ds$$.map($d$$=>$d$$.tien_thue).reduce(($a$$,$b$$)=>$a$$+$b$$,0);0==$tien_thue_nt$$&&0==$tien_thue$$&&($tien_thue_nt$$=$obj$jscomp$0$$.t_thue_nt||0,$tien_thue$$=
|
|
13
|
+
$obj$jscomp$0$$.t_thue||0);$ds$$[0].tien_thue_nt=$tien_thue_nt$$;$ds$$[0].tien_thue=$tien_thue$$}(new PostBook($obj$jscomp$0$$,$ds$$,Vatra,function($detail$$,$callback$$){try{$detail$$.tk_du_thue=$obj$jscomp$0$$.tk_co,$detail$$.t_tien_nt=-($detail$$.tien_ct_nt-$detail$$.tien_ck_nt),$detail$$.t_tien=-($detail$$.tien_ct-$detail$$.tien_ck),$detail$$.t_thue_nt=0-$detail$$.tien_thue_nt,$detail$$.t_thue=0-$detail$$.tien_thue,$detail$$.ten_vt=$detail$$.ten_vt_vat||$obj$jscomp$0$$.ten_vt||$obj$jscomp$0$$.dien_giai}catch($e$$){console.error($e$$,
|
|
14
|
+
$obj$jscomp$0$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})}):$callback$jscomp$0$$()})()},post_socai:function($callback$$){(async()=>{const $details_sc$$=[];if(0===$details_thue$$.length&&$obj$jscomp$0$$.t_thue_nt&&$obj$jscomp$0$$.tk_thue_co){const $o$$={...$obj$jscomp$0$$};$o$$.tk_co=$obj$jscomp$0$$.tk_co;$o$$.tk_no=$obj$jscomp$0$$.tk_thue_co;$o$$.tien_nt=Math.abs($obj$jscomp$0$$.t_thue_nt);$o$$.tien=Math.abs($obj$jscomp$0$$.t_thue);$o$$.dien_giai_thue&&
|
|
15
|
+
($o$$.dien_giai=$o$$.dien_giai_thue);$details_sc$$.push($o$$)}else $details_thue$$.forEach($v_vatra$$=>{$v_vatra$$={...$v_vatra$$};$v_vatra$$.tk_co=$obj$jscomp$0$$.tk_co;$v_vatra$$.tk_no=$v_vatra$$.tk_thue_co;$v_vatra$$.tien_nt=$v_vatra$$.tien_thue_nt;$v_vatra$$.tien=$v_vatra$$.tien_thue;$details_sc$$.push($v_vatra$$)});$obj$jscomp$0$$.details.forEach(function($d$jscomp$9_detail$$){$d$jscomp$9_detail$$={...$d$jscomp$9_detail$$};$d$jscomp$9_detail$$.tien_ct_nt||($d$jscomp$9_detail$$.tien_ct_nt=$d$jscomp$9_detail$$.tien_nt,
|
|
16
|
+
$d$jscomp$9_detail$$.tien_ct=$d$jscomp$9_detail$$.tien);$d$jscomp$9_detail$$.tk_no=$d$jscomp$9_detail$$.tk_tl||"52131";$d$jscomp$9_detail$$.ma_kh||($d$jscomp$9_detail$$.ma_kh=$obj$jscomp$0$$.ma_kh);$d$jscomp$9_detail$$.tk_co=$obj$jscomp$0$$.tk_co||"1111";$d$jscomp$9_detail$$.tien_nt=$d$jscomp$9_detail$$.tien_ct_nt-($d$jscomp$9_detail$$.tien_ck_nt||0);$d$jscomp$9_detail$$.tien=$d$jscomp$9_detail$$.tien_ct-($d$jscomp$9_detail$$.tien_ck||0);$details_sc$$.push($d$jscomp$9_detail$$)});[...$product_details$$].forEach(function($d$jscomp$10_detail$$){$d$jscomp$10_detail$$=
|
|
17
|
+
{...$d$jscomp$10_detail$$};$d$jscomp$10_detail$$.tk_no=$d$jscomp$10_detail$$.tk_vt||"1561";$d$jscomp$10_detail$$.ma_kh||($d$jscomp$10_detail$$.ma_kh=$obj$jscomp$0$$.ma_kh);$d$jscomp$10_detail$$.tk_co=$d$jscomp$10_detail$$.tk_gv||"6321";$d$jscomp$10_detail$$.tien_nt=$d$jscomp$10_detail$$.tien_nhap_nt;$d$jscomp$10_detail$$.tien=$d$jscomp$10_detail$$.tien_nhap;$details_sc$$.push($d$jscomp$10_detail$$)});(await $obj$jscomp$0$$.details.filter($r$$=>$r$$.tien_hoa_hong_ctv&&$r$$.ma_ctv).asyncGroupBy(["ma_ctv",
|
|
18
|
+
"tk_cp_ctv","tk_cn_ctv"],["tien_hoa_hong_ctv"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_co=$r$$.tk_cp_ctv;$tt$$.tk_no=$r$$.tk_cn_ctv;$tt$$.ma_kh=$r$$.ma_ctv;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong_ctv;$tt$$.tk_no&&$tt$$.tk_co&&$tt$$.tien&&$details_sc$$.push($tt$$)});(await $obj$jscomp$0$$.details.filter($r$$=>$r$$.tien_hoa_hong_ctv2&&$r$$.ma_ctv2).asyncGroupBy(["ma_ctv2","tk_cp_ctv","tk_cn_ctv"],["tien_hoa_hong_ctv2"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_co=$r$$.tk_cp_ctv;$tt$$.tk_no=$r$$.tk_cn_ctv;
|
|
19
|
+
$tt$$.ma_kh=$r$$.ma_ctv2;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong_ctv2;$tt$$.tk_no&&$tt$$.tk_co&&$tt$$.tien&&$details_sc$$.push($tt$$)});(await $obj$jscomp$0$$.details.filter($r$$=>$r$$.tien_hoa_hong&&$r$$.ma_kh_hoa_hong).asyncGroupBy(["ma_kh_hoa_hong","tk_no_hoa_hong","tk_co_hoa_hong"],["tien_hoa_hong"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_co=$r$$.tk_no_hoa_hong;$tt$$.tk_no=$r$$.tk_co_hoa_hong;$tt$$.ma_kh=$r$$.ma_kh_hoa_hong;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong;$tt$$.tien=$tt$$.tien_nt*
|
|
20
|
+
($obj$jscomp$0$$.ty_gia||1);$tt$$.check_balance=!1;$tt$$.tk_no&&$tt$$.tk_co&&$tt$$.tien&&$details_sc$$.push($tt$$)});(await $obj$jscomp$0$$.details.filter($r$$=>$r$$.tien_hoa_hong_gt&&$r$$.ma_kh_hoa_hong_gt).asyncGroupBy(["ma_kh_hoa_hong_gt","tk_no_hoa_hong_gt","tk_co_hoa_hong_gt"],["tien_hoa_hong_gt"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_co=$r$$.tk_no_hoa_hong_gt;$tt$$.tk_no=$r$$.tk_co_hoa_hong_gt;$tt$$.ma_kh=$r$$.ma_kh_hoa_hong_gt;$tt$$.tien_nt=$r$$.tien_hoa_hong_gt;$tt$$.tien=$tt$$.tien_nt*($obj$jscomp$0$$.ty_gia||
|
|
21
|
+
1);$tt$$.check_balance=!1;$tt$$.tk_no&&$tt$$.tk_co&&$tt$$.tien&&$details_sc$$.push($tt$$)});(await $obj$jscomp$0$$.details.filter($r$$=>$r$$.tien_hoa_hong_ql&&$r$$.ma_kh_hoa_hong_ql).asyncGroupBy(["ma_kh_hoa_hong_ql","tk_no_hoa_hong_ql","tk_co_hoa_hong_ql"],["tien_hoa_hong_ql"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_co=$r$$.tk_no_hoa_hong_ql;$tt$$.tk_no=$r$$.tk_co_hoa_hong_ql;$tt$$.ma_kh=$r$$.ma_kh_hoa_hong_ql;$tt$$.tien_nt=$r$$.tien_hoa_hong_ql;$tt$$.tien=$tt$$.tien_nt*($obj$jscomp$0$$.ty_gia||1);
|
|
22
|
+
$tt$$.check_balance=!1;$tt$$.tk_no&&$tt$$.tk_co&&$tt$$.tien&&$details_sc$$.push($tt$$)});(await $obj$jscomp$0$$.details.filter($r$$=>$r$$.tien_hoa_hong_kho&&$r$$.ma_kh_hoa_hong_kho).asyncGroupBy(["ma_kh_hoa_hong_kho","tk_no_hoa_hong_kho","tk_co_hoa_hong_kho"],["tien_hoa_hong_kho"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_co=$r$$.tk_no_hoa_hong_kho;$tt$$.tk_no=$r$$.tk_co_hoa_hong_kho;$tt$$.ma_kh=$r$$.ma_kh_hoa_hong_kho;$tt$$.tien_nt=$r$$.tien_hoa_hong_kho;$tt$$.tien=$tt$$.tien_nt*($obj$jscomp$0$$.ty_gia||
|
|
23
|
+
1);$tt$$.check_balance=!1;$tt$$.tk_no&&$tt$$.tk_co&&$tt$$.tien&&$details_sc$$.push($tt$$)});(new PostSocai($obj$jscomp$0$$,$details_sc$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})()}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};const $valid$$=function($f_tien_nt_i$$,$obj$$,$next$$){for($f_tien_nt_i$$=0;$f_tien_nt_i$$<$obj$$.details.length;$f_tien_nt_i$$++){const $detail$$=$obj$$.details[$f_tien_nt_i$$];$detail$$.tien_ct_nt||($detail$$.gia_ban_ct_nt=$detail$$.gia_ban_nt,$detail$$.tien_ct_nt=
|
|
24
|
+
$detail$$.tien_nt,$detail$$.tien_ck_nt=0,$detail$$.thue_suat=$detail$$.thue_suat||0,$detail$$.tien_thue_nt=$detail$$.tien_thue_nt||0,$detail$$.gia_ban_nt=$detail$$.gia_ban_ct_nt*(1+$detail$$.thue_suat/100));$detail$$.tien_ck_nt=$detail$$.tien_ck_nt||0;$detail$$.tien_thue_nt=$detail$$.tien_thue_nt||0;$detail$$.tien_nt=$detail$$.tien_ct_nt+$detail$$.tien_thue_nt-$detail$$.tien_ck_nt;$detail$$.line=$f_tien_nt_i$$;$detail$$.tien_ct=utils.round($detail$$.tien_ct_nt*$obj$$.ty_gia,0);$detail$$.tien=utils.round($detail$$.tien_nt*
|
|
25
|
+
$obj$$.ty_gia,0);$detail$$.tien_ck=utils.round($detail$$.tien_ck_nt*$obj$$.ty_gia,0);$detail$$.tien_thue=utils.round($detail$$.tien_thue_nt*$obj$$.ty_gia,0);$detail$$.tien_nhap=$detail$$.tien_nhap_nt}$obj$$.details.find($d$$=>$d$$.tien_thue_nt)?($obj$$.t_thue_nt=$obj$$.details.csum("tien_thue_nt"),$obj$$.t_thue=utils.round($obj$$.t_thue_nt*($obj$$.ty_gia||1),0)):$obj$$.thue_suat&&!$obj$$.t_thue_nt&&($f_tien_nt_i$$="VND"===$obj$$.ma_nt?0:2,$obj$$.t_thue_nt=utils.round(($obj$$.details.csum("tien_ct_nt")-
|
|
26
|
+
$obj$$.details.csum("tien_ck_nt"))*$obj$$.thue_suat/100,$f_tien_nt_i$$),$obj$$.t_thue=utils.round($obj$$.t_thue_nt*($obj$$.ty_gia||1),0));$next$$(null,$obj$$)};$contr_router$$.creating=function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$valid$$($user$$,$obj$$,async function($error$$){if($error$$)return $next$$($error$$);await $obj$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["combo"]});$obj$$.details.filter($d$$=>$d$$.combo).forEach($detail$$=>{$detail$$.combo=
|
|
27
|
+
$detail$$.combo.map($item_combo$$=>{$item_combo$$=$item_combo$$.toObject?$item_combo$$.toObject():{...$item_combo$$};$item_combo$$.sl_nhap_1_combo=$item_combo$$.sl_xuat||0;delete $item_combo$$.sl_xuat;delete $item_combo$$.tien_xuat;delete $item_combo$$.tien_xuat_nt;delete $item_combo$$.px_gia_dd;$item_combo$$.sl_nhap=$item_combo$$.sl_nhap_1_combo*$detail$$.sl_nhap;$item_combo$$.tien_nhap=$item_combo$$.tien_nhap_nt=$item_combo$$.sl_nhap*($item_combo$$.gia_von_nt||0);$item_combo$$.tien=$item_combo$$.tien_nt=
|
|
28
|
+
$item_combo$$.sl_nhap*($item_combo$$.gia_ban_nt||0);$item_combo$$.tien_ck=$item_combo$$.tien_ck_nt=$item_combo$$.sl_nhap*($item_combo$$.tien_ck_nt||0);return $item_combo$$})});$next$$(null,$obj$$)})};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$next$$){$data$$.details=$data$$.details||$obj$$.details;$valid$$($user$$,$data$$,async function($error$$){if($error$$)return $next$$($error$$);await $data$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",setFields:($item$$,$ref$$)=>
|
|
29
|
+
{$item$$.combo&&0!=$item$$.combo.length?$ref$$.combo&&$ref$$.combo.forEach($c$$=>{let $cb$$=$item$$.combo.find($ci$$=>$ci$$.ma_vt===$c$$.ma_vt);$cb$$?$cb$$.sl_nhap_1_combo=$c$$.sl_xuat||0:$item$$.combo.push($c$$)}):$item$$.combo=$ref$$.combo}});$data$$.details.filter($d$$=>$d$$.combo).forEach($detail$$=>{$detail$$.combo=$detail$$.combo.map($item_combo$$=>{$item_combo$$=$item_combo$$.toObject?$item_combo$$.toObject():{...$item_combo$$};void 0==$item_combo$$.sl_nhap_1_combo&&($item_combo$$.sl_nhap_1_combo=
|
|
30
|
+
$item_combo$$.sl_xuat||0);delete $item_combo$$.sl_xuat;delete $item_combo$$.tien_xuat;delete $item_combo$$.tien_xuat_nt;delete $item_combo$$.px_gia_dd;$item_combo$$.sl_nhap=$item_combo$$.sl_nhap_1_combo*$detail$$.sl_nhap;$item_combo$$.tien_nhap=$item_combo$$.tien_nhap_nt=$item_combo$$.sl_nhap*($item_combo$$.gia_von_nt||0);$item_combo$$.tien=$item_combo$$.tien_nt=$item_combo$$.sl_nhap*($item_combo$$.gia_ban_nt||0);$item_combo$$.tien_ck=$item_combo$$.tien_ck_nt=$item_combo$$.sl_nhap*($item_combo$$.tien_ck_nt||
|
|
31
|
+
0);return $item_combo$$})});$next$$(null,$data$$,$obj$$)})};$contr_router$$.view=function($user$$,$items$$,$fn$$){const $id_app$$=$user$$.current_id_app;async.series({tk:function($callback$$){$items$$.filter($item$$=>$item$$.tk_co).joinModel2($id_app$$,account,[{where:{tk_co:"tk"},fields:[{name:"ten_tk_co",value:"ten_tk"}]}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:[{name:"ten_kh",value:"ten_kh"}]}],
|
|
32
|
+
function(){$callback$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.details||($r$$.details=[]);$r$$.details.forEach($d$$=>{if(!$d$$.tien_ct_nt){$d$$.gia_ban_ct_nt=$d$$.gia_ban_nt;$d$$.tien_ct_nt=$d$$.tien_nt;$d$$.tien_ck_nt=$d$$.tien_ck_nt||0;let $thue_suat$$=$d$$.thue_suat||0;$d$$.tien_thue_nt=$d$$.tien_thue_nt||0;$d$$.gia_ban_nt=$d$$.gia_ban_ct_nt*(1+$thue_suat$$/100);$d$$.tien_nt=$d$$.tien_ct_nt-$d$$.tien_ck_nt+$d$$.tien_thue_nt}});$r$$.t_thue_ra=$r$$.details.csum("tien_thue");
|
|
33
|
+
$r$$.t_thue_ra_nt=$r$$.details.csum("tien_thue_nt");$r$$.t_sl=$r$$.details.csum("sl_nhap");$r$$.t_ck=$r$$.details.csum("tien_ck");$r$$.t_ck_nt=$r$$.details.csum("tien_ck_nt");$r$$.t_tien=$r$$.details.csum("tien");$r$$.t_tien_nt=$r$$.details.csum("tien_nt");$r$$.t_tien_ct=$r$$.details.csum("tien_ct");$r$$.t_tien_ct_nt=$r$$.details.csum("tien_ct_nt");$r$$.t_tt=$r$$.t_tien_ct-$r$$.t_ck+$r$$.t_thue_ra;$r$$.t_tt_nt=$r$$.t_tien_ct_nt-$r$$.t_ck_nt+$r$$.t_thue_ra_nt;$r$$.t_tien_nhap=$r$$.details.csum("tien_nhap");
|
|
34
|
+
$r$$.t_tien_nhap_nt=$r$$.details.csum("tien_nhap_nt")});$callback$$()},details_hd2:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($d$$=>$d$$.id_hd&&!$d$$.so_ct_hd).joinModel2($id_app$$,"hd2",[{where:{id_hd:"_id"},fields:[{name:"so_ct_hd",value:"so_ct"},{name:"ngay_ct_hd",value:"ngay_ct"},{name:"ma_ct_hd",value:"ma_ct"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_pbl:function($callback$$){async.mapSeries($items$$,function($r$$,
|
|
35
|
+
$callback1$$){($r$$.details||[]).filter($d$$=>$d$$.id_hd&&!$d$$.so_ct_hd).joinModel2($id_app$$,"pbl",[{where:{id_hd:"_id"},fields:[{name:"so_ct_hd",value:"so_ct"},{name:"ngay_ct_hd",value:"ngay_ct"},{name:"ma_ct_hd",value:"ma_ct"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_so1:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($d$$=>$d$$.id_hd&&!$d$$.so_ct_hd).joinModel2($id_app$$,"so1",[{where:{id_hd:"_id"},fields:[{name:"so_ct_hd",
|
|
36
|
+
value:"so_ct"},{name:"ngay_ct_hd",value:"ngay_ct"},{name:"ma_ct_hd",value:"ma_ct"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_tk:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel($id_app$$,account,[{akey:"tk_vt",bkey:"tk",fields:[{name:"ten_tk_vt",value:"ten_tk"}]},{akey:"tk_gv",bkey:"tk",fields:[{name:"ten_tk_gv",value:"ten_tk"}]},{akey:"tk_tl",bkey:"tk",fields:[{name:"ten_tk_tl",value:"ten_tk"}]}],function(){$callback1$$()})},
|
|
37
|
+
function(){$callback$$()})},details_vt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel($id_app$$,dmvt,[{akey:"ma_vt",bkey:"ma_vt",fields:[{name:"ten_vt",value:"ten_vt"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_tt1:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($d$$=>$d$$.ma_tt1).joinModel2($id_app$$,"dmtt",[{where:{ma_vt:"ma_vt",ma_tt1:"ma_tt"},setFields:($item$$,
|
|
38
|
+
$ref$$)=>{$item$$.thuoc_tinh=$ref$$}}],function(){$callback1$$()})},function(){$callback$$()})},details_kho:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_kho).joinModel($id_app$$,dmkho,[{akey:"ma_kho",bkey:"ma_kho",fields:[{name:"ten_kho",value:"ten_kho"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>
|
|
39
|
+
$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$$,
|
|
40
|
+
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$$)})}};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';const PostBook=require("../../libs/post-book"),PostSocai=require("../../libs/post-socai"),Tdttco=global.getModel("tdttco"),Tdttco_tt=global.getModel("tdttco_tt"),Vatvao=global.getModel("vatvao"),dmvt=global.getModel("dmvt"),dmcpmh=global.getModel("dmcpmh"),account=global.getModel("account"),customer=global.getModel("customer"),dmdt=global.getModel("dmdt"),dmnv=global.getModel("dmnv"),model=global.getModel("hd4"),controller=require("../../controllers/controller"),async=require("async"),
|
|
2
|
+
ma_ct="HD4";
|
|
3
|
+
module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,check_stock:!1,sort:{ngay_ct:-1,so_ct:-1}});$contr_router$$.route();$contr_router$$.post=function($obj$jscomp$0$$,$fn$$){$fn$$||($fn$$=function(){});async.series({post_vatvao:function($callback$jscomp$0$$){(new PostBook($obj$jscomp$0$$,$obj$jscomp$0$$.vatvaos,Vatvao,($detail$$,$callback$$)=>{$detail$$={...$detail$$};$detail$$.ten_vt=$detail$$.ten_vt||$obj$jscomp$0$$.dien_giai||($obj$jscomp$0$$.details||
|
|
4
|
+
[]).map($d$$=>$d$$.ten_vt).join(", ");$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},post_socai:function($callback$$){const $details_sc$$=[];$obj$jscomp$0$$.vatvaos.forEach(function($v_vatvao$$){$v_vatvao$$={...$v_vatvao$$};$v_vatvao$$.tk_no=$v_vatvao$$.tk_thue_no;$v_vatvao$$.tk_co=$v_vatvao$$.tk_du_thue;$v_vatvao$$.tien_nt=$v_vatvao$$.t_thue_nt;$v_vatvao$$.tien=$v_vatvao$$.t_thue;$details_sc$$.push($v_vatvao$$)});$obj$jscomp$0$$.details.forEach(function($d$$){($d$$.details_cp||
|
|
5
|
+
[]).forEach($cp$$=>{const $detail$$={...$d$$};$detail$$.ma_kh=$obj$jscomp$0$$.ma_kh;$detail$$.tk_co=$obj$jscomp$0$$.tk_co;$detail$$.tk_no=$cp$$.tk_no;$detail$$.tien_nt=$cp$$.tien_pb||0;$detail$$.tien=($cp$$.tien_pb||0)*$obj$jscomp$0$$.ty_gia;$details_sc$$.push($detail$$)})});(new PostSocai($obj$jscomp$0$$,$details_sc$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},post_tdttco:function($callback$jscomp$0$$){account.findOne({tk:$obj$jscomp$0$$.tk_co,id_app:$obj$jscomp$0$$.id_app},{tk_cn:1},
|
|
6
|
+
function($error$$,$tk$$){if($error$$)return $callback$jscomp$0$$($error$$);$tk$$&&!0===$tk$$.tk_cn?(new PostBook($obj$jscomp$0$$,[{...$obj$jscomp$0$$}],Tdttco,function($obj$$,$callback$$){$obj$$.so_hd=$obj$$.so_ct;$obj$$.ngay_hd=$obj$$.ngay_ct;$obj$$.tien_nt=$obj$$.details.csum("tien_phi_nt")+($obj$$.vatvaos||[]).csum("t_thue_nt");$obj$$.tien=$obj$$.details.csum("tien_phi")+($obj$$.vatvaos||[]).csum("t_thue");$callback$$($obj$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)}):Tdttco.deleteMany({id_ct:$obj$jscomp$0$$._id},
|
|
7
|
+
function(){$callback$jscomp$0$$($error$$)})})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};const $valid$$=function($i_i$jscomp$1_i$$,$obj$$,$next$$){for($i_i$jscomp$1_i$$=0;$i_i$jscomp$1_i$$<$obj$$.details.length;$i_i$jscomp$1_i$$++){var $ctcpbh_detail$jscomp$2_vatvao$$=$obj$$.details[$i_i$jscomp$1_i$$];$ctcpbh_detail$jscomp$2_vatvao$$.line=$i_i$jscomp$1_i$$;"VND"==$obj$$.ma_nt&&($ctcpbh_detail$jscomp$2_vatvao$$.tien_phi=$ctcpbh_detail$jscomp$2_vatvao$$.tien_phi_nt)}if($obj$$.vatvaos)for($i_i$jscomp$1_i$$=
|
|
8
|
+
0;$i_i$jscomp$1_i$$<$obj$$.vatvaos.length;$i_i$jscomp$1_i$$++)$ctcpbh_detail$jscomp$2_vatvao$$=$obj$$.vatvaos[$i_i$jscomp$1_i$$],$ctcpbh_detail$jscomp$2_vatvao$$.line=$i_i$jscomp$1_i$$,"VND"==$obj$$.ma_nt&&($ctcpbh_detail$jscomp$2_vatvao$$.t_thue=$ctcpbh_detail$jscomp$2_vatvao$$.t_thue_nt);if($obj$$.ctcpbhs)for($i_i$jscomp$1_i$$=0;$i_i$jscomp$1_i$$<$obj$$.ctcpbhs.length;$i_i$jscomp$1_i$$++)$ctcpbh_detail$jscomp$2_vatvao$$=$obj$$.ctcpbhs[$i_i$jscomp$1_i$$],$ctcpbh_detail$jscomp$2_vatvao$$.line=$i_i$jscomp$1_i$$,
|
|
9
|
+
"VND"==$obj$$.ma_nt&&($ctcpbh_detail$jscomp$2_vatvao$$.tien_cp=$ctcpbh_detail$jscomp$2_vatvao$$.tien_cp_nt);$next$$(null,$obj$$)};$contr_router$$.creating=function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$valid$$($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$obj$$)})};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$next$$){Tdttco_tt.find({id_hd:$obj$$._id},function($error$jscomp$0$$,$results$$){if($error$jscomp$0$$)return $next$$($error$jscomp$0$$);
|
|
10
|
+
$results$$&&0<$results$$.length?$next$$("L\u1ed7i: Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt ch\u1ee9ng t\u1eeb n\u00e0y do \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n"):$valid$$($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})})};$contr_router$$.deleting=function($user$$,$obj$$,$next$$){Tdttco_tt.find({id_hd:$obj$$._id},function($error$$,$results$$){if($error$$)return $next$$($error$$);$results$$&&0<$results$$.length?$next$$("L\u1ed7i: Kh\u00f4ng th\u1ec3 x\u00f3a ch\u1ee9ng t\u1eeb n\u00e0y do \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n"):
|
|
11
|
+
$next$$(null,$obj$$)})};$contr_router$$.view=function($user$$,$items$$,$fn$$){let $id_app$$=$user$$.current_id_app;async.series({kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel($id_app$$,customer,[{akey:"ma_kh",bkey:"ma_kh",fields:[{name:"ten_kh",value:"ten_kh"}]}],function(){$callback$$()})},dmdt:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,{where:"ma_dt",fields:"ten_dt"},function(){$callback$$()})},dmnv:function($callback$$){$items$$.filter($item$$=>
|
|
12
|
+
$item$$.ma_nv).joinModel2($id_app$$,dmnv,{where:"ma_nv",fields:"ten_nv"},function(){$callback$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.t_cp=0;$r$$.t_cp_nt=0;$r$$.t_thue_vao=0;$r$$.t_thue_vao_nt=0;$r$$.details&&($r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_cp=$r$$.details.csum("tien_phi"),$r$$.t_cp_nt=$r$$.details.csum("tien_phi_nt"));$r$$.vatvaos&&($r$$.t_thue_vao=$r$$.vatvaos.csum("t_thue"),$r$$.t_thue_vao_nt=$r$$.vatvaos.csum("t_thue_nt"));$r$$.ctcpbhs&&($r$$.t_cp_cpb_nt=
|
|
13
|
+
$r$$.ctcpbhs.csum("tien_cp_nt"),$r$$.t_cp_cpb=$r$$.ctcpbhs.csum("tien_cp"));$r$$.t_tt=$r$$.t_cp+$r$$.t_thue_vao;$r$$.t_tt_nt=$r$$.t_cp_nt+$r$$.t_thue_vao_nt});$callback$$()},details_ct:function($callback$$){async.each($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.id_hd).joinModel2($id_app$$,"hd2",[{where:{id_hd:"_id"},fields:[{so_hd:"so_ct"},{ngay_hd:"ngay_ct"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_vt:function($callback$$){async.each($items$$,
|
|
14
|
+
function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_vt).joinModel2($id_app$$,dmvt,[{where:"ma_vt",fields:["ten_vt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_cpbh:function($callback$$){async.each($items$$,function($ctcpbhs_r$$,$callback1$$){($ctcpbhs_r$$=$ctcpbhs_r$$.ctcpbhs)?$ctcpbhs_r$$.filter($item$$=>$item$$.ma_cp).joinModel2($id_app$$,dmcpmh,[{where:"ma_cp",fields:["ten_cp"]}],function(){$callback1$$()}):$callback1$$()},function(){$callback$$()})}},
|
|
15
|
+
function(){$fn$$(null,$items$$)})}};
|
|
@@ -12,7 +12,8 @@ $results$$&&0<$results$$.length?$next$$("L\u1ed7i: Kh\u00f4ng th\u1ec3 c\u1eadp
|
|
|
12
12
|
$next$$(null,$obj$$)})};$contr_router$$.view=function($user$$,$items$$,$fn$$){let $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_co).joinModel($id_app$$,account,[{akey:"tk_co",bkey:"tk",fields:[{name:"ten_tk_co",value:"ten_tk"}]}],function(){$callback$$()})},
|
|
13
13
|
kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel($id_app$$,customer,[{akey:"ma_kh",bkey:"ma_kh",fields:[{name:"ten_kh",value:"ten_kh"}]}],function(){$callback$$()})},dmdt:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,{where:"ma_dt",fields:"ten_dt"},function(){$callback$$()})},dmnv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_nv).joinModel2($id_app$$,dmnv,{where:"ma_nv",fields:"ten_nv"},function(){$callback$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.t_cp=
|
|
14
14
|
0;$r$$.t_cp_nt=0;$r$$.t_thue_vao=0;$r$$.t_thue_vao_nt=0;$r$$.details&&($r$$.t_sl=$r$$.details.csum("sl_nhap"),$r$$.t_cp=$r$$.details.csum("tien_phi"),$r$$.t_cp_nt=$r$$.details.csum("tien_phi_nt"));$r$$.vatvaos&&($r$$.t_thue_vao=$r$$.vatvaos.csum("t_thue"),$r$$.t_thue_vao_nt=$r$$.vatvaos.csum("t_thue_nt"));$r$$.ctcpmhs&&($r$$.t_cp_cpb_nt=$r$$.ctcpmhs.csum("tien_cp_nt"),$r$$.t_cp_cpb=$r$$.ctcpmhs.csum("tien_cp"));$r$$.t_tt=$r$$.t_cp+$r$$.t_thue_vao;$r$$.t_tt_nt=$r$$.t_cp_nt+$r$$.t_thue_vao_nt});$callback$$()},
|
|
15
|
-
|
|
16
|
-
function(){$callback1$$()})},function(){$callback$$()})},
|
|
17
|
-
|
|
18
|
-
$callback1$$){($ctcpmhs_r$$=$ctcpmhs_r$$.ctcpmhs)?$ctcpmhs_r$$.filter($item$$=>$item$$.ma_cp).joinModel($id_app$$,dmcpmh,[{akey:"ma_cp",bkey:"ma_cp",fields:[{name:"ten_cp",value:"ten_cp"}]}],function(){$callback1$$()}):$callback1$$()},
|
|
15
|
+
details_ct:function($callback$$){async.each($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.id_hd).joinModel2($id_app$$,"pn1",[{where:{id_hd:"_id"},fields:[{so_hd:"so_ct"},{ngay_hd:"ngay_ct"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_tk:function($callback$$){async.each($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.tk_vt).joinModel($id_app$$,account,[{akey:"tk_vt",bkey:"tk",fields:[{name:"ten_tk_vt",value:"ten_tk"}]}],
|
|
16
|
+
function(){$callback1$$()})},function(){$callback$$()})},details_vt:function($callback$$){async.each($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_vt).joinModel($id_app$$,dmvt,[{akey:"ma_vt",bkey:"ma_vt",fields:[{name:"ten_vt",value:"ten_vt"}]}],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,
|
|
17
|
+
[{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||
|
|
18
|
+
[]).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$$()})},details_cpmh:function($callback$$){async.each($items$$,function($ctcpmhs_r$$,$callback1$$){($ctcpmhs_r$$=$ctcpmhs_r$$.ctcpmhs)?$ctcpmhs_r$$.filter($item$$=>$item$$.ma_cp).joinModel($id_app$$,dmcpmh,[{akey:"ma_cp",bkey:"ma_cp",fields:[{name:"ten_cp",value:"ten_cp"}]}],function(){$callback1$$()}):$callback1$$()},
|
|
19
|
+
function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
'use strict';const PostBook=require("../../libs/post-book"),PostSocai=require("../../libs/post-socai"),Sokho=global.getModel("sokho"),Sokhott=global.getModel("sokhott"),Vatvao=global.getModel("vatvao"),dvcs=global.getModel("dvcs"),dmvt=global.getModel("dmvt"),dmkho=global.getModel("dmkho"),account=global.getModel("account"),customer=global.getModel("customer"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),model=global.getModel("pn5"),trangthai=global.getModel("trangthai"),
|
|
2
2
|
controller=require("../../controllers/controller"),async=require("async"),ma_ct="PN5";
|
|
3
|
-
module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,check_stock:!1,sort:{ngay_ct:-1,so_ct:-1}});$contr_router$$.route();$contr_router$$.post=async function($obj$$,$fn$$){$fn$$||($fn$$=function(){});async.series({
|
|
4
|
-
$
|
|
5
|
-
|
|
6
|
-
$
|
|
7
|
-
$
|
|
8
|
-
$
|
|
9
|
-
$
|
|
10
|
-
|
|
11
|
-
$
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
value:"
|
|
15
|
-
|
|
3
|
+
module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,check_stock:!1,sort:{ngay_ct:-1,so_ct:-1}});$contr_router$$.route();$contr_router$$.post=async function($obj$$,$fn$$){$fn$$||($fn$$=function(){});async.series({post_tdttco:$callback$jscomp$0$$=>{setImmediate(async()=>{var $hds_tdttco_tt$$=[...(new Set(($obj$$.details||[]).filter($d$$=>$d$$.id_hd).map($d$$=>$d$$.id_hd)))];if(0==$hds_tdttco_tt$$.length)return $callback$jscomp$0$$();
|
|
4
|
+
$hds_tdttco_tt$$=(await global.getModel("tdttco").getBalance({id_app:$obj$$.id_app,id_hd:{$in:$hds_tdttco_tt$$}})).filter($i$$=>0<$i$$.con_lai_nt).map($invoice$$=>{let $t_invoice$$={sel:!1,id_tdtt:$invoice$$._id,line:$invoice$$.line,id_hd:$invoice$$.id_ct,so_hd:$invoice$$.so_hd||$invoice$$.so_ct,ngay_hd:$invoice$$.ngay_hd||$invoice$$.ngay_ct,tien_hd_nt:$invoice$$.tien_nt};$t_invoice$$.ma_nt_hd=$invoice$$.ma_nt;$t_invoice$$.ty_gia_hd=$invoice$$.ty_gia;$t_invoice$$.ma_kh=$invoice$$.ma_kh;$t_invoice$$.dien_giai=
|
|
5
|
+
$invoice$$.dien_giai;$t_invoice$$.tk_co=$invoice$$.tk_no;$t_invoice$$.da_thanh_toan_nt=$invoice$$.da_thanh_toan_nt;$t_invoice$$.da_thanh_toan=$invoice$$.da_thanh_toan;$t_invoice$$.con_lai_nt=$invoice$$.con_lai_nt;$t_invoice$$.con_lai=$invoice$$.con_lai;$t_invoice$$.tien_nt=$obj$$.details.filter($d$$=>$d$$.id_hd===$t_invoice$$.id_hd).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$t_invoice$$.tien=$t_invoice$$.tien_nt*$obj$$.ty_gia;$t_invoice$$.thanh_toan_qd=$t_invoice$$.tien/$t_invoice$$.ty_gia_hd;
|
|
6
|
+
return $t_invoice$$});(new PostBook($obj$$,$hds_tdttco_tt$$,global.getModel("tdttco_tt"),function($tdttco$$,$callback$$){$callback$$($tdttco$$)})).run(function($e$$,$details$$){if($e$$)return $callback$jscomp$0$$($e$$);async.mapSeries($details$$,($detail$$,$callback$$)=>{$detail$$.con_lai_nt<=$detail$$.thanh_toan_qd?global.getModel("tdttco").findOneAndUpdate({_id:$detail$$.id_tdtt.toString()},{$set:{tat_toan:!0}},($error$$,$result$$)=>{$callback$$($error$$,$result$$)}):$callback$$(null,$detail$$)},
|
|
7
|
+
($e$$,$rs$$)=>{$callback$jscomp$0$$($e$$,$rs$$)})})})},post_sokho:function($callback$jscomp$0$$){(new PostBook($obj$$,$obj$$.details,Sokho,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.px_gia_dd=!0;$detail$$.tk_no=$obj$$.tk_no;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},post_sokhott:function($callback$jscomp$0$$){(new PostBook($obj$$,$obj$$.details,Sokhott,async function($detail$$,$callback$$){$detail$$.nxt=2;$detail$$.px_gia_dd=!0;$detail$$.tk_no=
|
|
8
|
+
$obj$$.tk_no;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},post_socai:function($callback$$){const $details_sc$$=[];$obj$$.details.forEach(function($d$jscomp$4_detail$$){$d$jscomp$4_detail$$={...$d$jscomp$4_detail$$};$d$jscomp$4_detail$$.tk_no=$obj$$.tk_no;$d$jscomp$4_detail$$.ma_kh||($d$jscomp$4_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$4_detail$$.tk_co=$d$jscomp$4_detail$$.tk_vt;$d$jscomp$4_detail$$.tien_nt=$d$jscomp$4_detail$$.tien_xuat_nt;$d$jscomp$4_detail$$.tien=
|
|
9
|
+
$d$jscomp$4_detail$$.tien_xuat;$details_sc$$.push($d$jscomp$4_detail$$)});$obj$$.vatvaos.forEach(function($v_vatvao$$){$v_vatvao$$={...$v_vatvao$$};$v_vatvao$$.tk_no=$v_vatvao$$.tk_du_thue||"1111";$v_vatvao$$.tk_co=$v_vatvao$$.tk_thue_no;$v_vatvao$$.tien_nt=$v_vatvao$$.t_thue_nt;$v_vatvao$$.tien=$v_vatvao$$.t_thue;$details_sc$$.push($v_vatvao$$)});(new PostSocai($obj$$,$details_sc$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},post_vatvao:function($callback$jscomp$0$$){(new PostBook($obj$$,
|
|
10
|
+
$obj$$.vatvaos,Vatvao,($detail$$,$callback$$)=>{$detail$$={...$detail$$};$detail$$.ten_vt=$detail$$.ten_vt||$obj$$.dien_giai||($obj$$.details||[]).map($d$$=>$d$$.ten_vt).join(", ");$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};const $valid$$=function($i$jscomp$1_i$$,$obj$$,$next$$){for($i$jscomp$1_i$$=0;$i$jscomp$1_i$$<$obj$$.details.length;$i$jscomp$1_i$$++){var $detail$jscomp$5_vatvao$$=$obj$$.details[$i$jscomp$1_i$$];
|
|
11
|
+
$detail$jscomp$5_vatvao$$.line=$i$jscomp$1_i$$;"VND"==$obj$$.ma_nt&&($detail$jscomp$5_vatvao$$.tien_hang=$detail$jscomp$5_vatvao$$.tien_hang_nt,$detail$jscomp$5_vatvao$$.tien_ck=$detail$jscomp$5_vatvao$$.tien_ck_nt,$detail$jscomp$5_vatvao$$.tien_xuat=$detail$jscomp$5_vatvao$$.tien_xuat_nt)}if($obj$$.vatvaos)for($i$jscomp$1_i$$=0;$i$jscomp$1_i$$<$obj$$.vatvaos.length;$i$jscomp$1_i$$++)$detail$jscomp$5_vatvao$$=$obj$$.vatvaos[$i$jscomp$1_i$$],$detail$jscomp$5_vatvao$$.line=$i$jscomp$1_i$$,"VND"==$obj$$.ma_nt&&
|
|
12
|
+
($detail$jscomp$5_vatvao$$.t_thue=$detail$jscomp$5_vatvao$$.t_thue_nt);$next$$(null,$obj$$)};$contr_router$$.creating=function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$valid$$($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$obj$$)})};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$next$$){$valid$$($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})};$contr_router$$.view=function($user$$,
|
|
13
|
+
$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$$()})},kh:function($callback$$){$items$$.filter($item$$=>
|
|
14
|
+
$item$$.ma_kh).joinModel($id_app$$,customer,[{akey:"ma_kh",bkey:"ma_kh",fields:[{name:"ten_kh",value:"ten_kh"}]}],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$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.details&&($r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang=$r$$.details.csum("tien_hang"),
|
|
15
|
+
$r$$.t_tien_hang_nt=$r$$.details.csum("tien_hang_nt"),$r$$.t_ck=$r$$.details.csum("tien_ck"),$r$$.t_ck_nt=$r$$.details.csum("tien_ck_nt"),$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat"),$r$$.t_tien_xuat_nt=$r$$.details.csum("tien_xuat_nt"),$r$$.vatvaos?($r$$.t_thue=Math.abs($r$$.vatvaos.csum("t_thue")),$r$$.t_thue_nt=Math.abs($r$$.vatvaos.csum("t_thue_nt"))):($r$$.t_thue=0,$r$$.t_thue_nt=0),$r$$.t_tt=$r$$.t_tien_hang+$r$$.t_thue-$r$$.t_ck,$r$$.t_tt_nt=$r$$.t_tien_hang_nt+$r$$.t_thue_nt-$r$$.t_ck_nt)});
|
|
16
|
+
$callback$$()},details_pn1:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($d$$=>$d$$.id_hd&&!$d$$.so_ct_hd).joinModel2($id_app$$,"pn1",[{where:{id_hd:"_id"},fields:[{name:"so_ct_hd",value:"so_ct"},{name:"ngay_ct_hd",value:"ngay_ct"},{name:"ma_ct_hd",value:"ma_ct"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_tk:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel($id_app$$,
|
|
17
|
+
account,[{akey:"tk_vt",bkey:"tk",fields:[{name:"ten_tk_vt",value:"ten_tk"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_vt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel($id_app$$,dmvt,[{akey:"ma_vt",bkey:"ma_vt",fields:[{name:"ten_vt",value:"ten_vt"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_kho:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>
|
|
18
|
+
$item$$.ma_kho).joinModel($id_app$$,dmkho,[{akey:"ma_kho",bkey:"ma_kho",fields:[{name:"ten_kho",value:"ten_kho"}]}],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$$,
|
|
19
|
+
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$$()})},
|
|
20
|
+
function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};
|
package/server/route.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';const fs=require("fs"),appModel=global.getModel("app"),listinfo=global.getModel("listinfo"),Token=global.getModel("token"),express=require("express"),underscore=require("underscore"),passport=require("passport"),path=require("path"),async=require("async"),sharp=require("sharp"),permission=require("./libs/permission"),{isValidObjectId}=require("mongoose");
|
|
1
|
+
'use strict';const fs=require("fs"),appModel=global.getModel("app"),listinfo=global.getModel("listinfo"),Token=global.getModel("token"),express=require("express"),underscore=require("underscore"),passport=require("passport"),path=require("path"),async=require("async"),sharp=require("sharp"),permission=require("./libs/permission"),docs=require("./libs/docs"),{isValidObjectId}=require("mongoose");
|
|
2
2
|
module.exports=async function($app$$,$cb$$=()=>{},$limiter$jscomp$2_limiter$$=!1){var $createRateLimiterMiddleware_limiter_others$$=global.createRateLimiterMiddleware;const $router$$=global.routerAPI=express.Router();!0!==$limiter$jscomp$2_limiter$$&&(configs.trust_proxy&&$app$$.enable("trust proxy",!0),require("./auths/google")($app$$,passport),require("./auths/facebook")($app$$,passport),require("./auths/local")($app$$,passport),require("./auths/bearer")(passport),$router$$.use(function($req$$,
|
|
3
3
|
$res$$,$next$$){for(let $key$$ in $req$$.query)"true"==$req$$.query[$key$$]&&($req$$.query[$key$$]=!0),"false"==$req$$.query[$key$$]&&($req$$.query[$key$$]=!1);let $access_token$$=$req$$.query.access_token;$access_token$$||($access_token$$=$req$$.get("X-Access-Token"));if($access_token$$){$req$$.query.access_token=$access_token$$;const $send$$=$res$$.send;$res$$.send=function($body$$){Token.updateOne({token:$access_token$$},{used:!0}).then(()=>{});$send$$.call(this,$body$$)}}$next$$()}),$router$$.use(passport.authenticate("bearer",
|
|
4
4
|
{session:!1})),$router$$.param("id_app",function($req$$,$res$$,$next$$,$id_app$$){let $_clientIp$$=(($req$$.headers["x-forwarded-for"]||"").split(",").pop()||$req$$.connection.remoteAddress||$req$$.socket.remoteAddress||$req$$.connection.socket.remoteAddress).split(":");if($id_app$$){if($req$$.user.token_id_app&&$req$$.user.token_id_app!=$id_app$$)return $res$$.status(400).send(`Token is not valid for app ${$id_app$$}`);if(mongoose.Types.ObjectId.isValid($id_app$$))appModel.findById($id_app$$).lean().exec(async($error$$,
|
|
@@ -48,6 +48,8 @@ const $axios$$=require("axios"),$querystring$$=require("querystring");$app$$.get
|
|
|
48
48
|
$app$jscomp$3_id_app$$=await global.getModel("app").findOne({_id:$app$jscomp$3_id_app$$});if(!$app$jscomp$3_id_app$$)return $res$$.status(400).send({error:"App kh\u00f4ng t\u1ed3n t\u1ea1i"});$app$jscomp$3_id_app$$.zalo_oa_id=$headers_zalo_oa_id$$;$app$jscomp$3_id_app$$.zalo_code=$data$jscomp$3_req$$;if($app$jscomp$3_id_app$$.zalo_secret_key&&$app$jscomp$3_id_app$$.zalo_app_id){$headers_zalo_oa_id$$={"Content-Type":"application/x-www-form-urlencoded",secret_key:$app$jscomp$3_id_app$$.zalo_secret_key};
|
|
49
49
|
$data$jscomp$3_req$$={code:$app$jscomp$3_id_app$$.zalo_code,app_id:$app$jscomp$3_id_app$$.zalo_app_id,grant_type:"authorization_code"};try{var $message_zalo_token$$=(await $axios$$.post("https://oauth.zaloapp.com/v4/oa/access_token",$querystring$$.stringify($data$jscomp$3_req$$),{headers:$headers_zalo_oa_id$$})).data;$app$jscomp$3_id_app$$.zalo_access_token=$message_zalo_token$$.access_token;$app$jscomp$3_id_app$$.zalo_refresh_token=$message_zalo_token$$.refresh_token;$app$jscomp$3_id_app$$.zalo_expires_in=
|
|
50
50
|
$message_zalo_token$$.expires_in;$app$jscomp$3_id_app$$.zalo_updated=new Date}catch($e$$){return $message_zalo_token$$=(($e$$.response||{}).data||{}).message,console.error("Can't get access token from zalo",$message_zalo_token$$||$e$$),$res$$.status(400).send({error:$message_zalo_token$$||$e$$.message||$e$$})}}else return $res$$.status(400).send({error:"Ch\u01b0a khai b\u00e1o th\u00f4ng tin zalo app id v\u00e0 secret key cho c\u00f4ng ty n\u00e0y"});await $app$jscomp$3_id_app$$.save();$res$$.send({ok:!0})});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
$
|
|
51
|
+
$app$$.get("/api-docs-auth",$createRateLimiterMiddleware_limiter_others$$,async function($document_req$$,$res$$){$document_req$$=await docs.apiAuth();return $res$$.send($document_req$$)});$app$$.get("/api-docs-fields/:code",$createRateLimiterMiddleware_limiter_others$$,async function($document$jscomp$1_req$$,$res$$){$document$jscomp$1_req$$=await docs.apiFields($document$jscomp$1_req$$.params.code,$document$jscomp$1_req$$.query.id_app);return $res$$.send($document$jscomp$1_req$$)});$app$$.get("/api-docs-input/:code",
|
|
52
|
+
$createRateLimiterMiddleware_limiter_others$$,async function($document$jscomp$2_req$$,$res$$){$document$jscomp$2_req$$=await docs.apiDocs($document$jscomp$2_req$$.params.code,$document$jscomp$2_req$$.query.id_app);return $res$$.send($document$jscomp$2_req$$)});$app$$.get("/api-docs-report/:code",$createRateLimiterMiddleware_limiter_others$$,async function($document$jscomp$3_req$$,$res$$){$document$jscomp$3_req$$=await docs.apiReport($document$jscomp$3_req$$.params.code,$document$jscomp$3_req$$.query.id_app);
|
|
53
|
+
return $res$$.send($document$jscomp$3_req$$)});if(configs.has_api_barcode){const $qr$$=require("qr-image");$app$$.get("/qrcode",$createRateLimiterMiddleware_limiter_others$$,function($req$$,$res$$){let $report$$=$req$$.query.report,$type$$=$req$$.query.type||"svg",$size$$=5;if($req$$.query.size)try{$size$$=Number($req$$.query.size),isNaN($size$$)&&($size$$=void 0)}catch($e$$){console.error("size qrcode is not valid",$e$$)}else $size$$=5;$report$$||($report$$=$req$$.query.data)&&($report$$=Buffer.from($report$$,
|
|
54
|
+
"base64").toString("utf8"));if(!$report$$)return $res$$.status(400).send("miss parameter 'report'");setImmediate(()=>{const $code$$=$qr$$.image($report$$,{type:$type$$,size:$size$$});$res$$.type($type$$);$code$$.pipe($res$$)})});const $bwipjs$$=require("bwip-js"),$stream$$=require("stream");$app$$.get("/barcode",$createRateLimiterMiddleware_limiter_others$$,function($height_req$$,$res$$){let $code$$=$height_req$$.query.code||"code128",$data$$=$height_req$$.query.data;$height_req$$=Number($height_req$$.query.height||
|
|
55
|
+
10);if(!$data$$)return $res$$.status(400).send({error:"Thi\u1ebfu c\u00e1c tham s\u1ed1 data"});$bwipjs$$.toBuffer({bcid:$code$$,text:$data$$,scale:3,height:$height_req$$,includetext:!0,textxalign:"center"},function($bufferStream_e$$,$png$$){$bufferStream_e$$?(console.error($bufferStream_e$$,$code$$,$data$$),$res$$.status(400).send({error:$bufferStream_e$$.message||$bufferStream_e$$.error||$bufferStream_e$$})):($bufferStream_e$$=new $stream$$.PassThrough,$bufferStream_e$$.end($png$$),$bufferStream_e$$.pipe($res$$))})})}}$cb$$()};
|