UNPKG

flexbiz-server

Version:

Flexible Server

8 lines (7 loc) 3.11 kB
const vatvao=global.getModel("vatvao"),dmtc=global.getModel("tc"),async=require("async"),underscore=require("underscore"),controller=require("../../controllers/controllerRPT"); module.exports=function($router$$){new controller($router$$,"bkvatvao",function($query_req$$,$callback$$){const $condition$$=$query_req$$.query;if(!$condition$$.tu_ngay||!$condition$$.den_ngay)return $callback$$("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);vatvao.find($query_req$$).lean().then(function($rows$$){$rows$$.forEach($r$$=>{$r$$.t_tien=$r$$.t_tien_nt*($r$$.ty_gia||1);$r$$.t_thue=$r$$.t_thue_nt*($r$$.ty_gia||1);$r$$.t_hd=$r$$.t_tien+$r$$.t_thue;$r$$.t_hd_nt=$r$$.t_tien_nt+$r$$.t_thue_nt});dmtc.find({status:!0,id_app:$condition$$.id_app}).sort({ma_tc:1}).lean().then(function($tcs$$){async.map($tcs$$,function($tc$$,$callback$$){let $vat_tc1$$=underscore.filter($rows$$, function($r$$){return $r$$.ma_tc==$tc$$.ma_tc});$vat_tc1$$=underscore.sortBy($vat_tc1$$,function($v$$){return $v$$[$sort$$]});for(var $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$$.length===0&&$vat_tc1$$.push({ma_tc:$tc$$.ma_tc,stt:1,sysorder:5,t_tien_nt:0,t_tien:0,t_thue_nt:0,t_thue:0});$vat_tc1$$.push({ma_tc:$tc$$.ma_tc,stt:$tc$$.ma_tc.toString()+ ". "+$tc$$.ten_tc,sysorder:1,bold:!0});$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");$vat_tc1$$.push({ma_tc:$tc$$.ma_tc,stt:"T\u1ed5ng c\u1ed9ng",sysorder:7,bold:!0,t_tien_nt:$stt_t_tien_nt$$,t_tien:$t_tien$$,t_thue_nt:$t_thue_nt$$,t_thue:$t_thue$$,t_hd:$t_tien$$+$t_thue$$,t_hd_nt:$stt_t_tien_nt$$+$t_thue_nt$$});$callback$$(null,$vat_tc1$$)},function($error$$,$rs$$){if($error$$)return $callback$$($error$$); let $report$$=[];$rs$$.forEach(function($rows$$){$rows$$.forEach(function($r$$){$report$$.push($r$$)})});$report$$=underscore.sortBy($report$$,function($r$$){return $r$$.ma_tc+$r$$.sysorder.toString()+"0000000000000000".substring(0,16-$r$$.stt.toString().length)+$r$$.stt.toString()});$callback$$(null,$report$$)})}).catch($error$$=>{$callback$$($error$$)})}).catch($e$$=>{$callback$$($e$$)})},{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&&$r$$.sysorder==5&&($app$$.tong_tien_nt+=$r$$.t_tien_nt,$app$$.tong_tien+=$r$$.t_tien);$r$$.t_thue_nt&&$r$$.sysorder==5&&($app$$.tong_thue_nt+=$r$$.t_thue_nt,$app$$.tong_thue+=$r$$.t_thue)});$next$$()}})};