UNPKG

flexbiz-server

Version:

Flexible Server

35 lines (34 loc) 17.2 kB
const PostBook=require("../../libs/post-book"),PostSocai=require("../../libs/post-socai"),Tdttno_tt=global.getModel("tdttno_tt"),Tdttno=global.getModel("tdttno"),dvcs=global.getModel("dvcs"),account=global.getModel("account"),dmphi=global.getModel("dmphi"),customer=global.getModel("customer"),dmnv=global.getModel("dmnv"),dmdt=global.getModel("dmdt"),App=global.getModel("app"),assinvestment=global.getModel("assinvestment"),so5=global.getModel("so5"),contract=global.getModel("contract"),model=global.getModel("pt1"), pn6=global.getModel("pn6"),controller=require("../../controllers/controller"),trangthai=global.getModel("trangthai"),async=require("async"),ma_ct="BC1",{round}=require("../../libs/utils"),blockchainconnect=require("../../libs/blockchainconnect"),tien_cl_can_xu_ly=5E3,valid_detail=function($i_i$$,$obj$$,$fn$$){for($i_i$$=0;$i_i$$<$obj$$.details.length;$i_i$$++){var $detail_tdttno$$=$obj$$.details[$i_i$$];$detail_tdttno$$.line=$i_i$$;$obj$$.ma_nt=="VND"&&($detail_tdttno$$.tien=Math.roundBy($detail_tdttno$$.tien_nt, 0))}if($obj$$.tdttnos)for($i_i$$=0;$i_i$$<$obj$$.tdttnos.length;$i_i$$++)$detail_tdttno$$=$obj$$.tdttnos[$i_i$$],$detail_tdttno$$.line=$i_i$$,$obj$$.ma_nt==="VND"&&($detail_tdttno$$.tien=$detail_tdttno$$.tien_nt),$detail_tdttno$$.thanh_toan_qd=$detail_tdttno$$.ma_nt_hd==$obj$$.ma_nt?$detail_tdttno$$.tien_nt:round($detail_tdttno$$.tien/$detail_tdttno$$.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$$.tdttnos&&$obj$$.tdttnos.length>0&&($obj$$.details=$obj$$.tdttnos);$next$$()}});$contr_router$$.route();$contr_router$$.post=async function($obj$$,$fn$$,$options$$={}){$fn$$||=function(){};$obj$$.tdttnos=$obj$$.tdttnos||[];const $appInfo$$=await global.getModel("app").findOne({_id:$obj$$.id_app}).lean(); async.series({post_tdttno:function($callback$$){(new PostBook($obj$$,$obj$$.tdttnos,Tdttno_tt,function($tdttno$$,$callback$$){$tdttno$$.tk_no=$obj$$.tk_no;$callback$$($tdttno$$)})).run(function($e$$,$details$$){if($e$$)return $callback$$($e$$);$callback$$(null,$details$$)})},post_socai:function($callback$$){setImmediate(async()=>{const $details_sc$$=[];$obj$$.details.forEach(function($d_detail$$){$d_detail$$={...$d_detail$$};$d_detail$$.tk_no=$obj$$.tk_no;$d_detail$$.ma_kh_no=$obj$$.ma_kh_no||$obj$$.ma_kh; $d_detail$$.ma_kh||($d_detail$$.ma_kh=$obj$$.ma_kh);$details_sc$$.push($d_detail$$)});$obj$$.tdttnos.forEach($t_tdttno$$=>{$t_tdttno$$={...$t_tdttno$$};$t_tdttno$$.tk_no=$obj$$.tk_no;$t_tdttno$$.ma_kh||($t_tdttno$$.ma_kh=$obj$$.ma_kh);$details_sc$$.push($t_tdttno$$)});await $obj$$.tdttnos.filter($t$$=>$t$$.ty_gia_hd!=$obj$$.ty_gia&&$t$$.ma_nt_hd==$obj$$.ma_nt).asyncJoinModel2($obj$$.id_app,"currency",{where:{ma_nt_hd:"ma_nt"},fields:["tk_cl_no","tk_cl_co"]});for(let $t$$ of $obj$$.tdttnos){var $con_lai_nt_ht_so_du_hd$$= await Tdttno.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_co,$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_co),$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_co,$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_co),$details_sc$$.push($con_lai_nt_ht_so_du_hd$$))),await Tdttno.updateOne({_id:$t$$.id_tdtt.toString()},{tat_toan:!0}).catch(Logger.error)}}(new PostSocai($obj$$,$details_sc$$)).run(($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})})},nap_tien_vao_vi:$callback$$=>{(async()=>{if(!$obj$$.id_so5)return $callback$$();try{let $inv$$= await so5.findOne({id_app:$obj$$.id_app,_id:$obj$$.id_so5});if(!$inv$$)return $callback$$("Phi\u1ebfu n\u1ea1p ti\u1ec1n kh\u00f4ng t\u1ed3n t\u1ea1i");if($inv$$.trang_thai=="5")return $callback$$();if($inv$$.trang_thai=="9")return $callback$$("Phi\u1ebfu n\u1ea1p ti\u1ec1n n\u00e0y \u0111\u00e3 b\u1ecb hu\u1ef7");if($inv$$.trang_thai=="0"||$inv$$.trang_thai=="2"){let $tg_hien_tai$$=(new Date).getTime(),$tg_tao$$=(new Date($inv$$.date_created)).getTime();if(($tg_hien_tai$$-$tg_tao$$)/864E5>1)return $inv$$.trang_thai= "9",await $inv$$.save(),$callback$$("Phi\u1ebfu n\u1ea1p ti\u1ec1n n\u00e0y \u0111\u00e3 h\u1ebft h\u1ea1n thanh to\u00e1n")}if($obj$$.da_chuyen_token)Logger.info("da chuyen token");else{let $app$$=await App.findById($obj$$.id_app);if(!($app$$.wallet_address&&$app$$.wallet_token&&$obj$$.details))return $callback$$("Kh\u00f4ng th\u1ec3 th\u1ef1c hi\u1ec7n l\u00fac n\u00e0y. Hay th\u1eed l\u1ea1i sau");let $details$$=$inv$$.details.filter($d$$=>$d$$.is_coin&&!$d$$.transferred&&$d$$.wallet_receiver&& $d$$.sl_xuat);await Promise.all($details$$.map($detail$$=>(async()=>{var $denom_rs$$=$detail$$.ma_vt.toLowerCase();$denom_rs$$=await blockchainconnect.spend($obj$$.id_app,$app$$.wallet_token,$app$$.wallet_address,$detail$$.wallet_receiver,{amount:$detail$$.sl_xuat,denom:$denom_rs$$,memo:"N\u1ea1p ti\u1ec1n v\u00e0o v\u00ed"});if($denom_rs$$.code){if($denom_rs$$.code===5)throw"V\u00ed h\u1ec7 th\u1ed1ng kh\u00f4ng \u0111\u1ee7 ti\u1ec1n \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y";throw $denom_rs$$.rawLog; }$detail$$.transferred=!0})()));await model.findOneAndUpdate({_id:$obj$$._id},{da_chuyen_token:!0})}let $ctrlinvest$$=global.controllers.SO5;$inv$$.trang_thai="5";$inv$$.save($e$$=>{if($e$$)return $callback$$($e$$.message);controller.postData($inv$$,$ctrlinvest$$,async $e$$=>{if($e$$)return $callback$$($e$$);$obj$$.da_chuyen_token||($e$$=await $ctrlinvest$$.asyncView($options$$.req.user,[$inv$$.toObject()],$options$$),controller.pushNotification($ctrlinvest$$,$e$$[0]));$callback$$()})})}catch($e$$){$callback$$($e$$.message|| $e$$.error||$e$$)}})()},thanh_toan_dau_tu:$callback$$=>{(async()=>{if(!$obj$$.id_assinvestment)return $callback$$();try{let $inv$$=await assinvestment.findOne({id_app:$obj$$.id_app,_id:$obj$$.id_assinvestment});if(!$inv$$)return $callback$$("H\u1ee3p \u0111\u1ed3ng \u0111\u1ea7u t\u01b0 kh\u00f4ng t\u1ed3n t\u1ea1i");if($inv$$.trang_thai==="1"||$inv$$.trang_thai!=="2"&&$inv$$.trang_thai!=="0")return $callback$$();let $period$$=await global.getModel("assperiod").findOne({id_app:$obj$$.id_app,id:$inv$$.id_period}).lean(); if($inv$$.trang_thai=="0"||$inv$$.trang_thai=="2"){if(!$period$$.hoat_dong)return $callback$$("G\u00f3i \u0111\u1ea7u t\u01b0 n\u00e0y \u0111\u00e3 h\u1ebft hi\u1ec7u l\u1ef1c");let $tg_hien_tai$$=(new Date).getTime(),$tg_tao$$=(new Date($inv$$.date_created)).getTime();if(($tg_hien_tai$$-$tg_tao$$)/864E5>($period$$.han_tt||1))return $inv$$.trang_thai="7",await $inv$$.save(),$callback$$("G\u00f3i \u0111\u1ea7u t\u01b0 n\u00e0y \u0111\u00e3 h\u1ebft h\u1ea1n thanh to\u00e1n")}if(!$obj$$.da_chuyen_token){let $amount$$= $inv$$.gia*$inv$$.so_luong,$denom$$=$inv$$.denom,$app$$=await App.findOne({_id:$obj$$.id_app});if($app$$.wallet_address&&$app$$.wallet_token&&$obj$$.details)try{Logger.info("Chuy\u1ec3n token t\u1eeb v\u00ed c\u00f4ng ty sang v\u00ed nh\u00e0 \u0111\u1ea7u t\u01b0 \u0111\u1ec3 thanh to\u00e1n cho c\u00e1c khaonr \u0111\u1ea7u t\u01b0",$amount$$,$denom$$,$inv$$.gia,$inv$$.so_luong);let $rs$$=await blockchainconnect.spend($obj$$.id_app,$app$$.wallet_token,$app$$.wallet_address,$inv$$.creator,{amount:$amount$$, denom:$denom$$,memo:"N\u1ea1p ti\u1ec1n v\u00e0o v\u00ed \u0111\u1ec3 thanh to\u00e1n \u0111\u1ea7u t\u01b0"});if($rs$$.code)return $callback$$($rs$$.message||$rs$$.error||"V\u00ed c\u00f4ng ty kh\u00f4ng \u0111\u1ee7 s\u1ed1 d\u01b0");await model.updateOne({_id:$obj$$._id},{da_chuyen_token:!0})}catch($e$$){return $callback$$($e$$.message||$e$$.error||$e$$)}else return $callback$$("Kh\u00f4ng th\u1ec3 th\u1ef1c hi\u1ec7n l\u00fac n\u00e0y. Hay th\u1eed l\u1ea1i sau")}Logger.info("C\u1eadp nh\u1eadt tr\u1ea1ng th\u00e1i kho\u1ea3n \u0111\u1ea7u t\u01b0 \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n"); let $ctrlinvest$$=global.controllers.ASSINVESTMENT;$ctrlinvest$$.updating({email:$inv$$.user_created,current_id_app:$obj$$.id_app},{trang_thai:"1"},$inv$$,($e$$,$data$$)=>{if($e$$)return $callback$$($e$$);for(let $key$$ in $data$$)$inv$$[$key$$]=$data$$[$key$$];$inv$$.trang_thai="1";$inv$$.save(async $e$jscomp$7_view_objs$$=>{if($e$jscomp$7_view_objs$$)return $callback$$($e$jscomp$7_view_objs$$.message||$e$jscomp$7_view_objs$$.error||$e$jscomp$7_view_objs$$);$e$jscomp$7_view_objs$$=await $ctrlinvest$$.asyncView($options$$.req.user, [$inv$$.toObject()],$options$$);controller.pushNotification($ctrlinvest$$,$e$jscomp$7_view_objs$$[0]);$callback$$()})})}catch($e$$){$callback$$($e$$.message)}})()}},($e$$,$rs$$)=>{$fn$$($e$$,$rs$$)})};$contr_router$$.creating=async function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$obj$$.da_chuyen_token=!1;if($obj$$.tdttnos&&$obj$$.tdttnos.length>0&&(await $obj$$.tdttnos.asyncJoinModel2($user$$.current_id_app,Tdttno,{where:{id_tdtt:"_id"},fields:["tat_toan",{tien_hd_nt:"tien_nt"}]}), (await Promise.all($obj$$.tdttnos.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 Tdttno_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),$con_lai$$=$hd$$.tien_hd_nt-$da_thanh_toan$$;return $con_lai$$<=0?{error:"Ho\u00e1 \u0111\u01a1n \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n", invoice:$hd$$,da_thanh_toan:$da_thanh_toan$$,con_lai:$con_lai$$,ds_da_thanh_toan:$ds_da_thanh_toan$$}:{invoice:$hd$$,da_thanh_toan:$da_thanh_toan$$,con_lai:$con_lai$$,ds_da_thanh_toan:$ds_da_thanh_toan$$}})()))).filter($hd$$=>$hd$$.error).length>0))return $next$$("Ho\u00e1 \u0111\u01a1n \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n");valid_detail($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$obj$$)})};$contr_router$$.updating=async function($user$$,$data$$, $obj$$,$next$$){if($obj$$.id_so5){let $inv$$=await so5.findOne({id_app:$obj$$.id_app,_id:$obj$$.id_so5});if(!$inv$$)return $next$$("Phi\u1ebfu n\u1ea1p ti\u1ec1n kh\u00f4ng t\u1ed3n t\u1ea1i");if($inv$$.trang_thai=="5")return $next$$("Phi\u1ebfu n\u1ea1p ti\u1ec1n n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n")}$data$$.da_chuyen_token=void 0;valid_detail($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})};$contr_router$$.deleting= async function($inv$jscomp$3_user$$,$obj$$,$next$$){if($obj$$.id_so5&&($inv$jscomp$3_user$$=await so5.findOne({id_app:$obj$$.id_app,_id:$obj$$.id_so5}))&&$inv$jscomp$3_user$$.trang_thai=="5")return $next$$("Kh\u00f4ng th\u1ec3 xo\u00e1 phi\u1ebfu n\u00e0y do phi\u1ebfu n\u1ea1p ti\u1ec1n n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n");$next$$(null,$obj$$)};$contr_router$$.deleted=($details$jscomp$2_user$$,$obj$$,$next$$)=>{$details$jscomp$2_user$$=($obj$$.details||[]).filter($d$$=> $d$$.id_tdtt);async.mapSeries($details$jscomp$2_user$$,($detail$$,$callback$$)=>{setImmediate(()=>{Tdttno.findOneAndUpdate({_id:$detail$$.id_tdtt.toString(),id_app:$obj$$.id_app},{$set:{tat_toan:!1}},($error$$,$result$$)=>{$callback$$($error$$,$result$$)})})},$e$$=>{$next$$($e$$,$obj$$)})};$contr_router$$.on("saved",function($obj$$){$obj$$.id_pn6&&pn6.updateMany({_id:$obj$$.id_pn6,id_app:$obj$$.id_app},{id_pt1:$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_pn6&&pn6.updateMany({_id:$obj$$.id_pn6,id_app:$obj$$.id_app},{id_pt1:""},()=>{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.series({kh:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:["ten_kh"]}],function(){$callback$$()})})},nv:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.ma_nv).joinModel2($id_app$$, dmnv,[{where:"ma_nv",fields:["ten_nv"]}],function(){$callback$$()})})},tk:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.tk_no).joinModel2($id_app$$,account,[{where:$item$$=>({tk:$item$$.tk_no}),fields:{ten_tk_co:"ten_tk"}}],function(){$callback$$()})})},dv:function($callback$$){setImmediate(()=>{$items$$.filter($item$$=>$item$$.ma_dvcs).joinModel2($id_app$$,dvcs,[{where:$item$$=>({_id:$item$$.ma_dvcs}),fields:["ten_dvcs"]}],function(){$callback$$()})})},trangthai:function($callback$$){setImmediate(()=> {$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:$item$$=>({ma_trang_thai:$item$$.trang_thai,ma_ct:$item$$.ma_ct}),fields:["ten_trang_thai","color"]}],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$$.details&&($r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tien_nt=Math.roundBy($r$$.details.csum("tien_nt"),$f_tien_nt$$));$r$$.tdttnos&&($r$$.t_tien+= $r$$.tdttnos.csum("tien"),$r$$.t_tien_nt=Math.roundBy($r$$.t_tien_nt+$r$$.tdttnos.csum("tien_nt"),$f_tien_nt$$));$r$$.t_tt=$r$$.t_tien;$r$$.t_tt_nt=$r$$.t_tien_nt});$callback$$()})},details_tk:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){setImmediate(()=>{($r$$.details||[]).filter($item$$=>$item$$.tk_co).joinModel2($id_app$$,account,[{where:$item$$=>({tk:$item$$.tk_co}),fields:[{ten_tk_co:"ten_tk"}]}],function(){$callback1$$()})})},function(){$callback$$()})},details_tk_tdttno:function($callback$$){async.mapSeries($items$$, function($r$$,$callback1$$){setImmediate(()=>{($r$$.tdttnos||[]).filter($item$$=>$item$$.tk_co).joinModel2($id_app$$,account,[{where:$item$$=>({tk:$item$$.tk_co}),fields:[{ten_tk_co:"ten_tk"}]}],function(){$callback1$$()})})},function(){$callback$$()})},details_contract_tdttno:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){setImmediate(()=>{($r$$.tdttnos||[]).filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:$item$$=>({so_hd:$item$$.ma_hd}),fields:["ten_hd"]}], function(){$callback1$$()})})},function(){$callback$$()})},details_dt_tdttno:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){setImmediate(()=>{($r$$.tdttnos||[]).filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:$item$$=>({ma_dt:$item$$.ma_dt}),fields:["ten_dt"]}],function(){$callback1$$()})})},function(){$callback$$()})},details_customer:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){setImmediate(()=>{($r$$.details||[]).filter($item$$=> $item$$.ma_kh).joinModel2($id_app$$,customer,[{where:$item$$=>({ma_kh:$item$$.ma_kh}),fields:["ten_kh"]}],function(){$callback1$$()})})},function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){setImmediate(()=>{($r$$.details||[]).filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:$item$$=>({ma_dt:$item$$.ma_dt}),fields:["ten_dt"]}],function(){$callback1$$()})})},function(){$callback$$()})},details_contract:function($callback$$){async.mapSeries($items$$, function($r$$,$callback1$$){setImmediate(()=>{($r$$.details||[]).filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:$item$$=>({so_hd:$item$$.ma_hd}),fields:["ten_hd"]}],function(){$callback1$$()})})},function(){$callback$$()})},details_phi:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){setImmediate(()=>{($r$$.details||[]).filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:$item$$=>({ma_phi:$item$$.ma_phi}),fields:["ten_phi"]}],function(){$callback1$$()})})}, function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};