flexbiz-server
Version:
Flexible Server
8 lines (7 loc) • 2.88 kB
JavaScript
const async=require("async"),_=require("lodash"),moment=require("moment");
exports.find=function($query$$,$fn$$,$options$$={model:"socai"}){const $socai$$=global.getModel($options$$.model||"socai");$options$$.model&&$options$$.model!=="socai"||!$options$$.queryByDateHour||!$query$$.ngay_ct||($query$$.ngay_ct_full=$query$$.ngay_ct,delete $query$$.ngay_ct);async.parallel({ps_no:function($callback$$){setImmediate(async()=>{let $query_no$$={};_.extend($query_no$$,$query$$);$query_no$$.tk&&($query_no$$.tk_no=$query_no$$.tk,delete $query_no$$.tk);$query_no$$.ma_kh&&($query_no$$.ma_kh_no=
$query_no$$.ma_kh,delete $query_no$$.ma_kh);$socai$$.find($query_no$$).lean().then(function($rs$$){for(let $r$$ of $rs$$)$r$$.tk=$r$$.tk_no,$r$$.tk_du=$r$$.tk_co,$r$$.ma_kh=$r$$.ma_kh_no,!$r$$.ma_kh&&$r$$.ma_kh_co&&($r$$.ma_kh=$r$$.ma_kh_co),$r$$.ps_no_nt=$r$$.tien_nt,$r$$.ps_no=Math.roundBy($r$$.tien,0),$r$$.ps_co_nt=0,$r$$.ps_co=0;$callback$$(null,$rs$$)}).catch($e$$=>{$callback$$($e$$)})})},ps_co:function($callback$$){setImmediate(()=>{let $query_co$$={};_.extend($query_co$$,$query$$);$query_co$$.tk&&
($query_co$$.tk_co=$query_co$$.tk,delete $query_co$$.tk);$query_co$$.ma_kh&&($query_co$$.ma_kh_co=$query_co$$.ma_kh,delete $query_co$$.ma_kh);$socai$$.find($query_co$$).lean().then(function($rs$$){for(let $r$$ of $rs$$)$r$$.tk=$r$$.tk_co,$r$$.tk_du=$r$$.tk_no,$r$$.ma_kh=$r$$.ma_kh_co,!$r$$.ma_kh&&$r$$.ma_kh_no&&($r$$.ma_kh=$r$$.ma_kh_no),$r$$.ps_co_nt=$r$$.tien_nt,$r$$.ps_co=Math.roundBy($r$$.tien,0),$r$$.ps_no_nt=0,$r$$.ps_no=0;$callback$$(null,$rs$$)}).catch($e$$=>{$callback$$($e$$)})})}},function($e$$,
$rs$$){if($e$$)return $fn$$($e$$);$e$$=[...$rs$$.ps_no,...$rs$$.ps_co];$options$$&&$options$$.sortData&&($e$$=$e$$.sort(($a$$,$b$$)=>{let $a_ngay_ct$$=moment($a$$.ngay_ct_full||$a$$.ngay_ct).endOf("date").toDate().getTime(),$b_ngay_ct$$=moment($b$$.ngay_ct_full||$a$$.ngay_ct).endOf("date").toDate().getTime();return $a_ngay_ct$$<$b_ngay_ct$$?-1:$a_ngay_ct$$>$b_ngay_ct$$?1:$a$$.so_ct<$b$$.so_ct?-1:$a$$.so_ct>$b$$.so_ct?1:$a$$.id_ct<$b$$.id_ct?-1:$a$$.id_ct>$b$$.id_ct?1:$a$$.nh_dk<$b$$.nh_dk?-1:$a$$.nh_dk>
$b$$.nh_dk||$a$$.ps_no<$b$$.ps_no?1:$a$$.ps_no>$b$$.ps_no||$a$$.ps_co<$b$$.ps_co?-1:$a$$.ps_co>$b$$.ps_co?1:0}));if($options$$&&$options$$.groupBy){let $groupBy$$;$options$$.groupBy&&(_.isArray($options$$.groupBy)&&$options$$.groupBy.length>0&&($groupBy$$=$options$$.groupBy),$groupBy$$=$groupBy$$||"id_app ma_dvcs id_ct ma_ct listinfo_code ma_gd ngay_ct ngay_ct_full so_ct ngay_hd so_hd tk tk_du ma_kh ong_ba ma_nt ty_gia dien_giai ma_bp id_lenhsx ma_phi ma_hd ma_dt ma_nv ma_sp ma_cp ma_kho ma_vt ma_kenh ma_td1 ma_td2 ma_td3 ma_td4 ma_td5 ma_td6 ma_td7 ma_td8 ma_td9 gio ngay thang quy nam".split(" "));
$e$$.groupBy($groupBy$$,["ps_no","ps_co","ps_no_nt","ps_co_nt"],($e$$,$rs$$)=>{if($e$$)return $fn$$($e$$);$fn$$(null,$rs$$)})}else $fn$$(null,$e$$)})};