UNPKG

flexbiz-server

Version:

Flexible Server

5 lines (4 loc) 1.75 kB
'use strict';const model=global.getModel("giaoca"),dmvt=global.getModel("dmvt"),ptthanhtoan=global.getModel("ptthanhtoan"),controller=require("../../controllers/controller"),async=require("async"); module.exports=function($router$$){(new controller($router$$,model,"giaoca",{sort:{ma_kho:1,den_ngay:-1},onView:async($user$$,$items$$,$next$$)=>{const $ptthanhtoans$$=await ptthanhtoan.find({id_app:$user$$.current_id_app}).lean();async.mapSeries($items$$,($item$$,$cb$$)=>{async.mapSeries($item$$.details,($vc$$,$cb$$)=>{($vc$$.details||[]).joinModel2($vc$$.id_app,dmvt,{where:"ma_vt",fields:"ten_vt"},()=>{$cb$$(null)})},()=>{$cb$$(null)})},()=>{$items$$.forEach($item$$=>{($item$$.details||[]).forEach($d$$=> {$d$$.ten_vt=$d$$.details.map($d2$$=>$d2$$.ten_vt).join(",");$d$$.tien_doanh_thu=$d$$.details.map($d2$$=>$d2$$.tien_hang||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});$item$$.t_doanh_thu=($item$$.details||[]).map($d$$=>$d$$.tien_doanh_thu||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$item$$.ptthanhtoans=[...$ptthanhtoans$$];$item$$.ptthanhtoans.forEach($pt$$=>{$pt$$.t_tien=($item$$.details||[]).filter($d$$=>$d$$.pt_thanh_toan===$pt$$._id.toString()).map($d$$=>$d$$.tien_thu||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$pt$$.t_tien+= ($item$$.details||[]).filter($d$$=>$d$$.pt_thanh_toan2===$pt$$._id.toString()).map($d$$=>$d$$.tien_thu2||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});$item$$.tien_evoucher=($item$$.details||[]).map($d$$=>$d$$.tien_evoucher||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$item$$.tien_paymentByPoints=($item$$.details||[]).map($d$$=>$d$$.tien_paymentByPoints||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$item$$.tien_tra_lai=($item$$.details||[]).map($d$$=>$d$$.phai_tra||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});$next$$(null,$items$$)})}})).route()};