UNPKG

flexbiz-server

Version:

Flexible Server

15 lines (14 loc) 6.79 kB
'use strict';const PostBook=require("../../libs/post-book"),PostSocai=require("../../libs/post-socai"),Sokho=global.getModel("sokho"),Sokhott=global.getModel("sokhott"),dvcs=global.getModel("dvcs"),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("pnk"),controller=require("../../controllers/controller"), trangthai=global.getModel("trangthai"),async=require("async"),ma_ct="PNK"; 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;$next$$(null,$condition$$)}});$contr_router$$.route();$contr_router$$.post=function($obj$$,$fn$$){$fn$$|| ($fn$$=function(){});async.series({post_sokho:function($callback$jscomp$0$$){(new PostBook($obj$$,[...$obj$$.details],Sokho,function($_detail_detail$$,$callback$$){$_detail_detail$$={...$_detail_detail$$,nxt:1};$_detail_detail$$.ma_kho=$obj$$.ma_kho||$_detail_detail$$.ma_kho;$_detail_detail$$.he_so_qd=1;$_detail_detail$$.sl_nhap_qd=$_detail_detail$$.sl_nhap*$_detail_detail$$.he_so_qd;"1"==$obj$$.ma_gd&&($_detail_detail$$.pn_gia_tb=!1);$callback$$($_detail_detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$, $rs$$)})},post_sokhott:function($callback$jscomp$0$$){(new PostBook($obj$$,[...$obj$$.details],Sokhott,function($_detail$jscomp$1_detail$$,$callback$$){$_detail$jscomp$1_detail$$={...$_detail$jscomp$1_detail$$,nxt:1};$_detail$jscomp$1_detail$$.ma_kho=$obj$$.ma_kho||$_detail$jscomp$1_detail$$.ma_kho;$_detail$jscomp$1_detail$$.he_so_qd=1;$_detail$jscomp$1_detail$$.sl_nhap_qd=$_detail$jscomp$1_detail$$.sl_nhap*$_detail$jscomp$1_detail$$.he_so_qd;"1"==$obj$$.ma_gd&&($_detail$jscomp$1_detail$$.pn_gia_tb= !1);$callback$$($_detail$jscomp$1_detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($e$$,$rs$$)})},post_socai:function($callback$jscomp$0$$){(new PostSocai($obj$$,[...$obj$$.details],function($_detail$jscomp$2_detail$$,$callback$$){$_detail$jscomp$2_detail$$={...$_detail$jscomp$2_detail$$};$_detail$jscomp$2_detail$$.tk_no=$_detail$jscomp$2_detail$$.tk_vt;$_detail$jscomp$2_detail$$.tk_co=$obj$$.tk_du||$_detail$jscomp$2_detail$$.tk_du||"6321";$_detail$jscomp$2_detail$$.tien_nt=$_detail$jscomp$2_detail$$.tien_nhap_nt; $_detail$jscomp$2_detail$$.tien=$_detail$jscomp$2_detail$$.tien_nhap;$callback$$($_detail$jscomp$2_detail$$)})).run(function($e$$,$rs$$){$callback$jscomp$0$$($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$$++){const $detail$$=$obj$$.details[$i_user$$];$detail$$.line=$i_user$$;"VND"==$obj$$.ma_nt&&($detail$$.tien_nhap=$detail$$.tien_nhap_nt)}$next$$(null,$obj$$)};$contr_router$$.creating= function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);"1"==$obj$$.ma_gd&&$obj$$.details.forEach($d$$=>{$d$$.pn_gia_tb=!1;$d$$.gia_von=0;$d$$.gia_von_nt=0;$d$$.tien_nhap_nt=0;$d$$.tien_nhap=0});$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$$){const $id_app$$=$user$$.current_id_app;async.series({dv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dvcs).joinModel2($id_app$$,dvcs,{where:{ma_dvcs:"_id"},fields:"ten_dvcs"},function(){$callback$$()})},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$$.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$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.details&&($r$$.t_sl=$r$$.details.csum("sl_nhap"),$r$$.t_tien_nhap=$r$$.details.csum("tien_nhap"),$r$$.t_tien_nhap_nt=$r$$.details.csum("tien_nhap_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).joinModel2($id_app$$,dmvt,[{where:"ma_vt",fields:[{name:"ten_vt", 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_dt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($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_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).joinModel2($id_app$$,dmphi,[{where:"ma_phi",fields:[{name:"ten_phi",value:"ten_phi"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_kho:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_kho).joinModel2($id_app$$,dmkho,[{where:"ma_kho",fields:[{name:"ten_kho",value:"ten_kho"}]}],function(){$callback1$$()})},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};