UNPKG

flexbiz-server

Version:

Flexible Server

6 lines (5 loc) 2.25 kB
const dkdiem=require("./dkdiem"),transaction=global.getModel("transaction"),async=require("async"); module.exports=function($condition$$,$fn$$){if($condition$$&&$condition$$.tu_ngay&&$condition$$.email&&$condition$$.den_ngay&&$condition$$.id_app){var $tu_ngay$$=$condition$$.tu_ngay,$den_ngay$$=$condition$$.den_ngay,$id_app$$=$condition$$.id_app;async.series({dn:function($callback$$){dkdiem($condition$$,function($error$$,$result$$){if($error$$)return $callback$$($error$$);$callback$$(null,$result$$)})},ps:function($callback$$){transaction.find({id_app:$id_app$$,ngay_ct:{$gte:$tu_ngay$$,$lte:$den_ngay$$}, $or:[{"sender.email":$condition$$.email},{"receiver.email":$condition$$.email}]}).lean().then(function($ps_pss$$){$ps_pss$$=$ps_pss$$.map($p_x$$=>{$p_x$$=Object.assign({},$p_x$$);$p_x$$.sender.email===$condition$$.email?($p_x$$.email=$p_x$$.sender.email,$p_x$$.sl_xuat=$p_x$$.amount,$p_x$$.sl_nhap=0):($p_x$$.email=$p_x$$.receiver.email,$p_x$$.sl_nhap=$p_x$$.amount,$p_x$$.sl_xuat=0);return[$p_x$$]}).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]).filter($r$$=>$r$$.email===$condition$$.email);$callback$$(null, $ps_pss$$)}).catch($error$$=>{$callback$$($error$$)})}},function($error$$,$results$$){if($error$$)$fn$$($error$$);else{var $data$$=[];$results$$.ps.forEach(function($r$$){$r$$.sysorder=5;$r$$.bold=!1;$data$$.push($r$$)});async.series({ton_dau:function($callback$$){var $ton_dau$$=$results$$.dn.csum("ton00");$callback$$(null,$ton_dau$$)},sl_nhap:function($callback$$){var $sl_nhap$$=$results$$.ps.csum("sl_nhap");$callback$$(null,$sl_nhap$$)},sl_xuat:function($callback$$){var $sl_xuat$$=$results$$.ps.csum("sl_xuat"); $callback$$(null,$sl_xuat$$)}},function($error$$,$results$$){$data$$.push({sysorder:1,bold:!0,description:"T\u1ed3n \u0111\u1ea7u k\u1ef3",sl_nhap:$results$$.ton_dau,sl_xuat:0});$data$$.push({sysorder:6,bold:!0,description:"C\u1ed9ng ph\u00e1t sinh trong k\u1ef3",sl_nhap:$results$$.sl_nhap,sl_xuat:$results$$.sl_xuat});$data$$.push({sysorder:9,bold:!0,description:"T\u1ed3n cu\u1ed1i k\u1ef3",sl_nhap:$results$$.ton_dau+$results$$.sl_nhap-$results$$.sl_xuat});$fn$$(null,$data$$)})}})}else $fn$$("L\u1ed7i: B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1: tu_ngay,den_ngay,email,id_app")};