flexbiz-server
Version:
Flexible Server
9 lines (8 loc) • 3.35 kB
JavaScript
'use strict';const databanle=require("../../libs/databanle"),giaoca=global.getModel("giaoca"),ptthanhtoan=global.getModel("ptthanhtoan"),async=require("async"),controller=require("../../controllers/controllerRPT");
module.exports=function($router$$){new controller($router$$,"getcashbycashier",function($req$$,$callback$jscomp$0$$){let $condition$$=$req$$.query;$condition$$.thoi_gian_tu&&($condition$$.tu_ngay=new Date($condition$$.thoi_gian_tu));$condition$$.thoi_gian_den&&($condition$$.den_ngay=new Date($condition$$.thoi_gian_den));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");let $id_app$$=$req$$.user.current_id_app,
$query$$={id_app:$id_app$$};$query$$.payment_time={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$query$$.ma_kho=$condition$$.ma_kho;$condition$$.ma_ca&&($query$$.ma_ca=$condition$$.ma_ca);$query$$.cashier=$req$$.user.email;databanle($query$$,function($error$jscomp$0$$,$details$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);async.mapSeries($details$$,($r$$,$callback$$)=>{(async()=>{var $_pttt__pttt2$$=await ptthanhtoan.findOne({id_app:$id_app$$,_id:$r$$.pt_thanh_toan});
let $t_tien_thu$$=0;$_pttt__pttt2$$&&"TIEN"!==$_pttt__pttt2$$.loai_tien||($t_tien_thu$$=$r$$.tien_thu||0);$r$$.pt_thanh_toan2&&$r$$.tien_thu2&&(($_pttt__pttt2$$=await ptthanhtoan.findOne({id_app:$id_app$$,_id:$r$$.pt_thanh_toan2}))&&"TIEN"!==$_pttt__pttt2$$.loai_tien||($t_tien_thu$$+=$r$$.tien_thu2));$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien=$r$$.details.csum("tien_hang");$r$$.t_tien_ck=$r$$.details.csum("tien_ck");$r$$.tien_ck_hd=$r$$.tien_ck_hd||0;$r$$.tien_evoucher=$r$$.tien_evoucher||
0;$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat");$r$$.t_tien_hang=$r$$.t_tien-$r$$.t_tien_ck-$r$$.tien_ck_hd-$r$$.tien_evoucher;$r$$.t_tien_thu=$t_tien_thu$$;$callback$$(null,$r$$)})()},function($error$$,$details$$){if($error$$)return $callback$jscomp$0$$($error$$);let $tien_hang$$=$details$$.csum("t_tien_hang"),$tien_thu$$=$details$$.csum("t_tien_thu"),$phai_tra$$=$details$$.csum("phai_tra"),$tien_thu_net$$=$tien_thu$$-$phai_tra$$;$query$$={id_app:$id_app$$};$query$$.tu_ngay=$condition$$.tu_ngay;
$query$$.den_ngay=$condition$$.den_ngay;$query$$.ma_kho=$condition$$.ma_kho;$condition$$.ma_ca&&($query$$.ma_ca=$condition$$.ma_ca);$query$$.nhan_vien=$req$$.user.email;giaoca.find($query$$).lean().exec(async($da_giao_e$$,$query_nhan_rs_tien_ket$$)=>{if($da_giao_e$$)return $callback$jscomp$0$$($da_giao_e$$);$da_giao_e$$=$query_nhan_rs_tien_ket$$.csum("tien_giao");$query_nhan_rs_tien_ket$$={id_app:$id_app$$};$query_nhan_rs_tien_ket$$.ma_kho=$condition$$.ma_kho;$query_nhan_rs_tien_ket$$.nhan_vien_nhan=
$req$$.user.email;$query_nhan_rs_tien_ket$$.tu_ngay=$condition$$.tu_ngay;$query_nhan_rs_tien_ket$$.den_ngay=$condition$$.den_ngay;$condition$$.ma_ca&&($query_nhan_rs_tien_ket$$.ma_ca=$condition$$.ma_ca);$query_nhan_rs_tien_ket$$=(await giaoca.find({query_nhan:$query_nhan_rs_tien_ket$$}).lean()).map($r$$=>$r$$.tien_giao||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$callback$jscomp$0$$(null,{tien_ket:$query_nhan_rs_tien_ket$$,tien_hang:$tien_hang$$,tien_thu:$tien_thu$$,phai_tra:$phai_tra$$,tien_thu_net:$tien_thu_net$$,
da_giao:$da_giao_e$$,details:$details$$})})})})},{cache:!1})};