flexbiz-server
Version:
Flexible Server
37 lines (36 loc) • 18.7 kB
JavaScript
const PostBook=require("../../libs/post-book"),PostSocai=require("../../libs/post-socai"),Vatvao=global.getModel("vatvao"),Tdttco_tt=global.getModel("tdttco_tt"),Tdttco=global.getModel("tdttco"),dvcs=global.getModel("dvcs"),account=global.getModel("account"),dmdt=global.getModel("dmdt"),customer=global.getModel("customer"),dmnv=global.getModel("dmnv"),contract=global.getModel("contract"),dmphi=global.getModel("dmphi"),model=global.getModel("pc1"),pc0=global.getModel("pc0"),pn6=global.getModel("pn6"),
App=global.getModel("app"),trangthai=global.getModel("trangthai"),controller=require("../../controllers/controller"),async=require("async"),ma_ct="BN1",{round}=require("../../libs/utils"),utils=require("../../libs/utils"),numeral=require("numeral"),tien_cl_can_xu_ly=5E3,valid_detail=function($user$$,$obj$$,$fn$$){setImmediate(()=>{for(var $i_i$jscomp$1_i$$=0;$i_i$jscomp$1_i$$<$obj$$.details.length;$i_i$jscomp$1_i$$++){var $detail_tdttco_vatvao$$=$obj$$.details[$i_i$jscomp$1_i$$];$detail_tdttco_vatvao$$.line=
$i_i$jscomp$1_i$$;$obj$$.ma_nt==="VND"&&($detail_tdttco_vatvao$$.tien=$detail_tdttco_vatvao$$.tien_nt)}if($obj$$.vatvaos)for($i_i$jscomp$1_i$$=0;$i_i$jscomp$1_i$$<$obj$$.vatvaos.length;$i_i$jscomp$1_i$$++)$detail_tdttco_vatvao$$=$obj$$.vatvaos[$i_i$jscomp$1_i$$],$detail_tdttco_vatvao$$.line=$i_i$jscomp$1_i$$,$obj$$.ma_nt==="VND"&&($detail_tdttco_vatvao$$.t_thue=$detail_tdttco_vatvao$$.t_thue_nt);if($obj$$.tdttcos)for($i_i$jscomp$1_i$$=0;$i_i$jscomp$1_i$$<$obj$$.tdttcos.length;$i_i$jscomp$1_i$$++)$detail_tdttco_vatvao$$=
$obj$$.tdttcos[$i_i$jscomp$1_i$$],$detail_tdttco_vatvao$$.line=$i_i$jscomp$1_i$$,$obj$$.ma_nt==="VND"&&($detail_tdttco_vatvao$$.tien=$detail_tdttco_vatvao$$.tien_nt),$detail_tdttco_vatvao$$.thanh_toan_qd=$detail_tdttco_vatvao$$.ma_nt_hd==$obj$$.ma_nt?$detail_tdttco_vatvao$$.tien_nt:round($detail_tdttco_vatvao$$.tien/$detail_tdttco_vatvao$$.ty_gia_hd,2);$fn$$(null,$obj$$)})};
module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,sort:{ngay_ct:-1,so_ct:-1},keyValues:{ma_ct},onExport:function($user$$,$obj$$,$next$$){$obj$$.tdttcos&&$obj$$.tdttcos.length>0&&($obj$$.details=$obj$$.tdttcos);$next$$()}});$contr_router$$.route();$contr_router$$.post=async function($obj$$,$fn$$){$fn$$||=function(){};const $appInfo$$=await global.getModel("app").findOne({_id:$obj$$.id_app}).lean();async.series({post_vatvao:function($callback$$){(new PostBook($obj$$,
$obj$$.vatvaos,Vatvao)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},post_tdttco:function($callback$$){(new PostBook($obj$$,$obj$$.tdttcos,Tdttco_tt,function($tdttco$$,$callback$$){$tdttco$$.tk_co=$obj$$.tk_co;$callback$$($tdttco$$)})).run(function($e$$,$details$$){if($e$$)return $callback$$($e$$);$callback$$(null,$details$$)})},post_socai:function($callback$$){setImmediate(async()=>{const $details_sc$$=[];$obj$$.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$$.details.forEach(function($d_detail$$){$d_detail$$={...$d_detail$$};$d_detail$$.tk_co=$obj$$.tk_co;$d_detail$$.ma_kh||($d_detail$$.ma_kh=$obj$$.ma_kh);$details_sc$$.push($d_detail$$)});$obj$$.tdttcos.forEach(function($t_tdttco$$){$t_tdttco$$={...$t_tdttco$$};$t_tdttco$$.tk_co=$obj$$.tk_co;$t_tdttco$$.ma_kh||($t_tdttco$$.ma_kh=
$obj$$.ma_kh);$details_sc$$.push($t_tdttco$$)});await $obj$$.tdttcos.filter($t$$=>$t$$.ty_gia_hd!=$obj$$.ty_gia).asyncJoinModel2($obj$$.id_app,"currency",{where:{ma_nt_hd:"ma_nt"},fields:["tk_cl_no","tk_cl_co"]});for(let $t$$ of $obj$$.tdttcos){var $con_lai_nt_ht_so_du_hd$$=await Tdttco.getBalance({id_app:$obj$$.id_app,id_ct:$obj$$._id.toString(),_id:$t$$.id_tdtt});if($con_lai_nt_ht_so_du_hd$$.length==1){let $con_lai$$=$con_lai_nt_ht_so_du_hd$$[0].con_lai-$t$$.tien;$con_lai_nt_ht_so_du_hd$$=$con_lai_nt_ht_so_du_hd$$[0].con_lai_nt-
$t$$.thanh_toan_qd;if(Math.abs($con_lai$$)<=tien_cl_can_xu_ly||$con_lai_nt_ht_so_du_hd$$<=0)$con_lai$$&&($con_lai_nt_ht_so_du_hd$$={...$t$$,ma_nt:"VND",ty_gia:1},$con_lai_nt_ht_so_du_hd$$.tien_nt=$con_lai_nt_ht_so_du_hd$$.tien=Math.abs($con_lai$$),$con_lai_nt_ht_so_du_hd$$.ma_kh||($con_lai_nt_ht_so_du_hd$$.ma_kh=$obj$$.ma_kh),$t$$.ty_gia_hd!=$obj$$.ty_gia&&$t$$.ma_nt_hd==$obj$$.ma_nt?($t$$.chenh_lech_ty_gia=$con_lai$$,$con_lai$$>0?($con_lai_nt_ht_so_du_hd$$.tk_no=$t$$.tk_no,$con_lai_nt_ht_so_du_hd$$.tk_co=
$t$$.tk_cl_co):($con_lai_nt_ht_so_du_hd$$.tk_no=$t$$.tk_cl_no,$con_lai_nt_ht_so_du_hd$$.tk_co=$t$$.tk_no),$details_sc$$.push($con_lai_nt_ht_so_du_hd$$)):$appInfo$$?.options.tk_tn_khac&&$appInfo$$?.options.tk_cp_khac&&($con_lai$$>0?($con_lai_nt_ht_so_du_hd$$.tk_no=$t$$.tk_no,$con_lai_nt_ht_so_du_hd$$.tk_co=$appInfo$$?.options.tk_tn_khac):($con_lai_nt_ht_so_du_hd$$.tk_no=$appInfo$$?.options.tk_cp_khac,$con_lai_nt_ht_so_du_hd$$.tk_co=$t$$.tk_no),$details_sc$$.push($con_lai_nt_ht_so_du_hd$$))),await Tdttco.updateOne({_id:$t$$.id_tdtt.toString()},
{tat_toan:!0}).catch(Logger.error)}}(new PostSocai($obj$$,$details_sc$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})},post_cashwithdraw:$callback$$=>{(async()=>{if($obj$$.id_asscashwithdraw){const $CashWithdraw$$=await global.getModel("asscashwithdraw").findOne({_id:$obj$$.id_asscashwithdraw});if(!$CashWithdraw$$)return $callback$$("Y\u00eau c\u1ea7u n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i");if($CashWithdraw$$.trang_thai=="5")return $callback$$();if($CashWithdraw$$.trang_thai=="9")return $callback$$("Y\u00eau c\u1ea7u n\u00e0y \u0111\u00e3 b\u1ecb hu\u1ef7");
if($CashWithdraw$$.trang_thai!=0)return $callback$$("Can't pay for this require");let $app$$=await App.findOne({_id:$obj$$.id_app});if(!$app$$||!$app$$.wallet_address||!$app$$.wallet_token)return $callback$$("Kh\u00f4ng th\u1ec3 x\u00e1c nh\u1eadn thanh to\u00e1n. H\u00e3y th\u1eed l\u1ea1i sau");if($app$$.wallet_address!=$CashWithdraw$$.payer)return $callback$$("incorrect payer");try{await global.getModel("assbank").sendCoinsFromSystemToAccount($CashWithdraw$$.id_app,$CashWithdraw$$.payer,$CashWithdraw$$.amount,
$CashWithdraw$$.token),$CashWithdraw$$.trang_thai="5",await $CashWithdraw$$.save()}catch($e$$){return $callback$$($e$$)}}$callback$$()})()}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr_router$$.creating=async function($user$$,$obj$$,$next$$){if($user$$.current_app_info.options.phieu_chi_phai_co_phieu_de_nghi&&!$obj$$.id_pc0&&!$obj$$.id_pn6)return $next$$("Ch\u01b0a c\u00f3 phi\u1ebfu \u0111\u1ec1 ngh\u1ecb thanh to\u00e1n");$obj$$.details||($obj$$.details=[]);if($obj$$.id_pc0){if(await model.findOne({id_app:$user$$.current_id_app,
id_pc0:$obj$$.id_pc0}))return $next$$("\u0110\u1ec1 ngh\u1ecb thanh to\u00e1n n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c chi");var $dntt_t_tien_dn$$=await pc0.findOne({_id:$obj$$.id_pc0,id_app:$user$$.current_id_app});if(!$dntt_t_tien_dn$$)return $next$$("\u0110\u1ec1 ngh\u1ecb thanh to\u00e1n kh\u00f4ng t\u1ed3n t\u1ea1i");$dntt_t_tien_dn$$=utils.round(($dntt_t_tien_dn$$.details||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($dntt_t_tien_dn$$.tdttcos||[]).map($d$$=>$d$$.tien_nt||
0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($dntt_t_tien_dn$$.vatvaos||[]).map($d$$=>$d$$.t_thue_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0),0);let $t_tien_tt$$=utils.round(($obj$$.details||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($obj$$.tdttcos||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($obj$$.vatvaos||[]).map($d$$=>$d$$.t_thue_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0),0);if($dntt_t_tien_dn$$!==$t_tien_tt$$)return $next$$(`T\u1ed5ng s\u1ed1 ti\u1ec1n thanh to\u00e1n ${numeral($t_tien_tt$$).format()} ph\u1ea3i b\u1eb1ng s\u1ed1 ti\u1ec1n ${numeral($dntt_t_tien_dn$$).format()} trong \u0111\u1ec1 ngh\u1ecb thanh to\u00e1n \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t`)}if($obj$$.tdttcos&&
$obj$$.tdttcos.length>0&&(await $obj$$.tdttcos.asyncJoinModel2($user$$.current_id_app,Tdttco,{where:{id_tdtt:"_id"},fields:["tat_toan",{tien_hd_nt:"tien_nt"}]}),(await Promise.all($obj$$.tdttcos.map($hd$$=>(async()=>{if(!global.mongoose.Types.ObjectId.isValid($hd$$.id_tdtt))return{error:"Ho\u00e1 \u0111\u01a1n kh\u00f4ng h\u1ee3p l\u1ec7",invoice:$hd$$};let $ds_da_thanh_toan$$=await Tdttco_tt.find({id_app:$obj$$.id_app,id_tdtt:$hd$$.id_tdtt}).lean(),$da_thanh_toan$$=$ds_da_thanh_toan$$.map($t$$=>
$t$$.thanh_toan_qd||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);return{invoice:$hd$$,da_thanh_toan:$da_thanh_toan$$,con_lai:$hd$$.tien_hd_nt-$da_thanh_toan$$,ds_da_thanh_toan:$ds_da_thanh_toan$$}})()))).filter($hd$$=>$hd$$.error).length>0))return $next$$("S\u1ed1 ti\u1ec1n thanh to\u00e1n kh\u00f4ng \u0111\u01b0\u1ee3c l\u1edbn h\u01a1n s\u1ed1 ti\u1ec1n c\u00f2n l\u1ea1i c\u1ee7a ho\u00e1 \u0111\u01a1n");valid_detail($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$obj$$)})};
$contr_router$$.updating=async function($user$$,$data$$,$obj$$,$next$$){if($data$$.id_pc0||$obj$$.id_pc0){var $dntt$jscomp$1_id_pc0_t_tien_dn$$=$data$$.id_pc0||$obj$$.id_pc0,$ex$jscomp$1_t_tien_tt$$=await model.findOne({id_app:$obj$$.id_app,id_pc0:$dntt$jscomp$1_id_pc0_t_tien_dn$$}).lean();if($ex$jscomp$1_t_tien_tt$$&&$ex$jscomp$1_t_tien_tt$$._id.toString()!==$obj$$._id.toString())return $next$$("\u0110\u1ec1 ngh\u1ecb thanh to\u00e1n n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c chi");$dntt$jscomp$1_id_pc0_t_tien_dn$$=
await pc0.findOne({_id:$dntt$jscomp$1_id_pc0_t_tien_dn$$,id_app:$user$$.current_id_app});if(!$dntt$jscomp$1_id_pc0_t_tien_dn$$)return $next$$("\u0110\u1ec1 ngh\u1ecb thanh to\u00e1n kh\u00f4ng t\u1ed3n t\u1ea1i");$dntt$jscomp$1_id_pc0_t_tien_dn$$=utils.round(($dntt$jscomp$1_id_pc0_t_tien_dn$$.details||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($dntt$jscomp$1_id_pc0_t_tien_dn$$.tdttcos||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($dntt$jscomp$1_id_pc0_t_tien_dn$$.vatvaos||
[]).map($d$$=>$d$$.t_thue_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0),0);$ex$jscomp$1_t_tien_tt$$=utils.round(($data$$.details||$obj$$.details||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($data$$.tdttcos||$obj$$.tdttcos||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($data$$.vatvaos||$obj$$.vatvaos||[]).map($d$$=>$d$$.t_thue_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0),0);if($dntt$jscomp$1_id_pc0_t_tien_dn$$!==$ex$jscomp$1_t_tien_tt$$)return $next$$(`T\u1ed5ng s\u1ed1 ti\u1ec1n thanh to\u00e1n ${numeral($ex$jscomp$1_t_tien_tt$$).format()} ph\u1ea3i b\u1eb1ng s\u1ed1 ti\u1ec1n ${numeral($dntt$jscomp$1_id_pc0_t_tien_dn$$).format()} trong \u0111\u1ec1 ngh\u1ecb thanh to\u00e1n \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t`)}if($obj$$.tdttcos&&
$obj$$.tdttcos.length>0&&(await $obj$$.tdttcos.asyncJoinModel2($user$$.current_id_app,Tdttco,{where:{id_tdtt:"_id"},fields:["tat_toan",{tien_hd_nt:"tien_nt"}]}),(await Promise.all($obj$$.tdttcos.map($hd$$=>(async()=>{if(!global.mongoose.Types.ObjectId.isValid($hd$$.id_tdtt))return{error:"Ho\u00e1 \u0111\u01a1n kh\u00f4ng h\u1ee3p l\u1ec7",invoice:$hd$$};let $ds_da_thanh_toan$$=await Tdttco_tt.find({id_app:$obj$$.id_app,id_tdtt:$hd$$.id_tdtt,id_ct:{$ne:$obj$$._id.toString()}}).lean(),$da_thanh_toan$$=
$ds_da_thanh_toan$$.map($t$$=>$t$$.thanh_toan_qd||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$con_lai$$=$hd$$.tien_hd_nt-$da_thanh_toan$$;return $con_lai$$<$hd$$.thanh_toan_qd?{error:!0,invoice:$hd$$}:{ds_da_thanh_toan:$ds_da_thanh_toan$$,da_thanh_toan:$da_thanh_toan$$,invoice:$hd$$,con_lai:$con_lai$$}})()))).filter($hd$$=>$hd$$.error).length>0))return $next$$("S\u1ed1 ti\u1ec1n thanh to\u00e1n kh\u00f4ng \u0111\u01b0\u1ee3c l\u1edbn h\u01a1n s\u1ed1 ti\u1ec1n c\u00f2n l\u1ea1i c\u1ee7a ho\u00e1 \u0111\u01a1n");
valid_detail($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})};$contr_router$$.deleted=($details$jscomp$1_user$$,$obj$$,$next$$)=>{$details$jscomp$1_user$$=($obj$$.details||[]).filter($d$$=>$d$$.id_tdtt);async.map($details$jscomp$1_user$$,($detail$$,$callback$$)=>{setImmediate(()=>{Tdttco.findOneAndUpdate({_id:$detail$$.id_tdtt.toString()},{$set:{tat_toan:!1}},function($error$$,$result$$){$callback$$($error$$,$result$$)})})},$e$$=>{$next$$($e$$,
$obj$$)})};$contr_router$$.on("saved",function($obj$$){$obj$$.id_pc0&&pc0.updateMany({_id:$obj$$.id_pc0,id_app:$obj$$.id_app},{id_pc1:$obj$$._id.toString(),trang_thai:"6"},($e$$,$rs$$)=>{Logger.info("update pc0",$obj$$.id_pc0,$rs$$);pc0.findOne({_id:$obj$$.id_pc0,id_app:$obj$$.id_app},($e$$,$_obj$$)=>{$_obj$$&&controller.postData($_obj$$,global.controllers.PC0,$e$$=>{$e$$&&Logger.error($e$$)})})});$obj$$.id_pn6&&pn6.updateMany({_id:$obj$$.id_pn6,id_app:$obj$$.id_app},{id_pc1:$obj$$._id.toString(),
trang_thai:"7"},($e$$,$rs$$)=>{Logger.info("update pn6",$obj$$.id_pn6,$rs$$);pn6.findOne({_id:$obj$$.id_pn6,id_app:$obj$$.id_app},($e$$,$_obj$$)=>{$_obj$$&&controller.postData($_obj$$,global.controllers.PN6,$e$$=>{$e$$&&Logger.error($e$$)})})})});$contr_router$$.on("deleted",function($obj$$){$obj$$.id_pc0&&pc0.updateMany({_id:$obj$$.id_pc0,id_app:$obj$$.id_app},{id_pc1:""},()=>{pc0.updateMany({_id:$obj$$.id_pc0,id_app:$obj$$.id_app,trang_thai:"6"},{trang_thai:"4"},($e$$,$rs$$)=>{Logger.info("update pc0",
$obj$$.id_pc0,$rs$$);pc0.findOne({_id:$obj$$.id_pc0,id_app:$obj$$.id_app},($e$$,$_obj$$)=>{$_obj$$&&controller.postData($_obj$$,global.controllers.PC0,$e$$=>{$e$$&&Logger.error($e$$)})})})});$obj$$.id_pn6&&pn6.updateMany({_id:$obj$$.id_pn6,id_app:$obj$$.id_app},{id_pc1:""},()=>{pn6.updateMany({_id:$obj$$.id_pn6,id_app:$obj$$.id_app,trang_thai:"7"},{trang_thai:"5"},($e$$,$rs$$)=>{Logger.info("update pn6",$obj$$.id_pn6,$rs$$);pn6.findOne({_id:$obj$$.id_pn6,id_app:$obj$$.id_app},($e$$,$_obj$$)=>{$_obj$$&&
controller.postData($_obj$$,global.controllers.PN6,$e$$=>{$e$$&&Logger.error($e$$)})})})})});$contr_router$$.view=function($user$$,$items$$,$fn$$){const $id_app$$=$user$$.current_id_app;async.parallel({kh:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:[{name:"ten_kh",value:"ten_kh"}]}],function(){$callback$$()})})},nv:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.ma_nv).joinModel2($id_app$$,
dmnv,[{where:"ma_nv",fields:[{name:"ten_nv",value:"ten_nv"}]}],function(){$callback$$()})})},tk:function($callback$$){setImmediate(()=>{$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$$()})})},dv:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.ma_dvcs).joinModel($id_app$$,dvcs,[{akey:"ma_dvcs",bkey:"_id",fields:[{name:"ten_dvcs",value:"ten_dvcs"}]}],function(){$callback$$()})})},
trangthai:function($callback$$){setImmediate(()=>{$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$$()})})},pc0:function($callback$$){setImmediate(()=>{$items$$.joinModel2($id_app$$,pc0,[{where:{id_pc0:"_id"},fields:[{so_ct_pc0:"so_ct"},{ngay_ct_pc0:"ngay_ct"}]}],function(){$callback$$()})})},t_tien:function($callback$$){setImmediate(()=>{$items$$.forEach(function($r$$){let $f_tien_nt$$=
$r$$.ma_nt=="VND"?0:3;$r$$.t_tien=0;$r$$.t_tien_nt=0;$r$$.t_thue_vao=0;$r$$.t_thue_vao_nt=0;$r$$.details&&($r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tien_nt=$r$$.details.csum("tien_nt"));$r$$.tdttcos&&($r$$.t_tien+=$r$$.tdttcos.csum("tien"),$r$$.t_tien_nt=Math.roundBy($r$$.t_tien_nt+$r$$.tdttcos.csum("tien_nt"),$f_tien_nt$$));$r$$.vatvaos&&($r$$.t_thue_vao=$r$$.vatvaos.csum("t_thue"),$r$$.t_thue_vao_nt=$r$$.vatvaos.csum("t_thue_nt"));$r$$.t_tt=$r$$.t_tien+$r$$.t_thue_vao;$r$$.t_tt_nt=Math.roundBy($r$$.t_tien_nt+
$r$$.t_thue_vao_nt,$f_tien_nt$$)});$callback$$()})},details_tk:function($callback$$){setImmediate(()=>{async.map($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel($id_app$$,account,[{akey:"tk_no",bkey:"tk",fields:[{name:"ten_tk_no",value:"ten_tk"}]}],function(){$callback1$$()})},function(){$callback$$()})})},details_tk_tdttco:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{($r$$.tdttcos||[]).joinModel($id_app$$,account,[{akey:"tk_no",bkey:"tk",
fields:[{name:"ten_tk_no",value:"ten_tk"}]}],function(){$callback1$$()})})},function(){$callback$$()})},details_dt_tdttco:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{($r$$.tdttcos||[]).filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback1$$()})})},function(){$callback$$()})},details_hd_tdttco:function($callback$$){setImmediate(()=>{async.map($items$$,function($r$$,$callback1$$){($r$$.tdttcos||
[]).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_tdttco:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{($r$$.tdttcos||[]).filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:"ma_phi",fields:[{name:"ten_phi",value:"ten_phi"}]}],function(){$callback1$$()})})},function(){$callback$$()})},details_customer:function($callback$$){async.map($items$$,
function($r$$,$callback1$$){setImmediate(()=>{($r$$.details||[]).filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:[{name:"ten_kh",value:"ten_kh"}]}],function(){$callback1$$()})})},function(){$callback$$()})},details_dt:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{($r$$.details||[]).filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback1$$()})})},
function(){$callback$$()})},details_hopdong:function($callback$$){async.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{($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.map($items$$,function($r$$,$callback1$$){setImmediate(()=>{($r$$.details||[]).filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,
dmphi,[{where:"ma_phi",fields:[{name:"ten_phi",value:"ten_phi"}]}],function(){$callback1$$()})})},function(){$callback$$()})}},function(){setImmediate(()=>{$fn$$(null,$items$$)})})}};