UNPKG

flexbiz-server

Version:

Flexible Server

12 lines (11 loc) 5.09 kB
'use strict';const Pbl=global.getModel("pbl"),So1=global.getModel("so1"),Trangthai=global.getModel("trangthai"),xhd=global.getModel("xhd"),dmvt=global.getModel("dmvt"),vat=global.getModel("vat"),async=require("async"),controller=require("../../controllers/controllerRPT"); module.exports=function($router$$){new controller($router$$,"getvc2xhd",async function($req$$,$callback$jscomp$1$$){const $condition$$=$req$$.query;if(!$condition$$.ma_thue||!$condition$$.tu_ngay||!$condition$$.den_ngay)return $callback$jscomp$1$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:ma_thue,tu_ngay,den_ngay");let $_vat$$=await vat.findOne({id_app:$condition$$.id_app,ma_thue:$condition$$.ma_thue});if(!$_vat$$)return $callback$jscomp$1$$("M\u00e3 thu\u1ebf kh\u00f4ng t\u1ed3n t\u1ea1i"); const $trang_thais$$=await Trangthai.find({ma_ct:{$in:["PBL","SO1"]},post:!0},{ma_trang_thai:1,ma_ct:1});async.series({pbl:function($callback$jscomp$0$$){const $query$$={id_app:$condition$$.id_app,trang_thai:{$in:$trang_thais$$.filter($r$$=>"PBL"==$r$$.ma_ct).map($a$$=>$a$$.ma_trang_thai)}};$query$$.ngay_ct={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$condition$$.ma_dvcs&&($query$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.so_ct&&($query$$.so_ct=$condition$$.so_ct);$condition$$.ma_kh&& ($query$$.ma_kh=$condition$$.ma_kh);$condition$$.ma_ct&&($query$$.ma_ct=$condition$$.ma_ct);Pbl.find($query$$).lean().exec(function($error$$,$pbls$$){if($error$$)return $callback$jscomp$0$$($error$$);async.mapSeries($pbls$$,($pbl$$,$callback$$)=>{$pbl$$.details.joinModel2($condition$$.id_app,xhd,{where:$item$$=>({details:{$elemMatch:{id_ct:$pbl$$._id,ma_vt:$item$$.ma_vt}}}),fields:[{id_xhd:"_id"}]},()=>{$pbl$$.details=$pbl$$.details.filter($d$$=>!$d$$.id_xhd);$pbl$$.details.joinModel2($condition$$.id_app, dmvt,{where:"ma_vt",fields:["ten_vt","ma_thue"]},()=>{$pbl$$.details=$pbl$$.details.filter($detail$$=>$detail$$.ma_thue===$_vat$$.ma_thue).map($detail$$=>{let $_detail$$={...$detail$$,sel:!1};$_detail$$.id_ct=$pbl$$._id.toString();$_detail$$.code_ct="PBL";$_detail$$.so_ct=$pbl$$.so_ct;$_detail$$.ngay_ct=$pbl$$.ngay_ct;$_detail$$.thue_suat=$_vat$$.thue_suat;$_detail$$.sl_xuat=$_detail$$.sl_xuat||1;$_detail$$.tt_nt=$_detail$$.tt=$_detail$$.tien;$_detail$$.tien_nt=$_detail$$.tien=$_detail$$.tt/(1+$_detail$$.thue_suat/ 100);$_detail$$.gia_ban_nt=$_detail$$.gia_ban=Math.roundBy($_detail$$.tien_nt/$_detail$$.sl_xuat);$_detail$$.tien_hang_nt=$_detail$$.tien_hang=Math.roundBy($_detail$$.gia_ban_nt*$detail$$.sl_xuat);$_detail$$.ty_le_ck=0;$_detail$$.tien_ck=$_detail$$.tien_ck_nt=0;$_detail$$.tien_nt=$_detail$$.tien=$_detail$$.tien_hang_nt-$_detail$$.tien_ck_nt;$_detail$$.tien_thue_nt=$_detail$$.tien_thue=Math.roundBy($_detail$$.tien_nt*$_detail$$.thue_suat/100);return $_detail$$});$callback$$()})})},()=>{$callback$jscomp$0$$(null, $pbls$$.filter($p$$=>0<$p$$.details.length))})})},so1:function($callback$jscomp$0$$){const $query$$={id_app:$condition$$.id_app,trang_thai:{$in:$trang_thais$$.filter($r$$=>"SO1"==$r$$.ma_ct).map($a$$=>$a$$.ma_trang_thai)}};$query$$.ngay_ct={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$condition$$.ma_dvcs&&($query$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.so_ct&&($query$$.so_ct=$condition$$.so_ct);$condition$$.ma_kh&&($query$$.ma_kh=$condition$$.ma_kh);$condition$$.ma_ct&&($query$$.ma_ct= $condition$$.ma_ct);So1.find($query$$).lean().exec(function($error$$,$so1s$$){if($error$$)return $callback$jscomp$0$$($error$$);async.mapSeries($so1s$$,($so1$$,$callback$$)=>{$so1$$.details.joinModel2($condition$$.id_app,xhd,{where:$item$$=>({details:{$elemMatch:{id_ct:$so1$$._id,ma_vt:$item$$.ma_vt}}}),fields:[{id_xhd:"_id"}]},()=>{$so1$$.details=$so1$$.details.filter($d$$=>!$d$$.id_xhd);$so1$$.details.joinModel2($condition$$.id_app,dmvt,{where:"ma_vt",fields:["ten_vt","ma_thue"]},()=>{$so1$$.details= $so1$$.details.filter($detail$$=>$detail$$.ma_thue===$_vat$$.ma_thue).map($detail$$=>{let $_detail$$={...$detail$$,sel:!1};$_detail$$.id_ct=$so1$$._id.toString();$_detail$$.code_ct="SO1";$_detail$$.so_ct=$so1$$.so_ct;$_detail$$.ngay_ct=$so1$$.ngay_ct;$_detail$$.thue_suat=$_vat$$.thue_suat;$_detail$$.sl_xuat=$_detail$$.sl_xuat||1;$_detail$$.tt_nt=$_detail$$.tt=$_detail$$.tien;$_detail$$.tien_nt=$_detail$$.tien=$_detail$$.tt/(1+$_detail$$.thue_suat/100);$_detail$$.gia_ban_nt=$_detail$$.gia_ban=Math.roundBy($_detail$$.tien_nt/ $_detail$$.sl_xuat);$_detail$$.tien_hang_nt=$_detail$$.tien_hang=Math.roundBy($_detail$$.gia_ban_nt*$detail$$.sl_xuat);$_detail$$.ty_le_ck=0;$_detail$$.tien_ck=$_detail$$.tien_ck_nt=0;$_detail$$.tien_nt=$_detail$$.tien=$_detail$$.tien_hang_nt-$_detail$$.tien_ck_nt;$_detail$$.tien_thue_nt=$_detail$$.tien_thue=Math.roundBy($_detail$$.tien_nt*$_detail$$.thue_suat/100);return $_detail$$});$callback$$()})})},()=>{$callback$jscomp$0$$(null,$so1s$$.filter($p$$=>0<$p$$.details.length))})})}},function($error$$, $results$$){if($error$$)return $callback$jscomp$1$$($error$$);$error$$=$results$$.pbl.map($r$$=>$r$$.details).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);$callback$jscomp$1$$(null,$error$$)})})};