UNPKG

flexbiz-server

Version:

Flexible Server

38 lines (37 loc) 19 kB
'use strict';const options=global.getModel("options"),PostSocai=require("../../libs/post-socai"),transaction=global.getModel("transaction"),dvcs=global.getModel("dvcs"),Evoucher=global.getModel("evoucher"),department=global.getModel("department"),dmcpmh=global.getModel("dmcpmh"),customer=global.getModel("customer"),service=global.getModel("service"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),trangthai=global.getModel("trangthai"),currency=global.getModel("currency"), ptthanhtoan=global.getModel("ptthanhtoan"),dmdiemthuong=global.getModel("dmdiemthuong"),onepay=global.getModel("onepay"),model=global.getModel("so2"),controller=require("../../controllers/controller"),async=require("async"),Moment=require("moment"),ma_ct="SO2",ckdiem=require("../../libs/ckdiem"),getPointBalance=async($id_app$$,$sender_email$$)=>new Promise(($resolve$$,$reject$$)=>{ckdiem({id_app:$id_app$$,email:$sender_email$$},($e$$,$rs$$)=>{if($e$$)return $reject$$(Error($e$$));$resolve$$(0===$rs$$.length? 0:$rs$$[0].ton00)})}),createTransactionPayment=async function($obj$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});if($obj$$.paymentByPoints){var $description$$=$obj$$.dien_giai;if(!$description$$&&$obj$$.details&&0<$obj$$.details.length&&($description$$=$obj$$.details[0].service_name,!$description$$))try{$description$$=await service.getInfo($obj$$.id_app,{service_code:$obj$$.details[0].service_code},"service_name")}catch($e$$){console.log($e$$.message,$obj$$.details[0].service_code)}await transaction.createTrans({id_app:$obj$$.id_app, sender_email:$obj$$.user_created,receiver_email:$obj$$.id_app,amount:$obj$$.paymentByPoints,description:`Thanh to\u00e1n d\u1ecbch v\u1ee5 ${$description$$||""}`,otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()}})}},createTransactionBonus=async function($obj$$){if("5"!=$obj$$.trang_thai&&"4"!=$obj$$.trang_thai)return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"), null;var $amount_ckdiemthuong_kh_ty_le_diem_thuong$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh});if($amount_ckdiemthuong_kh_ty_le_diem_thuong$$){var $lan_mua_old_trans_sl_t_tien$$=(await model.find({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,ngay_ct:{$lte:$obj$$.ngay_ct}})).length+1,$now$$=Moment(new Date).startOf("date").toDate();$amount_ckdiemthuong_kh_ty_le_diem_thuong$$=await dmdiemthuong.find({id_app:$obj$$.id_app,status:!0,ma_kh:{$in:[null,"",$amount_ckdiemthuong_kh_ty_le_diem_thuong$$.ma_kh]}, nh_kh:{$in:[null,"",$amount_ckdiemthuong_kh_ty_le_diem_thuong$$.nh_kh]},hieu_luc_tu:{$lte:$now$$},hieu_luc_den:{$gte:$now$$},ap_dung_lan_mua_thu:{$in:[0,$lan_mua_old_trans_sl_t_tien$$]}}).sort({hieu_luc_tu:-1}).limit(1);if(0===$amount_ckdiemthuong_kh_ty_le_diem_thuong$$.length)await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i");else{if($amount_ckdiemthuong_kh_ty_le_diem_thuong$$[0].tien){$amount_ckdiemthuong_kh_ty_le_diem_thuong$$= $amount_ckdiemthuong_kh_ty_le_diem_thuong$$[0].diem/$amount_ckdiemthuong_kh_ty_le_diem_thuong$$[0].tien;if(!$amount_ckdiemthuong_kh_ty_le_diem_thuong$$)return;$lan_mua_old_trans_sl_t_tien$$=$obj$$.details.map($d$$=>$d$$.tien_hang-($d$$.tien_ck||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$amount_ckdiemthuong_kh_ty_le_diem_thuong$$=Math.roundBy($lan_mua_old_trans_sl_t_tien$$*$amount_ckdiemthuong_kh_ty_le_diem_thuong$$,0)}else $lan_mua_old_trans_sl_t_tien$$=$obj$$.details.filter($d$$=>$d$$.tien_hang).map($d$$=> $d$$.sl_xuat||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$amount_ckdiemthuong_kh_ty_le_diem_thuong$$=Math.roundBy($amount_ckdiemthuong_kh_ty_le_diem_thuong$$[0].diem*$lan_mua_old_trans_sl_t_tien$$,0);if($amount_ckdiemthuong_kh_ty_le_diem_thuong$$){if($lan_mua_old_trans_sl_t_tien$$=await transaction.findOne({id_ct:$obj$$._id.toString()+":bonus"}),!$lan_mua_old_trans_sl_t_tien$$||$lan_mua_old_trans_sl_t_tien$$.amount!==$amount_ckdiemthuong_kh_ty_le_diem_thuong$$)return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+ ":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"),await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$obj$$.id_app,receiver_email:$obj$$.user_created,amount:$amount_ckdiemthuong_kh_ty_le_diem_thuong$$,description:"\u0110i\u1ec3m th\u01b0\u1edfng s\u1eed d\u1ee5ng d\u1ecbch v\u1ee5",otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()+":bonus"}})}else await transaction.deleteTrans({id_ct:$obj$$._id.toString()+ ":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i")}}else await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i")},isFree=async($id_app$$,$department_code$$,$ngay_den$$,$ngay_di$$)=>{if(!await department.getInfo($id_app$$,{department_code:$department_code$$},"auto_check_available"))return!0;let $condition$$={id_app:$id_app$$,details:{$elemMatch:{department_code:$department_code$$}}, $or:[{ngay_den:{$gte:$ngay_den$$,$lte:$ngay_di$$}},{ngay_di:{$gte:$ngay_den$$,$lte:$ngay_di$$}},{$and:[{ngay_den:{$lte:$ngay_di$$}},{ngay_di:{$gte:$ngay_di$$}}]}],trang_thai:{$ne:"9"}};return new Promise(($resolve$$,$reject$$)=>{model.findOne($condition$$).lean().exec(($e$$,$rs$$)=>$e$$?$reject$$(Error($e$$.message)):$rs$$?$resolve$$(!1):$resolve$$(!0))})},checkEvoucher=($user$$,$obj$$)=>($obj$$.evouchers||[]).map($ev$$=>new Promise(($resolve$$,$reject$$)=>{(async()=>{const $_e$$=await Evoucher.findOne({_id:$ev$$._id}); if(!$_e$$)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng t\u1ed3n t\u1ea1i`));if($_e$$.id_ct_used&&$_e$$.id_ct_used!==($obj$$._id||"").toString())return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng`));if($_e$$.user&&$_e$$.user!==($obj$$.user_created||$user$$.email))return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng h\u1ee3p l\u1ec7`));var $date_created_so_tien_giam$$=new Date($obj$$.date_created);if(Moment($_e$$.hieu_luc_den).endOf("date").toDate().getTime()< $date_created_so_tien_giam$$.getTime())return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 h\u1ebft h\u1ea1n s\u1eed d\u1ee5ng`));$date_created_so_tien_giam$$=$_e$$.so_tien;$_e$$.ty_le&&($date_created_so_tien_giam$$=Math.roundBy($obj$$.details.map($d$$=>$d$$.tien_hang_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0)*$_e$$.ty_le/100));$_e$$.so_tien_max&&$date_created_so_tien_giam$$>$_e$$.so_tien_max&&($date_created_so_tien_giam$$=$_e$$.so_tien_max);if($ev$$.so_tien_giam!==$date_created_so_tien_giam$$)return $reject$$(Error(`S\u1ed1 ti\u1ec1n gi\u1ea3m cho th\u1ebb ${$ev$$.ma} kh\u00f4ng h\u1ee3p l\u1ec7`)); $resolve$$(!0)})()})),valid=async function($user$$,$obj$$,$next$$){try{var $_checkEvoucher_i$$=checkEvoucher($user$$,$obj$$);await Promise.all($_checkEvoucher_i$$)}catch($e$$){return $next$$($e$$.message)}if($obj$$.paymentByPoints)try{var $detail_he_so_qd$$=await currency.getRate($obj$$.id_app,$obj$$.ma_nt);$obj$$.tien_paymentByPoints=$obj$$.paymentByPoints*$detail_he_so_qd$$}catch($e$$){return $next$$($e$$.message)}for($_checkEvoucher_i$$=0;$_checkEvoucher_i$$<$obj$$.details.length;$_checkEvoucher_i$$++)$detail_he_so_qd$$= $obj$$.details[$_checkEvoucher_i$$],$detail_he_so_qd$$.line=$_checkEvoucher_i$$,"VND"===$obj$$.ma_nt&&($detail_he_so_qd$$.tien=$detail_he_so_qd$$.tien_nt,$detail_he_so_qd$$.tien_hang=$detail_he_so_qd$$.tien_hang_nt,$detail_he_so_qd$$.tien_ck=$detail_he_so_qd$$.tien_ck_nt,$detail_he_so_qd$$.gia_ban=$detail_he_so_qd$$.gia_ban_nt);$obj$$.ma_dvcs?$next$$(null,$obj$$):dvcs.findOne({id_app:$user$$.current_id_app},{_id:1},function($error$$,$dv$$){return $error$$?$next$$($error$$):$dv$$?($obj$$.ma_dvcs=$dv$$._id.toString(), $next$$(null,$obj$$)):$next$$("C\u00f4ng ty/c\u1eeda h\u00e0ng n\u00e0y ch\u01b0a c\u00f3 m\u1ed9t \u0111\u01a1n v\u1ecb c\u01a1 s\u1edf n\u00e0o")})}; module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,sort:{trang_thai:1,ngay_ct:-1,so_ct:-1},onErrorCreating:async($user$$,$obj$$,$next$$)=>{if($obj$$.id_trans)try{await transaction.deleteTrans($obj$$.id_trans)}catch($e$$){return $next$$($e$$.message)}$next$$(null,$obj$$)},onErrorUpdating:async($user$$,$obj$$,$next$$,$old_obj$$)=>{if($obj$$.id_trans)try{await transaction.deleteTrans($obj$$.id_trans)}catch($e$$){return $next$$($e$$.message)}if($old_obj$$.id_trans)try{await transaction.deleteTrans($old_obj$$.id_trans)}catch($e$$){return $next$$($e$$.message)}$next$$(null, $obj$$)}});$contr_router$$.route();$contr_router$$.post=function($obj$$,$fn$$){$fn$$||($fn$$=function(){});async.series({post_socai:function($callback$$){options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean().exec(function($error$$,$rs$jscomp$0$$){let $option$$;$option$$=$rs$jscomp$0$$?$rs$jscomp$0$$.option||{}:{};(new Promise($resolve$$=>{if($obj$$.pt_thanh_toan)ptthanhtoan.findOne({id_app:$obj$$.id_app,_id:$obj$$.pt_thanh_toan}).lean().exec(($e$$,$pt$$)=>{$e$$&&console.log($e$$); $resolve$$($pt$$||{})});else return $resolve$$({})})).then($pt$$=>{$option$$.tk_tien=$pt$$.tk_tien||$option$$.tk_tien||"1111";$option$$.tk_cn=$pt$$.tk_cn||$option$$.tk_cn||"131111";$option$$.tk_tien_dc=$option$$.tk_cn;$option$$.tk_dt=$pt$$.tk_dt||$option$$.tk_dt||"51111";$option$$.tk_tl=$pt$$.tk_tl||$option$$.tk_tl||"52131";$option$$.tk_ck=$pt$$.tk_ck||$option$$.tk_ck||"5211";$option$$.ma_kh="1"==$obj$$.pt_giao_hang||$pt$$.tra_truoc?$pt$$.ma_kh||$obj$$.ma_kh:$obj$$.dich_vu_giao_hang||$pt$$.ma_kh|| $obj$$.ma_kh;const $details$$=[];if($pt$$.tra_truoc&&!$pt$$.thanh_toan_bang_diem){var $detail$$={...$obj$$};$detail$$.tk_co=$option$$.tk_cn;$detail$$.tk_no=$option$$.tk_tien;$detail$$.ma_kh=$option$$.ma_kh;$detail$$.tien_nt=$obj$$.details.map($d$$=>$d$$.tien_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien=$obj$$.details.map($d$$=>$d$$.tien).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien_nt+=$obj$$.ctcpbhs.map($c$$=>$c$$.tien_cp_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien+=$obj$$.ctcpbhs.map($c$$=> $c$$.tien_cp).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$details$$.push($detail$$)}$obj$$.details.forEach(function($d$jscomp$6_detail$$){$d$jscomp$6_detail$$={...$d$jscomp$6_detail$$};$d$jscomp$6_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$6_detail$$.ma_kh=$option$$.ma_kh;$d$jscomp$6_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$6_detail$$.tk_no=$pt$$.tra_truoc?$option$$.tk_cn:"1"!==$obj$$.pt_giao_hang&&$option$$.tk_tien_dc?$option$$.tk_tien_dc:$option$$.tk_tien;$d$jscomp$6_detail$$.tien_nt= $d$jscomp$6_detail$$.tien_hang_nt;$d$jscomp$6_detail$$.tien=$d$jscomp$6_detail$$.tien_hang;$details$$.push($d$jscomp$6_detail$$)});$obj$$.ctcpbhs&&$obj$$.ctcpbhs.forEach(function($d$jscomp$7_detail$$){$d$jscomp$7_detail$$={...$d$jscomp$7_detail$$};$d$jscomp$7_detail$$.tk_co=$option$$.tk_dt;$d$jscomp$7_detail$$.ma_kh=$option$$.ma_kh;$d$jscomp$7_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$7_detail$$.tk_no=$pt$$.tra_truoc?$option$$.tk_cn:"1"!==$obj$$.pt_giao_hang&&$option$$.tk_tien_dc? $option$$.tk_tien_dc:$option$$.tk_tien;$d$jscomp$7_detail$$.tien_nt=$d$jscomp$7_detail$$.tien_cp_nt;$d$jscomp$7_detail$$.tien=$d$jscomp$7_detail$$.tien_cp;$details$$.push($d$jscomp$7_detail$$)});$obj$$.details.forEach(function($d$jscomp$8_detail$$){$d$jscomp$8_detail$$={...$d$jscomp$8_detail$$};$d$jscomp$8_detail$$.tk_no=$option$$.tk_ck;$d$jscomp$8_detail$$.ma_kh=$option$$.ma_kh;$d$jscomp$8_detail$$.ngay_ct=$obj$$.ngay_giao_hang||$obj$$.ngay_ct;$d$jscomp$8_detail$$.tk_co=$pt$$.tra_truoc?$option$$.tk_cn: $option$$.tk_tien;$d$jscomp$8_detail$$.tien_nt=$d$jscomp$8_detail$$.tien_ck_nt;$d$jscomp$8_detail$$.tien=$d$jscomp$8_detail$$.tien_ck;$details$$.push($d$jscomp$8_detail$$)});if($obj$$.tien_ck_hd||$obj$$.tien_evoucher)$detail$$={},$detail$$.tk_no=$option$$.tk_ck,$detail$$.tk_co=$obj$$.tien_thu&&$obj$$.t_tt==$obj$$.tien_thu?$option$$.tk_tien:$option$$.tk_cn,$detail$$.tien_nt=($obj$$.tien_ck_hd||0)+($obj$$.tien_evoucher||0),$detail$$.tien=$detail$$.tien_nt,$detail$$.ma_kh=$option$$.ma_kh,$details$$.push($detail$$); (new PostSocai($obj$$,$details$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr_router$$.creating=async function($user$$,$obj$$,$next$$){if(!$obj$$.details||0===$obj$$.details.length)return $next$$("Y\u00eau c\u1ea7u ch\u1ecdn m\u1ed9t ph\u00f2ng");for(let $i$$=0;$i$$<$obj$$.details.length;$i$$++)if(!await isFree($obj$$.id_app,$obj$$.details[$i$$].department_code,$obj$$.ngay_den,$obj$$.ngay_di))return $next$$("Ph\u00f2ng n\u00e0y hi\u1ec7n t\u1ea1i \u0111\u00e3 c\u00f3 ng\u01b0\u1eddi \u0111\u1eb7t. B\u1ea1n vui l\u00f2ng ch\u1ecdn ph\u00f2ng kh\u00e1c"); valid($user$$,$obj$$,async $error$$=>{if($error$$)return $next$$($error$$);if(!$obj$$.paymentByPoints)return $next$$(null,$obj$$);try{if(await getPointBalance($user$$.current_id_app,$user$$.email)<$obj$$.paymentByPoints)return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 \u0111\u1ee7 \u0111i\u1ec3m \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y.");$next$$(null,$obj$$)}catch($e$$){$next$$($e$$.message)}})};$contr_router$$.created=async function($user$$,$obj$$,$next$$){try{let $virtual_payment_client_url$$= await onepay.createVirtualPaymentClientURL($obj$$,$user$$.clientIp);model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$virtual_payment_client_url$$},$e$$=>{$e$$&&console.log("error create Virtual Payment ClientURL",$e$$.message)});$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$}catch($e$$){console.log("Error create Virtual Payment ClientURL",$e$$.message),$obj$$.virtual_payment_client_url=""}await createTransactionPayment($obj$$);await createTransactionBonus($obj$$); $obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>Evoucher.findOneAndUpdate({_id:$e$$._id},{id_ct_used:$obj$$._id.toString()})));$next$$(null,$obj$$)};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$next$$){valid($user$$,$data$$,async $error$$=>{if($error$$)return $next$$($error$$);if(($obj$$.paymentByPoints||0)!==($data$$.paymentByPoints||0))return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt s\u1ed1 \u0111i\u1ec3m thanh to\u00e1n.");$next$$(null,$data$$,$obj$$)})}; $contr_router$$.updated=async function($user$$,$obj$$,$next$$){try{let $virtual_payment_client_url$$=await onepay.createVirtualPaymentClientURL($obj$$,$user$$.clientIp);model.findOneAndUpdate({_id:$obj$$._id},{virtual_payment_client_url:$virtual_payment_client_url$$},$e$$=>{$e$$&&console.log("error create Virtual Payment ClientURL",$e$$.message)});$obj$$.virtual_payment_client_url=$virtual_payment_client_url$$}catch($e$$){console.log("Error create Virtual Payment ClientURL",$e$$.message),$obj$$.virtual_payment_client_url= ""}"9"==$obj$$.trang_thai?(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng")):await createTransactionBonus($obj$$);await Evoucher.updateMany({id_ct_used:$obj$$._id.toString()},{id_ct_used:""});$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>Evoucher.findOneAndUpdate({_id:$e$$._id},{id_ct_used:$obj$$._id.toString()})));$next$$(null,$obj$$)};$contr_router$$.deleting= function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.deleted=async function($user$$,$obj$$,$next$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng");$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>Evoucher.findOneAndUpdate({_id:$e$$._id},{id_ct_used:""})));$next$$(null,$obj$$)};$contr_router$$.view=function($user$$,$items$$,$fn$$){let $id_app$$= $user$$.current_id_app;async.series({kh:function($callback$$){$items$$.joinModel2($id_app$$,customer,[{where:"ma_kh",fields:"ten_kh"}],function(){$callback$$()})},dich_vu_giao_hang:function($callback$$){$items$$.joinModel2($id_app$$,customer,[{where:{dich_vu_giao_hang:"ma_kh"},fields:{ten_dich_vu_giao_hang:"ten_kh"}}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}], function(){$callback$$()})},ptthanhtoan:function($callback$$){$items$$.joinModel2($id_app$$,ptthanhtoan,[{where:{pt_thanh_toan:"_id"},fields:{ten_pt_thanh_toan:"ten"}}],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"),$r$$.t_tien_hang_nt=$r$$.details.csum("tien_hang_nt"),$r$$.t_ck=$r$$.details.csum("tien_ck")+$r$$.tien_ck_hd,$r$$.t_ck_nt=$r$$.details.csum("tien_ck_nt")+ $r$$.tien_ck_hd):($r$$.t_sl=0,$r$$.t_tien_hang=0,$r$$.t_tien_hang_nt=0,$r$$.t_ck=0,$r$$.t_ck_nt=0);$r$$.t_tien=$r$$.t_tien_hang-$r$$.t_ck;$r$$.t_tien_nt=$r$$.t_tien_hang_nt-$r$$.t_ck_nt;$r$$.ctcpbhs?($r$$.t_cp_cpb_nt=$r$$.ctcpbhs.csum("tien_cp_nt"),$r$$.t_cp_cpb=$r$$.ctcpbhs.csum("tien_cp")):($r$$.t_cp_cpb_nt=0,$r$$.t_cp_cpb=0);$r$$.t_tt_nt=$r$$.t_tien_nt+$r$$.t_cp_cpb_nt;$r$$.t_tt=$r$$.t_tien+$r$$.t_cp_cpb});$callback$$()},details_vt:function($callback$$){async.each($items$$,function($details$jscomp$1_r$$, $callback1$$){$details$jscomp$1_r$$=$details$jscomp$1_r$$.details||[];$details$jscomp$1_r$$.forEach($d$$=>{$d$$.obj_model="department"});$details$jscomp$1_r$$.joinModel2($id_app$$,department,[{where:"department_code",fields:["department_name","picture",{code:"department_code"},{title:"department_name"},{obj_id:"_id"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$, dmdt,[{where:"ma_dt",fields:"ten_dt"}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},fields:"ten_hd"}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$,dmphi,[{where:"ma_phi",fields:"ten_phi"}], function(){$callback1$$()})},function(){$callback$$()})},details_cpbh:function($callback$$){async.each($items$$,function($ctcpbhs_r$$,$callback1$$){($ctcpbhs_r$$=$ctcpbhs_r$$.ctcpbhs)?$ctcpbhs_r$$.joinModel2($id_app$$,dmcpmh,[{where:"ma_cp",fields:"ten_cp"}],function(){$callback1$$()}):$callback1$$()},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};