UNPKG

flexbiz-server

Version:

Flexible Server

15 lines (14 loc) 6.29 kB
const PostBook=require("../../libs/post-book"),PostSocai=require("../../libs/post-socai"),Sokho=global.getModel("sokhonpp"),sokhocapphat=global.getModel("sokhocapphat"),dmvt=global.getModel("dmvt"),dmkho=global.getModel("dmkho"),account=global.getModel("account"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),customer=global.getModel("customer"),model=global.getModel("pxk"),controller=require("../../controllers/controller"),trangthai=global.getModel("trangthai"), async=require("async"),ma_ct="PXKNPP"; module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,sort:{ngay_ct:-1,so_ct:-1},onFinding:($user$$,$condition$$,$next$$,$options$$)=>{if($options$$.req.query.id_lenhsx||$condition$$.id_lenhsx)$condition$$.details={$elemMatch:{id_lenhsx:$options$$.req.query.id_lenhsx||$condition$$.id_lenhsx}},delete $condition$$.id_lenhsx;if($options$$.req.query.ma_sp||$condition$$.ma_sp)$condition$$.details={$elemMatch:{ma_sp:$options$$.req.query.ma_sp|| $condition$$.ma_sp}},delete $condition$$.ma_sp;$next$$(null,$condition$$)}});$contr_router$$.route();$contr_router$$.post=function($obj$$,$fn$$){$fn$$||=function(){};async.series({post_sokhocapphat:function($callback$$){(new PostBook($obj$$,$obj$$.details,sokhocapphat,async($_detail_detail$$,$callback$$)=>{$_detail_detail$$={...$_detail_detail$$,nxt:2};$_detail_detail$$.ma_kho=$obj$$.ma_kho||$_detail_detail$$.ma_kho;$callback$$($_detail_detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}, post_sokho:function($callback$$){(new PostBook($obj$$,$obj$$.details,Sokho,async($_detail$jscomp$1_detail$$,$callback$$)=>{$_detail$jscomp$1_detail$$={...$_detail$jscomp$1_detail$$,nxt:2};$_detail$jscomp$1_detail$$.ma_kho=$obj$$.ma_kho||$_detail$jscomp$1_detail$$.ma_kho;$callback$$($_detail$jscomp$1_detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},post_socai:function($callback$$){(new PostSocai($obj$$,$obj$$.details,($_detail$jscomp$2_detail$$,$callback$$)=>{$_detail$jscomp$2_detail$$= {...$_detail$jscomp$2_detail$$};$_detail$jscomp$2_detail$$.tk_no=$obj$$.tk_du||$_detail$jscomp$2_detail$$.tk_du||"6321";$_detail$jscomp$2_detail$$.tk_co=$_detail$jscomp$2_detail$$.tk_vt;$_detail$jscomp$2_detail$$.tien_nt=$_detail$jscomp$2_detail$$.tien_xuat_nt;$_detail$jscomp$2_detail$$.tien=$_detail$jscomp$2_detail$$.tien_xuat;$callback$$($_detail$jscomp$2_detail$$)},global.getModel("socainpp"))).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};const $valid$$= function($i_user$$,$obj$$,$next$$){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_xuat=$detail$$.tien_xuat_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$$,$items$$,$fn$$){let $id_app$$=$user$$.current_id_app;async.series({dt:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,{where:"ma_dt",fields:"ten_dt"},function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,{where:"ma_kh",fields:"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$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.details&&($r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat"),$r$$.t_tien_xuat_nt=$r$$.details.csum("tien_xuat_nt"))});$callback$$()},details_tk:function($callback$$){async.mapSeries($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"}]},{akey:"tk_du",bkey:"tk",fields:[{name:"ten_tk_du",value:"ten_tk"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_vt:function($callback$$){async.mapSeries($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"}]},{akey:"ma_sp",bkey:"ma_vt",fields:[{name:"ten_sp",value:"ten_vt"}]}],function(){$callback1$$()})},function(){$callback$$()})},lenhsx:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.id_lenhsx).joinModel2($id_app$$,global.getModel("lenhsx"),[{where:{id_lenhsx:"_id"},fields:[{so_lenh_sx:"so_ct"}]}],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$$=>$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$$,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$$)})}};