@things-factory/worksheet-base 8.0.0-beta.0 → 8.0.0-beta.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 (283) hide show
  1. package/package.json +17 -17
  2. package/server/constants/index.ts +0 -5
  3. package/server/constants/rule-type.ts +0 -4
  4. package/server/constants/target-type.ts +0 -6
  5. package/server/constants/template.ts +0 -12
  6. package/server/constants/transaction-type.ts +0 -9
  7. package/server/constants/worksheet.ts +0 -38
  8. package/server/controllers/ecommerce/ecommerce-controller.ts +0 -209
  9. package/server/controllers/ecommerce/index.ts +0 -2
  10. package/server/controllers/ecommerce/sellercraft-controller.ts +0 -358
  11. package/server/controllers/inbound/index.ts +0 -4
  12. package/server/controllers/inbound/putaway-returning-worksheet-controller.ts +0 -450
  13. package/server/controllers/inbound/putaway-worksheet-controller.ts +0 -454
  14. package/server/controllers/inbound/unloading-returning-worksheet-controller.ts +0 -291
  15. package/server/controllers/inbound/unloading-worksheet-controller.ts +0 -1398
  16. package/server/controllers/index.ts +0 -21
  17. package/server/controllers/inspect/cycle-count-worksheet-controller.ts +0 -537
  18. package/server/controllers/inspect/index.ts +0 -1
  19. package/server/controllers/outbound/index.ts +0 -5
  20. package/server/controllers/outbound/loading-worksheet-controller.ts +0 -377
  21. package/server/controllers/outbound/packing-worksheet-controller.ts +0 -449
  22. package/server/controllers/outbound/picking-worksheet-controller.ts +0 -1769
  23. package/server/controllers/outbound/returning-worksheet-controller.ts +0 -254
  24. package/server/controllers/outbound/sorting-worksheet-controller.ts +0 -554
  25. package/server/controllers/render-elccl-grn.ts +0 -228
  26. package/server/controllers/render-fm-grn.ts +0 -287
  27. package/server/controllers/render-grn.ts +0 -285
  28. package/server/controllers/render-invoices.ts +0 -201
  29. package/server/controllers/render-job-sheet.ts +0 -208
  30. package/server/controllers/render-kimeda-grn.ts +0 -185
  31. package/server/controllers/render-manifest.ts +0 -76
  32. package/server/controllers/render-manual-do.ts +0 -227
  33. package/server/controllers/render-orientage-do.ts +0 -376
  34. package/server/controllers/render-orientage-grn.ts +0 -191
  35. package/server/controllers/render-po.ts +0 -182
  36. package/server/controllers/render-ro-do.ts +0 -404
  37. package/server/controllers/render-seebuu-grn.ts +0 -208
  38. package/server/controllers/vas/index.ts +0 -1
  39. package/server/controllers/vas/vas-worksheet-controller.ts +0 -848
  40. package/server/controllers/worksheet-controller.ts +0 -1267
  41. package/server/entities/index.ts +0 -8
  42. package/server/entities/warehouse-bizplace-onhand-inventory.ts +0 -148
  43. package/server/entities/worksheet-detail.ts +0 -106
  44. package/server/entities/worksheet-movement.ts +0 -34
  45. package/server/entities/worksheet.ts +0 -100
  46. package/server/graphql/index.ts +0 -7
  47. package/server/graphql/resolvers/index.ts +0 -8
  48. package/server/graphql/resolvers/pallet/index.ts +0 -7
  49. package/server/graphql/resolvers/pallet/pallet-outbound.ts +0 -92
  50. package/server/graphql/resolvers/worksheet/batch-picking-worksheet.ts +0 -137
  51. package/server/graphql/resolvers/worksheet/cancel-draft-release-order.ts +0 -20
  52. package/server/graphql/resolvers/worksheet/check-inventory-release.ts +0 -37
  53. package/server/graphql/resolvers/worksheet/check-stock-take-current-location.ts +0 -63
  54. package/server/graphql/resolvers/worksheet/confirm-cancellation-release-order.ts +0 -213
  55. package/server/graphql/resolvers/worksheet/create-worksheet.ts +0 -21
  56. package/server/graphql/resolvers/worksheet/cross-dock-picking.ts +0 -173
  57. package/server/graphql/resolvers/worksheet/cycle-count-adjustment.ts +0 -211
  58. package/server/graphql/resolvers/worksheet/cycle-count-worksheet.ts +0 -79
  59. package/server/graphql/resolvers/worksheet/delete-worksheet.ts +0 -21
  60. package/server/graphql/resolvers/worksheet/delivery-order-by-worksheet.ts +0 -104
  61. package/server/graphql/resolvers/worksheet/fetch-delivery-order-ro.ts +0 -191
  62. package/server/graphql/resolvers/worksheet/fetch-sellercraft-document.ts +0 -69
  63. package/server/graphql/resolvers/worksheet/find-release-orders-by-task-no.ts +0 -36
  64. package/server/graphql/resolvers/worksheet/find-release-orders-by-worksheet-no.ts +0 -29
  65. package/server/graphql/resolvers/worksheet/find-sorting-release-orders-by-task-no.ts +0 -80
  66. package/server/graphql/resolvers/worksheet/generate-worksheet/generate-arrival-notice-worksheet.ts +0 -100
  67. package/server/graphql/resolvers/worksheet/generate-worksheet/generate-batch-picking-worksheet.ts +0 -26
  68. package/server/graphql/resolvers/worksheet/generate-worksheet/generate-cycle-count-worksheet.ts +0 -51
  69. package/server/graphql/resolvers/worksheet/generate-worksheet/generate-multiple-release-good-worksheet.ts +0 -17
  70. package/server/graphql/resolvers/worksheet/generate-worksheet/generate-partial-putaway-return-worksheet.ts +0 -69
  71. package/server/graphql/resolvers/worksheet/generate-worksheet/generate-partial-putaway-worksheet.ts +0 -65
  72. package/server/graphql/resolvers/worksheet/generate-worksheet/generate-putaway-worksheet.ts +0 -54
  73. package/server/graphql/resolvers/worksheet/generate-worksheet/generate-release-good-worksheet.ts +0 -114
  74. package/server/graphql/resolvers/worksheet/generate-worksheet/generate-return-order-worksheet.ts +0 -45
  75. package/server/graphql/resolvers/worksheet/generate-worksheet/generate-vas-order-worksheet.ts +0 -35
  76. package/server/graphql/resolvers/worksheet/generate-worksheet/index.ts +0 -23
  77. package/server/graphql/resolvers/worksheet/having-vas.ts +0 -45
  78. package/server/graphql/resolvers/worksheet/index.ts +0 -142
  79. package/server/graphql/resolvers/worksheet/inspecting/activate-cycle-count.ts +0 -24
  80. package/server/graphql/resolvers/worksheet/inspecting/add-extra-pallet.ts +0 -49
  81. package/server/graphql/resolvers/worksheet/inspecting/check-missing-pallet.ts +0 -18
  82. package/server/graphql/resolvers/worksheet/inspecting/complete-inspection.ts +0 -41
  83. package/server/graphql/resolvers/worksheet/inspecting/index.ts +0 -17
  84. package/server/graphql/resolvers/worksheet/inspecting/inspecting.ts +0 -30
  85. package/server/graphql/resolvers/worksheet/inspecting/relocate-pallet.ts +0 -46
  86. package/server/graphql/resolvers/worksheet/inspecting/undo-inspection.ts +0 -23
  87. package/server/graphql/resolvers/worksheet/inventories-by-pallet.ts +0 -150
  88. package/server/graphql/resolvers/worksheet/loaded-inventories.ts +0 -40
  89. package/server/graphql/resolvers/worksheet/loading/activate-loading.ts +0 -73
  90. package/server/graphql/resolvers/worksheet/loading/complete-loading.ts +0 -165
  91. package/server/graphql/resolvers/worksheet/loading/index.ts +0 -11
  92. package/server/graphql/resolvers/worksheet/loading/loading.ts +0 -46
  93. package/server/graphql/resolvers/worksheet/loading/undo-loading.ts +0 -25
  94. package/server/graphql/resolvers/worksheet/loading-worksheet.ts +0 -150
  95. package/server/graphql/resolvers/worksheet/not-tally-target-inventories.ts +0 -34
  96. package/server/graphql/resolvers/worksheet/packing/activate-packing.ts +0 -69
  97. package/server/graphql/resolvers/worksheet/packing/complete-packing.ts +0 -102
  98. package/server/graphql/resolvers/worksheet/packing/index.ts +0 -13
  99. package/server/graphql/resolvers/worksheet/packing/packing.ts +0 -59
  100. package/server/graphql/resolvers/worksheet/packing/scan-product-packing.ts +0 -70
  101. package/server/graphql/resolvers/worksheet/packing/undo-serial-number-packing.ts +0 -24
  102. package/server/graphql/resolvers/worksheet/packing-worksheet.ts +0 -378
  103. package/server/graphql/resolvers/worksheet/palletizing-pallets.ts +0 -142
  104. package/server/graphql/resolvers/worksheet/pending-cancellation-release-order.ts +0 -234
  105. package/server/graphql/resolvers/worksheet/picking/activate-batch-picking.ts +0 -40
  106. package/server/graphql/resolvers/worksheet/picking/activate-picking.ts +0 -98
  107. package/server/graphql/resolvers/worksheet/picking/assign-picking-inventories.ts +0 -50
  108. package/server/graphql/resolvers/worksheet/picking/assign-picking-worker.ts +0 -44
  109. package/server/graphql/resolvers/worksheet/picking/batch-picking.ts +0 -32
  110. package/server/graphql/resolvers/worksheet/picking/complete-batch-picking.ts +0 -137
  111. package/server/graphql/resolvers/worksheet/picking/complete-picking.ts +0 -282
  112. package/server/graphql/resolvers/worksheet/picking/fetch-and-assign-picking-task.ts +0 -121
  113. package/server/graphql/resolvers/worksheet/picking/index.ts +0 -31
  114. package/server/graphql/resolvers/worksheet/picking/my-picking-assignment-status.ts +0 -35
  115. package/server/graphql/resolvers/worksheet/picking/picking-assignment-status-by-user.ts +0 -96
  116. package/server/graphql/resolvers/worksheet/picking/picking.ts +0 -55
  117. package/server/graphql/resolvers/worksheet/picking/scan-product-batch-picking.ts +0 -52
  118. package/server/graphql/resolvers/worksheet/picking/scan-product-picking.ts +0 -25
  119. package/server/graphql/resolvers/worksheet/picking/seal-tote.ts +0 -25
  120. package/server/graphql/resolvers/worksheet/picking/undo-picking-assignment.ts +0 -31
  121. package/server/graphql/resolvers/worksheet/picking/undo-serial-number-picking.ts +0 -24
  122. package/server/graphql/resolvers/worksheet/picking-worksheet.ts +0 -147
  123. package/server/graphql/resolvers/worksheet/proceed-extra-products.ts +0 -242
  124. package/server/graphql/resolvers/worksheet/putaway/activate-putaway.ts +0 -51
  125. package/server/graphql/resolvers/worksheet/putaway/complete-putaway.ts +0 -105
  126. package/server/graphql/resolvers/worksheet/putaway/index.ts +0 -11
  127. package/server/graphql/resolvers/worksheet/putaway/putaway.ts +0 -26
  128. package/server/graphql/resolvers/worksheet/putaway/undo-putaway.ts +0 -25
  129. package/server/graphql/resolvers/worksheet/putaway-return/activate-putaway-return.ts +0 -55
  130. package/server/graphql/resolvers/worksheet/putaway-return/complete-putaway-return.ts +0 -38
  131. package/server/graphql/resolvers/worksheet/putaway-return/index.ts +0 -11
  132. package/server/graphql/resolvers/worksheet/putaway-return/putaway-return.ts +0 -30
  133. package/server/graphql/resolvers/worksheet/putaway-return/undo-putaway-return.ts +0 -29
  134. package/server/graphql/resolvers/worksheet/putaway-returning-worksheet.ts +0 -83
  135. package/server/graphql/resolvers/worksheet/putaway-worksheet.ts +0 -82
  136. package/server/graphql/resolvers/worksheet/recommend-putway-location.ts +0 -133
  137. package/server/graphql/resolvers/worksheet/reject-cancellation-release-order.ts +0 -186
  138. package/server/graphql/resolvers/worksheet/relocate-pallet.ts +0 -67
  139. package/server/graphql/resolvers/worksheet/replace-picking-pallets.ts +0 -127
  140. package/server/graphql/resolvers/worksheet/return-worksheet.ts +0 -70
  141. package/server/graphql/resolvers/worksheet/returning/activate-return.ts +0 -24
  142. package/server/graphql/resolvers/worksheet/returning/complete-return.ts +0 -39
  143. package/server/graphql/resolvers/worksheet/returning/index.ts +0 -9
  144. package/server/graphql/resolvers/worksheet/returning/returning.ts +0 -26
  145. package/server/graphql/resolvers/worksheet/sorting/activate-sorting.ts +0 -25
  146. package/server/graphql/resolvers/worksheet/sorting/complete-order-sorting.ts +0 -40
  147. package/server/graphql/resolvers/worksheet/sorting/complete-worksheet-sorting.ts +0 -23
  148. package/server/graphql/resolvers/worksheet/sorting/index.ts +0 -13
  149. package/server/graphql/resolvers/worksheet/sorting/scan-product-sorting.ts +0 -31
  150. package/server/graphql/resolvers/worksheet/sorting/sorting-product.ts +0 -32
  151. package/server/graphql/resolvers/worksheet/sorting-worksheet.ts +0 -87
  152. package/server/graphql/resolvers/worksheet/transfer.ts +0 -176
  153. package/server/graphql/resolvers/worksheet/unloaded-inventories-by-reusable-pallet.ts +0 -54
  154. package/server/graphql/resolvers/worksheet/unloaded-inventories.ts +0 -78
  155. package/server/graphql/resolvers/worksheet/unloading/activate-unloading.ts +0 -56
  156. package/server/graphql/resolvers/worksheet/unloading/complete-product-scan-unload.ts +0 -25
  157. package/server/graphql/resolvers/worksheet/unloading/complete-unloading-partially.ts +0 -25
  158. package/server/graphql/resolvers/worksheet/unloading/complete-unloading.ts +0 -76
  159. package/server/graphql/resolvers/worksheet/unloading/index.ts +0 -21
  160. package/server/graphql/resolvers/worksheet/unloading/scan-product-unload.ts +0 -26
  161. package/server/graphql/resolvers/worksheet/unloading/scan-serial-number-unload.ts +0 -26
  162. package/server/graphql/resolvers/worksheet/unloading/undo-serial-number-unload.ts +0 -24
  163. package/server/graphql/resolvers/worksheet/unloading/undo-unloading.ts +0 -25
  164. package/server/graphql/resolvers/worksheet/unloading/unload.ts +0 -26
  165. package/server/graphql/resolvers/worksheet/unloading-return/activate-unloading-return.ts +0 -28
  166. package/server/graphql/resolvers/worksheet/unloading-return/complete-unload-return-partially.ts +0 -29
  167. package/server/graphql/resolvers/worksheet/unloading-return/complete-unload-returning.ts +0 -91
  168. package/server/graphql/resolvers/worksheet/unloading-return/index.ts +0 -9
  169. package/server/graphql/resolvers/worksheet/unloading-return-worksheet.ts +0 -75
  170. package/server/graphql/resolvers/worksheet/unloading-worksheet.ts +0 -98
  171. package/server/graphql/resolvers/worksheet/update-worksheet.ts +0 -25
  172. package/server/graphql/resolvers/worksheet/vas/activate-vas.ts +0 -25
  173. package/server/graphql/resolvers/worksheet/vas/assign-vas-inventories.ts +0 -25
  174. package/server/graphql/resolvers/worksheet/vas/complete-vas.ts +0 -72
  175. package/server/graphql/resolvers/worksheet/vas/execute-vas.ts +0 -31
  176. package/server/graphql/resolvers/worksheet/vas/index.ts +0 -15
  177. package/server/graphql/resolvers/worksheet/vas/undo-vas-inventory.ts +0 -24
  178. package/server/graphql/resolvers/worksheet/vas/undo-vas.ts +0 -24
  179. package/server/graphql/resolvers/worksheet/vas-candidates.ts +0 -177
  180. package/server/graphql/resolvers/worksheet/vas-inventories.ts +0 -41
  181. package/server/graphql/resolvers/worksheet/vas-transactions/common-utils.ts +0 -1182
  182. package/server/graphql/resolvers/worksheet/vas-transactions/index.ts +0 -5
  183. package/server/graphql/resolvers/worksheet/vas-transactions/interfaces/index.ts +0 -56
  184. package/server/graphql/resolvers/worksheet/vas-transactions/interfaces/relabeling.ts +0 -20
  185. package/server/graphql/resolvers/worksheet/vas-transactions/interfaces/repackaging.ts +0 -27
  186. package/server/graphql/resolvers/worksheet/vas-transactions/interfaces/repalletizing.ts +0 -14
  187. package/server/graphql/resolvers/worksheet/vas-transactions/interfaces/unpacking.ts +0 -14
  188. package/server/graphql/resolvers/worksheet/vas-transactions/relabeling/check-relabelable.ts +0 -96
  189. package/server/graphql/resolvers/worksheet/vas-transactions/relabeling/complete-relabeling.ts +0 -93
  190. package/server/graphql/resolvers/worksheet/vas-transactions/relabeling/index.ts +0 -4
  191. package/server/graphql/resolvers/worksheet/vas-transactions/relabeling/relabeling.ts +0 -105
  192. package/server/graphql/resolvers/worksheet/vas-transactions/relabeling/undo-relabeling.ts +0 -40
  193. package/server/graphql/resolvers/worksheet/vas-transactions/repackaging/complete-repackaging.ts +0 -236
  194. package/server/graphql/resolvers/worksheet/vas-transactions/repackaging/index.ts +0 -3
  195. package/server/graphql/resolvers/worksheet/vas-transactions/repackaging/repackaging.ts +0 -402
  196. package/server/graphql/resolvers/worksheet/vas-transactions/repackaging/undo-repackaging.ts +0 -166
  197. package/server/graphql/resolvers/worksheet/vas-transactions/repalletizing/complete-repalletizing.ts +0 -116
  198. package/server/graphql/resolvers/worksheet/vas-transactions/repalletizing/index.ts +0 -3
  199. package/server/graphql/resolvers/worksheet/vas-transactions/repalletizing/repalletizing.ts +0 -167
  200. package/server/graphql/resolvers/worksheet/vas-transactions/repalletizing/undo-repalletizing.ts +0 -74
  201. package/server/graphql/resolvers/worksheet/vas-transactions/unpacking/complete-unpacking.ts +0 -20
  202. package/server/graphql/resolvers/worksheet/vas-transactions/unpacking/index.ts +0 -2
  203. package/server/graphql/resolvers/worksheet/vas-transactions/unpacking/unpacking.ts +0 -164
  204. package/server/graphql/resolvers/worksheet/vas-worksheet.ts +0 -110
  205. package/server/graphql/resolvers/worksheet/worksheet-by-order-no.ts +0 -43
  206. package/server/graphql/resolvers/worksheet/worksheet-with-pagination.ts +0 -46
  207. package/server/graphql/resolvers/worksheet/worksheet.ts +0 -330
  208. package/server/graphql/resolvers/worksheet/worksheets.ts +0 -493
  209. package/server/graphql/resolvers/worksheet-detail/check-progressing-pallet.ts +0 -22
  210. package/server/graphql/resolvers/worksheet-detail/create-worksheet-detail.ts +0 -38
  211. package/server/graphql/resolvers/worksheet-detail/delete-worksheet-detail.ts +0 -18
  212. package/server/graphql/resolvers/worksheet-detail/generate-batch-picking-worksheet-details-by-bulk.ts +0 -206
  213. package/server/graphql/resolvers/worksheet-detail/generate-batch-picking-worksheet-details.ts +0 -165
  214. package/server/graphql/resolvers/worksheet-detail/generate-carton-id.ts +0 -26
  215. package/server/graphql/resolvers/worksheet-detail/generate-pallet-id.ts +0 -94
  216. package/server/graphql/resolvers/worksheet-detail/generate-picking-worksheet-details.ts +0 -259
  217. package/server/graphql/resolvers/worksheet-detail/generate-release-good-worksheet-details.ts +0 -142
  218. package/server/graphql/resolvers/worksheet-detail/index.ts +0 -34
  219. package/server/graphql/resolvers/worksheet-detail/regenerate-release-good-worksheet-details.ts +0 -165
  220. package/server/graphql/resolvers/worksheet-detail/update-worksheet-detail.ts +0 -39
  221. package/server/graphql/resolvers/worksheet-detail/worksheet-detail.ts +0 -19
  222. package/server/graphql/resolvers/worksheet-detail/worksheet-details-by-product-group.ts +0 -56
  223. package/server/graphql/resolvers/worksheet-detail/worksheet-details.ts +0 -21
  224. package/server/graphql/resolvers/worksheet-movement/create-worksheet-movement.ts +0 -17
  225. package/server/graphql/resolvers/worksheet-movement/delete-worksheet-movement.ts +0 -12
  226. package/server/graphql/resolvers/worksheet-movement/index.ts +0 -17
  227. package/server/graphql/resolvers/worksheet-movement/update-worksheet-movement.ts +0 -15
  228. package/server/graphql/resolvers/worksheet-movement/worksheet-movement.ts +0 -10
  229. package/server/graphql/resolvers/worksheet-movement/worksheet-movements.ts +0 -14
  230. package/server/graphql/types/index.ts +0 -15
  231. package/server/graphql/types/pallet/index.ts +0 -12
  232. package/server/graphql/types/pallet/pallet.ts +0 -7
  233. package/server/graphql/types/worksheet/arrival-notice-worksheet.ts +0 -8
  234. package/server/graphql/types/worksheet/batch-pick-worksheet-info.ts +0 -9
  235. package/server/graphql/types/worksheet/contact-point-info.ts +0 -12
  236. package/server/graphql/types/worksheet/cycle-count-worksheet.ts +0 -16
  237. package/server/graphql/types/worksheet/delivery-info.ts +0 -11
  238. package/server/graphql/types/worksheet/delivery-order-info.ts +0 -25
  239. package/server/graphql/types/worksheet/delivery-order-ro.ts +0 -15
  240. package/server/graphql/types/worksheet/delivery-worksheet.ts +0 -7
  241. package/server/graphql/types/worksheet/executing-worksheet.ts +0 -8
  242. package/server/graphql/types/worksheet/find-release-orders-by-task-no.ts +0 -8
  243. package/server/graphql/types/worksheet/goods-delivery-note.ts +0 -8
  244. package/server/graphql/types/worksheet/index.ts +0 -750
  245. package/server/graphql/types/worksheet/inventory-check-worksheet.ts +0 -7
  246. package/server/graphql/types/worksheet/loaded-worksheet-detail.ts +0 -9
  247. package/server/graphql/types/worksheet/multiple-release-good-worksheet.ts +0 -8
  248. package/server/graphql/types/worksheet/my-picking-assignment-status.ts +0 -9
  249. package/server/graphql/types/worksheet/new-worksheet.ts +0 -10
  250. package/server/graphql/types/worksheet/picking-assignment-status.ts +0 -9
  251. package/server/graphql/types/worksheet/product-approval.ts +0 -11
  252. package/server/graphql/types/worksheet/release-good-worksheet.ts +0 -8
  253. package/server/graphql/types/worksheet/return-order-worksheet.ts +0 -8
  254. package/server/graphql/types/worksheet/sellercraft-document.ts +0 -8
  255. package/server/graphql/types/worksheet/vas-order-worksheet.ts +0 -7
  256. package/server/graphql/types/worksheet/vas-worksheet.ts +0 -8
  257. package/server/graphql/types/worksheet/worksheet-detail-info.ts +0 -68
  258. package/server/graphql/types/worksheet/worksheet-info.ts +0 -33
  259. package/server/graphql/types/worksheet/worksheet-list.ts +0 -8
  260. package/server/graphql/types/worksheet/worksheet-patch.ts +0 -19
  261. package/server/graphql/types/worksheet/worksheet-with-pagination.ts +0 -9
  262. package/server/graphql/types/worksheet/worksheet.ts +0 -34
  263. package/server/graphql/types/worksheet-detail/index.ts +0 -81
  264. package/server/graphql/types/worksheet-detail/inventory-detail.ts +0 -39
  265. package/server/graphql/types/worksheet-detail/new-worksheet-detail.ts +0 -20
  266. package/server/graphql/types/worksheet-detail/pallet-info.ts +0 -8
  267. package/server/graphql/types/worksheet-detail/worksheet-detail-list.ts +0 -8
  268. package/server/graphql/types/worksheet-detail/worksheet-detail-patch.ts +0 -28
  269. package/server/graphql/types/worksheet-detail/worksheet-detail.ts +0 -29
  270. package/server/graphql/types/worksheet-movement/index.ts +0 -30
  271. package/server/graphql/types/worksheet-movement/new-worksheet-movement.ts +0 -8
  272. package/server/graphql/types/worksheet-movement/worksheet-movement-list.ts +0 -8
  273. package/server/graphql/types/worksheet-movement/worksheet-movement-patch.ts +0 -8
  274. package/server/graphql/types/worksheet-movement/worksheet-movement.ts +0 -10
  275. package/server/index.ts +0 -14
  276. package/server/middlewares/index.ts +0 -3
  277. package/server/migrations/index.ts +0 -9
  278. package/server/routes.ts +0 -80
  279. package/server/utils/datetime-util.ts +0 -54
  280. package/server/utils/index.ts +0 -4
  281. package/server/utils/inventory-util.ts +0 -390
  282. package/server/utils/worksheet-no-generator.ts +0 -206
  283. package/server/utils/worksheet-util.ts +0 -85
@@ -1,1398 +0,0 @@
1
- import { Equal, In, Not, SelectQueryBuilder } from 'typeorm'
2
-
3
- import { Bizplace } from '@things-factory/biz-base'
4
- import { generateId } from '@things-factory/id-rule-base'
5
- import { Product, ProductDetail } from '@things-factory/product-base'
6
- import {
7
- ArrivalNotice,
8
- ORDER_PRODUCT_STATUS,
9
- ORDER_STATUS,
10
- ORDER_TYPES,
11
- ORDER_VAS_STATUS,
12
- OrderInventory,
13
- OrderNoGenerator,
14
- OrderProduct,
15
- OrderVas,
16
- ReleaseGood,
17
- ReturnOrder,
18
- Vas,
19
- VAS_TARGET_TYPES,
20
- VAS_TYPES
21
- } from '@things-factory/sales-base'
22
- import { PartnerSetting, Setting } from '@things-factory/setting-base'
23
- import { Domain } from '@things-factory/shell'
24
- import {
25
- Inventory,
26
- INVENTORY_ITEM_SOURCE,
27
- INVENTORY_STATUS,
28
- INVENTORY_TRANSACTION_TYPE,
29
- InventoryHistory,
30
- InventoryItem,
31
- InventoryNoGenerator,
32
- Location,
33
- Pallet,
34
- Warehouse
35
- } from '@things-factory/warehouse-base'
36
-
37
- import { RULE_TYPE, WORKSHEET_STATUS, WORKSHEET_TYPE } from '../../constants'
38
- import { Worksheet, WorksheetDetail } from '../../entities'
39
- import { DateGenerator, generateInventoryHistory } from '../../utils'
40
- import { VasWorksheetController } from '../vas/vas-worksheet-controller'
41
-
42
- export type UnloadingWorksheetDetail = Partial<WorksheetDetail> & {
43
- palletizingVasId: string
44
- palletQty: number
45
- palletizingDescription: string
46
- }
47
-
48
- export class UnloadingWorksheetController extends VasWorksheetController {
49
- async generateUnloadingWorksheet(arrivalNoticeNo: string, bufferLocationId: string): Promise<Worksheet> {
50
- try {
51
- //@ts-ignore
52
- let arrivalNotice: ArrivalNotice = await this.findRefOrder(
53
- //@ts-ignore
54
- ArrivalNotice,
55
- {
56
- domain: { id: this.domain.id },
57
- name: arrivalNoticeNo,
58
- status: ORDER_STATUS.ARRIVED
59
- },
60
- ['bizplace', 'orderProducts', 'orderVass']
61
- )
62
- const orderProducts: OrderProduct[] = arrivalNotice.orderProducts
63
- const orderVASs: OrderVas[] = arrivalNotice.orderVass
64
- const bufferLocation: Location = await this.trxMgr.getRepository(Location).findOneBy({ id: bufferLocationId })
65
-
66
- const worksheet: Worksheet = await this.generateWorksheet(
67
- WORKSHEET_TYPE.UNLOADING,
68
- arrivalNotice,
69
- orderProducts,
70
- ORDER_STATUS.READY_TO_UNLOAD,
71
- ORDER_PRODUCT_STATUS.READY_TO_UNLOAD,
72
- { bufferLocation }
73
- )
74
-
75
- if (orderVASs?.length > 0) {
76
- await this.generateVasWorksheet(arrivalNotice)
77
- }
78
-
79
- return worksheet
80
- } catch (e) {
81
- throw new Error(e)
82
- }
83
- }
84
-
85
- async unload(worksheetDetailName: string, inventory: Partial<Inventory>, productBarcode: string): Promise<string> {
86
- const worksheetDetail: WorksheetDetail = await this.trxMgr.getRepository(WorksheetDetail).findOne({
87
- where: {
88
- name: worksheetDetailName,
89
- status: Not(Equal(WORKSHEET_STATUS.DEACTIVATED))
90
- },
91
- relations: [
92
- 'bizplace',
93
- 'worksheet',
94
- 'worksheet.arrivalNotice',
95
- 'worksheet.returnOrder',
96
- 'worksheet.bufferLocation',
97
- 'worksheet.bufferLocation.warehouse',
98
- 'targetProduct',
99
- 'targetProduct.product',
100
- 'targetProduct.product.productDetails',
101
- 'targetProduct.product.productDetails.childProductDetail',
102
- 'targetInventory',
103
- 'targetInventory.inventory',
104
- 'targetInventory.product',
105
- 'targetInventory.product.productDetails',
106
- 'targetInventory.product.productDetails.childProductDetail'
107
- ]
108
- })
109
- if (!worksheetDetail) throw new Error(this.ERROR_MSG.FIND.NO_RESULT(worksheetDetailName))
110
- const targetProduct: OrderProduct = worksheetDetail.targetProduct
111
-
112
- if (targetProduct && targetProduct.status == ORDER_PRODUCT_STATUS.EDITED)
113
- throw new Error('this product is pending for changes approval')
114
-
115
- const bizplace: Bizplace = worksheetDetail.bizplace
116
- const companyDomain: Domain = bizplace?.company?.domain
117
- const worksheet: Worksheet = worksheetDetail.worksheet
118
- const arrivalNotice: ArrivalNotice = worksheet.arrivalNotice
119
- const returnOrder: ReturnOrder = worksheet.returnOrder
120
- const orderId: string = Boolean(arrivalNotice?.id) ? arrivalNotice.id : returnOrder.id
121
- const targetInventory: OrderInventory = worksheetDetail?.targetInventory
122
- //@ts-ignore
123
- const originInventory: OrderInventory = targetInventory ? targetInventory.inventory : null
124
- const batchId: string = Boolean(arrivalNotice) ? targetProduct.batchId : targetInventory.batchId
125
- const batchIdRef: string = Boolean(arrivalNotice) ? targetProduct.batchIdRef : null
126
- const product: Product = Boolean(arrivalNotice) ? targetProduct.product : targetInventory.product
127
- const packingType: string = Boolean(arrivalNotice) ? targetProduct.packingType : targetInventory.packingType
128
- const packingSize: number = Boolean(arrivalNotice) ? targetProduct.packingSize : targetInventory.packingSize
129
- const remark: string = Boolean(arrivalNotice) ? targetProduct.remark : targetInventory.remark
130
- //@ts-ignore
131
- const manufactureDate: number = Boolean(arrivalNotice) ? targetProduct.manufactureDate : null
132
- let qty: number = inventory.qty
133
- let uom: string = Boolean(arrivalNotice) ? targetProduct.uom : originInventory.uom
134
- const location: Location = worksheet.bufferLocation
135
- const warehouse: Warehouse = location.warehouse
136
- const zone: string = location.zone
137
- const unitCost: number = Boolean(arrivalNotice)
138
- ? targetProduct?.unitPrice
139
- ? ((targetProduct.packQty * targetProduct.unitPrice + targetProduct.miscAmt - targetProduct.discountAmt) *
140
- (1 + targetProduct.taxRate / 100)) /
141
- targetProduct.packQty
142
- : 0
143
- : null
144
-
145
- const palletId: string = inventory?.palletId
146
- const cartonId: string = inventory?.cartonId
147
-
148
- if (!inventory?.palletId) {
149
- inventory.palletId = await generateId({
150
- domain: this.domain,
151
- type: RULE_TYPE.LOT_NUMBER_ID,
152
- seed: { date: DateGenerator.generateDate() }
153
- })
154
- if (inventory?.cartonId) await this.checkCartonDuplication(cartonId, orderId)
155
- } else {
156
- await this.checkPalletDuplication(palletId)
157
- }
158
-
159
- if (productBarcode) {
160
- const productDetails: ProductDetail[] = product?.productDetails.filter(detail => !detail.deletedAt)
161
- const isMatchingBarcode: boolean = productDetails.map(detail => detail.gtin).includes(productBarcode)
162
- if (!isMatchingBarcode) throw new Error(this.ERROR_MSG.FIND.NO_RESULT(productBarcode))
163
-
164
- const foundProductDetail: ProductDetail = productDetails.find(
165
- (detail: ProductDetail) =>
166
- detail.gtin === productBarcode && detail.packingType === packingType && detail.packingSize == packingSize
167
- )
168
-
169
- if (!foundProductDetail) {
170
- const orderProductDetail: ProductDetail = productDetails.find(
171
- (parentDetail: ProductDetail) =>
172
- parentDetail.packingType === packingType && parentDetail.packingSize == packingSize
173
- )
174
- if (!orderProductDetail)
175
- throw new Error(
176
- this.ERROR_MSG.FIND.NO_RESULT(`Packing Type ( ${packingType}) or Packing Size (${packingSize})`)
177
- )
178
-
179
- if (arrivalNotice) {
180
- uom = targetProduct.uom
181
- } else {
182
- uom = orderProductDetail.uom
183
- }
184
- qty = (await this.getChildQty(productDetails, productBarcode, orderProductDetail)) * qty
185
- } else {
186
- uom = foundProductDetail.uom
187
- qty
188
- }
189
- }
190
-
191
- const uomValue: number =
192
- Math.round(
193
- qty *
194
- (Boolean(arrivalNotice)
195
- ? targetProduct.uomValue
196
- : targetInventory.returnUomValue / targetInventory.returnQty) *
197
- 100
198
- ) / 100
199
-
200
- let newInventory: Partial<Inventory> = new Inventory()
201
- newInventory.bizplace = bizplace
202
- newInventory.name = InventoryNoGenerator.inventoryName()
203
- newInventory.palletId = inventory.palletId
204
- newInventory.cartonId = inventory.cartonId
205
- newInventory.batchId = batchId
206
- newInventory.product = product
207
- newInventory.packingType = packingType
208
- newInventory.packingSize = packingSize
209
- newInventory.uom = uom
210
- newInventory.remark = remark
211
- newInventory.qty = qty
212
- newInventory.uomValue = uomValue
213
- newInventory.refOrderId = orderId
214
- newInventory.unitCost = unitCost
215
- if (inventory.reusablePallet?.id) {
216
- newInventory.reusablePallet = await this.trxMgr
217
- .getRepository(Pallet)
218
- .findOneBy({ id: inventory.reusablePallet.id })
219
- }
220
- if (arrivalNotice) {
221
- if (manufactureDate) {
222
- //@ts-ignore
223
- newInventory.manufactureDate = manufactureDate
224
- } else if (inventory?.manufactureDate) {
225
- newInventory.manufactureDate = new Date(inventory.manufactureDate)
226
- }
227
- newInventory.batchIdRef = batchIdRef
228
- newInventory.orderProductId = targetProduct?.id
229
- } else if (returnOrder) {
230
- newInventory.orderInventoryId = targetInventory?.id
231
- newInventory.refInventory = targetInventory?.inventory
232
- }
233
- newInventory.warehouse = warehouse
234
- newInventory.location = location
235
- newInventory.zone = zone
236
- newInventory.status = INVENTORY_STATUS.UNLOADED
237
-
238
- // product color, quality, zaho, work category
239
- newInventory.productColor = inventory.productColor || ''
240
- newInventory.productQuality = inventory.productQuality || ''
241
- newInventory.auxInfo2 = inventory.auxInfo2 || null
242
- newInventory.workCategory = inventory.workCategory || ''
243
-
244
- if (inventory?.expirationDate) {
245
- newInventory.expirationDate = new Date(inventory.expirationDate)
246
- }
247
-
248
- newInventory = await this.transactionInventory(
249
- newInventory,
250
- Boolean(arrivalNotice) ? arrivalNotice : returnOrder,
251
- newInventory.qty,
252
- newInventory.uomValue,
253
- INVENTORY_TRANSACTION_TYPE.UNLOADING
254
- )
255
-
256
- if (arrivalNotice) {
257
- targetProduct.actualPalletQty++
258
- targetProduct.actualPackQty += qty
259
- targetProduct.status = ORDER_PRODUCT_STATUS.UNLOADED
260
- targetProduct.updater = this.user
261
- this.updateOrderTargets([targetProduct])
262
- } else if (returnOrder) {
263
- targetInventory.actualPalletQty++
264
- targetInventory.actualPackQty += qty
265
- targetInventory.status = ORDER_PRODUCT_STATUS.UNLOADED
266
- targetInventory.updater = this.user
267
- this.updateOrderTargets([targetInventory])
268
- }
269
-
270
- return inventory.palletId
271
- }
272
-
273
- async scanSerialNumberUnload(
274
- worksheetDetailName: string,
275
- serialNumber: string,
276
- inventory: Partial<Inventory>
277
- ): Promise<void> {
278
- const worksheetDetail: WorksheetDetail = await this.trxMgr.getRepository(WorksheetDetail).findOne({
279
- where: {
280
- name: worksheetDetailName,
281
- status: Not(Equal(WORKSHEET_STATUS.DEACTIVATED))
282
- },
283
- relations: [
284
- 'bizplace',
285
- 'worksheet',
286
- 'worksheet.arrivalNotice',
287
- 'worksheet.returnOrder',
288
- 'worksheet.bufferLocation',
289
- 'worksheet.bufferLocation.warehouse',
290
- 'targetProduct',
291
- 'targetProduct.product',
292
- 'targetProduct.product.productDetails',
293
- 'targetProduct.product.productDetails.childProductDetail',
294
- 'targetInventory',
295
- 'targetInventory.product',
296
- 'targetInventory.product.productDetails',
297
- 'targetInventory.product.productDetails.childProductDetail'
298
- ]
299
- })
300
- if (!worksheetDetail) throw new Error(this.ERROR_MSG.FIND.NO_RESULT(worksheetDetailName))
301
-
302
- if (!inventory?.palletId)
303
- inventory.palletId = await generateId({
304
- domain: this.domain,
305
- type: RULE_TYPE.LOT_NUMBER_ID,
306
- seed: { date: DateGenerator.generateDate() }
307
- })
308
-
309
- const targetProduct: OrderProduct = worksheetDetail.targetProduct
310
-
311
- if (targetProduct.status == ORDER_PRODUCT_STATUS.EDITED)
312
- throw new Error('this product is pending for changes approval')
313
-
314
- const bizplace: Bizplace = worksheetDetail.bizplace
315
- const worksheet: Worksheet = worksheetDetail.worksheet
316
- const arrivalNotice: ArrivalNotice = worksheet.arrivalNotice
317
- const returnOrder: ReturnOrder = worksheet.returnOrder
318
- const targetInventory: OrderInventory = worksheetDetail.targetInventory
319
- const product: Product = Boolean(arrivalNotice) ? targetProduct.product : targetInventory.product
320
- const packingType: string = Boolean(arrivalNotice) ? targetProduct.packingType : targetInventory.packingType
321
- const packingSize: number = Boolean(arrivalNotice) ? targetProduct.packingSize : targetInventory.packingSize
322
- const batchId: string = Boolean(arrivalNotice) ? targetProduct.batchId : targetInventory.batchId
323
- let qty: number = 0
324
- let uom: string = Boolean(arrivalNotice) ? targetProduct.uom : targetInventory.uom
325
- const cartonId: string = inventory.cartonId
326
- const orderId: string = Boolean(arrivalNotice) ? arrivalNotice.id : returnOrder.id
327
- await this.checkSerialNumberDuplication(serialNumber, product)
328
-
329
- qty++
330
-
331
- const invQb: SelectQueryBuilder<Inventory> = await this.trxMgr
332
- .getRepository(Inventory)
333
- .createQueryBuilder('INV')
334
- .where('INV.domain_id = :domainId', { domainId: this.domain.id })
335
- .andWhere('INV.bizplace_id = :bizplaceId', { bizplaceId: bizplace.id })
336
- .andWhere('INV.product_id = :productId', { productId: product.id })
337
- .andWhere('INV.batch_id = :batchId', { batchId: batchId })
338
- .andWhere('INV.packing_type = :packingType', { packingType: packingType })
339
- .andWhere('INV.packing_size = :packingSize', { packingSize: packingSize })
340
-
341
- if (arrivalNotice) invQb.andWhere('INV.ref_order_id = :arrivalNoticeId', { arrivalNoticeId: arrivalNotice.id })
342
- else if (returnOrder) invQb.andWhere('INV.ref_order_id = :returnOrderId', { returnOrderId: returnOrder.id })
343
-
344
- if (inventory?.expirationDate) {
345
- invQb.andWhere('INV.expiration_date = :expirationDate', {
346
- expirationDate: inventory.expirationDate
347
- })
348
- }
349
-
350
- if (inventory?.cartonId) invQb.andWhere('INV.carton_id = :cartonId', { cartonId: inventory.cartonId })
351
- else invQb.andWhere('INV.pallet_id = :palletId', { palletId: inventory.palletId })
352
-
353
- let foundInventory: Inventory = await invQb.getOne()
354
-
355
- const batchIdRef: string = Boolean(arrivalNotice) ? targetProduct.batchIdRef : null
356
- const remark: string = Boolean(arrivalNotice) ? targetProduct.remark : targetInventory.remark
357
- //@ts-ignore
358
- const manufactureDate: number = Boolean(arrivalNotice) ? targetProduct.manufactureDate : null
359
- const location: Location = worksheet.bufferLocation
360
- const warehouse: Warehouse = location.warehouse
361
- const zone: string = location.zone
362
- const unitCost: number = Boolean(arrivalNotice)
363
- ? targetProduct?.unitPrice
364
- ? ((targetProduct.packQty * targetProduct.unitPrice + targetProduct.miscAmt - targetProduct.discountAmt) *
365
- (1 + targetProduct.taxRate / 100)) /
366
- targetProduct.packQty
367
- : 0
368
- : null
369
-
370
- if (!foundInventory) {
371
- let newInventory: Partial<Inventory> = new Inventory()
372
- newInventory.bizplace = bizplace
373
- newInventory.domain = this.domain
374
- newInventory.name = InventoryNoGenerator.inventoryName()
375
- newInventory.palletId = inventory.palletId
376
- newInventory.cartonId = inventory.cartonId
377
- newInventory.batchId = batchId
378
- newInventory.batchIdRef = batchIdRef
379
- newInventory.product = product
380
- newInventory.packingType = packingType
381
- newInventory.packingSize = packingSize
382
- newInventory.uom = uom
383
- newInventory.remark = remark
384
- newInventory.qty = qty
385
- newInventory.uomValue =
386
- Math.round(
387
- qty *
388
- (Boolean(arrivalNotice)
389
- ? targetProduct.uomValue
390
- : targetInventory.returnUomValue / targetInventory.returnQty) *
391
- 100
392
- ) / 100
393
- //@ts-ignore
394
- newInventory.manufactureDate = manufactureDate
395
- newInventory.refOrderId = orderId
396
- newInventory.unitCost = unitCost
397
- if (inventory.reusablePallet?.id) {
398
- newInventory.reusablePallet = await this.trxMgr
399
- .getRepository(Pallet)
400
- .findOneBy({ id: inventory.reusablePallet.id })
401
- }
402
- newInventory.orderProductId = Boolean(arrivalNotice) ? targetProduct.id : null
403
- newInventory.orderInventoryId = Boolean(returnOrder) ? targetInventory.id : null
404
- newInventory.warehouse = warehouse
405
- newInventory.location = location
406
- newInventory.zone = zone
407
- newInventory.status = INVENTORY_STATUS.CHECKED
408
- newInventory.creator = this.user
409
-
410
- if (inventory?.expirationDate) {
411
- newInventory.expirationDate = new Date(inventory.expirationDate)
412
- }
413
-
414
- if (arrivalNotice) {
415
- targetProduct.actualPalletQty++
416
- targetProduct.actualPackQty = Boolean(targetProduct.actualPackQty) ? targetProduct.actualPackQty + qty : qty
417
- } else if (returnOrder) {
418
- targetInventory.actualPalletQty++
419
- targetInventory.actualPackQty = Boolean(targetInventory.actualPackQty)
420
- ? targetInventory.actualPackQty + qty
421
- : qty
422
- }
423
- foundInventory = await this.trxMgr.getRepository(Inventory).save(newInventory)
424
- } else {
425
- const updatedQty: number = foundInventory.qty + qty
426
- foundInventory.expirationDate = foundInventory.expirationDate ? new Date(foundInventory.expirationDate) : null
427
- foundInventory.qty = updatedQty
428
- foundInventory.uomValue +=
429
- Math.round(
430
- qty *
431
- (Boolean(arrivalNotice)
432
- ? targetProduct.uomValue
433
- : targetInventory.returnUomValue / targetInventory.returnQty) *
434
- 100
435
- ) / 100
436
- if (arrivalNotice) targetProduct.actualPackQty = targetProduct.actualPackQty + qty
437
- else if (returnOrder) targetInventory.actualPackQty = targetInventory.actualPackQty + qty
438
- foundInventory = await this.trxMgr.getRepository(Inventory).save(foundInventory)
439
- }
440
-
441
- let inventoryItem: InventoryItem = new InventoryItem()
442
- inventoryItem.name = InventoryNoGenerator.inventoryItemName()
443
- inventoryItem.serialNumber = serialNumber
444
- inventoryItem.status = foundInventory.status
445
- inventoryItem.inboundOrderId = foundInventory.refOrderId
446
- inventoryItem.product = product
447
- inventoryItem.inventory = foundInventory
448
- inventoryItem.source = INVENTORY_ITEM_SOURCE.INBOUND
449
- inventoryItem.domain = this.domain
450
- inventoryItem.creator = this.user
451
- inventoryItem.updater = this.user
452
-
453
- await this.trxMgr.getRepository(InventoryItem).save(inventoryItem)
454
-
455
- if (arrivalNotice) {
456
- targetProduct.updater = this.user
457
- this.updateOrderTargets([targetProduct])
458
- } else if (returnOrder) {
459
- targetInventory.updater = this.user
460
- this.updateOrderTargets([targetInventory])
461
- }
462
- }
463
-
464
- async scanProductUnload(
465
- worksheetDetailName: string,
466
- productBarcode: string,
467
- inventory: Partial<Inventory>
468
- ): Promise<void> {
469
- const worksheetDetail: WorksheetDetail = await this.trxMgr.getRepository(WorksheetDetail).findOne({
470
- where: {
471
- name: worksheetDetailName,
472
- status: Not(Equal(WORKSHEET_STATUS.DEACTIVATED))
473
- },
474
- relations: [
475
- 'bizplace',
476
- 'worksheet',
477
- 'worksheet.arrivalNotice',
478
- 'worksheet.returnOrder',
479
- 'worksheet.bufferLocation',
480
- 'worksheet.bufferLocation.warehouse',
481
- 'targetProduct',
482
- 'targetProduct.product',
483
- 'targetProduct.product.productDetails',
484
- 'targetProduct.product.productDetails.childProductDetail',
485
- 'targetInventory',
486
- 'targetInventory.product',
487
- 'targetInventory.product.productDetails',
488
- 'targetInventory.product.productDetails.childProductDetail'
489
- ]
490
- })
491
- if (!worksheetDetail) throw new Error(this.ERROR_MSG.FIND.NO_RESULT(worksheetDetailName))
492
-
493
- if (!inventory?.palletId)
494
- inventory.palletId = await generateId({
495
- domain: this.domain,
496
- type: RULE_TYPE.LOT_NUMBER_ID,
497
- seed: { date: DateGenerator.generateDate() }
498
- })
499
-
500
- const targetProduct: OrderProduct = worksheetDetail.targetProduct
501
-
502
- if (targetProduct.status == ORDER_PRODUCT_STATUS.EDITED)
503
- throw new Error('this product is pending for changes approval')
504
-
505
- const bizplace: Bizplace = worksheetDetail.bizplace
506
- const worksheet: Worksheet = worksheetDetail.worksheet
507
- const arrivalNotice: ArrivalNotice = worksheet.arrivalNotice
508
- const returnOrder: ReturnOrder = worksheet.returnOrder
509
- const targetInventory: OrderInventory = worksheetDetail.targetInventory
510
- const product: Product = Boolean(arrivalNotice) ? targetProduct.product : targetInventory.product
511
- const packingType: string = Boolean(arrivalNotice) ? targetProduct.packingType : targetInventory.packingType
512
- const packingSize: number = Boolean(arrivalNotice) ? targetProduct.packingSize : targetInventory.packingSize
513
- const batchId: string = Boolean(arrivalNotice) ? targetProduct.batchId : targetInventory.batchId
514
- let qty: number = 0
515
- let uom: string = Boolean(arrivalNotice) ? targetProduct.uom : targetInventory.uom
516
- const cartonId: string = inventory.cartonId
517
- const orderId: string = Boolean(arrivalNotice) ? arrivalNotice.id : returnOrder.id
518
- await this.checkCartonDuplication(cartonId, orderId)
519
-
520
- // search for matching product barcode
521
- const productDetails: ProductDetail[] = product?.productDetails.filter(detail => !detail.deletedAt)
522
- const isMatchingBarcode: boolean = productDetails.map(detail => detail.gtin).includes(productBarcode)
523
- if (!isMatchingBarcode) throw new Error(this.ERROR_MSG.FIND.NO_RESULT(productBarcode))
524
-
525
- // case for scanning parent packing type, packing size
526
- const foundProductDetail: ProductDetail = productDetails.find(
527
- (detail: ProductDetail) =>
528
- detail.gtin === productBarcode && detail.packingType === packingType && detail.packingSize == packingSize
529
- )
530
-
531
- if (!foundProductDetail) {
532
- const orderProductDetail: ProductDetail = productDetails.find(
533
- (parentDetail: ProductDetail) =>
534
- parentDetail.packingType === packingType && parentDetail.packingSize == packingSize
535
- )
536
- if (!orderProductDetail)
537
- throw new Error(
538
- this.ERROR_MSG.FIND.NO_RESULT(`Packing Type ( ${packingType}) or Packing Size (${packingSize})`)
539
- )
540
-
541
- if (arrivalNotice) {
542
- uom = targetProduct.uom
543
- } else {
544
- uom = orderProductDetail.uom
545
- }
546
- qty = await this.getChildQty(productDetails, productBarcode, orderProductDetail)
547
- } else {
548
- uom = foundProductDetail.uom
549
- qty++
550
- }
551
-
552
- const invQb: SelectQueryBuilder<Inventory> = await this.trxMgr
553
- .getRepository(Inventory)
554
- .createQueryBuilder('INV')
555
- .where('INV.domain_id = :domainId', { domainId: this.domain.id })
556
- .andWhere('INV.bizplace_id = :bizplaceId', { bizplaceId: bizplace.id })
557
- .andWhere('INV.product_id = :productId', { productId: product.id })
558
- .andWhere('INV.batch_id = :batchId', { batchId: batchId })
559
- .andWhere('INV.packing_type = :packingType', { packingType: packingType })
560
- .andWhere('INV.packing_size = :packingSize', { packingSize: packingSize })
561
-
562
- if (arrivalNotice) invQb.andWhere('INV.ref_order_id = :arrivalNoticeId', { arrivalNoticeId: arrivalNotice.id })
563
- else if (returnOrder) invQb.andWhere('INV.ref_order_id = :returnOrderId', { returnOrderId: returnOrder.id })
564
-
565
- if (inventory?.expirationDate) {
566
- invQb.andWhere('INV.expiration_date = :expirationDate', {
567
- expirationDate: inventory.expirationDate
568
- })
569
- }
570
-
571
- if (inventory?.cartonId) invQb.andWhere('INV.carton_id = :cartonId', { cartonId: inventory.cartonId })
572
- else invQb.andWhere('INV.pallet_id = :palletId', { palletId: inventory.palletId })
573
-
574
- let foundInventory: Inventory = await invQb.getOne()
575
-
576
- const batchIdRef: string = Boolean(arrivalNotice) ? targetProduct.batchIdRef : null
577
- const remark: string = Boolean(arrivalNotice) ? targetProduct.remark : targetInventory.remark
578
- //@ts-ignore
579
- const manufactureDate: number = Boolean(arrivalNotice) ? targetProduct.manufactureDate : null
580
- const location: Location = worksheet.bufferLocation
581
- const warehouse: Warehouse = location.warehouse
582
- const zone: string = location.zone
583
- const unitCost: number = Boolean(arrivalNotice)
584
- ? targetProduct?.unitPrice
585
- ? ((targetProduct.packQty * targetProduct.unitPrice + targetProduct.miscAmt - targetProduct.discountAmt) *
586
- (1 + targetProduct.taxRate / 100)) /
587
- targetProduct.packQty
588
- : 0
589
- : null
590
-
591
- if (!foundInventory) {
592
- let newInventory: Partial<Inventory> = new Inventory()
593
- newInventory.bizplace = bizplace
594
- newInventory.domain = this.domain
595
- newInventory.name = InventoryNoGenerator.inventoryName()
596
- newInventory.palletId = inventory.palletId
597
- newInventory.cartonId = inventory.cartonId
598
- newInventory.batchId = batchId
599
- newInventory.batchIdRef = batchIdRef
600
- newInventory.product = product
601
- newInventory.packingType = packingType
602
- newInventory.packingSize = packingSize
603
- newInventory.uom = uom
604
- newInventory.remark = remark
605
- newInventory.qty = qty
606
- newInventory.uomValue =
607
- Math.round(
608
- qty *
609
- (Boolean(arrivalNotice)
610
- ? targetProduct.uomValue
611
- : targetInventory.returnUomValue / targetInventory.returnQty) *
612
- 100
613
- ) / 100
614
- //@ts-ignore
615
- newInventory.manufactureDate = manufactureDate
616
- newInventory.refOrderId = orderId
617
- newInventory.unitCost = unitCost
618
- if (inventory.reusablePallet?.id) {
619
- newInventory.reusablePallet = await this.trxMgr
620
- .getRepository(Pallet)
621
- .findOneBy({ id: inventory.reusablePallet.id })
622
- }
623
- newInventory.orderProductId = Boolean(arrivalNotice) ? targetProduct.id : null
624
- newInventory.orderInventoryId = Boolean(returnOrder) ? targetInventory.id : null
625
- newInventory.warehouse = warehouse
626
- newInventory.location = location
627
- newInventory.zone = zone
628
- newInventory.status = INVENTORY_STATUS.CHECKED
629
- newInventory.creator = this.user
630
-
631
- if (inventory?.expirationDate) {
632
- newInventory.expirationDate = new Date(inventory.expirationDate)
633
- }
634
-
635
- if (arrivalNotice) {
636
- targetProduct.actualPalletQty++
637
- targetProduct.actualPackQty = Boolean(targetProduct.actualPackQty) ? targetProduct.actualPackQty + qty : qty
638
- } else if (returnOrder) {
639
- targetInventory.actualPalletQty++
640
- targetInventory.actualPackQty = Boolean(targetInventory.actualPackQty)
641
- ? targetInventory.actualPackQty + qty
642
- : qty
643
- }
644
- await this.trxMgr.getRepository(Inventory).save(newInventory)
645
- } else {
646
- const updatedQty: number = foundInventory.qty + qty
647
- foundInventory.expirationDate = foundInventory.expirationDate ? new Date(foundInventory.expirationDate) : null
648
- foundInventory.qty = updatedQty
649
- foundInventory.uomValue +=
650
- Math.round(
651
- qty *
652
- (Boolean(arrivalNotice)
653
- ? targetProduct.uomValue
654
- : targetInventory.returnUomValue / targetInventory.returnQty) *
655
- 100
656
- ) / 100
657
- if (arrivalNotice) targetProduct.actualPackQty = targetProduct.actualPackQty + qty
658
- else if (returnOrder) targetInventory.actualPackQty = targetInventory.actualPackQty + qty
659
- await this.trxMgr.getRepository(Inventory).save(foundInventory)
660
- }
661
-
662
- if (arrivalNotice) {
663
- targetProduct.updater = this.user
664
- this.updateOrderTargets([targetProduct])
665
- } else if (returnOrder) {
666
- targetInventory.updater = this.user
667
- this.updateOrderTargets([targetInventory])
668
- }
669
- }
670
-
671
- async completeProductScanUnload(worksheetDetailName: string, inventory: Partial<Inventory>): Promise<void> {
672
- const worksheetDetail: WorksheetDetail = await this.trxMgr.getRepository(WorksheetDetail).findOne({
673
- where: {
674
- name: worksheetDetailName,
675
- status: Not(Equal(WORKSHEET_STATUS.DEACTIVATED))
676
- },
677
- relations: [
678
- 'bizplace',
679
- 'worksheet',
680
- 'worksheet.arrivalNotice',
681
- 'worksheet.returnOrder',
682
- 'worksheet.bufferLocation',
683
- 'worksheet.bufferLocation.warehouse',
684
- 'targetProduct',
685
- 'targetProduct.product',
686
- 'targetInventory',
687
- 'targetInventory.product'
688
- ]
689
- })
690
- if (!worksheetDetail) throw new Error(this.ERROR_MSG.FIND.NO_RESULT(worksheetDetailName))
691
-
692
- const bizplace: Bizplace = worksheetDetail.bizplace
693
- const worksheet: Worksheet = worksheetDetail.worksheet
694
- const arrivalNotice: ArrivalNotice = worksheet.arrivalNotice
695
- const returnOrder: ReturnOrder = worksheet.returnOrder
696
- const targetProduct: OrderProduct = worksheetDetail.targetProduct
697
- const targetInventory: OrderInventory = worksheetDetail.targetInventory
698
- const product: Product = Boolean(arrivalNotice) ? targetProduct.product : targetInventory.product
699
- const packingType: string = Boolean(arrivalNotice) ? targetProduct.packingType : targetInventory.packingType
700
- const packingSize: number = Boolean(arrivalNotice) ? targetProduct.packingSize : targetInventory.packingSize
701
- const batchId: string = Boolean(arrivalNotice) ? targetProduct.batchId : targetInventory.batchId
702
-
703
- const invQb: SelectQueryBuilder<Inventory> = await this.trxMgr
704
- .getRepository(Inventory)
705
- .createQueryBuilder('INV')
706
- .where('INV.domain_id = :domainId', { domainId: this.domain.id })
707
- .andWhere('INV.bizplace_id = :bizplaceId', { bizplaceId: bizplace.id })
708
- .andWhere('INV.product_id = :productId', { productId: product.id })
709
- .andWhere('INV.batch_id = :batchId', { batchId: batchId })
710
- .andWhere('INV.packing_type = :packingType', { packingType: packingType })
711
- .andWhere('INV.packing_size = :packingSize', { packingSize: packingSize })
712
-
713
- if (arrivalNotice) invQb.andWhere('INV.ref_order_id = :arrivalNoticeId', { arrivalNoticeId: arrivalNotice.id })
714
- else if (returnOrder) invQb.andWhere('INV.ref_order_id = :returnOrderId', { returnOrderId: returnOrder.id })
715
-
716
- if (inventory?.expirationDate) {
717
- invQb.andWhere('INV.expiration_date = :expirationDate', {
718
- expirationDate: inventory.expirationDate
719
- })
720
- }
721
-
722
- if (inventory?.cartonId) invQb.andWhere('INV.carton_id = :cartonId', { cartonId: inventory.cartonId })
723
- else invQb.andWhere('INV.pallet_id = :palletId', { palletId: inventory.palletId })
724
-
725
- let foundInventory: Inventory = await invQb.getOne()
726
- if (!foundInventory) throw new Error(this.ERROR_MSG.FIND.NO_RESULT(foundInventory.palletId))
727
-
728
- foundInventory.status = INVENTORY_STATUS.UNLOADED
729
-
730
- foundInventory = await this.transactionInventory(
731
- foundInventory,
732
- Boolean(arrivalNotice) ? arrivalNotice : returnOrder,
733
- foundInventory.qty,
734
- foundInventory.uomValue,
735
- INVENTORY_TRANSACTION_TYPE.UNLOADING
736
- )
737
- }
738
-
739
- async undoUnload(orderType: string, orderNo: string, inventoryIds: [string]): Promise<void> {
740
- for (var i = 0; i < inventoryIds.length; i++) {
741
- const inventoryId: string = inventoryIds[i]
742
- let inventory: Inventory = await this.trxMgr.getRepository(Inventory).findOne({
743
- where: { domain: { id: this.domain.id }, id: inventoryId },
744
- relations: ['location', 'product']
745
- })
746
-
747
- this.checkRecordValidity(inventory, {
748
- status: (status: string) => {
749
- const availableStatus: string[] = [INVENTORY_STATUS.UNLOADED, INVENTORY_STATUS.CHECKED]
750
- if (availableStatus.indexOf(status) < 0) {
751
- throw new Error(
752
- this.ERROR_MSG.VALIDITY.UNEXPECTED_FIELD_VALUE(
753
- 'status',
754
- 'Inventory current status unable to undo',
755
- status
756
- )
757
- )
758
- }
759
- return true
760
- }
761
- })
762
-
763
- const qty: number = inventory.qty
764
-
765
- let targetProduct: OrderProduct
766
- let targetInventory: OrderInventory
767
- let arrivalNotice: ArrivalNotice
768
- let returnOrder: ReturnOrder
769
- let worksheetDetail: WorksheetDetail
770
-
771
- if (orderType === ORDER_TYPES.ARRIVAL_NOTICE) {
772
- arrivalNotice = await this.trxMgr.getRepository(ArrivalNotice).findOne({
773
- where: { domain: { id: this.domain.id }, name: orderNo },
774
- relations: ['orderProducts', 'orderProducts.product']
775
- })
776
-
777
- targetProduct = arrivalNotice.orderProducts.find(op => op.id === inventory.orderProductId)
778
-
779
- if (inventory.status == INVENTORY_STATUS.UNLOADED) {
780
- targetProduct.actualPackQty -= qty
781
- targetProduct.actualPalletQty--
782
- targetProduct.remark = null
783
- targetProduct.issue = null
784
- targetProduct.status = ORDER_PRODUCT_STATUS.UNLOADING
785
- } else {
786
- targetProduct.actualPackQty--
787
- // targetProduct.actualPalletQty--
788
- }
789
- targetProduct.updater = this.user
790
- await this.updateOrderTargets([targetProduct])
791
-
792
- worksheetDetail = await this.trxMgr
793
- .getRepository(WorksheetDetail)
794
- .findOne({ where: { domain: { id: this.domain.id }, targetProduct: { id: targetProduct.id } } })
795
- } else {
796
- returnOrder = await this.trxMgr.getRepository(ReturnOrder).findOne({
797
- where: { domain: { id: this.domain.id }, name: orderNo },
798
- relations: ['orderInventories', 'orderInventories.inventory', 'orderInventories.product']
799
- })
800
-
801
- targetInventory = returnOrder.orderInventories.find(
802
- oi =>
803
- oi.batchId == inventory.batchId &&
804
- oi.packingType == inventory.packingType &&
805
- oi.product.id == inventory.product.id &&
806
- oi.packingSize === inventory.packingSize
807
- )
808
- if (inventory.status == INVENTORY_STATUS.UNLOADED) {
809
- targetInventory.actualPackQty -= qty
810
- targetInventory.actualPalletQty--
811
- targetInventory.status = ORDER_PRODUCT_STATUS.UNLOADING
812
- } else {
813
- targetInventory.actualPackQty--
814
- // targetInventory.actualPalletQty--
815
- }
816
- targetInventory.updater = this.user
817
- await this.updateOrderTargets([targetInventory])
818
-
819
- worksheetDetail = await this.trxMgr
820
- .getRepository(WorksheetDetail)
821
- .findOne({ where: { domain: { id: this.domain.id }, targetInventory: { id: targetInventory.id } } })
822
- }
823
-
824
- if (inventory.status == INVENTORY_STATUS.CHECKED) {
825
- inventory.qty--
826
- inventory.uomValue =
827
- Math.round(
828
- inventory.qty *
829
- (Boolean(orderType === ORDER_TYPES.ARRIVAL_NOTICE)
830
- ? targetProduct.uomValue
831
- : targetInventory.returnUomValue) *
832
- 100
833
- ) / 100
834
- inventory.updater = this.user
835
- await this.trxMgr.getRepository(Inventory).save(inventory)
836
-
837
- if (inventory.qty == 0) {
838
- inventory.lastSeq++
839
- inventory.status = INVENTORY_STATUS.DELETED
840
- inventory = await this.transactionInventory(
841
- inventory,
842
- Boolean(orderType === ORDER_TYPES.ARRIVAL_NOTICE) ? arrivalNotice : returnOrder,
843
- -inventory.qty,
844
- -inventory.uomValue,
845
- INVENTORY_TRANSACTION_TYPE.UNDO_UNLOADING
846
- )
847
- inventory.qty = 0
848
- inventory.uomValue = 0
849
- inventory.updater = this.user
850
- targetProduct.actualPalletQty--
851
-
852
- await this.updateOrderTargets([targetProduct])
853
-
854
- await this.trxMgr.getRepository(InventoryHistory).update({ inventory }, { inventory: null })
855
-
856
- await this.trxMgr.getRepository(Inventory).delete({ id: inventory.id })
857
- }
858
- } else {
859
- inventory.lastSeq++
860
- inventory.status = INVENTORY_STATUS.DELETED
861
- inventory = await this.transactionInventory(
862
- inventory,
863
- Boolean(orderType === ORDER_TYPES.ARRIVAL_NOTICE) ? arrivalNotice : returnOrder,
864
- -inventory.qty,
865
- -inventory.uomValue,
866
- INVENTORY_TRANSACTION_TYPE.UNDO_UNLOADING
867
- )
868
- inventory.qty = 0
869
- inventory.uomValue = 0
870
- inventory.updater = this.user
871
-
872
- await this.trxMgr.getRepository(InventoryHistory).update({ inventory }, { inventory: null })
873
-
874
- await this.trxMgr.getRepository(Inventory).delete({ id: inventory.id })
875
- }
876
-
877
- worksheetDetail.issue = inventory.qty == 0 && worksheetDetail?.issue ? null : worksheetDetail.issue
878
- worksheetDetail.status = WORKSHEET_STATUS.EXECUTING
879
- worksheetDetail.updater = this.user
880
- await this.trxMgr.getRepository(WorksheetDetail).save(worksheetDetail)
881
- }
882
- }
883
-
884
- async undoSerialNumberUnload(worksheetDetailName: string, inventoryItemId: string): Promise<void> {
885
- const worksheetDetail: WorksheetDetail = await this.trxMgr.getRepository(WorksheetDetail).findOne({
886
- where: {
887
- name: worksheetDetailName,
888
- domain: { id: this.domain.id },
889
- status: Not(Equal(WORKSHEET_STATUS.DEACTIVATED))
890
- },
891
- relations: [
892
- 'worksheet',
893
- 'worksheet.arrivalNotice',
894
- 'worksheet.returnOrder',
895
- 'targetProduct',
896
- 'targetProduct.product'
897
- ]
898
- })
899
-
900
- let worksheet: Worksheet = worksheetDetail.worksheet
901
- let arrivalNotice: ArrivalNotice = worksheet.arrivalNotice
902
- let returnOrder: ReturnOrder = worksheet.returnOrder
903
- let targetInventory: OrderInventory = worksheetDetail.targetInventory
904
- let targetProduct: OrderProduct = worksheetDetail.targetProduct
905
- let inventoryItem: InventoryItem = await this.trxMgr.getRepository(InventoryItem).findOne({
906
- where: { domain: { id: this.domain.id }, id: inventoryItemId },
907
- relations: ['inventory', 'product']
908
- })
909
- let inventory: Inventory = inventoryItem.inventory
910
-
911
- await this.trxMgr.getRepository(InventoryItem).delete(inventoryItem.id)
912
-
913
- inventory.qty--
914
- inventory.uomValue =
915
- Math.round(
916
- inventory.qty *
917
- (Boolean(arrivalNotice)
918
- ? targetProduct.uomValue
919
- : targetInventory.returnUomValue / targetInventory.returnQty) *
920
- 100
921
- ) / 100
922
- await this.trxMgr
923
- .getRepository(Inventory)
924
- .update({ id: inventory.id }, { qty: inventory.qty, uomValue: inventory.uomValue })
925
-
926
- targetProduct.actualPackQty--
927
-
928
- const inventoryItems: InventoryItem[] = await this.trxMgr.getRepository(InventoryItem).find({
929
- where: { domain: { id: this.domain.id }, inboundOrderId: arrivalNotice.id, inventory: { id: inventory.id } }
930
- })
931
-
932
- if (inventoryItems?.length == 0) {
933
- await this.trxMgr.getRepository(Inventory).delete(inventory.id)
934
-
935
- targetProduct.actualPalletQty--
936
- }
937
-
938
- targetProduct.updater = this.user
939
- await this.updateOrderTargets([targetProduct])
940
- }
941
-
942
- async activateUnloading(
943
- worksheetNo: string,
944
- unloadingWorksheetDetails: UnloadingWorksheetDetail[]
945
- ): Promise<Worksheet> {
946
- let worksheet: Worksheet = await this.findActivatableWorksheet(worksheetNo, WORKSHEET_TYPE.UNLOADING, [
947
- 'bizplace',
948
- 'arrivalNotice',
949
- 'worksheetDetails',
950
- 'worksheetDetails.targetProduct',
951
- 'worksheetDetails.targetProduct.product',
952
- 'worksheetDetails.targetVas'
953
- ])
954
-
955
- let arrivalNotice: ArrivalNotice = worksheet.arrivalNotice
956
- let vasWorksheet: Worksheet = new Worksheet()
957
-
958
- try {
959
- vasWorksheet = await this.findWorksheetByRefOrder(arrivalNotice, WORKSHEET_TYPE.VAS)
960
- } catch (e) {
961
- // do nothing
962
- }
963
-
964
- if (!Object.keys(vasWorksheet).length || vasWorksheet?.status == WORKSHEET_STATUS.DONE) {
965
- const bizplace: Bizplace = worksheet.bizplace
966
- let worksheetDetails: WorksheetDetail[] = worksheet.worksheetDetails
967
-
968
- const targetProducts: OrderProduct[] = worksheetDetails.map((wsd: WorksheetDetail) => {
969
- let targetProduct: OrderProduct = wsd.targetProduct
970
-
971
- if (!targetProduct.palletQty) {
972
- const { palletQty }: { palletQty: number } = this.findMatchedWSD(wsd.name, unloadingWorksheetDetails)
973
- targetProduct.palletQty = palletQty
974
- }
975
- targetProduct.status = ORDER_PRODUCT_STATUS.UNLOADING
976
- targetProduct.updater = this.user
977
-
978
- return targetProduct
979
- })
980
- await this.updateOrderTargets(targetProducts)
981
-
982
- arrivalNotice.status = ORDER_STATUS.PROCESSING
983
- arrivalNotice.updater = this.user
984
- this.updateRefOrder(arrivalNotice)
985
-
986
- const palletizingWSDs: UnloadingWorksheetDetail[] = this.filterPalletizingWSDs(unloadingWorksheetDetails)
987
- if (palletizingWSDs?.length) {
988
- this.createPalletizingWSDs(bizplace, arrivalNotice, worksheetDetails, unloadingWorksheetDetails)
989
- }
990
-
991
- worksheet = await this.activateWorksheet(worksheet, worksheetDetails, unloadingWorksheetDetails)
992
- } else if (vasWorksheet && vasWorksheet.status == WORKSHEET_STATUS.DEACTIVATED) {
993
- await this.activateVAS(vasWorksheet.name, vasWorksheet.worksheetDetails)
994
- } else if (vasWorksheet && vasWorksheet.status == WORKSHEET_STATUS.EXECUTING) {
995
- throw new Error(`There is pending VAS execution`)
996
- }
997
-
998
- return worksheet
999
- }
1000
-
1001
- async getProductScanningVal(arrivalNotice: ArrivalNotice) {
1002
- let productScanning: string = 'false'
1003
- const enableProductScanning: Setting = await this.trxMgr.getRepository(Setting).findOne({
1004
- where: { domain: { id: this.domain.id }, category: 'id-rule', name: 'enable-product-scanning' }
1005
- })
1006
-
1007
- if (enableProductScanning) {
1008
- productScanning = enableProductScanning.value
1009
-
1010
- const partnerEnableProductScanning: PartnerSetting = await this.trxMgr.getRepository(PartnerSetting).findOne({
1011
- where: {
1012
- setting: { id: enableProductScanning.id },
1013
- domain: { id: this.domain.id },
1014
- partnerDomain: { id: arrivalNotice.bizplace?.domain.id }
1015
- }
1016
- })
1017
-
1018
- if (partnerEnableProductScanning) productScanning = partnerEnableProductScanning.value
1019
- }
1020
-
1021
- return productScanning
1022
- }
1023
-
1024
- async getInputQtyVal(arrivalNotice: ArrivalNotice) {
1025
- let inputQty: string = 'false'
1026
- const enableInputQty: Setting = await this.trxMgr.getRepository(Setting).findOne({
1027
- where: { domain: { id: this.domain.id }, category: 'id-rule', name: 'enable-input-qty' }
1028
- })
1029
-
1030
- if (enableInputQty) {
1031
- inputQty = enableInputQty.value
1032
-
1033
- const partnerEnableInputQty: PartnerSetting = await this.trxMgr.getRepository(PartnerSetting).findOne({
1034
- where: {
1035
- setting: { id: enableInputQty.id },
1036
- domain: { id: this.domain.id },
1037
- partnerDomain: { id: arrivalNotice.bizplace?.domain.id }
1038
- }
1039
- })
1040
-
1041
- if (partnerEnableInputQty) inputQty = partnerEnableInputQty.value
1042
- }
1043
-
1044
- return inputQty
1045
- }
1046
-
1047
- // only creates inventory history upon partial or full unload when
1048
- // productScanning is true
1049
- // inputQty is false
1050
- async createInventoryHistory(arrivalNotice: ArrivalNotice, inventories?: Inventory[]) {
1051
- try {
1052
- if (inventories === undefined) {
1053
- const inventoryList = await this.trxMgr.getRepository(Inventory).findAndCount({
1054
- where: {
1055
- //@ts-ignore
1056
- domain: { id: this.domain },
1057
- refOrderId: arrivalNotice.id
1058
- }
1059
- })
1060
-
1061
- inventories = inventoryList[0]
1062
- }
1063
-
1064
- for (const inventory of inventories) {
1065
- await this.transactionInventory(
1066
- inventory,
1067
- arrivalNotice,
1068
- inventory.qty,
1069
- inventory.uomValue,
1070
- INVENTORY_TRANSACTION_TYPE.UNLOADING
1071
- )
1072
- }
1073
- } catch (e) {
1074
- throw e
1075
- }
1076
- }
1077
-
1078
- async completeUnloading(
1079
- arrivalNoticeNo: string,
1080
- unloadingWorksheetDetails: Partial<WorksheetDetail>[]
1081
- ): Promise<void> {
1082
- //@ts-ignore
1083
- let arrivalNotice: ArrivalNotice = await this.findRefOrder(
1084
- //@ts-ignore
1085
- ArrivalNotice,
1086
- {
1087
- domain: { id: this.domain.id },
1088
- name: arrivalNoticeNo,
1089
- status: In([ORDER_STATUS.PROCESSING, ORDER_STATUS.PUTTING_AWAY])
1090
- },
1091
- ['orderProducts', 'releaseGood', 'bizplace', 'bizplace.domain']
1092
- )
1093
-
1094
- if (arrivalNotice.crossDocking) {
1095
- // Picking worksheet for cross docking should be completed before complete it
1096
- // Find picking worksheet
1097
- const releaseGood: ReleaseGood = arrivalNotice.releaseGood
1098
- const executingPickingWS: Worksheet = await this.trxMgr.getRepository(Worksheet).findOne({
1099
- where: {
1100
- domain: { id: this.domain.id },
1101
- releaseGood: { id: releaseGood.id },
1102
- type: WORKSHEET_TYPE.PICKING,
1103
- status: Not(Equal(WORKSHEET_STATUS.DONE))
1104
- }
1105
- })
1106
-
1107
- if (executingPickingWS)
1108
- throw new Error(`Picking should be completed before complete unloading for cross docking.`)
1109
- }
1110
-
1111
- if (arrivalNotice.orderProducts.some((op: OrderProduct) => op.status === ORDER_PRODUCT_STATUS.READY_TO_APPROVED)) {
1112
- throw new Error(`There's non-approved order products`)
1113
- }
1114
-
1115
- let worksheet: Worksheet = await this.findWorksheetByRefOrder(arrivalNotice, WORKSHEET_TYPE.UNLOADING, [
1116
- 'worksheetDetails',
1117
- 'worksheetDetails.targetProduct'
1118
- ])
1119
- this.checkRecordValidity(worksheet, { status: WORKSHEET_STATUS.EXECUTING })
1120
-
1121
- const partiallyUnloadedCnt: number = await this.trxMgr.getRepository(Inventory).count({
1122
- where: {
1123
- domain: { id: this.domain.id },
1124
- refOrderId: arrivalNotice.id,
1125
- status: INVENTORY_STATUS.PARTIALLY_UNLOADED
1126
- }
1127
- })
1128
- if (partiallyUnloadedCnt) {
1129
- throw new Error('There is partially unloaded pallet, generate putaway worksheet before complete unloading.')
1130
- }
1131
-
1132
- if (unloadingWorksheetDetails.some((wsd: Partial<WorksheetDetail>) => wsd.issue)) {
1133
- const worksheetDetails: WorksheetDetail[] = worksheet.worksheetDetails
1134
- unloadingWorksheetDetails = this.renewWorksheetDetails(worksheetDetails, unloadingWorksheetDetails, 'name', {
1135
- updater: this.user
1136
- })
1137
- const worksheetDetailsWithIssue: WorksheetDetail[] = unloadingWorksheetDetails.filter(
1138
- (wsd: WorksheetDetail) => wsd.issue
1139
- ) as WorksheetDetail[]
1140
- if (worksheetDetailsWithIssue.length) {
1141
- await this.trxMgr.getRepository(WorksheetDetail).save(worksheetDetailsWithIssue)
1142
- }
1143
-
1144
- const targetProductsWithIssue: OrderProduct[] = worksheetDetailsWithIssue.map((wsd: WorksheetDetail) => {
1145
- let targetProduct: OrderProduct = wsd.targetProduct
1146
- targetProduct.issue = wsd.issue
1147
- return targetProduct
1148
- })
1149
- await this.updateOrderTargets(targetProductsWithIssue)
1150
- }
1151
-
1152
- if (arrivalNotice.status !== ORDER_STATUS.PUTTING_AWAY) {
1153
- await this.completeWorksheet(worksheet, ORDER_STATUS.READY_TO_PUTAWAY)
1154
- } else {
1155
- await this.completeWorksheet(worksheet)
1156
- }
1157
-
1158
- const productScanning = await this.getProductScanningVal(arrivalNotice)
1159
- const inputQty = await this.getInputQtyVal(arrivalNotice)
1160
- if (productScanning === 'true' && inputQty === 'false') await this.createInventoryHistory(arrivalNotice)
1161
-
1162
- const inventories: Inventory[] = await this.trxMgr.getRepository(Inventory).find({
1163
- where: {
1164
- domain: { id: this.domain.id },
1165
- refOrderId: arrivalNotice.id,
1166
- status: In([INVENTORY_STATUS.UNLOADED, INVENTORY_STATUS.CHECKED])
1167
- },
1168
- relations: ['domain', 'bizplace', 'product', 'warehouse', 'location']
1169
- })
1170
-
1171
- for (let inventory of inventories) {
1172
- let inventoryItems: InventoryItem[] = await this.trxMgr.getRepository(InventoryItem).find({
1173
- where: { domain: { id: this.domain.id }, inventory: { id: inventory.id } }
1174
- })
1175
-
1176
- if (inventoryItems?.length) {
1177
- inventory.status = INVENTORY_STATUS.STORED
1178
-
1179
- await Promise.all(
1180
- inventoryItems.map(async inventoryItem => {
1181
- await this.trxMgr
1182
- .getRepository(InventoryItem)
1183
- .update({ id: inventoryItem.id }, { status: INVENTORY_STATUS.STORED })
1184
- })
1185
- )
1186
-
1187
- await generateInventoryHistory(
1188
- inventory,
1189
- arrivalNotice,
1190
- INVENTORY_TRANSACTION_TYPE.UNLOADING,
1191
- inventory.qty,
1192
- inventory.uomValue,
1193
- this.user,
1194
- this.trxMgr
1195
- )
1196
- }
1197
- }
1198
-
1199
- let vasWorksheet: Worksheet = await this.trxMgr.getRepository(Worksheet).findOne({
1200
- where: {
1201
- arrivalNotice: { id: arrivalNotice.id },
1202
- type: WORKSHEET_TYPE.VAS
1203
- },
1204
- relations: ['worksheetDetails', 'worksheetDetails.targetVas', 'worksheetDetails.targetVas.vas']
1205
- })
1206
-
1207
- if (vasWorksheet) {
1208
- let serviceVasWorksheetDetails: WorksheetDetail[] = vasWorksheet.worksheetDetails.filter(
1209
- x => x.targetVas.vas.type == VAS_TYPES.SERVICE && x.status != WORKSHEET_STATUS.DONE
1210
- )
1211
- let materialsVasWorksheetDetails: WorksheetDetail[] = vasWorksheet.worksheetDetails.filter(
1212
- x => x.targetVas.vas.type == VAS_TYPES.MATERIALS
1213
- )
1214
- materialsVasWorksheetDetails.forEach((wsd: WorksheetDetail) => {
1215
- wsd.status = WORKSHEET_STATUS.DONE
1216
- wsd.updater = this.user
1217
- })
1218
- await this.trxMgr.getRepository(WorksheetDetail).save(materialsVasWorksheetDetails)
1219
-
1220
- let targetVASs: OrderVas[] = materialsVasWorksheetDetails.map((wsd: WorksheetDetail) => {
1221
- let targetVas: OrderVas = wsd.targetVas
1222
- targetVas.status = ORDER_VAS_STATUS.TERMINATED
1223
- targetVas.updater = this.user
1224
- return targetVas
1225
- })
1226
-
1227
- if (targetVASs.length) await this.updateOrderTargets(targetVASs)
1228
-
1229
- if (serviceVasWorksheetDetails.length <= 0) {
1230
- vasWorksheet.status = WORKSHEET_STATUS.DONE
1231
- vasWorksheet.updater = this.user
1232
-
1233
- await this.trxMgr.getRepository(Worksheet).save(vasWorksheet)
1234
- }
1235
- }
1236
- }
1237
-
1238
- async completeUnloadingPartially(
1239
- arrivalNoticeNo: string,
1240
- unloadingWorksheetDetail: Partial<WorksheetDetail>[]
1241
- ): Promise<Worksheet> {
1242
- //@ts-ignore
1243
- const arrivalNotice: ArrivalNotice = await this.findRefOrder(
1244
- //@ts-ignore
1245
- ArrivalNotice,
1246
- {
1247
- domain: { id: this.domain.id },
1248
- name: arrivalNoticeNo,
1249
- status: In([ORDER_STATUS.PROCESSING, ORDER_STATUS.PUTTING_AWAY])
1250
- },
1251
- ['bizplace', 'bizplace.domain']
1252
- )
1253
-
1254
- const worksheet: Worksheet = await this.findWorksheetByRefOrder(arrivalNotice, WORKSHEET_TYPE.UNLOADING, [
1255
- 'worksheetDetails',
1256
- 'worksheetDetails.targetProduct'
1257
- ])
1258
- this.checkRecordValidity(worksheet, { status: WORKSHEET_STATUS.EXECUTING })
1259
-
1260
- let worksheetDetails = worksheet.worksheetDetails.filter(({ name: itm1 }) =>
1261
- unloadingWorksheetDetail.some(({ name: itm2 }) => itm2 === itm1)
1262
- )
1263
-
1264
- worksheetDetails.forEach((wsds: WorksheetDetail) => {
1265
- wsds.status = WORKSHEET_STATUS.PARTIALLY_UNLOADED
1266
- wsds.updater = this.user
1267
- })
1268
-
1269
- worksheetDetails = await this.trxMgr.getRepository(WorksheetDetail).save(worksheetDetails)
1270
-
1271
- for (let i = 0; i < worksheetDetails.length; i++) {
1272
- worksheetDetails[i].targetProduct.status = ORDER_PRODUCT_STATUS.PARTIALLY_UNLOADED
1273
- worksheetDetails[i].targetProduct.remark = worksheetDetails[i].issue || worksheetDetails[i].targetProduct.remark
1274
- await this.updateOrderTargets([worksheetDetails[i].targetProduct])
1275
- }
1276
-
1277
- let inventories: Inventory[] = await this.trxMgr.getRepository(Inventory).find({
1278
- where: {
1279
- domain: { id: this.domain.id },
1280
- refOrderId: arrivalNotice.id,
1281
- status: In([INVENTORY_STATUS.UNLOADED, INVENTORY_STATUS.CHECKED])
1282
- }
1283
- })
1284
-
1285
- inventories.forEach((inventory: Inventory) => {
1286
- inventory.status = INVENTORY_STATUS.PARTIALLY_UNLOADED
1287
- inventory.updater = this.user
1288
- })
1289
- await this.trxMgr.getRepository(Inventory).save(inventories)
1290
-
1291
- const productScanning = await this.getProductScanningVal(arrivalNotice)
1292
- const inputQty = await this.getInputQtyVal(arrivalNotice)
1293
- if (productScanning === 'true' && inputQty === 'false')
1294
- await this.createInventoryHistory(arrivalNotice, inventories)
1295
-
1296
- let vasWorksheet: Worksheet = await this.trxMgr.getRepository(Worksheet).findOne({
1297
- where: {
1298
- arrivalNotice: { id: arrivalNotice.id },
1299
- type: WORKSHEET_TYPE.VAS
1300
- },
1301
- relations: ['worksheetDetails', 'worksheetDetails.targetVas', 'worksheetDetails.targetVas.vas']
1302
- })
1303
-
1304
- if (vasWorksheet) {
1305
- let serviceVasWorksheetDetails: WorksheetDetail[] = vasWorksheet.worksheetDetails.filter(
1306
- x => x.targetVas.vas.type == VAS_TYPES.SERVICE && x.status != WORKSHEET_STATUS.DONE
1307
- )
1308
- let materialsVasWorksheetDetails: WorksheetDetail[] = vasWorksheet.worksheetDetails.filter(
1309
- x => x.targetVas.vas.type == VAS_TYPES.MATERIALS
1310
- )
1311
- materialsVasWorksheetDetails.forEach((wsd: WorksheetDetail) => {
1312
- wsd.status = WORKSHEET_STATUS.DONE
1313
- wsd.updater = this.user
1314
- })
1315
- await this.trxMgr.getRepository(WorksheetDetail).save(materialsVasWorksheetDetails)
1316
-
1317
- let targetVASs: OrderVas[] = materialsVasWorksheetDetails.map((wsd: WorksheetDetail) => {
1318
- let targetVas: OrderVas = wsd.targetVas
1319
- targetVas.status = ORDER_VAS_STATUS.TERMINATED
1320
- targetVas.updater = this.user
1321
- return targetVas
1322
- })
1323
-
1324
- await this.updateOrderTargets(targetVASs)
1325
-
1326
- if (serviceVasWorksheetDetails.length <= 0) {
1327
- vasWorksheet.status = WORKSHEET_STATUS.DONE
1328
- vasWorksheet.updater = this.user
1329
-
1330
- await this.trxMgr.getRepository(Worksheet).save(vasWorksheet)
1331
- }
1332
- }
1333
-
1334
- return worksheet
1335
- }
1336
-
1337
- async createPalletizingWSDs(
1338
- bizplace: Bizplace,
1339
- arrivalNotice: ArrivalNotice,
1340
- worksheetDetails: WorksheetDetail[],
1341
- palletizingWSDs: UnloadingWorksheetDetail[]
1342
- ): Promise<void> {
1343
- let palletizingOrderVASs: OrderVas[] = []
1344
- let currentSetNo: number = 1
1345
-
1346
- if (worksheetDetails.some((wd: WorksheetDetail) => wd.targetVas)) {
1347
- const getSetNo: number[] = worksheetDetails.map((wd: WorksheetDetail) => wd.targetVas.set)
1348
-
1349
- if (getSetNo.length > 0) {
1350
- currentSetNo = Math.max(...getSetNo) + 1
1351
- }
1352
- }
1353
-
1354
- for (let palletizingWSD of palletizingWSDs) {
1355
- const palletizingVAS: Vas = await this.trxMgr.getRepository(Vas).findOne({
1356
- where: { domain: { id: this.domain.id }, id: palletizingWSD.palletizingVasId }
1357
- })
1358
-
1359
- const targetProduct: OrderProduct = worksheetDetails.find(
1360
- (wsd: WorksheetDetail) => wsd.name === palletizingWSD.name
1361
- ).targetProduct
1362
-
1363
- let palletizingOrderVas: OrderVas = new OrderVas()
1364
- palletizingOrderVas.domain = this.domain
1365
- palletizingOrderVas.bizplace = bizplace
1366
- palletizingOrderVas.name = OrderNoGenerator.orderVas()
1367
- palletizingOrderVas.arrivalNotice = arrivalNotice
1368
- palletizingOrderVas.vas = palletizingVAS
1369
- palletizingOrderVas.set = currentSetNo
1370
- palletizingOrderVas.targetType = VAS_TARGET_TYPES.BATCH_AND_PRODUCT_TYPE
1371
- palletizingOrderVas.targetBatchId = targetProduct.batchId
1372
- palletizingOrderVas.qty = targetProduct.packQty
1373
- palletizingOrderVas.targetProduct = targetProduct.product
1374
- palletizingOrderVas.packingType = targetProduct.packingType
1375
- palletizingOrderVas.description = palletizingWSD.palletizingDescription
1376
- palletizingOrderVas.type = ORDER_TYPES.ARRIVAL_NOTICE
1377
- palletizingOrderVas.status = ORDER_VAS_STATUS.COMPLETED
1378
- palletizingOrderVas.creator = this.user
1379
- palletizingOrderVas.updater = this.user
1380
-
1381
- palletizingOrderVas = await this.trxMgr.getRepository(OrderVas).save(palletizingOrderVas)
1382
- palletizingOrderVASs.push(palletizingOrderVas)
1383
-
1384
- currentSetNo++
1385
- }
1386
-
1387
- let vasWorksheet: Worksheet = await this.findWorksheetByRefOrder(arrivalNotice, WORKSHEET_TYPE.VAS)
1388
- if (!vasWorksheet) {
1389
- await this.generateVasWorksheet(arrivalNotice)
1390
- } else {
1391
- await this.createWorksheetDetails(vasWorksheet, WORKSHEET_TYPE.VAS, palletizingOrderVASs)
1392
- }
1393
- }
1394
-
1395
- filterPalletizingWSDs(unloadingWSDs: UnloadingWorksheetDetail[]): UnloadingWorksheetDetail[] {
1396
- return unloadingWSDs.filter((wsd: UnloadingWorksheetDetail) => wsd.palletQty && wsd.palletizingDescription)
1397
- }
1398
- }