flexbiz-server 12.5.33 → 12.5.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,268 @@
1
- const dmvt=global.getModel("dmvt"),sokho=global.getModel("sokho"),hanmucton=global.getModel("hanmucton"),ckvtcapphat=require("./ckvtcapphat"),utils=require("./utils"),async=require("async"),_=require("lodash"),moment=require("moment");
2
- module.exports=async($condition$$,$fn$$)=>{$fn$$||=()=>{};!$condition$$.ngay&&$condition$$.den_ngay&&($condition$$.ngay=$condition$$.den_ngay);let $ma_dvcs$$=$condition$$.ma_dvcs,$ma_kho$$=$condition$$.ma_kho,$ma_vt$$=$condition$$.ma_vt;if(_.isString($ma_vt$$)&&$ma_vt$$.indexOf("[")>=0&&$ma_vt$$.indexOf("]")>0)try{$ma_vt$$=JSON.parse($ma_vt$$),$ma_vt$$.length==0&&($ma_vt$$=void 0)}catch($e$$){console.error($e$$)}$ma_vt$$&&_.isArray($ma_vt$$)&&($ma_vt$$={$in:Object.assign($ma_vt$$)});let $id_app$$=
3
- $condition$$.id_app;if(!await global.getModel("app").findOne({_id:$condition$$.id_app},{ngay_ks:1}).lean())return $fn$$("C\u00f4ng ty kh\u00f4ng t\u1ed3n t\u1ea1i");let $ngay$$=moment($condition$$.ngay).endOf("date").toDate(),$ngay_ks$$=(await global.getModel("cdvttheongay").findOne({id_app:$id_app$$,den_ngay:{$lte:moment($ngay$$).startOf("date").toDate()}},{den_ngay:1}).sort({den_ngay:-1}).lean()||{}).den_ngay;$ngay_ks$$&&=moment($ngay_ks$$).endOf("date").toDate();let $ngay_tinh_dn$$=$condition$$.tu_ngay&&
4
- new Date($condition$$.tu_ngay)<$ngay$$?moment($condition$$.tu_ngay).endOf("date").toDate():$ngay$$,$ngay_dn$$=moment($ngay_tinh_dn$$).startOf("year").toDate(),$nam$$,$cdvt$$;!$ngay_ks$$||$ngay_ks$$<$ngay_dn$$?($cdvt$$=global.getModel("cdvt"),$nam$$=$ngay_tinh_dn$$.getFullYear()):($cdvt$$=global.getModel("cdvttheongay"),$ngay_dn$$=moment($ngay_ks$$).startOf("date").add(1,"days").toDate());return new Promise(($resolve$$,$reject$$)=>{async.parallel({ckcapphat:$callback$$=>{setImmediate(()=>{ckvtcapphat($condition$$,
5
- ($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})})},dn:$callback$$=>{setImmediate(()=>{const $c_dk$$={id_app:$id_app$$};$nam$$?$c_dk$$.nam=$nam$$:(console.log("lay cdvt theo ngay khoa so",$ngay_ks$$),$c_dk$$.den_ngay=$ngay_ks$$);$ma_kho$$&&($c_dk$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($c_dk$$.ma_dvcs=$ma_dvcs$$);$ma_vt$$&&($c_dk$$.ma_vt=$ma_vt$$);$condition$$.ma_lo&&($c_dk$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($c_dk$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($c_dk$$.ma_tt1=$condition$$.ma_tt1);
6
- $condition$$.ma_tt2&&($c_dk$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($c_dk$$.ma_tt3=$condition$$.ma_tt3);$cdvt$$.find($c_dk$$).lean().then($results$$=>{$callback$$(null,$results$$)}).catch($error$$=>{$callback$$($error$$)})})},hanmucton:$callback$$=>{setImmediate(()=>{const $c_dk$$={id_app:$id_app$$};$ma_kho$$&&($c_dk$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($c_dk$$.ma_dvcs=$ma_dvcs$$);$ma_vt$$&&($c_dk$$.ma_vt=$ma_vt$$);$condition$$.ma_lo&&($c_dk$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&
7
- ($c_dk$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($c_dk$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($c_dk$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($c_dk$$.ma_tt3=$condition$$.ma_tt3);hanmucton.find($c_dk$$).lean().then($results$$=>{$callback$$(null,$results$$)}).catch($error$$=>{$callback$$($error$$)})})},ps:$callback$$=>{setImmediate(()=>{const $query$$={id_app:$id_app$$,ngay_ct:{$gte:$ngay_dn$$,$lte:$ngay$$}};$ma_kho$$&&($query$$.ma_kho=$ma_kho$$);$ma_dvcs$$&&($query$$.ma_dvcs=
8
- $ma_dvcs$$);$ma_vt$$&&($query$$.ma_vt=$ma_vt$$);$condition$$.ma_lo&&($query$$.ma_lo=$condition$$.ma_lo);$condition$$.han_sd&&($query$$.han_sd=$condition$$.han_sd);$condition$$.ma_tt1&&($query$$.ma_tt1=$condition$$.ma_tt1);$condition$$.ma_tt2&&($query$$.ma_tt2=$condition$$.ma_tt2);$condition$$.ma_tt3&&($query$$.ma_tt3=$condition$$.ma_tt3);$condition$$.id_ct&&($query$$.id_ct={$ne:$condition$$.id_ct});sokho.find($query$$,{ma_vt:1,ma_kho:1,ma_tt1:1,ma_tt2:1,ma_tt3:1,sl_nhap:1,sl_xuat:1,sl_nhap_qd:1,sl_xuat_qd:1,
9
- tien_nhap:1,tien_xuat:1}).lean().then($pss$$=>{$pss$$=$pss$$.map($ps$$=>{$ps$$.sl_nhap=utils.round($ps$$.sl_nhap_qd,4);$ps$$.sl_xuat=utils.round($ps$$.sl_xuat_qd,4);return $ps$$});$callback$$(null,$pss$$)}).catch($error$$=>{$callback$$($error$$)})})},ton_kho_mac_dinh:$callback$$=>{setImmediate(()=>{let $query$$={id_app:$id_app$$,ton_kho_mac_dinh:{$nin:[null,void 0,0]}};$ma_vt$$&&($query$$.ma_vt=$ma_vt$$);dmvt.find($query$$,{ma_vt:1,ton_kho_mac_dinh:1}).lean().then($rs$$=>{$callback$$(null,$rs$$)}).catch($error$$=>
10
- {console.error($error$$)})})}},($ckcapphat_error$$,$data_results$$)=>{if($ckcapphat_error$$)return $fn$$($ckcapphat_error$$),$reject$$(Error($ckcapphat_error$$));$ckcapphat_error$$=$data_results$$.ckcapphat.map($c$$=>{$c$$.ton00_capphat=$c$$.ton00;$c$$.du00_capphat=$c$$.du00;$c$$.ton00=0;$c$$.du00=0;return $c$$});$data_results$$=$data_results$$.dn.concat($data_results$$.ps).concat($ckcapphat_error$$).concat($data_results$$.ton_kho_mac_dinh).concat($data_results$$.hanmucton);($ckcapphat_error$$=$condition$$.groupBy||
11
- $condition$$.groupby)||($ckcapphat_error$$=["ma_vt"]);if(_.isString($ckcapphat_error$$))if($ckcapphat_error$$.indexOf("[")>=0)try{$ckcapphat_error$$=JSON.parse($ckcapphat_error$$)}catch($e$$){console.error($e$$)}else $ckcapphat_error$$=$ckcapphat_error$$.split(",");$data_results$$.groupBy($ckcapphat_error$$,"sl_nhap sl_xuat ton00 du00 ton00_capphat du00_capphat tien_nhap tien_xuat ton_kho_mac_dinh ton_toi_thieu ton_toi_da".split(" "),($e$$,$groups$$)=>{if($e$$)return $fn$$($e$$),$reject$$(Error($e$$));
12
- setImmediate(()=>{for(let $r$$ of $groups$$)$r$$.ton00=utils.round($r$$.ton00+$r$$.sl_nhap-$r$$.sl_xuat,4),$r$$.du00=Math.roundBy($r$$.du00,0)+Math.roundBy($r$$.tien_nhap,0)-Math.roundBy($r$$.tien_xuat,0),$r$$.sl_nhap=0,$r$$.sl_xuat=0,$r$$.tien_nhap=0,$r$$.tien_xuat=0,$r$$.ton=$r$$.ton00-($r$$.ton00_capphat>0?$r$$.ton00_capphat:0),$r$$.du=$r$$.du00-($r$$.du00_capphat>0?$r$$.du00_capphat:0);$fn$$(null,$groups$$);$resolve$$($groups$$)})})})})};
1
+ const dmvt = global.getModel('dmvt');
2
+ const sokho = global.getModel('sokho');
3
+ const hanmucton = global.getModel('hanmucton');
4
+ const ckvtcapphat = require('./ckvtcapphat');
5
+ const utils = require('./utils');
6
+ const async = require('async');
7
+ const _ = require("lodash");
8
+ const moment = require("moment");
9
+ module.exports = async (condition, fn)=> {
10
+ if(!fn) fn = ()=>{}
11
+ //kiem tra dieu kien
12
+ if (!condition.ngay && condition.den_ngay) {
13
+ condition.ngay = condition.den_ngay;
14
+ }
15
+ //lay dieu kien
16
+ ////don vi co so
17
+ let ma_dvcs = condition.ma_dvcs;
18
+ /////kho
19
+ let ma_kho = condition.ma_kho;
20
+ ////vat tu
21
+ let ma_vt = condition.ma_vt;
22
+ //
23
+
24
+ if(_.isString(ma_vt) && ma_vt.indexOf('[') >= 0 && ma_vt.indexOf(']') > 0 ){
25
+ try {
26
+ ma_vt = JSON.parse(ma_vt);
27
+ if(ma_vt.length==0) ma_vt = undefined;
28
+
29
+ } catch (e) {console.error(e)}
30
+ }
31
+
32
+ if (ma_vt && _.isArray(ma_vt)) {
33
+ let _ma_vt = Object.assign(ma_vt);
34
+ ma_vt = {$in:_ma_vt};
35
+ }
36
+
37
+ let id_app = condition.id_app;
38
+ //Xác định sổ cân đối tk và điều kiện thời gian
39
+ let app = await global.getModel("app").findOne({_id:condition.id_app},{ngay_ks:1}).lean();
40
+ if(!app) return fn("Công ty không tồn tại");
41
+ let ngay = moment(condition.ngay).endOf("date").toDate();
42
+ //let ngay_ks = moment(app.ngay_ks).endOf("date").toDate();
43
+ //lấy ngày khoá sổ gần nhất
44
+ let ngay_ks = ((await global.getModel('cdvttheongay').findOne({id_app,den_ngay:{$lte:moment(ngay).startOf("date").toDate()}},{den_ngay:1}).sort({den_ngay:-1}).lean())||{}).den_ngay;
45
+ if(ngay_ks) ngay_ks = moment(ngay_ks).endOf("date").toDate();
46
+ //let ngay_tinh_dn = moment(condition.tu_ngay || condition.ngay).startOf("date").toDate();
47
+ let ngay_tinh_dn = condition.tu_ngay && new Date(condition.tu_ngay) < ngay? moment(condition.tu_ngay).endOf("date").toDate() : ngay;
48
+ let ngay_dn = moment(ngay_tinh_dn).startOf("year").toDate();
49
+ let nam;
50
+ let cdvt;
51
+ //if(!ngay_ks || (ngay_tinh_dn<ngay_chua_ks || ngay_dn>=ngay_chua_ks)){
52
+ if(!ngay_ks || ngay_ks<ngay_dn){
53
+ cdvt = global.getModel('cdvt');
54
+ nam = ngay_tinh_dn.getFullYear();
55
+ }else{
56
+ cdvt = global.getModel('cdvttheongay');
57
+ ngay_dn = moment(ngay_ks).startOf("date").add(1,"days").toDate();
58
+ }
59
+ //
60
+ return new Promise((resolve,reject)=>{
61
+ async.parallel({
62
+ //capphat
63
+ ckcapphat:(callback)=>{
64
+ setImmediate(()=>{
65
+ ckvtcapphat(condition,(e,rs)=>{
66
+ callback(e,rs);
67
+ })
68
+ })
69
+
70
+ },
71
+ //dau nam
72
+ dn: (callback) => {
73
+ setImmediate(()=>{
74
+ const c_dk = {id_app};
75
+ if(nam){
76
+ c_dk.nam = nam;
77
+ }else{
78
+ console.log("lay cdvt theo ngay khoa so",ngay_ks);
79
+ c_dk.den_ngay = ngay_ks;
80
+ }
81
+ if (ma_kho) {
82
+ c_dk.ma_kho = ma_kho;
83
+ }
84
+ if (ma_dvcs) {
85
+ c_dk.ma_dvcs = ma_dvcs;
86
+ }
87
+ if (ma_vt) {
88
+ c_dk.ma_vt = ma_vt;
89
+ }
90
+ if (condition.ma_lo) c_dk.ma_lo = condition.ma_lo;
91
+ if (condition.han_sd) c_dk.han_sd = condition.han_sd;
92
+ if (condition.ma_tt1) c_dk.ma_tt1 = condition.ma_tt1;
93
+ if (condition.ma_tt2) c_dk.ma_tt2 = condition.ma_tt2;
94
+ if (condition.ma_tt3) c_dk.ma_tt3 = condition.ma_tt3;
95
+ //Tìm
96
+ cdvt.find(c_dk).lean().then((results)=> {
97
+ callback(null, results);
98
+ }).catch(error=>{
99
+ callback(error);
100
+ })
101
+ })
102
+ },
103
+ //han muc ton
104
+ hanmucton: (callback) => {
105
+ setImmediate(()=>{
106
+ const c_dk = {
107
+ id_app: id_app
108
+ };
109
+ if (ma_kho) {
110
+ c_dk.ma_kho = ma_kho;
111
+ }
112
+ if (ma_dvcs) {
113
+ c_dk.ma_dvcs = ma_dvcs;
114
+ }
115
+ if (ma_vt) {
116
+ c_dk.ma_vt = ma_vt;
117
+ }
118
+ if (condition.ma_lo)
119
+ c_dk.ma_lo = condition.ma_lo;
120
+ if (condition.han_sd)
121
+ c_dk.han_sd = condition.han_sd;
122
+
123
+ if (condition.ma_tt1)
124
+ c_dk.ma_tt1 = condition.ma_tt1;
125
+ if (condition.ma_tt2)
126
+ c_dk.ma_tt2 = condition.ma_tt2;
127
+ if (condition.ma_tt3)
128
+ c_dk.ma_tt3 = condition.ma_tt3;
129
+ hanmucton.find(c_dk).lean().then((results)=> {
130
+ callback(null, results);
131
+ }).catch(error=>{
132
+ callback(error);
133
+ })
134
+ })
135
+ },
136
+ //phat sinh
137
+ ps: (callback) => {
138
+ setImmediate(()=>{
139
+ const query = {
140
+ id_app: id_app,
141
+ ngay_ct: {
142
+ $gte: ngay_dn,
143
+ $lte: ngay
144
+ }
145
+ };
146
+ if (ma_kho) {
147
+ query.ma_kho = ma_kho;
148
+ }
149
+ if (ma_dvcs) {
150
+ query.ma_dvcs = ma_dvcs;
151
+ }
152
+ if (ma_vt) {
153
+ query.ma_vt = ma_vt;
154
+ }
155
+ if (condition.ma_lo)
156
+ query.ma_lo = condition.ma_lo;
157
+ if (condition.han_sd)
158
+ query.han_sd = condition.han_sd;
159
+
160
+ if (condition.ma_tt1)
161
+ query.ma_tt1 = condition.ma_tt1;
162
+ if (condition.ma_tt2)
163
+ query.ma_tt2 = condition.ma_tt2;
164
+ if (condition.ma_tt3)
165
+ query.ma_tt3 = condition.ma_tt3;
166
+
167
+ if(condition.id_ct){
168
+ query.id_ct = {$ne:condition.id_ct}
169
+ }
170
+ //Tìm
171
+ sokho.find(query,{ma_vt:1,ma_kho:1,ma_tt1:1,ma_tt2:1,ma_tt3:1,sl_nhap:1,sl_xuat:1,sl_nhap_qd:1,sl_xuat_qd:1,tien_nhap:1,tien_xuat:1}).inTxn().lean().then((pss)=>{
172
+ //lay theo so luong quy doi
173
+ pss = pss.map(ps=>{
174
+ ps.sl_nhap = utils.round(ps.sl_nhap_qd,4);
175
+ ps.sl_xuat =utils.round(ps.sl_xuat_qd,4);
176
+ return ps;
177
+ })
178
+ callback(null, pss);
179
+ }).catch(error=>{
180
+ callback(error);
181
+ })
182
+ })
183
+ },
184
+ ton_kho_mac_dinh:(callback)=>{
185
+ setImmediate(()=>{
186
+ let query = {
187
+ id_app: id_app,
188
+ ton_kho_mac_dinh:{$nin:[null,undefined,0]}
189
+ };
190
+ if (ma_vt) {
191
+ query.ma_vt = ma_vt;
192
+ }
193
+ dmvt.find(query,{ma_vt:1,ton_kho_mac_dinh:1}).lean().then((rs)=>{
194
+ callback(null, rs);
195
+ }).catch(error=>{
196
+ console.error(error);
197
+ })
198
+ })
199
+
200
+ }
201
+ }, (error, results) => {
202
+ if (error) {
203
+ fn(error);
204
+ return reject(new Error(error));
205
+ }
206
+ let ckcapphat = results.ckcapphat.map(c=>{
207
+ c.ton00_capphat = c.ton00;
208
+ c.du00_capphat = c.du00;
209
+
210
+ c.ton00=0;
211
+ c.du00=0;
212
+
213
+ return c;
214
+ })
215
+ let data = results.dn.concat(results.ps).concat(ckcapphat).concat(results.ton_kho_mac_dinh).concat(results.hanmucton);
216
+
217
+ let groupBy = condition.groupBy || condition.groupby;
218
+ if (!groupBy) groupBy = ['ma_vt'];
219
+ if(_.isString(groupBy)){
220
+ if (groupBy.indexOf('[') >= 0) {
221
+ try {
222
+ groupBy = JSON.parse(groupBy);
223
+ } catch (e) {console.error(e)}
224
+ }else{
225
+ groupBy = groupBy.split(",");
226
+ }
227
+ }
228
+
229
+ let sumFields = [
230
+ 'sl_nhap',
231
+ 'sl_xuat',
232
+ 'ton00',
233
+ 'du00',
234
+ 'ton00_capphat',
235
+ 'du00_capphat',
236
+ 'tien_nhap',
237
+ 'tien_xuat',
238
+ 'ton_kho_mac_dinh',
239
+ 'ton_toi_thieu',
240
+ 'ton_toi_da'
241
+ ];
242
+ data.groupBy(groupBy, sumFields, (e, groups) => {
243
+ if (e){
244
+ fn(e);
245
+ return reject(new Error(e));
246
+ }
247
+ setImmediate(()=>{
248
+ for (let r of groups) {
249
+ r.ton00 = utils.round(r.ton00 + r.sl_nhap - r.sl_xuat, 4);
250
+ r.du00 = Math.roundBy(r.du00, 0) + Math.roundBy(r.tien_nhap, 0) - Math.roundBy(r.tien_xuat, 0);
251
+ r.sl_nhap = 0;
252
+ r.sl_xuat = 0;
253
+ r.tien_nhap = 0;
254
+ r.tien_xuat = 0;
255
+ r.ton = r.ton00 - (r.ton00_capphat>0?r.ton00_capphat:0);
256
+ r.du = r.du00 - (r.du00_capphat>0?r.du00_capphat:0);
257
+
258
+ }
259
+ fn(null, groups);
260
+ resolve(groups);
261
+ })
262
+
263
+ })
264
+
265
+ });
266
+ })
267
+
268
+ };
@@ -11,5 +11,6 @@ async.mapLimit($rs$$,100,function($r$$,$callback$$){let $details$$=$r$$.details|
11
11
  ...$r$$.details_tl.map($detail$$=>{delete $detail$$._id;$detail$$={...$r$$,...$detail$$};$detail$$.ma_nv||($detail$$.ma_nv=$r$$.ma_nv);$detail$$.ma_dt||($detail$$.ma_dt=$r$$.ma_dt);$detail$$.ma_bp||($detail$$.ma_bp=$r$$.ma_bp);$detail$$.tien_hang_nt=0-$detail$$.tien_hang_nt||0;$detail$$.tien_hang=0-($detail$$.tien_hang||0);$detail$$.tien_hang_ct_nt=0-$detail$$.tien_hang_ct_nt||0;$detail$$.tien_hang_ct=0-($detail$$.tien_hang_ct||0);$detail$$.tien_ck=0-($detail$$.tien_ck||0);$detail$$.tien_ck_nt=0-
12
12
  ($detail$$.tien_ck_nt||0);$detail$$.tien_thue=0-($detail$$.tien_thue||0);$detail$$.tien_thue_nt=0-($detail$$.tien_thue_nt||0);$detail$$.tien_xuat_tmp=0-($detail$$.tien_nhap_nt||0);$detail$$.tien_xuat_nt=0-($detail$$.tien_nhap_nt||0);$detail$$.sl_xuat=0;$detail$$.tien_hoa_hong=0-$detail$$.tien_hoa_hong;$detail$$.tien_hoa_hong_gt=0-$detail$$.tien_hoa_hong_gt;$detail$$.tien_hoa_hong_ctv=0-$detail$$.tien_hoa_hong_ctv;$detail$$.tien_hoa_hong_ql=0-$detail$$.tien_hoa_hong_ql;$detail$$.nxt=1;return $detail$$})],
13
13
  delete $r$$.details_tl);$callback$$(null,$details$$)},async function($error$$,$report$$){if($error$$)return $reject$$($error$$);$report$$=$report$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]);$ma_vts$$&&($report$$=$report$$.filter($r$$=>$ma_vts$$.indexOf($r$$.ma_vt)>=0));$condition$$.id_cs&&($report$$=$report$$.filter($r$$=>$r$$.id_cs===$condition$$.id_cs));$condition$$.id_cs_ck&&($report$$=$report$$.filter($r$$=>$r$$.id_cs_ck===$condition$$.id_cs_ck));await $report$$.asyncJoinModel2($condition$$.id_app,
14
- "dmqddvt",{where:{ma_dvt:"ma_dvt",ma_vt:"ma_vt"},fields:["tu","mau","ma_dvt_goc"]});$report$$.forEach(function($r$$,$he_so_qd_i$$){$r$$.stt=$he_so_qd_i$$+1;$r$$.id_ct=$r$$._id.toString();$r$$.bold=!1;$r$$.tt=$r$$.tien=($r$$.tien_hang_ct||0)-($r$$.tien_ck||0)+($r$$.tien_thue||0);$r$$.loi_nhuan_tmp=$r$$.tien_xuat_tmp?$r$$.tt-$r$$.tien_xuat_tmp-($r$$.tien_thue||0)-($r$$.tien_cp||0):0;$r$$.loi_nhuan=$r$$.tt-($r$$.tien_xuat||0)-($r$$.tien_thue||0)-($r$$.tien_cp||0);$r$$.t_hoa_hong=$r$$.tien_hoa_hong+$r$$.tien_hoa_hong_gt+
15
- $r$$.tien_hoa_hong_ctv+$r$$.tien_hoa_hong_ql;$r$$.mau?($he_so_qd_i$$=$r$$.tu/$r$$.mau,$r$$.sl_xuat_qd=$he_so_qd_i$$*($r$$.sl_xuat||0),$r$$.sl_nhap_qd=$he_so_qd_i$$*($r$$.sl_nhap||0)):($r$$.sl_xuat_qd=$r$$.sl_xuat||0,$r$$.sl_nhap_qd=$r$$.sl_nhap||0)});$resolve$$($report$$)})})})};
14
+ "dmqddvt",{where:{ma_dvt:"ma_dvt",ma_vt:"ma_vt"},fields:["tu","mau","ma_dvt_goc"]});$report$$.forEach(function($r$$,$he_so_qd_i$$){$r$$.stt=$he_so_qd_i$$+1;$r$$.id_ct=$r$$._id.toString();$r$$.bold=!1;$r$$.sysorder=5;$r$$.tt=$r$$.tien=($r$$.tien_hang_ct||0)-($r$$.tien_ck||0)+($r$$.tien_thue||0);$r$$.loi_nhuan_tmp=$r$$.tien_xuat_tmp?$r$$.tt-$r$$.tien_xuat_tmp-($r$$.tien_thue||0)-($r$$.tien_cp||0):0;$r$$.loi_nhuan=$r$$.tt-($r$$.tien_xuat||0)-($r$$.tien_thue||0)-($r$$.tien_cp||0);$r$$.t_hoa_hong=$r$$.tien_hoa_hong+
15
+ $r$$.tien_hoa_hong_gt+$r$$.tien_hoa_hong_ctv+$r$$.tien_hoa_hong_ql;$r$$.mau?($he_so_qd_i$$=$r$$.tu/$r$$.mau,$r$$.sl_xuat_qd=$he_so_qd_i$$*($r$$.sl_xuat||0),$r$$.sl_nhap_qd=$he_so_qd_i$$*($r$$.sl_nhap||0)):($r$$.sl_xuat_qd=$r$$.sl_xuat||0,$r$$.sl_nhap_qd=$r$$.sl_nhap||0);$r$$.sl_xuat_qd_bc=$r$$.sl_xuat_qd;$r$$.sl_nhap_qd_bc=$r$$.sl_nhap_qd;$r$$.ma_dvt_bc=$r$$.ma_dvt_goc||$r$$.ma_dvt});$condition$$.ma_dvt&&await $report$$.asyncJoinModel2($condition$$.id_app,"dmqddvt",{where:$item$$=>({ma_vt:$item$$.ma_vt,
16
+ ma_dvt:$condition$$.ma_dvt}),setFields:($item$$,$he_so_qd$$)=>{$he_so_qd$$&&$he_so_qd$$.tu?($item$$.ma_dvt_bc=$condition$$.ma_dvt,$he_so_qd$$=$he_so_qd$$.mau/$he_so_qd$$.tu,$item$$.sl_xuat_qd_bc=$he_so_qd$$*($item$$.sl_xuat_qd||0),$item$$.sl_nhap_qd_bc=$he_so_qd$$*($item$$.sl_nhap_qd||0)):($item$$.sl_xuat_qd_bc=$item$$.sl_xuat_qd,$item$$.sl_nhap_qd_bc=$item$$.sl_nhap_qd)}});$resolve$$($report$$)})})})};