flexbiz-server 12.7.1 → 12.7.2

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.
Files changed (884) hide show
  1. package/package.json +5 -5
  2. package/server/app.js +23 -348
  3. package/server/cluster.js +1 -5
  4. package/server/models/account.js +7 -0
  5. package/server/models/actionLog.js +2 -0
  6. package/server/models/afflink.js +2 -0
  7. package/server/models/aimemory.js +1 -0
  8. package/server/models/app.js +16 -0
  9. package/server/models/approve.js +95 -0
  10. package/server/models/assabcihandler.js +35 -0
  11. package/server/models/assbank.js +19 -0
  12. package/server/models/assbooking.js +4 -0
  13. package/server/models/assbuy.js +3 -0
  14. package/server/models/asscashwithdraw.js +4 -0
  15. package/server/models/assfindhash.js +2 -0
  16. package/server/models/assinvestment.js +13 -0
  17. package/server/models/assissue.js +2 -0
  18. package/server/models/asskey.js +15 -0
  19. package/server/models/assneedtobuy.js +6 -0
  20. package/server/models/assperiod.js +7 -0
  21. package/server/models/assproduct.js +13 -0
  22. package/server/models/assprofitsharing.js +4 -0
  23. package/server/models/assreceiver.js +2 -0
  24. package/server/models/assrequest.js +10 -0
  25. package/server/models/asssell.js +7 -0
  26. package/server/models/asstransaction.js +3 -0
  27. package/server/models/asstransfer.js +4 -0
  28. package/server/models/assuser_identity.js +4 -0
  29. package/server/models/asswithdraw.js +4 -0
  30. package/server/models/attend.js +2 -0
  31. package/server/models/banggiaban.js +8 -0
  32. package/server/models/bangtinhluong.js +6 -0
  33. package/server/models/base.js +1 -0
  34. package/server/models/bg1.js +9 -0
  35. package/server/models/bg2.js +10 -0
  36. package/server/models/cache.js +3 -0
  37. package/server/models/cacheDataReport.js +2 -0
  38. package/server/models/cacheSessionReport.js +5 -0
  39. package/server/models/calllog.js +4 -0
  40. package/server/models/cart.js +5 -0
  41. package/server/models/cddiem.js +2 -0
  42. package/server/models/cddt.js +3 -0
  43. package/server/models/cdkh.js +5 -0
  44. package/server/models/cdkhtheongay.js +5 -0
  45. package/server/models/cdnphep.js +2 -0
  46. package/server/models/cdtk.js +3 -0
  47. package/server/models/cdtktheongay.js +3 -0
  48. package/server/models/cdvt.js +5 -0
  49. package/server/models/cdvtnpp.js +6 -0
  50. package/server/models/cdvttheongay.js +5 -0
  51. package/server/models/chamcong.js +7 -0
  52. package/server/models/chat_message.js +2 -0
  53. package/server/models/chat_session.js +2 -0
  54. package/server/models/checkin.js +4 -0
  55. package/server/models/checkinactivity.js +3 -0
  56. package/server/models/checkinkpi.js +4 -0
  57. package/server/models/checkinlocation.js +2 -0
  58. package/server/models/chitietluongds.js +12 -0
  59. package/server/models/chitieukpi.js +3 -0
  60. package/server/models/chudethaoluan.js +3 -0
  61. package/server/models/ckgtluong.js +2 -0
  62. package/server/models/colleague.js +2 -0
  63. package/server/models/comment.js +4 -0
  64. package/server/models/congdoansx.js +4 -0
  65. package/server/models/congtacvien.js +4 -0
  66. package/server/models/congthuctinhgiaban.js +8 -0
  67. package/server/models/consultant.js +4 -0
  68. package/server/models/contract.js +6 -0
  69. package/server/models/counter.js +2 -0
  70. package/server/models/csluongtheods.js +3 -0
  71. package/server/models/csphucap.js +2 -0
  72. package/server/models/ctds.js +5 -0
  73. package/server/models/ctds2.js +7 -0
  74. package/server/models/currency.js +3 -0
  75. package/server/models/custom_report.js +1 -0
  76. package/server/models/customer.js +31 -0
  77. package/server/models/customer_care.js +2 -0
  78. package/server/models/data_list_config.js +7 -0
  79. package/server/models/databanle.js +8 -0
  80. package/server/models/datlich.js +4 -0
  81. package/server/models/deal.js +2 -0
  82. package/server/models/dh2.js +20 -0
  83. package/server/models/diagram.js +2 -0
  84. package/server/models/dinhmucsx.js +8 -0
  85. package/server/models/dkhoc.js +6 -0
  86. package/server/models/dknphep.js +2 -0
  87. package/server/models/dmban.js +4 -0
  88. package/server/models/dmbp.js +12 -0
  89. package/server/models/dmca.js +2 -0
  90. package/server/models/dmchietkhau.js +8 -0
  91. package/server/models/dmchietkhauhd.js +19 -0
  92. package/server/models/dmchinhanh.js +2 -0
  93. package/server/models/dmcpmh.js +2 -0
  94. package/server/models/dmdiemthuong.js +3 -0
  95. package/server/models/dmdoi.js +4 -0
  96. package/server/models/dmdoituongdanhgia.js +2 -0
  97. package/server/models/dmdt.js +8 -0
  98. package/server/models/dmdvt.js +3 -0
  99. package/server/models/dmgiaban.js +9 -0
  100. package/server/models/dmgiamua.js +5 -0
  101. package/server/models/dmgiathitruong.js +5 -0
  102. package/server/models/dmgiathitruong_ngay.js +2 -0
  103. package/server/models/dmgiathitruong_theodoi.js +2 -0
  104. package/server/models/dmhoahonghd.js +8 -0
  105. package/server/models/dmhoahongnpp.js +8 -0
  106. package/server/models/dmkc.js +3 -0
  107. package/server/models/dmkho.js +7 -0
  108. package/server/models/dmkhuyenmai.js +9 -0
  109. package/server/models/dmkhuyenmaihd.js +11 -0
  110. package/server/models/dmletet.js +2 -0
  111. package/server/models/dmlo.js +4 -0
  112. package/server/models/dmloaicong.js +4 -0
  113. package/server/models/dmloaitask.js +2 -0
  114. package/server/models/dmloaits.js +2 -0
  115. package/server/models/dmnckkm.js +4 -0
  116. package/server/models/dmnghiepvu.js +4 -0
  117. package/server/models/dmnguonvon.js +2 -0
  118. package/server/models/dmnhnv.js +4 -0
  119. package/server/models/dmnv.js +17 -0
  120. package/server/models/dmnvt.js +10 -0
  121. package/server/models/dmphi.js +3 -0
  122. package/server/models/dmqct.js +3 -0
  123. package/server/models/dmqddvt.js +3 -0
  124. package/server/models/dmtanggiamts.js +3 -0
  125. package/server/models/dmto.js +4 -0
  126. package/server/models/dmtt.js +6 -0
  127. package/server/models/dmvt.js +17 -0
  128. package/server/models/dmyt.js +4 -0
  129. package/server/models/dn0.js +13 -0
  130. package/server/models/dnm.js +11 -0
  131. package/server/models/dokho.js +2 -0
  132. package/server/models/domain.js +2 -0
  133. package/server/models/dvcs.js +3 -0
  134. package/server/models/ecomcategories.js +3 -0
  135. package/server/models/ecomcategories_cty.js +3 -0
  136. package/server/models/ecomproductlines.js +2 -0
  137. package/server/models/ecompromotion_flashsales.js +2 -0
  138. package/server/models/ecompromotion_freeships.js +2 -0
  139. package/server/models/email.js +2 -0
  140. package/server/models/endpoint.js +1 -0
  141. package/server/models/events.js +3 -0
  142. package/server/models/evoucher.js +5 -0
  143. package/server/models/experiencejourney.js +2 -0
  144. package/server/models/experiencejourneydata.js +4 -0
  145. package/server/models/experiencejourneypersona.js +3 -0
  146. package/server/models/experiencejourneystage.js +2 -0
  147. package/server/models/exportexceltemplate.js +2 -0
  148. package/server/models/fbconversation.js +15 -0
  149. package/server/models/fbmessage.js +2 -0
  150. package/server/models/fbpage.js +2 -0
  151. package/server/models/fbpost.js +2 -0
  152. package/server/models/fieldright.js +2 -0
  153. package/server/models/fifo_dk.js +2 -0
  154. package/server/models/fifo_lot.js +3 -0
  155. package/server/models/fifo_trace.js +4 -0
  156. package/server/models/file.js +4 -0
  157. package/server/models/filechunk.js +2 -0
  158. package/server/models/financialroadmap.js +3 -0
  159. package/server/models/flow.js +2 -0
  160. package/server/models/flowdata.js +3 -0
  161. package/server/models/flowpending.js +2 -0
  162. package/server/models/folder.js +4 -0
  163. package/server/models/follow.js +2 -0
  164. package/server/models/forminfo.js +5 -0
  165. package/server/models/giaoca.js +4 -0
  166. package/server/models/giatb.js +3 -0
  167. package/server/models/group.js +9 -0
  168. package/server/models/gt_ctgt.js +4 -0
  169. package/server/models/gt_hspb.js +3 -0
  170. package/server/models/gt_sltk.js +3 -0
  171. package/server/models/gt_thcppstk.js +3 -0
  172. package/server/models/hanmucton.js +4 -0
  173. package/server/models/hd1.js +11 -0
  174. package/server/models/hd2.js +26 -0
  175. package/server/models/hd3.js +17 -0
  176. package/server/models/hd4.js +13 -0
  177. package/server/models/hd7.js +17 -0
  178. package/server/models/hd8.js +12 -0
  179. package/server/models/hde.js +11 -0
  180. package/server/models/hmcn.js +3 -0
  181. package/server/models/hmcnct.js +2 -0
  182. package/server/models/hspbts.js +4 -0
  183. package/server/models/htl.js +13 -0
  184. package/server/models/importexceltemplate.js +2 -0
  185. package/server/models/introducebonus.js +4 -0
  186. package/server/models/introducecode.js +3 -0
  187. package/server/models/introducer.js +4 -0
  188. package/server/models/kbbtpb.js +7 -0
  189. package/server/models/kbmPttct.js +4 -0
  190. package/server/models/kbmTkgtgt.js +5 -0
  191. package/server/models/kbm_bcdkt_old.js +4 -0
  192. package/server/models/kbm_kqhdkd_old.js +3 -0
  193. package/server/models/kbm_lcttgt_old.js +5 -0
  194. package/server/models/kbm_lctttt_old.js +4 -0
  195. package/server/models/kbm_pttct_old.js +4 -0
  196. package/server/models/kbm_tkgtgt_old.js +5 -0
  197. package/server/models/kbmbcdkt.js +4 -0
  198. package/server/models/kbmbcqt.js +4 -0
  199. package/server/models/kbmkqhdkd.js +3 -0
  200. package/server/models/kbmlcttgt.js +6 -0
  201. package/server/models/kbmlctttt.js +4 -0
  202. package/server/models/kbmtmbctc.js +4 -0
  203. package/server/models/kehoachdtcp.js +3 -0
  204. package/server/models/kehoachmh.js +8 -0
  205. package/server/models/keyresult.js +7 -0
  206. package/server/models/khunghangthanhvien.js +3 -0
  207. package/server/models/label.js +2 -0
  208. package/server/models/labelinfo.js +2 -0
  209. package/server/models/lenhcapphat.js +8 -0
  210. package/server/models/lenhsx.js +8 -0
  211. package/server/models/lienhe.js +4 -0
  212. package/server/models/like_module.js +2 -0
  213. package/server/models/link.js +2 -0
  214. package/server/models/listinfo.js +1365 -0
  215. package/server/models/loaidiem.js +2 -0
  216. package/server/models/lock.js +2 -0
  217. package/server/models/log.js +8 -0
  218. package/server/models/mailaccount.js +3 -0
  219. package/server/models/mailgroup.js +3 -0
  220. package/server/models/mailreceived.js +2 -0
  221. package/server/models/mailsent.js +2 -0
  222. package/server/models/mailtemplate.js +2 -0
  223. package/server/models/maudanhgia.js +2 -0
  224. package/server/models/menuinfo.js +2 -0
  225. package/server/models/message.js +8 -0
  226. package/server/models/message2.js +4 -0
  227. package/server/models/message2setting.js +3 -0
  228. package/server/models/moduleinfo.js +4 -0
  229. package/server/models/momo.js +18 -0
  230. package/server/models/news.js +3 -0
  231. package/server/models/newsfeed.js +4 -0
  232. package/server/models/note.js +2 -0
  233. package/server/models/notification.js +8 -0
  234. package/server/models/okr.js +4 -0
  235. package/server/models/okrdiagram.js +3 -0
  236. package/server/models/onepay.js +24 -0
  237. package/server/models/opportunity.js +4 -0
  238. package/server/models/options.js +2 -0
  239. package/server/models/originimportid.js +1 -0
  240. package/server/models/otp.js +1 -0
  241. package/server/models/parameter.js +2 -0
  242. package/server/models/participant.js +21 -0
  243. package/server/models/partner.js +1 -0
  244. package/server/models/payload.js +1 -0
  245. package/server/models/pbl.js +16 -0
  246. package/server/models/pc0.js +13 -0
  247. package/server/models/pc1.js +14 -0
  248. package/server/models/pc2.js +13 -0
  249. package/server/models/pc3.js +13 -0
  250. package/server/models/pc5.js +8 -0
  251. package/server/models/pc6.js +14 -0
  252. package/server/models/pcl.js +6 -0
  253. package/server/models/pdn.js +9 -0
  254. package/server/models/pdx.js +9 -0
  255. package/server/models/pgh.js +5 -0
  256. package/server/models/phieudanhgia.js +3 -0
  257. package/server/models/pht.js +8 -0
  258. package/server/models/phucap.js +4 -0
  259. package/server/models/pkc.js +6 -0
  260. package/server/models/pkh.js +6 -0
  261. package/server/models/pkk.js +10 -0
  262. package/server/models/pkt.js +12 -0
  263. package/server/models/pn1.js +18 -0
  264. package/server/models/pn2.js +12 -0
  265. package/server/models/pn3.js +13 -0
  266. package/server/models/pn5.js +14 -0
  267. package/server/models/pn6.js +14 -0
  268. package/server/models/pn9.js +17 -0
  269. package/server/models/pnc.js +9 -0
  270. package/server/models/pnh.js +11 -0
  271. package/server/models/pnk.js +10 -0
  272. package/server/models/po1.js +19 -0
  273. package/server/models/ppb.js +6 -0
  274. package/server/models/productcode.js +2 -0
  275. package/server/models/profile.js +4 -0
  276. package/server/models/pt1.js +12 -0
  277. package/server/models/pt5.js +8 -0
  278. package/server/models/ptl.js +5 -0
  279. package/server/models/ptthanhtoan.js +6 -0
  280. package/server/models/purchase_contract.js +17 -0
  281. package/server/models/pxc.js +9 -0
  282. package/server/models/pxh.js +11 -0
  283. package/server/models/pxk.js +9 -0
  284. package/server/models/qts.js +14 -0
  285. package/server/models/qts_dieuchinh.js +3 -0
  286. package/server/models/qts_dieuchuyen.js +4 -0
  287. package/server/models/quanhuyen.js +2 -0
  288. package/server/models/reason.js +2 -0
  289. package/server/models/receivedinvoice.js +2 -0
  290. package/server/models/reportinfo.js +5 -0
  291. package/server/models/right.js +4 -0
  292. package/server/models/rpt.js +2 -0
  293. package/server/models/rptform.js +3 -0
  294. package/server/models/rptobject.js +2 -0
  295. package/server/models/sale_contract.js +9 -0
  296. package/server/models/schedule.js +18 -0
  297. package/server/models/schedule_log.js +2 -0
  298. package/server/models/shipbook.js +12 -0
  299. package/server/models/shortcut.js +2 -0
  300. package/server/models/smsaccount.js +10 -0
  301. package/server/models/smssend.js +2 -0
  302. package/server/models/so1.js +22 -0
  303. package/server/models/so5.js +15 -0
  304. package/server/models/so9.js +19 -0
  305. package/server/models/socai.js +28 -0
  306. package/server/models/socainpp.js +18 -0
  307. package/server/models/socaitc.js +6 -0
  308. package/server/models/socaitmp.js +16 -0
  309. package/server/models/socaitt.js +4 -0
  310. package/server/models/sodiemthuong.js +4 -0
  311. package/server/models/sokho.js +27 -0
  312. package/server/models/sokhocapphat.js +18 -0
  313. package/server/models/sokhokhongton.js +19 -0
  314. package/server/models/sokhonpp.js +19 -0
  315. package/server/models/sokhotc.js +8 -0
  316. package/server/models/sokhott.js +18 -0
  317. package/server/models/sophanbokh.js +3 -0
  318. package/server/models/sosanxuat.js +5 -0
  319. package/server/models/sotinhkh.js +2 -0
  320. package/server/models/spdd_ck.js +3 -0
  321. package/server/models/spdd_dk.js +3 -0
  322. package/server/models/step.js +2 -0
  323. package/server/models/strategicdiagram.js +3 -0
  324. package/server/models/strategicgoal.js +4 -0
  325. package/server/models/strategickpi.js +6 -0
  326. package/server/models/strategicobjective.js +5 -0
  327. package/server/models/strategicplan.js +5 -0
  328. package/server/models/subscribe.js +2 -0
  329. package/server/models/support.js +2 -0
  330. package/server/models/synctime.js +2 -0
  331. package/server/models/sys_job_queue_book_keeping.js +2 -0
  332. package/server/models/sysconfig.js +2 -0
  333. package/server/models/sysgroup.js +2 -0
  334. package/server/models/tableinfo.js +3 -0
  335. package/server/models/task.js +9 -0
  336. package/server/models/tc.js +2 -0
  337. package/server/models/tdttco.js +9 -0
  338. package/server/models/tdttco_tt.js +5 -0
  339. package/server/models/tdttno.js +9 -0
  340. package/server/models/tdttno_tt.js +5 -0
  341. package/server/models/templaterpt.js +2 -0
  342. package/server/models/templatestore.js +3 -0
  343. package/server/models/templatevoucher.js +3 -0
  344. package/server/models/tinhthanh.js +2 -0
  345. package/server/models/tokens.js +3 -0
  346. package/server/models/tontucthoi.js +9 -0
  347. package/server/models/trangthai.js +4 -0
  348. package/server/models/trangthaiapp.js +4 -0
  349. package/server/models/transaction.js +16 -0
  350. package/server/models/trialinfo.js +2 -0
  351. package/server/models/user.js +40 -0
  352. package/server/models/usergroup.js +7 -0
  353. package/server/models/vanchuyen.js +12 -0
  354. package/server/models/vat.js +3 -0
  355. package/server/models/vatra.js +6 -0
  356. package/server/models/vatvao.js +6 -0
  357. package/server/models/versioninfo.js +2 -0
  358. package/server/models/vietqrbanks.js +2 -0
  359. package/server/models/vsocai.js +6 -0
  360. package/server/models/wallet.js +8 -0
  361. package/server/models/warranty.js +3 -0
  362. package/server/models/warrantyclaim.js +2 -0
  363. package/server/models/warrantypolicy.js +1 -0
  364. package/server/models/workflow.js +4 -0
  365. package/server/models/xaphuong.js +2 -0
  366. package/server/models/xhd.js +10 -0
  367. package/server/models/ytdd_ck.js +4 -0
  368. package/server/models/ytdd_dk.js +4 -0
  369. package/server/models/zalo.js +17 -0
  370. package/server/modules/lists/bg-cddiem.js +6 -0
  371. package/server/modules/lists/bg-cddt.js +7 -0
  372. package/server/modules/lists/bg-cdkh.js +11 -0
  373. package/server/modules/lists/bg-cdnphep.js +6 -0
  374. package/server/modules/lists/bg-cdtk.js +9 -0
  375. package/server/modules/lists/bg-cdvt.js +8 -0
  376. package/server/modules/lists/bg-cdvtnpp.js +8 -0
  377. package/server/modules/lists/bg-fifo_dk.js +8 -0
  378. package/server/modules/lists/ls-account.js +4 -0
  379. package/server/modules/lists/ls-afflink.js +3 -0
  380. package/server/modules/lists/ls-approve.js +5 -0
  381. package/server/modules/lists/ls-assabcihandler.js +3 -0
  382. package/server/modules/lists/ls-assbank.js +3 -0
  383. package/server/modules/lists/ls-assbooking.js +20 -0
  384. package/server/modules/lists/ls-assbuy.js +8 -0
  385. package/server/modules/lists/ls-asscashwithdraw.js +8 -0
  386. package/server/modules/lists/ls-assinvestment.js +31 -0
  387. package/server/modules/lists/ls-assissue.js +3 -0
  388. package/server/modules/lists/ls-asskey.js +41 -0
  389. package/server/modules/lists/ls-assneedtobuy.js +10 -0
  390. package/server/modules/lists/ls-assperiod.js +19 -0
  391. package/server/modules/lists/ls-assproduct.js +9 -0
  392. package/server/modules/lists/ls-assprofitsharing.js +8 -0
  393. package/server/modules/lists/ls-assreceiver.js +3 -0
  394. package/server/modules/lists/ls-assrequest.js +4 -0
  395. package/server/modules/lists/ls-asssell.js +13 -0
  396. package/server/modules/lists/ls-asstransaction.js +3 -0
  397. package/server/modules/lists/ls-asstransfer.js +3 -0
  398. package/server/modules/lists/ls-assuser_identity.js +1 -0
  399. package/server/modules/lists/ls-asswithdraw.js +12 -0
  400. package/server/modules/lists/ls-bangtinhluong.js +2 -0
  401. package/server/modules/lists/ls-calllog.js +4 -0
  402. package/server/modules/lists/ls-cart.js +14 -0
  403. package/server/modules/lists/ls-chamcong.js +3 -0
  404. package/server/modules/lists/ls-chat_session.js +5 -0
  405. package/server/modules/lists/ls-checkin.js +24 -0
  406. package/server/modules/lists/ls-checkinactivity.js +8 -0
  407. package/server/modules/lists/ls-checkinkpi.js +3 -0
  408. package/server/modules/lists/ls-checkinlocation.js +1 -0
  409. package/server/modules/lists/ls-chitietluongds.js +4 -0
  410. package/server/modules/lists/ls-chitieukpi.js +1 -0
  411. package/server/modules/lists/ls-chudethaoluan.js +1 -0
  412. package/server/modules/lists/ls-ckgtluong.js +1 -0
  413. package/server/modules/lists/ls-comment.js +9 -0
  414. package/server/modules/lists/ls-congdoansx.js +3 -0
  415. package/server/modules/lists/ls-congtacvien.js +5 -0
  416. package/server/modules/lists/ls-consultant.js +2 -0
  417. package/server/modules/lists/ls-contract.js +7 -0
  418. package/server/modules/lists/ls-csluongtheods.js +1 -0
  419. package/server/modules/lists/ls-csphucap.js +1 -0
  420. package/server/modules/lists/ls-ctds.js +4 -0
  421. package/server/modules/lists/ls-ctds2.js +4 -0
  422. package/server/modules/lists/ls-currency.js +1 -0
  423. package/server/modules/lists/ls-customer.js +22 -0
  424. package/server/modules/lists/ls-customer_care.js +1 -0
  425. package/server/modules/lists/ls-datlich.js +9 -0
  426. package/server/modules/lists/ls-dckhauhaots.js +3 -0
  427. package/server/modules/lists/ls-deal.js +3 -0
  428. package/server/modules/lists/ls-diagram.js +1 -0
  429. package/server/modules/lists/ls-dkhoc.js +6 -0
  430. package/server/modules/lists/ls-dknphep.js +1 -0
  431. package/server/modules/lists/ls-dmban.js +4 -0
  432. package/server/modules/lists/ls-dmbp.js +7 -0
  433. package/server/modules/lists/ls-dmca.js +1 -0
  434. package/server/modules/lists/ls-dmchietkhau.js +19 -0
  435. package/server/modules/lists/ls-dmchietkhauhd.js +4 -0
  436. package/server/modules/lists/ls-dmchinhanh.js +1 -0
  437. package/server/modules/lists/ls-dmchucvu.js +2 -0
  438. package/server/modules/lists/ls-dmcpmh.js +1 -0
  439. package/server/modules/lists/ls-dmdiemthuong.js +4 -0
  440. package/server/modules/lists/ls-dmdoi.js +4 -0
  441. package/server/modules/lists/ls-dmdoituongdanhgia.js +1 -0
  442. package/server/modules/lists/ls-dmdt.js +11 -0
  443. package/server/modules/lists/ls-dmdvt.js +2 -0
  444. package/server/modules/lists/ls-dmgiaban.js +4 -0
  445. package/server/modules/lists/ls-dmgiamua.js +4 -0
  446. package/server/modules/lists/ls-dmgiathitruong.js +15 -0
  447. package/server/modules/lists/ls-dmgiathitruong_ngay.js +2 -0
  448. package/server/modules/lists/ls-dmgiathitruong_theodoi.js +1 -0
  449. package/server/modules/lists/ls-dmhoahonghd.js +1 -0
  450. package/server/modules/lists/ls-dmhoahongnpp.js +1 -0
  451. package/server/modules/lists/ls-dmkc.js +3 -0
  452. package/server/modules/lists/ls-dmkho.js +7 -0
  453. package/server/modules/lists/ls-dmkhuyenmai.js +5 -0
  454. package/server/modules/lists/ls-dmkhuyenmaihd.js +3 -0
  455. package/server/modules/lists/ls-dmletet.js +1 -0
  456. package/server/modules/lists/ls-dmlo.js +1 -0
  457. package/server/modules/lists/ls-dmloaicong.js +1 -0
  458. package/server/modules/lists/ls-dmloaits.js +1 -0
  459. package/server/modules/lists/ls-dmnckkm.js +7 -0
  460. package/server/modules/lists/ls-dmnghiepvu.js +1 -0
  461. package/server/modules/lists/ls-dmnguonvon.js +1 -0
  462. package/server/modules/lists/ls-dmnhnv.js +6 -0
  463. package/server/modules/lists/ls-dmnhtask.js +5 -0
  464. package/server/modules/lists/ls-dmnkh.js +6 -0
  465. package/server/modules/lists/ls-dmntt.js +6 -0
  466. package/server/modules/lists/ls-dmnv.js +14 -0
  467. package/server/modules/lists/ls-dmnvt.js +7 -0
  468. package/server/modules/lists/ls-dmphi.js +6 -0
  469. package/server/modules/lists/ls-dmqct.js +2 -0
  470. package/server/modules/lists/ls-dmqddvt.js +3 -0
  471. package/server/modules/lists/ls-dmtanggiamts.js +1 -0
  472. package/server/modules/lists/ls-dmto.js +5 -0
  473. package/server/modules/lists/ls-dmtt.js +7 -0
  474. package/server/modules/lists/ls-dmvt.js +52 -0
  475. package/server/modules/lists/ls-dmyt.js +1 -0
  476. package/server/modules/lists/ls-dokho.js +1 -0
  477. package/server/modules/lists/ls-dvcs.js +1 -0
  478. package/server/modules/lists/ls-ecomcategories.js +5 -0
  479. package/server/modules/lists/ls-ecomcategories_cty.js +5 -0
  480. package/server/modules/lists/ls-email.js +4 -0
  481. package/server/modules/lists/ls-events.js +3 -0
  482. package/server/modules/lists/ls-evoucher.js +3 -0
  483. package/server/modules/lists/ls-experiencejourney.js +1 -0
  484. package/server/modules/lists/ls-experiencejourneydata.js +3 -0
  485. package/server/modules/lists/ls-experiencejourneypersona.js +4 -0
  486. package/server/modules/lists/ls-experiencejourneystage.js +1 -0
  487. package/server/modules/lists/ls-fbconversation.js +2 -0
  488. package/server/modules/lists/ls-fbmessage.js +2 -0
  489. package/server/modules/lists/ls-fbpage.js +11 -0
  490. package/server/modules/lists/ls-fbpost.js +2 -0
  491. package/server/modules/lists/ls-file.js +38 -0
  492. package/server/modules/lists/ls-financialroadmap.js +3 -0
  493. package/server/modules/lists/ls-flow.js +6 -0
  494. package/server/modules/lists/ls-flowdata.js +1 -0
  495. package/server/modules/lists/ls-flowpending.js +3 -0
  496. package/server/modules/lists/ls-folder.js +1 -0
  497. package/server/modules/lists/ls-forminfo.js +1 -0
  498. package/server/modules/lists/ls-giaoca.js +5 -0
  499. package/server/modules/lists/ls-group.js +5 -0
  500. package/server/modules/lists/ls-hmcn.js +2 -0
  501. package/server/modules/lists/ls-hspbts.js +3 -0
  502. package/server/modules/lists/ls-introducebonus.js +4 -0
  503. package/server/modules/lists/ls-introducecode.js +10 -0
  504. package/server/modules/lists/ls-introducer.js +21 -0
  505. package/server/modules/lists/ls-kbm-bcdkt.js +1 -0
  506. package/server/modules/lists/ls-kbm-bcqt.js +5 -0
  507. package/server/modules/lists/ls-kbm-kqhdkd.js +1 -0
  508. package/server/modules/lists/ls-kbm-lcttgt.js +1 -0
  509. package/server/modules/lists/ls-kbm-lctttt.js +1 -0
  510. package/server/modules/lists/ls-kbm-pttct.js +3 -0
  511. package/server/modules/lists/ls-kbm-tkgtgt.js +3 -0
  512. package/server/modules/lists/ls-kbm-tmbctc.js +3 -0
  513. package/server/modules/lists/ls-kehoachdtcp.js +4 -0
  514. package/server/modules/lists/ls-keyresult.js +7 -0
  515. package/server/modules/lists/ls-khunghangthanhvien.js +1 -0
  516. package/server/modules/lists/ls-label.js +1 -0
  517. package/server/modules/lists/ls-lienhe.js +4 -0
  518. package/server/modules/lists/ls-like-module.js +1 -0
  519. package/server/modules/lists/ls-link.js +1 -0
  520. package/server/modules/lists/ls-loaidiem.js +1 -0
  521. package/server/modules/lists/ls-lock.js +1 -0
  522. package/server/modules/lists/ls-log.js +3 -0
  523. package/server/modules/lists/ls-mailaccount.js +5 -0
  524. package/server/modules/lists/ls-mailreceived.js +5 -0
  525. package/server/modules/lists/ls-mailsent.js +4 -0
  526. package/server/modules/lists/ls-mailtemplate.js +4 -0
  527. package/server/modules/lists/ls-maudanhgia.js +3 -0
  528. package/server/modules/lists/ls-message2.js +8 -0
  529. package/server/modules/lists/ls-message2setting.js +5 -0
  530. package/server/modules/lists/ls-news.js +7 -0
  531. package/server/modules/lists/ls-newsfeed.js +4 -0
  532. package/server/modules/lists/ls-note.js +6 -0
  533. package/server/modules/lists/ls-okr.js +5 -0
  534. package/server/modules/lists/ls-okrdiagram.js +1 -0
  535. package/server/modules/lists/ls-opportunity.js +5 -0
  536. package/server/modules/lists/ls-options.js +4 -0
  537. package/server/modules/lists/ls-parameter.js +3 -0
  538. package/server/modules/lists/ls-participant.js +12 -0
  539. package/server/modules/lists/ls-phieudanhgia.js +7 -0
  540. package/server/modules/lists/ls-phucap.js +2 -0
  541. package/server/modules/lists/ls-productcode.js +9 -0
  542. package/server/modules/lists/ls-profile.js +1 -0
  543. package/server/modules/lists/ls-ptthanhtoan.js +3 -0
  544. package/server/modules/lists/ls-qts-dieuchinh.js +2 -0
  545. package/server/modules/lists/ls-qts-dieuchuyen.js +8 -0
  546. package/server/modules/lists/ls-reason.js +1 -0
  547. package/server/modules/lists/ls-rpt.js +5 -0
  548. package/server/modules/lists/ls-rptform.js +3 -0
  549. package/server/modules/lists/ls-shortcut.js +1 -0
  550. package/server/modules/lists/ls-smsaccount.js +1 -0
  551. package/server/modules/lists/ls-smssend.js +3 -0
  552. package/server/modules/lists/ls-sosanxuat.js +4 -0
  553. package/server/modules/lists/ls-step.js +1 -0
  554. package/server/modules/lists/ls-strategicdiagram.js +1 -0
  555. package/server/modules/lists/ls-strategicgoal.js +3 -0
  556. package/server/modules/lists/ls-strategickpi.js +7 -0
  557. package/server/modules/lists/ls-strategicobjective.js +3 -0
  558. package/server/modules/lists/ls-strategicplan.js +6 -0
  559. package/server/modules/lists/ls-support.js +3 -0
  560. package/server/modules/lists/ls-task.js +28 -0
  561. package/server/modules/lists/ls-tc.js +1 -0
  562. package/server/modules/lists/ls-templaterpt.js +5 -0
  563. package/server/modules/lists/ls-templatevoucher.js +1 -0
  564. package/server/modules/lists/ls-tontucthoi.js +3 -0
  565. package/server/modules/lists/ls-trangthaiapp.js +3 -0
  566. package/server/modules/lists/ls-transaction.js +4 -0
  567. package/server/modules/lists/ls-usergroup.js +7 -0
  568. package/server/modules/lists/ls-vat.js +1 -0
  569. package/server/modules/lists/ls-vatra.js +5 -0
  570. package/server/modules/lists/ls-vatvao.js +6 -0
  571. package/server/modules/lists/ls-warranty.js +3 -0
  572. package/server/modules/lists/ls-workflow.js +1 -0
  573. package/server/modules/lists/ls_hanmucton.js +3 -0
  574. package/server/modules/lists/ls_hspb.js +4 -0
  575. package/server/modules/lists/ls_spdd_ck.js +3 -0
  576. package/server/modules/lists/ls_spdd_dk.js +3 -0
  577. package/server/modules/lists/ls_ytdd_ck.js +4 -0
  578. package/server/modules/lists/ls_ytdd_dk.js +4 -0
  579. package/server/modules/lists/sys-attend.js +4 -0
  580. package/server/modules/lists/sys-follow.js +4 -0
  581. package/server/modules/lists/sys-right.js +2 -0
  582. package/server/modules/public/app.js +4 -0
  583. package/server/modules/public/approve.js +37 -0
  584. package/server/modules/public/callin.js +7 -0
  585. package/server/modules/public/comment.js +5 -0
  586. package/server/modules/public/dmnvt.js +4 -0
  587. package/server/modules/public/dmvt.js +9 -0
  588. package/server/modules/public/file.js +11 -0
  589. package/server/modules/public/forminfo.js +1 -0
  590. package/server/modules/public/group.js +4 -0
  591. package/server/modules/public/introducecode.js +1 -0
  592. package/server/modules/public/listinfo.js +1 -0
  593. package/server/modules/public/media-webhook.js +1 -0
  594. package/server/modules/public/partner.js +1 -0
  595. package/server/modules/public/paymentCallback.js +32 -0
  596. package/server/modules/public/province.js +1 -0
  597. package/server/modules/public/ptthanhtoan.js +4 -0
  598. package/server/modules/public/subscribe.js +30 -0
  599. package/server/modules/public/support.js +3 -0
  600. package/server/modules/public/tableinfo.js +1 -0
  601. package/server/modules/public/trialinfo.js +4 -0
  602. package/server/modules/public/versioninfo.js +1 -0
  603. package/server/modules/reports/calc-tinhgiafifo.js +8 -0
  604. package/server/modules/reports/calc-tinhgiatb.js +7 -0
  605. package/server/modules/reports/calc-tinhgiathanh.js +7 -0
  606. package/server/modules/reports/calc-tinhkhauhaots.js +3 -0
  607. package/server/modules/reports/calc-tinhluong.js +68 -0
  608. package/server/modules/reports/rp-analyzedata.js +6 -0
  609. package/server/modules/reports/rp-assbonus.js +4 -0
  610. package/server/modules/reports/rp-assinterest.js +8 -0
  611. package/server/modules/reports/rp-assproductowners.js +3 -0
  612. package/server/modules/reports/rp-asssupply.js +1 -0
  613. package/server/modules/reports/rp-asstransferlog.js +10 -0
  614. package/server/modules/reports/rp-backup.js +4 -0
  615. package/server/modules/reports/rp-banggiatb.js +3 -0
  616. package/server/modules/reports/rp-bangtinhkhauhao.js +6 -0
  617. package/server/modules/reports/rp-baoCaoFifoKy.js +1 -0
  618. package/server/modules/reports/rp-baocaokhachhang.js +6 -0
  619. package/server/modules/reports/rp-bcdkt.js +11 -0
  620. package/server/modules/reports/rp-bcintroducebonus.js +4 -0
  621. package/server/modules/reports/rp-bckhtiemnang.js +3 -0
  622. package/server/modules/reports/rp-bcqt.js +85 -0
  623. package/server/modules/reports/rp-bkchamcong.js +5 -0
  624. package/server/modules/reports/rp-bkct.js +13 -0
  625. package/server/modules/reports/rp-bkshipbook.js +8 -0
  626. package/server/modules/reports/rp-bkvanchuyen.js +8 -0
  627. package/server/modules/reports/rp-bkvatra.js +7 -0
  628. package/server/modules/reports/rp-bkvatvao.js +7 -0
  629. package/server/modules/reports/rp-capnhatsocaitc.js +4 -0
  630. package/server/modules/reports/rp-cdpsdiem.js +4 -0
  631. package/server/modules/reports/rp-cdpsdt.js +5 -0
  632. package/server/modules/reports/rp-cdpskh.js +8 -0
  633. package/server/modules/reports/rp-cdpsnphep.js +3 -0
  634. package/server/modules/reports/rp-cdpstk.js +4 -0
  635. package/server/modules/reports/rp-chitietchitientheohoadon.js +12 -0
  636. package/server/modules/reports/rp-chitiettaisan.js +13 -0
  637. package/server/modules/reports/rp-chitietthutientheohoadon.js +13 -0
  638. package/server/modules/reports/rp-ckcn.js +3 -0
  639. package/server/modules/reports/rp-ckdiem.js +2 -0
  640. package/server/modules/reports/rp-cktk.js +3 -0
  641. package/server/modules/reports/rp-ckvt.js +10 -0
  642. package/server/modules/reports/rp-ckvttheokho.js +4 -0
  643. package/server/modules/reports/rp-ckvttheotg.js +4 -0
  644. package/server/modules/reports/rp-ckvttt.js +3 -0
  645. package/server/modules/reports/rp-congnophaithutheotuoino.js +3 -0
  646. package/server/modules/reports/rp-congnophaitratheotuoino.js +3 -0
  647. package/server/modules/reports/rp-congnosapthu.js +4 -0
  648. package/server/modules/reports/rp-congnosaptra.js +4 -0
  649. package/server/modules/reports/rp-congviectheobp.js +9 -0
  650. package/server/modules/reports/rp-congviectheodt.js +8 -0
  651. package/server/modules/reports/rp-congviectheokh.js +8 -0
  652. package/server/modules/reports/rp-congviectheonv.js +9 -0
  653. package/server/modules/reports/rp-congviectheotimeline.js +6 -0
  654. package/server/modules/reports/rp-ctbanle.js +15 -0
  655. package/server/modules/reports/rp-ctbanle2.js +20 -0
  656. package/server/modules/reports/rp-ctbanlectv.js +20 -0
  657. package/server/modules/reports/rp-ctbanlenpp.js +24 -0
  658. package/server/modules/reports/rp-ctdanhgianhanvien.js +8 -0
  659. package/server/modules/reports/rp-cthangbanbitralai.js +4 -0
  660. package/server/modules/reports/rp-ctmuahang.js +7 -0
  661. package/server/modules/reports/rp-cttralaihang.js +4 -0
  662. package/server/modules/reports/rp-databanle.js +10 -0
  663. package/server/modules/reports/rp-diemthuong.js +2 -0
  664. package/server/modules/reports/rp-dkcn.js +3 -0
  665. package/server/modules/reports/rp-dktk.js +2 -0
  666. package/server/modules/reports/rp-dsnhanviencm.js +9 -0
  667. package/server/modules/reports/rp-dsnhanvientb.js +9 -0
  668. package/server/modules/reports/rp-dtbanlekempk.js +12 -0
  669. package/server/modules/reports/rp-dtbanletheoct.js +22 -0
  670. package/server/modules/reports/rp-dtbanletheoctkempk.js +25 -0
  671. package/server/modules/reports/rp-dtbanletheokh.js +17 -0
  672. package/server/modules/reports/rp-dtbanletheokhnpp.js +19 -0
  673. package/server/modules/reports/rp-dtbanletheokho.js +15 -0
  674. package/server/modules/reports/rp-dtbanletheonam.js +3 -0
  675. package/server/modules/reports/rp-dtbanletheongay.js +1 -0
  676. package/server/modules/reports/rp-dtbanletheonpp.js +23 -0
  677. package/server/modules/reports/rp-dtbanletheonv.js +19 -0
  678. package/server/modules/reports/rp-dtbanletheoquy.js +3 -0
  679. package/server/modules/reports/rp-dtbanletheosp.js +9 -0
  680. package/server/modules/reports/rp-dtbanletheospnpp.js +6 -0
  681. package/server/modules/reports/rp-dtbanletheothang.js +3 -0
  682. package/server/modules/reports/rp-dtbanletheothungan.js +12 -0
  683. package/server/modules/reports/rp-dtbanletheovt.js +2 -0
  684. package/server/modules/reports/rp-dtbanletheovtnpp.js +2 -0
  685. package/server/modules/reports/rp-dutoanthuchitheodt.js +4 -0
  686. package/server/modules/reports/rp-getPXC2PNC.js +8 -0
  687. package/server/modules/reports/rp-getariseofaccountsbymonth.js +4 -0
  688. package/server/modules/reports/rp-getbtpb.js +6 -0
  689. package/server/modules/reports/rp-getcashbycashier.js +7 -0
  690. package/server/modules/reports/rp-getcschietkhau.js +5 -0
  691. package/server/modules/reports/rp-getdinhmuc4lenhcp.js +7 -0
  692. package/server/modules/reports/rp-getdinhmuc4pxk.js +9 -0
  693. package/server/modules/reports/rp-getdk4pht.js +8 -0
  694. package/server/modules/reports/rp-getdk4pkc.js +10 -0
  695. package/server/modules/reports/rp-getdttheoca.js +5 -0
  696. package/server/modules/reports/rp-getinvoice2pay.js +4 -0
  697. package/server/modules/reports/rp-getinvoice2receive.js +4 -0
  698. package/server/modules/reports/rp-getinvoice2return.js +5 -0
  699. package/server/modules/reports/rp-getinvoice2return_bl.js +6 -0
  700. package/server/modules/reports/rp-getkehoachmh4lenhcp.js +4 -0
  701. package/server/modules/reports/rp-getkhauhao.js +7 -0
  702. package/server/modules/reports/rp-getluong.js +8 -0
  703. package/server/modules/reports/rp-getluongchuyen.js +5 -0
  704. package/server/modules/reports/rp-getpn2fee.js +5 -0
  705. package/server/modules/reports/rp-getpn2return.js +5 -0
  706. package/server/modules/reports/rp-getthanhpham4pnk.js +7 -0
  707. package/server/modules/reports/rp-getvc2xhd.js +11 -0
  708. package/server/modules/reports/rp-gt_cpnvltt.js +6 -0
  709. package/server/modules/reports/rp-hangbanbitralai.js +5 -0
  710. package/server/modules/reports/rp-hangthanhvien.js +3 -0
  711. package/server/modules/reports/rp-hoadonbanhangtheohantt.js +5 -0
  712. package/server/modules/reports/rp-hoadonmuahangtheohantt.js +5 -0
  713. package/server/modules/reports/rp-hoahong.js +15 -0
  714. package/server/modules/reports/rp-kcsns.js +19 -0
  715. package/server/modules/reports/rp-kgchamcong.js +1 -0
  716. package/server/modules/reports/rp-khoaso.js +11 -0
  717. package/server/modules/reports/rp-kiemtrasocaitcvssocai.js +6 -0
  718. package/server/modules/reports/rp-kqdanhgianhanvien.js +5 -0
  719. package/server/modules/reports/rp-kqhdkd.js +1 -0
  720. package/server/modules/reports/rp-lcttgt.js +16 -0
  721. package/server/modules/reports/rp-lctttt.js +11 -0
  722. package/server/modules/reports/rp-linkslist.js +4 -0
  723. package/server/modules/reports/rp-phanbochitienchohoadon.js +11 -0
  724. package/server/modules/reports/rp-phanbothutienchohoadon.js +11 -0
  725. package/server/modules/reports/rp-ptbitralai.js +7 -0
  726. package/server/modules/reports/rp-ptcttct.js +24 -0
  727. package/server/modules/reports/rp-ptdonhang.js +8 -0
  728. package/server/modules/reports/rp-pttct.js +52 -0
  729. package/server/modules/reports/rp-pttctkho.js +32 -0
  730. package/server/modules/reports/rp-pttctkho2.js +29 -0
  731. package/server/modules/reports/rp-referredusers.js +5 -0
  732. package/server/modules/reports/rp-sctbhxh.js +4 -0
  733. package/server/modules/reports/rp-sctcnkh.js +11 -0
  734. package/server/modules/reports/rp-sctdiem.js +3 -0
  735. package/server/modules/reports/rp-sctdt.js +7 -0
  736. package/server/modules/reports/rp-sctdtcp.js +11 -0
  737. package/server/modules/reports/rp-sctluong.js +6 -0
  738. package/server/modules/reports/rp-sctthuetncn.js +4 -0
  739. package/server/modules/reports/rp-scttk.js +9 -0
  740. package/server/modules/reports/rp-sctvt.js +5 -0
  741. package/server/modules/reports/rp-sctvt_sl.js +5 -0
  742. package/server/modules/reports/rp-sctvtnpp.js +6 -0
  743. package/server/modules/reports/rp-sctvttt.js +5 -0
  744. package/server/modules/reports/rp-search.js +4 -0
  745. package/server/modules/reports/rp-socai.js +6 -0
  746. package/server/modules/reports/rp-socaitk.js +1 -0
  747. package/server/modules/reports/rp-sochut.js +7 -0
  748. package/server/modules/reports/rp-sokho.js +7 -0
  749. package/server/modules/reports/rp-sokhott.js +5 -0
  750. package/server/modules/reports/rp-sonkbh.js +5 -0
  751. package/server/modules/reports/rp-sonkc.js +6 -0
  752. package/server/modules/reports/rp-sonkct.js +5 -0
  753. package/server/modules/reports/rp-sonkmh.js +5 -0
  754. package/server/modules/reports/rp-sonktt.js +5 -0
  755. package/server/modules/reports/rp-soquy.js +11 -0
  756. package/server/modules/reports/rp-sosanhkhvatt.js +13 -0
  757. package/server/modules/reports/rp-sosanhkhvatt2.js +5 -0
  758. package/server/modules/reports/rp-sotaisan.js +13 -0
  759. package/server/modules/reports/rp-sotiengui.js +7 -0
  760. package/server/modules/reports/rp-taodinhmuctudkhoc.js +5 -0
  761. package/server/modules/reports/rp-thbanhangkempk.js +28 -0
  762. package/server/modules/reports/rp-thdanhgianhanvien.js +9 -0
  763. package/server/modules/reports/rp-thgt.js +6 -0
  764. package/server/modules/reports/rp-thnxt.js +11 -0
  765. package/server/modules/reports/rp-thnxt_sl.js +9 -0
  766. package/server/modules/reports/rp-thnxtnpp.js +10 -0
  767. package/server/modules/reports/rp-thnxttt.js +9 -0
  768. package/server/modules/reports/rp-tkbanhangtheogioithieu.js +9 -0
  769. package/server/modules/reports/rp-tkgioithieukh.js +4 -0
  770. package/server/modules/reports/rp-tkgtgt.js +76 -0
  771. package/server/modules/reports/rp-tkgtgt_old.js +7 -0
  772. package/server/modules/reports/rp-tmbctc.js +20 -0
  773. package/server/modules/reports/rp-tonghopbanhang.js +6 -0
  774. package/server/modules/reports/rp-tonghopmuahang.js +5 -0
  775. package/server/modules/reports/rp-tonghoptralaihang.js +5 -0
  776. package/server/modules/reports/rp-tongquanbanle.js +20 -0
  777. package/server/modules/reports/rp-tongquanbds.js +3 -0
  778. package/server/modules/reports/rp-tongquancongty.js +6 -0
  779. package/server/modules/reports/rp-tongquanctvnpp.js +12 -0
  780. package/server/modules/reports/rp-tongquannvbh.js +14 -0
  781. package/server/modules/reports/rp-tongquannvnpp.js +5 -0
  782. package/server/modules/reports/rp-uoctinhnvl.js +11 -0
  783. package/server/modules/reports/rp-wallet.js +3 -0
  784. package/server/modules/reports/rpt-tkdiemtichluy.js +9 -0
  785. package/server/modules/systems/sys-app.js +34 -0
  786. package/server/modules/systems/sys-colleague.js +11 -0
  787. package/server/modules/systems/sys-data_list_config.js +1 -0
  788. package/server/modules/systems/sys-domain.js +1 -0
  789. package/server/modules/systems/sys-ecomproductlines.js +1 -0
  790. package/server/modules/systems/sys-exportexceltemplate.js +1 -0
  791. package/server/modules/systems/sys-fieldright.js +1 -0
  792. package/server/modules/systems/sys-importexceltemplate.js +1 -0
  793. package/server/modules/systems/sys-labelinfo.js +4 -0
  794. package/server/modules/systems/sys-listinfo.js +10 -0
  795. package/server/modules/systems/sys-menuinfo.js +4 -0
  796. package/server/modules/systems/sys-message.js +14 -0
  797. package/server/modules/systems/sys-moduleinfo.js +4 -0
  798. package/server/modules/systems/sys-notification.js +8 -0
  799. package/server/modules/systems/sys-quanhuyen.js +1 -0
  800. package/server/modules/systems/sys-reportinfo.js +5 -0
  801. package/server/modules/systems/sys-rptobject.js +1 -0
  802. package/server/modules/systems/sys-schedule.js +10 -0
  803. package/server/modules/systems/sys-sysconfig.js +1 -0
  804. package/server/modules/systems/sys-sysgroup.js +1 -0
  805. package/server/modules/systems/sys-tableinfo.js +1 -0
  806. package/server/modules/systems/sys-templatestore.js +5 -0
  807. package/server/modules/systems/sys-tinhthanh.js +1 -0
  808. package/server/modules/systems/sys-token.js +3 -0
  809. package/server/modules/systems/sys-trangthai.js +3 -0
  810. package/server/modules/systems/sys-trialinfo.js +1 -0
  811. package/server/modules/systems/sys-user.js +45 -0
  812. package/server/modules/systems/sys-users.js +10 -0
  813. package/server/modules/systems/sys-versioninfo.js +1 -0
  814. package/server/modules/systems/sys-vietqrbanks.js +1 -0
  815. package/server/modules/systems/sys-xaphuong.js +1 -0
  816. package/server/modules/vouchers/vo-banggiaban.js +8 -0
  817. package/server/modules/vouchers/vo-bc1.js +34 -0
  818. package/server/modules/vouchers/vo-bc5.js +15 -0
  819. package/server/modules/vouchers/vo-bg1.js +10 -0
  820. package/server/modules/vouchers/vo-bg2.js +12 -0
  821. package/server/modules/vouchers/vo-bn1.js +36 -0
  822. package/server/modules/vouchers/vo-bn5.js +15 -0
  823. package/server/modules/vouchers/vo-dh2.js +35 -0
  824. package/server/modules/vouchers/vo-dinhmucsx.js +6 -0
  825. package/server/modules/vouchers/vo-dkb.js +21 -0
  826. package/server/modules/vouchers/vo-dn0.js +9 -0
  827. package/server/modules/vouchers/vo-dnm.js +20 -0
  828. package/server/modules/vouchers/vo-hd1.js +37 -0
  829. package/server/modules/vouchers/vo-hd2.js +108 -0
  830. package/server/modules/vouchers/vo-hd3.js +38 -0
  831. package/server/modules/vouchers/vo-hd4.js +13 -0
  832. package/server/modules/vouchers/vo-hd7.js +29 -0
  833. package/server/modules/vouchers/vo-hd8.js +29 -0
  834. package/server/modules/vouchers/vo-hde.js +39 -0
  835. package/server/modules/vouchers/vo-htl.js +11 -0
  836. package/server/modules/vouchers/vo-kbbtpb.js +6 -0
  837. package/server/modules/vouchers/vo-kehoachmh.js +11 -0
  838. package/server/modules/vouchers/vo-lenhcapphat.js +9 -0
  839. package/server/modules/vouchers/vo-lenhsx.js +12 -0
  840. package/server/modules/vouchers/vo-pbl.js +94 -0
  841. package/server/modules/vouchers/vo-pc0.js +14 -0
  842. package/server/modules/vouchers/vo-pc1.js +31 -0
  843. package/server/modules/vouchers/vo-pc2.js +25 -0
  844. package/server/modules/vouchers/vo-pc3.js +14 -0
  845. package/server/modules/vouchers/vo-pc5.js +15 -0
  846. package/server/modules/vouchers/vo-pc6.js +19 -0
  847. package/server/modules/vouchers/vo-pcl.js +7 -0
  848. package/server/modules/vouchers/vo-pdn.js +11 -0
  849. package/server/modules/vouchers/vo-pdx.js +9 -0
  850. package/server/modules/vouchers/vo-pgh.js +16 -0
  851. package/server/modules/vouchers/vo-pht.js +6 -0
  852. package/server/modules/vouchers/vo-pkc.js +5 -0
  853. package/server/modules/vouchers/vo-pkh.js +9 -0
  854. package/server/modules/vouchers/vo-pkk.js +12 -0
  855. package/server/modules/vouchers/vo-pkt.js +12 -0
  856. package/server/modules/vouchers/vo-pn1.js +30 -0
  857. package/server/modules/vouchers/vo-pn2.js +17 -0
  858. package/server/modules/vouchers/vo-pn3.js +18 -0
  859. package/server/modules/vouchers/vo-pn5.js +18 -0
  860. package/server/modules/vouchers/vo-pn6.js +18 -0
  861. package/server/modules/vouchers/vo-pn9.js +23 -0
  862. package/server/modules/vouchers/vo-pnc.js +19 -0
  863. package/server/modules/vouchers/vo-pnh.js +17 -0
  864. package/server/modules/vouchers/vo-pnk.js +14 -0
  865. package/server/modules/vouchers/vo-pnknpp.js +12 -0
  866. package/server/modules/vouchers/vo-po1.js +14 -0
  867. package/server/modules/vouchers/vo-ppb.js +8 -0
  868. package/server/modules/vouchers/vo-pt1.js +20 -0
  869. package/server/modules/vouchers/vo-pt5.js +15 -0
  870. package/server/modules/vouchers/vo-ptl.js +8 -0
  871. package/server/modules/vouchers/vo-purchase_contract.js +9 -0
  872. package/server/modules/vouchers/vo-pxc.js +24 -0
  873. package/server/modules/vouchers/vo-pxh.js +18 -0
  874. package/server/modules/vouchers/vo-pxk.js +15 -0
  875. package/server/modules/vouchers/vo-pxknpp.js +14 -0
  876. package/server/modules/vouchers/vo-qts.js +12 -0
  877. package/server/modules/vouchers/vo-sale_contract.js +11 -0
  878. package/server/modules/vouchers/vo-shipbook.js +17 -0
  879. package/server/modules/vouchers/vo-so1.js +125 -0
  880. package/server/modules/vouchers/vo-so5.js +57 -0
  881. package/server/modules/vouchers/vo-so7.js +97 -0
  882. package/server/modules/vouchers/vo-so9.js +119 -0
  883. package/server/modules/vouchers/vo-vanchuyen.js +14 -0
  884. package/server/modules/vouchers/vo-xhd.js +33 -0
@@ -0,0 +1,29 @@
1
+ const PostBook=require("../../libs/post-book"),PostSocai=require("../../libs/post-socai"),Options=global.getModel("options"),Sokho=global.getModel("sokhonpp"),dmvt=global.getModel("dmvt"),dmkho=global.getModel("dmkho"),customer=global.getModel("customer"),trangthai=global.getModel("trangthai"),model=global.getModel("hd8"),controller=require("../../controllers/controller"),ptthanhtoan=global.getModel("ptthanhtoan"),async=require("async"),ma_ct="HD8";
2
+ module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,sort:{ngay_ct:-1,so_ct:-1}});$contr_router$$.route();$contr_router$$.saving=async($cust_kho_npp_kho_npp$$,$obj$$)=>{$obj$$.user_created||($obj$$.user_created=$cust_kho_npp_kho_npp$$.email);$obj$$.of_user="";!$obj$$.ma_kho&&($cust_kho_npp_kho_npp$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,of_user:$cust_kho_npp_kho_npp$$.email}).lean())&&$cust_kho_npp_kho_npp$$.of_user&&
3
+ ($cust_kho_npp_kho_npp$$=await global.getModel("dmkho").findOne({id_app:$obj$$.id_app,user_npp:$cust_kho_npp_kho_npp$$.of_user,la_kho_npp:!0}).lean())&&($obj$$.ma_kho=$cust_kho_npp_kho_npp$$.ma_kho,$obj$$.of_user=$cust_kho_npp_kho_npp$$.user_npp);!$obj$$.of_user&&$obj$$.ma_kho&&($cust_kho_npp_kho_npp$$=await global.getModel("dmkho").findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho,la_kho_npp:!0}).lean())&&($obj$$.of_user=$cust_kho_npp_kho_npp$$.user_npp)};$contr_router$$.post=async function($_obj_details$$,
4
+ $fn$$){let $obj$$={...$_obj_details$$};$fn$$||=function(){};$_obj_details$$=[...$obj$$.details];await $_obj_details$$.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["combo"]});let $data_post_kho$$=$_obj_details$$.map($detail$$=>$detail$$.combo&&$detail$$.combo.length>0?$detail$$.combo.map($item_combo$$=>{$item_combo$$=$item_combo$$.toObject?$item_combo$$.toObject():{...$item_combo$$};$item_combo$$.sl_nhap=$item_combo$$.sl_xuat;delete $item_combo$$.sl_xuat;delete $item_combo$$.tien_xuat;
5
+ delete $item_combo$$.tien_xuat_nt;delete $item_combo$$.px_gia_dd;$item_combo$$.sl_nhap*=$detail$$.sl_nhap;$item_combo$$.tien_nhap=$item_combo$$.tien_nhap_nt=$item_combo$$.sl_nhap*($item_combo$$.gia_von_nt||0);$item_combo$$.tien_hang=$item_combo$$.tien_hang_nt=$item_combo$$.sl_nhap*($item_combo$$.gia_ban_nt||0);$item_combo$$.tien_ck=$item_combo$$.tien_ck_nt=$item_combo$$.sl_nhap*($item_combo$$.tien_ck_nt||0);$item_combo$$.tien=$item_combo$$.tien_nt=$item_combo$$.tien_hang_nt-($item_combo$$.tien_ck_nt||
6
+ 0);return $item_combo$$}):[$detail$$]).reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]),$details_thue$$=$obj$$.details.map($detail$$=>({...$detail$$,thue_suat:($detail$$.ma_thue?$detail$$.thue_suat:$obj$$.thue_suat)||0,ma_thue:$detail$$.ma_thue||$obj$$.ma_thue,tien_thue_nt:$detail$$.tien_thue_nt||0,tien_thue:$detail$$.tien_thue||0})).filter($d$$=>$d$$.ma_thue);await $details_thue$$.filter($r$$=>!$r$$.tk_thue_co&&$r$$.ma_thue).asyncJoinModel2($obj$$.id_app,"vat",{where:"ma_thue",fields:["tk_thue_co"]});async.series({post_sokho:function($callback$$){(new PostBook($obj$$,
7
+ $data_post_kho$$,Sokho,async function($detail$$,$callback$$){$detail$$.nxt=1;$detail$$.tk_co=$obj$$.tk_co;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},post_socainpp:function($callback$$){async.series({options:$callback$$=>{Options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean().exec(function($error$$,$rs$$){$callback$$(null,$rs$$||{})})},kho:$callback$$=>{dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean().exec(($e$$,$kho$$)=>{$callback$$(null,
8
+ $kho$$||{})})},tk:$callback$$=>{$obj$$.details.joinModel2($obj$$.id_app,dmvt,[{where:"ma_vt",fields:[{tk_vt_def:"tk_vt"},{tk_gv_def:"tk_gv"},{tk_tl_def:"tk_tl"},{tk_dt_def:"tk_dt"}]}],function(){$obj$$.details.forEach($d$$=>{$d$$.toObject&&delete $d$$.toObject});$callback$$()})},ptthanhtoan:$callback$$=>{ptthanhtoan.findOne({id_app:$obj$$.id_app,_id:$obj$$.pt_thanh_toan}).lean().exec(($e$$,$pt$$)=>{$callback$$(null,$pt$$||{})})}},async($e$jscomp$3_kho$$,$ma_kh_o_pt$jscomp$1_rs$$)=>{let $option$$=
9
+ $ma_kh_o_pt$jscomp$1_rs$$.options;$e$jscomp$3_kho$$=$ma_kh_o_pt$jscomp$1_rs$$.kho;$ma_kh_o_pt$jscomp$1_rs$$=$ma_kh_o_pt$jscomp$1_rs$$.ptthanhtoan;$option$$.tk_tien=$ma_kh_o_pt$jscomp$1_rs$$.tk_tien||$e$jscomp$3_kho$$.tk_tien||$option$$.tk_tien;$option$$.tk_cn=$ma_kh_o_pt$jscomp$1_rs$$.tk_cn||$e$jscomp$3_kho$$.tk_cn||$option$$.tk_cn;$option$$.tk_dt=$ma_kh_o_pt$jscomp$1_rs$$.tk_dt||$e$jscomp$3_kho$$.tk_dt||$option$$.tk_dt;$option$$.tk_tl=$ma_kh_o_pt$jscomp$1_rs$$.tk_tl||$e$jscomp$3_kho$$.tk_tl||$option$$.tk_tl;
10
+ $option$$.tk_ck=$ma_kh_o_pt$jscomp$1_rs$$.tk_ck||$e$jscomp$3_kho$$.tk_ck||$option$$.tk_ck;$option$$.tk_gv=$ma_kh_o_pt$jscomp$1_rs$$.tk_gv||$e$jscomp$3_kho$$.tk_gv||$option$$.tk_gv;$option$$.tk_vt=$ma_kh_o_pt$jscomp$1_rs$$.tk_vt||$e$jscomp$3_kho$$.tk_vt||$option$$.tk_vt;if($ma_kh_o_pt$jscomp$1_rs$$=$ma_kh_o_pt$jscomp$1_rs$$.ma_kh||$e$jscomp$3_kho$$.ma_kh)$option$$.ma_kh=$ma_kh_o_pt$jscomp$1_rs$$,$option$$.tk_tien=$option$$.tk_cn;const $details_sc$$=[];$details_thue$$.length===0&&$obj$$.t_thue_nt&&
11
+ $obj$$.tk_thue_co?($ma_kh_o_pt$jscomp$1_rs$$={...$obj$$},$ma_kh_o_pt$jscomp$1_rs$$.tk_co=$obj$$.tk_co||$option$$.tk_tien,$ma_kh_o_pt$jscomp$1_rs$$.tk_no=$obj$$.tk_thue_co,$ma_kh_o_pt$jscomp$1_rs$$.tien_nt=Math.abs($obj$$.t_thue_nt),$ma_kh_o_pt$jscomp$1_rs$$.tien=Math.abs($obj$$.t_thue),$ma_kh_o_pt$jscomp$1_rs$$.dien_giai_thue&&($ma_kh_o_pt$jscomp$1_rs$$.dien_giai=$ma_kh_o_pt$jscomp$1_rs$$.dien_giai_thue),$details_sc$$.push($ma_kh_o_pt$jscomp$1_rs$$)):$details_thue$$.forEach($v_vatra$$=>{$v_vatra$$=
12
+ {...$v_vatra$$};$v_vatra$$.tk_co=$obj$$.tk_co||$option$$.tk_tien;$v_vatra$$.tk_no=$v_vatra$$.tk_thue_co;$v_vatra$$.tien_nt=$v_vatra$$.tien_thue_nt;$v_vatra$$.tien=$v_vatra$$.tien_thue;$details_sc$$.push($v_vatra$$)});$obj$$.details.forEach(function($d$jscomp$3_detail$$){$d$jscomp$3_detail$$=Object.assign({},$d$jscomp$3_detail$$);$d$jscomp$3_detail$$.tk_no=$option$$.tk_tl||$d$jscomp$3_detail$$.tk_tl_def;$d$jscomp$3_detail$$.ma_kh||($d$jscomp$3_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$3_detail$$.tk_co=
13
+ $obj$$.tk_co||$option$$.tk_tien;$d$jscomp$3_detail$$.tien_nt=$d$jscomp$3_detail$$.tien_hang_ct_nt-$d$jscomp$3_detail$$.tien_ck_nt;$d$jscomp$3_detail$$.tien=$d$jscomp$3_detail$$.tien_hang_ct-$d$jscomp$3_detail$$.tien_ck;$details_sc$$.push($d$jscomp$3_detail$$)});$obj$$.details.forEach(function($d$jscomp$4_detail$$){$d$jscomp$4_detail$$=Object.assign({},$d$jscomp$4_detail$$);$d$jscomp$4_detail$$.tk_no=$option$$.tk_vt||$d$jscomp$4_detail$$.tk_vt_def;$d$jscomp$4_detail$$.ma_kh||($d$jscomp$4_detail$$.ma_kh=
14
+ $obj$$.ma_kh);$d$jscomp$4_detail$$.tk_co=$option$$.tk_gv||$d$jscomp$4_detail$$.tk_gv_def;$d$jscomp$4_detail$$.tien_nt=$d$jscomp$4_detail$$.tien_nhap_nt;$d$jscomp$4_detail$$.tien=$d$jscomp$4_detail$$.tien_nhap;$details_sc$$.push($d$jscomp$4_detail$$)});$option$$.ma_kh&&$details_sc$$.forEach($d$$=>{$d$$.ma_kh=$option$$.ma_kh});(new PostSocai($obj$$,$details_sc$$,null,global.getModel("socainpp"))).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})},post_socai:function($callback$$){async.series({options:$callback$$=>
15
+ {Options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean().exec(function($error$$,$rs$$){$callback$$(null,$rs$$||{})})},kho:$callback$$=>{dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean().exec(($e$$,$kho$$)=>{$callback$$(null,$kho$$||{})})},tk:$callback$$=>{$obj$$.details.joinModel2($obj$$.id_app,dmvt,[{where:"ma_vt",fields:[{tk_vt_def:"tk_vt"},{tk_gv_def:"tk_gv"},{tk_tl_def:"tk_tl"},{tk_dt_def:"tk_dt"}]}],function(){$obj$$.details.forEach($d$$=>{$d$$.toObject&&delete $d$$.toObject});
16
+ $callback$$()})},ptthanhtoan:$callback$$=>{ptthanhtoan.findOne({id_app:$obj$$.id_app,_id:$obj$$.pt_thanh_toan}).lean().exec(($e$$,$pt$$)=>{$callback$$(null,$pt$$||{})})}},async($e$jscomp$7_kho$$,$ma_kh$jscomp$1_pt$jscomp$3_rs$$)=>{let $option$$=$ma_kh$jscomp$1_pt$jscomp$3_rs$$.options;$e$jscomp$7_kho$$=$ma_kh$jscomp$1_pt$jscomp$3_rs$$.kho;$ma_kh$jscomp$1_pt$jscomp$3_rs$$=$ma_kh$jscomp$1_pt$jscomp$3_rs$$.ptthanhtoan;$option$$.tk_tien=$ma_kh$jscomp$1_pt$jscomp$3_rs$$.tk_tien||$e$jscomp$7_kho$$.tk_tien||
17
+ $option$$.tk_tien;$option$$.tk_cn=$ma_kh$jscomp$1_pt$jscomp$3_rs$$.tk_cn||$e$jscomp$7_kho$$.tk_cn||$option$$.tk_cn;$option$$.tk_dt=$ma_kh$jscomp$1_pt$jscomp$3_rs$$.tk_dt||$e$jscomp$7_kho$$.tk_dt||$option$$.tk_dt;$option$$.tk_tl=$ma_kh$jscomp$1_pt$jscomp$3_rs$$.tk_tl||$e$jscomp$7_kho$$.tk_tl||$option$$.tk_tl;$option$$.tk_ck=$ma_kh$jscomp$1_pt$jscomp$3_rs$$.tk_ck||$e$jscomp$7_kho$$.tk_ck||$option$$.tk_ck;$option$$.tk_gv=$ma_kh$jscomp$1_pt$jscomp$3_rs$$.tk_gv||$e$jscomp$7_kho$$.tk_gv||$option$$.tk_gv;
18
+ $option$$.tk_vt=$ma_kh$jscomp$1_pt$jscomp$3_rs$$.tk_vt||$e$jscomp$7_kho$$.tk_vt||$option$$.tk_vt;if($ma_kh$jscomp$1_pt$jscomp$3_rs$$=$ma_kh$jscomp$1_pt$jscomp$3_rs$$.ma_kh||$e$jscomp$7_kho$$.ma_kh)$option$$.ma_kh=$ma_kh$jscomp$1_pt$jscomp$3_rs$$,$option$$.tk_tien=$option$$.tk_cn;const $details_sc$$=[];(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_ctv&&$r$$.ma_ctv).asyncGroupBy(["ma_ctv","tk_cp_ctv","tk_cn_ctv"],["tien_hoa_hong_ctv"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_co=$r$$.tk_cp_ctv;
19
+ $tt$$.tk_no=$r$$.tk_cn_ctv;$tt$$.ma_kh=$r$$.ma_ctv;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong_ctv;$tt$$.tk_no&&$tt$$.tk_co&&$tt$$.tien&&$details_sc$$.push($tt$$)});(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong&&$r$$.ma_kh_hoa_hong).asyncGroupBy(["ma_kh_hoa_hong","tk_no_hoa_hong","tk_co_hoa_hong"],["tien_hoa_hong"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_co=$r$$.tk_no_hoa_hong;$tt$$.tk_no=$r$$.tk_co_hoa_hong;$tt$$.ma_kh=$r$$.ma_kh_hoa_hong;$tt$$.tien=$tt$$.tien_nt=$r$$.tien_hoa_hong;$tt$$.tien=
20
+ $tt$$.tien_nt*($obj$$.ty_gia||1);$tt$$.check_balance=!1;$tt$$.tk_no&&$tt$$.tk_co&&$tt$$.tien&&$details_sc$$.push($tt$$)});(await $obj$$.details.filter($r$$=>$r$$.tien_hoa_hong_gt&&$r$$.ma_kh_hoa_hong_gt).asyncGroupBy(["ma_kh_hoa_hong_gt","tk_no_hoa_hong_gt","tk_co_hoa_hong_gt"],["tien_hoa_hong_gt"])).forEach($r$$=>{let $tt$$={};$tt$$.tk_co=$r$$.tk_no_hoa_hong_gt;$tt$$.tk_no=$r$$.tk_co_hoa_hong_gt;$tt$$.ma_kh=$r$$.ma_kh_hoa_hong_gt;$tt$$.tien_nt=$r$$.tien_hoa_hong_gt;$tt$$.tien=$tt$$.tien_nt*($obj$$.ty_gia||
21
+ 1);$tt$$.check_balance=!1;$tt$$.tk_no&&$tt$$.tk_co&&$tt$$.tien&&$details_sc$$.push($tt$$)});$option$$.ma_kh&&$details_sc$$.forEach($d$$=>{$d$$.ma_kh=$option$$.ma_kh});(new PostSocai($obj$$,$details_sc$$,null,global.getModel("socai"))).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};const $valid$$=function($i_user$$,$obj$$,$next$$){for($i_user$$=0;$i_user$$<$obj$$.details.length;$i_user$$++){let $detail$$=$obj$$.details[$i_user$$];$detail$$.line=$i_user$$;
22
+ $detail$$.tien_nt=$detail$$.tien_hang_ct_nt-$detail$$.tien_ck_nt+($detail$$.tien_thue_nt||0);$detail$$.tien=$detail$$.tien_hang_ct-$detail$$.tien_ck+($detail$$.tien_thue||0);$obj$$.ma_nt=="VND"&&($detail$$.tien_hang_ct_nt=$detail$$.tien_hang_ct_nt=Math.roundBy($detail$$.tien_hang_ct_nt||0),$detail$$.tien_hang_nt=$detail$$.tien_hang_nt=Math.roundBy($detail$$.tien_hang_nt||0),$detail$$.tien=$detail$$.tien_nt=Math.roundBy($detail$$.tien_nt||0),$detail$$.tien_thue=$detail$$.tien_thue_nt=Math.roundBy($detail$$.tien_thue_nt||
23
+ 0),$detail$$.tien_ck=$detail$$.tien_ck_nt=Math.roundBy($detail$$.tien_ck_nt||0),$detail$$.tien_nhap=$detail$$.tien_nhap_nt=Math.roundBy($detail$$.tien_nhap_nt||0))}$next$$(null,$obj$$)};$contr_router$$.creating=function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$valid$$($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$obj$$)})};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$next$$){$valid$$($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);
24
+ $next$$(null,$data$$,$obj$$)})};$contr_router$$.view=function($user$$,$items$$,$fn$$){const $id_app$$=$user$$.current_id_app;async.series({trangthai:function($callback$$){$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel($id_app$$,customer,[{akey:"ma_kh",bkey:"ma_kh",fields:[{name:"ten_kh",
25
+ value:"ten_kh"}]}],function(){$callback$$()})},dich_vu_giao_hang:function($callback$$){$items$$.filter($item$$=>$item$$.dich_vu_giao_hang).joinModel($id_app$$,customer,[{akey:"dich_vu_giao_hang",bkey:"ma_kh",fields:[{name:"ten_dich_vu_giao_hang",value:"ten_kh"}]}],function(){$callback$$()})},ptthanhtoan:function($callback$$){$items$$.filter($item$$=>$item$$.pt_thanh_toan).joinModel2($id_app$$,ptthanhtoan,[{where:{pt_thanh_toan:"_id"},fields:{ten_pt_thanh_toan:"ten"}}],function(){$callback$$()})},
26
+ t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.details&&($r$$.t_thue_ra=$r$$.details.csum("tien_thue"),$r$$.t_thue_ra_nt=$r$$.details.csum("tien_thue_nt"),$r$$.t_sl=$r$$.details.csum("sl_nhap"),$r$$.t_tien_hang=$r$$.details.csum("tien_hang"),$r$$.t_tien_hang_nt=$r$$.details.csum("tien_hang_nt"),$r$$.t_tien_hang_ct=$r$$.details.csum("tien_hang_ct"),$r$$.t_tien_hang_ct_nt=$r$$.details.csum("tien_hang_ct_nt"),$r$$.t_ck=$r$$.details.csum("tien_ck"),$r$$.t_ck_nt=$r$$.details.csum("tien_ck_nt"),
27
+ $r$$.t_tt=$r$$.t_tien_hang_ct-$r$$.t_ck+$r$$.t_thue_ra,$r$$.t_tt_nt=$r$$.t_tien_hang_ct_nt-$r$$.t_ck_nt+$r$$.t_thue_ra_nt,$r$$.t_tien_nhap=$r$$.details.csum("tien_nhap"),$r$$.t_tien_nhap_nt=$r$$.details.csum("tien_nhap_nt"))});$callback$$()},details_vt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$,dmvt,[{where:"ma_vt",fields:"ten_vt picture chieu_cao chieu_rong chieu_sau trong_luong".split(" ")}],function(){$callback1$$()})},function(){$callback$$()})},
28
+ details_tt1:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($d$$=>$d$$.ma_tt1).joinModel2($id_app$$,"dmtt",[{where:{ma_vt:"ma_vt",ma_tt1:"ma_tt"},setFields:($item$$,$ref$$)=>{$item$$.thuoc_tinh=$ref$$}}],function(){$callback1$$()})},function(){$callback$$()})},details_kho:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_kho).joinModel($id_app$$,dmkho,[{akey:"ma_kho",bkey:"ma_kho",
29
+ fields:[{name:"ten_kho",value:"ten_kho"}]}],function(){$callback1$$()})},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};
@@ -0,0 +1,39 @@
1
+ const PostBook=require("../../libs/post-book"),PostSocai=require("../../libs/post-socai"),Tdttno=global.getModel("tdttno"),Tdttno_tt=global.getModel("tdttno_tt"),Vatra=global.getModel("vatra"),account=global.getModel("account"),customer=global.getModel("customer"),dmnv=global.getModel("dmnv"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),salecontract=global.getModel("sale_contract"),model=global.getModel("hde"),controller=require("../../controllers/controller"),
2
+ trangthai=global.getModel("trangthai"),utils=require("../../libs/utils"),async=require("async"),ma_ct="HDE",App=global.getModel("app"),axios=require("axios"),Moment=require("moment"),{onAfterCommit}=require("../../libs/sessionContext");
3
+ module.exports=function($router$$){const $contr$$=new controller($router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,sort:{ngay_ct:-1,so_ct:-1}});$contr$$.route();$contr$$.post=function($obj$$,$fn$$){$fn$$||=function(){};async.series({post_socai:function($callback$$){const $details_sc$$=[];$obj$$.details.forEach(function($d_detail$$){$d_detail$$={...$d_detail$$};$d_detail$$.tk_co=$d_detail$$.tk_dt;$d_detail$$.ma_kh||($d_detail$$.ma_kh=$obj$$.ma_kh);$d_detail$$.tk_no=$obj$$.tk_no;$details_sc$$.push($d_detail$$)});
4
+ $obj$$.details.forEach(function($d$jscomp$1_detail$$){$d$jscomp$1_detail$$={...$d$jscomp$1_detail$$};$d$jscomp$1_detail$$.tk_no=$d$jscomp$1_detail$$.tk_ck;$d$jscomp$1_detail$$.ma_kh||($d$jscomp$1_detail$$.ma_kh=$obj$$.ma_kh);$d$jscomp$1_detail$$.tk_co=$obj$$.tk_no;$d$jscomp$1_detail$$.tien_nt=$d$jscomp$1_detail$$.tien_ck_nt;$d$jscomp$1_detail$$.tien=$d$jscomp$1_detail$$.tien_ck;$d$jscomp$1_detail$$.check_balance=!1;$details_sc$$.push($d$jscomp$1_detail$$)});const $o$$={...$obj$$};$o$$.tk_co=$o$$.tk_thue_co;
5
+ $o$$.tien_nt=$obj$$.details.csum("tien_thue_nt");$o$$.tien=$obj$$.details.csum("tien_thue");$o$$.dien_giai_thue&&($o$$.dien_giai=$o$$.dien_giai_thue);$details_sc$$.push($o$$);(new PostSocai($obj$$,$details_sc$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},post_tdttno:function($callback$$){account.findOne({tk:$obj$$.tk_no,id_app:$obj$$.id_app},{tk_cn:1},function($error$$,$tk$$){if($error$$)return $callback$$($error$$);$tk$$&&$tk$$.tk_cn===!0?(new PostBook($obj$$,[{...$obj$$}],Tdttno,function($detail$$,
6
+ $callback$$){try{$detail$$.so_hd||($detail$$.so_hd=$obj$$.so_ct),$detail$$.ngay_hd||($detail$$.ngay_hd=$obj$$.ngay_ct),$detail$$.tien_nt=$obj$$.details.csum("tien_nt")-$obj$$.details.csum("tien_ck_nt")+$obj$$.details.csum("tien_thue_nt"),$detail$$.tien=$obj$$.details.csum("tien")-$obj$$.details.csum("tien_ck")+$obj$$.details.csum("tien_thue")}catch($e$$){Logger.error($e$$,$obj$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)}):Tdttno.deleteMany({id_ct:$obj$$._id},function($error$$){$callback$$($error$$)})})},
7
+ post_vatra:function($callback$$){$obj$$.so_hd&&$obj$$.ngay_hd?$obj$$.details.map($detail$$=>({...$detail$$,thue_suat:($detail$$.ma_thue?$detail$$.thue_suat:$obj$$.thue_suat)||0,ma_thue:$detail$$.ma_thue||$obj$$.ma_thue})).filter($d$$=>$d$$.ma_thue).asyncGroupBy(["ma_thue","thue_suat","ten_vt_vat"],"tien_nt tien tien_ck tien_ck_nt tien_thue tien_thue_nt".split(" ")).then($ds$$=>{if($ds$$.length==1){let $tien_thue_nt$$=$ds$$.map($d$$=>$d$$.tien_thue_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0),$tien_thue$$=
8
+ $ds$$.map($d$$=>$d$$.tien_thue||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$tien_thue_nt$$==0&&$tien_thue$$==0&&($tien_thue_nt$$=$obj$$.t_thue_nt||0,$tien_thue$$=$obj$$.t_thue||0);$ds$$[0].tien_thue_nt=$tien_thue_nt$$;$ds$$[0].tien_thue=$tien_thue$$}(new PostBook($obj$$,$ds$$,Vatra,function($detail$$,$callback$$){try{$detail$$.tk_du_thue=$obj$$.tk_no,$detail$$.t_tien_nt=$detail$$.tien_nt-$detail$$.tien_ck_nt,$detail$$.t_tien=$detail$$.tien-$detail$$.tien_ck,$detail$$.t_thue_nt=$detail$$.tien_thue_nt,$detail$$.t_thue=
9
+ $detail$$.tien_thue,$detail$$.ten_vt=$detail$$.ten_vt_vat||$obj$$.ten_vt||$obj$$.dien_giai}catch($e$$){Logger.error($e$$,$obj$$)}$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}):$callback$$()}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};const $valid$$=async($t_thue_nt_user$$,$obj$$,$next$$,$old_obj_t_thue$$)=>{for(var $i_row_dieu_chinh$$=0;$i_row_dieu_chinh$$<$obj$$.details.length;$i_row_dieu_chinh$$++){const $detail$$=$obj$$.details[$i_row_dieu_chinh$$];if(!$detail$$.ma_evoucher)return $next$$("B\u1ea1n ch\u01b0a nh\u1eadp m\u00e3 evoucher");
10
+ var $e$$=await global.getModel("evoucher").findOne({ma:$detail$$.ma_evoucher,for_sell:!0});if(!$e$$)return $next$$("M\u00e3 evoucher "+$detail$$.ma_evoucher+" kh\u00f4ng t\u1ed3n t\u1ea1i ho\u1eb7c kh\u00f4ng \u0111\u1ec3 b\u00e1n");if($e$$.id_ct_used||$e$$.id_ct_useds&&$e$$.id_ct_useds.length>0)return $next$$("M\u00e3 evoucher "+$detail$$.ma_evoucher+" \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng");if(($e$$=await model.findOne({id_app:$t_thue_nt_user$$.current_id_app,"details.ma_evoucher":$detail$$.ma_evoucher}).lean())&&
11
+ $e$$._id!=$old_obj_t_thue$$._id)return $next$$("M\u00e3 evoucher "+$detail$$.ma_evoucher+" \u0111\u00e3 \u0111\u01b0\u1ee3c b\u00e1n");$detail$$.line=$i_row_dieu_chinh$$;$obj$$.ma_nt==="VND"&&($detail$$.tien=$detail$$.tien_nt,$detail$$.tien_ck=$detail$$.tien_ck_nt);$detail$$.tien_ck=$detail$$.tien_ck||0;$detail$$.tien_ck_nt=$detail$$.tien_ck_nt||0;$detail$$.tien=$detail$$.tien||0;$detail$$.tien_nt=$detail$$.tien_nt||0}let $f_tien_nt$$=$obj$$.ma_nt==="VND"?0:2;$obj$$.thue_suat=$obj$$.thue_suat||0;
12
+ $obj$$.details.forEach($detail$$=>{let $thue_suat$$=($detail$$.ma_thue?$detail$$.thue_suat:$obj$$.thue_suat)||0;$detail$$.tien_thue=utils.round(($detail$$.tien-$detail$$.tien_ck)*$thue_suat$$/100,0);$detail$$.tien_thue_nt=utils.round(($detail$$.tien_nt-$detail$$.tien_ck_nt)*$thue_suat$$/100,$f_tien_nt$$)});$obj$$.details.find($r$$=>$r$$.ma_thue)||$obj$$.thue_suat==void 0||($obj$$.t_thue_nt=utils.round(($obj$$.details.csum("tien_nt")-$obj$$.details.csum("tien_ck_nt"))*$obj$$.thue_suat/100,$f_tien_nt$$),
13
+ $obj$$.t_thue=utils.round($obj$$.t_thue_nt*($obj$$.ty_gia||1),0),$t_thue_nt_user$$=$obj$$.details.csum("tien_thue_nt"),$old_obj_t_thue$$=$obj$$.details.csum("tien_thue"),($t_thue_nt_user$$!==$obj$$.t_thue_nt||$old_obj_t_thue$$!==$obj$$.t_thue)&&$obj$$.details.length>0&&($i_row_dieu_chinh$$=$obj$$.details[$obj$$.details.length-1],$i_row_dieu_chinh$$.tien_thue_nt+=$obj$$.t_thue_nt-$t_thue_nt_user$$,$i_row_dieu_chinh$$.tien_thue+=$obj$$.t_thue-$old_obj_t_thue$$));$obj$$.id_contract?salecontract.findOne({_id:$obj$$.id_contract}).lean().exec(($e$$,
14
+ $c$$)=>{$c$$&&($obj$$.ma_hd=$c$$.ma_hd);$next$$(null,$obj$$)}):$next$$(null,$obj$$)};$contr$$.creating=function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$valid$$($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$obj$$.result_export_einvoice=null;$next$$(null,$obj$$)},$obj$$)};$contr$$.created=async function($user$$,$obj$$,$next$$){onAfterCommit(async()=>{let $of_user$$="";$obj$$.ma_kh&&($of_user$$=(await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh}).lean()||
15
+ {}).of_user||"");$obj$$.details.forEach(async $d$$=>{await global.getModel("evoucher").updateOne({id_app:$user$$.current_id_app,ma:$d$$.ma_evoucher},{id_sell:$obj$$._id.toString(),user:$of_user$$}).catch(console.error)})});$next$$(null,$obj$$)};$contr$$.updating=function($user$$,$data$$,$obj$$,$next$$){Tdttno_tt.findOne({id_hd:$obj$$._id,id_app:$obj$$.id_app},function($error$$,$ct_tt$$){if($error$$)return $next$$($error$$);$ct_tt$$?$next$$(`Kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt phi\u1ebfu n\u00e0y do \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n b\u1edfi ${$ct_tt$$.ma_ct||
16
+ "ch\u1ee9ng t\u1eeb"}: ${$ct_tt$$.so_ct}, ng\u00e0y ${Moment($ct_tt$$.ngay_ct).format("DD/MM/YYYY")}`):$valid$$($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)},$obj$$)})};$contr$$.updated=async function($user$$,$obj$$,$next$$){onAfterCommit(async()=>{global.getModel("evoucher").updateMany({id_app:$user$$.current_id_app,id_sell:$obj$$._id.toString()},{id_sell:"",user:""});let $of_user$$="";$obj$$.ma_kh&&($of_user$$=(await customer.findOne({id_app:$obj$$.id_app,
17
+ ma_kh:$obj$$.ma_kh}).lean()||{}).of_user||"");$obj$$.details.forEach(async $d$$=>{await global.getModel("evoucher").updateOne({id_app:$user$$.current_id_app,ma:$d$$.ma_evoucher},{id_sell:$obj$$._id.toString(),user:$of_user$$}).catch(console.error)})});$next$$(null,$obj$$)};$contr$$.deleting=function($user$$,$obj$$,$next$$){Tdttno_tt.findOne({id_hd:$obj$$._id,id_app:$obj$$.id_app},function($error$$,$ct_tt$$){if($error$$)return $next$$($error$$);$ct_tt$$?$next$$(`Kh\u00f4ng th\u1ec3 xo\u00e1 phi\u1ebfu n\u00e0y do \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n b\u1edfi ${$ct_tt$$.ma_ct||
18
+ "ch\u1ee9ng t\u1eeb"}: ${$ct_tt$$.so_ct}, ng\u00e0y ${Moment($ct_tt$$.ngay_ct).format("DD/MM/YYYY")}`):$next$$(null,$obj$$)})};$contr$$.deleted=($user$$,$obj$$,$next$$)=>{global.getModel("evoucher").updateMany({id_app:$user$$.current_id_app,id_sell:$obj$$._id.toString()},{id_sell:"",user:""});$next$$(null,$obj$$)};$contr$$.view=function($user$$,$items$$,$fn$$){const $id_app$$=$user$$.current_id_app;async.parallel({dt:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dt).joinModel($id_app$$,
19
+ dmdt,[{akey:"ma_dt",bkey:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:["ten_kh","email","nh_kh"]}],function(){$callback$$()})},nv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_nv).joinModel($id_app$$,dmnv,[{akey:"ma_nv",bkey:"ma_nv",fields:[{name:"ten_nv",value:"ten_nv"}]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>
20
+ $item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},contract:function($callback$$){$items$$.filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},fields:["ten_hd","ten_hd"]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.details&&($r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tien_nt=$r$$.details.csum("tien_nt"),
21
+ $r$$.t_ck=$r$$.details.csum("tien_ck"),$r$$.t_ck_nt=$r$$.details.csum("tien_ck_nt"),$r$$.t_thue=$r$$.details.csum("tien_thue"),$r$$.t_thue_nt=$r$$.details.csum("tien_thue_nt"),$r$$.t_tt=$r$$.t_tien-$r$$.t_ck+$r$$.t_thue,$r$$.t_tt_nt=$r$$.t_tien_nt-$r$$.t_ck_nt+$r$$.t_thue_nt,$r$$.details.forEach($detail$$=>{$detail$$.dien_giai||($detail$$.dien_giai=$r$$.dien_giai)}))});$callback$$()},details_dt:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>
22
+ $item$$.ma_dt).joinModel($id_app$$,dmdt,[{akey:"ma_dt",bkey:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.mapSeries($items$$,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_hd).joinModel($id_app$$,contract,[{akey:"ma_hd",bkey:"so_hd",fields:[{name:"ten_hd",value:"ten_hd"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapSeries($items$$,
23
+ function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_phi).joinModel($id_app$$,dmphi,[{akey:"ma_phi",bkey:"ma_phi",fields:[{name:"ten_phi",value:"ten_phi"}]}],function(){$callback1$$()})},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})};$contr$$.createRoute("export2viettel/:id_ct",async($req$$,$next$$)=>{try{Logger.info("Export to viettel....");const $id_app$$=$req$$.user.current_id_app,$app$$=await App.findOne({_id:$id_app$$});if(!$app$$)return Logger.info("Kh\u00f4ng tim th\u1ea5y th\u00f4ng tin coogn ty"),
24
+ $next$$("Kh\u00f4ng t\u00ecm th\u1ea5y c\u00f4ng ty n\u00e0y");if(!$app$$.viettel_url_service||!$app$$.viettel_user||!$app$$.viettel_password)return Logger.info("Chua khai bao thong tin ket noi viettel"),$next$$("Th\u00f4ng tin xu\u1ea5t ho\u00e1 \u0111\u01a1n Viettel ch\u01b0a \u0111\u01b0\u1ee3c khai b\u00e1o \u0111\u1ea7y \u0111\u1ee7");if(!$app$$.ma_so_thue)return Logger.info("Chua nhap ma so thue cua cong ty"),$next$$("B\u1ea1n ch\u01b0a nh\u1eadp m\u00e3 s\u1ed1 thu\u1ebf c\u1ee7a c\u00f4ng ty");
25
+ const $ct$$=await model.findOne({id_app:$id_app$$,_id:$req$$.params.id_ct}).lean();if(!$ct$$)return Logger.info("Khong tim thay chung tu"),$next$$("Ch\u1ee9ng t\u1eeb kh\u00f4ng h\u1ee3p l\u1ec7");let $transactionUuid$$=$ct$$._id.toString();try{let $result_export_einvoice$$=await utils.getInvoice($app$$,$transactionUuid$$);if($result_export_einvoice$$){if($result_export_einvoice$$.errorCode)return $next$$($result_export_einvoice$$.data||$result_export_einvoice$$.description);Logger.info("\u0110\u1ed3ng b\u1ed9 hoa \u0111\u01a1n viettel");
26
+ $ct$$.result_export_einvoice=$result_export_einvoice$$;await utils.updateInvoice($contr$$,$ct$$);return $next$$(null,$result_export_einvoice$$)}}catch($e$$){return Logger.error("error export to viettel",$e$$),$next$$($e$$)}if($ct$$.result_export_einvoice&&$ct$$.result_export_einvoice.result&&$ct$$.result_export_einvoice.result.invoiceNo)return $next$$(null,$ct$$.result_export_einvoice);const $kh$$=await customer.findOne({id_app:$id_app$$,ma_kh:$ct$$.ma_kh})||{},$t_tien_hang$$=Math.abs($ct$$.details.map($d$$=>
27
+ $d$$.tien_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0)),$t_ck$$=Math.abs($ct$$.details.map($d$$=>$d$$.tien_ck_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0)),$t_tien$$=Math.abs($ct$$.details.map($d$$=>$d$$.tien_nt-$d$$.tien_ck_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0)),$t_thue$$=Math.abs($ct$$.details.map($d$$=>$d$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0)),$tien_ck_hd$$=$ct$$.tien_ck_hd||0;let $taxBreakdowns$$=$ct$$.details.map($detail$$=>({...$detail$$,ma_thue:$detail$$.ma_thue||$ct$$.ma_thue,thue_suat:($detail$$.ma_thue?
28
+ $detail$$.thue_suat:$ct$$.thue_suat)||0})).filter($d$$=>$d$$.ma_thue);if($taxBreakdowns$$.length===0)return $next$$("B\u1ea1n ch\u01b0a khai b\u00e1o thu\u1ebf");$taxBreakdowns$$=$taxBreakdowns$$.filter($d$$=>$d$$.ma_thue!=="KT"&&$d$$.ma_thue!="KK").map($detail$$=>({taxPercentage:$detail$$.thue_suat,taxableAmount:Math.abs($detail$$.tien_nt-$detail$$.tien_ck_nt),taxAmount:Math.abs($detail$$.tien_thue_nt)}));$taxBreakdowns$$=await $taxBreakdowns$$.asyncGroupBy("taxPercentage",["taxableAmount","taxAmount"]);
29
+ const $data$$={generalInvoiceInfo:{invoiceType:$ct$$.ma_hoa_don||$app$$.ma_hoa_don||"1",templateCode:$ct$$.ky_hieu_hoa_don||$app$$.ky_hieu_hoa_don||"1/001",invoiceSeries:$ct$$.so_seri,transactionUuid:$transactionUuid$$,currencyCode:"VND",adjustmentType:"1",paymentStatus:!0,cusGetInvoiceRight:!0,userName:$ct$$.user_created},buyerInfo:{buyerName:$ct$$.ong_ba||"",buyerLegalName:$ct$$.ten_kh||$kh$$.ten_kh||"",buyerTaxCode:$ct$$.ma_so_thue||$kh$$.ma_so_thue||"",buyerAddressLine:$ct$$.dia_chi||$kh$$.dia_chi||
30
+ "",buyerPostalCode:"",buyerDistrictName:"",buyerCityName:"",buyerCountryCode:"",buyerPhoneNumber:$ct$$.dien_thoai||$kh$$.dien_thoai||"",buyerFaxNumber:"",buyerEmail:$kh$$.email||"",buyerBankName:"",buyerBankAccount:"",buyerIdType:"",buyerIdNo:"",buyerCode:"",buyerBirthDay:""},sellerInfo:{sellerLegalName:$app$$.name,sellerTaxCode:$app$$.ma_so_thue,sellerAddressLine:$app$$.address,sellerPhoneNumber:$app$$.phone||"",sellerEmail:$app$$.email||"",sellerBankName:$app$$.ten_ngan_hang||"",sellerBankAccount:$app$$.tai_khoan_ngan_hang||
31
+ ""},itemInfo:$ct$$.details.map(($detail$$,$index$$)=>{var $JSCompiler_temp_const$$=$detail$$.tien_nt<0?3:1,$JSCompiler_temp_const$jscomp$8$$=($index$$+1).toString(),$JSCompiler_temp_const$jscomp$7$$=$detail$$.dien_giai,$JSCompiler_temp_const$jscomp$6$$=$detail$$.tien_nt<0?"":$detail$$.ma_dvt,$JSCompiler_temp_const$jscomp$5$$=$detail$$.tien_nt<0?void 0:$detail$$.gia_ban_nt,$JSCompiler_temp_const$jscomp$4$$=$detail$$.tien_nt<0?void 0:$detail$$.sl_xuat,$JSCompiler_temp_const$jscomp$3$$=Math.abs($detail$$.tien_nt),
32
+ $JSCompiler_temp_const$jscomp$2$$=$detail$$.ty_le_ck,$JSCompiler_temp_const$jscomp$1$$=Math.abs($detail$$.tien_ck_nt),$JSCompiler_temp_const$jscomp$0$$=Math.abs($detail$$.tien_nt-$detail$$.tien_ck_nt);a:{var $JSCompiler_inline_result$jscomp$10_thue_suat$$=($detail$$.ma_thue?$detail$$.thue_suat:$ct$$.thue_suat)||0;var $tien_ct_nt$$=$detail$$.tien_nt;switch($detail$$.ma_thue||$ct$$.ma_thue){case "KT":$JSCompiler_inline_result$jscomp$10_thue_suat$$=$tien_ct_nt$$<0?void 0:-2;break a;case "KK":$JSCompiler_inline_result$jscomp$10_thue_suat$$=
33
+ $tien_ct_nt$$<0?void 0:-1}}return{lineNumber:$index$$+1,selection:$JSCompiler_temp_const$$,itemCode:$JSCompiler_temp_const$jscomp$8$$,itemName:$JSCompiler_temp_const$jscomp$7$$,unitName:$JSCompiler_temp_const$jscomp$6$$,itemNote:"",unitPrice:$JSCompiler_temp_const$jscomp$5$$,quantity:$JSCompiler_temp_const$jscomp$4$$,itemTotalAmountWithoutTax:$JSCompiler_temp_const$jscomp$3$$,discount:$JSCompiler_temp_const$jscomp$2$$,itemDiscount:$JSCompiler_temp_const$jscomp$1$$,itemTotalAmountAfterDiscount:$JSCompiler_temp_const$jscomp$0$$,
34
+ taxPercentage:$JSCompiler_inline_result$jscomp$10_thue_suat$$,taxAmount:Math.abs($detail$$.tien_thue_nt),itemTotalAmountWithTax:Math.abs($detail$$.tien_nt-$detail$$.tien_ck_nt+$detail$$.tien_thue_nt),customTaxAmount:"0",batchNo:"",expDate:""}}),summarizeInfo:{sumOfTotalLineAmountWithoutTax:$t_tien_hang$$,discountAmount:$t_ck$$,settlementDiscountAmount:$tien_ck_hd$$,totalAmountWithoutTax:$t_tien$$,totalTaxAmount:$t_thue$$,totalAmountWithTax:$t_tien$$+$t_thue$$},taxBreakdowns:$taxBreakdowns$$,payments:[{paymentMethodName:$ct$$.hinh_thuc_tt||
35
+ "TM"}],extAttribute:[],deliveryInfo:{},metadata:[]};$ct$$.ngay_hd||($ct$$.ngay_hd=new Date);let $headers$$,$url$$,$viettel_token$$,$auth$$={username:$app$$.viettel_user.trim(),password:$app$$.viettel_password.trim()};if($app$$.viettel_version!="1"){$data$$.generalInvoiceInfo.invoiceIssuedDate=(new Date($ct$$.ngay_hd)).getTime();let $url_token$$=`${$app$$.viettel_url_service.trim()}/auth/login`;$url$$=$app$$.viettel_direct_issue?`${$app$$.viettel_url_service.trim()}/services/einvoiceapplication/api/InvoiceAPI/InvoiceWS/createInvoice/${$app$$.ma_so_thue.trim()}`:
36
+ `${$app$$.viettel_url_service.trim()}/services/einvoiceapplication/api/InvoiceAPI/InvoiceWS/createOrUpdateInvoiceDraft/${$app$$.ma_so_thue.trim()}`;try{$viettel_token$$=(await axios({method:"post",url:$url_token$$,data:$auth$$})).data.access_token}catch($e$$){Logger.error("error when get token viettel",$auth$$,$url_token$$);let $msg_e$$=$e$$.response?$e$$.response.data:$e$$.message;$msg_e$$&&$msg_e$$.detail&&($msg_e$$.message=$msg_e$$.detail);return $next$$($msg_e$$||$e$$.message||$e$$.error||$e$$)}$headers$$=
37
+ {Cookie:`"access_token":"${$viettel_token$$}"; access_token=${$viettel_token$$}; session_token=${$viettel_token$$}`,"Content-Type":"application/json"};$auth$$=void 0}else $data$$.generalInvoiceInfo.invoiceIssuedDate=Moment($ct$$.ngay_hd).format("YYYY-MM-DD"),$url$$=$app$$.viettel_direct_issue?`${$app$$.viettel_url_service.trim()}/InvoiceAPI/InvoiceWS/createInvoice/${$app$$.ma_so_thue.trim()}`:`${$app$$.viettel_url_service.trim()}/InvoiceAPI/InvoiceWS/createOrUpdateInvoiceDraft/${$app$$.ma_so_thue.trim()}`;
38
+ Logger.info("post to viettel...");axios({method:"post",url:$url$$,data:$app$$.viettel_version!="1"?JSON.stringify($data$$):$data$$,auth:$auth$$,headers:$headers$$}).then(async $data$$=>{$data$$=$data$$.data;Logger.error("result data",$data$$);if(!$data$$)return $next$$("Kh\u00f4ng th\u1ec3 xu\u1ea5t ho\u00e1 \u0111\u01a1n");if($data$$.errorCode)return $next$$($data$$.description);$ct$$.result_export_einvoice=$data$$;$ct$$.so_hd=$ct$$.result_export_einvoice.result.invoiceNo;await model.findOneAndUpdate({_id:$ct$$._id},
39
+ $ct$$);$next$$(null,$data$$)}).catch($e$$=>{Logger.error("error when export invocie viettel",$e$$.response);let $msg_e$$=$e$$.response?$e$$.response.data:$e$$.message;$msg_e$$.data&&($msg_e$$.message=$msg_e$$.data);$msg_e$$.detail&&($msg_e$$.message=$msg_e$$.detail);$next$$($msg_e$$||$e$$.message||$e$$.error||$e$$)})}catch($e$$){Logger.info($e$$),$next$$($e$$.message)}},{method:"GET"})};
@@ -0,0 +1,11 @@
1
+ const PostBook=require("../../libs/post-book"),PostSocai=require("../../libs/post-socai"),Vatvao=global.getModel("vatvao"),Vatra=global.getModel("vatra"),dmdt=global.getModel("dmdt"),customer=global.getModel("customer"),dmnv=global.getModel("dmnv"),contract=global.getModel("contract"),dmphi=global.getModel("dmphi"),dmbp=global.getModel("dmbp"),model=global.getModel("htl"),controller=require("../../controllers/controller"),async=require("async"),ma_ct="HTL",valid_detail=function($i_i$jscomp$1_i$$,
2
+ $obj$$,$fn$$){for($i_i$jscomp$1_i$$=0;$i_i$jscomp$1_i$$<$obj$$.details.length;$i_i$jscomp$1_i$$++){var $detail_vatra_vatvao$$=$obj$$.details[$i_i$jscomp$1_i$$];$detail_vatra_vatvao$$.line=$i_i$jscomp$1_i$$;$obj$$.ma_nt=="VND"&&($detail_vatra_vatvao$$.tien=Math.roundBy($detail_vatra_vatvao$$.tien_nt,0))}if($obj$$.vatvaos)for($i_i$jscomp$1_i$$=0;$i_i$jscomp$1_i$$<$obj$$.vatvaos.length;$i_i$jscomp$1_i$$++)$detail_vatra_vatvao$$=$obj$$.vatvaos[$i_i$jscomp$1_i$$],$detail_vatra_vatvao$$.line=$i_i$jscomp$1_i$$,
3
+ $obj$$.ma_nt=="VND"&&($detail_vatra_vatvao$$.t_thue=Math.roundBy($detail_vatra_vatvao$$.t_thue_nt,0));if($obj$$.vatras)for($i_i$jscomp$1_i$$=0;$i_i$jscomp$1_i$$<$obj$$.vatras.length;$i_i$jscomp$1_i$$++)$detail_vatra_vatvao$$=$obj$$.vatras[$i_i$jscomp$1_i$$],$detail_vatra_vatvao$$.line=$i_i$jscomp$1_i$$,$obj$$.ma_nt=="VND"&&($detail_vatra_vatvao$$.t_thue=Math.roundBy($detail_vatra_vatvao$$.t_thue_nt,0));$fn$$()};
4
+ module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,sort:{ngay_ct:-1,so_ct:-1}});$contr_router$$.route();$contr_router$$.post=function($obj$$,$fn$$){$fn$$||=function(){};async.series({post_vatvao:function($callback$$){(new PostBook($obj$$,$obj$$.vatvaos,Vatvao)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},post_vatra:function($callback$$){(new PostBook($obj$$,$obj$$.vatras,Vatra)).run(function($e$$,$rs$$){$callback$$($e$$,
5
+ $rs$$)})},post_socai:function($callback$$){let $details_sc$$=[];$obj$$.vatvaos.forEach(function($v_vatvao$$){$v_vatvao$$={...$v_vatvao$$};$v_vatvao$$.tk_no=$v_vatvao$$.tk_thue_no;$v_vatvao$$.tk_co=$v_vatvao$$.tk_du_thue;$v_vatvao$$.tien_nt=$v_vatvao$$.t_thue_nt;$v_vatvao$$.tien=$v_vatvao$$.t_thue;$v_vatvao$$.ma_kh=$v_vatvao$$.ma_kh_cn||$v_vatvao$$.ma_kh;$details_sc$$.push($v_vatvao$$)});$obj$$.vatras.forEach(function($v$jscomp$1_vatra$$){$v$jscomp$1_vatra$$={...$v$jscomp$1_vatra$$};$v$jscomp$1_vatra$$.tk_no=
6
+ $v$jscomp$1_vatra$$.tk_du_thue;$v$jscomp$1_vatra$$.tk_co=$v$jscomp$1_vatra$$.tk_thue_co;$v$jscomp$1_vatra$$.tien_nt=$v$jscomp$1_vatra$$.t_thue_nt;$v$jscomp$1_vatra$$.tien=$v$jscomp$1_vatra$$.t_thue;$v$jscomp$1_vatra$$.ma_kh=$v$jscomp$1_vatra$$.ma_kh_cn||$v$jscomp$1_vatra$$.ma_kh;$details_sc$$.push($v$jscomp$1_vatra$$)});$obj$$.details.forEach(function($d$$){$details_sc$$.push({...$d$$})});(new PostSocai($obj$$,$details_sc$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}},function($e$$,$rs$$){$fn$$($e$$,
7
+ $rs$$)})};$contr_router$$.creating=function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);valid_detail($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$obj$$)})};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$next$$){valid_detail($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})};$contr_router$$.view=function($user$$,$items$$,$fn$$){let $id_app$$=$user$$.current_id_app;async.parallel({t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.details&&
8
+ ($r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tien_nt=$r$$.details.csum("tien_nt"));$r$$.vatvaos&&($r$$.t_thue_vao=$r$$.vatvaos.csum("t_thue"),$r$$.t_thue_vao_nt=$r$$.vatvaos.csum("t_thue_nt"));$r$$.vatras&&($r$$.t_thue_ra=$r$$.vatras.csum("t_thue"),$r$$.t_thue_ra_nt=$r$$.vatras.csum("t_thue_nt"))});$callback$$()},details_customer:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_kh_no||$item$$.ma_kh_co).joinModel2($id_app$$,
9
+ customer,[{where:{ma_kh_no:"ma_kh"},fields:{ten_kh_no:"ten_kh"}},{where:{ma_kh_co:"ma_kh"},fields:{ten_kh_co:"ten_kh"}}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,{where:"ma_dt",fields:"ten_dt"},function(){$callback1$$()})},function(){$callback$$()})},details_hopdong:function($callback$$){async.mapLimit($items$$,20,function($r$$,
10
+ $callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,{where:{ma_hd:"so_hd"},fields:"ten_hd"},function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,dmphi,{where:"ma_phi",fields:"ten_phi"},function(){$callback1$$()})},function(){$callback$$()})},details_nv:function($callback$$){async.mapLimit($items$$,
11
+ 20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_nv).joinModel2($id_app$$,dmnv,{where:"ma_nv",fields:"ten_nv"},function(){$callback1$$()})},function(){$callback$$()})},details_bp:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_bp).joinModel2($id_app$$,dmbp,{where:"ma_bp",fields:"ten_bp"},function(){$callback1$$()})},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};
@@ -0,0 +1,6 @@
1
+ const dvcs=global.getModel("dvcs"),account=global.getModel("account"),dmdt=global.getModel("dmdt"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),customer=global.getModel("customer"),dmkho=global.getModel("dmkho"),model=global.getModel("kbbtpb"),controller=require("../../controllers/controller"),async=require("async"),ma_ct="KBBTPB";
2
+ module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,sort:{stt:1}});$contr_router$$.route();$contr_router$$.creating=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$next$$){$next$$(null,$data$$,$obj$$)};$contr_router$$.view=function($user$$,$items$$,$fn$$){const $id_app$$=$user$$.current_id_app;async.parallel({dv:function($callback$$){$items$$.filter($item$$=>
3
+ $item$$.ma_dvcs).joinModel2($id_app$$,dvcs,[{where:{ma_dvcs:"_id"},fields:["ten_dvcs"]}],function(){$callback$$()})},tkco:function($callback$$){$items$$.filter($item$$=>$item$$.tk_co).joinModel2($id_app$$,account,[{where:{tk_co:"tk"},fields:[{ten_tk_co:"ten_tk"}]}],function(){$callback$$()})},details_tk_no:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$,account,[{where:{tk_no:"tk"},fields:[{ten_tk_no:"ten_tk"}]},{where:{tk_no1:"tk"},
4
+ fields:[{ten_tk_no1:"ten_tk"}]},{where:{tk_co1:"tk"},fields:[{ten_tk_co1:"ten_tk"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:"ma_dt",fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||
5
+ []).filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},fields:["ten_hd"]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:"ma_phi",fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})},details_kh:function($callback$$){async.mapLimit($items$$,20,function($r$$,
6
+ $callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:["ten_kh"]}],function(){$callback1$$()})},function(){$callback$$()})},details_kho:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_kho).joinModel2($id_app$$,dmkho,[{where:"ma_kho",fields:["ten_kho"]}],function(){$callback1$$()})},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};
@@ -0,0 +1,11 @@
1
+ const dmvt=global.getModel("dmvt"),dmdt=global.getModel("dmdt"),customer=global.getModel("customer"),lenhsx=global.getModel("lenhsx"),congdoansx=global.getModel("congdoansx"),purchase_contract=global.getModel("purchase_contract"),dnm=global.getModel("dnm"),sale_contract=global.getModel("sale_contract"),model=global.getModel("kehoachmh"),trangthai=global.getModel("trangthai"),Ckvt=require("../../libs/ckvt"),controller=require("../../controllers/controller"),async=require("async"),ma_ct="KEHOACHMH";
2
+ module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,check_stock:!1,sort:{ngay_ct:-1,so_ct:-1}});$contr_router$$.route();const $valid$$=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.creating=function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$valid$$($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$obj$$)})};$contr_router$$.created=function($user$$,
3
+ $obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$next$$){$valid$$($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})};$contr_router$$.updated=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.view=function($user$$,$items$$,$fn$$){let $id_app$$=$user$$.current_id_app;async.parallel({dt:function($callback$$){$items$$.joinModel2($id_app$$,
4
+ dmdt,[{where:"ma_dt",fields:["ten_dt"]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},tinhtongcong:function($callback$$){async.each($items$$,function($r$$,$callback1$$){const $details$$=$r$$.details||[];$r$$.t_sl_nhu_cau=$details$$.csum("sl_nhu_cau");$r$$.t_sl_da_cap_phat=$details$$.csum("sl_da_cap_phat");$r$$.t_sl_ke_hoach=$details$$.csum("sl_ke_hoach");
5
+ $r$$.t_tien_nt=$details$$.csum("tien_nt");$r$$.t_tien=$details$$.csum("tien");$callback1$$()},function(){$callback$$()})},details_vt:function($callback$$){async.each($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$,dmvt,[{where:{ma_vt:"ma_vt"},fields:{ten_vt:"ten_vt"}}],function(){$callback1$$()})},function(){$callback$$()})},details_tonkho:$callback$$=>{async.each($items$$,($r$$,$callback$$)=>{Promise.all(($r$$.details||[]).map($detail$$=>(async()=>{const $condition$$=
6
+ {id_app:$r$$.id_app,ma_vt:$detail$$.ma_vt,ngay:$r$$.ngay_ct};try{let $rs$$=await Ckvt($condition$$);$detail$$.ton=$rs$$.map($r$$=>$r$$.ton00).reduce(($a$$,$b$$)=>$a$$+$b$$,0)}catch($e$$){Logger.error($e$$)}})())).then(()=>{$callback$$()})},function(){$callback$$()})},details_sp:function($callback$$){async.each($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$,dmvt,[{where:{ma_sp:"ma_vt"},fields:{ten_sp:"ten_vt"}}],function(){$callback1$$()})},function(){$callback$$()})},
7
+ details_congdoan:function($callback$$){async.each($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$,congdoansx,[{where:{ma_cong_doan:"ma_cong_doan"},fields:{ten_cong_doan:"ten_cong_doan"}}],function(){$callback1$$()})},function(){$callback$$()})},details_kh:function($callback$$){async.each($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$,customer,[{where:{ma_kh:"ma_kh"},fields:{ten_kh:"ten_kh"}}],function(){$callback1$$()})},function(){$callback$$()})},
8
+ details_ncc:function($callback$$){async.each($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$,customer,[{where:{ma_ncc:"ma_kh"},fields:{ten_ncc:"ten_kh"}}],function(){$callback1$$()})},function(){$callback$$()})},details_lenhsx:function($callback$$){async.each($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$,lenhsx,[{where:{id_lenhsx:"_id"},fields:[{so_ct_lenhsx:"so_ct"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.each($items$$,
9
+ function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$,sale_contract,[{where:{id_contract:"_id"},fields:[{so_ct_contract:"so_ct"}]}],function(){$callback1$$()})},function(){$callback$$()})}},function(){async.mapLimit($items$$,20,($kehoach$$,$callback$$)=>{if(!$kehoach$$.details)return $callback$$();async.series([$callback$$=>{purchase_contract.find({id_kehoachmh:$kehoach$$._id}).lean().exec(($e$$,$contracts$$)=>{async.mapLimit($contracts$$,20,($contract$$,$callback$$)=>{purchase_contract.tinhSoLuongDaNhap($contract$$,
10
+ ($e$$,$_contract$$)=>{$callback$$(null,$_contract$$)})},($e$$,$_contracts$$)=>{$kehoach$$.details.forEach($d$$=>{$d$$.sl_da_nhap=$_contracts$$.map($_contr$$=>$_contr$$.details.filter($_d$$=>$_d$$.ma_vt===$d$$.ma_vt).csum("sl_da_nhap")).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$d$$.sl_contract=$_contracts$$.map($_contr$$=>$_contr$$.details.filter($_d$$=>$_d$$.ma_vt===$d$$.ma_vt).csum("so_luong")).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});$callback$$()})})},$callback$$=>{dnm.find({id_kehoachmh:$kehoach$$._id}).lean().exec(($e$$,
11
+ $dnms$$)=>{$kehoach$$.details.forEach($d$$=>{$d$$.sl_dnm=$dnms$$.map($_dnm$$=>$_dnm$$.details.filter($_d$$=>$_d$$.ma_vt===$d$$.ma_vt).csum("so_luong")).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});$callback$$()})}],()=>{$kehoach$$.t_sl_contract=$kehoach$$.details.csum("sl_contract");$kehoach$$.t_sl_da_nhap=$kehoach$$.details.csum("sl_da_nhap");$kehoach$$.t_sl_dnm=$kehoach$$.details.csum("sl_dnm");$callback$$(null,$kehoach$$)})},()=>{$fn$$(null,$items$$)})})}};
@@ -0,0 +1,9 @@
1
+ const PostBook=require("../../libs/post-book"),dmvt=global.getModel("dmvt"),dmdt=global.getModel("dmdt"),congdoansx=global.getModel("congdoansx"),lenhsx=global.getModel("lenhsx"),sokhocapphat=global.getModel("sokhocapphat"),dmkho=global.getModel("dmkho"),sale_contract=global.getModel("sale_contract"),pxk=global.getModel("pxk"),model=global.getModel("lenhcapphat"),trangthai=global.getModel("trangthai"),controller=require("../../controllers/controller"),async=require("async"),ma_ct="LENHCAPPHAT";
2
+ module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,check_stock:!1,sort:{ngay_ct:-1,so_ct:-1}});$contr_router$$.route();$contr_router$$.post=function($obj$$,$fn$$){$fn$$||=function(){};async.series({post_sokhocapphat:function($callback$$){(new PostBook($obj$$,$obj$$.details,sokhocapphat,function($detail$$,$callback$$){$detail$$.nxt=1;$detail$$.ma_kho=$obj$$.ma_kho||$detail$$.ma_kho;$detail$$.he_so_qd=1;$detail$$.sl_nhap=$detail$$.so_luong;
3
+ $detail$$.sl_nhap_qd=$detail$$.sl_nhap*$detail$$.he_so_qd;$detail$$.id_lenhcapphat=$obj$$._id.toString();$obj$$.ma_gd=="1"&&($detail$$.pn_gia_tb=!1);$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};const $valid$$=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.creating=function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$valid$$($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);
4
+ $next$$(null,$obj$$)})};$contr_router$$.created=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$next$$){$valid$$($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})};$contr_router$$.updated=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.view=function($user$$,$items$$,$fn$$){const $id_app$$=
5
+ $user$$.current_id_app;async.parallel({dt:function($callback$$){$items$$.joinModel($id_app$$,dmdt,[{akey:"ma_dt",bkey:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},kho:function($callback$$){$items$$.joinModel2(null,dmkho,[{where:{ma_kho:"ma_kho"},fields:["ten_kho"]}],function(){$callback$$()})},
6
+ tinhtong:function($callback$$){$items$$.forEach($item$$=>{$item$$.t_sl=($item$$.details||[]).csum("so_luong")});$callback$$()},details_vt:function($callback$$){async.each($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$,dmvt,[{where:"ma_vt",fields:["ten_vt","tk_vt"]}],function(){$callback1$$()})},function(){$callback$$()})},san_pham:function($callback$$){async.each($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$,dmvt,[{where:{ma_sp:"ma_vt"},
7
+ fields:{ten_sp:"ten_vt"}}],function(){$callback1$$()})},function(){$callback$$()})},sale_contract:function($callback$$){$items$$.joinModel2($id_app$$,sale_contract,{where:{id_contract:"_id"},fields:{so_ct_contract:"so_ct"}},function(){$callback$$()})},lenhsx:function($callback$$){$items$$.joinModel2($id_app$$,lenhsx,{where:{id_lenhsx:"_id"},fields:{so_lenh_sx:"so_ct"}},function(){$callback$$()})},congdoansx:function($callback$$){async.each($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$,
8
+ congdoansx,{where:{ma_cong_doan:"ma_cong_doan"},fields:{ten_cong_doan:"ten_cong_doan"}},function(){$callback1$$()})},function(){$callback$$()})}},function(){async.mapLimit($items$$,20,($item$$,$callback$$)=>{pxk.find({id_lenhcapphat:$item$$._id,id_app:$item$$.id_app}).lean().exec(($e$$,$pxks$$)=>{if(!$item$$.details)return $callback$$();$item$$.details.forEach($d$$=>{$d$$.sl_da_xuat=$pxks$$.map($xk$$=>$xk$$.details.filter($_d$$=>$d$$.ma_vt===$_d$$.ma_vt).csum("sl_xuat")).reduce(($a$$,$b$$)=>$a$$+
9
+ $b$$,0)});$item$$.t_sl_da_xuat=$pxks$$.map($xk$$=>$xk$$.details.csum("sl_xuat")).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$callback$$()})},()=>{$fn$$(null,$items$$)})})}};
@@ -0,0 +1,12 @@
1
+ const dvcs=global.getModel("dvcs"),dmvt=global.getModel("dmvt"),dmdt=global.getModel("dmdt"),dmbp=global.getModel("dmbp"),customer=global.getModel("customer"),congdoansx=global.getModel("congdoansx"),dinhmucsx=global.getModel("dinhmucsx"),sale_contract=global.getModel("sale_contract"),model=global.getModel("lenhsx"),Sosanxuat=global.getModel("sosanxuat"),trangthai=global.getModel("trangthai"),controller=require("../../controllers/controller"),PostBook=require("../../libs/post-book"),async=require("async"),
2
+ lenhcapphat=global.getModel("lenhcapphat"),ma_ct="LENHSX";
3
+ module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,check_stock:!1,sort:{ngay_ct:-1,so_ct:-1}});$contr_router$$.route();const $valid$$=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.creating=function($user$$,$obj$$,$next$$){$obj$$.details||($obj$$.details=[]);$valid$$($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$obj$$)})};$contr_router$$.created=function($user$$,
4
+ $obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$next$$){$valid$$($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})};$contr_router$$.updated=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.post=function($obj$$,$fn$$){$fn$$||=function(){};async.series({post_sosanxuat:function($callback$$){let $details$$=
5
+ [];($obj$$.details||[]).forEach($detail$$=>{let $_detail$$={...$detail$$};delete $_detail$$.sl_ht;($_detail$$.cong_doan_sx||[]).forEach($congdoan$$=>{$details$$.push({...$_detail$$,...$congdoan$$,id_lenhsx:$obj$$._id.toString()})})});(new PostBook($obj$$,$details$$,Sosanxuat,function($detail$$,$callback$$){$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr_router$$.view=function($user$$,$items$$,$fn$$){let $id_app$$=$user$$.current_id_app;
6
+ async.parallel({dv:function($callback$$){$items$$.joinModel2($id_app$$,dvcs,[{where:$item$$=>({_id:$item$$.ma_dvcs}),fields:["ten_dvcs"]}],function(){$callback$$()})},cust:function($callback$$){$items$$.filter($i$$=>$i$$.ma_kh).joinModel2($id_app$$,customer,[{where:$item$$=>({ma_kh:$item$$.ma_kh}),fields:["ten_kh"]}],function(){$callback$$()})},dt:function($callback$$){$items$$.filter($i$$=>$i$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:$item$$=>({ma_dt:$item$$.ma_dt}),fields:["ma_dt"]}],function(){$callback$$()})},
7
+ trangthai:function($callback$$){$items$$.joinModel2(null,trangthai,[{where:$item$$=>({ma_trang_thai:$item$$.trang_thai,ma_ct:$item$$.ma_ct}),fields:["ten_trang_thai","color"]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.forEach($r$$=>{$r$$.t_sl=($r$$.details||[]).map($d$$=>$d$$.sl_sx||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)});$callback$$()},details_vt:function($callback$$){async.each($items$$,function($r$$,$callback1$$){($r$$.details||[]).joinModel2($id_app$$,dmvt,[{where:{ma_sp:"ma_vt"},
8
+ fields:[{ten_sp:"ten_vt"},{tk_vt:"tk_vt"}]}],function(){$callback1$$()})},function(){$callback$$()})},sale_contract:function($callback$$){$items$$.filter($i$$=>$i$$.id_contract).joinModel2($id_app$$,sale_contract,{where:{id_contract:"_id"},fields:{so_ct_contract:"so_ct"}},function(){$callback$$()})},capphat:function($callback$$){$items$$.joinModel2($id_app$$,lenhcapphat,{where:{_id:"id_lenhsx"},fields:{id_lenhcapphat:"_id"}},function(){$callback$$()})},dinhmucsx:function($callback$$){async.each($items$$,
9
+ function($r$$,$callback1$$){($r$$.details||[]).filter($i$$=>$i$$.id_dinhmucsx).joinModel2($id_app$$,dinhmucsx,{where:{id_dinhmucsx:"_id"},fields:{so_ct_dinhmucsx:"so_ct"}},function(){$callback1$$()})},function(){$callback$$()})},congdoansx:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback$$){const $id_app$$=$r$$.id_app,$id_lenhsx$$=$r$$._id.toString();async.mapLimit($r$$.details||[],20,($detail$$,$callback$$)=>{const $cong_doan_sx$$=$detail$$.cong_doan_sx||[],$ma_sp$$=$detail$$.ma_sp;
10
+ async.parallel({cd:$callback$$=>{$cong_doan_sx$$.joinModel2(null,trangthai,{where:$item$$=>({ma_trang_thai:$item$$.trang_thai,ma_ct:"CONGDOANSX"}),fields:["ten_trang_thai","color"]},function(){$callback$$()})},tt:$callback$$=>{$cong_doan_sx$$.joinModel2($id_app$$,congdoansx,{where:{ma_cong_doan:"ma_cong_doan"},fields:["ten_cong_doan"]},function(){$callback$$()})},bp:$callback$$=>{$cong_doan_sx$$.joinModel2($id_app$$,dmbp,{where:{ma_bp:"ma_bp"},fields:{ten_bp:"ten_bp"}},function(){$callback$$()})},
11
+ ht:$callback$$=>{const $tinh_sl_ht$$=$cong_doan_sx$$.map($cong_doan$$=>new Promise($resolve$$=>{Sosanxuat.find({id_app:$id_app$$,id_lenhsx:$id_lenhsx$$,ma_sp:$ma_sp$$,ma_cong_doan:$cong_doan$$.ma_cong_doan}).lean().exec(($e$$,$rs$$)=>{$e$$&&Logger.error($e$$);$cong_doan$$.sl_ht=$rs$$.map($s$$=>$s$$.sl_ht||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$resolve$$()})}));Promise.all($tinh_sl_ht$$).then(()=>{$detail$$.sl_ht=$cong_doan_sx$$.filter($c$$=>$c$$.cong_doan_cuoi).map($c$$=>$c$$.sl_ht).reduce(($a$$,$b$$)=>
12
+ $a$$+$b$$,0);$callback$$()})}},()=>{$callback$$()})},()=>{$callback$$()})},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};
@@ -0,0 +1,94 @@
1
+ const async=require("async"),_=require("lodash"),moment=require("moment"),numeral=require("numeral"),PostSokho=require("flexbiz-server/server/libs/post-sokho"),PostBook=require("flexbiz-server/server/libs/post-book"),Options=global.getModel("options"),PostSocai=require("flexbiz-server/server/libs/post-socai"),Sokhott=global.getModel("sokhott"),App=global.getModel("app"),dmkho=global.getModel("dmkho"),dmvt=global.getModel("dmvt"),customer=global.getModel("customer"),dmdt=global.getModel("dmdt"),dmtt=
2
+ global.getModel("dmtt"),Dmban=global.getModel("dmban"),dmphi=global.getModel("dmphi"),contract=global.getModel("contract"),trangthai=global.getModel("trangthai"),model=global.getModel("pbl"),hd7=global.getModel("hd7"),ptthanhtoan=global.getModel("ptthanhtoan"),controller=require("flexbiz-server/server/controllers/controller"),ma_ct="PBL",transaction=global.getModel("transaction"),Evoucher=global.getModel("evoucher"),ckdiem=require("flexbiz-server/server/libs/ckdiem"),dmdiemthuong=global.getModel("dmdiemthuong"),
3
+ currency=global.getModel("currency"),vat=global.getModel("vat"),Wallet=global.getModel("wallet"),dmchietkhauhd=global.getModel("dmchietkhauhd"),dmkhuyenmaihd=global.getModel("dmkhuyenmaihd"),{QRPay}=require("vietnam-qr-pay"),khuyenmaihd=async $obj$$=>{if($obj$$.details){var $ckhds_query_t_tien_hang_ct_nt$$=$obj$$.details.csum("tien_hang_ct_nt")+$obj$$.details.csum("tien_hang_options_ct");if($ckhds_query_t_tien_hang_ct_nt$$!==0){var $hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=$obj$$.details.csum("tien_ck_nt");
4
+ $hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=$ckhds_query_t_tien_hang_ct_nt$$-$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$;$obj$$.details=$obj$$.details.filter($d$$=>$d$$.km_yn_for!="khuyenmaihd");$ckhds_query_t_tien_hang_ct_nt$$={id_app:$obj$$.id_app,gt_tu:{$lte:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$},ma_kho:{$in:[void 0,null,"",$obj$$.ma_kho]}};$ckhds_query_t_tien_hang_ct_nt$$.$and=[{$or:[{gt_den:{$in:[0,void 0,null]}},{gt_den:{$gte:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$}}]}];var $hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$=
5
+ moment($obj$$.ngay_ct).startOf("date").toDate();$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$={$lte:moment($obj$$.ngay_ct).endOf("date").toDate()};$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$={$gte:$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$};$ckhds_query_t_tien_hang_ct_nt$$.hieu_luc_tu=$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$;$ckhds_query_t_tien_hang_ct_nt$$.hieu_luc_den=$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$;$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$={$in:[void 0,null,"",$obj$$.ma_kh]};$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$=
6
+ {$in:[void 0,null,""]};if($obj$$.ma_kh){var $kh_lan_mua_thu$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{nh_kh:1}).lean();$kh_lan_mua_thu$$&&$kh_lan_mua_thu$$.nh_kh&&($hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$={$in:[void 0,null,"",$kh_lan_mua_thu$$.nh_kh]});($kh_lan_mua_thu$$=await model.countDocuments({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,trang_thai:{$in:["5","6"]}}))||($kh_lan_mua_thu$$=0);$kh_lan_mua_thu$$+=1}$ckhds_query_t_tien_hang_ct_nt$$.$or=[{$and:[{ma_kh:$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$},
7
+ {nh_kh:{$in:["",null,void 0]}}]},{$and:[{nh_kh:$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$},{ma_kh:{$in:["",null,void 0]}}]}];$ckhds_query_t_tien_hang_ct_nt$$.ap_dung_lan_mua_thu={$in:[null,void 0,0,void 0]};$ckhds_query_t_tien_hang_ct_nt$$=await dmkhuyenmaihd.find($ckhds_query_t_tien_hang_ct_nt$$).sort({stt_uu_tien:1,gt_tu:-1,ma_kh:-1,nh_kh:-1,hieu_luc_tu:-1}).lean();for($hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$=0;$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$<$ckhds_query_t_tien_hang_ct_nt$$.length;$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$++){let $ckhd$$=
8
+ $ckhds_query_t_tien_hang_ct_nt$$[$hieu_luc_tu_i_q_ma_kh_t_ck_nt_t_tt_nt$$];if($ckhd$$&&$ckhd$$.details_km&&$ckhd$$.details_km.length>0){$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$=$ckhd$$.sl_toi_thieu||0;let $sl_dap_ung$$=0;$hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$&&$ckhd$$.vts&&$ckhd$$.vts.length>0&&$ckhd$$.vts.forEach($vt$$=>{var $ds_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&(!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||
9
+ $vt$$.ma_tt3===$d$$.ma_tt3));if($ds_tien$$.length!=0){var $so_luong$$=$ds_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds_tien$$=$ds_tien$$.map($d$$=>($d$$.tien_hang_ct_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds_tien$$>$vt$$.gt_den||($sl_dap_ung$$+=1)}});if($hieu_luc_den_q_nh_kh_sl_toi_thieu_tu_ngay$$<=$sl_dap_ung$$){$ckhd$$.details_km.forEach($d$$=>
10
+ {$d$$={...$d$$,km_yn_for:"khuyenmaihd"};$d$$.id_cs=$ckhd$$._id.toString();$d$$.sl_xuat=$d$$.sl_km;$d$$.tien_hang_ct_nt=$d$$.tien_hang_ct=$d$$.tien_hang_nt=$d$$.tien_hang=0;$d$$.tien_ck_nt=$d$$.tien_ck=0;$d$$.ty_le_ck=0;$d$$.tien_nt=$d$$.tien=0;$obj$$.details.push($d$$)});break}}}}}},chietkhauhd=async($user$$,$obj$$)=>{if(!$obj$$.signature){$obj$$.details=$obj$$.details||[];var $t_ck_nt$$=$obj$$.details.csum("tien_ck_nt"),$t_tien_hang_ct_nt$$=$obj$$.details.csum("tien_hang_ct_nt")+$obj$$.details.csum("tien_hang_options_ct");
11
+ $user$$.current_app_info&&($user$$.current_app_info.options||{}).tinh_lai_chiet_khau_pbl!=0&&dmchietkhauhd.tinhChietKhau($user$$,$obj$$.id_app,$obj$$,$t_tien_hang_ct_nt$$-$t_ck_nt$$)}},tinhtienthue=($detail$$,$action$$)=>{$action$$=="import"&&$detail$$.tien_thue_nt?$detail$$.tien_thue=$detail$$.tien_thue_nt:($detail$$.thue_suat=$detail$$.thue_suat||0,$detail$$.gia_ban_ct_nt=$detail$$.gia_ban_ct=Math.roundBy($detail$$.gia_ban_nt/(1+$detail$$.thue_suat/100)),$detail$$.tien_hang_ct=$detail$$.tien_hang_ct_nt=
12
+ Math.roundBy($detail$$.sl_xuat*$detail$$.gia_ban_ct_nt),$detail$$.ty_le_ck&&($detail$$.tien_ck_nt=Math.roundBy($detail$$.tien_hang_ct_nt*$detail$$.ty_le_ck/100)),$detail$$.tien_thue=$detail$$.tien_thue_nt=Math.roundBy(($detail$$.tien_hang_ct_nt-$detail$$.tien_ck_nt)*$detail$$.thue_suat/100))},tinhtongtien=$r$$=>{$r$$.details&&($r$$.details.forEach($d$$=>{$d$$.sl_order=$d$$.sl_order||$d$$.sl_xuat}),$r$$.t_sl_order=$r$$.details.csum("sl_order"),$r$$.t_sl=$r$$.details.csum("sl_xuat"),$r$$.t_tien_hang_ct=
13
+ $r$$.details.csum("tien_hang_ct")+$r$$.details.csum("tien_hang_options_ct"),$r$$.t_tien_hang_ct_nt=$r$$.details.csum("tien_hang_ct_nt")+$r$$.details.csum("tien_hang_options_ct"),$r$$.t_thue_nt=$r$$.details.csum("tien_thue_nt")+$r$$.details.csum("tien_thue_options"),$r$$.t_thue=$r$$.details.csum("tien_thue")+$r$$.details.csum("tien_thue_options"),$r$$.t_tien_hang=$r$$.t_tien_hang_ct+$r$$.t_thue,$r$$.t_tien_hang_nt=$r$$.t_tien_hang_ct_nt+$r$$.t_thue_nt,$r$$.t_ck=$r$$.details.csum("tien_ck")+$r$$.tien_ck_hd+
14
+ ($r$$.tien_evoucher||0),$r$$.t_ck_nt=$r$$.details.csum("tien_ck_nt")+$r$$.tien_ck_hd+($r$$.tien_evoucher||0),$r$$.t_tien_nt=$r$$.details.csum("tien_nt"),$r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tt=$r$$.t_tt_nt=$r$$.t_tien_nt-$r$$.t_ck_nt,$r$$.con_no=$r$$.t_tt-($r$$.tien_thu||0)-($r$$.tien_thu2||0)-($r$$.tien_paymentByPoints||0),$r$$.con_no<0&&($r$$.con_no=0),$r$$.t_tien_xuat=$r$$.details.csum("tien_xuat"),$r$$.t_tien_xuat_nt=$r$$.details.csum("tien_xuat_nt"))},taothongtinchuyenkhoan=async($bank_bin$jscomp$1_user$$,
15
+ $r$$)=>{if($r$$.trang_thai!="6"&&$r$$.trang_thai!="9"){var $amount_bank_name_bank_name$$=$r$$.t_tt-($r$$.tien_paymentByPoints||0);if($amount_bank_name_bank_name$$>0&&$r$$.pt_thanh_toan){var $amount$jscomp$2_bank_bin_pttt_pttt$$=await ptthanhtoan.findOne({id_app:$r$$.id_app,_id:$r$$.pt_thanh_toan,payment_service:"bank"}).lean();if($amount$jscomp$2_bank_bin_pttt_pttt$$&&$amount$jscomp$2_bank_bin_pttt_pttt$$.payment_service=="bank"&&$bank_bin$jscomp$1_user$$.current_app_info){$amount_bank_name_bank_name$$=
16
+ ($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_ngan_hang;var $bank_account_number_bank_account_number$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_number||$bank_bin$jscomp$1_user$$.current_app_info.tai_khoan_ngan_hang,$bank_account_name_bank_account_name$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_chu_tai_khoan;$amount$jscomp$2_bank_bin_pttt_pttt$$=
17
+ ($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).so_bin||$bank_bin$jscomp$1_user$$.current_app_info.so_bin;var $amount$jscomp$1_purpose$$=$r$$.t_tt,$purpose_qrcode$$=`TTDH ${$r$$.so_ct} ${$r$$._id.toString()}`;const $qrcode$$=QRPay.initVietQR({bankBin:$amount$jscomp$2_bank_bin_pttt_pttt$$,bankNumber:$bank_account_number_bank_account_number$$,amount:$amount$jscomp$1_purpose$$.toString(),purpose:$purpose_qrcode$$}).build();$r$$.bank_payment_info={bank_name:$amount_bank_name_bank_name$$,bank_bin:$amount$jscomp$2_bank_bin_pttt_pttt$$,
18
+ bank_account_number:$bank_account_number_bank_account_number$$,bank_account_name:$bank_account_name_bank_account_name$$,amount:$amount$jscomp$1_purpose$$,purpose:$purpose_qrcode$$,qrcode:$qrcode$$}}else $r$$.bank_payment_info=void 0}else $r$$.bank_payment_info=void 0;$amount_bank_name_bank_name$$=$r$$.t_tt-($r$$.tien_thu||0)-($r$$.tien_paymentByPoints||0);$amount_bank_name_bank_name$$>0&&$r$$.pt_thanh_toan2?($amount$jscomp$2_bank_bin_pttt_pttt$$=await ptthanhtoan.findOne({id_app:$r$$.id_app,_id:$r$$.pt_thanh_toan2,
19
+ payment_service:"bank"}).lean())&&$amount$jscomp$2_bank_bin_pttt_pttt$$.payment_service=="bank"&&$bank_bin$jscomp$1_user$$.current_app_info?($amount_bank_name_bank_name$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_ngan_hang,$bank_account_number_bank_account_number$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_number||$bank_bin$jscomp$1_user$$.current_app_info.tai_khoan_ngan_hang,$bank_account_name_bank_account_name$$=
20
+ ($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).bank_account_name||$bank_bin$jscomp$1_user$$.current_app_info.ten_chu_tai_khoan,$bank_bin$jscomp$1_user$$=($amount$jscomp$2_bank_bin_pttt_pttt$$.bank_configs||{}).so_bin||$bank_bin$jscomp$1_user$$.current_app_info.so_bin,$amount$jscomp$2_bank_bin_pttt_pttt$$=$r$$.t_tt,$amount$jscomp$1_purpose$$=`TTDH ${$r$$.so_ct} ${$r$$._id.toString()}`,$purpose_qrcode$$=QRPay.initVietQR({bankBin:$bank_bin$jscomp$1_user$$,bankNumber:$bank_account_number_bank_account_number$$,
21
+ amount:$amount$jscomp$2_bank_bin_pttt_pttt$$.toString(),purpose:$amount$jscomp$1_purpose$$}).build(),$r$$.bank_payment_info2={bank_name:$amount_bank_name_bank_name$$,bank_bin:$bank_bin$jscomp$1_user$$,bank_account_number:$bank_account_number_bank_account_number$$,bank_account_name:$bank_account_name_bank_account_name$$,amount:$amount$jscomp$2_bank_bin_pttt_pttt$$,purpose:$amount$jscomp$1_purpose$$,qrcode:$purpose_qrcode$$}):$r$$.bank_payment_info2=void 0:$r$$.bank_payment_info2=void 0}},getPointBalance=
22
+ async($id_app$$,$user$$)=>new Promise(($resolve$$,$reject$$)=>{ckdiem({id_app:$id_app$$,email:$user$$},($e$$,$rs$$)=>{if($e$$)return $reject$$(Error($e$$));$resolve$$($rs$$.length===0?0:$rs$$[0].ton00)})}),createTransactionBonus=async function($obj$$){if($obj$$.trang_thai!=="5")return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"),null;let $kh$$=await customer.findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh}).lean();
23
+ if(!$kh$$)return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"),null;const $receiver$$=$kh$$.of_user||$kh$$.ma_kh;let $lan_mua$$=(await model.find({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh,ngay_ct:{$lte:$obj$$.ngay_ct}})).length+1;let $now$$=moment(new Date).startOf("date").toDate();var $amount$$=$obj$$.details.filter($d$$=>$d$$.tien_hang).map(async $d$$=>{var $amount$$=await dmvt.findOne({ma_vt:$d$$.ma_vt,
24
+ id_app:$obj$$.id_app}).lean(),$ckdiemthuong_ty_le_diem_thuong$$=await dmdiemthuong.find({id_app:$obj$$.id_app,status:!0,ma_kh:{$in:[null,"",$kh$$.ma_kh]},ma_kho:{$in:[null,"",$obj$$.ma_kho]},nh_kh:{$in:[null,"",$kh$$.nh_kh]},hieu_luc_tu:{$lte:$now$$},hieu_luc_den:{$gte:$now$$},ap_dung_lan_mua_thu:{$in:[null,0,$lan_mua$$]},ma_vt:{$in:[null,"",void 0,$d$$.ma_vt]},ma_nvt:{$in:[null,"",void 0,$amount$$?$amount$$.ma_nvt:""]}}).sort({ma_vt:-1,ma_nvt:-1,hieu_luc_tu:-1}).limit(1).lean();return $ckdiemthuong_ty_le_diem_thuong$$.length>
25
+ 0?($amount$$=0,$ckdiemthuong_ty_le_diem_thuong$$[0].tien?($ckdiemthuong_ty_le_diem_thuong$$=$ckdiemthuong_ty_le_diem_thuong$$[0].diem/$ckdiemthuong_ty_le_diem_thuong$$[0].tien)&&($amount$$=Math.roundBy(($d$$.tien_hang-($d$$.tien_ck||0))*$ckdiemthuong_ty_le_diem_thuong$$,0)):$amount$$=$ckdiemthuong_ty_le_diem_thuong$$[0].diem*($d$$.sl_xuat||1),$amount$$):0});if($amount$$=(await Promise.all($amount$$)).reduce(($a$$,$b$$)=>$a$$+$b$$,0)){var $old_trans$$=await transaction.findOne({id_ct:$obj$$._id.toString()+
26
+ ":bonus"});if(!$old_trans$$||$old_trans$$.amount!==$amount$$)return await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i"),await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$obj$$.id_app,receiver_email:$receiver$$,amount:$amount$$,description:"\u0110i\u1ec3m th\u01b0\u1edfng mua h\u00e0ng",otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()+
27
+ ":bonus"}})}else await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng \u0111\u1ec3 t\u00ednh l\u1ea1i")},createTransactionPayment=async function($obj$$,$user_payment$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});let $amount$$=$obj$$.paymentByPoints;$amount$$&&($user_payment$$=$user_payment$$||$obj$$.user_created,await transaction.createTrans({id_app:$obj$$.id_app,sender_email:$user_payment$$,receiver_email:$obj$$.id_app,
28
+ amount:$amount$$,description:"Thanh to\u00e1n cho bill "+$obj$$.so_ct,otherData:{ma_ct:$obj$$.ma_ct,so_ct:$obj$$.so_ct,ngay_ct:$obj$$.ngay_ct,id_ct:$obj$$._id.toString()}}))},checkEvoucher=($user$$,$obj$$)=>{let $gt_don_hang$$=$obj$$.details.csum("tien_nt")-$obj$$.details.csum("tien_ck_nt")-$obj$$.tien_ck_hd;return($obj$$.evouchers||[]).map($ev$$=>new Promise(($resolve$$,$reject$$)=>{(async()=>{var $cust_date_created_id_ct_so_tien_giam$$=($obj$$._id||"").toString();const $_e$$=await Evoucher.findOne({ma:$ev$$.ma,
29
+ id_app:$user$$.current_id_app});if(!$_e$$)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng t\u1ed3n t\u1ea1i`));if($_e$$.id_ct_used&&$_e$$.id_ct_used!==$cust_date_created_id_ct_so_tien_giam$$)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng`));if($_e$$.so_lan_sd>=1&&$_e$$.id_ct_useds&&$_e$$.id_ct_useds.length>0&&($_e$$.id_ct_useds=[...(new Set([...$_e$$.id_ct_useds]))],$_e$$.id_ct_useds.length>=$_e$$.so_lan_sd&&(!$obj$$._id||
30
+ $_e$$.id_ct_useds.indexOf($obj$$._id)<0)))return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng h\u1ebft`));if($_e$$.user){if(!$obj$$.ma_kh)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} n\u00e0y ch\u1ec9 s\u1eed d\u1ee5ng cho m\u1ed9t kh\u00e1ch h\u00e0ng c\u1ee5 th\u1ec3`));$cust_date_created_id_ct_so_tien_giam$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,ma_kh:$obj$$.ma_kh},{of_user:1}).lean();if(!$cust_date_created_id_ct_so_tien_giam$$||
31
+ $cust_date_created_id_ct_so_tien_giam$$.of_user!==$_e$$.user)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng th\u1ec3 \u00e1p d\u1ee5ng cho kh\u00e1ch h\u00e0ng n\u00e0y`))}$cust_date_created_id_ct_so_tien_giam$$=new Date($obj$$.date_created);if(moment($_e$$.hieu_luc_den).endOf("date").toDate().getTime()<$cust_date_created_id_ct_so_tien_giam$$.getTime())return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} \u0111\u00e3 h\u1ebft h\u1ea1n s\u1eed d\u1ee5ng`));if($_e$$.gt_don_hang_toi_thieu&&
32
+ $gt_don_hang$$<$_e$$.gt_don_hang_toi_thieu)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} ch\u1ec9 \u00e1p d\u1ee5ng cho c\u00e1c \u0111\u01a1n h\u00e0ng c\u00f3 gi\u00e1 tr\u1ecb l\u1edbn h\u01a1n ho\u1eb7c b\u1eb1ng ${numeral($_e$$.gt_don_hang_toi_thieu).format()}`));if($_e$$.vts&&$_e$$.vts.length>0&&$_e$$.sl_toi_thieu){let $sl_dap_ung$$=0;$_e$$.vts.forEach($vt$$=>{var $ds$jscomp$1_tien$$=$obj$$.details.filter($d$$=>$d$$.ma_vt===$vt$$.ma_vt&&(!$vt$$.ma_tt1||$vt$$.ma_tt1===$d$$.ma_tt1)&&
33
+ (!$vt$$.ma_tt2||$vt$$.ma_tt2===$d$$.ma_tt2)&&(!$vt$$.ma_tt3||$vt$$.ma_tt3===$d$$.ma_tt3));if($ds$jscomp$1_tien$$.length!=0){var $so_luong$$=$ds$jscomp$1_tien$$.map($d$$=>$d$$.sl_xuat).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ds$jscomp$1_tien$$=$ds$jscomp$1_tien$$.map($d$$=>($d$$.tien_hang_ct_nt||0)-($d$$.tien_ck_nt||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$vt$$.sl_tu&&$so_luong$$<$vt$$.sl_tu||$vt$$.sl_den&&$so_luong$$>$vt$$.sl_den||$vt$$.gt_tu&&$ds$jscomp$1_tien$$<$vt$$.gt_tu||$vt$$.gt_den&&$ds$jscomp$1_tien$$>
34
+ $vt$$.gt_den||($sl_dap_ung$$+=1)}});if($_e$$.sl_toi_thieu>$sl_dap_ung$$)return $reject$$(Error(`Th\u1ebb mua h\u00e0ng ${$ev$$.ma} kh\u00f4ng h\u1ee3p l\u1ec7 do kh\u00f4ng \u0111\u00e1p \u1ee9ng \u0111\u01b0\u1ee3c y\u00eau c\u1ea7u s\u1ea3n ph\u1ea9m`))}$cust_date_created_id_ct_so_tien_giam$$=$_e$$.so_tien;$_e$$.ty_le&&($cust_date_created_id_ct_so_tien_giam$$=Math.roundBy($gt_don_hang$$*$_e$$.ty_le/100));$_e$$.so_tien_max&&$cust_date_created_id_ct_so_tien_giam$$>$_e$$.so_tien_max&&($cust_date_created_id_ct_so_tien_giam$$=
35
+ $_e$$.so_tien_max);$ev$$.so_tien_giam=$cust_date_created_id_ct_so_tien_giam$$;$resolve$$(!0)})()}))},updateEvoucher=async($id_app$jscomp$1_rs$$,$evoucher_code$$,$id_ct$$)=>{$id_ct$$=$id_ct$$.toString();var $e$$=await Evoucher.findOne({ma:$evoucher_code$$,id_app:$id_app$jscomp$1_rs$$});$e$$?($e$$=$e$$.id_ct_useds||[],$e$$.push($id_ct$$),$e$$=[...(new Set($e$$))],$id_app$jscomp$1_rs$$=await Evoucher.updateOne({ma:$evoucher_code$$,id_app:$id_app$jscomp$1_rs$$},{id_ct_useds:$e$$}),Logger.info("update id_ct_useds",
36
+ $evoucher_code$$,$e$$,$id_app$jscomp$1_rs$$)):Logger.error("can't find evoucher",$evoucher_code$$)},deleteEvoucher=async($id_app$jscomp$2_id_ct_useds$$,$evoucher_code$$,$id_ct$$)=>{if($evoucher_code$$){$id_ct$$=$id_ct$$.toString();var $e$jscomp$2_rs$$=await Evoucher.findOne({id_app:$id_app$jscomp$2_id_ct_useds$$,ma:$evoucher_code$$});$e$jscomp$2_rs$$&&($id_app$jscomp$2_id_ct_useds$$=($e$jscomp$2_rs$$.id_ct_useds||[]).filter($ct$$=>$ct$$!==$id_ct$$),$e$jscomp$2_rs$$=await Evoucher.updateOne({_id:$e$jscomp$2_rs$$._id},
37
+ {id_ct_useds:$id_app$jscomp$2_id_ct_useds$$}),Logger.info("update id_ct_useds",$evoucher_code$$,$id_app$jscomp$2_id_ct_useds$$,$e$jscomp$2_rs$$))}},valid=async function($_opt_t_tien_evoucher_user$$,$obj$$,$next$$,$pre_obj_tien_con_lai$$,$options$$={}){$pre_obj_tien_con_lai$$&&($obj$$._id=$pre_obj_tien_con_lai$$._id,$obj$$.details=$obj$$.details||$pre_obj_tien_con_lai$$.details||[],$obj$$.evouchers=$obj$$.evouchers||$pre_obj_tien_con_lai$$.evouchers||[]);$obj$$.details=$obj$$.details||[];if($obj$$.signature&&
38
+ !await Wallet.verifySignature($obj$$.id_app,$obj$$.sign_user,$obj$$.sign_data,$obj$$.signature))return $next$$("Signature is not valid");try{await Promise.all(($obj$$.details||[]).map($detail$$=>(async()=>{if($detail$$.signature&&!await Wallet.verifySignature($obj$$.id_app,$detail$$.sign_user,$detail$$.sign_data,$detail$$.signature))throw"Signature is not valid";})()))}catch($e$$){return $next$$($e$$||$e$$.message)}await $obj$$.details.asyncJoinModel2($obj$$.id_app,vat,{where:"ma_thue",fields:["thue_suat",
39
+ "tk_thue_co","tk_thue_co_treo"]});const $should_tinh_thue$$=!_.isEqual($obj$$.details,$pre_obj_tien_con_lai$$?.details);for(let $i$$=0;$i$$<$obj$$.details.length;$i$$++){const $detail$$=$obj$$.details[$i$$];if($detail$$.line==null||$detail$$.line==void 0)$detail$$.line=(new Date).getTime();$detail$$.tien_hang=$detail$$.tien_hang_nt=Math.roundBy($detail$$.tien_hang_nt);$detail$$.tien_ck=$detail$$.tien_ck_nt=Math.roundBy($detail$$.tien_ck_nt||0);$detail$$.gia_ban=$detail$$.gia_ban_nt;$detail$$.ma_kho=
40
+ $obj$$.ma_kho;$detail$$.tien_xuat=$detail$$.tien_xuat_nt=Math.roundBy($detail$$.tien_xuat_nt||0);$should_tinh_thue$$&&tinhtienthue($detail$$,$options$$?.action);$detail$$.options=$detail$$.options||[];for(let $i_o$$=0;$i_o$$<$detail$$.options.length;$i_o$$++){let $o$$=$detail$$.options[0];$o$$.details=$o$$.details||[];await $o$$.details.filter($d$$=>!$d$$.ma_thue).asyncJoinModel2($_opt_t_tien_evoucher_user$$.current_id_app,dmvt,{where:"ma_vt",fields:["ma_thue"]});await $o$$.details.asyncJoinModel2($obj$$.id_app,
41
+ vat,{where:"ma_thue",fields:["thue_suat","tk_thue_co","tk_thue_co_treo"]});$o$$.details.filter($d$$=>$d$$.sl_xuat).forEach($d$$=>{$d$$.tien_hang=$d$$.tien_hang_nt=$d$$.sl_xuat*($d$$.gia_ban_nt||0);$should_tinh_thue$$&&tinhtienthue($d$$,$options$$?.action)});$o$$.tien_hang_nt=$o$$.details.map($d$$=>$d$$.tien_hang_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$o$$.tien_hang_ct_nt=$o$$.details.map($d$$=>$d$$.tien_hang_ct_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$o$$.tien_thue_nt=$o$$.details.map($d$$=>$d$$.tien_thue_nt).reduce(($a$$,
42
+ $b$$)=>$a$$+$b$$,0)}$detail$$.tien_hang_options=$detail$$.options.map($o$$=>$o$$.tien_hang_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien_hang_options_ct=$detail$$.options.map($o$$=>$o$$.tien_hang_ct_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien_thue_options=$detail$$.options.map($o$$=>$o$$.tien_thue_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.tien=$detail$$.tien_nt=$detail$$.tien_hang_nt+$detail$$.tien_hang_options}await $obj$$.details.filter($d$$=>!$d$$.ma_dvt&&$d$$.ma_tt1).asyncJoinModel2($_opt_t_tien_evoucher_user$$.current_id_app,
43
+ dmtt,{where:{ma_vt:"ma_vt",ma_tt1:"ma_tt"},fields:"ma_dvt"});await $obj$$.details.filter($d$$=>!$d$$.ma_dvt&&$d$$.ma_tt2).asyncJoinModel2($_opt_t_tien_evoucher_user$$.current_id_app,dmtt,{where:{ma_vt:"ma_vt",ma_tt2:"ma_tt"},fields:"ma_dvt"});await $obj$$.details.filter($d$$=>!$d$$.ma_dvt&&$d$$.ma_tt3).asyncJoinModel2($_opt_t_tien_evoucher_user$$.current_id_app,dmtt,{where:{ma_vt:"ma_vt",ma_tt3:"ma_tt"},fields:"ma_dvt"});try{const $_checkEvoucher$$=checkEvoucher($_opt_t_tien_evoucher_user$$,$obj$$,
44
+ $pre_obj_tien_con_lai$$);await Promise.all($_checkEvoucher$$)}catch($e$$){return $next$$($e$$.message)}$_opt_t_tien_evoucher_user$$=$obj$$.evouchers.map($e$$=>$e$$.so_tien_giam||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$pre_obj_tien_con_lai$$=$obj$$.details.map($a$$=>($a$$.tien_hang_ct_nt||0)-($a$$.tien_ck_nt||0)+($a$$.tien_thue_nt||0)+$a$$.tien_hang_options_ct+$a$$.tien_thue_options).reduce(($a$$,$b$$)=>$a$$+$b$$,0)-(($obj$$.tt_tien_thuong||0)+($obj$$.tien_ck_hd||0));$_opt_t_tien_evoucher_user$$>$pre_obj_tien_con_lai$$&&
45
+ ($_opt_t_tien_evoucher_user$$=$pre_obj_tien_con_lai$$);$obj$$.tien_evoucher=$_opt_t_tien_evoucher_user$$;$_opt_t_tien_evoucher_user$$=await Options.findOne({id_app:$obj$$.id_app,id_func:$obj$$.ma_ct.toLowerCase()}).lean();$_opt_t_tien_evoucher_user$$=($_opt_t_tien_evoucher_user$$||{}).option||{};if($obj$$.tien_evoucher&&$_opt_t_tien_evoucher_user$$.phan_bo_evoucher){let $tien_evoucher_da_phan_bo$$=0,$tien_evoucher$$=$obj$$.tien_evoucher,$tien_evoucher_con_lai$$=$tien_evoucher$$-$tien_evoucher_da_phan_bo$$;
46
+ $obj$$.details.forEach($detail$$=>{if($tien_evoucher_con_lai$$>0){var $tien_evoucher_duoc_pb_tien_hang_con_lai$$=$detail$$.tien_hang_ct_nt-($detail$$.tien_ck_nt||0)+($detail$$.tien_thue_nt||0)+$detail$$.tien_hang_options_ct+$detail$$.tien_thue_options;$tien_evoucher_duoc_pb_tien_hang_con_lai$$=$tien_evoucher_con_lai$$>$tien_evoucher_duoc_pb_tien_hang_con_lai$$?$tien_evoucher_duoc_pb_tien_hang_con_lai$$:$tien_evoucher_con_lai$$;$detail$$.tien_evoucher_duoc_pb=$tien_evoucher_duoc_pb_tien_hang_con_lai$$;
47
+ $tien_evoucher_da_phan_bo$$+=$tien_evoucher_duoc_pb_tien_hang_con_lai$$;$tien_evoucher_con_lai$$=$tien_evoucher$$-$tien_evoucher_da_phan_bo$$}else $tien_evoucher_con_lai$$=0})}if($obj$$.paymentByPoints)try{let $he_so_qd$$=await currency.getRate($obj$$.id_app,$obj$$.ma_nt);$obj$$.tien_paymentByPoints=$obj$$.paymentByPoints*$he_so_qd$$}catch($e$$){return $next$$($e$$.message)}$next$$(null,$obj$$)};
48
+ module.exports=function($router$$){const $contr$$=new controller($router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,kiem_tra_han_muc_cong_no:!0,sort:{ngay_ct:-1,so_ct:-1},users_receive_notification_default:[{send_tat_ca_nhan_vien:!0,send_admin:!0}],onFinding:($user$$,$condition$$,$next$$)=>{$next$$(null,$condition$$)}});$contr$$.route();$contr$$.post=async function($obj$$,$fn$$,$_options$$={}){$fn$$||=function(){};await $obj$$.details.asyncJoinModel2($obj$$.id_app,dmvt,{where:"ma_vt",fields:["ten_vt",
49
+ "tk_vt","tg_tk"]});$obj$$.details.filter($d$$=>!$d$$.tg_tk).forEach($d$$=>{$d$$.tien_xuat=$d$$.tien_xuat_nt=0;$d$$.gia_von_nt=$d$$.gia_von=0});$obj$$.t_tien=$obj$$.details.csum("tien");$obj$$.t_tien_nt=$obj$$.details.csum("tien_nt");$obj$$.t_ck_nt=$obj$$.details.csum("tien_ck_nt")+$obj$$.tien_ck_hd+($obj$$.tien_evoucher||0);$obj$$.t_ck=Math.roundBy($obj$$.t_ck_nt*($obj$$.ty_gia||1));$obj$$.t_tien_hang_ct_nt=$obj$$.details.csum("tien_hang_ct_nt")+$obj$$.details.csum("tien_hang_options_ct");$obj$$.t_thue_nt=
50
+ $obj$$.details.csum("tien_thue_nt")+$obj$$.details.csum("tien_thue_options");$obj$$.t_tt_nt=$obj$$.t_tien_hang_ct_nt+$obj$$.t_thue_nt-$obj$$.t_ck_nt;$obj$$.t_tt=Math.roundBy($obj$$.t_tt_nt*($obj$$.ty_gia||1));$obj$$.con_no=$obj$$.t_tt_nt-($obj$$.tien_paymentByPoints||0)-($obj$$.tien_thu||0)-($obj$$.tien_thu2||0);$obj$$.con_no<0&&($obj$$.con_no=0);let $product_details$$=[...$obj$$.details.map($d$$=>({...$d$$}))];$product_details$$.forEach($d$$=>{$d$$={...$d$$};$d$$.promotion&&$d$$.promotion.details_km&&
51
+ $d$$.promotion.details_km.forEach($p$$=>{if($p$$.ma_vt&&$p$$.sl_km){let $_p$$={};_.extend($_p$$,$p$$,{sl_xuat:$p$$.sl_km});$product_details$$.push($_p$$)}});$d$$.combo&&$d$$.combo.length>0&&($d$$.combo.forEach($item$$=>{delete $item$$.px_gia_dd;$item$$.ma_kho=$item$$.ma_kho||$d$$.ma_kho}),$product_details$$=[...$product_details$$,...$d$$.combo]);$d$$.options&&$d$$.options.length>0&&$d$$.options.forEach($ds$jscomp$2_o$$=>{$ds$jscomp$2_o$$=$ds$jscomp$2_o$$.details.filter($d$$=>$d$$.sl_xuat);$ds$jscomp$2_o$$.forEach($item$$=>
52
+ {delete $item$$.px_gia_dd;$item$$.ma_kho=$d$$.ma_kho});$product_details$$=[...$product_details$$,...$ds$jscomp$2_o$$]})});$obj$$.promotion&&$obj$$.promotion.forEach($p$$=>{$p$$={...$p$$};if($p$$.ma_vt&&$p$$.sl_km){let $_p$$={};_.extend($_p$$,$p$$,{sl_xuat:$p$$.sl_km});$product_details$$.push($_p$$)}});$product_details$$=$product_details$$.filter($d$$=>!$d$$.combo||$d$$.combo.length===0);let $du_lieu_kho_kt$$;async.series({post_sokho:function($callback$$){async.series({kho:$callback$$=>{(new PostSokho($obj$$,
53
+ $product_details$$,async function($detail$$,$callback$$){$detail$$={...$detail$$,nxt:2};$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){if($e$$)return $callback$$($e$$);$du_lieu_kho_kt$$=$rs$$?.rs_sokho;$callback$$(null,$rs$$)})},khott:$callback$$=>{(new PostBook($obj$$,$product_details$$,Sokhott,async function($detail$$,$callback$$){$detail$$={...$detail$$,nxt:2};$detail$$.ma_kho=$obj$$.ma_kho;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}},
54
+ ($e$$,$rs$$)=>{$callback$$($e$$,$rs$$)})},post_vatra:function($callback$$){$obj$$.ngay_hd&&$obj$$.so_hd?setImmediate(async()=>{let $details_vatra$$=[];var $d$jscomp$26_ds$$=$product_details$$.map($detail$$=>({...$detail$$,thue_suat:($detail$$.ma_thue?$detail$$.thue_suat:$obj$$.thue_suat)||0,ma_thue:$detail$$.ma_thue||$obj$$.ma_thue,tien_thue_nt:$detail$$.tien_thue_nt||0,tien_thue:$detail$$.tien_thue||0})).filter($d$$=>$d$$.ma_thue);await $d$jscomp$26_ds$$.filter($r$$=>!$r$$.tk_thue_co&&$r$$.ma_thue).asyncJoinModel2($obj$$.id_app,
55
+ "vat",{where:"ma_thue",fields:["tk_thue_co"]});$d$jscomp$26_ds$$=await $d$jscomp$26_ds$$.asyncGroupBy(["ma_thue","thue_suat","ten_vt_vat","tk_thue_co"],"tien_hang_ct_nt tien_hang_ct tien_ck_nt tien_ck tien_thue tien_thue_nt tien_hang_options_ct tien_thue_options".split(" "));$d$jscomp$26_ds$$.forEach($detail$$=>{try{$detail$$.tk_du_thue=$obj$$.tk_no,$detail$$.t_tien_nt=($detail$$.tien_hang_ct_nt||0)+($detail$$.tien_hang_options_ct||0)-($detail$$.tien_ck_nt||0),$detail$$.t_tien=($detail$$.tien_hang_ct||
56
+ 0)+($detail$$.tien_hang_options_ct||0)-($detail$$.tien_ck||0),$detail$$.t_thue_nt=$detail$$.tien_thue_nt+($detail$$.tien_thue_options||0),$detail$$.t_thue=$detail$$.tien_thue+($detail$$.tien_thue_options||0),$detail$$.ten_vt=$detail$$.ten_vt_vat||$obj$$.ten_vt||$obj$$.dien_giai}catch($e$$){Logger.error($e$$,$obj$$)}});$details_vatra$$=[...$details_vatra$$,...$d$jscomp$26_ds$$];(new PostBook($obj$$,$details_vatra$$,global.getModel("vatra"),($detail$$,$callback$$)=>{$detail$$={...$detail$$};$detail$$.ten_vt=
57
+ $detail$$.ten_vt||$obj$$.dien_giai;$callback$$($detail$$)})).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}):$callback$$()},post_socai:function($callback$$){setImmediate(async()=>{try{var $_opt$$=await Options.findOne({id_app:$obj$$.id_app,id_func:ma_ct.toLowerCase()}).lean();let $option$$;$option$$=$_opt$$?$_opt$$.option||{}:{};let $kho$$=await dmkho.findOne({id_app:$obj$$.id_app,ma_kho:$obj$$.ma_kho}).lean()||{},$pt$$;$obj$$.pt_thanh_toan&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan)&&
58
+ ($pt$$=await ptthanhtoan.findOne({id_app:$obj$$.id_app,_id:$obj$$.pt_thanh_toan}).lean());$pt$$=$pt$$||{};$pt$$.tk_tien=$pt$$.tk_tien||$kho$$.tk_tien;$pt$$.tk_cn=$pt$$.tk_cn||$kho$$.tk_cn;$pt$$.tk_dt=$kho$$.tk_dt||$pt$$.tk_dt;$pt$$.tk_gv=$kho$$.tk_gv||$pt$$.tk_gv;$pt$$.tk_ck=$kho$$.tk_ck||$pt$$.tk_ck;$pt$$.ma_kh||($pt$$.ma_kh=$kho$$.ma_kh);$pt$$.ma_kh&&($pt$$.tk_tien=$pt$$.tk_cn);$option$$.tk_tien=$pt$$.tk_tien||$option$$.tk_tien||"1111";$option$$.tk_cn=$pt$$.tk_cn||$option$$.tk_cn||"131111";$option$$.tk_dt=
59
+ $pt$$.tk_dt||$option$$.tk_dt||"51111";$option$$.tk_ck=$pt$$.tk_ck||$option$$.tk_ck||"52111";$option$$.tk_gv=$pt$$.tk_gv||$option$$.tk_gv||"6321";let $details$$=[...$obj$$.details.map($d$$=>({...$d$$}))],$details_ht$$=[];$details$$.forEach($detail$$=>{$detail$$={...$detail$$};let $tien$$=$detail$$.tien_hang_ct+$detail$$.tien_hang_options_ct,$tien_nt$$=$detail$$.tien_hang_ct_nt+$detail$$.tien_hang_options_ct;$detail$$.tk_no=$option$$.tk_tien;$detail$$.tk_co=$option$$.tk_dt;$detail$$.ma_kh||($detail$$.ma_kh=
60
+ $pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tien_nt=$tien_nt$$;$detail$$.tien=$tien$$;$detail$$.flag="DT_"+($detail$$.ma_vt||"");$details_ht$$.push($detail$$)});$details$$.filter($d$$=>$d$$.tien_thue_nt+$d$$.tien_thue_options&&($d$$.tk_thue_co_treo||$d$$.tk_thue_co)).forEach($detail$$=>{$detail$$={...$detail$$};$detail$$.tk_no=$option$$.tk_tien;$detail$$.tk_co=$obj$$.ngay_hd&&$obj$$.so_hd?$detail$$.tk_thue_co:$detail$$.tk_thue_co_treo||$detail$$.tk_thue_co;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||
61
+ $obj$$.ma_kh);$detail$$.tien=$detail$$.tien_nt=$detail$$.tien_thue_nt+$detail$$.tien_thue_options;$detail$$.flag="THUE_"+($detail$$.ma_vt||"");$details_ht$$.push($detail$$)});var $tien_evoucher_con_lai$jscomp$1_tt$$=$obj$$.tien_evoucher||0;$tien_evoucher_con_lai$jscomp$1_tt$$&&($_opt$$={},$_opt$$.tk_no=$obj$$.tk_no_evoucher||$option$$.tk_no_evoucher||$option$$.tk_ck,$_opt$$.tk_co=$obj$$.tk_co_evoucher||$option$$.tk_co_evoucher||$option$$.tk_tien,$_opt$$.tien_nt=$tien_evoucher_con_lai$jscomp$1_tt$$,
62
+ $_opt$$.tien=$_opt$$.tien_nt,$_opt$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh,$_opt$$.check_balance=!1,$details_ht$$.push($_opt$$));var $tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$=($obj$$.tien_ck_hd||0)+$obj$$.details.map($d$$=>$d$$.tien_ck||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$&&($tien_evoucher_con_lai$jscomp$1_tt$$={},$tien_evoucher_con_lai$jscomp$1_tt$$.tk_no=$option$$.tk_ck,$tien_evoucher_con_lai$jscomp$1_tt$$.tk_co=$option$$.tk_tien,$tien_evoucher_con_lai$jscomp$1_tt$$.tien=
63
+ $tien_evoucher_con_lai$jscomp$1_tt$$.tien_nt=$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$,$tien_evoucher_con_lai$jscomp$1_tt$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh,$tien_evoucher_con_lai$jscomp$1_tt$$.check_balance=!1,$details_ht$$.push($tien_evoucher_con_lai$jscomp$1_tt$$));$obj$$.con_no&&$obj$$.ma_kh&&($tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$={},$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$option$$.tk_cn,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_tien,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=
64
+ $obj$$.con_no,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$obj$$.con_no,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh=$obj$$.ma_kh,$details_ht$$.push($tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$));$obj$$.tien_thu&&$pt$$.tk_cn&&$pt$$.tk_cn!==$option$$.tk_tien&&($tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$={},$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$pt$$.tk_cn,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=$option$$.tk_tien,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tien_thu,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tien=
65
+ $obj$$.tien_thu,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh,$details_ht$$.push($tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$));if($obj$$.tien_thu2){let $pt2$$=($obj$$.pt_thanh_toan2&&global.mongoose.Types.ObjectId.isValid($obj$$.pt_thanh_toan2)?await ptthanhtoan.findOne({_id:$obj$$.pt_thanh_toan2}).lean():null)||$pt$$;$pt2$$.tk_cn&&$pt2$$.ma_kh!==$pt$$.ma_kh&&($tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$={},$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tk_no=$pt2$$.tk_cn,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tk_co=
66
+ $option$$.tk_tien,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tien_nt=$obj$$.tien_thu2,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.tien=$obj$$.tien_thu2,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_no=$pt2$$.ma_kh,$tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$.ma_kh_co=$pt$$.ma_kh,$details_ht$$.push($tien_ck_hd_tt$jscomp$2_tt$jscomp$3_tt$$))}let $details_tienvon$$=[];($du_lieu_kho_kt$$||[]).forEach(function($detail$$){$detail$$.toObject&&($detail$$=$detail$$.toObject());$detail$$={...$detail$$};$detail$$.tk_no=
67
+ $option$$.tk_gv||$detail$$.tk_gv;$detail$$.ma_kh||($detail$$.ma_kh=$pt$$.ma_kh||$obj$$.ma_kh);$detail$$.tk_co=$detail$$.tk_vt;$detail$$.tien_nt=$detail$$.tien_xuat_nt;$detail$$.tien=$detail$$.tien_xuat;$detail$$.ma_nt="VND";$detail$$.ty_gia=1;$details_tienvon$$.push($detail$$)});$details_ht$$=$details_ht$$.concat($details_tienvon$$);$details_ht$$.forEach($d$$=>{$d$$.ma_kho=$obj$$.ma_kho});(new PostSocai($obj$$,$details_ht$$,void 0,void 0,$_options$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}catch($e$$){$callback$$($e$$)}})}},
68
+ async function($e$$,$rs$$){if($rs$$)try{$obj$$.details.filter($d$$=>!$d$$.px_gia_dd).forEach($detail$$=>{let $sokhos$$=($du_lieu_kho_kt$$||[]).filter($d$$=>$d$$.ma_vt==$detail$$.ma_vt&&$d$$.ma_tt1==$detail$$.ma_tt1||$d$$.ma_sp==$detail$$.ma_vt&&$d$$.ma_tt1_sp==$detail$$.ma_tt1);$detail$$.tien_xuat_nt=$detail$$.tien_xuat=$sokhos$$.map($s$$=>$s$$.tien_xuat_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$detail$$.sl_xuat&&($detail$$.gia_von_nt=$detail$$.gia_von=Math.round($detail$$.tien_xuat_nt/$detail$$.sl_xuat))}),
69
+ await model.updateOne({_id:$obj$$._id},{details:$obj$$.details})}catch($e$$){return $fn$$($e$$)}$fn$$($e$$,$rs$$)})};$contr$$.saving=async($user$$,$obj$$)=>{$obj$$.details=$obj$$.details||[];await chietkhauhd($user$$.email,$obj$$);await khuyenmaihd($obj$$);tinhtongtien($obj$$);await taothongtinchuyenkhoan($user$$,$obj$$)};$contr$$.creating=async function($user$$,$obj$$,$next$$,$options$$={}){$obj$$.details||($obj$$.details=[]);await $obj$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",
70
+ setFields:($item$$,$ref$$)=>{$item$$.combo=$ref$$.combo||[];$item$$.ma_thue||($item$$.ma_thue=$ref$$.ma_thue)}});$obj$$.details.forEach($detail$$=>{$detail$$.combo&&$detail$$.combo.length>0&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat_1_combo=$item$$.sl_xuat||0;$item$$.sl_xuat=($item$$.sl_xuat_1_combo||0)*($detail$$.sl_xuat||0);$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=
71
+ $item$$.tien_hang_nt=$item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});$obj$$.tien_thu=Math.roundBy($obj$$.tien_thu||0);$obj$$.tien_thu2=Math.roundBy($obj$$.tien_thu2||0);valid($user$$,$obj$$,async $error$$=>{if($error$$)return $next$$($error$$);if(!$obj$$.paymentByPoints)return $next$$(null,$obj$$);try{if(await getPointBalance($user$$.current_id_app,
72
+ $user$$.email)<$obj$$.paymentByPoints)return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 \u0111\u1ee7 \u0111i\u1ec3m \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y.");$next$$(null,$obj$$)}catch($e$$){$next$$($e$$.message)}},null,$options$$)};$contr$$.created=async function($user$$,$obj$$,$next$$){await createTransactionPayment($obj$$);await createTransactionBonus($obj$$);$obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$obj$$.trang_thai==
73
+ "5"&&($obj$$.trang_thai="6",await model.updateOne({_id:$obj$$._id},{trang_thai:"6"}));$next$$(null,$obj$$)};$contr$$.updating=async function($user$$,$data$$,$obj$$,$next$$,$options$$={}){$data$$.details||($data$$.details=$obj$$.details||[]);$data$$.evouchers||($data$$.evouchers=$obj$$.evouchers||[]);await $data$$.details.asyncJoinModel2($user$$.current_id_app,dmvt,{where:"ma_vt",setFields:($item$$,$ref$$)=>{let $old_combo$$=($item$$.combo||[]).map($i$$=>({ma_vt:$i$$.ma_vt,sl_xuat:$i$$.sl_xuat})),
74
+ $new_combo$$=($ref$$.combo||[]).map($i$$=>({ma_vt:$i$$.ma_vt,sl_xuat:$i$$.sl_xuat}));_.isEqual($old_combo$$,$new_combo$$)||($item$$.combo=$ref$$.combo||[]);$item$$.ma_thue||($obj$$.details.find($d$$=>$d$$.ma_vt===$item$$.ma_vt),$item$$.ma_thue=$ref$$.ma_thue)}});$data$$.details.forEach($detail$$=>{$detail$$.combo&&$detail$$.combo.length>0&&($detail$$.combo=$detail$$.combo.map($item$$=>{$item$$=$item$$.toObject?$item$$.toObject():{...$item$$};$item$$.sl_xuat_1_combo==void 0&&($item$$.sl_xuat_1_combo=
75
+ $item$$.sl_xuat||0);$item$$.sl_xuat=($item$$.sl_xuat_1_combo||0)*($detail$$.sl_xuat||0);$item$$.tien_xuat=$item$$.tien_xuat_nt=$item$$.sl_xuat*($item$$.gia_von_nt||0);$item$$.tien_hang=$item$$.tien_hang_nt=$item$$.sl_xuat*($item$$.gia_ban_nt||0);$item$$.tien_ck=$item$$.tien_ck_nt=$item$$.sl_xuat*($item$$.tien_ck_nt||0);$item$$.tien=$item$$.tien_nt=$item$$.tien_hang_nt-($item$$.tien_ck_nt||0);return $item$$}))});$data$$.tien_thu=$data$$.tien_thu==void 0?$obj$$.tien_thu:$data$$.tien_thu;$data$$.tien_thu2=
76
+ $data$$.tien_thu2==void 0?$obj$$.tien_thu2:$data$$.tien_thu2;$data$$.tien_thu=Math.roundBy($data$$.tien_thu||0);$data$$.tien_thu2=Math.roundBy($data$$.tien_thu2||0);$data$$.ma_ban&&$obj$$.ma_ban!==$data$$.ma_ban&&($data$$.ma_ban0=$obj$$.ma_ban);$data$$.details.forEach(function($d$$){$obj$$.details.forEach(function($_d$$){if($_d$$.ma_vt===$d$$.ma_vt&&$_d$$.line===$d$$.line){if($d$$.sl_order==void 0||$d$$.sl_order==null)$d$$.sl_order=$_d$$.sl_order;if($d$$.sl_xuat==void 0||$d$$.sl_xuat==null)$d$$.sl_xuat=
77
+ $_d$$.sl_xuat;$d$$.order_time=$d$$.order_time||$_d$$.order_time||new Date;$d$$.sl_order<=$d$$.sl_xuat?$d$$.finish_time&&$d$$.sl_xuat===$_d$$.sl_xuat||($d$$.finish_time=new Date):$d$$.finish_time=null;let $trang_thai$$=$data$$.trang_thai||$obj$$.trang_thai;$d$$.finish_time||$trang_thai$$!=="5"&&$trang_thai$$!=="6"&&$trang_thai$$!=="9"||($d$$.finish_time=new Date);$_d$$.het_hang&&($d$$.het_hang=!0)}})});valid($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);if($obj$$.paymentByPoints&&
78
+ $obj$$.paymentByPoints!==($data$$.paymentByPoints||0))return $next$$("B\u1ea1n kh\u00f4ng th\u1ec3 c\u1eadp nh\u1eadt s\u1ed1 \u0111i\u1ec3m thanh to\u00e1n.");$data$$.ma_ban&&$obj$$.ma_ban&&$data$$.ma_ban!==$obj$$.ma_ban&&App.emitEvent($obj$$.id_app,"pbl:delete",{_id:$obj$$._id,ma_ban:$obj$$.ma_ban,action:"DELETE",trang_thai:-1});$next$$(null,$data$$,$obj$$)},$obj$$,$options$$)};$contr$$.updated=async function($evouchers_user$$,$obj$$,$next$$){await Evoucher.updateMany({id_ct_used:$obj$$._id.toString(),
79
+ id_app:$obj$$.id_app},{id_ct_used:null});$evouchers_user$$=await Evoucher.find({id_ct_useds:$obj$$._id.toString(),id_app:$obj$$.id_app}).lean();await Promise.all($evouchers_user$$.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$obj$$.trang_thai==="9"?(await transaction.deleteTrans({id_ct:$obj$$._id.toString()}),await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng")):(await createTransactionBonus($obj$$),$obj$$.evouchers&&
80
+ await Promise.all($obj$$.evouchers.map($e$$=>updateEvoucher($e$$.id_app,$e$$.ma,$obj$$._id))));$obj$$.trang_thai=="5"&&($obj$$.trang_thai="6",await model.updateOne({_id:$obj$$._id},{trang_thai:"6"}));$next$$(null,$obj$$)};$contr$$.deleting=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr$$.deleted=async function($user$$,$obj$$,$callback$$){await transaction.deleteTrans({id_ct:$obj$$._id.toString()});await transaction.deleteTrans({id_ct:$obj$$._id.toString()+":bonus"},"Tr\u1ea3 l\u1ea1i \u0111i\u1ec3m th\u01b0\u1edfng");
81
+ $obj$$.evouchers&&await Promise.all($obj$$.evouchers.map($e$$=>deleteEvoucher($e$$.id_app,$e$$.ma,$obj$$._id)));$callback$$(null,$obj$$)};$contr$$.view=function($user$$,$items$$,$fn$$){let $id_app$$=$user$$.current_id_app;$items$$.forEach($item$$=>{$item$$.trang_thai=$item$$.trang_thai.toString();$item$$.evouchers&&($item$$.evouchers_string=$item$$.evouchers.map($e$$=>$e$$.ma).join(","))});async.parallel({cashier:function($callback$$){$items$$.filter($item$$=>$item$$.cashier).joinModel2(null,"user",
82
+ [{where:{cashier:"email"},fields:[{cashier_name:"name"}]}],function(){$callback$$()})},kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:{ma_kh:"ma_kh"},fields:[{ten_kh:"ten_kh"},{nh_kh:"nh_kh"},{dia_chi_kh:"dia_chi"},{dien_thoai_kh:"dien_thoai"}]}],function(){$callback$$()})},ban:function($callback$$){$items$$.filter($item$$=>$item$$.ma_ban).joinModel2($id_app$$,Dmban,[{where:{ma_ban:"ma_ban"},fields:[{ten_ban:"ten_ban"}]}],function(){$callback$$()})},
83
+ ban0:function($callback$$){$items$$.filter($item$$=>$item$$.ma_ban0).joinModel2($id_app$$,Dmban,[{where:{ma_ban0:"ma_ban"},fields:[{ten_ban0:"ten_ban"}]}],function(){$callback$$()})},kho:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kho).joinModel2($id_app$$,dmkho,[{where:{ma_kho:"ma_kho"},fields:["ten_kho","wifi","wifi_pass"],setFields:($a$$,$b$$)=>{$b$$&&$b$$.exfields&&($a$$.dia_chi_kho=$b$$.exfields.dia_chi,$a$$.dien_thoai_kho=$b$$.exfields.dien_thoai)}}],function(){$callback$$()})},
84
+ hd7:function($callback$$){$items$$.joinModel2($id_app$$,hd7,[{where:{_id:"id_pbl"},fields:[{id_hd7:"_id"},{so_ct_hd7:"so_ct"},{ngay_ct_hd7:"ngay_ct"}]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},ptthanhtoan:function($callback$$){$items$$.filter($item$$=>$item$$.pt_thanh_toan).joinModel2($id_app$$,
85
+ ptthanhtoan,[{where:{pt_thanh_toan:"_id"},fields:{ten_pt_thanh_toan:"ten"}}],function(){$callback$$()})},ptthanhtoan2:function($callback$$){$items$$.filter($item$$=>$item$$.pt_thanh_toan2).joinModel2($id_app$$,ptthanhtoan,[{where:{pt_thanh_toan2:"_id"},fields:{ten_pt_thanh_toan2:"ten"}}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.details&&($r$$.details.forEach($d$$=>{$d$$.sl_order=$d$$.sl_order||$d$$.sl_xuat;$d$$.sl_order<=$d$$.sl_xuat?$d$$.finish_time||
86
+ ($d$$.finish_time=new Date):$d$$.finish_time=null}),tinhtongtien($r$$))});$callback$$()},details_vt:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_vt).joinModel2($id_app$$,dmvt,[{where:{ma_vt:"ma_vt"},fields:[{ten_vt:"ten_vt"},{picture:"picture"},{sp_yeu_cau_che_bien:"sp_yeu_cau_che_bien",sp_yeu_cau_pha_che:"sp_yeu_cau_pha_che"},{gia_ban_le_goc:"gia_ban_le"},{barcode:"ma_vt2",ma_can:"ma_can"}]}],function(){$callback1$$()})},
87
+ function(){$callback$$()})},details_dt:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:{ma_dt:"ma_dt"},fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_contract:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},
88
+ fields:[{ten_hd:"ten_hd"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:{ma_phi:"ma_phi"},fields:[{name:"ten_phi",value:"ten_phi"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_chietkhau:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>
89
+ $item$$.id_cs_ck).joinModel2(null,"dmchietkhau",[{where:$item$$=>({id_app:$r$$.id_app,_id:$item$$.id_cs_ck}),fields:["ma_chietkhau","ten_chietkhau"]}],function(){$callback1$$()})},function(){$callback$$()})}},function(){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_tt1).joinModel2($id_app$$,dmtt,[{where:{ma_vt:"ma_vt",ma_tt1:"ma_tt"},setFields:($item$$,$ref$$)=>{$item$$.ten_vt=$item$$.ten_vt+" - "+$ref$$.ten_tt;$item$$.barcode=$ref$$.ma_tt2||
90
+ $item$$.barcode;$item$$.ma_can=$ref$$.ma_can||$item$$.ma_can}}],function(){$callback1$$()})},function(){$fn$$(null,$items$$)})})};$contr$$.createRoute("payment/:id",async($req$$,$next$$)=>{var $id_obj$$=$req$$.params.id;if(!global.mongoose.Types.ObjectId.isValid($id_obj$$))return $next$$("Bill kh\u00f4ng t\u1ed3n t\u1ea1i");$id_obj$$=await model.findOne({_id:$id_obj$$});if(!$id_obj$$)return $next$$("Bill kh\u00f4ng t\u1ed3n t\u1ea1i");var $t_tien$$=$id_obj$$.details.map($r$$=>$r$$.tien_hang||0).reduce(($a$$,
91
+ $b$$)=>$a$$+$b$$,0);let $t_ck$$=$id_obj$$.details.map($r$$=>$r$$.tien_ck||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($id_obj$$.tien_ck_hd||0)+($id_obj$$.tien_evoucher||0);$t_tien$$=$t_tien$$-$t_ck$$-($id_obj$$.tien_paymentByPoints||0)-($id_obj$$.tien_thu||0)-($id_obj$$.tien_thu2||0);if($id_obj$$.trang_thai==="5"||$id_obj$$.trang_thai==="6"||!$t_tien$$)return $next$$("Bill n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n");try{var $he_so_qd$$=await currency.getRate($id_obj$$.id_app,$id_obj$$.ma_nt);
92
+ if(!$he_so_qd$$)return $next$$("Ch\u01b0a khai bao h\u1ec7 s\u1ed1 quy \u0111\u1ed5i v\u1edbi lo\u1ea1i ti\u1ec1n "+$id_obj$$.ma_nt);$he_so_qd$$=$t_tien$$/$he_so_qd$$;if(await getPointBalance($req$$.user.current_id_app,$req$$.user.email)<$he_so_qd$$)return $next$$("B\u1ea1n kh\u00f4ng c\u00f3 \u0111\u1ee7 \u0111i\u1ec3m \u0111\u1ec3 th\u1ef1c hi\u1ec7n giao d\u1ecbch n\u00e0y.");$id_obj$$.paymentByPoints=$he_so_qd$$;$id_obj$$.tien_paymentByPoints=$t_tien$$;await createTransactionPayment($id_obj$$,
93
+ $req$$.user.email);$id_obj$$.con_no=0;$id_obj$$.trang_thai="6";tinhtongtien($id_obj$$);await $id_obj$$.save();const $obj_updated$$=await model.findOne({_id:$id_obj$$._id}).lean();controller.postData($id_obj$$,$contr$$,async function($e$$){if($e$$)return $next$$($e$$);$e$$=await $contr$$.asyncView($req$$.user,[$obj_updated$$],{req:$req$$});controller.pushNotification($contr$$,$e$$[0],"update");controller.pushNotification($contr$$,$e$$[0],"payment",null,!1,{title:`Bill ${$obj_updated$$.so_ct} \u0111\u00e3 \u0111\u01b0\u1ee3c thanh to\u00e1n`});
94
+ $next$$(null,{rs:"B\u1ea1n \u0111\u00e3 thanh to\u00e1n th\u00e0nh c\u00f4ng"})})}catch($e$$){$next$$($e$$.message)}},{method:"GET"})};
@@ -0,0 +1,14 @@
1
+ const dvcs=global.getModel("dvcs"),account=global.getModel("account"),dmdt=global.getModel("dmdt"),customer=global.getModel("customer"),dmnv=global.getModel("dmnv"),dmbp=global.getModel("dmbp"),contract=global.getModel("contract"),dmphi=global.getModel("dmphi"),model=global.getModel("pc0"),pc1=global.getModel("pc1"),trangthai=global.getModel("trangthai"),controller=require("../../controllers/controller"),async=require("async"),ma_ct="PC0",valid_detail=function($i_i$jscomp$1_i$$,$obj$$,$fn$$){if($obj$$.details)for($i_i$jscomp$1_i$$=
2
+ 0;$i_i$jscomp$1_i$$<$obj$$.details.length;$i_i$jscomp$1_i$$++){var $detail_tdttco_vatvao$$=$obj$$.details[$i_i$jscomp$1_i$$];$detail_tdttco_vatvao$$.line=$i_i$jscomp$1_i$$;$obj$$.ma_nt=="VND"&&($detail_tdttco_vatvao$$.tien=$detail_tdttco_vatvao$$.tien_nt)}if($obj$$.vatvaos)for($i_i$jscomp$1_i$$=0;$i_i$jscomp$1_i$$<$obj$$.vatvaos.length;$i_i$jscomp$1_i$$++)$detail_tdttco_vatvao$$=$obj$$.vatvaos[$i_i$jscomp$1_i$$],$detail_tdttco_vatvao$$.line=$i_i$jscomp$1_i$$,$obj$$.ma_nt=="VND"&&($detail_tdttco_vatvao$$.t_thue=
3
+ $detail_tdttco_vatvao$$.t_thue_nt);if($obj$$.tdttcos)for($i_i$jscomp$1_i$$=0;$i_i$jscomp$1_i$$<$obj$$.tdttcos.length;$i_i$jscomp$1_i$$++)$detail_tdttco_vatvao$$=$obj$$.tdttcos[$i_i$jscomp$1_i$$],$detail_tdttco_vatvao$$.line=$i_i$jscomp$1_i$$,$obj$$.ma_nt=="VND"&&($detail_tdttco_vatvao$$.tien=$detail_tdttco_vatvao$$.tien_nt);$fn$$(null,$obj$$)};
4
+ module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,sort:{ngay_ct:-1,so_ct:-1},onExport:($user$$,$obj$$,$next$$)=>{$obj$$.tdttcos&&$obj$$.tdttcos.length>0&&($obj$$.details=$obj$$.tdttcos);$next$$()}});$contr_router$$.route();$contr_router$$.creating=function($user$$,$obj$$,$next$$){if(!($obj$$.details&&$obj$$.details.csum("tien_nt")!=0||$obj$$.tdttcos&&$obj$$.tdttcos.csum("tien_nt")!=0))return $next$$("B\u1ea1n ch\u01b0a nh\u1eadp chi ti\u1ebft \u0111\u1ec1 ngh\u1ecb thanh to\u00e1n");
5
+ $obj$$.id_pc1="";valid_detail($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$obj$$)})};$contr_router$$.updating=function($user$$,$data$$,$obj$$,$next$$){valid_detail($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})};$contr_router$$.view=function($user$$,$items$$,$fn$$){const $id_app$$=$user$$.current_id_app;async.parallel({kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,
6
+ customer,[{where:"ma_kh",fields:["ten_kh"]}],function(){$callback$$()})},nv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_nv).joinModel2($id_app$$,dmnv,[{where:"ma_nv",fields:["ten_nv"]}],function(){$callback$$()})},bp:function($callback$$){$items$$.filter($item$$=>$item$$.ma_bp).joinModel2($id_app$$,dmbp,[{where:"ma_bp",fields:["ten_bp"]}],function(){$callback$$()})},tk:function($callback$$){$items$$.filter($item$$=>$item$$.tk_co).joinModel2($id_app$$,account,[{where:$item$$=>({tk:$item$$.tk_co}),
7
+ fields:[{name:"ten_tk_co",value:"ten_tk"}]}],function(){$callback$$()})},dv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dvcs).joinModel2($id_app$$,dvcs,[{where:$item$$=>({_id:$item$$.ma_dvcs}),setFields:($item$$,$ref$$)=>{$item$$.ten_dvcs=$ref$$.ten_dvcs}}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>$item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},
8
+ pc1:function($callback$$){$items$$.joinModel2($id_app$$,pc1,[{where:{_id:"id_pc0"},fields:[{id_pc1:"_id"},{so_ct_pc1:"so_ct"},{ma_ct_pc1:"ma_ct"},{ngay_ct_pc1:"ngay_ct"}]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.t_tien=0;$r$$.t_tien_nt=0;$r$$.t_thue_vao=0;$r$$.t_thue_vao_nt=0;$r$$.details&&($r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tien_nt=$r$$.details.csum("tien_nt"));$r$$.tdttcos&&($r$$.t_tien+=$r$$.tdttcos.csum("tien"),$r$$.t_tien_nt+=$r$$.tdttcos.csum("tien_nt"));
9
+ $r$$.vatvaos&&($r$$.t_thue_vao=$r$$.vatvaos.csum("t_thue"),$r$$.t_thue_vao_nt=$r$$.vatvaos.csum("t_thue_nt"));$r$$.t_tt=$r$$.t_tien+$r$$.t_thue_vao;$r$$.t_tt_nt=$r$$.t_tien_nt+$r$$.t_thue_vao_nt});$callback$$()},details_tk:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.tk_no).joinModel2($id_app$$,account,[{where:$item$$=>({tk:$item$$.tk_no}),fields:[{ten_tk_no:"ten_tk"}]}],function(){$callback1$$()})},function(){$callback$$()})},
10
+ details_tk_tdttco:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.tdttcos||[]).filter($item$$=>$item$$.tk_no).joinModel2($id_app$$,account,[{where:{tk_no:"tk"},fields:[{ten_tk_no:"ten_tk"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_dt_tdttco:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.tdttcos||[]).filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:"ma_dt",fields:["ten_dt"]}],function(){$callback1$$()})},
11
+ function(){$callback$$()})},details_hd_tdttco:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.tdttcos||[]).filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{wher:$item$$=>({so_hd:$item$$.ma_hd}),fields:["ten_hd"]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi_tdttco:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.tdttcos||[]).filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:"ma_phi",
12
+ fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})},details_customer:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:["ten_kh"]}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,
13
+ dmdt,[{where:"ma_dt",fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_hopdong:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:$item$$=>({so_hd:$item$$.ma_hd}),fields:["ten_hd"]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>
14
+ $item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:"ma_phi",fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};
@@ -0,0 +1,31 @@
1
+ const PostBook=require("../../libs/post-book"),PostSocai=require("../../libs/post-socai"),Vatvao=global.getModel("vatvao"),Tdttco_tt=global.getModel("tdttco_tt"),Tdttco=global.getModel("tdttco"),dmdt=global.getModel("dmdt"),customer=global.getModel("customer"),dmnv=global.getModel("dmnv"),contract=global.getModel("contract"),dmphi=global.getModel("dmphi"),model=global.getModel("pc1"),pc0=global.getModel("pc0"),pn6=global.getModel("pn6"),trangthai=global.getModel("trangthai"),controller=require("../../controllers/controller"),
2
+ {round}=require("../../libs/utils"),async=require("async"),ma_ct="PC1",tien_cl_can_xu_ly=5E3,valid_detail=function($i_i$jscomp$1_i$$,$obj$$,$fn$$){for($i_i$jscomp$1_i$$=0;$i_i$jscomp$1_i$$<$obj$$.details.length;$i_i$jscomp$1_i$$++){var $detail_tdttco_vatvao$$=$obj$$.details[$i_i$jscomp$1_i$$];$detail_tdttco_vatvao$$.line=$i_i$jscomp$1_i$$;$obj$$.ma_nt==="VND"&&($detail_tdttco_vatvao$$.tien=$detail_tdttco_vatvao$$.tien_nt)}if($obj$$.vatvaos)for($i_i$jscomp$1_i$$=0;$i_i$jscomp$1_i$$<$obj$$.vatvaos.length;$i_i$jscomp$1_i$$++)$detail_tdttco_vatvao$$=
3
+ $obj$$.vatvaos[$i_i$jscomp$1_i$$],$detail_tdttco_vatvao$$.line=$i_i$jscomp$1_i$$,$obj$$.ma_nt==="VND"&&($detail_tdttco_vatvao$$.t_thue=$detail_tdttco_vatvao$$.t_thue_nt);if($obj$$.tdttcos)for($i_i$jscomp$1_i$$=0;$i_i$jscomp$1_i$$<$obj$$.tdttcos.length;$i_i$jscomp$1_i$$++)$detail_tdttco_vatvao$$=$obj$$.tdttcos[$i_i$jscomp$1_i$$],$detail_tdttco_vatvao$$.line=$i_i$jscomp$1_i$$,$obj$$.ma_nt==="VND"&&($detail_tdttco_vatvao$$.tien=$detail_tdttco_vatvao$$.tien_nt),$detail_tdttco_vatvao$$.thanh_toan_qd=$detail_tdttco_vatvao$$.ma_nt_hd==
4
+ $obj$$.ma_nt?$detail_tdttco_vatvao$$.tien_nt:round($detail_tdttco_vatvao$$.tien/$detail_tdttco_vatvao$$.ty_gia_hd,2);$fn$$(null,$obj$$)};
5
+ module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,sort:{ngay_ct:-1,so_ct:-1},keyValues:{ma_ct},onExport:function($user$$,$obj$$,$next$$){$obj$$.tdttcos&&$obj$$.tdttcos.length>0&&($obj$$.details=$obj$$.tdttcos);$next$$()}});$contr_router$$.route();$contr_router$$.post=async function($obj$$,$fn$$){$fn$$||=function(){};const $appInfo$$=await global.getModel("app").findOne({_id:$obj$$.id_app}).lean();async.series({post_vatvao:function($callback$$){(new PostBook($obj$$,
6
+ $obj$$.vatvaos,Vatvao)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})},post_tdttco:function($callback$$){(new PostBook($obj$$,$obj$$.tdttcos,Tdttco_tt,function($tdttco$$,$callback$$){$tdttco$$.tk_co=$obj$$.tk_co;$callback$$($tdttco$$)})).run(function($e$$,$details$$){if($e$$)return $callback$$($e$$);$callback$$(null,$details$$)})},post_socai:function($callback$$){setImmediate(async()=>{const $details_sc$$=[];$obj$$.vatvaos.forEach(function($v_vatvao$$){$v_vatvao$$={...$v_vatvao$$};$v_vatvao$$.tk_no=
7
+ $v_vatvao$$.tk_thue_no;$v_vatvao$$.tk_co=$v_vatvao$$.tk_du_thue;$v_vatvao$$.tien_nt=$v_vatvao$$.t_thue_nt;$v_vatvao$$.tien=$v_vatvao$$.t_thue;$details_sc$$.push($v_vatvao$$)});$obj$$.details.forEach(function($d_detail$$){$d_detail$$={...$d_detail$$};$d_detail$$.tk_co=$obj$$.tk_co;$d_detail$$.ma_kh||($d_detail$$.ma_kh=$obj$$.ma_kh);$details_sc$$.push($d_detail$$)});$obj$$.tdttcos.forEach(function($t_tdttco$$){$t_tdttco$$={...$t_tdttco$$};$t_tdttco$$.tk_co=$obj$$.tk_co;$t_tdttco$$.ma_kh||($t_tdttco$$.ma_kh=
8
+ $obj$$.ma_kh);$details_sc$$.push($t_tdttco$$)});await $obj$$.tdttcos.filter($t$$=>$t$$.ty_gia_hd!=$obj$$.ty_gia).asyncJoinModel2($obj$$.id_app,"currency",{where:{ma_nt_hd:"ma_nt"},fields:["tk_cl_no","tk_cl_co"]});for(let $t$$ of $obj$$.tdttcos){var $con_lai_nt_ht_so_du_hd$$=await Tdttco.getBalance({id_app:$obj$$.id_app,id_ct:$obj$$._id.toString(),_id:$t$$.id_tdtt});if($con_lai_nt_ht_so_du_hd$$.length==1){let $con_lai$$=$con_lai_nt_ht_so_du_hd$$[0].con_lai-$t$$.tien;$con_lai_nt_ht_so_du_hd$$=$con_lai_nt_ht_so_du_hd$$[0].con_lai_nt-
9
+ $t$$.thanh_toan_qd;if(Math.abs($con_lai$$)<=tien_cl_can_xu_ly||$con_lai_nt_ht_so_du_hd$$<=0)$con_lai$$&&($con_lai_nt_ht_so_du_hd$$={...$t$$,ma_nt:"VND",ty_gia:1},$con_lai_nt_ht_so_du_hd$$.tien_nt=$con_lai_nt_ht_so_du_hd$$.tien=Math.abs($con_lai$$),$con_lai_nt_ht_so_du_hd$$.ma_kh||($con_lai_nt_ht_so_du_hd$$.ma_kh=$obj$$.ma_kh),$t$$.ty_gia_hd!=$obj$$.ty_gia&&$t$$.ma_nt_hd==$obj$$.ma_nt?($t$$.chenh_lech_ty_gia=$con_lai$$,$con_lai$$>0?($con_lai_nt_ht_so_du_hd$$.tk_no=$t$$.tk_no,$con_lai_nt_ht_so_du_hd$$.tk_co=
10
+ $t$$.tk_cl_co):($con_lai_nt_ht_so_du_hd$$.tk_no=$t$$.tk_cl_no,$con_lai_nt_ht_so_du_hd$$.tk_co=$t$$.tk_no),$details_sc$$.push($con_lai_nt_ht_so_du_hd$$)):$appInfo$$?.options.tk_tn_khac&&$appInfo$$?.options.tk_cp_khac&&($con_lai$$>0?($con_lai_nt_ht_so_du_hd$$.tk_no=$t$$.tk_no,$con_lai_nt_ht_so_du_hd$$.tk_co=$appInfo$$?.options.tk_tn_khac):($con_lai_nt_ht_so_du_hd$$.tk_no=$appInfo$$?.options.tk_cp_khac,$con_lai_nt_ht_so_du_hd$$.tk_co=$t$$.tk_no),$details_sc$$.push($con_lai_nt_ht_so_du_hd$$))),await Tdttco.updateOne({_id:$t$$.id_tdtt.toString()},
11
+ {tat_toan:!0}).catch(Logger.error)}}(new PostSocai($obj$$,$details_sc$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr_router$$.creating=async function($user$$,$obj$$,$next$$){if($user$$.current_app_info.options.phieu_chi_phai_co_phieu_de_nghi&&!$obj$$.id_pc0&&!$obj$$.id_pn6)return $next$$("Ch\u01b0a c\u00f3 phi\u1ebfu \u0111\u1ec1 ngh\u1ecb thanh to\u00e1n");$obj$$.details||($obj$$.details=[]);if($obj$$.id_pc0&&global.mongoose.Types.ObjectId.isValid($obj$$.id_pc0)){if(await model.findOne({id_app:$user$$.current_id_app,
12
+ id_pc0:$obj$$.id_pc0}))return $next$$("\u0110\u1ec1 ngh\u1ecb thanh to\u00e1n n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c chi");var $dntt_t_tien_dn$$=await pc0.findOne({_id:$obj$$.id_pc0,id_app:$user$$.current_id_app});if(!$dntt_t_tien_dn$$)return $next$$("\u0110\u1ec1 ngh\u1ecb thanh to\u00e1n kh\u00f4ng t\u1ed3n t\u1ea1i");$dntt_t_tien_dn$$=($dntt_t_tien_dn$$.details||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($dntt_t_tien_dn$$.tdttcos||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,
13
+ $b$$)=>$a$$+$b$$,0)+($dntt_t_tien_dn$$.vatvaos||[]).map($d$$=>$d$$.t_thue_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);let $t_tien_tt$$=($obj$$.details||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($obj$$.tdttcos||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($obj$$.vatvaos||[]).map($d$$=>$d$$.t_thue_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);if($dntt_t_tien_dn$$!==$t_tien_tt$$)return $next$$("T\u1ed5ng s\u1ed1 ti\u1ec1n thanh to\u00e1n ph\u1ea3i b\u1eb1ng v\u1edbi s\u1ed1 ti\u1ec1n trong \u0111\u1ec1 ngh\u1ecb thanh to\u00e1n \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t")}if($obj$$.tdttcos&&
14
+ $obj$$.tdttcos.length>0&&(await $obj$$.tdttcos.asyncJoinModel2($user$$.current_id_app,Tdttco,{where:{id_tdtt:"_id"},fields:["tat_toan",{tien_hd_nt:"tien_nt"}]}),(await Promise.all($obj$$.tdttcos.map($hd$$=>(async()=>{if(!global.mongoose.Types.ObjectId.isValid($hd$$.id_tdtt))return{error:"Ho\u00e1 \u0111\u01a1n kh\u00f4ng h\u1ee3p l\u1ec7",invoice:$hd$$};let $ds_da_thanh_toan$$=await Tdttco_tt.find({id_app:$obj$$.id_app,id_tdtt:$hd$$.id_tdtt}).lean(),$da_thanh_toan$$=$ds_da_thanh_toan$$.map($t$$=>
15
+ $t$$.thanh_toan_qd||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);return{invoice:$hd$$,da_thanh_toan:$da_thanh_toan$$,con_lai:$hd$$.tien_hd_nt-$da_thanh_toan$$,ds_da_thanh_toan:$ds_da_thanh_toan$$}})()))).filter($hd$$=>$hd$$.error).length>0))return $next$$("S\u1ed1 ti\u1ec1n thanh to\u00e1n kh\u00f4ng \u0111\u01b0\u1ee3c l\u1edbn h\u01a1n s\u1ed1 ti\u1ec1n c\u00f2n l\u1ea1i c\u1ee7a ho\u00e1 \u0111\u01a1n");valid_detail($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$obj$$)})};
16
+ $contr_router$$.updating=async function($user$$,$data$$,$obj$$,$next$$){if($data$$.id_pc0||$obj$$.id_pc0){var $dntt$jscomp$1_id_pc0_t_tien_dn$$=$data$$.id_pc0||$obj$$.id_pc0,$ex$jscomp$1_t_tien_tt$$=await model.findOne({id_app:$obj$$.id_app,id_pc0:$dntt$jscomp$1_id_pc0_t_tien_dn$$}).lean();if($ex$jscomp$1_t_tien_tt$$&&$ex$jscomp$1_t_tien_tt$$._id.toString()!==$obj$$._id.toString())return $next$$("\u0110\u1ec1 ngh\u1ecb thanh to\u00e1n n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c chi");$dntt$jscomp$1_id_pc0_t_tien_dn$$=
17
+ await pc0.findOne({_id:$dntt$jscomp$1_id_pc0_t_tien_dn$$,id_app:$user$$.current_id_app});if(!$dntt$jscomp$1_id_pc0_t_tien_dn$$)return $next$$("\u0110\u1ec1 ngh\u1ecb thanh to\u00e1n kh\u00f4ng t\u1ed3n t\u1ea1i");$dntt$jscomp$1_id_pc0_t_tien_dn$$=($dntt$jscomp$1_id_pc0_t_tien_dn$$.details||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($dntt$jscomp$1_id_pc0_t_tien_dn$$.tdttcos||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($dntt$jscomp$1_id_pc0_t_tien_dn$$.vatvaos||
18
+ []).map($d$$=>$d$$.t_thue_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$ex$jscomp$1_t_tien_tt$$=($data$$.details||$obj$$.details||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($data$$.tdttcos||$obj$$.tdttcos||[]).map($d$$=>$d$$.tien_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0)+($data$$.vatvaos||$obj$$.vatvaos||[]).map($d$$=>$d$$.t_thue_nt||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);if($dntt$jscomp$1_id_pc0_t_tien_dn$$!==$ex$jscomp$1_t_tien_tt$$)return $next$$("T\u1ed5ng s\u1ed1 ti\u1ec1n thanh to\u00e1n ph\u1ea3i b\u1eb1ng v\u1edbi s\u1ed1 ti\u1ec1n trong \u0111\u1ec1 ngh\u1ecb thanh to\u00e1n \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t")}if($obj$$.tdttcos&&
19
+ $obj$$.tdttcos.length>0&&(await $obj$$.tdttcos.asyncJoinModel2($user$$.current_id_app,Tdttco,{where:{id_tdtt:"_id"},fields:["tat_toan",{tien_hd_nt:"tien_nt"}]}),(await Promise.all($obj$$.tdttcos.map($hd$$=>(async()=>{if(!global.mongoose.Types.ObjectId.isValid($hd$$.id_tdtt))return{error:"Ho\u00e1 \u0111\u01a1n kh\u00f4ng h\u1ee3p l\u1ec7",invoice:$hd$$};let $ds_da_thanh_toan$$=await Tdttco_tt.find({id_app:$obj$$.id_app,id_tdtt:$hd$$.id_tdtt,id_ct:{$ne:$obj$$._id.toString()}}).lean(),$da_thanh_toan$$=
20
+ $ds_da_thanh_toan$$.map($t$$=>$t$$.thanh_toan_qd||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);return{ds_da_thanh_toan:$ds_da_thanh_toan$$,da_thanh_toan:$da_thanh_toan$$,invoice:$hd$$,con_lai:$hd$$.tien_hd_nt-$da_thanh_toan$$}})()))).filter($hd$$=>$hd$$.error).length>0))return $next$$("S\u1ed1 ti\u1ec1n thanh to\u00e1n kh\u00f4ng \u0111\u01b0\u1ee3c l\u1edbn h\u01a1n s\u1ed1 ti\u1ec1n c\u00f2n l\u1ea1i c\u1ee7a ho\u00e1 \u0111\u01a1n");valid_detail($user$$,$data$$,function($error$$){if($error$$)return $next$$($error$$);
21
+ $next$$(null,$data$$,$obj$$)})};$contr_router$$.deleted=($details$jscomp$1_user$$,$obj$$,$next$$)=>{$details$jscomp$1_user$$=($obj$$.details||[]).filter($d$$=>$d$$.id_tdtt);async.map($details$jscomp$1_user$$,($detail$$,$callback$$)=>{setImmediate(()=>{Tdttco.findOneAndUpdate({_id:$detail$$.id_tdtt.toString()},{$set:{tat_toan:!1}},function($error$$,$result$$){$callback$$($error$$,$result$$)})})},$e$$=>{$next$$($e$$,$obj$$)})};$contr_router$$.on("saved",async function($_obj$jscomp$1_obj$$){if($_obj$jscomp$1_obj$$.id_pc0){await pc0.updateMany({_id:$_obj$jscomp$1_obj$$.id_pc0,
22
+ id_app:$_obj$jscomp$1_obj$$.id_app},{id_pc1:$_obj$jscomp$1_obj$$._id.toString(),trang_thai:"6"});const $_obj$$=await pc0.findOne({_id:$_obj$jscomp$1_obj$$.id_pc0});$_obj$$&&controller.postData($_obj$$,global.controllers.PC0,$e$$=>{$e$$&&Logger.error($e$$)})}$_obj$jscomp$1_obj$$.id_pn6&&(await pn6.updateMany({_id:$_obj$jscomp$1_obj$$.id_pn6,id_app:$_obj$jscomp$1_obj$$.id_app},{id_pc1:$_obj$jscomp$1_obj$$._id.toString(),trang_thai:"7"}),($_obj$jscomp$1_obj$$=await pn6.findOne({_id:$_obj$jscomp$1_obj$$.id_pn6}))&&
23
+ controller.postData($_obj$jscomp$1_obj$$,global.controllers.PN6,$e$$=>{$e$$&&Logger.error($e$$)}))});$contr_router$$.on("deleted",async function($_obj$jscomp$3_obj$$){if($_obj$jscomp$3_obj$$.id_pc0){await pc0.updateMany({_id:$_obj$jscomp$3_obj$$.id_pc0,id_app:$_obj$jscomp$3_obj$$.id_app},{id_pc1:""});await pc0.updateMany({_id:$_obj$jscomp$3_obj$$.id_pc0,id_app:$_obj$jscomp$3_obj$$.id_app,trang_thai:"6"},{trang_thai:"4"});const $_obj$$=await pc0.findOne({_id:$_obj$jscomp$3_obj$$.id_pc0,id_app:$_obj$jscomp$3_obj$$.id_app});
24
+ $_obj$$&&controller.postData($_obj$$,global.controllers.PC0,$e$$=>{$e$$&&Logger.error($e$$)})}$_obj$jscomp$3_obj$$.id_pn6&&(await pn6.updateMany({_id:$_obj$jscomp$3_obj$$.id_pn6,id_app:$_obj$jscomp$3_obj$$.id_app},{id_pc1:""}),await pn6.updateMany({_id:$_obj$jscomp$3_obj$$.id_pn6,id_app:$_obj$jscomp$3_obj$$.id_app,trang_thai:"7"},{trang_thai:"5"}),($_obj$jscomp$3_obj$$=await pn6.findOne({_id:$_obj$jscomp$3_obj$$.id_pn6,id_app:$_obj$jscomp$3_obj$$.id_app}))&&controller.postData($_obj$jscomp$3_obj$$,
25
+ global.controllers.PN6,$e$$=>{$e$$&&Logger.error($e$$)}))});$contr_router$$.view=function($user$$,$items$$,$fn$$){let $id_app$$=$user$$.current_id_app;async.parallel({kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:["ten_kh"]}],function(){$callback$$()})},nv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_nv).joinModel2($id_app$$,dmnv,[{where:"ma_nv",fields:["ten_nv"]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.filter($item$$=>
26
+ $item$$.trang_thai).joinModel2(null,trangthai,[{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},pc0:function($callback$$){$items$$.joinModel2($id_app$$,pc0,[{where:{id_pc0:"_id"},fields:[{so_ct_pc0:"so_ct"},{ngay_ct_pc0:"ngay_ct"}]}],function(){$callback$$()})},t_tien:function($callback$$){$items$$.forEach(function($r$$){$r$$.t_tien=0;$r$$.t_tien_nt=0;$r$$.t_thue_vao=0;$r$$.t_thue_vao_nt=0;$r$$.details&&($r$$.t_tien=$r$$.details.csum("tien"),
27
+ $r$$.t_tien_nt=$r$$.details.csum("tien_nt"));$r$$.tdttcos&&($r$$.t_tien+=$r$$.tdttcos.csum("tien"),$r$$.t_tien_nt+=$r$$.tdttcos.csum("tien_nt"));$r$$.vatvaos&&($r$$.t_thue_vao=$r$$.vatvaos.csum("t_thue"),$r$$.t_thue_vao_nt=$r$$.vatvaos.csum("t_thue_nt"));$r$$.t_tt=$r$$.t_tien+$r$$.t_thue_vao;$r$$.t_tt_nt=$r$$.t_tien_nt+$r$$.t_thue_vao_nt});$callback$$()},details_dt_tdttco:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.tdttcos||[]).filter($item$$=>$item$$.ma_dt).joinModel($id_app$$,
28
+ dmdt,[{akey:"ma_dt",bkey:"ma_dt",fields:[{name:"ten_dt",value:"ten_dt"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_hd_tdttco:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.tdttcos||[]).filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{wher:{ma_hd:"so_hd"},fields:["ten_hd"]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi_tdttco:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.tdttcos||
29
+ []).filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:"ma_phi",fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})},details_customer:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:["ten_kh"]}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||
30
+ []).filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:"ma_dt",fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_hopdong:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},fields:["ten_hd"]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapLimit($items$$,20,function($r$$,
31
+ $callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:"ma_phi",fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})}},function(){$fn$$(null,$items$$)})}};
@@ -0,0 +1,25 @@
1
+ const PostBook=require("../../libs/post-book"),PostSocai=require("../../libs/post-socai"),Socai=global.getModel("socai"),Vatvao=global.getModel("vatvao"),Tdttco_tt=global.getModel("tdttco_tt"),Tdttco=global.getModel("tdttco"),dvcs=global.getModel("dvcs"),account=global.getModel("account"),dmdt=global.getModel("dmdt"),customer=global.getModel("customer"),dmnv=global.getModel("dmnv"),contract=global.getModel("contract"),pn6=global.getModel("pn6"),dmphi=global.getModel("dmphi"),model=global.getModel("pc2"),
2
+ trangthai=global.getModel("trangthai"),pc3=global.getModel("pc3"),controller=require("../../controllers/controller"),async=require("async"),ma_ct="PC2",valid_detail=function($i_i$jscomp$1_i$$,$obj$$,$fn$$){for($i_i$jscomp$1_i$$=0;$i_i$jscomp$1_i$$<$obj$$.details.length;$i_i$jscomp$1_i$$++){var $detail_tdttco_vatvao$$=$obj$$.details[$i_i$jscomp$1_i$$];$detail_tdttco_vatvao$$.line=$i_i$jscomp$1_i$$;$obj$$.ma_nt=="VND"&&($detail_tdttco_vatvao$$.tien=$detail_tdttco_vatvao$$.tien_nt)}if($obj$$.vatvaos)for($i_i$jscomp$1_i$$=
3
+ 0;$i_i$jscomp$1_i$$<$obj$$.vatvaos.length;$i_i$jscomp$1_i$$++)$detail_tdttco_vatvao$$=$obj$$.vatvaos[$i_i$jscomp$1_i$$],$detail_tdttco_vatvao$$.line=$i_i$jscomp$1_i$$,$obj$$.ma_nt=="VND"&&($detail_tdttco_vatvao$$.t_thue=$detail_tdttco_vatvao$$.t_thue_nt);if($obj$$.tdttcos)for($i_i$jscomp$1_i$$=0;$i_i$jscomp$1_i$$<$obj$$.tdttcos.length;$i_i$jscomp$1_i$$++)$detail_tdttco_vatvao$$=$obj$$.tdttcos[$i_i$jscomp$1_i$$],$detail_tdttco_vatvao$$.line=$i_i$jscomp$1_i$$,$obj$$.ma_nt=="VND"&&($detail_tdttco_vatvao$$.tien=
4
+ $detail_tdttco_vatvao$$.tien_nt);$fn$$(null,$obj$$)};
5
+ module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,ma_ct.toLowerCase(),{isVoucher:!0,sort:{ngay_ct:-1,so_ct:-1},onExport:function($user$$,$obj$$,$next$$){$obj$$.tdttcos&&$obj$$.tdttcos.length>0&&($obj$$.details=$obj$$.tdttcos);$next$$()}});$contr_router$$.route();$contr_router$$.post=function($obj$$,$fn$$){$fn$$||=function(){};async.series({post_vatvao:function($callback$$){(new PostBook($obj$$,$obj$$.vatvaos,Vatvao)).run(function($e$$,$rs$$){$callback$$($e$$,
6
+ $rs$$)})},post_tdttco:function($callback$$){(new PostBook($obj$$,$obj$$.tdttcos,Tdttco_tt,function($tdttco$$,$callback$$){$tdttco$$.tk_co=$obj$$.tk_co;$callback$$($tdttco$$)})).run(function($e$$,$details$$){if($e$$)return $callback$$($e$$);async.map($details$$,function($detail$$,$callback$$){$detail$$.con_lai_nt<=$detail$$.thanh_toan_qd?Tdttco.findOneAndUpdate({_id:$detail$$.id_hd},{$set:{tat_toan:!0}},function($error$$,$result$$){$callback$$($error$$,$result$$)}):$callback$$(null,$detail$$)},function($e$$,
7
+ $rs$$){$callback$$($e$$,$rs$$)})})},post_socai:function($callback$$){const $details_sc$$=[];$obj$$.vatvaos.forEach(function($v_vatvao$$){$v_vatvao$$={...$v_vatvao$$};$v_vatvao$$.tk_no=$v_vatvao$$.tk_thue_no;$v_vatvao$$.tk_co=$v_vatvao$$.tk_du_thue;$v_vatvao$$.tien_nt=$v_vatvao$$.t_thue_nt;$v_vatvao$$.tien=$v_vatvao$$.t_thue;$details_sc$$.push($v_vatvao$$)});$obj$$.details.forEach(function($d_detail$$){$d_detail$$={...$d_detail$$};$d_detail$$.tk_co=$obj$$.tk_co;$d_detail$$.ma_kh||($d_detail$$.ma_kh=
8
+ $obj$$.ma_kh);$details_sc$$.push($d_detail$$)});$obj$$.tdttcos.forEach(function($t_tdttco$$){$t_tdttco$$={...$t_tdttco$$};$t_tdttco$$.tk_co=$obj$$.tk_co;$t_tdttco$$.ma_kh||($t_tdttco$$.ma_kh=$obj$$.ma_kh);$details_sc$$.push($t_tdttco$$)});(new PostSocai($obj$$,$details_sc$$)).run(function($e$$,$rs$$){$callback$$($e$$,$rs$$)})}},function($e$$,$rs$$){$fn$$($e$$,$rs$$)})};$contr_router$$.creating=async function($user$$,$obj$$,$next$$){if($user$$.current_app_info.options.phieu_chi_phai_co_phieu_de_nghi&&
9
+ !$obj$$.id_pc3)return $next$$("Ch\u01b0a c\u00f3 phi\u1ebfu \u0111\u1ec1 ngh\u1ecb t\u1ea1m \u1ee9ng");$obj$$.id_pn6="";$obj$$.details||($obj$$.details=[]);if($obj$$.id_pc3){var $dntt_t_tien_dn$$=await pc3.findOne({_id:$obj$$.id_pc3,id_app:$user$$.current_id_app});if(!$dntt_t_tien_dn$$)return $next$$("\u0110\u1ec1 ngh\u1ecb t\u1ea1m \u1ee9ng kh\u00f4ng t\u1ed3n t\u1ea1i");$dntt_t_tien_dn$$=($dntt_t_tien_dn$$.details||[]).map($d$$=>$d$$.tien_nt||0)+($dntt_t_tien_dn$$.vatvaos||[]).map($d$$=>$d$$.t_thue_nt||
10
+ 0);let $t_tien_tt$$=($obj$$.details||[]).map($d$$=>$d$$.tien_nt||0)+($obj$$.vatvaos||[]).map($d$$=>$d$$.t_thue_nt||0);if($dntt_t_tien_dn$$!==$t_tien_tt$$)return $next$$("T\u1ed5ng s\u1ed1 ti\u1ec1n t\u1ea1m \u1ee9ng ph\u1ea3i b\u1eb1ng v\u1edbi s\u1ed1 ti\u1ec1n trong \u0111\u1ec1 ngh\u1ecb t\u1ea1m \u1ee9ng \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t")}valid_detail($user$$,$obj$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$obj$$)})};$contr_router$$.created=function($user$$,
11
+ $obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.updating=async function($user$$,$data$$,$obj$$,$next$$){var $dntt$jscomp$1_id_pc3_t_tien_dn$$=$data$$.id_pc3||$obj$$.id_pc3;if($dntt$jscomp$1_id_pc3_t_tien_dn$$){$dntt$jscomp$1_id_pc3_t_tien_dn$$=await pc3.findOne({_id:$dntt$jscomp$1_id_pc3_t_tien_dn$$,id_app:$user$$.current_id_app});if(!$dntt$jscomp$1_id_pc3_t_tien_dn$$)return $next$$("\u0110\u1ec1 ngh\u1ecb t\u1ea1m \u1ee9ng kh\u00f4ng t\u1ed3n t\u1ea1i");$dntt$jscomp$1_id_pc3_t_tien_dn$$=($dntt$jscomp$1_id_pc3_t_tien_dn$$.details||
12
+ []).map($d$$=>$d$$.tien_nt||0)+($dntt$jscomp$1_id_pc3_t_tien_dn$$.vatvaos||[]).map($d$$=>$d$$.t_thue_nt||0);let $t_tien_tt$$=($data$$.details||$obj$$.details||[]).map($d$$=>$d$$.tien_nt||0)+($data$$.vatvaos||$obj$$.vatvaos||[]).map($d$$=>$d$$.t_thue_nt||0);if($dntt$jscomp$1_id_pc3_t_tien_dn$$!==$t_tien_tt$$)return $next$$("T\u1ed5ng s\u1ed1 ti\u1ec1n t\u1ea1m \u1ee9ng ph\u1ea3i b\u1eb1ng v\u1edbi s\u1ed1 ti\u1ec1n trong \u0111\u1ec1 ngh\u1ecb t\u1ea1m \u1ee9ng \u0111\u00e3 \u0111\u01b0\u1ee3c duy\u1ec7t")}valid_detail($user$$,
13
+ $data$$,function($error$$){if($error$$)return $next$$($error$$);$next$$(null,$data$$,$obj$$)})};$contr_router$$.updated=function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)};$contr_router$$.on("saved",async function($_obj_obj$$){$_obj_obj$$.id_pc3&&(await pc3.updateMany({_id:$_obj_obj$$.id_pc3,id_app:$_obj_obj$$.id_app},{id_pc2:$_obj_obj$$._id.toString(),trang_thai:"6"}),($_obj_obj$$=await pc3.findOne({_id:$_obj_obj$$.id_pc3,id_app:$_obj_obj$$.id_app}))&&controller.postData($_obj_obj$$,global.controllers.PC3,
14
+ $e$$=>{$e$$&&Logger.error($e$$)}))});$contr_router$$.on("deleted",async function($_obj$jscomp$1_obj$$){$_obj$jscomp$1_obj$$.id_pc3&&(await pc3.updateMany({_id:$_obj$jscomp$1_obj$$.id_pc3,id_app:$_obj$jscomp$1_obj$$.id_app},{id_pc2:""}),await pc3.updateMany({_id:$_obj$jscomp$1_obj$$.id_pc3,id_app:$_obj$jscomp$1_obj$$.id_app,trang_thai:"6"},{trang_thai:"4"}),($_obj$jscomp$1_obj$$=await pc3.findOne({_id:$_obj$jscomp$1_obj$$.id_pc3,id_app:$_obj$jscomp$1_obj$$.id_app}))&&controller.postData($_obj$jscomp$1_obj$$,
15
+ global.controllers.PC3,$e$$=>{$e$$&&Logger.error($e$$)}))});$contr_router$$.view=function($user$$,$items$$,$fn$$){let $id_app$$=$user$$.current_id_app;async.parallel({kh:function($callback$$){$items$$.filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:["ten_kh"]}],function(){$callback$$()})},nv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_nv).joinModel2($id_app$$,dmnv,[{where:"ma_nv",fields:["ten_nv"]}],function(){$callback$$()})},tk:function($callback$$){$items$$.filter($item$$=>
16
+ $item$$.tk_co).joinModel2($id_app$$,account,[{where:{tk_co:"tk"},fields:[{ten_tk_co:"ten_tk"}]}],function(){$callback$$()})},dv:function($callback$$){$items$$.filter($item$$=>$item$$.ma_dvcs).joinModel2($id_app$$,dvcs,[{where:{ma_dvcs:"_id"},fields:["ten_dvcs"]}],function(){$callback$$()})},pn6:function($callback$$){$items$$.joinModel2($id_app$$,pn6,[{where:{_id:"id_pc2"},fields:[{name:"id_pn6",value:"_id"}]}],function(){$callback$$()})},trangthai:function($callback$$){$items$$.joinModel2(null,trangthai,
17
+ [{where:{trang_thai:"ma_trang_thai",ma_ct:"ma_ct"},fields:["ten_trang_thai","color"]}],function(){$callback$$()})},pc3:function($callback$$){$items$$.joinModel2($id_app$$,pc3,[{where:{id_pc3:"_id"},fields:[{id_pc3:"_id"},{so_ct_pc3:"so_ct"},{ngay_ct_pc3:"ngay_ct"}]}],function(){$callback$$()})},details_tk:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.tk_no).joinModel2($id_app$$,account,[{where:{tk_no:"tk"},fields:[{ten_tk_no:"ten_tk"}]}],
18
+ function(){$callback1$$()})},function(){$callback$$()})},details_tk_tdttco:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.tdttcos||[]).filter($item$$=>$item$$.tk_no).joinModel2($id_app$$,account,[{where:{tk_no:"tk"},fields:[{ten_tk_no:"ten_tk"}]}],function(){$callback1$$()})},function(){$callback$$()})},details_dt_tdttco:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.tdttcos||[]).filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,
19
+ dmdt,[{where:"ma_dt",fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_hd_tdttco:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.tdttcos||[]).filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},fields:["ten_hd"]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi_tdttco:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.tdttcos||[]).filter($item$$=>
20
+ $item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:"ma_phi",fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})},details_customer:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_kh).joinModel2($id_app$$,customer,[{where:"ma_kh",fields:["ten_kh"]}],function(){$callback1$$()})},function(){$callback$$()})},details_dt:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||
21
+ []).filter($item$$=>$item$$.ma_dt).joinModel2($id_app$$,dmdt,[{where:"ma_dt",fields:["ten_dt"]}],function(){$callback1$$()})},function(){$callback$$()})},details_hopdong:function($callback$$){async.mapLimit($items$$,20,function($r$$,$callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_hd).joinModel2($id_app$$,contract,[{where:{ma_hd:"so_hd"},fields:["ten_hd"]}],function(){$callback1$$()})},function(){$callback$$()})},details_phi:function($callback$$){async.mapLimit($items$$,20,function($r$$,
22
+ $callback1$$){($r$$.details||[]).filter($item$$=>$item$$.ma_phi).joinModel2($id_app$$,dmphi,[{where:"ma_phi",fields:["ten_phi"]}],function(){$callback1$$()})},function(){$callback$$()})}},async()=>{try{await Promise.all($items$$.map($r$$=>(async()=>{$r$$.t_tien=0;$r$$.t_tien_nt=0;$r$$.t_thue_vao=0;$r$$.t_thue_vao_nt=0;$r$$.details&&($r$$.t_tien=$r$$.details.csum("tien"),$r$$.t_tien_nt=$r$$.details.csum("tien_nt"));$r$$.tdttcos&&($r$$.t_tien+=$r$$.tdttcos.csum("tien"),$r$$.t_tien_nt+=$r$$.tdttcos.csum("tien_nt"));
23
+ $r$$.vatvaos&&($r$$.t_thue_vao=$r$$.vatvaos.csum("t_thue"),$r$$.t_thue_vao_nt=$r$$.vatvaos.csum("t_thue_nt"));$r$$.t_tt=$r$$.t_tien+$r$$.t_thue_vao;$r$$.t_tt_nt=$r$$.t_tien_nt+$r$$.t_thue_vao_nt;var $id_pn6s_sc_pn6$$=(await pn6.find({id_app:$r$$.id_app,id_pc2:$r$$._id.toString()}).lean()).map($d$$=>$d$$._id.toString());Logger.info("pn6",$id_pn6s_sc_pn6$$);var $sc_khac_tk_cos$$=($r$$.details||[]).map($d$$=>$d$$.tk_no);$id_pn6s_sc_pn6$$=await Socai.find({id_app:$r$$.id_app,tk_co:{$in:$sc_khac_tk_cos$$},
24
+ id_ct:{$in:$id_pn6s_sc_pn6$$}}).lean();$r$$.t_hoan_ung_nt=$id_pn6s_sc_pn6$$.map($r$$=>$r$$.tien_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$sc_khac_tk_cos$$=await Socai.find({id_app:$r$$.id_app,tk_co:{$in:$sc_khac_tk_cos$$},id_link:$r$$._id.toString()}).lean();$r$$.t_hoan_ung_nt=$sc_khac_tk_cos$$.filter($r$$=>($r$$.ma_ct_link||"").toLowerCase()!=="pn6").map($r$$=>$r$$.tien_nt).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$r$$.t_con_lai_nt=$r$$.t_tt_nt-$r$$.t_hoan_ung_nt;return $r$$})())),$fn$$(null,$items$$)}catch($e$$){$fn$$($e$$.message||
25
+ $e$$)}})}};