UNPKG

flexbiz-server

Version:

Flexible Server

13 lines (12 loc) 5.55 kB
'use strict';const databanle=require("../../libs/databanle"),User=global.getModel("user"),async=require("async"),underscore=require("underscore"),controller=require("../../controllers/controllerRPT"); module.exports=function($router$$){new controller($router$$,"dtbanletheothungan",function($condition_req$$,$callback$jscomp$0$$){$condition_req$$=$condition_req$$.query;if(!$condition_req$$.tu_ngay||!$condition_req$$.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");const $query$$={id_app:$condition_req$$.id_app};$query$$.ngay_ct={$gte:$condition_req$$.tu_ngay,$lte:$condition_req$$.den_ngay};$condition_req$$.ma_dvcs&&($query$$.ma_dvcs= $condition_req$$.ma_dvcs);$condition_req$$.user_created&&($query$$.user_created=$condition_req$$.user_created);$condition_req$$.cashier&&($query$$.cashier=$condition_req$$.cashier);$condition_req$$.ma_kho&&($query$$.$or=[{ma_kho:$condition_req$$.ma_kho},{"details.ma_kho":$condition_req$$.ma_kho}]);$condition_req$$.ma_ct&&($query$$.ma_ct=$condition_req$$.ma_ct);databanle($query$$,function($error$jscomp$2$$,$rs$$,$ptthanhtoans$$){if($error$jscomp$2$$)return $callback$jscomp$0$$($error$jscomp$2$$);const $thanh_toan$$= $ptthanhtoans$$.map($pt$$=>({name:$pt$$.ma,value:$pt$$.ma,ma:$pt$$.ma,ten:$pt$$.ten}));async.mapSeries($rs$$,function($r$$,$callback$$){$r$$.cashier=$r$$.cashier||$r$$.user_created;$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien_hang=$r$$.details.csum("tien_hang");$r$$.t_tien_hang_ct=$r$$.details.csum("tien_hang_ct");$r$$.t_thue=$r$$.details.csum("tien_thue");$r$$.t_tien_ck=$r$$.details.csum("tien_ck");$r$$.t_tien=$r$$.details.csum("tien");$r$$.t_tien_cp=$r$$.details.csum("tien_cp");$r$$.tien_freeship= $r$$.tien_freeship||0;$r$$.tien_phi_vc=$r$$.tien_phi_vc||0;$r$$.tien_ck_hd=$r$$.tien_ck_hd?$r$$.tien_ck_hd:0;$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat");$r$$.details_tl?($r$$.t_tien_tl=$r$$.details_tl.csum("tien_hang_ct")-$r$$.details_tl.csum("tien_ck"),$r$$.t_tien_thue_tl=$r$$.details_tl.csum("tien_thue"),$r$$.t_tien_nhap=$r$$.details_tl.csum("tien_nhap"),$r$$.t_sl_nhap=$r$$.details_tl.csum("sl_nhap")):($r$$.t_tien_tl=0,$r$$.t_sl_nhap=0,$r$$.t_tien_nhap=0);$callback$$(null,$r$$)},function($error$jscomp$0$$, $rs$jscomp$0$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);$rs$jscomp$0$$.groupBy("cashier",[{name:"t_sl_xuat",value:"t_sl_xuat"},{name:"t_tien_hang",value:"t_tien_hang"},{name:"t_tien_hang_ct",value:"t_tien_hang_ct"},{name:"t_thue",value:"t_thue"},{name:"t_tien_cp",value:"t_tien_cp"},{name:"t_tien_ck",value:"t_tien_ck"},{name:"t_tien",value:"t_tien"},{name:"tien_ck_hd",value:"tien_ck_hd"},{name:"tien_freeship",value:"tien_freeship"},{name:"tien_phi_vc",value:"tien_phi_vc"}, {name:"tien_evoucher",value:"tien_evoucher"},{name:"tien_thu",value:"tien_thu"},{name:"tien_thu2",value:"tien_thu2"},{name:"tien_paymentByPoints",value:"tien_paymentByPoints"},{name:"t_tien_xuat",value:"t_tien_xuat"},{name:"t_sl_nhap",value:"t_sl_nhap"},{name:"t_tien_tl",value:"t_tien_tl"},{name:"t_tien_thue_tl",value:"t_tien_thue_tl"},{name:"t_tien_nhap",value:"t_tien_nhap"},{name:"phai_tra",value:"phai_tra"},...$thanh_toan$$],function($error$$,$rs$$){if($error$$)return $callback$jscomp$0$$($error$$); const $report$$=underscore.sortBy($rs$$,function($r$$){return $r$$.user_created});let $i$$=1;$report$$.forEach(function($r$$){$r$$.stt=$i$$;$r$$.bold=!1;$r$$.t_phai_thu=$r$$.t_tien_hang_ct-($r$$.t_tien_ck||0)+($r$$.t_thue||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0)-($r$$.tien_ck_hd||0)-($r$$.tien_evoucher||0);$r$$.t_doanh_thu=$r$$.t_tien_hang_ct-($r$$.t_tien_ck||0)+($r$$.tien_phi_vc||0)-($r$$.tien_freeship||0)-($r$$.tien_ck_hd||0)-($r$$.tien_evoucher||0);$r$$.t_doanh_thu_thuan=$r$$.t_doanh_thu- $r$$.t_tien_tl;$r$$.t_lai=$r$$.t_doanh_thu-$r$$.t_tien_xuat-($r$$.t_tien_tl-$r$$.t_tien_nhap);$r$$.t_tien_thu=$thanh_toan$$.map($pt$$=>$r$$[$pt$$.ma]||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$r$$.t_tien_paymentByPoints=$r$$.tien_paymentByPoints||0;$i$$++});$report$$.joinModel(null,User,[{akey:"cashier",bkey:"email",fields:[{name:"name",value:"name"}]}],function(){const $tong_cong$$={name:"T\u1ed5ng c\u1ed9ng",t_sl_xuat:$report$$.csum("t_sl_xuat"),t_tien_hang:$report$$.csum("t_tien_hang"),t_tien_hang_ct:$report$$.csum("t_tien_hang_ct"), t_thue:$report$$.csum("t_thue"),t_tien_cp:$report$$.csum("t_tien_cp"),t_tien_ck:$report$$.csum("t_tien_ck"),t_tien:$report$$.csum("t_tien"),tien_ck_hd:$report$$.csum("tien_ck_hd"),tien_phi_vc:$report$$.csum("tien_phi_vc"),tien_freeship:$report$$.csum("tien_freeship"),t_tien_xuat:$report$$.csum("t_tien_xuat"),t_phai_thu:$report$$.csum("t_phai_thu"),t_doanh_thu:$report$$.csum("t_doanh_thu"),t_sl_nhap:$report$$.csum("t_sl_nhap"),t_tien_tl:$report$$.csum("t_tien_tl"),t_tien_thue_tl:$report$$.csum("t_tien_thue_tl"), t_tien_nhap:$report$$.csum("t_tien_nhap"),t_doanh_thu_thuan:$report$$.csum("t_doanh_thu_thuan"),tien_evoucher:$report$$.csum("tien_evoucher"),tien_thu:$report$$.csum("tien_thu"),tien_thu2:$report$$.csum("tien_thu2"),t_tien_thu:$report$$.csum("t_tien_thu"),phai_tra:$report$$.csum("phai_tra"),t_tien_paymentByPoints:$report$$.csum("tien_paymentByPoints"),t_lai:$report$$.csum("t_lai"),bold:!0};$thanh_toan$$.forEach($pt$$=>{$pt$$.tong_cong=$tong_cong$$[$pt$$.ma]=$report$$.csum($pt$$.ma)});$report$$.push($tong_cong$$); $report$$.forEach($r$$=>{$r$$.t_tien_phai_tl=$r$$.t_tien_tl+$r$$.t_tien_thue_tl});$callback$jscomp$0$$(null,{data:$report$$,thanh_toan:$thanh_toan$$.filter($t$$=>$t$$.tong_cong)})})})})})})};