flexbiz-server
Version:
Flexible Server
8 lines (7 loc) • 3.52 kB
JavaScript
'use strict';const sokho=global.getModel("sokho"),dmvt=global.getModel("dmvt"),customer=global.getModel("customer"),group=global.getModel("group"),dmkho=global.getModel("dmkho"),dmnvt=global.getModel("dmnvt"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),dmbp=global.getModel("dmbp"),dmhd=global.getModel("contract"),dmnv=global.getModel("dmnv"),async=require("async"),underscore=require("underscore"),controller=require("../../controllers/controllerRPT"),moment=require("moment");
module.exports=function($router$$){new controller($router$$,"ctmuahang",function($query_req$$,$callback$jscomp$0$$){const $condition$$=$query_req$$.query;if(!$condition$$.tu_ngay||!$condition$$.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");$query_req$$={id_app:$condition$$.id_app,ma_ct:{$in:["PN1","PN9"]}};$query_req$$.ngay_ct={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$condition$$.ma_dvcs&&($query_req$$.ma_dvcs=
$condition$$.ma_dvcs);$condition$$.ma_vt&&($query_req$$.ma_vt=$condition$$.ma_vt.toUpperCase());$condition$$.ma_kho&&($query_req$$.ma_kho=$condition$$.ma_kho.toUpperCase());$condition$$.ma_kh&&($query_req$$.ma_kh=$condition$$.ma_kh);sokho.find($query_req$$).lean().exec(function($error$$,$rs$$){if($error$$)return $callback$jscomp$0$$($error$$);(new Promise(($resolve$$,$reject$$)=>{async.series({ten_vt:$callback$$=>{$rs$$.joinModel2($condition$$.id_app,dmvt,{where:"ma_vt",fields:["ten_vt","ma_nvt",
"ma_lvt"]},()=>{$callback$$()})},ten_kho:$callback$$=>{$rs$$.joinModel2($condition$$.id_app,dmkho,{where:"ma_kho",fields:"ten_kho"},()=>{$callback$$()})},ten_kh:$callback$$=>{$rs$$.joinModel2($condition$$.id_app,customer,{where:"ma_kh",fields:["ten_kh","nh_kh"]},()=>{$callback$$()})},dmdt:$callback$$=>{$rs$$.joinModel2($condition$$.id_app,dmdt,{where:"ma_dt",fields:"ten_dt"},()=>{$callback$$()})},dmhd:$callback$$=>{$rs$$.joinModel2($condition$$.id_app,dmhd,{where:{ma_hd:"so_hd"},fields:"ten_hd"},
()=>{$callback$$()})},dmbp:$callback$$=>{$rs$$.joinModel2($condition$$.id_app,dmbp,{where:"ma_bp",fields:"ten_bp"},()=>{$callback$$()})},dmphi:$callback$$=>{$rs$$.joinModel2($condition$$.id_app,dmphi,{where:"ma_phi",fields:"ten_phi"},()=>{$callback$$()})},dmnv:$callback$$=>{$rs$$.joinModel2($condition$$.id_app,dmnv,{where:"ma_nv",fields:"ten_nv"},()=>{$callback$$()})}},($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resolve$$($rs$$)})})).then(()=>new Promise(($resolve$$,$reject$$)=>{async.series({nh_vt:$callback$$=>
{$rs$$.joinModel2($condition$$.id_app,dmnvt,{where:{ma_nvt:"_id"},fields:"ten_nvt"},()=>{$callback$$()})},nh_kh:$callback$$=>{$rs$$.joinModel2($condition$$.id_app,group,{where:{nh_kh:"_id"},fields:[{ten_nh_kh:"group_name"}]},()=>{$callback$$()})}},($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resolve$$($rs$$)})})).then(()=>{$rs$$.forEach(function($r$$){$r$$.bold=!1});var $report$$=underscore.sortBy($rs$$,function($r$$){return moment($r$$.ngay_ct).format("YYYY-MM-DD")+$r$$.so_ct+$r$$.ma_vt});$report$$.push({ten_vt:"T\u1ed5ng c\u1ed9ng",
sl_nhap:$report$$.csum("sl_nhap"),tien_hang:$report$$.csum("tien_hang"),tien_phi:$report$$.csum("tien_phi"),tien_ck:$report$$.csum("tien_ck"),tien_nhap:$report$$.csum("tien_nhap"),tien_hang_nt:$report$$.csum("tien_hang_nt"),tien_phi_nt:$report$$.csum("tien_phi_nt"),tien_ck_nt:$report$$.csum("tien_ck_nt"),tien_nhap_nt:$report$$.csum("tien_nhap_nt"),bold:!0});$callback$jscomp$0$$(null,$report$$)}).catch($e$$=>{$callback$jscomp$0$$($e$$)})})})};