@things-factory/warehouse-base 4.0.0-y.0 → 4.0.4

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 (358) hide show
  1. package/dist-server/constants/inventory.js +4 -1
  2. package/dist-server/constants/inventory.js.map +1 -1
  3. package/dist-server/controllers/ecommerce/ecommerce-controller.js +3 -3
  4. package/dist-server/controllers/ecommerce/ecommerce-controller.js.map +1 -1
  5. package/dist-server/controllers/ecommerce/index.js +1 -0
  6. package/dist-server/controllers/ecommerce/index.js.map +1 -1
  7. package/dist-server/controllers/ecommerce/sellercraft-controller.js +48 -0
  8. package/dist-server/controllers/ecommerce/sellercraft-controller.js.map +1 -0
  9. package/dist-server/controllers/warehouse-controller.js +40 -1
  10. package/dist-server/controllers/warehouse-controller.js.map +1 -1
  11. package/dist-server/entities/reduced-inventory-history.js +8 -7
  12. package/dist-server/entities/reduced-inventory-history.js.map +1 -1
  13. package/dist-server/graphql/resolvers/inventory/check-product-identicality.js +2 -2
  14. package/dist-server/graphql/resolvers/inventory/check-product-identicality.js.map +1 -1
  15. package/dist-server/graphql/resolvers/inventory/inventories-by-strategy.js +4 -2
  16. package/dist-server/graphql/resolvers/inventory/inventories-by-strategy.js.map +1 -1
  17. package/dist-server/graphql/resolvers/inventory-change/approve-inventory-changes.js +25 -5
  18. package/dist-server/graphql/resolvers/inventory-change/approve-inventory-changes.js.map +1 -1
  19. package/dist-server/graphql/resolvers/inventory-history/inventory-history-summary-report.js +12 -11
  20. package/dist-server/graphql/resolvers/inventory-history/inventory-history-summary-report.js.map +1 -1
  21. package/dist-server/graphql/resolvers/inventory-history/onhand-inventories.js +6 -3
  22. package/dist-server/graphql/resolvers/inventory-history/onhand-inventories.js.map +1 -1
  23. package/dist-server/graphql/resolvers/location/location-occupancies.js +15 -28
  24. package/dist-server/graphql/resolvers/location/location-occupancies.js.map +1 -1
  25. package/dist-server/graphql/resolvers/location/location.js +3 -2
  26. package/dist-server/graphql/resolvers/location/location.js.map +1 -1
  27. package/dist-server/graphql/resolvers/movement/inbound-movements-counter.js +5 -7
  28. package/dist-server/graphql/resolvers/movement/inbound-movements-counter.js.map +1 -1
  29. package/dist-server/graphql/resolvers/movement/outbound-movements-counter.js +5 -7
  30. package/dist-server/graphql/resolvers/movement/outbound-movements-counter.js.map +1 -1
  31. package/dist-server/graphql/resolvers/movement/weekly-movements-counter.js +14 -32
  32. package/dist-server/graphql/resolvers/movement/weekly-movements-counter.js.map +1 -1
  33. package/dist-server/graphql/types/inventory/index.js +1 -1
  34. package/dist-server/graphql/types/inventory/inventory-patch.js +1 -0
  35. package/dist-server/graphql/types/inventory/inventory-patch.js.map +1 -1
  36. package/dist-server/graphql/types/location/index.js +4 -4
  37. package/dist-server/graphql/types/location/index.js.map +1 -1
  38. package/dist-server/graphql/types/warehouse/index.js.map +1 -1
  39. package/dist-server/index.js +11 -12
  40. package/dist-server/index.js.map +1 -1
  41. package/dist-server/service/index.js +71 -0
  42. package/dist-server/service/index.js.map +1 -0
  43. package/dist-server/service/inventory/index.js +9 -0
  44. package/dist-server/service/inventory/index.js.map +1 -0
  45. package/dist-server/service/inventory/inventory-mutation.js +324 -0
  46. package/dist-server/service/inventory/inventory-mutation.js.map +1 -0
  47. package/dist-server/service/inventory/inventory-query.js +678 -0
  48. package/dist-server/service/inventory/inventory-query.js.map +1 -0
  49. package/dist-server/service/inventory/inventory-types.js +405 -0
  50. package/dist-server/service/inventory/inventory-types.js.map +1 -0
  51. package/dist-server/service/inventory/inventory.js +292 -0
  52. package/dist-server/service/inventory/inventory.js.map +1 -0
  53. package/dist-server/service/inventory-change/index.js +9 -0
  54. package/dist-server/service/inventory-change/index.js.map +1 -0
  55. package/dist-server/service/inventory-change/inventory-change-mutation.js +530 -0
  56. package/dist-server/service/inventory-change/inventory-change-mutation.js.map +1 -0
  57. package/dist-server/service/inventory-change/inventory-change-query.js +121 -0
  58. package/dist-server/service/inventory-change/inventory-change-query.js.map +1 -0
  59. package/dist-server/service/inventory-change/inventory-change-types.js +65 -0
  60. package/dist-server/service/inventory-change/inventory-change-types.js.map +1 -0
  61. package/dist-server/service/inventory-change/inventory-change.js +185 -0
  62. package/dist-server/service/inventory-change/inventory-change.js.map +1 -0
  63. package/dist-server/service/inventory-history/index.js +9 -0
  64. package/dist-server/service/inventory-history/index.js.map +1 -0
  65. package/dist-server/service/inventory-history/inventory-history-mutation.js +121 -0
  66. package/dist-server/service/inventory-history/inventory-history-mutation.js.map +1 -0
  67. package/dist-server/service/inventory-history/inventory-history-query.js +1283 -0
  68. package/dist-server/service/inventory-history/inventory-history-query.js.map +1 -0
  69. package/dist-server/service/inventory-history/inventory-history-types.js +382 -0
  70. package/dist-server/service/inventory-history/inventory-history-types.js.map +1 -0
  71. package/dist-server/service/inventory-history/inventory-history.js +233 -0
  72. package/dist-server/service/inventory-history/inventory-history.js.map +1 -0
  73. package/dist-server/service/location/index.js +9 -0
  74. package/dist-server/service/location/index.js.map +1 -0
  75. package/dist-server/service/location/location-mutation.js +157 -0
  76. package/dist-server/service/location/location-mutation.js.map +1 -0
  77. package/dist-server/service/location/location-query.js +251 -0
  78. package/dist-server/service/location/location-query.js.map +1 -0
  79. package/dist-server/service/location/location-types.js +223 -0
  80. package/dist-server/service/location/location-types.js.map +1 -0
  81. package/dist-server/service/location/location.js +125 -0
  82. package/dist-server/service/location/location.js.map +1 -0
  83. package/dist-server/service/movement/index.js +9 -0
  84. package/dist-server/service/movement/index.js.map +1 -0
  85. package/dist-server/service/movement/movement-mutation.js +80 -0
  86. package/dist-server/service/movement/movement-mutation.js.map +1 -0
  87. package/dist-server/service/movement/movement-query.js +286 -0
  88. package/dist-server/service/movement/movement-query.js.map +1 -0
  89. package/dist-server/service/movement/movement-types.js +117 -0
  90. package/dist-server/service/movement/movement-types.js.map +1 -0
  91. package/dist-server/service/movement/movement.js +101 -0
  92. package/dist-server/service/movement/movement.js.map +1 -0
  93. package/dist-server/service/pallet/index.js +9 -0
  94. package/dist-server/service/pallet/index.js.map +1 -0
  95. package/dist-server/service/pallet/pallet-mutation.js +192 -0
  96. package/dist-server/service/pallet/pallet-mutation.js.map +1 -0
  97. package/dist-server/service/pallet/pallet-query.js +164 -0
  98. package/dist-server/service/pallet/pallet-query.js.map +1 -0
  99. package/dist-server/service/pallet/pallet-types.js +109 -0
  100. package/dist-server/service/pallet/pallet-types.js.map +1 -0
  101. package/dist-server/service/pallet/pallet.js +112 -0
  102. package/dist-server/service/pallet/pallet.js.map +1 -0
  103. package/dist-server/service/pallet-count/index.js +9 -0
  104. package/dist-server/service/pallet-count/index.js.map +1 -0
  105. package/dist-server/service/pallet-count/pallet-count-mutation.js +156 -0
  106. package/dist-server/service/pallet-count/pallet-count-mutation.js.map +1 -0
  107. package/dist-server/service/pallet-count/pallet-count-query.js +86 -0
  108. package/dist-server/service/pallet-count/pallet-count-query.js.map +1 -0
  109. package/dist-server/service/pallet-count/pallet-count-types.js +65 -0
  110. package/dist-server/service/pallet-count/pallet-count-types.js.map +1 -0
  111. package/dist-server/service/pallet-count/pallet-count.js +89 -0
  112. package/dist-server/service/pallet-count/pallet-count.js.map +1 -0
  113. package/dist-server/service/pallet-history/index.js +9 -0
  114. package/dist-server/service/pallet-history/index.js.map +1 -0
  115. package/dist-server/service/pallet-history/pallet-history-mutation.js +120 -0
  116. package/dist-server/service/pallet-history/pallet-history-mutation.js.map +1 -0
  117. package/dist-server/service/pallet-history/pallet-history-query.js +87 -0
  118. package/dist-server/service/pallet-history/pallet-history-query.js.map +1 -0
  119. package/dist-server/service/pallet-history/pallet-history-types.js +65 -0
  120. package/dist-server/service/pallet-history/pallet-history-types.js.map +1 -0
  121. package/dist-server/service/pallet-history/pallet-history.js +107 -0
  122. package/dist-server/service/pallet-history/pallet-history.js.map +1 -0
  123. package/dist-server/service/reduced-inventory-history/index.js +6 -0
  124. package/dist-server/service/reduced-inventory-history/index.js.map +1 -0
  125. package/dist-server/service/reduced-inventory-history/reduced-inventory-history.js +133 -0
  126. package/dist-server/service/reduced-inventory-history/reduced-inventory-history.js.map +1 -0
  127. package/dist-server/service/warehouse/index.js +9 -0
  128. package/dist-server/service/warehouse/index.js.map +1 -0
  129. package/dist-server/service/warehouse/warehouse-mutation.js +135 -0
  130. package/dist-server/service/warehouse/warehouse-mutation.js.map +1 -0
  131. package/dist-server/service/warehouse/warehouse-query.js +91 -0
  132. package/dist-server/service/warehouse/warehouse-query.js.map +1 -0
  133. package/dist-server/service/warehouse/warehouse-types.js +82 -0
  134. package/dist-server/service/warehouse/warehouse-types.js.map +1 -0
  135. package/dist-server/service/warehouse/warehouse.js +102 -0
  136. package/dist-server/service/warehouse/warehouse.js.map +1 -0
  137. package/dist-server/utils/inventory-util.js +46 -12
  138. package/dist-server/utils/inventory-util.js.map +1 -1
  139. package/package.json +8 -7
  140. package/server/constants/inventory.ts +4 -1
  141. package/server/controllers/ecommerce/ecommerce-controller.ts +4 -3
  142. package/server/controllers/ecommerce/index.ts +1 -0
  143. package/server/controllers/ecommerce/sellercraft-controller.ts +58 -0
  144. package/server/controllers/warehouse-controller.ts +54 -2
  145. package/server/index.ts +8 -4
  146. package/server/service/index.ts +61 -0
  147. package/server/service/inventory/index.ts +6 -0
  148. package/server/{graphql/resolvers/inventory/update-multiple-inventory.ts → service/inventory/inventory-mutation.ts} +158 -7
  149. package/server/service/inventory/inventory-query.ts +745 -0
  150. package/server/service/inventory/inventory-types.ts +289 -0
  151. package/server/{entities → service/inventory}/inventory.ts +92 -8
  152. package/server/service/inventory-change/index.ts +6 -0
  153. package/server/{graphql/resolvers/inventory-change/approve-inventory-changes.ts → service/inventory-change/inventory-change-mutation.ts} +299 -11
  154. package/server/{graphql/resolvers/inventory-change/inventory-changes.ts → service/inventory-change/inventory-change-query.ts} +35 -4
  155. package/server/service/inventory-change/inventory-change-types.ts +36 -0
  156. package/server/{entities → service/inventory-change}/inventory-change.ts +55 -5
  157. package/server/service/inventory-history/index.ts +6 -0
  158. package/server/service/inventory-history/inventory-history-mutation.ts +119 -0
  159. package/server/service/inventory-history/inventory-history-query.ts +1435 -0
  160. package/server/service/inventory-history/inventory-history-types.ts +269 -0
  161. package/server/{entities → service/inventory-history}/inventory-history.ts +65 -10
  162. package/server/service/location/index.ts +6 -0
  163. package/server/service/location/location-mutation.ts +134 -0
  164. package/server/service/location/location-query.ts +209 -0
  165. package/server/service/location/location-types.ts +151 -0
  166. package/server/{entities → service/location}/location.ts +40 -3
  167. package/server/service/movement/index.ts +6 -0
  168. package/server/service/movement/movement-mutation.ts +61 -0
  169. package/server/service/movement/movement-query.ts +258 -0
  170. package/server/service/movement/movement-types.ts +74 -0
  171. package/server/{entities → service/movement}/movement.ts +35 -2
  172. package/server/service/pallet/index.ts +6 -0
  173. package/server/service/pallet/pallet-mutation.ts +244 -0
  174. package/server/service/pallet/pallet-query.ts +105 -0
  175. package/server/service/pallet/pallet-types.ts +68 -0
  176. package/server/{entities → service/pallet}/pallet.ts +31 -4
  177. package/server/service/pallet-count/index.ts +6 -0
  178. package/server/service/pallet-count/pallet-count-mutation.ts +148 -0
  179. package/server/service/pallet-count/pallet-count-query.ts +46 -0
  180. package/server/service/pallet-count/pallet-count-types.ts +36 -0
  181. package/server/service/pallet-count/pallet-count.ts +70 -0
  182. package/server/service/pallet-history/index.ts +6 -0
  183. package/server/service/pallet-history/pallet-history-mutation.ts +114 -0
  184. package/server/service/pallet-history/pallet-history-query.ts +46 -0
  185. package/server/service/pallet-history/pallet-history-types.ts +36 -0
  186. package/server/{entities → service/pallet-history}/pallet-history.ts +34 -12
  187. package/server/service/reduced-inventory-history/index.ts +3 -0
  188. package/server/{entities → service/reduced-inventory-history}/reduced-inventory-history.ts +7 -12
  189. package/server/service/warehouse/index.ts +6 -0
  190. package/server/service/warehouse/warehouse-mutation.ts +114 -0
  191. package/server/service/warehouse/warehouse-query.ts +51 -0
  192. package/server/service/warehouse/warehouse-types.ts +50 -0
  193. package/server/{entities → service/warehouse}/warehouse.ts +29 -4
  194. package/server/utils/inventory-util.ts +58 -4
  195. package/translations/en.json +2 -1
  196. package/translations/ko.json +2 -1
  197. package/translations/ms.json +2 -1
  198. package/translations/zh.json +2 -1
  199. package/server/entities/index.ts +0 -36
  200. package/server/entities/pallet-count.ts +0 -40
  201. package/server/graphql/index.ts +0 -7
  202. package/server/graphql/resolvers/index.ts +0 -33
  203. package/server/graphql/resolvers/inventory/check-carton-identicality.ts +0 -32
  204. package/server/graphql/resolvers/inventory/check-inventory-owner.ts +0 -26
  205. package/server/graphql/resolvers/inventory/check-product-identicality.ts +0 -24
  206. package/server/graphql/resolvers/inventory/create-inventory.ts +0 -15
  207. package/server/graphql/resolvers/inventory/delete-inventories.ts +0 -14
  208. package/server/graphql/resolvers/inventory/delete-inventory.ts +0 -10
  209. package/server/graphql/resolvers/inventory/index.ts +0 -38
  210. package/server/graphql/resolvers/inventory/inventories-by-bundle.ts +0 -168
  211. package/server/graphql/resolvers/inventory/inventories-by-product.ts +0 -164
  212. package/server/graphql/resolvers/inventory/inventories-by-strategy.ts +0 -143
  213. package/server/graphql/resolvers/inventory/inventories.ts +0 -129
  214. package/server/graphql/resolvers/inventory/inventory-by-pallet.ts +0 -15
  215. package/server/graphql/resolvers/inventory/inventory-transfer.ts +0 -50
  216. package/server/graphql/resolvers/inventory/inventory.ts +0 -14
  217. package/server/graphql/resolvers/inventory/update-inventory-remark.ts +0 -19
  218. package/server/graphql/resolvers/inventory/update-inventory.ts +0 -31
  219. package/server/graphql/resolvers/inventory-change/create-inventory-change.ts +0 -17
  220. package/server/graphql/resolvers/inventory-change/delete-inventory-change.ts +0 -12
  221. package/server/graphql/resolvers/inventory-change/delete-inventory-changes.ts +0 -15
  222. package/server/graphql/resolvers/inventory-change/index.ts +0 -27
  223. package/server/graphql/resolvers/inventory-change/inventory-change.ts +0 -14
  224. package/server/graphql/resolvers/inventory-change/reject-inventory-changes.ts +0 -42
  225. package/server/graphql/resolvers/inventory-change/submit-inventory-changes.ts +0 -101
  226. package/server/graphql/resolvers/inventory-change/update-inventory-change.ts +0 -21
  227. package/server/graphql/resolvers/inventory-change/update-multiple-inventory-change.ts +0 -47
  228. package/server/graphql/resolvers/inventory-history/bizplace-inventory-histories.ts +0 -81
  229. package/server/graphql/resolvers/inventory-history/create-inventory-history.ts +0 -17
  230. package/server/graphql/resolvers/inventory-history/delete-inventory-histories.ts +0 -15
  231. package/server/graphql/resolvers/inventory-history/delete-inventory-history.ts +0 -12
  232. package/server/graphql/resolvers/inventory-history/index.ts +0 -34
  233. package/server/graphql/resolvers/inventory-history/inventory-histories.ts +0 -62
  234. package/server/graphql/resolvers/inventory-history/inventory-history-pallet-detail-report.ts +0 -166
  235. package/server/graphql/resolvers/inventory-history/inventory-history-pallet-report.ts +0 -133
  236. package/server/graphql/resolvers/inventory-history/inventory-history-pallet-storage-report.ts +0 -146
  237. package/server/graphql/resolvers/inventory-history/inventory-history-report.ts +0 -233
  238. package/server/graphql/resolvers/inventory-history/inventory-history-summary-report.ts +0 -317
  239. package/server/graphql/resolvers/inventory-history/inventory-history.ts +0 -13
  240. package/server/graphql/resolvers/inventory-history/onhand-inventories.ts +0 -233
  241. package/server/graphql/resolvers/inventory-history/update-inventory-history.ts +0 -21
  242. package/server/graphql/resolvers/inventory-history/update-multiple-inventory-history.ts +0 -48
  243. package/server/graphql/resolvers/location/create-location.ts +0 -25
  244. package/server/graphql/resolvers/location/delete-all-locations.ts +0 -12
  245. package/server/graphql/resolvers/location/delete-location.ts +0 -16
  246. package/server/graphql/resolvers/location/delete-locations.ts +0 -16
  247. package/server/graphql/resolvers/location/index.ts +0 -32
  248. package/server/graphql/resolvers/location/location-by-name.ts +0 -17
  249. package/server/graphql/resolvers/location/location-occupancies.ts +0 -45
  250. package/server/graphql/resolvers/location/location-with-inventories.ts +0 -87
  251. package/server/graphql/resolvers/location/location.ts +0 -10
  252. package/server/graphql/resolvers/location/locations-by-group.ts +0 -29
  253. package/server/graphql/resolvers/location/locations.ts +0 -18
  254. package/server/graphql/resolvers/location/update-location.ts +0 -27
  255. package/server/graphql/resolvers/location/update-multiple-location.ts +0 -29
  256. package/server/graphql/resolvers/movement/create-movement.ts +0 -13
  257. package/server/graphql/resolvers/movement/delete-movement.ts +0 -9
  258. package/server/graphql/resolvers/movement/inbound-movements-counter.ts +0 -68
  259. package/server/graphql/resolvers/movement/index.ts +0 -23
  260. package/server/graphql/resolvers/movement/movement.ts +0 -16
  261. package/server/graphql/resolvers/movement/movements.ts +0 -17
  262. package/server/graphql/resolvers/movement/outbound-movements-counter.ts +0 -70
  263. package/server/graphql/resolvers/movement/update-movement.ts +0 -25
  264. package/server/graphql/resolvers/movement/weekly-movements-counter.ts +0 -94
  265. package/server/graphql/resolvers/pallet/create-pallet.ts +0 -18
  266. package/server/graphql/resolvers/pallet/delete-pallet.ts +0 -13
  267. package/server/graphql/resolvers/pallet/delete-pallets.ts +0 -44
  268. package/server/graphql/resolvers/pallet/index.ts +0 -29
  269. package/server/graphql/resolvers/pallet/pallet-by-status.ts +0 -16
  270. package/server/graphql/resolvers/pallet/pallet-inbound-validate.ts +0 -21
  271. package/server/graphql/resolvers/pallet/pallet-outbound-validate.ts +0 -21
  272. package/server/graphql/resolvers/pallet/pallet-return.ts +0 -57
  273. package/server/graphql/resolvers/pallet/pallet.ts +0 -15
  274. package/server/graphql/resolvers/pallet/pallets.ts +0 -22
  275. package/server/graphql/resolvers/pallet/update-multiple-pallet.ts +0 -95
  276. package/server/graphql/resolvers/pallet/update-pallet.ts +0 -21
  277. package/server/graphql/resolvers/pallet-count/create-pallet-count.ts +0 -17
  278. package/server/graphql/resolvers/pallet-count/delete-pallet-count.ts +0 -12
  279. package/server/graphql/resolvers/pallet-count/delete-pallet-counts.ts +0 -15
  280. package/server/graphql/resolvers/pallet-count/index.ts +0 -23
  281. package/server/graphql/resolvers/pallet-count/pallet-count.ts +0 -14
  282. package/server/graphql/resolvers/pallet-count/pallet-counts.ts +0 -14
  283. package/server/graphql/resolvers/pallet-count/update-multiple-pallet-count.ts +0 -47
  284. package/server/graphql/resolvers/pallet-count/update-pallet-count-seq.ts +0 -44
  285. package/server/graphql/resolvers/pallet-count/update-pallet-count.ts +0 -21
  286. package/server/graphql/resolvers/pallet-history/create-pallet-history.ts +0 -17
  287. package/server/graphql/resolvers/pallet-history/delete-pallet-histories.ts +0 -16
  288. package/server/graphql/resolvers/pallet-history/delete-pallet-history.ts +0 -13
  289. package/server/graphql/resolvers/pallet-history/index.ts +0 -21
  290. package/server/graphql/resolvers/pallet-history/pallet-histories.ts +0 -14
  291. package/server/graphql/resolvers/pallet-history/pallet-history.ts +0 -14
  292. package/server/graphql/resolvers/pallet-history/update-multiple-pallet-history.ts +0 -46
  293. package/server/graphql/resolvers/pallet-history/update-pallet-history.ts +0 -21
  294. package/server/graphql/resolvers/warehouse/create-warehouse.ts +0 -22
  295. package/server/graphql/resolvers/warehouse/delete-warehouse.ts +0 -16
  296. package/server/graphql/resolvers/warehouse/delete-warehouses.ts +0 -16
  297. package/server/graphql/resolvers/warehouse/index.ts +0 -22
  298. package/server/graphql/resolvers/warehouse/update-multiple-warehouse.ts +0 -29
  299. package/server/graphql/resolvers/warehouse/update-warehouse.ts +0 -23
  300. package/server/graphql/resolvers/warehouse/warehouse.ts +0 -17
  301. package/server/graphql/resolvers/warehouse/warehouses.ts +0 -16
  302. package/server/graphql/types/index.ts +0 -45
  303. package/server/graphql/types/inventory/index.ts +0 -61
  304. package/server/graphql/types/inventory/inventory-bundle-group-detail.ts +0 -8
  305. package/server/graphql/types/inventory/inventory-bundle-group.ts +0 -33
  306. package/server/graphql/types/inventory/inventory-list.ts +0 -8
  307. package/server/graphql/types/inventory/inventory-patch.ts +0 -41
  308. package/server/graphql/types/inventory/inventory.ts +0 -50
  309. package/server/graphql/types/inventory/new-inventory.ts +0 -29
  310. package/server/graphql/types/inventory-change/index.ts +0 -47
  311. package/server/graphql/types/inventory-change/inventory-change-list.ts +0 -8
  312. package/server/graphql/types/inventory-change/inventory-change-patch.ts +0 -10
  313. package/server/graphql/types/inventory-change/inventory-change.ts +0 -33
  314. package/server/graphql/types/inventory-change/new-inventory-change.ts +0 -8
  315. package/server/graphql/types/inventory-history/index.ts +0 -54
  316. package/server/graphql/types/inventory-history/inventory-history-list.ts +0 -8
  317. package/server/graphql/types/inventory-history/inventory-history-pallet-report-list.ts +0 -9
  318. package/server/graphql/types/inventory-history/inventory-history-pallet-report.ts +0 -13
  319. package/server/graphql/types/inventory-history/inventory-history-patch.ts +0 -37
  320. package/server/graphql/types/inventory-history/inventory-history-summary-list.ts +0 -10
  321. package/server/graphql/types/inventory-history/inventory-history-summary.ts +0 -17
  322. package/server/graphql/types/inventory-history/inventory-history.ts +0 -56
  323. package/server/graphql/types/inventory-history/new-inventory-history.ts +0 -29
  324. package/server/graphql/types/location/index.ts +0 -53
  325. package/server/graphql/types/location/location-inventories.ts +0 -8
  326. package/server/graphql/types/location/location-inventory.ts +0 -21
  327. package/server/graphql/types/location/location-list.ts +0 -8
  328. package/server/graphql/types/location/location-occupancy.ts +0 -10
  329. package/server/graphql/types/location/location-patch.ts +0 -17
  330. package/server/graphql/types/location/location.ts +0 -21
  331. package/server/graphql/types/location/new-location.ts +0 -15
  332. package/server/graphql/types/movement/index.ts +0 -31
  333. package/server/graphql/types/movement/movement-count.ts +0 -11
  334. package/server/graphql/types/movement/movement-list.ts +0 -8
  335. package/server/graphql/types/movement/movement-patch.ts +0 -12
  336. package/server/graphql/types/movement/movement.ts +0 -17
  337. package/server/graphql/types/movement/new-movement.ts +0 -12
  338. package/server/graphql/types/pallet/index.ts +0 -48
  339. package/server/graphql/types/pallet/new-pallet.ts +0 -11
  340. package/server/graphql/types/pallet/pallet-list.ts +0 -8
  341. package/server/graphql/types/pallet/pallet-patch.ts +0 -14
  342. package/server/graphql/types/pallet/pallet-validate.ts +0 -8
  343. package/server/graphql/types/pallet/pallet.ts +0 -18
  344. package/server/graphql/types/pallet-count/index.ts +0 -38
  345. package/server/graphql/types/pallet-count/new-pallet-count.ts +0 -8
  346. package/server/graphql/types/pallet-count/pallet-count-list.ts +0 -8
  347. package/server/graphql/types/pallet-count/pallet-count-patch.ts +0 -10
  348. package/server/graphql/types/pallet-count/pallet-count.ts +0 -14
  349. package/server/graphql/types/pallet-history/index.ts +0 -34
  350. package/server/graphql/types/pallet-history/new-pallet-history.ts +0 -8
  351. package/server/graphql/types/pallet-history/pallet-history-list.ts +0 -8
  352. package/server/graphql/types/pallet-history/pallet-history-patch.ts +0 -10
  353. package/server/graphql/types/pallet-history/pallet-history.ts +0 -14
  354. package/server/graphql/types/warehouse/index.ts +0 -35
  355. package/server/graphql/types/warehouse/new-warehouse.ts +0 -10
  356. package/server/graphql/types/warehouse/warehouse-list.ts +0 -8
  357. package/server/graphql/types/warehouse/warehouse-patch.ts +0 -12
  358. package/server/graphql/types/warehouse/warehouse.ts +0 -17
@@ -0,0 +1,678 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var _a, _b, _c;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.inventoriesByStrategy = exports.InventoryQuery = void 0;
17
+ const type_graphql_1 = require("type-graphql");
18
+ const typeorm_1 = require("typeorm");
19
+ const auth_base_1 = require("@things-factory/auth-base");
20
+ const biz_base_1 = require("@things-factory/biz-base");
21
+ const product_base_1 = require("@things-factory/product-base");
22
+ const setting_base_1 = require("@things-factory/setting-base");
23
+ const shell_1 = require("@things-factory/shell");
24
+ const constants_1 = require("../../constants");
25
+ const inventory_change_1 = require("../inventory-change/inventory-change");
26
+ const inventory_1 = require("./inventory");
27
+ const inventory_types_1 = require("./inventory-types");
28
+ let InventoryQuery = class InventoryQuery {
29
+ async inventories(context, filters, pagination, sortings, locationSortingRules) {
30
+ var _a, _b;
31
+ const { domain, user } = context.state;
32
+ const productFilters = filters.find(x => x.name == 'product_info');
33
+ filters = filters.filter(x => x.name != 'product_info');
34
+ const params = { filters, pagination };
35
+ if (!params.filters.find((filter) => filter.name === 'bizplace')) {
36
+ params.filters.push({
37
+ name: 'bizplace',
38
+ operator: 'in',
39
+ value: await (0, biz_base_1.getPermittedBizplaceIds)(domain, user),
40
+ relation: true
41
+ });
42
+ }
43
+ const remainOnlyParam = (_a = params === null || params === void 0 ? void 0 : params.filters) === null || _a === void 0 ? void 0 : _a.find((f) => f.name === 'remainOnly');
44
+ let remainOnly = false;
45
+ if (typeof (remainOnlyParam === null || remainOnlyParam === void 0 ? void 0 : remainOnlyParam.value) !== 'undefined') {
46
+ remainOnly = remainOnlyParam.value;
47
+ params.filters = params.filters.filter((f) => f.name !== 'remainOnly');
48
+ }
49
+ const unlockOnlyParam = (_b = params === null || params === void 0 ? void 0 : params.filters) === null || _b === void 0 ? void 0 : _b.find((f) => f.name === 'unlockOnly');
50
+ let unlockOnly = false;
51
+ if (typeof (unlockOnlyParam === null || unlockOnlyParam === void 0 ? void 0 : unlockOnlyParam.value) !== 'undefined') {
52
+ unlockOnly = unlockOnlyParam.value;
53
+ params.filters = params.filters.filter((f) => f.name !== 'unlockOnly');
54
+ }
55
+ const qb = (0, typeorm_1.getRepository)(inventory_1.Inventory).createQueryBuilder('iv');
56
+ (0, shell_1.buildQuery)(qb, params, context);
57
+ qb.leftJoinAndSelect('iv.domain', 'domain')
58
+ .leftJoinAndSelect('iv.bizplace', 'bizplace')
59
+ .leftJoinAndSelect('iv.product', 'product')
60
+ .leftJoinAndSelect('iv.warehouse', 'warehouse')
61
+ .leftJoinAndSelect('iv.location', 'location')
62
+ .leftJoinAndSelect('iv.creator', 'creator')
63
+ .leftJoinAndSelect('iv.updater', 'updater');
64
+ if (remainOnly) {
65
+ qb.andWhere('iv.qty > 0')
66
+ .andWhere('CASE WHEN iv.lockedQty IS NULL THEN 0 ELSE iv.lockedQty END >= 0')
67
+ .andWhere('iv.qty - CASE WHEN iv.lockedQty IS NULL THEN 0 ELSE iv.lockedQty END > 0');
68
+ }
69
+ if (unlockOnly) {
70
+ qb.andWhere('CASE WHEN iv.lockedQty IS NULL THEN 0 ELSE iv.lockedQty END = 0');
71
+ }
72
+ if (productFilters) {
73
+ let productFilterValue = `%${productFilters.value.toLowerCase()}%`;
74
+ qb.andWhere(qb => {
75
+ const subQuery = qb
76
+ .subQuery()
77
+ .select()
78
+ .from(product_base_1.Product, `products`)
79
+ .where(`products.id = iv.product_id`)
80
+ .andWhere(new typeorm_1.Brackets(qb => {
81
+ qb.where('Lower(products.sku) LIKE :productInfo', { productInfo: productFilterValue })
82
+ .orWhere('Lower(products.name) LIKE :productInfo', { productInfo: productFilterValue })
83
+ .orWhere('Lower(products.description) LIKE :productInfo', { productInfo: productFilterValue });
84
+ }))
85
+ .getQuery();
86
+ return `EXISTS ${subQuery}`;
87
+ });
88
+ }
89
+ if ((sortings === null || sortings === void 0 ? void 0 : sortings.length) !== 0) {
90
+ const arrChildSortData = ['bizplace', 'product', 'location', 'warehouse', 'zone'];
91
+ const sort = (sortings || []).reduce((acc, sort) => (Object.assign(Object.assign({}, acc), { [arrChildSortData.indexOf(sort.name) >= 0 ? sort.name + '.name' : 'iv.' + sort.name]: sort.desc
92
+ ? 'DESC'
93
+ : 'ASC' })), {});
94
+ qb.orderBy(sort);
95
+ }
96
+ if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
97
+ locationSortingRules.forEach((rule) => {
98
+ qb.addOrderBy(`location.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
99
+ });
100
+ }
101
+ let [items, total] = await qb.getManyAndCount();
102
+ items = await Promise.all(items.map(async (item) => {
103
+ let inventoryChangeCount = await (0, typeorm_1.getRepository)(inventory_change_1.InventoryChange).count({
104
+ where: { inventory: item.id }
105
+ });
106
+ const selectedQty = item.lockedQty ? item.lockedQty : 0;
107
+ const selectedUomValue = item.lockedUomValue ? item.lockedUomValue : 0;
108
+ return Object.assign(Object.assign({}, item), { changeCount: inventoryChangeCount, remainQty: item.qty - selectedQty, remainUomValue: item.uomValue - selectedUomValue });
109
+ }));
110
+ return { items, total };
111
+ }
112
+ async inventory(palletId, context) {
113
+ const { domain } = context.state;
114
+ return await (0, typeorm_1.getRepository)(inventory_1.Inventory).findOne({
115
+ where: { domain: domain, palletId },
116
+ relations: ['domain', 'bizplace', 'product', 'location', 'warehouse', 'creator', 'updater']
117
+ });
118
+ }
119
+ async inventoryByPallet(palletId, context) {
120
+ const { domain } = context.state;
121
+ return await (0, typeorm_1.getRepository)(inventory_1.Inventory).findOne({
122
+ where: { domain, palletId, status: (0, typeorm_1.Not)((0, typeorm_1.Equal)(constants_1.INVENTORY_STATUS.TERMINATED)) },
123
+ relations: ['domain', 'bizplace', 'product', 'location', 'warehouse', 'creator', 'updater']
124
+ });
125
+ }
126
+ async inventoriesByProduct(params, context) {
127
+ try {
128
+ const { domain, user, tx } = context.state;
129
+ let permittedBizplaceIds = await (0, biz_base_1.getPermittedBizplaceIds)(domain, user);
130
+ const partnersCompanyBizplaces = await (0, biz_base_1.getPartnersCompanyBizplaces)(domain, user);
131
+ const page = params.pagination.page;
132
+ const limit = params.pagination.limit;
133
+ let bizplaceFilter = params.filters.find(filter => filter.name == 'bizplace');
134
+ let productFilter = params.filters.find(filter => filter.name == 'product');
135
+ let productTypeFilter = params.filters.find(filter => filter.name == 'type');
136
+ let availableStockFilter = params.filters.find(filter => filter.name == 'availableStock');
137
+ let lowStockFilter = params.filters.find(filter => filter.name == 'lowStock');
138
+ let overStockFilter = params.filters.find(filter => filter.name == 'overStock');
139
+ if (bizplaceFilter) {
140
+ const bizplaceQueryBuilder = (0, typeorm_1.getRepository)(biz_base_1.Bizplace).createQueryBuilder('b');
141
+ bizplaceQueryBuilder
142
+ .innerJoin('companies', 'c2', ' c2.domain_id = b.domain_id')
143
+ .innerJoin('bizplaces', 'b2', 'b2.company_id = c2.id')
144
+ .where('b2.id = :bizplaceId', { bizplaceId: bizplaceFilter.value });
145
+ let bizplaceList = await bizplaceQueryBuilder.getMany();
146
+ permittedBizplaceIds = [
147
+ ...permittedBizplaceIds.filter(itm => itm == bizplaceFilter.value),
148
+ ...bizplaceList.map(bz => bz.id),
149
+ ...partnersCompanyBizplaces.map(biz => biz.id)
150
+ ];
151
+ }
152
+ let bizplaceQuery = '';
153
+ if (permittedBizplaceIds.length > 0) {
154
+ bizplaceQuery = `AND EXISTS (
155
+ SELECT * FROM (VALUES ${permittedBizplaceIds.map(id => `('${id}')`).join(',')})
156
+ AS bizFilter(bizplace_id)
157
+ WHERE bizFilter.bizplace_id::uuid = "Inventory"."bizplace_id"
158
+ )`;
159
+ }
160
+ else {
161
+ bizplaceQuery = `1 = 0`;
162
+ }
163
+ let productQuery = '';
164
+ if (productFilter) {
165
+ let productValue = productFilter.value
166
+ .toLowerCase()
167
+ .split(',')
168
+ .map(prod => {
169
+ return "'%" + prod.trim().replace(/'/g, "''") + "%'";
170
+ })
171
+ .join(',');
172
+ productQuery = `AND (
173
+ Lower("Product"."name") LIKE ANY(ARRAY[${productValue}])
174
+ OR Lower("Product"."sku") LIKE ANY(ARRAY[${productValue}])
175
+ OR Lower("Product"."description") LIKE ANY(ARRAY[${productValue}])
176
+ OR Lower("ProductRef"."name") LIKE ANY(ARRAY[${productValue}])
177
+ OR Lower("ProductRef"."sku") LIKE ANY(ARRAY[${productValue}])
178
+ OR Lower("ProductRef"."description") LIKE ANY(ARRAY[${productValue}])
179
+ )`;
180
+ }
181
+ if (productTypeFilter) {
182
+ let productTypeValue = productTypeFilter.value
183
+ .toLowerCase()
184
+ .split(',')
185
+ .map(prod => {
186
+ return "'%" + prod.trim().replace(/'/g, "''") + "%'";
187
+ })
188
+ .join(',');
189
+ productQuery =
190
+ productQuery +
191
+ ` AND (
192
+ Lower("Product"."type") LIKE ANY(ARRAY[${productTypeValue}])
193
+ )`;
194
+ }
195
+ let availableStockQuery = '';
196
+ if (availableStockFilter === null || availableStockFilter === void 0 ? void 0 : availableStockFilter.value) {
197
+ availableStockQuery = ` AND SUM("Inventory"."qty") > 0`;
198
+ }
199
+ let thresholdQuery = '';
200
+ if (lowStockFilter === null || lowStockFilter === void 0 ? void 0 : lowStockFilter.value) {
201
+ thresholdQuery = `AND COALESCE("ProductDetailBizplaceSetting"."min_qty", "Product"."min_qty",0) > SUM("Inventory"."qty")`;
202
+ }
203
+ if (overStockFilter === null || overStockFilter === void 0 ? void 0 : overStockFilter.value) {
204
+ thresholdQuery = `AND COALESCE("ProductDetailBizplaceSetting"."max_qty", "Product"."max_qty",0) > 0 AND
205
+ COALESCE("ProductDetailBizplaceSetting"."max_qty", "Product"."max_qty",0) < SUM("Inventory"."qty")`;
206
+ }
207
+ await tx.query(`
208
+ create temp table temp_inv_history AS
209
+ (
210
+ SELECT "Product"."id" AS "id", "Product"."sku" AS "sku", "Product"."name" AS "name", "Product"."type" AS "type", "Product"."description" AS "description",
211
+ "Product"."weight" AS "weight", "ProductRef"."name" AS "productRefName",
212
+ "ProductRef"."description" AS "productRefDesciption", "Bizplace"."name" AS "bizplaceName", SUM("Inventory"."qty") AS "qty" ,
213
+ CASE WHEN SUM("Inventory"."qty") > 0 THEN SUM(COALESCE("Inventory"."unit_cost", 0) * "Inventory"."qty")/ SUM("Inventory"."qty") ELSE 0 END AS "averageUnitCost",
214
+ COALESCE("ProductDetailBizplaceSetting"."min_qty", "Product"."min_qty",0) AS "minQty",
215
+ COALESCE("ProductDetailBizplaceSetting"."max_qty", "Product"."max_qty",0) AS "maxQty"
216
+ FROM "inventories" "Inventory"
217
+ LEFT JOIN "products" "Product" ON "Product"."id"="Inventory"."product_id"
218
+ LEFT JOIN "product_details" "ProductDetails" ON "ProductDetails"."product_id" = "Product"."id"
219
+ AND "ProductDetails"."is_default"
220
+ LEFT JOIN "product_detail_bizplace_settings" "ProductDetailBizplaceSetting" ON "ProductDetailBizplaceSetting"."product_detail_id" = "ProductDetails"."id"
221
+ AND "ProductDetailBizplaceSetting"."domain_id" = "Inventory"."domain_id"
222
+ LEFT JOIN "products" "ProductRef" ON "ProductRef"."id"="Product"."product_ref_id"
223
+ INNER JOIN "bizplaces" "Bizplace" ON "Bizplace"."id"="Inventory"."bizplace_id"
224
+ WHERE "Inventory"."qty" >= 0
225
+ AND "Inventory"."domain_id" = $1
226
+ ${bizplaceQuery}
227
+ ${productQuery}
228
+ GROUP BY "Product"."id", "ProductRef"."id", "Bizplace"."id", "ProductDetailBizplaceSetting"."id"
229
+ HAVING 1 = 1
230
+ ${availableStockQuery}
231
+ ${thresholdQuery}
232
+ )`, [domain.id]);
233
+ const results = await tx.query(`
234
+ SELECT * FROM temp_inv_history
235
+ ORDER BY "bizplaceName", "sku"
236
+ OFFSET $1 LIMIT $2
237
+ `, [(page - 1) * limit, limit]);
238
+ const total = await tx.query(`SELECT COUNT(*) FROM temp_inv_history`);
239
+ tx.query(`drop table temp_inv_history`);
240
+ return {
241
+ items: results.map((item) => {
242
+ return {
243
+ product: {
244
+ id: item.id,
245
+ name: item.name,
246
+ sku: item.sku,
247
+ description: item.description,
248
+ type: item.type,
249
+ weight: item.weight,
250
+ productRef: { name: item.productRefName, description: item.productRefDesciption },
251
+ bizplace: { name: item.bizplaceName },
252
+ minQty: item.minQty,
253
+ maxQty: item.maxQty
254
+ },
255
+ averageUnitCost: item.averageUnitCost,
256
+ qty: item.qty
257
+ };
258
+ }),
259
+ total: total[0].count
260
+ };
261
+ }
262
+ catch (error) {
263
+ throw error;
264
+ }
265
+ }
266
+ async inventoriesByStrategy(context, worksheetId, batchId, productName, productSku, packingType, pickingStrategy, locationSortingRules, bizplaceId) {
267
+ const { domain, tx } = context.state;
268
+ const inventoryAssignmentSetting = await tx.getRepository(setting_base_1.Setting).findOne({
269
+ where: { domain, name: 'rule-for-inventory-assignment' }
270
+ });
271
+ if (!locationSortingRules && inventoryAssignmentSetting) {
272
+ locationSortingRules = [];
273
+ let locationSetting = JSON.parse(inventoryAssignmentSetting.value);
274
+ for (const key in locationSetting) {
275
+ locationSortingRules.push({ name: key, desc: locationSetting[key] == 'ASC' ? false : true });
276
+ }
277
+ }
278
+ return inventoriesByStrategy({ worksheetId, batchId, bizplaceId, productName, productSku, packingType, pickingStrategy, locationSortingRules }, tx);
279
+ }
280
+ async checkProductIdenticality(palletA, palletB, context) {
281
+ var _a, _b;
282
+ const { tx } = context.state;
283
+ const invRepo = tx.getRepository(inventory_1.Inventory);
284
+ const invA = await invRepo.findOne({
285
+ where: { domain: context.state.domain, palletId: palletA, status: constants_1.INVENTORY_STATUS.STORED },
286
+ relations: ['product']
287
+ });
288
+ const invB = await invRepo.findOne({
289
+ where: { domain: context.state.domain, palletId: palletB, status: constants_1.INVENTORY_STATUS.STORED },
290
+ relations: ['product']
291
+ });
292
+ return ((invA === null || invA === void 0 ? void 0 : invA.batchId) === (invB === null || invB === void 0 ? void 0 : invB.batchId) &&
293
+ ((_a = invA === null || invA === void 0 ? void 0 : invA.product) === null || _a === void 0 ? void 0 : _a.id) === ((_b = invB === null || invB === void 0 ? void 0 : invB.product) === null || _b === void 0 ? void 0 : _b.id) &&
294
+ (invA === null || invA === void 0 ? void 0 : invA.packingType) === (invB === null || invB === void 0 ? void 0 : invB.packingType));
295
+ }
296
+ async checkCartonIdenticality(cartonA, palletA, cartonB, context) {
297
+ var _a, _b;
298
+ const invRepo = (0, typeorm_1.getRepository)(inventory_1.Inventory);
299
+ const invA = await invRepo.findOne({
300
+ where: { domain: context.state.domain, palletId: palletA, cartonId: cartonA, status: constants_1.INVENTORY_STATUS.STORED },
301
+ relations: ['product']
302
+ });
303
+ const invB = await invRepo.findOne({
304
+ where: {
305
+ domain: context.state.domain,
306
+ packingType: invA.packingType,
307
+ packingSize: invA.packingSize,
308
+ product: invA.product,
309
+ cartonId: cartonB,
310
+ status: constants_1.INVENTORY_STATUS.STORED
311
+ },
312
+ relations: ['product']
313
+ });
314
+ return ((invA === null || invA === void 0 ? void 0 : invA.expirationDate) === (invB === null || invB === void 0 ? void 0 : invB.expirationDate) &&
315
+ ((_a = invA === null || invA === void 0 ? void 0 : invA.product) === null || _a === void 0 ? void 0 : _a.id) === ((_b = invB === null || invB === void 0 ? void 0 : invB.product) === null || _b === void 0 ? void 0 : _b.id) &&
316
+ (invA === null || invA === void 0 ? void 0 : invA.packingType) === (invB === null || invB === void 0 ? void 0 : invB.packingType) &&
317
+ (invA === null || invA === void 0 ? void 0 : invA.packingSize) === (invB === null || invB === void 0 ? void 0 : invB.packingSize));
318
+ }
319
+ async checkInventoryOwner(palletId, bizplaceName, context) {
320
+ const invRepo = (0, typeorm_1.getRepository)(inventory_1.Inventory);
321
+ const bizRepo = (0, typeorm_1.getRepository)(biz_base_1.Bizplace);
322
+ const inventory = await invRepo.findOne({
323
+ where: { domain: context.state.domain, palletId, status: constants_1.INVENTORY_STATUS.STORED },
324
+ relations: ['bizplace']
325
+ });
326
+ if (!inventory)
327
+ throw new Error('This inventory status is not stored.');
328
+ const ownerBizplace = await bizRepo.findOne({
329
+ where: { name: bizplaceName }
330
+ });
331
+ const foundBizplace = inventory.bizplace;
332
+ return Boolean(ownerBizplace.id === foundBizplace.id);
333
+ }
334
+ async inventoriesByBundle(context, filters, pagination, sortings) {
335
+ var _a, _b;
336
+ const { domain, user } = context.state;
337
+ const params = { filters, pagination };
338
+ const productBundleId = params.filters.filter(x => x.name === 'productBundleId')[0].value;
339
+ if (!productBundleId) {
340
+ throw new Error('params product bundle is missing');
341
+ }
342
+ const bundleReleaseQty = params.filters.filter(x => x.name === 'bundleReleaseQty')[0].value;
343
+ // remove productBundleId and bundleReleaseQty from params.filters
344
+ params.filters = params.filters.filter(x => x.name !== 'productBundleId' && x.name !== 'bundleReleaseQty');
345
+ if (!params.filters.find((filter) => filter.name === 'bizplace_id')) {
346
+ params.filters.push({
347
+ name: 'bizplace_id',
348
+ operator: 'in',
349
+ value: await (0, biz_base_1.getPermittedBizplaceIds)(domain, user),
350
+ relation: true
351
+ });
352
+ }
353
+ const remainOnlyParam = (_a = params === null || params === void 0 ? void 0 : params.filters) === null || _a === void 0 ? void 0 : _a.find((f) => f.name === 'remainOnly');
354
+ let remainOnly = false;
355
+ if (typeof (remainOnlyParam === null || remainOnlyParam === void 0 ? void 0 : remainOnlyParam.value) !== 'undefined') {
356
+ remainOnly = remainOnlyParam.value;
357
+ params.filters = params.filters.filter((f) => f.name !== 'remainOnly');
358
+ }
359
+ const unlockOnlyParam = (_b = params === null || params === void 0 ? void 0 : params.filters) === null || _b === void 0 ? void 0 : _b.find((f) => f.name === 'unlockOnly');
360
+ let unlockOnly = false;
361
+ if (typeof (unlockOnlyParam === null || unlockOnlyParam === void 0 ? void 0 : unlockOnlyParam.value) !== 'undefined') {
362
+ unlockOnly = unlockOnlyParam.value;
363
+ params.filters = params.filters.filter((f) => f.name !== 'unlockOnly');
364
+ }
365
+ const productBundleSettings = await (0, typeorm_1.getRepository)(product_base_1.ProductBundleSetting).find({
366
+ where: { productBundle: productBundleId },
367
+ relations: ['product', 'productBundle']
368
+ });
369
+ if (!productBundleSettings.length) {
370
+ throw new Error('product bundle settings is not found');
371
+ }
372
+ const qb = (0, typeorm_1.getRepository)(inventory_1.Inventory).createQueryBuilder('iv');
373
+ (0, shell_1.buildQuery)(qb, params, context);
374
+ qb.select('iv.product_id', 'productId')
375
+ .addSelect('iv.batch_id', 'batchId')
376
+ .addSelect('iv.batch_id_ref', 'batchIdRef')
377
+ .addSelect('iv.packing_type', 'packingType')
378
+ .addSelect('SUM(iv.qty)', 'qty')
379
+ .addSelect('SUM(iv.locked_qty)', 'lockedQty')
380
+ .addSelect('SUM(iv.uom_value)', 'uomValue')
381
+ .addSelect('SUM(iv.locked_uom_value)', 'lockedUomValue')
382
+ .addSelect('prd.sku', 'productSku')
383
+ .addSelect('prd.name', 'productName')
384
+ .addSelect('prd.description', 'productDescription')
385
+ .addSelect('prd.type', 'productType')
386
+ .addSelect('prd.primary_unit', 'uom')
387
+ .leftJoin('iv.product', 'prd');
388
+ if (remainOnly) {
389
+ qb.andWhere('iv.qty > 0')
390
+ .andWhere('CASE WHEN iv.lockedQty IS NULL THEN 0 ELSE iv.lockedQty END >= 0')
391
+ .andWhere('iv.qty - CASE WHEN iv.lockedQty IS NULL THEN 0 ELSE iv.lockedQty END > 0');
392
+ }
393
+ if (unlockOnly) {
394
+ qb.andWhere('CASE WHEN iv.lockedQty IS NULL THEN 0 ELSE iv.lockedQty END = 0');
395
+ }
396
+ qb.andWhere('iv.product_id IN (:...productIds)', {
397
+ productIds: productBundleSettings.map(productBundle => productBundle.product.id)
398
+ })
399
+ .groupBy('iv.product_id')
400
+ .addGroupBy('iv.batch_id')
401
+ .addGroupBy('iv.batch_id_ref')
402
+ .addGroupBy('iv.packing_type')
403
+ .addGroupBy('prd.sku')
404
+ .addGroupBy('prd.name')
405
+ .addGroupBy('prd.description')
406
+ .addGroupBy('prd.type')
407
+ .addOrderBy('prd.name')
408
+ .addGroupBy('prd.primary_unit')
409
+ .addOrderBy('iv.batch_id');
410
+ let bundleGroup = await qb.getRawMany();
411
+ bundleGroup = bundleGroup.map((item) => {
412
+ return Object.assign(Object.assign({}, item), { bundleId: productBundleId, remainQty: item.qty - (item.lockedQty ? item.lockedQty : 0), remainUomValue: item.uomValue - (item.lockedUomValue ? item.lockedUomValue : 0), uom: item.uom, bundleQty: productBundleSettings.filter(pbs => pbs.product.id === item.productId)[0].bundleQty });
413
+ });
414
+ const bundleSetting = productBundleSettings.map(pbs => {
415
+ return {
416
+ id: pbs.id,
417
+ productId: pbs.product.id,
418
+ bundleId: pbs.productBundle.id,
419
+ bundleQty: pbs.bundleQty,
420
+ releaseQty: bundleReleaseQty * pbs.bundleQty,
421
+ productReleaseQty: 0,
422
+ productReleaseUomValue: 0
423
+ };
424
+ });
425
+ /** ************************ **/
426
+ bundleGroup = bundleGroup
427
+ .map(group => {
428
+ const uomValue = group.remainUomValue / group.remainQty;
429
+ bundleSetting.forEach(setting => {
430
+ let assigned = false;
431
+ let releaseQty = 0;
432
+ let releaseUomValue = 0;
433
+ if (group.productId === setting.productId) {
434
+ if (setting.productReleaseQty < setting.releaseQty) {
435
+ assigned = true;
436
+ const leftQty = setting.releaseQty - setting.productReleaseQty;
437
+ releaseQty = leftQty > group.remainQty ? group.remainQty : leftQty;
438
+ releaseUomValue = Math.round(releaseQty * uomValue * 100) / 100;
439
+ setting.productReleaseQty += releaseQty;
440
+ setting.productReleaseUomValue += releaseUomValue;
441
+ }
442
+ group.assigned = assigned;
443
+ group.releaseQty = releaseQty;
444
+ group.releaseUomValue = releaseUomValue;
445
+ group.releaseUomValueWithUom = `${releaseUomValue} ${group.uom}`;
446
+ }
447
+ });
448
+ return group;
449
+ })
450
+ .filter(group => group.assigned);
451
+ /** ************************ **/
452
+ return { bundleGroup, bundleSetting };
453
+ }
454
+ async domain(inventory) {
455
+ return await (0, typeorm_1.getRepository)(shell_1.Domain).findOne(inventory.domainId);
456
+ }
457
+ async updater(inventory) {
458
+ return await (0, typeorm_1.getRepository)(auth_base_1.User).findOne(inventory.updaterId);
459
+ }
460
+ async creator(inventory) {
461
+ return await (0, typeorm_1.getRepository)(auth_base_1.User).findOne(inventory.creatorId);
462
+ }
463
+ };
464
+ __decorate([
465
+ (0, type_graphql_1.Directive)('@privilege(category: "inventory", privilege: "query")'),
466
+ (0, type_graphql_1.Query)(returns => inventory_types_1.InventoryList),
467
+ __param(0, (0, type_graphql_1.Ctx)()),
468
+ __param(1, (0, type_graphql_1.Arg)('filters', type => [shell_1.Filter], { nullable: true })),
469
+ __param(2, (0, type_graphql_1.Arg)('pagination', type => shell_1.Pagination, { nullable: true })),
470
+ __param(3, (0, type_graphql_1.Arg)('sortings', type => [shell_1.Sorting], { nullable: true })),
471
+ __param(4, (0, type_graphql_1.Arg)('locationSortingRules', type => [shell_1.Sorting], { nullable: true })),
472
+ __metadata("design:type", Function),
473
+ __metadata("design:paramtypes", [Object, Array, typeof (_a = typeof shell_1.Pagination !== "undefined" && shell_1.Pagination) === "function" ? _a : Object, Array, Array]),
474
+ __metadata("design:returntype", Promise)
475
+ ], InventoryQuery.prototype, "inventories", null);
476
+ __decorate([
477
+ (0, type_graphql_1.Directive)('@privilege(category: "inventory", privilege: "query")'),
478
+ (0, type_graphql_1.Query)(returns => inventory_1.Inventory),
479
+ __param(0, (0, type_graphql_1.Arg)('palletId')),
480
+ __param(1, (0, type_graphql_1.Ctx)()),
481
+ __metadata("design:type", Function),
482
+ __metadata("design:paramtypes", [String, Object]),
483
+ __metadata("design:returntype", Promise)
484
+ ], InventoryQuery.prototype, "inventory", null);
485
+ __decorate([
486
+ (0, type_graphql_1.Directive)('@privilege(category: "inventory", privilege: "query")'),
487
+ (0, type_graphql_1.Query)(returns => inventory_1.Inventory),
488
+ __param(0, (0, type_graphql_1.Arg)('palletId')),
489
+ __param(1, (0, type_graphql_1.Ctx)()),
490
+ __metadata("design:type", Function),
491
+ __metadata("design:paramtypes", [String, Object]),
492
+ __metadata("design:returntype", Promise)
493
+ ], InventoryQuery.prototype, "inventoryByPallet", null);
494
+ __decorate([
495
+ (0, type_graphql_1.Directive)('@privilege(category: "inventory", privilege: "query")'),
496
+ (0, type_graphql_1.Directive)('@transaction'),
497
+ (0, type_graphql_1.Query)(returns => inventory_types_1.InventoryList),
498
+ __param(0, (0, type_graphql_1.Args)()),
499
+ __param(1, (0, type_graphql_1.Ctx)()),
500
+ __metadata("design:type", Function),
501
+ __metadata("design:paramtypes", [typeof (_b = typeof shell_1.ListParam !== "undefined" && shell_1.ListParam) === "function" ? _b : Object, Object]),
502
+ __metadata("design:returntype", Promise)
503
+ ], InventoryQuery.prototype, "inventoriesByProduct", null);
504
+ __decorate([
505
+ (0, type_graphql_1.Directive)('@transaction'),
506
+ (0, type_graphql_1.Query)(returns => inventory_types_1.InventoryList),
507
+ __param(0, (0, type_graphql_1.Ctx)()),
508
+ __param(1, (0, type_graphql_1.Arg)('worksheetId')),
509
+ __param(2, (0, type_graphql_1.Arg)('batchId')),
510
+ __param(3, (0, type_graphql_1.Arg)('productName')),
511
+ __param(4, (0, type_graphql_1.Arg)('productSku')),
512
+ __param(5, (0, type_graphql_1.Arg)('packingType')),
513
+ __param(6, (0, type_graphql_1.Arg)('pickingStrategy')),
514
+ __param(7, (0, type_graphql_1.Arg)('locationSortingRules', type => [shell_1.Sorting], { nullable: true })),
515
+ __param(8, (0, type_graphql_1.Arg)('bizplaceId', { nullable: true })),
516
+ __metadata("design:type", Function),
517
+ __metadata("design:paramtypes", [Object, String, String, String, String, String, String, Array, String]),
518
+ __metadata("design:returntype", Promise)
519
+ ], InventoryQuery.prototype, "inventoriesByStrategy", null);
520
+ __decorate([
521
+ (0, type_graphql_1.Directive)('@transaction'),
522
+ (0, type_graphql_1.Query)(returns => Boolean),
523
+ __param(0, (0, type_graphql_1.Arg)('palletA')),
524
+ __param(1, (0, type_graphql_1.Arg)('palletB')),
525
+ __param(2, (0, type_graphql_1.Ctx)()),
526
+ __metadata("design:type", Function),
527
+ __metadata("design:paramtypes", [String, String, Object]),
528
+ __metadata("design:returntype", Promise)
529
+ ], InventoryQuery.prototype, "checkProductIdenticality", null);
530
+ __decorate([
531
+ (0, type_graphql_1.Query)(returns => Boolean),
532
+ __param(0, (0, type_graphql_1.Arg)('cartonA')),
533
+ __param(1, (0, type_graphql_1.Arg)('palletA')),
534
+ __param(2, (0, type_graphql_1.Arg)('cartonB')),
535
+ __param(3, (0, type_graphql_1.Ctx)()),
536
+ __metadata("design:type", Function),
537
+ __metadata("design:paramtypes", [String, String, String, Object]),
538
+ __metadata("design:returntype", Promise)
539
+ ], InventoryQuery.prototype, "checkCartonIdenticality", null);
540
+ __decorate([
541
+ (0, type_graphql_1.Query)(returns => Boolean),
542
+ __param(0, (0, type_graphql_1.Arg)('palletId')),
543
+ __param(1, (0, type_graphql_1.Arg)('bizplaceName')),
544
+ __param(2, (0, type_graphql_1.Ctx)()),
545
+ __metadata("design:type", Function),
546
+ __metadata("design:paramtypes", [String, String, Object]),
547
+ __metadata("design:returntype", Promise)
548
+ ], InventoryQuery.prototype, "checkInventoryOwner", null);
549
+ __decorate([
550
+ (0, type_graphql_1.Directive)('@privilege(category: "inventory", privilege: "query")'),
551
+ (0, type_graphql_1.Query)(returns => inventory_types_1.InventoryBundleGroupDetail),
552
+ __param(0, (0, type_graphql_1.Ctx)()),
553
+ __param(1, (0, type_graphql_1.Arg)('filters', type => [shell_1.Filter], { nullable: true })),
554
+ __param(2, (0, type_graphql_1.Arg)('pagination', type => shell_1.Pagination, { nullable: true })),
555
+ __param(3, (0, type_graphql_1.Arg)('sortings', type => [shell_1.Sorting], { nullable: true })),
556
+ __metadata("design:type", Function),
557
+ __metadata("design:paramtypes", [Object, Array, typeof (_c = typeof shell_1.Pagination !== "undefined" && shell_1.Pagination) === "function" ? _c : Object, Array]),
558
+ __metadata("design:returntype", Promise)
559
+ ], InventoryQuery.prototype, "inventoriesByBundle", null);
560
+ __decorate([
561
+ (0, type_graphql_1.FieldResolver)(type => shell_1.Domain),
562
+ __param(0, (0, type_graphql_1.Root)()),
563
+ __metadata("design:type", Function),
564
+ __metadata("design:paramtypes", [inventory_1.Inventory]),
565
+ __metadata("design:returntype", Promise)
566
+ ], InventoryQuery.prototype, "domain", null);
567
+ __decorate([
568
+ (0, type_graphql_1.FieldResolver)(type => auth_base_1.User),
569
+ __param(0, (0, type_graphql_1.Root)()),
570
+ __metadata("design:type", Function),
571
+ __metadata("design:paramtypes", [inventory_1.Inventory]),
572
+ __metadata("design:returntype", Promise)
573
+ ], InventoryQuery.prototype, "updater", null);
574
+ __decorate([
575
+ (0, type_graphql_1.FieldResolver)(type => auth_base_1.User),
576
+ __param(0, (0, type_graphql_1.Root)()),
577
+ __metadata("design:type", Function),
578
+ __metadata("design:paramtypes", [inventory_1.Inventory]),
579
+ __metadata("design:returntype", Promise)
580
+ ], InventoryQuery.prototype, "creator", null);
581
+ InventoryQuery = __decorate([
582
+ (0, type_graphql_1.Resolver)(inventory_1.Inventory)
583
+ ], InventoryQuery);
584
+ exports.InventoryQuery = InventoryQuery;
585
+ async function inventoriesByStrategy({ worksheetId, batchId, bizplaceId, productName, productSku, packingType, pickingStrategy, locationSortingRules }, trxMgr) {
586
+ const qb = await trxMgr.getRepository(inventory_1.Inventory).createQueryBuilder('INV');
587
+ qb.leftJoinAndSelect('INV.product', 'PROD')
588
+ .leftJoinAndSelect('INV.location', 'LOC')
589
+ .addSelect(subQuery => subQuery
590
+ .select('COALESCE(SUM(release_qty), 0)', 'releaseQty')
591
+ .from('order_inventories', 'OI')
592
+ .where('"OI"."inventory_id" = "INV"."id"')
593
+ .andWhere("\"OI\".\"status\" IN ('PENDING', 'PENDING_RECEIVE', 'PENDING_WORKSHEET', 'PENDING_SPLIT')")
594
+ .andWhere('"OI"."ref_worksheet_id" <> :worksheetId', { worksheetId: worksheetId }))
595
+ .addSelect(subQuery => subQuery
596
+ .select('COALESCE(SUM(release_uom_value), 0)', 'releaseUomValue')
597
+ .from('order_inventories', 'OI')
598
+ .where('"OI"."inventory_id" = "INV"."id"')
599
+ .andWhere("\"OI\".\"status\" IN ('PENDING', 'PENDING_RECEIVE', 'PENDING_WORKSHEET', 'PENDING_SPLIT')")
600
+ .andWhere('"OI"."ref_worksheet_id" <> :worksheetId', { worksheetId: worksheetId }))
601
+ .andWhere('"PROD"."name" = :productName')
602
+ .andWhere('"PROD"."sku" = :productSku')
603
+ .andWhere('"INV"."packing_type" = :packingType')
604
+ .andWhere('"INV"."status" = :status', { status: 'STORED' })
605
+ .setParameters({
606
+ productName,
607
+ productSku,
608
+ packingType
609
+ });
610
+ if (batchId !== '') {
611
+ qb.andWhere('"INV"."batch_id" = :batchId', { batchId });
612
+ }
613
+ if (bizplaceId) {
614
+ qb.andWhere('"INV"."bizplace_id" = :bizplaceId', { bizplaceId: bizplaceId });
615
+ }
616
+ switch (pickingStrategy.toUpperCase()) {
617
+ case 'FIFO':
618
+ qb.orderBy('"INV"."created_at"', 'ASC');
619
+ if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
620
+ locationSortingRules.forEach((rule, idx) => {
621
+ idx === 0
622
+ ? qb.addOrderBy(`LOC.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
623
+ : qb.addOrderBy(`LOC.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
624
+ });
625
+ }
626
+ break;
627
+ case 'LIFO':
628
+ qb.orderBy('"INV"."created_at"', 'DESC');
629
+ if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
630
+ locationSortingRules.forEach((rule, idx) => {
631
+ idx === 0
632
+ ? qb.addOrderBy(`LOC.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
633
+ : qb.addOrderBy(`LOC.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
634
+ });
635
+ }
636
+ break;
637
+ case 'FEFO':
638
+ qb.orderBy('"INV"."expiration_date"', 'ASC');
639
+ if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
640
+ locationSortingRules.forEach((rule, idx) => {
641
+ idx === 0
642
+ ? qb.addOrderBy(`LOC.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
643
+ : qb.addOrderBy(`LOC.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
644
+ });
645
+ }
646
+ break;
647
+ case 'LOCATION':
648
+ if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
649
+ locationSortingRules.forEach((rule, idx) => {
650
+ idx === 0
651
+ ? qb.orderBy(`LOC.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
652
+ : qb.addOrderBy(`LOC.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
653
+ });
654
+ }
655
+ else
656
+ qb.orderBy('"LOC"."name"', 'DESC');
657
+ break;
658
+ default:
659
+ qb.orderBy('"INV"."created_at"', 'ASC');
660
+ break;
661
+ }
662
+ const { entities, raw } = await qb.getRawAndEntities();
663
+ const items = entities
664
+ .map((inv, idx) => {
665
+ const qty = (inv === null || inv === void 0 ? void 0 : inv.qty) > 0 ? inv.qty : 0;
666
+ const uomValue = (inv === null || inv === void 0 ? void 0 : inv.uomValue) > 0 ? inv.uomValue : 0;
667
+ const lockedQty = inv.lockedQty || 0;
668
+ const lockedUomValue = inv.lockedUomValue || 0;
669
+ const releaseQty = parseInt(raw[idx].releaseQty) || 0;
670
+ const releaseUomValue = parseFloat(raw[idx].releaseUomValue) || 0;
671
+ return Object.assign(Object.assign({}, inv), { qty: qty - lockedQty - releaseQty, uomValue: uomValue - lockedUomValue - releaseUomValue });
672
+ })
673
+ .filter((inv) => inv.qty);
674
+ const total = await qb.getCount();
675
+ return { items, total };
676
+ }
677
+ exports.inventoriesByStrategy = inventoriesByStrategy;
678
+ //# sourceMappingURL=inventory-query.js.map