flexbiz-server
Version:
Flexible Server
10 lines (9 loc) • 4.33 kB
JavaScript
'use strict';const databanle=require("../../libs/databanle"),dmkh=global.getModel("customer"),introducer=global.getModel("introducer"),user=global.getModel("user"),async=require("async"),controller=require("../../controllers/controllerRPT");
module.exports=function($router$$){new controller($router$$,"tkbanhangtheogioithieu",async($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};$query_req$$.ngay_ct={$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay};$condition$$.ma_dvcs&&($query_req$$.ma_dvcs=$condition$$.ma_dvcs);
var $_query_intro_customers$$={id_app:$condition$$.id_app};$condition$$.introducer&&($_query_intro_customers$$.be_introduced_by=$condition$$.introducer);$condition$$.ma_kh&&($_query_intro_customers$$.be_introduced=$condition$$.ma_kh.toLowerCase());$_query_intro_customers$$=(await introducer.find($_query_intro_customers$$,{be_introduced:1,be_introduced_by:1})).filter($r$$=>$r$$.be_introduced!==$r$$.be_introduced_by).map($u$$=>$u$$.be_introduced.toUpperCase());$query_req$$.ma_kh={$in:$_query_intro_customers$$};
$condition$$.ma_kho&&($query_req$$.ma_kho=$condition$$.ma_kho);$condition$$.ma_ct&&($query_req$$.ma_ct=$condition$$.ma_ct);$query_req$$.show_bonus_points=!0;databanle($query_req$$,function($error$jscomp$2$$,$rs$$){if($error$jscomp$2$$)return $callback$jscomp$0$$($error$jscomp$2$$);async.mapSeries($rs$$,function($r$$,$callback$$){$r$$.t_sl_xuat=$r$$.details.csum("sl_xuat");$r$$.t_tien_hang=$r$$.details.csum("tien_hang");$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_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"),$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);$r$$.t_so_bill="HD7"!==$r$$.so_ct?1:0;$callback$$(null,$r$$)},function($error$jscomp$0$$,$rs$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);
$rs$$.groupBy("ma_kh",[{name:"t_so_bill",value:"t_so_bill"},{name:"t_sl_xuat",value:"t_sl_xuat"},{name:"t_tien_hang",value:"t_tien_hang"},{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:"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_nhap",value:"t_tien_nhap"},{name:"t_bonus_points",value:"bonus_points"},{name:"t_used_points",
value:"used_points"}],async($error$$,$report$$)=>{if($error$$)return $callback$jscomp$0$$($error$$);$report$$.forEach(($r$$,$i$$)=>{$r$$.stt=$i$$+1;$r$$.bold=!1;$r$$.t_doanh_thu=$r$$.t_tien-$r$$.tien_ck_hd;$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)});await $report$$.asyncJoinModel2($condition$$.id_app,dmkh,[{where:"ma_kh",fields:["ten_kh","dia_chi"]}]);await $report$$.asyncJoinModel2($condition$$.id_app,introducer,
[{where:$row$$=>({be_introduced:$row$$.ma_kh.toLowerCase()}),fields:{introducer:"be_introduced_by"}}]);await $report$$.asyncJoinModel2(null,user,[{where:{introducer:"email"},fields:{introducer_name:"name"}}]);$report$$=$report$$.filter($r$$=>$r$$.introducer_name);$report$$.push({ten_kh:"T\u1ed5ng c\u1ed9ng",t_so_bill:$report$$.csum("t_so_bill"),t_sl_xuat:$report$$.csum("t_sl_xuat"),t_tien_hang:$report$$.csum("t_tien_hang"),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"),t_tien_xuat:$report$$.csum("t_tien_xuat"),t_doanh_thu:$report$$.csum("t_doanh_thu"),t_doanh_thu_thuan:$report$$.csum("t_doanh_thu_thuan"),t_sl_nhap:$report$$.csum("t_sl_nhap"),t_tien_nhap:$report$$.csum("t_tien_nhap"),t_tien_tl:$report$$.csum("t_tien_tl"),t_lai:$report$$.csum("t_lai"),t_bonus_points:$report$$.csum("t_bonus_points"),t_used_points:$report$$.csum("t_used_points"),bold:!0});$callback$jscomp$0$$(null,$report$$)})})})})};