UNPKG

flexbiz-server

Version:

Flexible Server

19 lines (18 loc) 8.54 kB
const PostBook=require("../../libs/post-book"),PostSocai=require("../../libs/post-socai"),PostSokho=require("../../libs/post-sokho"),Sokhott=global.getModel("sokhott"),dmvt=global.getModel("dmvt"),dmkho=global.getModel("dmkho"),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$$||= function(){};let $product_details$$=($obj$$.details||[]).map($detail$$=>{if($detail$$.combo&&$detail$$.combo.length>0)return $detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};delete $item$$.px_gia_dd;$item$$.nxt=1;return $item$$});$detail$$={...$detail$$,nxt:1};return[$detail$$]}).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);var $pk_pk_nhaps$$=($obj$$.ds_pk_nhap||[]).filter($d$$=>$d$$.ma_pk_nhap&&$d$$.sl_pk_nhap).concat($obj$$.details.filter($d$$=>$d$$.ma_pk_nhap&& $d$$.sl_pk_nhap));for(var $detail$jscomp$1_pk$$ of $pk_pk_nhaps$$)$pk_pk_nhaps$$={...$detail$jscomp$1_pk$$},$pk_pk_nhaps$$.ma_vt=$pk_pk_nhaps$$.ma_pk_nhap,$pk_pk_nhaps$$.ma_dvt=$pk_pk_nhaps$$.ma_dvt_pk_nhap,$pk_pk_nhaps$$.ma_kho=$pk_pk_nhaps$$.ma_kho_pk_nhap,$pk_pk_nhaps$$.nxt=1,$pk_pk_nhaps$$.tk_co=$obj$$.tk_co,$pk_pk_nhaps$$.tk_no="",$pk_pk_nhaps$$.sl_nhap=$pk_pk_nhaps$$.sl_pk_nhap,$pk_pk_nhaps$$.gia_von_nt=$pk_pk_nhaps$$.gia_von_pk_nhap_nt||0,$pk_pk_nhaps$$.gia_von=$pk_pk_nhaps$$.gia_von_nt*($obj$$.ty_gia|| 1),$pk_pk_nhaps$$.tien_nhap_nt=$pk_pk_nhaps$$.tien_nhap_pk_nt||0,$pk_pk_nhaps$$.tien_nhap=$pk_pk_nhaps$$.tien_nhap_nt*($obj$$.ty_gia||1),$pk_pk_nhaps$$.sl_xuat=0,$pk_pk_nhaps$$.tien_xuat_nt=$pk_pk_nhaps$$.tien_xuat=0,$pk_pk_nhaps$$.tien_hang_nt=$pk_pk_nhaps$$.tien_hang=0,$pk_pk_nhaps$$.tien_ck=$pk_pk_nhaps$$.tien_ck_nt=$pk_pk_nhaps$$.ty_le_ck=0,$pk_pk_nhaps$$.tien_phi=$pk_pk_nhaps$$.tien_phi_nt=0,$product_details$$.push($pk_pk_nhaps$$);$detail$jscomp$1_pk$$=($obj$$.ds_pk_xuat||[]).filter($d$$=>$d$$.ma_pk_xuat&& $d$$.sl_pk_xuat).concat($obj$$.details.filter($d$$=>$d$$.ma_pk_xuat&&$d$$.sl_pk_xuat));for(let $d$$ of $detail$jscomp$1_pk$$)$detail$jscomp$1_pk$$={...$d$$},$detail$jscomp$1_pk$$.ma_vt=$d$$.ma_pk_xuat,$detail$jscomp$1_pk$$.ma_dvt=$d$$.ma_dvt_pk_xuat,$detail$jscomp$1_pk$$.ma_kho=$d$$.ma_kho_pk_xuat,$detail$jscomp$1_pk$$.nxt=2,$detail$jscomp$1_pk$$.tk_no=$obj$$.tk_co,$detail$jscomp$1_pk$$.tk_co="",$detail$jscomp$1_pk$$.sl_xuat=$d$$.sl_pk_xuat,$detail$jscomp$1_pk$$.gia_von_nt=$d$$.gia_von_pk_xuat_nt|| 0,$detail$jscomp$1_pk$$.gia_von=$detail$jscomp$1_pk$$.gia_von_nt*($obj$$.ty_gia||1),$detail$jscomp$1_pk$$.tien_xuat_nt=$d$$.tien_xuat_pk_nt||0,$detail$jscomp$1_pk$$.tien_xuat=$detail$jscomp$1_pk$$.tien_xuat_nt*($obj$$.ty_gia||1),$detail$jscomp$1_pk$$.sl_nhap=0,$detail$jscomp$1_pk$$.tien_nhap_nt=$detail$jscomp$1_pk$$.tien_nhap=0,$detail$jscomp$1_pk$$.tien_hang_nt=$detail$jscomp$1_pk$$.tien_hang=0,$detail$jscomp$1_pk$$.tien_ck=$detail$jscomp$1_pk$$.tien_ck_nt=$detail$jscomp$1_pk$$.ty_le_ck=0,$detail$jscomp$1_pk$$.tien_phi= $detail$jscomp$1_pk$$.tien_phi_nt=0,$product_details$$.push($detail$jscomp$1_pk$$);async.series({post_sokho:function($callback$$){(new PostSokho($obj$$,$product_details$$,function($_detail_detail$$,$callback$$){$_detail_detail$$={...$_detail_detail$$};$_detail_detail$$.ma_kho=$obj$$.ma_kho||$_detail_detail$$.ma_kho;$obj$$.ma_gd=="1"&&($_detail_detail$$.pn_gia_tb=!1);$callback$$($_detail_detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},post_sokhott:function($callback$$){(new PostBook($obj$$, $product_details$$,Sokhott,function($_detail$jscomp$1_detail$$,$callback$$){$_detail$jscomp$1_detail$$={...$_detail$jscomp$1_detail$$};$_detail$jscomp$1_detail$$.ma_kho=$obj$$.ma_kho||$_detail$jscomp$1_detail$$.ma_kho;$obj$$.ma_gd=="1"&&($_detail$jscomp$1_detail$$.pn_gia_tb=!1);$callback$$($_detail$jscomp$1_detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},post_socai:function($callback$$){(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$$($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$$;$obj$$.ma_nt=="VND"&&($detail$$.tien_nhap=$detail$$.tien_nhap_nt)}$next$$(null,$obj$$)};$contr_router$$.creating=function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$obj$$.ma_gd=="1"&&$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.parallel({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_vt:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_vt).joinModel2($id_app$$,dmvt,[{where:"ma_vt",fields:["ten_vt","ma_tt1_yn","ma_tt2_yn","ma_tt3_yn","ma_lo_yn"]}],function(){$callback1$$()})},function(){$callback$$()})},lenhsx:function($callback$$){async.mapLimit($items$$,20,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.mapLimit($items$$,20,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.mapLimit($items$$,20,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.mapLimit($items$$,20,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.mapLimit($items$$, 20,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$$)})}};