UNPKG

flexbiz-server

Version:

Flexible Server

8 lines (7 loc) 3.19 kB
'use strict';const vatra=global.getModel("vatra"),dmvat=global.getModel("vat"),async=require("async"),underscore=require("underscore"),controller=require("../../controllers/controllerRPT"); module.exports=function($router$$){new controller($router$$,"bkvatra",function($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 c\u1ea7n c\u00e1c tham s\u1ed1 sau:id_app,tu_ngay,den_ngay");$query_req$$={id_app:$condition$$.id_app,ngay_ct:{$gte:$condition$$.tu_ngay,$lte:$condition$$.den_ngay}};$condition$$.ma_dvcs&&($query_req$$.ma_dvcs=$condition$$.ma_dvcs);$condition$$.ma_thue&& ($query_req$$.ma_thue=$condition$$.ma_thue);let $sort$$="ngay_hd";$condition$$.sort&&($sort$$=$condition$$.sort);vatra.find($query_req$$).lean().exec(function($error$jscomp$2$$,$rows$$){if($error$jscomp$2$$)return $callback$jscomp$0$$($error$jscomp$2$$);dmvat.find({status:!0,id_app:$condition$$.id_app}).sort({ten_thue:1}).lean().exec(function($error$jscomp$0$$,$tcs$$){if($error$jscomp$0$$)return $callback$jscomp$0$$($error$jscomp$0$$);async.mapSeries($tcs$$,function($tc$$,$callback$$){let $vat_tc1$$= underscore.filter($rows$$,function($r$$){return $r$$.ma_thue==$tc$$.ma_thue});$vat_tc1$$=underscore.sortBy($vat_tc1$$,function($v$$){return $v$$[$sort$$]});for($stt_t_tien_nt$$=0;$stt_t_tien_nt$$<$vat_tc1$$.length;$stt_t_tien_nt$$++)$vat_tc1$$[$stt_t_tien_nt$$].sysorder=5,$vat_tc1$$[$stt_t_tien_nt$$].bold=!1,$vat_tc1$$[$stt_t_tien_nt$$].stt=$stt_t_tien_nt$$+1,$vat_tc1$$[$stt_t_tien_nt$$].ten_thue=$tc$$.ten_thue;0===$vat_tc1$$.length&&$vat_tc1$$.push({ma_thue:$tc$$.ma_thue,ten_thue:$tc$$.ten_thue, stt:1,sysorder:5,t_tien_nt:0,t_tien:0,t_thue_nt:0,t_thue:0});$vat_tc1$$.push({ma_thue:$tc$$.ma_thue,ten_thue:$tc$$.ten_thue,stt:$tc$$.ten_thue,sysorder:1,bold:!0});var $stt_t_tien_nt$$=$vat_tc1$$.csum("t_tien_nt");const $t_tien$$=$vat_tc1$$.csum("t_tien"),$t_thue_nt$$=$vat_tc1$$.csum("t_thue_nt"),$t_thue$$=$vat_tc1$$.csum("t_thue"),$total$$={ma_thue:$tc$$.ma_thue,ten_thue:$tc$$.ten_thue,stt:"T\u1ed5ng c\u1ed9ng",sysorder:7,bold:!0};$total$$.t_tien_nt=$stt_t_tien_nt$$;$total$$.t_tien=$t_tien$$;$total$$.t_thue_nt= $t_thue_nt$$;$total$$.t_thue=$t_thue$$;$vat_tc1$$.push($total$$);$callback$$(null,$vat_tc1$$)},function($error$$,$rs$$){if($error$$)return $callback$jscomp$0$$($error$$);let $report$$=[];$rs$$.forEach(function($rows$$){$rows$$.forEach(function($r$$){$report$$.push($r$$)})});$report$$=underscore.sortBy($report$$,function($r$$){return $r$$.ten_thue+$r$$.sysorder.toString()+"0000000000000000".substring(0,16-$r$$.stt.toString().length)+$r$$.stt.toString()});$callback$jscomp$0$$(null,$report$$)})})})}, {onExport:function($app$$,$next$$){$app$$.nam=$app$$.tu_ngay.getFullYear();$app$$.thang=$app$$.tu_ngay.getMonth()+1;$app$$.tong_tien_nt=0;$app$$.tong_thue_nt=0;$app$$.tong_tien=0;$app$$.tong_thue=0;$app$$.detail.forEach(function($r$$){$r$$.t_tien_nt&&5==$r$$.sysorder&&($app$$.tong_tien_nt+=$r$$.t_tien_nt,$app$$.tong_tien+=$r$$.t_tien);$r$$.t_thue_nt&&5==$r$$.sysorder&&($app$$.tong_thue_nt+=$r$$.t_thue_nt,$app$$.tong_thue+=$r$$.t_thue)});$next$$()}})};