UNPKG

flexbiz-server

Version:

Flexible Server

10 lines (9 loc) 4.08 kB
const dvcs=global.getModel("dvcs"),account=global.getModel("account"),dmdt=global.getModel("dmdt"),dmnv=global.getModel("dmnv"),dmbp=global.getModel("dmbp"),contract=global.getModel("contract"),dmphi=global.getModel("dmphi"),model=global.getModel("dn0"),pc1=global.getModel("pc1"),trangthai=global.getModel("trangthai"),controller=require("../../controllers/controller"),async=require("async"),ma_ct="DN0",valid_detail=function($i_user$$,$obj$$,$fn$$){if($obj$$.details)for($i_user$$=0;$i_user$$<$obj$$.details.length;$i_user$$++){let $detail$$= $obj$$.details[$i_user$$];$detail$$.line=$i_user$$;$obj$$.ma_nt=="VND"&&($detail$$.tien=$detail$$.tien_nt)}$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}});$contr_router$$.route();$contr_router$$.creating=function($user$$,$obj$$,$next$$){if(!$obj$$.details||$obj$$.details.csum("tien_nt")==0)return $next$$("B\u1ea1n ch\u01b0a nh\u1eadp chi ti\u1ebft \u0111\u1ec1 ngh\u1ecb chuy\u1ec3n l\u01b0\u01a1ng");valid_detail($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null, $obj$$)})};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$next$$){valid_detail($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})};$contr_router$$.view=function($user$$,$items$$,$fn$$){const $id_app$$=$user$$.current_id_app;async.series({bp:function($callback$$){$items$$.filter($item$$=>$item$$.ma_bp).joinModel2($id_app$$,dmbp,[{where:"ma_bp",fields:["ten_bp"]}],function(){$callback$$()})},tk:function($callback$$){$items$$.filter($item$$=> $item$$.tk_co).joinModel2($id_app$$,account,[{where:$item$$=>({tk:$item$$.tk_co}),fields:[{name:"ten_tk_co",value:"ten_tk"}]}],function(){$callback$$()})},dv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dvcs).joinModel2($id_app$$,dvcs,[{where:$item$$=>({_id:$item$$.ma_dvcs}),setFields:($item$$,$ref$$)=>{$item$$.ten_dvcs=$ref$$.ten_dvcs}}],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$$()})},pc1:function($callback$$){$items$$.joinModel2($id_app$$,pc1,[{where:{_id:"id_dn0"},fields:[{id_pc1:"_id"},{so_ct_pc1:"so_ct"},{ngay_ct_pc1:"ngay_ct"}]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.t_tien=0;$r$$.t_tien_nt=0;$r$$.details&&($r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tien_nt=$r$$.details.csum("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$$){($r$$.details||[]).joinModel2($id_app$$,account,[{where:$item$$=>({tk:$item$$.tk_no}),fields:[{ten_tk_no:"ten_tk"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_nv:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_nv).joinModel2($id_app$$,dmnv,[{where:"ma_nv",fields:["ten_nv"]}],function(){$callback1$$()})}, function(){$callback$$()})},details_dt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:"ma_dt",fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_hopdong:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($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$$){($r$$.details||[]).filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:"ma_phi",fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};