UNPKG

flexbiz-server

Version:

Flexible Server

10 lines (9 loc) 3.98 kB
'use strict';const thnxt=require("../../libs/thnxttt"),dmvt=global.getModel("dmvt"),dmkho=global.getModel("dmkho"),dmnvt=global.getModel("dmnvt"),customer=global.getModel("customer"),controller=require("../../controllers/controllerRPT"),async=require("async"); module.exports=function($router$$){new controller($router$$,"thnxttt",function($req$$,$callback$jscomp$0$$){const $query$$=$req$$.query,$id_app$$=$req$$.query.id_app;if(!$query$$.tu_ngay||!$query$$.den_ngay)return $callback$jscomp$0$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_ngay,den_ngay");$callback$jscomp$0$$(null,null,"begin");(new Promise(($resolve$$,$reject$$)=>{if(!$query$$.ma_vt&&($query$$.ma_ncc||$query$$.ma_kh||$query$$.ma_nvt||$query$$.ma_nvt2||$query$$.ma_nvt3|| $query$$.ma_nvt4)){const $_query$$={id_app:$id_app$$,tg_tk:!0};if($query$$.ma_ncc||$query$$.ma_kh)$_query$$.ma_ncc=$query$$.ma_ncc||$query$$.ma_kh;$query$$.ma_nvt&&0<$query$$.ma_nvt.length&&($_query$$.ma_nvt=$query$$.ma_nvt);$query$$.ma_nvt2&&0<$query$$.ma_nvt2.length&&($_query$$.ma_nvt2=$query$$.ma_nvt2);$query$$.ma_nvt3&&0<$query$$.ma_nvt3.length&&($_query$$.ma_nvt3=$query$$.ma_nvt3);$query$$.ma_nvt4&&0<$query$$.ma_nvt4.length&&($_query$$.ma_nvt4=$query$$.ma_nvt4);$callback$jscomp$0$$(null,null, "running");dmvt.find($_query$$,{ma_vt:1}).lean().exec(($err$$,$rs$$)=>{if($err$$)return $reject$$($err$$);$callback$jscomp$0$$(null,null,"running");$resolve$$($rs$$.map($r$$=>$r$$.ma_vt))})}else $resolve$$($query$$.ma_vt)})).then($ma_vt$$=>{$ma_vt$$&&($query$$.ma_vt=$ma_vt$$);$callback$jscomp$0$$(null,null,"running");thnxt($query$$,function($error$$,$report$$){if($error$$)return $callback$jscomp$0$$($error$$);$callback$jscomp$0$$(null,null,"running");async.series({vt:$callback$$=>{$report$$.filter($r$$=> $r$$.ma_vt).joinModel2($id_app$$,dmvt,{where:"ma_vt",fields:["ten_vt","tg_tk","ma_ncc","ma_dvt","ma_nvt"],setFields:($a$$,$b$$)=>{if($b$$.picture){let $p$$=$b$$.picture.split(".");$a$$.picture_thumb=$b$$.picture+".thumb."+$p$$[$p$$.length-1]}else $a$$.picture="/getfile/others/noimage.png",$a$$.picture_thumb="/getfile/others/noimage.png"}},()=>{$report$$.filter($r$$=>$r$$.ma_ncc).joinModel2($id_app$$,customer,{where:{ma_ncc:"ma_kh"},fields:[{ten_ncc:"ten_kh"}]},()=>{$report$$.filter($r$$=>$r$$.ma_nvt).joinModel2($id_app$$, dmnvt,{where:{ma_nvt:"_id"},fields:["ten_nvt"]},()=>{$callback$$()})})})},tt1:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_vt&&$r$$.ma_tt1).joinModel2($id_app$$,global.getModel("dmtt"),{where:$item$$=>({ma_vt:$item$$.ma_vt,ma_tt:$item$$.ma_tt1,loai_tt:"1"}),fields:[{barcode1:"ma_tt2"},{ten_tt1:"ten_tt"}]},()=>{$callback$$()})},tt2:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_vt&&$r$$.ma_tt2).joinModel2($id_app$$,global.getModel("dmtt"),{where:$item$$=>({ma_vt:$item$$.ma_vt,ma_tt:$item$$.ma_tt2,loai_tt:"2"}), fields:[{barcode2:"ma_tt2"},{ten_tt2:"ten_tt"}]},()=>{$callback$$()})},tt3:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_vt&&$r$$.ma_tt3).joinModel2($id_app$$,global.getModel("dmtt"),{where:$item$$=>({ma_vt:$item$$.ma_vt,ma_tt:$item$$.ma_tt3,loai_tt:"3"}),fields:[{barcode3:"ma_tt2"},{ten_tt3:"ten_tt"}]},()=>{$callback$$()})},kho:$callback$$=>{$report$$.filter($r$$=>$r$$.ma_kho).joinModel2($id_app$$,dmkho,{where:"ma_kho",fields:["ten_kho"]},()=>{$callback$$()})}},()=>{$callback$jscomp$0$$(null,null, "running");$report$$=$report$$.filter($r$$=>$r$$.tg_tk);const $total$$={ma_vt:"",ten_vt:"T\u1ed5ng c\u1ed9ng",ton_dau:$report$$.csum("ton_dau"),du_dau:$report$$.csum("du_dau"),sl_nhap:$report$$.csum("sl_nhap"),tien_nhap:$report$$.csum("tien_nhap"),sl_xuat:$report$$.csum("sl_xuat"),tien_xuat:$report$$.csum("tien_xuat"),ton_cuoi:$report$$.csum("ton_cuoi"),du_cuoi:$report$$.csum("du_cuoi"),systotal:1,bold:!0};$report$$.push($total$$);$callback$jscomp$0$$(null,$report$$,"data");$callback$jscomp$0$$(null, null,"end")})},$log$$=>{$callback$jscomp$0$$(null,null,"running");console.log($log$$)})}).catch($e$$=>{$callback$jscomp$0$$($e$$)})},{stream:!0})};