UNPKG

flexbiz-server

Version:

Flexible Server

8 lines (7 loc) 2.9 kB
'use strict';const async=require("async"),underscore=require("underscore"),moment=require("moment"); exports.find=function($query$$,$fn$$,$options$$){const $socai$$=global.getModel("socai");async.parallel({ps_no:function($callback$$){setImmediate(()=>{let $query_no$$={};underscore.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().exec(function($e$$,$rs$$){if($e$$)return $callback$$($e$$);async.mapSeries($rs$$,($r$$,$cb$$)=>{setImmediate(()=> {$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;$cb$$()})},()=>{$callback$$(null,$rs$$)})})})},ps_co:function($callback$$){setImmediate(()=>{let $query_co$$={};underscore.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().exec(function($e$$,$rs$$){if($e$$)return $callback$$($e$$);async.mapSeries($rs$$,($r$$,$cb$$)=>{setImmediate(()=>{$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;$cb$$()})},()=>{$callback$$(null,$rs$$)})})})}},function($e$jscomp$0$$,$rs$jscomp$0$$){if($e$jscomp$0$$)return $fn$$($e$jscomp$0$$);$e$jscomp$0$$= [...$rs$jscomp$0$$.ps_no,...$rs$jscomp$0$$.ps_co];$options$$&&$options$$.sortData&&($e$jscomp$0$$=$e$jscomp$0$$.sort(($a$$,$b$$)=>{let $a_ngay_ct$$=moment($a$$.ngay_ct).endOf("date").toDate().getTime(),$b_ngay_ct$$=moment($b$$.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&&(underscore.isArray($options$$.groupBy)&&0<$options$$.groupBy.length&&($groupBy$$=$options$$.groupBy),$groupBy$$=$groupBy$$||"id_app ma_dvcs id_ct ma_ct ma_gd ngay_ct 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 date_created date_updated".split(" ")); $e$jscomp$0$$.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$jscomp$0$$)})};