flexbiz-server
Version:
Flexible Server
6 lines (5 loc) • 2.06 kB
JavaScript
'use strict';const dkvt=require("./dkvt"),sokho=global.getModel("sokho"),async=require("async");
module.exports=function($condition$$,$fn$$){if(!($condition$$&&$condition$$.ma_vt&&$condition$$.tu_ngay&&$condition$$.den_ngay&&$condition$$.id_app))return $fn$$("L\u1ed7i: B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_ngay,den_ngay,id_app,ma_vt");let $ma_vt$$=$condition$$.ma_vt,$tu_ngay$$=$condition$$.tu_ngay,$den_ngay$$=$condition$$.den_ngay,$id_app$$=$condition$$.id_app;async.parallel({dn:function($callback$$){let $query$$={ngay:$tu_ngay$$,id_app:$id_app$$};$condition$$.ma_kho&&
($query$$.ma_kho=$condition$$.ma_kho);$query$$.ma_vt=$condition$$.ma_vt;dkvt($query$$,function($error$$,$du_dau_result$$){if($error$$)return $callback$$($error$$);$error$$=$du_dau_result$$.csum("ton00");$du_dau_result$$=$du_dau_result$$.csum("du00");$callback$$(null,{ton_dau:$error$$,du_dau:$du_dau_result$$})})},ps:function($callback$$){let $query$$={id_app:$id_app$$,ngay_ct:{$gte:$tu_ngay$$,$lt:$den_ngay$$},ma_vt:$ma_vt$$,$or:[{nxt:1,pn_gia_tb:!1},{nxt:2,px_gia_dd:!0}]};$condition$$.ma_kho&&($query$$.ma_kho=
$condition$$.ma_kho,$query$$.$or.push({nxt:1,pn_gia_tb:!0,ma_ct:"PNC"}));sokho.find($query$$).lean().exec(function($error$$,$pss_tien_nhap$$){$error$$?$callback$$($error$$):($pss_tien_nhap$$=$pss_tien_nhap$$.map($ps$$=>{$ps$$.sl_nhap=($ps$$.sl_nhap_qd||0)-($ps$$.sl_xuat_qd||0);return $ps$$}),$error$$=$pss_tien_nhap$$.csum("sl_nhap"),$pss_tien_nhap$$=$pss_tien_nhap$$.csum("tien_nhap")-$pss_tien_nhap$$.csum("tien_xuat"),$callback$$(null,{sl_nhap:$error$$,tien_nhap:$pss_tien_nhap$$}))})}},function($error$$,
$results$$){if($error$$)$fn$$($error$$);else{$error$$=$results$$.ps.sl_nhap+$results$$.dn.ton_dau;var $tong_tien$$=$results$$.ps.tien_nhap+$results$$.dn.du_dau,$gia$$=$error$$?Math.roundBy($tong_tien$$/$error$$,0):0;return $fn$$(null,{ma_vt:$ma_vt$$,ton_dau:$results$$.dn.ton_dau,du_dau:$results$$.dn.du_dau,sl_nhap:$results$$.ps.sl_nhap,tien_nhap:$results$$.ps.tien_nhap,tong_sl:$error$$,tong_tien:$tong_tien$$,gia:$gia$$})}})};