flexbiz-server
Version:
Flexible Server
16 lines (15 loc) • 7.19 kB
JavaScript
const ptthanhtoan=global.getModel("ptthanhtoan"),pbl=global.getModel("pbl"),so1=global.getModel("so1"),hd2=global.getModel("hd2"),dmvt=global.getModel("dmvt"),dmtt=global.getModel("dmtt"),customer=global.getModel("customer"),group=global.getModel("group"),dmkho=global.getModel("dmkho"),dmnvt=global.getModel("dmnvt"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),dmbp=global.getModel("dmbp"),dmban=global.getModel("dmban"),dmhd=global.getModel("contract"),dmnv=global.getModel("dmnv"),User=
global.getModel("user"),async=require("async"),underscore=require("underscore"),controller=require("../../controllers/controllerRPT"),moment=require("moment"),dtbanletheosp=require("../../libs/dtbanletheosp");
module.exports=function($router$$){new controller($router$$,"ctbanle",async function($req$$,$callback$$){const $condition$$=$req$$.query;if(!$condition$$.tu_ngay||!$condition$$.den_ngay)return $callback$$("B\u00e1o c\u00e1o n\u00e0y y\u00eau c\u1ea7u c\u00e1c tham s\u1ed1:tu_ngay,den_ngay");let $rs$$=await dtbanletheosp($condition$$);$rs$$.forEach($r$$=>{$r$$.nxt==1?($r$$.tien_tl=0-$r$$.tien_hang_ct,$r$$.tien_tl_nt=0-$r$$.tien_hang_ct_nt,$r$$.tien_ck_tl=0-$r$$.tien_ck,$r$$.tien_ck_tl_nt=0-$r$$.tien_ck_nt,
$r$$.tien_thue_tl=0-$r$$.tien_thue,$r$$.tien_thue_tl_nt=0-$r$$.tien_thue_nt,$r$$.tien_tl_net=$r$$.tien_tl-$r$$.tien_ck_tl+$r$$.tien_thue_tl,$r$$.tien_tl_net_nt=$r$$.tien_tl_nt-$r$$.tien_ck_tl_nt+$r$$.tien_thue_tl_nt,$r$$.tien_hoa_hong_tl=0-$r$$.tien_hoa_hong,$r$$.tien_hoa_hong_gt_tl=0-$r$$.tien_hoa_hong_gt,$r$$.tien_hoa_hong_ctv_tl=0-$r$$.tien_hoa_hong_ctv,$r$$.tien_hoa_hong_ql_tl=0-$r$$.tien_hoa_hong_ql,$r$$.tien_hang_nt=0,$r$$.tien_hang=0,$r$$.tien_hang_ct_nt=0,$r$$.tien_hang_ct=0,$r$$.tien_ck=
0,$r$$.tien_ck_nt=0,$r$$.tien=0,$r$$.tien_nt=0,$r$$.tien_thue=0,$r$$.tien_thue_nt=0,$r$$.tien_xuat_tmp=0,$r$$.sl_xuat=0,$r$$.tien_hoa_hong=0,$r$$.tien_hoa_hong_gt=0,$r$$.tien_hoa_hong_ctv=0,$r$$.tien_hoa_hong_ql=0):($r$$.tien_tl=0,$r$$.tien_tl_nt=0,$r$$.tien_ck_tl=0,$r$$.tien_ck_tl_nt=0,$r$$.tien_thue_tl=0,$r$$.tien_thue_tl_nt=0,$r$$.tien_tl_net=0,$r$$.tien_tl_net_nt=0,$r$$.tien_hoa_hong_tl=0,$r$$.tien_hoa_hong_gt_tl=0,$r$$.tien_hoa_hong_ctv_tl=0,$r$$.tien_hoa_hong_ql_tl=0);$r$$.von=($r$$.tien_xuat||
0)-($r$$.tien_nhap||0);$r$$.lai=$r$$.tien_hang_ct-$r$$.tien_ck-($r$$.tien_tl-$r$$.tien_ck_tl)-$r$$.von});(new Promise(($resolve$$,$reject$$)=>{async.series({ten_vt:$callback$$=>{$rs$$.joinModel2($condition$$.id_app,dmvt,{where:"ma_vt",fields:["ten_vt","ma_nvt","ma_lvt","ma_ncc","ma_vt2"]},()=>{$callback$$()})},tt1:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_tt1).joinModel2($condition$$.id_app,dmtt,{where:$item$$=>({ma_vt:$item$$.ma_vt,ma_tt:$item$$.ma_tt1,loai_tt:"1"}),fields:{barcode:"ma_tt2"}},()=>
{$callback$$()})},tt2:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_tt2).joinModel2($condition$$.id_app,dmtt,{where:$item$$=>({ma_vt:$item$$.ma_vt,ma_tt:$item$$.ma_tt2,loai_tt:"2"}),fields:{barcode:"ma_tt2"}},()=>{$callback$$()})},tt3:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_tt3).joinModel2($condition$$.id_app,dmtt,{where:$item$$=>({ma_vt:$item$$.ma_vt,ma_tt:$item$$.ma_tt3,loai_tt:"3"}),fields:{barcode:"ma_tt2"}},()=>{$callback$$()})},ban:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_ban).joinModel2($condition$$.id_app,
dmban,{where:"ma_ban",fields:["ten_ban","kenh_ban_hang","nh_ban","loai_ban"]},()=>{$callback$$()})},pbl:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_ct==="PBL").joinModel2($condition$$.id_app,pbl,{where:{id_ct:"_id"},fields:["pt_thanh_toan","pt_thanh_toan2"]},()=>{$callback$$()})},so1:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_ct==="SO1").joinModel2($condition$$.id_app,so1,{where:{id_ct:"_id"},fields:["pt_thanh_toan","pt_thanh_toan2"]},()=>{$callback$$()})},hd2:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_ct===
"HD2").joinModel2($condition$$.id_app,hd2,{where:{id_ct:"_id"},fields:["pt_thanh_toan"]},()=>{$callback$$()})},ten_kho:$callback$$=>{$rs$$.joinModel2($condition$$.id_app,dmkho,{where:"ma_kho",fields:"ten_kho"},()=>{$callback$$()})},ten_kh:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_kh).joinModel2($condition$$.id_app,customer,{where:"ma_kh",fields:["ten_kh","nh_kh"]},()=>{$callback$$()})},dmdt:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_dt).joinModel2($condition$$.id_app,dmdt,{where:"ma_dt",fields:"ten_dt"},
()=>{$callback$$()})},dmhd:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_hd).joinModel2($condition$$.id_app,dmhd,{where:{ma_hd:"so_hd"},fields:"ten_hd"},()=>{$callback$$()})},dmbp:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_bp).joinModel2($condition$$.id_app,dmbp,{where:"ma_bp",fields:"ten_bp"},()=>{$callback$$()})},dmphi:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_phi).joinModel2($condition$$.id_app,dmphi,{where:"ma_phi",fields:"ten_phi"},()=>{$callback$$()})},dmnv:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_nv).joinModel2($condition$$.id_app,
dmnv,{where:"ma_nv",fields:"ten_nv"},()=>{$callback$$()})},user:$callback$$=>{$rs$$.joinModel2(null,User,{where:{user_created:"email"},fields:[{user_name:"name"}]},()=>{$callback$$()})},cashier:$callback$$=>{$rs$$.filter($r$$=>$r$$.cashier).joinModel2(null,User,{where:{cashier:"email"},fields:[{cashier_name:"name"}]},()=>{$callback$$()})}},($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resolve$$($rs$$)})})).then(()=>new Promise(($resolve$$,$reject$$)=>{async.series({pt_thanh_toan:$callback$$=>{$rs$$.filter($r$$=>
$r$$.pt_thanh_toan).joinModel2($condition$$.id_app,ptthanhtoan,{where:{pt_thanh_toan:"_id"},fields:{ten_pt_thanh_toan:"ten"}},()=>{$callback$$()})},pt_thanh_toan2:$callback$$=>{$rs$$.filter($r$$=>$r$$.pt_thanh_toan2).joinModel2($condition$$.id_app,ptthanhtoan,{where:{pt_thanh_toan2:"_id"},fields:{ten_pt_thanh_toan2:"ten"}},()=>{$callback$$()})},nh_vt:$callback$$=>{$rs$$.joinModel2($condition$$.id_app,dmnvt,{where:{ma_nvt:"_id"},fields:"ten_nvt"},()=>{$callback$$()})},nh_kh:$callback$$=>{$rs$$.filter($r$$=>
$r$$.nh_kh).joinModel2($condition$$.id_app,group,{where:{nh_kh:"_id"},fields:[{ten_nh_kh:"group_name"}]},()=>{$callback$$()})},nha_cc:$callback$$=>{$rs$$.filter($r$$=>$r$$.ma_ncc).joinModel2($condition$$.id_app,customer,{where:{ma_ncc:"ma_kh"},fields:[{ten_ncc:"ten_kh"}]},()=>{$callback$$()})}},($e$$,$rs$$)=>{if($e$$)return $reject$$($e$$);$resolve$$($rs$$)})})).then(()=>{$rs$$.forEach(function($r$$){$r$$.barcode=$r$$.barcode||$r$$.ma_vt2;$r$$.lai=$r$$.tien-$r$$.tien_xuat-($r$$.tien_tl-$r$$.tien_nhap);
$r$$.bold=!1});const $report$$=underscore.sortBy($rs$$,function($r$$){return moment($r$$.ngay_ct).format("YYYY-MM-DD")+$r$$.so_ct+$r$$.ma_vt});$report$$.push({ten_vt:"T\u1ed5ng c\u1ed9ng",sl_xuat:$report$$.csum("sl_xuat"),sl_xuat_qd:$report$$.csum("sl_xuat_qd"),tien_xuat:$report$$.csum("tien_xuat"),tien_hang_ct:$report$$.csum("tien_hang_ct"),tien_ck:$report$$.csum("tien_ck"),tien_thue:$report$$.csum("tien_thue"),tien:$report$$.csum("tien"),sl_nhap:$report$$.csum("sl_nhap"),sl_nhap_qd:$report$$.csum("sl_nhap_qd"),
tien_nhap:$report$$.csum("tien_nhap"),tien_tl:$report$$.csum("tien_tl"),tien_ck_tl:$report$$.csum("tien_ck_tl"),tien_thue_tl:$report$$.csum("tien_thue_tl"),tien_tl_net:$report$$.csum("tien_tl_net"),von:$report$$.csum("von"),lai:$report$$.csum("lai"),bold:!0});$callback$$(null,$report$$)}).catch($e$$=>{$callback$$($e$$)})})};