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

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 (660) 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/index.js +11 -12
  12. package/dist-server/index.js.map +1 -1
  13. package/dist-server/service/index.js +71 -0
  14. package/dist-server/service/index.js.map +1 -0
  15. package/dist-server/service/inventory/index.js +9 -0
  16. package/dist-server/service/inventory/index.js.map +1 -0
  17. package/dist-server/service/inventory/inventory-mutation.js +324 -0
  18. package/dist-server/service/inventory/inventory-mutation.js.map +1 -0
  19. package/dist-server/service/inventory/inventory-query.js +678 -0
  20. package/dist-server/service/inventory/inventory-query.js.map +1 -0
  21. package/dist-server/service/inventory/inventory-types.js +405 -0
  22. package/dist-server/service/inventory/inventory-types.js.map +1 -0
  23. package/dist-server/{entities → service/inventory}/inventory.js +94 -11
  24. package/dist-server/service/inventory/inventory.js.map +1 -0
  25. package/dist-server/service/inventory-change/index.js +9 -0
  26. package/dist-server/service/inventory-change/index.js.map +1 -0
  27. package/dist-server/service/inventory-change/inventory-change-mutation.js +530 -0
  28. package/dist-server/service/inventory-change/inventory-change-mutation.js.map +1 -0
  29. package/dist-server/service/inventory-change/inventory-change-query.js +121 -0
  30. package/dist-server/service/inventory-change/inventory-change-query.js.map +1 -0
  31. package/dist-server/service/inventory-change/inventory-change-types.js +65 -0
  32. package/dist-server/service/inventory-change/inventory-change-types.js.map +1 -0
  33. package/dist-server/{entities → service/inventory-change}/inventory-change.js +47 -5
  34. package/dist-server/service/inventory-change/inventory-change.js.map +1 -0
  35. package/dist-server/service/inventory-history/index.js +9 -0
  36. package/dist-server/service/inventory-history/index.js.map +1 -0
  37. package/dist-server/service/inventory-history/inventory-history-mutation.js +121 -0
  38. package/dist-server/service/inventory-history/inventory-history-mutation.js.map +1 -0
  39. package/dist-server/service/inventory-history/inventory-history-query.js +1283 -0
  40. package/dist-server/service/inventory-history/inventory-history-query.js.map +1 -0
  41. package/dist-server/service/inventory-history/inventory-history-types.js +382 -0
  42. package/dist-server/service/inventory-history/inventory-history-types.js.map +1 -0
  43. package/dist-server/{entities → service/inventory-history}/inventory-history.js +64 -19
  44. package/dist-server/service/inventory-history/inventory-history.js.map +1 -0
  45. package/dist-server/service/location/index.js +9 -0
  46. package/dist-server/service/location/index.js.map +1 -0
  47. package/dist-server/service/location/location-mutation.js +157 -0
  48. package/dist-server/service/location/location-mutation.js.map +1 -0
  49. package/dist-server/service/location/location-query.js +248 -0
  50. package/dist-server/service/location/location-query.js.map +1 -0
  51. package/dist-server/service/location/location-types.js +223 -0
  52. package/dist-server/service/location/location-types.js.map +1 -0
  53. package/dist-server/{entities → service/location}/location.js +32 -3
  54. package/dist-server/service/location/location.js.map +1 -0
  55. package/dist-server/service/movement/index.js +9 -0
  56. package/dist-server/service/movement/index.js.map +1 -0
  57. package/dist-server/service/movement/movement-mutation.js +80 -0
  58. package/dist-server/service/movement/movement-mutation.js.map +1 -0
  59. package/dist-server/service/movement/movement-query.js +286 -0
  60. package/dist-server/service/movement/movement-query.js.map +1 -0
  61. package/dist-server/service/movement/movement-types.js +117 -0
  62. package/dist-server/service/movement/movement-types.js.map +1 -0
  63. package/dist-server/{entities → service/movement}/movement.js +28 -3
  64. package/dist-server/service/movement/movement.js.map +1 -0
  65. package/dist-server/service/pallet/index.js +9 -0
  66. package/dist-server/service/pallet/index.js.map +1 -0
  67. package/dist-server/service/pallet/pallet-mutation.js +192 -0
  68. package/dist-server/service/pallet/pallet-mutation.js.map +1 -0
  69. package/dist-server/service/pallet/pallet-query.js +164 -0
  70. package/dist-server/service/pallet/pallet-query.js.map +1 -0
  71. package/dist-server/service/pallet/pallet-types.js +109 -0
  72. package/dist-server/service/pallet/pallet-types.js.map +1 -0
  73. package/dist-server/{entities → service/pallet}/pallet.js +32 -5
  74. package/dist-server/service/pallet/pallet.js.map +1 -0
  75. package/dist-server/service/pallet-count/index.js +9 -0
  76. package/dist-server/service/pallet-count/index.js.map +1 -0
  77. package/dist-server/service/pallet-count/pallet-count-mutation.js +156 -0
  78. package/dist-server/service/pallet-count/pallet-count-mutation.js.map +1 -0
  79. package/dist-server/service/pallet-count/pallet-count-query.js +86 -0
  80. package/dist-server/service/pallet-count/pallet-count-query.js.map +1 -0
  81. package/dist-server/service/pallet-count/pallet-count-types.js +65 -0
  82. package/dist-server/service/pallet-count/pallet-count-types.js.map +1 -0
  83. package/dist-server/{entities → service/pallet-count}/pallet-count.js +25 -2
  84. package/dist-server/service/pallet-count/pallet-count.js.map +1 -0
  85. package/dist-server/service/pallet-history/index.js +9 -0
  86. package/dist-server/service/pallet-history/index.js.map +1 -0
  87. package/dist-server/service/pallet-history/pallet-history-mutation.js +120 -0
  88. package/dist-server/service/pallet-history/pallet-history-mutation.js.map +1 -0
  89. package/dist-server/service/pallet-history/pallet-history-query.js +87 -0
  90. package/dist-server/service/pallet-history/pallet-history-query.js.map +1 -0
  91. package/dist-server/service/pallet-history/pallet-history-types.js +65 -0
  92. package/dist-server/service/pallet-history/pallet-history-types.js.map +1 -0
  93. package/dist-server/{entities → service/pallet-history}/pallet-history.js +34 -11
  94. package/dist-server/service/pallet-history/pallet-history.js.map +1 -0
  95. package/dist-server/service/reduced-inventory-history/index.js +6 -0
  96. package/dist-server/service/reduced-inventory-history/index.js.map +1 -0
  97. package/dist-server/{entities → service/reduced-inventory-history}/reduced-inventory-history.js +8 -15
  98. package/dist-server/service/reduced-inventory-history/reduced-inventory-history.js.map +1 -0
  99. package/dist-server/service/warehouse/index.js +9 -0
  100. package/dist-server/service/warehouse/index.js.map +1 -0
  101. package/dist-server/service/warehouse/warehouse-mutation.js +135 -0
  102. package/dist-server/service/warehouse/warehouse-mutation.js.map +1 -0
  103. package/dist-server/service/warehouse/warehouse-query.js +91 -0
  104. package/dist-server/service/warehouse/warehouse-query.js.map +1 -0
  105. package/dist-server/service/warehouse/warehouse-types.js +82 -0
  106. package/dist-server/service/warehouse/warehouse-types.js.map +1 -0
  107. package/dist-server/{entities → service/warehouse}/warehouse.js +28 -3
  108. package/dist-server/service/warehouse/warehouse.js.map +1 -0
  109. package/dist-server/utils/inventory-util.js +46 -12
  110. package/dist-server/utils/inventory-util.js.map +1 -1
  111. package/package.json +8 -7
  112. package/server/constants/inventory.ts +4 -1
  113. package/server/controllers/ecommerce/ecommerce-controller.ts +4 -3
  114. package/server/controllers/ecommerce/index.ts +1 -0
  115. package/server/controllers/ecommerce/sellercraft-controller.ts +58 -0
  116. package/server/controllers/warehouse-controller.ts +54 -2
  117. package/server/index.ts +8 -4
  118. package/server/service/index.ts +61 -0
  119. package/server/service/inventory/index.ts +6 -0
  120. package/server/{graphql/resolvers/inventory/update-multiple-inventory.ts → service/inventory/inventory-mutation.ts} +158 -7
  121. package/server/service/inventory/inventory-query.ts +745 -0
  122. package/server/service/inventory/inventory-types.ts +289 -0
  123. package/server/{entities → service/inventory}/inventory.ts +86 -8
  124. package/server/service/inventory-change/index.ts +6 -0
  125. package/server/{graphql/resolvers/inventory-change/approve-inventory-changes.ts → service/inventory-change/inventory-change-mutation.ts} +299 -11
  126. package/server/{graphql/resolvers/inventory-change/inventory-changes.ts → service/inventory-change/inventory-change-query.ts} +35 -4
  127. package/server/service/inventory-change/inventory-change-types.ts +36 -0
  128. package/server/{entities → service/inventory-change}/inventory-change.ts +55 -5
  129. package/server/service/inventory-history/index.ts +6 -0
  130. package/server/service/inventory-history/inventory-history-mutation.ts +119 -0
  131. package/server/service/inventory-history/inventory-history-query.ts +1435 -0
  132. package/server/service/inventory-history/inventory-history-types.ts +269 -0
  133. package/server/{entities → service/inventory-history}/inventory-history.ts +65 -10
  134. package/server/service/location/index.ts +6 -0
  135. package/server/service/location/location-mutation.ts +134 -0
  136. package/server/service/location/location-query.ts +206 -0
  137. package/server/service/location/location-types.ts +151 -0
  138. package/server/{entities → service/location}/location.ts +40 -3
  139. package/server/service/movement/index.ts +6 -0
  140. package/server/service/movement/movement-mutation.ts +61 -0
  141. package/server/service/movement/movement-query.ts +258 -0
  142. package/server/service/movement/movement-types.ts +74 -0
  143. package/server/{entities → service/movement}/movement.ts +35 -2
  144. package/server/service/pallet/index.ts +6 -0
  145. package/server/service/pallet/pallet-mutation.ts +244 -0
  146. package/server/service/pallet/pallet-query.ts +105 -0
  147. package/server/service/pallet/pallet-types.ts +68 -0
  148. package/server/{entities → service/pallet}/pallet.ts +31 -4
  149. package/server/service/pallet-count/index.ts +6 -0
  150. package/server/service/pallet-count/pallet-count-mutation.ts +148 -0
  151. package/server/service/pallet-count/pallet-count-query.ts +46 -0
  152. package/server/service/pallet-count/pallet-count-types.ts +36 -0
  153. package/server/service/pallet-count/pallet-count.ts +70 -0
  154. package/server/service/pallet-history/index.ts +6 -0
  155. package/server/service/pallet-history/pallet-history-mutation.ts +114 -0
  156. package/server/service/pallet-history/pallet-history-query.ts +46 -0
  157. package/server/service/pallet-history/pallet-history-types.ts +36 -0
  158. package/server/{entities → service/pallet-history}/pallet-history.ts +34 -12
  159. package/server/service/reduced-inventory-history/index.ts +3 -0
  160. package/server/{entities → service/reduced-inventory-history}/reduced-inventory-history.ts +7 -12
  161. package/server/service/warehouse/index.ts +6 -0
  162. package/server/service/warehouse/warehouse-mutation.ts +114 -0
  163. package/server/service/warehouse/warehouse-query.ts +51 -0
  164. package/server/service/warehouse/warehouse-types.ts +50 -0
  165. package/server/{entities → service/warehouse}/warehouse.ts +29 -4
  166. package/server/utils/inventory-util.ts +58 -4
  167. package/dist-server/entities/index.js +0 -36
  168. package/dist-server/entities/index.js.map +0 -1
  169. package/dist-server/entities/inventory-change.js.map +0 -1
  170. package/dist-server/entities/inventory-history.js.map +0 -1
  171. package/dist-server/entities/inventory.js.map +0 -1
  172. package/dist-server/entities/location.js.map +0 -1
  173. package/dist-server/entities/movement.js.map +0 -1
  174. package/dist-server/entities/pallet-count.js.map +0 -1
  175. package/dist-server/entities/pallet-history.js.map +0 -1
  176. package/dist-server/entities/pallet.js.map +0 -1
  177. package/dist-server/entities/reduced-inventory-history.js.map +0 -1
  178. package/dist-server/entities/warehouse.js.map +0 -1
  179. package/dist-server/graphql/index.js +0 -29
  180. package/dist-server/graphql/index.js.map +0 -1
  181. package/dist-server/graphql/resolvers/index.js +0 -54
  182. package/dist-server/graphql/resolvers/index.js.map +0 -1
  183. package/dist-server/graphql/resolvers/inventory/check-carton-identicality.js +0 -32
  184. package/dist-server/graphql/resolvers/inventory/check-carton-identicality.js.map +0 -1
  185. package/dist-server/graphql/resolvers/inventory/check-inventory-owner.js +0 -25
  186. package/dist-server/graphql/resolvers/inventory/check-inventory-owner.js.map +0 -1
  187. package/dist-server/graphql/resolvers/inventory/check-product-identicality.js +0 -24
  188. package/dist-server/graphql/resolvers/inventory/check-product-identicality.js.map +0 -1
  189. package/dist-server/graphql/resolvers/inventory/create-inventory.js +0 -11
  190. package/dist-server/graphql/resolvers/inventory/create-inventory.js.map +0 -1
  191. package/dist-server/graphql/resolvers/inventory/delete-inventories.js +0 -15
  192. package/dist-server/graphql/resolvers/inventory/delete-inventories.js.map +0 -1
  193. package/dist-server/graphql/resolvers/inventory/delete-inventory.js +0 -11
  194. package/dist-server/graphql/resolvers/inventory/delete-inventory.js.map +0 -1
  195. package/dist-server/graphql/resolvers/inventory/index.js +0 -22
  196. package/dist-server/graphql/resolvers/inventory/index.js.map +0 -1
  197. package/dist-server/graphql/resolvers/inventory/inventories-by-bundle.js +0 -131
  198. package/dist-server/graphql/resolvers/inventory/inventories-by-bundle.js.map +0 -1
  199. package/dist-server/graphql/resolvers/inventory/inventories-by-product.js +0 -146
  200. package/dist-server/graphql/resolvers/inventory/inventories-by-product.js.map +0 -1
  201. package/dist-server/graphql/resolvers/inventory/inventories-by-strategy.js +0 -115
  202. package/dist-server/graphql/resolvers/inventory/inventories-by-strategy.js.map +0 -1
  203. package/dist-server/graphql/resolvers/inventory/inventories.js +0 -93
  204. package/dist-server/graphql/resolvers/inventory/inventories.js.map +0 -1
  205. package/dist-server/graphql/resolvers/inventory/inventory-by-pallet.js +0 -16
  206. package/dist-server/graphql/resolvers/inventory/inventory-by-pallet.js.map +0 -1
  207. package/dist-server/graphql/resolvers/inventory/inventory-transfer.js +0 -46
  208. package/dist-server/graphql/resolvers/inventory/inventory-transfer.js.map +0 -1
  209. package/dist-server/graphql/resolvers/inventory/inventory.js +0 -15
  210. package/dist-server/graphql/resolvers/inventory/inventory.js.map +0 -1
  211. package/dist-server/graphql/resolvers/inventory/update-inventory-remark.js +0 -13
  212. package/dist-server/graphql/resolvers/inventory/update-inventory-remark.js.map +0 -1
  213. package/dist-server/graphql/resolvers/inventory/update-inventory.js +0 -25
  214. package/dist-server/graphql/resolvers/inventory/update-inventory.js.map +0 -1
  215. package/dist-server/graphql/resolvers/inventory/update-multiple-inventory.js +0 -152
  216. package/dist-server/graphql/resolvers/inventory/update-multiple-inventory.js.map +0 -1
  217. package/dist-server/graphql/resolvers/inventory-change/approve-inventory-changes.js +0 -271
  218. package/dist-server/graphql/resolvers/inventory-change/approve-inventory-changes.js.map +0 -1
  219. package/dist-server/graphql/resolvers/inventory-change/create-inventory-change.js +0 -11
  220. package/dist-server/graphql/resolvers/inventory-change/create-inventory-change.js.map +0 -1
  221. package/dist-server/graphql/resolvers/inventory-change/delete-inventory-change.js +0 -12
  222. package/dist-server/graphql/resolvers/inventory-change/delete-inventory-change.js.map +0 -1
  223. package/dist-server/graphql/resolvers/inventory-change/delete-inventory-changes.js +0 -16
  224. package/dist-server/graphql/resolvers/inventory-change/delete-inventory-changes.js.map +0 -1
  225. package/dist-server/graphql/resolvers/inventory-change/index.js +0 -16
  226. package/dist-server/graphql/resolvers/inventory-change/index.js.map +0 -1
  227. package/dist-server/graphql/resolvers/inventory-change/inventory-change.js +0 -15
  228. package/dist-server/graphql/resolvers/inventory-change/inventory-change.js.map +0 -1
  229. package/dist-server/graphql/resolvers/inventory-change/inventory-changes.js +0 -48
  230. package/dist-server/graphql/resolvers/inventory-change/inventory-changes.js.map +0 -1
  231. package/dist-server/graphql/resolvers/inventory-change/reject-inventory-changes.js +0 -41
  232. package/dist-server/graphql/resolvers/inventory-change/reject-inventory-changes.js.map +0 -1
  233. package/dist-server/graphql/resolvers/inventory-change/submit-inventory-changes.js +0 -69
  234. package/dist-server/graphql/resolvers/inventory-change/submit-inventory-changes.js.map +0 -1
  235. package/dist-server/graphql/resolvers/inventory-change/update-inventory-change.js +0 -15
  236. package/dist-server/graphql/resolvers/inventory-change/update-inventory-change.js.map +0 -1
  237. package/dist-server/graphql/resolvers/inventory-change/update-multiple-inventory-change.js +0 -30
  238. package/dist-server/graphql/resolvers/inventory-change/update-multiple-inventory-change.js.map +0 -1
  239. package/dist-server/graphql/resolvers/inventory-history/bizplace-inventory-histories.js +0 -58
  240. package/dist-server/graphql/resolvers/inventory-history/bizplace-inventory-histories.js.map +0 -1
  241. package/dist-server/graphql/resolvers/inventory-history/create-inventory-history.js +0 -11
  242. package/dist-server/graphql/resolvers/inventory-history/create-inventory-history.js.map +0 -1
  243. package/dist-server/graphql/resolvers/inventory-history/delete-inventory-histories.js +0 -16
  244. package/dist-server/graphql/resolvers/inventory-history/delete-inventory-histories.js.map +0 -1
  245. package/dist-server/graphql/resolvers/inventory-history/delete-inventory-history.js +0 -12
  246. package/dist-server/graphql/resolvers/inventory-history/delete-inventory-history.js.map +0 -1
  247. package/dist-server/graphql/resolvers/inventory-history/index.js +0 -20
  248. package/dist-server/graphql/resolvers/inventory-history/index.js.map +0 -1
  249. package/dist-server/graphql/resolvers/inventory-history/inventory-histories.js +0 -48
  250. package/dist-server/graphql/resolvers/inventory-history/inventory-histories.js.map +0 -1
  251. package/dist-server/graphql/resolvers/inventory-history/inventory-history-pallet-detail-report.js +0 -158
  252. package/dist-server/graphql/resolvers/inventory-history/inventory-history-pallet-detail-report.js.map +0 -1
  253. package/dist-server/graphql/resolvers/inventory-history/inventory-history-pallet-report.js +0 -125
  254. package/dist-server/graphql/resolvers/inventory-history/inventory-history-pallet-report.js.map +0 -1
  255. package/dist-server/graphql/resolvers/inventory-history/inventory-history-pallet-storage-report.js +0 -113
  256. package/dist-server/graphql/resolvers/inventory-history/inventory-history-pallet-storage-report.js.map +0 -1
  257. package/dist-server/graphql/resolvers/inventory-history/inventory-history-report.js +0 -207
  258. package/dist-server/graphql/resolvers/inventory-history/inventory-history-report.js.map +0 -1
  259. package/dist-server/graphql/resolvers/inventory-history/inventory-history-summary-report.js +0 -259
  260. package/dist-server/graphql/resolvers/inventory-history/inventory-history-summary-report.js.map +0 -1
  261. package/dist-server/graphql/resolvers/inventory-history/inventory-history.js +0 -14
  262. package/dist-server/graphql/resolvers/inventory-history/inventory-history.js.map +0 -1
  263. package/dist-server/graphql/resolvers/inventory-history/onhand-inventories.js +0 -195
  264. package/dist-server/graphql/resolvers/inventory-history/onhand-inventories.js.map +0 -1
  265. package/dist-server/graphql/resolvers/inventory-history/update-inventory-history.js +0 -15
  266. package/dist-server/graphql/resolvers/inventory-history/update-inventory-history.js.map +0 -1
  267. package/dist-server/graphql/resolvers/inventory-history/update-multiple-inventory-history.js +0 -31
  268. package/dist-server/graphql/resolvers/inventory-history/update-multiple-inventory-history.js.map +0 -1
  269. package/dist-server/graphql/resolvers/location/create-location.js +0 -17
  270. package/dist-server/graphql/resolvers/location/create-location.js.map +0 -1
  271. package/dist-server/graphql/resolvers/location/delete-all-locations.js +0 -13
  272. package/dist-server/graphql/resolvers/location/delete-all-locations.js.map +0 -1
  273. package/dist-server/graphql/resolvers/location/delete-location.js +0 -17
  274. package/dist-server/graphql/resolvers/location/delete-location.js.map +0 -1
  275. package/dist-server/graphql/resolvers/location/delete-locations.js +0 -17
  276. package/dist-server/graphql/resolvers/location/delete-locations.js.map +0 -1
  277. package/dist-server/graphql/resolvers/location/index.js +0 -22
  278. package/dist-server/graphql/resolvers/location/index.js.map +0 -1
  279. package/dist-server/graphql/resolvers/location/location-by-name.js +0 -18
  280. package/dist-server/graphql/resolvers/location/location-by-name.js.map +0 -1
  281. package/dist-server/graphql/resolvers/location/location-occupancies.js +0 -42
  282. package/dist-server/graphql/resolvers/location/location-occupancies.js.map +0 -1
  283. package/dist-server/graphql/resolvers/location/location-with-inventories.js +0 -75
  284. package/dist-server/graphql/resolvers/location/location-with-inventories.js.map +0 -1
  285. package/dist-server/graphql/resolvers/location/location.js +0 -13
  286. package/dist-server/graphql/resolvers/location/location.js.map +0 -1
  287. package/dist-server/graphql/resolvers/location/locations-by-group.js +0 -27
  288. package/dist-server/graphql/resolvers/location/locations-by-group.js.map +0 -1
  289. package/dist-server/graphql/resolvers/location/locations.js +0 -20
  290. package/dist-server/graphql/resolvers/location/locations.js.map +0 -1
  291. package/dist-server/graphql/resolvers/location/update-location.js +0 -21
  292. package/dist-server/graphql/resolvers/location/update-location.js.map +0 -1
  293. package/dist-server/graphql/resolvers/location/update-multiple-location.js +0 -28
  294. package/dist-server/graphql/resolvers/location/update-multiple-location.js.map +0 -1
  295. package/dist-server/graphql/resolvers/movement/create-movement.js +0 -11
  296. package/dist-server/graphql/resolvers/movement/create-movement.js.map +0 -1
  297. package/dist-server/graphql/resolvers/movement/delete-movement.js +0 -12
  298. package/dist-server/graphql/resolvers/movement/delete-movement.js.map +0 -1
  299. package/dist-server/graphql/resolvers/movement/inbound-movements-counter.js +0 -61
  300. package/dist-server/graphql/resolvers/movement/inbound-movements-counter.js.map +0 -1
  301. package/dist-server/graphql/resolvers/movement/index.js +0 -14
  302. package/dist-server/graphql/resolvers/movement/index.js.map +0 -1
  303. package/dist-server/graphql/resolvers/movement/movement.js +0 -19
  304. package/dist-server/graphql/resolvers/movement/movement.js.map +0 -1
  305. package/dist-server/graphql/resolvers/movement/movements.js +0 -16
  306. package/dist-server/graphql/resolvers/movement/movements.js.map +0 -1
  307. package/dist-server/graphql/resolvers/movement/outbound-movements-counter.js +0 -63
  308. package/dist-server/graphql/resolvers/movement/outbound-movements-counter.js.map +0 -1
  309. package/dist-server/graphql/resolvers/movement/update-movement.js +0 -22
  310. package/dist-server/graphql/resolvers/movement/update-movement.js.map +0 -1
  311. package/dist-server/graphql/resolvers/movement/weekly-movements-counter.js +0 -91
  312. package/dist-server/graphql/resolvers/movement/weekly-movements-counter.js.map +0 -1
  313. package/dist-server/graphql/resolvers/pallet/create-pallet.js +0 -11
  314. package/dist-server/graphql/resolvers/pallet/create-pallet.js.map +0 -1
  315. package/dist-server/graphql/resolvers/pallet/delete-pallet.js +0 -12
  316. package/dist-server/graphql/resolvers/pallet/delete-pallet.js.map +0 -1
  317. package/dist-server/graphql/resolvers/pallet/delete-pallets.js +0 -35
  318. package/dist-server/graphql/resolvers/pallet/delete-pallets.js.map +0 -1
  319. package/dist-server/graphql/resolvers/pallet/index.js +0 -17
  320. package/dist-server/graphql/resolvers/pallet/index.js.map +0 -1
  321. package/dist-server/graphql/resolvers/pallet/pallet-by-status.js +0 -16
  322. package/dist-server/graphql/resolvers/pallet/pallet-by-status.js.map +0 -1
  323. package/dist-server/graphql/resolvers/pallet/pallet-inbound-validate.js +0 -26
  324. package/dist-server/graphql/resolvers/pallet/pallet-inbound-validate.js.map +0 -1
  325. package/dist-server/graphql/resolvers/pallet/pallet-outbound-validate.js +0 -26
  326. package/dist-server/graphql/resolvers/pallet/pallet-outbound-validate.js.map +0 -1
  327. package/dist-server/graphql/resolvers/pallet/pallet-return.js +0 -31
  328. package/dist-server/graphql/resolvers/pallet/pallet-return.js.map +0 -1
  329. package/dist-server/graphql/resolvers/pallet/pallet.js +0 -16
  330. package/dist-server/graphql/resolvers/pallet/pallet.js.map +0 -1
  331. package/dist-server/graphql/resolvers/pallet/pallets.js +0 -21
  332. package/dist-server/graphql/resolvers/pallet/pallets.js.map +0 -1
  333. package/dist-server/graphql/resolvers/pallet/update-multiple-pallet.js +0 -50
  334. package/dist-server/graphql/resolvers/pallet/update-multiple-pallet.js.map +0 -1
  335. package/dist-server/graphql/resolvers/pallet/update-pallet.js +0 -15
  336. package/dist-server/graphql/resolvers/pallet/update-pallet.js.map +0 -1
  337. package/dist-server/graphql/resolvers/pallet-count/create-pallet-count.js +0 -11
  338. package/dist-server/graphql/resolvers/pallet-count/create-pallet-count.js.map +0 -1
  339. package/dist-server/graphql/resolvers/pallet-count/delete-pallet-count.js +0 -12
  340. package/dist-server/graphql/resolvers/pallet-count/delete-pallet-count.js.map +0 -1
  341. package/dist-server/graphql/resolvers/pallet-count/delete-pallet-counts.js +0 -16
  342. package/dist-server/graphql/resolvers/pallet-count/delete-pallet-counts.js.map +0 -1
  343. package/dist-server/graphql/resolvers/pallet-count/index.js +0 -14
  344. package/dist-server/graphql/resolvers/pallet-count/index.js.map +0 -1
  345. package/dist-server/graphql/resolvers/pallet-count/pallet-count.js +0 -15
  346. package/dist-server/graphql/resolvers/pallet-count/pallet-count.js.map +0 -1
  347. package/dist-server/graphql/resolvers/pallet-count/pallet-counts.js +0 -14
  348. package/dist-server/graphql/resolvers/pallet-count/pallet-counts.js.map +0 -1
  349. package/dist-server/graphql/resolvers/pallet-count/update-multiple-pallet-count.js +0 -30
  350. package/dist-server/graphql/resolvers/pallet-count/update-multiple-pallet-count.js.map +0 -1
  351. package/dist-server/graphql/resolvers/pallet-count/update-pallet-count-seq.js +0 -38
  352. package/dist-server/graphql/resolvers/pallet-count/update-pallet-count-seq.js.map +0 -1
  353. package/dist-server/graphql/resolvers/pallet-count/update-pallet-count.js +0 -15
  354. package/dist-server/graphql/resolvers/pallet-count/update-pallet-count.js.map +0 -1
  355. package/dist-server/graphql/resolvers/pallet-history/create-pallet-history.js +0 -11
  356. package/dist-server/graphql/resolvers/pallet-history/create-pallet-history.js.map +0 -1
  357. package/dist-server/graphql/resolvers/pallet-history/delete-pallet-histories.js +0 -16
  358. package/dist-server/graphql/resolvers/pallet-history/delete-pallet-histories.js.map +0 -1
  359. package/dist-server/graphql/resolvers/pallet-history/delete-pallet-history.js +0 -12
  360. package/dist-server/graphql/resolvers/pallet-history/delete-pallet-history.js.map +0 -1
  361. package/dist-server/graphql/resolvers/pallet-history/index.js +0 -13
  362. package/dist-server/graphql/resolvers/pallet-history/index.js.map +0 -1
  363. package/dist-server/graphql/resolvers/pallet-history/pallet-histories.js +0 -14
  364. package/dist-server/graphql/resolvers/pallet-history/pallet-histories.js.map +0 -1
  365. package/dist-server/graphql/resolvers/pallet-history/pallet-history.js +0 -15
  366. package/dist-server/graphql/resolvers/pallet-history/pallet-history.js.map +0 -1
  367. package/dist-server/graphql/resolvers/pallet-history/update-multiple-pallet-history.js +0 -30
  368. package/dist-server/graphql/resolvers/pallet-history/update-multiple-pallet-history.js.map +0 -1
  369. package/dist-server/graphql/resolvers/pallet-history/update-pallet-history.js +0 -15
  370. package/dist-server/graphql/resolvers/pallet-history/update-pallet-history.js.map +0 -1
  371. package/dist-server/graphql/resolvers/warehouse/create-warehouse.js +0 -16
  372. package/dist-server/graphql/resolvers/warehouse/create-warehouse.js.map +0 -1
  373. package/dist-server/graphql/resolvers/warehouse/delete-warehouse.js +0 -17
  374. package/dist-server/graphql/resolvers/warehouse/delete-warehouse.js.map +0 -1
  375. package/dist-server/graphql/resolvers/warehouse/delete-warehouses.js +0 -17
  376. package/dist-server/graphql/resolvers/warehouse/delete-warehouses.js.map +0 -1
  377. package/dist-server/graphql/resolvers/warehouse/index.js +0 -17
  378. package/dist-server/graphql/resolvers/warehouse/index.js.map +0 -1
  379. package/dist-server/graphql/resolvers/warehouse/update-multiple-warehouse.js +0 -28
  380. package/dist-server/graphql/resolvers/warehouse/update-multiple-warehouse.js.map +0 -1
  381. package/dist-server/graphql/resolvers/warehouse/update-warehouse.js +0 -17
  382. package/dist-server/graphql/resolvers/warehouse/update-warehouse.js.map +0 -1
  383. package/dist-server/graphql/resolvers/warehouse/warehouse.js +0 -18
  384. package/dist-server/graphql/resolvers/warehouse/warehouse.js.map +0 -1
  385. package/dist-server/graphql/resolvers/warehouse/warehouses.js +0 -15
  386. package/dist-server/graphql/resolvers/warehouse/warehouses.js.map +0 -1
  387. package/dist-server/graphql/types/index.js +0 -65
  388. package/dist-server/graphql/types/index.js.map +0 -1
  389. package/dist-server/graphql/types/inventory/index.js +0 -62
  390. package/dist-server/graphql/types/inventory/index.js.map +0 -1
  391. package/dist-server/graphql/types/inventory/inventory-bundle-group-detail.js +0 -14
  392. package/dist-server/graphql/types/inventory/inventory-bundle-group-detail.js.map +0 -1
  393. package/dist-server/graphql/types/inventory/inventory-bundle-group.js +0 -39
  394. package/dist-server/graphql/types/inventory/inventory-bundle-group.js.map +0 -1
  395. package/dist-server/graphql/types/inventory/inventory-list.js +0 -14
  396. package/dist-server/graphql/types/inventory/inventory-list.js.map +0 -1
  397. package/dist-server/graphql/types/inventory/inventory-patch.js +0 -47
  398. package/dist-server/graphql/types/inventory/inventory-patch.js.map +0 -1
  399. package/dist-server/graphql/types/inventory/inventory.js +0 -56
  400. package/dist-server/graphql/types/inventory/inventory.js.map +0 -1
  401. package/dist-server/graphql/types/inventory/new-inventory.js +0 -35
  402. package/dist-server/graphql/types/inventory/new-inventory.js.map +0 -1
  403. package/dist-server/graphql/types/inventory-change/index.js +0 -48
  404. package/dist-server/graphql/types/inventory-change/index.js.map +0 -1
  405. package/dist-server/graphql/types/inventory-change/inventory-change-list.js +0 -14
  406. package/dist-server/graphql/types/inventory-change/inventory-change-list.js.map +0 -1
  407. package/dist-server/graphql/types/inventory-change/inventory-change-patch.js +0 -16
  408. package/dist-server/graphql/types/inventory-change/inventory-change-patch.js.map +0 -1
  409. package/dist-server/graphql/types/inventory-change/inventory-change.js +0 -39
  410. package/dist-server/graphql/types/inventory-change/inventory-change.js.map +0 -1
  411. package/dist-server/graphql/types/inventory-change/new-inventory-change.js +0 -14
  412. package/dist-server/graphql/types/inventory-change/new-inventory-change.js.map +0 -1
  413. package/dist-server/graphql/types/inventory-history/index.js +0 -55
  414. package/dist-server/graphql/types/inventory-history/index.js.map +0 -1
  415. package/dist-server/graphql/types/inventory-history/inventory-history-list.js +0 -14
  416. package/dist-server/graphql/types/inventory-history/inventory-history-list.js.map +0 -1
  417. package/dist-server/graphql/types/inventory-history/inventory-history-pallet-report-list.js +0 -15
  418. package/dist-server/graphql/types/inventory-history/inventory-history-pallet-report-list.js.map +0 -1
  419. package/dist-server/graphql/types/inventory-history/inventory-history-pallet-report.js +0 -19
  420. package/dist-server/graphql/types/inventory-history/inventory-history-pallet-report.js.map +0 -1
  421. package/dist-server/graphql/types/inventory-history/inventory-history-patch.js +0 -43
  422. package/dist-server/graphql/types/inventory-history/inventory-history-patch.js.map +0 -1
  423. package/dist-server/graphql/types/inventory-history/inventory-history-summary-list.js +0 -16
  424. package/dist-server/graphql/types/inventory-history/inventory-history-summary-list.js.map +0 -1
  425. package/dist-server/graphql/types/inventory-history/inventory-history-summary.js +0 -23
  426. package/dist-server/graphql/types/inventory-history/inventory-history-summary.js.map +0 -1
  427. package/dist-server/graphql/types/inventory-history/inventory-history.js +0 -62
  428. package/dist-server/graphql/types/inventory-history/inventory-history.js.map +0 -1
  429. package/dist-server/graphql/types/inventory-history/new-inventory-history.js +0 -35
  430. package/dist-server/graphql/types/inventory-history/new-inventory-history.js.map +0 -1
  431. package/dist-server/graphql/types/location/index.js +0 -54
  432. package/dist-server/graphql/types/location/index.js.map +0 -1
  433. package/dist-server/graphql/types/location/location-inventories.js +0 -14
  434. package/dist-server/graphql/types/location/location-inventories.js.map +0 -1
  435. package/dist-server/graphql/types/location/location-inventory.js +0 -27
  436. package/dist-server/graphql/types/location/location-inventory.js.map +0 -1
  437. package/dist-server/graphql/types/location/location-list.js +0 -14
  438. package/dist-server/graphql/types/location/location-list.js.map +0 -1
  439. package/dist-server/graphql/types/location/location-occupancy.js +0 -16
  440. package/dist-server/graphql/types/location/location-occupancy.js.map +0 -1
  441. package/dist-server/graphql/types/location/location-patch.js +0 -23
  442. package/dist-server/graphql/types/location/location-patch.js.map +0 -1
  443. package/dist-server/graphql/types/location/location.js +0 -27
  444. package/dist-server/graphql/types/location/location.js.map +0 -1
  445. package/dist-server/graphql/types/location/new-location.js +0 -21
  446. package/dist-server/graphql/types/location/new-location.js.map +0 -1
  447. package/dist-server/graphql/types/movement/index.js +0 -31
  448. package/dist-server/graphql/types/movement/index.js.map +0 -1
  449. package/dist-server/graphql/types/movement/movement-count.js +0 -17
  450. package/dist-server/graphql/types/movement/movement-count.js.map +0 -1
  451. package/dist-server/graphql/types/movement/movement-list.js +0 -14
  452. package/dist-server/graphql/types/movement/movement-list.js.map +0 -1
  453. package/dist-server/graphql/types/movement/movement-patch.js +0 -18
  454. package/dist-server/graphql/types/movement/movement-patch.js.map +0 -1
  455. package/dist-server/graphql/types/movement/movement.js +0 -23
  456. package/dist-server/graphql/types/movement/movement.js.map +0 -1
  457. package/dist-server/graphql/types/movement/new-movement.js +0 -18
  458. package/dist-server/graphql/types/movement/new-movement.js.map +0 -1
  459. package/dist-server/graphql/types/pallet/index.js +0 -49
  460. package/dist-server/graphql/types/pallet/index.js.map +0 -1
  461. package/dist-server/graphql/types/pallet/new-pallet.js +0 -17
  462. package/dist-server/graphql/types/pallet/new-pallet.js.map +0 -1
  463. package/dist-server/graphql/types/pallet/pallet-list.js +0 -14
  464. package/dist-server/graphql/types/pallet/pallet-list.js.map +0 -1
  465. package/dist-server/graphql/types/pallet/pallet-patch.js +0 -20
  466. package/dist-server/graphql/types/pallet/pallet-patch.js.map +0 -1
  467. package/dist-server/graphql/types/pallet/pallet-validate.js +0 -14
  468. package/dist-server/graphql/types/pallet/pallet-validate.js.map +0 -1
  469. package/dist-server/graphql/types/pallet/pallet.js +0 -24
  470. package/dist-server/graphql/types/pallet/pallet.js.map +0 -1
  471. package/dist-server/graphql/types/pallet-count/index.js +0 -39
  472. package/dist-server/graphql/types/pallet-count/index.js.map +0 -1
  473. package/dist-server/graphql/types/pallet-count/new-pallet-count.js +0 -14
  474. package/dist-server/graphql/types/pallet-count/new-pallet-count.js.map +0 -1
  475. package/dist-server/graphql/types/pallet-count/pallet-count-list.js +0 -14
  476. package/dist-server/graphql/types/pallet-count/pallet-count-list.js.map +0 -1
  477. package/dist-server/graphql/types/pallet-count/pallet-count-patch.js +0 -16
  478. package/dist-server/graphql/types/pallet-count/pallet-count-patch.js.map +0 -1
  479. package/dist-server/graphql/types/pallet-count/pallet-count.js +0 -20
  480. package/dist-server/graphql/types/pallet-count/pallet-count.js.map +0 -1
  481. package/dist-server/graphql/types/pallet-history/index.js +0 -35
  482. package/dist-server/graphql/types/pallet-history/index.js.map +0 -1
  483. package/dist-server/graphql/types/pallet-history/new-pallet-history.js +0 -14
  484. package/dist-server/graphql/types/pallet-history/new-pallet-history.js.map +0 -1
  485. package/dist-server/graphql/types/pallet-history/pallet-history-list.js +0 -14
  486. package/dist-server/graphql/types/pallet-history/pallet-history-list.js.map +0 -1
  487. package/dist-server/graphql/types/pallet-history/pallet-history-patch.js +0 -16
  488. package/dist-server/graphql/types/pallet-history/pallet-history-patch.js.map +0 -1
  489. package/dist-server/graphql/types/pallet-history/pallet-history.js +0 -20
  490. package/dist-server/graphql/types/pallet-history/pallet-history.js.map +0 -1
  491. package/dist-server/graphql/types/warehouse/index.js +0 -35
  492. package/dist-server/graphql/types/warehouse/index.js.map +0 -1
  493. package/dist-server/graphql/types/warehouse/new-warehouse.js +0 -16
  494. package/dist-server/graphql/types/warehouse/new-warehouse.js.map +0 -1
  495. package/dist-server/graphql/types/warehouse/warehouse-list.js +0 -14
  496. package/dist-server/graphql/types/warehouse/warehouse-list.js.map +0 -1
  497. package/dist-server/graphql/types/warehouse/warehouse-patch.js +0 -18
  498. package/dist-server/graphql/types/warehouse/warehouse-patch.js.map +0 -1
  499. package/dist-server/graphql/types/warehouse/warehouse.js +0 -23
  500. package/dist-server/graphql/types/warehouse/warehouse.js.map +0 -1
  501. package/server/entities/index.ts +0 -36
  502. package/server/entities/pallet-count.ts +0 -40
  503. package/server/graphql/index.ts +0 -7
  504. package/server/graphql/resolvers/index.ts +0 -33
  505. package/server/graphql/resolvers/inventory/check-carton-identicality.ts +0 -32
  506. package/server/graphql/resolvers/inventory/check-inventory-owner.ts +0 -26
  507. package/server/graphql/resolvers/inventory/check-product-identicality.ts +0 -24
  508. package/server/graphql/resolvers/inventory/create-inventory.ts +0 -15
  509. package/server/graphql/resolvers/inventory/delete-inventories.ts +0 -14
  510. package/server/graphql/resolvers/inventory/delete-inventory.ts +0 -10
  511. package/server/graphql/resolvers/inventory/index.ts +0 -38
  512. package/server/graphql/resolvers/inventory/inventories-by-bundle.ts +0 -168
  513. package/server/graphql/resolvers/inventory/inventories-by-product.ts +0 -164
  514. package/server/graphql/resolvers/inventory/inventories-by-strategy.ts +0 -143
  515. package/server/graphql/resolvers/inventory/inventories.ts +0 -129
  516. package/server/graphql/resolvers/inventory/inventory-by-pallet.ts +0 -15
  517. package/server/graphql/resolvers/inventory/inventory-transfer.ts +0 -50
  518. package/server/graphql/resolvers/inventory/inventory.ts +0 -14
  519. package/server/graphql/resolvers/inventory/update-inventory-remark.ts +0 -19
  520. package/server/graphql/resolvers/inventory/update-inventory.ts +0 -31
  521. package/server/graphql/resolvers/inventory-change/create-inventory-change.ts +0 -17
  522. package/server/graphql/resolvers/inventory-change/delete-inventory-change.ts +0 -12
  523. package/server/graphql/resolvers/inventory-change/delete-inventory-changes.ts +0 -15
  524. package/server/graphql/resolvers/inventory-change/index.ts +0 -27
  525. package/server/graphql/resolvers/inventory-change/inventory-change.ts +0 -14
  526. package/server/graphql/resolvers/inventory-change/reject-inventory-changes.ts +0 -42
  527. package/server/graphql/resolvers/inventory-change/submit-inventory-changes.ts +0 -101
  528. package/server/graphql/resolvers/inventory-change/update-inventory-change.ts +0 -21
  529. package/server/graphql/resolvers/inventory-change/update-multiple-inventory-change.ts +0 -47
  530. package/server/graphql/resolvers/inventory-history/bizplace-inventory-histories.ts +0 -81
  531. package/server/graphql/resolvers/inventory-history/create-inventory-history.ts +0 -17
  532. package/server/graphql/resolvers/inventory-history/delete-inventory-histories.ts +0 -15
  533. package/server/graphql/resolvers/inventory-history/delete-inventory-history.ts +0 -12
  534. package/server/graphql/resolvers/inventory-history/index.ts +0 -34
  535. package/server/graphql/resolvers/inventory-history/inventory-histories.ts +0 -62
  536. package/server/graphql/resolvers/inventory-history/inventory-history-pallet-detail-report.ts +0 -166
  537. package/server/graphql/resolvers/inventory-history/inventory-history-pallet-report.ts +0 -133
  538. package/server/graphql/resolvers/inventory-history/inventory-history-pallet-storage-report.ts +0 -146
  539. package/server/graphql/resolvers/inventory-history/inventory-history-report.ts +0 -233
  540. package/server/graphql/resolvers/inventory-history/inventory-history-summary-report.ts +0 -317
  541. package/server/graphql/resolvers/inventory-history/inventory-history.ts +0 -13
  542. package/server/graphql/resolvers/inventory-history/onhand-inventories.ts +0 -233
  543. package/server/graphql/resolvers/inventory-history/update-inventory-history.ts +0 -21
  544. package/server/graphql/resolvers/inventory-history/update-multiple-inventory-history.ts +0 -48
  545. package/server/graphql/resolvers/location/create-location.ts +0 -25
  546. package/server/graphql/resolvers/location/delete-all-locations.ts +0 -12
  547. package/server/graphql/resolvers/location/delete-location.ts +0 -16
  548. package/server/graphql/resolvers/location/delete-locations.ts +0 -16
  549. package/server/graphql/resolvers/location/index.ts +0 -32
  550. package/server/graphql/resolvers/location/location-by-name.ts +0 -17
  551. package/server/graphql/resolvers/location/location-occupancies.ts +0 -45
  552. package/server/graphql/resolvers/location/location-with-inventories.ts +0 -87
  553. package/server/graphql/resolvers/location/location.ts +0 -10
  554. package/server/graphql/resolvers/location/locations-by-group.ts +0 -29
  555. package/server/graphql/resolvers/location/locations.ts +0 -18
  556. package/server/graphql/resolvers/location/update-location.ts +0 -27
  557. package/server/graphql/resolvers/location/update-multiple-location.ts +0 -29
  558. package/server/graphql/resolvers/movement/create-movement.ts +0 -13
  559. package/server/graphql/resolvers/movement/delete-movement.ts +0 -9
  560. package/server/graphql/resolvers/movement/inbound-movements-counter.ts +0 -68
  561. package/server/graphql/resolvers/movement/index.ts +0 -23
  562. package/server/graphql/resolvers/movement/movement.ts +0 -16
  563. package/server/graphql/resolvers/movement/movements.ts +0 -17
  564. package/server/graphql/resolvers/movement/outbound-movements-counter.ts +0 -70
  565. package/server/graphql/resolvers/movement/update-movement.ts +0 -25
  566. package/server/graphql/resolvers/movement/weekly-movements-counter.ts +0 -94
  567. package/server/graphql/resolvers/pallet/create-pallet.ts +0 -18
  568. package/server/graphql/resolvers/pallet/delete-pallet.ts +0 -13
  569. package/server/graphql/resolvers/pallet/delete-pallets.ts +0 -44
  570. package/server/graphql/resolvers/pallet/index.ts +0 -29
  571. package/server/graphql/resolvers/pallet/pallet-by-status.ts +0 -16
  572. package/server/graphql/resolvers/pallet/pallet-inbound-validate.ts +0 -21
  573. package/server/graphql/resolvers/pallet/pallet-outbound-validate.ts +0 -21
  574. package/server/graphql/resolvers/pallet/pallet-return.ts +0 -57
  575. package/server/graphql/resolvers/pallet/pallet.ts +0 -15
  576. package/server/graphql/resolvers/pallet/pallets.ts +0 -22
  577. package/server/graphql/resolvers/pallet/update-multiple-pallet.ts +0 -95
  578. package/server/graphql/resolvers/pallet/update-pallet.ts +0 -21
  579. package/server/graphql/resolvers/pallet-count/create-pallet-count.ts +0 -17
  580. package/server/graphql/resolvers/pallet-count/delete-pallet-count.ts +0 -12
  581. package/server/graphql/resolvers/pallet-count/delete-pallet-counts.ts +0 -15
  582. package/server/graphql/resolvers/pallet-count/index.ts +0 -23
  583. package/server/graphql/resolvers/pallet-count/pallet-count.ts +0 -14
  584. package/server/graphql/resolvers/pallet-count/pallet-counts.ts +0 -14
  585. package/server/graphql/resolvers/pallet-count/update-multiple-pallet-count.ts +0 -47
  586. package/server/graphql/resolvers/pallet-count/update-pallet-count-seq.ts +0 -44
  587. package/server/graphql/resolvers/pallet-count/update-pallet-count.ts +0 -21
  588. package/server/graphql/resolvers/pallet-history/create-pallet-history.ts +0 -17
  589. package/server/graphql/resolvers/pallet-history/delete-pallet-histories.ts +0 -16
  590. package/server/graphql/resolvers/pallet-history/delete-pallet-history.ts +0 -13
  591. package/server/graphql/resolvers/pallet-history/index.ts +0 -21
  592. package/server/graphql/resolvers/pallet-history/pallet-histories.ts +0 -14
  593. package/server/graphql/resolvers/pallet-history/pallet-history.ts +0 -14
  594. package/server/graphql/resolvers/pallet-history/update-multiple-pallet-history.ts +0 -46
  595. package/server/graphql/resolvers/pallet-history/update-pallet-history.ts +0 -21
  596. package/server/graphql/resolvers/warehouse/create-warehouse.ts +0 -22
  597. package/server/graphql/resolvers/warehouse/delete-warehouse.ts +0 -16
  598. package/server/graphql/resolvers/warehouse/delete-warehouses.ts +0 -16
  599. package/server/graphql/resolvers/warehouse/index.ts +0 -22
  600. package/server/graphql/resolvers/warehouse/update-multiple-warehouse.ts +0 -29
  601. package/server/graphql/resolvers/warehouse/update-warehouse.ts +0 -23
  602. package/server/graphql/resolvers/warehouse/warehouse.ts +0 -17
  603. package/server/graphql/resolvers/warehouse/warehouses.ts +0 -16
  604. package/server/graphql/types/index.ts +0 -45
  605. package/server/graphql/types/inventory/index.ts +0 -61
  606. package/server/graphql/types/inventory/inventory-bundle-group-detail.ts +0 -8
  607. package/server/graphql/types/inventory/inventory-bundle-group.ts +0 -33
  608. package/server/graphql/types/inventory/inventory-list.ts +0 -8
  609. package/server/graphql/types/inventory/inventory-patch.ts +0 -41
  610. package/server/graphql/types/inventory/inventory.ts +0 -50
  611. package/server/graphql/types/inventory/new-inventory.ts +0 -29
  612. package/server/graphql/types/inventory-change/index.ts +0 -47
  613. package/server/graphql/types/inventory-change/inventory-change-list.ts +0 -8
  614. package/server/graphql/types/inventory-change/inventory-change-patch.ts +0 -10
  615. package/server/graphql/types/inventory-change/inventory-change.ts +0 -33
  616. package/server/graphql/types/inventory-change/new-inventory-change.ts +0 -8
  617. package/server/graphql/types/inventory-history/index.ts +0 -54
  618. package/server/graphql/types/inventory-history/inventory-history-list.ts +0 -8
  619. package/server/graphql/types/inventory-history/inventory-history-pallet-report-list.ts +0 -9
  620. package/server/graphql/types/inventory-history/inventory-history-pallet-report.ts +0 -13
  621. package/server/graphql/types/inventory-history/inventory-history-patch.ts +0 -37
  622. package/server/graphql/types/inventory-history/inventory-history-summary-list.ts +0 -10
  623. package/server/graphql/types/inventory-history/inventory-history-summary.ts +0 -17
  624. package/server/graphql/types/inventory-history/inventory-history.ts +0 -56
  625. package/server/graphql/types/inventory-history/new-inventory-history.ts +0 -29
  626. package/server/graphql/types/location/index.ts +0 -53
  627. package/server/graphql/types/location/location-inventories.ts +0 -8
  628. package/server/graphql/types/location/location-inventory.ts +0 -21
  629. package/server/graphql/types/location/location-list.ts +0 -8
  630. package/server/graphql/types/location/location-occupancy.ts +0 -10
  631. package/server/graphql/types/location/location-patch.ts +0 -17
  632. package/server/graphql/types/location/location.ts +0 -21
  633. package/server/graphql/types/location/new-location.ts +0 -15
  634. package/server/graphql/types/movement/index.ts +0 -31
  635. package/server/graphql/types/movement/movement-count.ts +0 -11
  636. package/server/graphql/types/movement/movement-list.ts +0 -8
  637. package/server/graphql/types/movement/movement-patch.ts +0 -12
  638. package/server/graphql/types/movement/movement.ts +0 -17
  639. package/server/graphql/types/movement/new-movement.ts +0 -12
  640. package/server/graphql/types/pallet/index.ts +0 -48
  641. package/server/graphql/types/pallet/new-pallet.ts +0 -11
  642. package/server/graphql/types/pallet/pallet-list.ts +0 -8
  643. package/server/graphql/types/pallet/pallet-patch.ts +0 -14
  644. package/server/graphql/types/pallet/pallet-validate.ts +0 -8
  645. package/server/graphql/types/pallet/pallet.ts +0 -18
  646. package/server/graphql/types/pallet-count/index.ts +0 -38
  647. package/server/graphql/types/pallet-count/new-pallet-count.ts +0 -8
  648. package/server/graphql/types/pallet-count/pallet-count-list.ts +0 -8
  649. package/server/graphql/types/pallet-count/pallet-count-patch.ts +0 -10
  650. package/server/graphql/types/pallet-count/pallet-count.ts +0 -14
  651. package/server/graphql/types/pallet-history/index.ts +0 -34
  652. package/server/graphql/types/pallet-history/new-pallet-history.ts +0 -8
  653. package/server/graphql/types/pallet-history/pallet-history-list.ts +0 -8
  654. package/server/graphql/types/pallet-history/pallet-history-patch.ts +0 -10
  655. package/server/graphql/types/pallet-history/pallet-history.ts +0 -14
  656. package/server/graphql/types/warehouse/index.ts +0 -35
  657. package/server/graphql/types/warehouse/new-warehouse.ts +0 -10
  658. package/server/graphql/types/warehouse/warehouse-list.ts +0 -8
  659. package/server/graphql/types/warehouse/warehouse-patch.ts +0 -12
  660. package/server/graphql/types/warehouse/warehouse.ts +0 -17
@@ -0,0 +1,1283 @@
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, _d, _e, _f, _g, _h;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.InventoryHistoryQuery = 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 shell_1 = require("@things-factory/shell");
23
+ const inventory_types_1 = require("../inventory/inventory-types");
24
+ const location_1 = require("../location/location");
25
+ const warehouse_1 = require("../warehouse/warehouse");
26
+ const inventory_history_1 = require("./inventory-history");
27
+ const inventory_history_types_1 = require("./inventory-history-types");
28
+ let InventoryHistoryQuery = class InventoryHistoryQuery {
29
+ async inventoryHistories(params, context) {
30
+ const { domain, user } = context.state;
31
+ if (!params.filters.find((filter) => filter.name === 'bizplace')) {
32
+ params.filters.push({
33
+ name: 'bizplace',
34
+ operator: 'in',
35
+ value: await (0, biz_base_1.getPermittedBizplaceIds)(domain, user)
36
+ });
37
+ }
38
+ const convertedParams = (0, shell_1.convertListParams)(params);
39
+ let [items, total] = await (0, typeorm_1.getRepository)(inventory_history_1.InventoryHistory).findAndCount(Object.assign(Object.assign({}, convertedParams), { relations: ['domain', 'bizplace', 'product', 'location', 'warehouse', 'creator', 'updater'], order: {
40
+ palletId: 'DESC',
41
+ createdAt: 'ASC'
42
+ } }));
43
+ items = (await Promise.all(items.map(async (item) => {
44
+ switch (item.transactionType) {
45
+ case 'UNLOADING':
46
+ item.description = 'Inbound';
47
+ break;
48
+ case 'UNDO_UNLOADING':
49
+ item.description = 'Undo Unloading';
50
+ item.orderRefNo = '';
51
+ break;
52
+ case 'LOADING':
53
+ item.description = 'Loading';
54
+ break;
55
+ case 'UNDO_LOADING':
56
+ item.description = 'Undo Loading';
57
+ break;
58
+ default:
59
+ item.description = String(item.transactionType);
60
+ break;
61
+ }
62
+ item.description = item.description.toUpperCase();
63
+ return Object.assign(Object.assign({}, item), { orderRefNo: item.orderRefNo, orderNo: item.orderNo, qty: item.qty, openingQty: item.openingQty });
64
+ })));
65
+ return { items, total };
66
+ }
67
+ async inventoryHistory(name, context) {
68
+ const { domain } = context.state;
69
+ return await (0, typeorm_1.getRepository)(inventory_history_1.InventoryHistory).findOne({
70
+ where: { domain: domain, name, relations: ['domain', 'creator', 'updater'] }
71
+ });
72
+ }
73
+ async bizplaceInventoryHistories(context, inventoryHistory, filters, pagination, sortings) {
74
+ const { domain, user, tx } = context.state;
75
+ const ownerBizplace = await (0, biz_base_1.getMyBizplace)(domain, user);
76
+ const customerBizplace = await tx.getRepository(biz_base_1.Bizplace).findOne(inventoryHistory.bizplace.id);
77
+ const productFilters = filters.find(x => x.name == 'product_info');
78
+ filters = filters.filter(x => x.name != 'product_info');
79
+ const fromDate = new Date(inventoryHistory.fromDate);
80
+ const toDate = new Date(inventoryHistory.toDate);
81
+ const convertedParams = (0, shell_1.convertListParams)({ filters, pagination, sortings });
82
+ let where = { domain: domain };
83
+ if (productFilters) {
84
+ let productFilterValue = `%${productFilters.value.toLowerCase()}%`;
85
+ const productQb = (0, typeorm_1.getRepository)(product_base_1.Product).createQueryBuilder('prd');
86
+ productQb.where(new typeorm_1.Brackets(qb => {
87
+ qb.where('Lower(prd.sku) LIKE :productInfo', { productInfo: productFilterValue })
88
+ .orWhere('Lower(prd.name) LIKE :productInfo', { productInfo: productFilterValue })
89
+ .orWhere('Lower(prd.description) LIKE :productInfo', { productInfo: productFilterValue });
90
+ }));
91
+ const _products = await productQb.getMany();
92
+ where['product'] = (0, typeorm_1.In)(_products.map((product) => product.id));
93
+ }
94
+ if (inventoryHistory && inventoryHistory.warehouseName) {
95
+ const _warehouses = await tx.getRepository(warehouse_1.Warehouse).find({
96
+ domain: domain,
97
+ name: (0, typeorm_1.Raw)(alias => `LOWER(${alias}) LIKE '${inventoryHistory.warehouseName.toLowerCase()}'`)
98
+ });
99
+ where['warehouse'] = (0, typeorm_1.In)(_warehouses.map((warehouse) => warehouse.id));
100
+ }
101
+ if (inventoryHistory && inventoryHistory.locationName) {
102
+ const _locations = await tx.getRepository(location_1.Location).find({
103
+ where: {
104
+ domain: domain,
105
+ name: (0, typeorm_1.Raw)(alias => `LOWER(${alias}) LIKE '${inventoryHistory.locationName.toLowerCase()}'`)
106
+ }
107
+ });
108
+ where['location'] = (0, typeorm_1.In)(_locations.map((location) => location.id));
109
+ }
110
+ where['createdAt'] = (0, typeorm_1.Between)(fromDate, toDate);
111
+ convertedParams.where = Object.assign(Object.assign(Object.assign({}, convertedParams.where), where), { bizplace: customerBizplace });
112
+ const result = await tx.getRepository(inventory_history_1.InventoryHistory).findAndCount(Object.assign(Object.assign({}, convertedParams), { relations: ['domain', 'product', 'warehouse', 'location', 'bizplace', 'updater'], order: {
113
+ palletId: 'ASC',
114
+ seq: 'ASC'
115
+ } }));
116
+ let items = result[0];
117
+ let total = result[1];
118
+ return { items, total };
119
+ }
120
+ async inventoryHistoryReport(params, context) {
121
+ try {
122
+ const { domain, tx } = context.state;
123
+ let bizplaceFilter = { name: '', operator: '', value: '' };
124
+ let userFilter = params.filters.find(data => data.name === 'user');
125
+ let fromDate = params.filters.find(data => data.name === 'fromDate');
126
+ let toDate = params.filters.find(data => data.name === 'toDate');
127
+ let batchNo = params.filters.find(data => data.name === 'batchNo');
128
+ let product = params.filters.find(data => data.name === 'product');
129
+ let productDesc = params.filters.find(data => data.name === 'productDescription');
130
+ let hasTransactionOrBalanceFilter = params.filters.find(data => data.name === 'hasTransactionOrBalance');
131
+ let tzoffset = params.filters.find(data => data.name === 'tzoffset').value + ' seconds';
132
+ if (userFilter) {
133
+ const user = await tx.getRepository(auth_base_1.User).findOne({
134
+ where: { id: userFilter.value },
135
+ relations: ['bizplaces']
136
+ });
137
+ const bizplace = user.bizplaces[0];
138
+ if (!bizplace)
139
+ throw 'Invalid input';
140
+ bizplaceFilter = { name: 'bizplace', operator: 'eq', value: bizplace.id };
141
+ }
142
+ else {
143
+ bizplaceFilter = params.filters.find(data => data.name === 'bizplace');
144
+ }
145
+ if (!bizplaceFilter || !fromDate || !toDate)
146
+ throw 'Invalid input';
147
+ const bizplace = await tx.getRepository(biz_base_1.Bizplace).findOne({
148
+ id: bizplaceFilter.value
149
+ });
150
+ let batchNoQuery = '';
151
+ if (batchNo) {
152
+ batchNoQuery =
153
+ 'AND Lower(invh.batch_id) LIKE ANY(ARRAY[' +
154
+ batchNo.value
155
+ .toLowerCase()
156
+ .split(',')
157
+ .map(prod => {
158
+ return "'%" + prod.trim().replace(/'/g, "''") + "%'";
159
+ })
160
+ .join(',') +
161
+ '])';
162
+ }
163
+ let productQuery = '';
164
+ if (product) {
165
+ let productValue = product.value
166
+ .toLowerCase()
167
+ .split(',')
168
+ .map(prod => {
169
+ return "'%" + prod.trim().replace(/'/g, "''") + "%'";
170
+ })
171
+ .join(',');
172
+ productQuery = `AND (
173
+ Lower(prd.name) LIKE ANY(ARRAY[${productValue}])
174
+ OR Lower(prd.sku) LIKE ANY(ARRAY[${productValue}])
175
+ OR Lower(prd.description) LIKE ANY(ARRAY[${productValue}])
176
+ )`;
177
+ }
178
+ let productDescQuery = '';
179
+ if (productDesc) {
180
+ productDescQuery = "AND Lower(description) LIKE '%" + productDesc.value.toLowerCase() + "%'";
181
+ }
182
+ let hasTransactionOrBalanceQuery = '';
183
+ if (hasTransactionOrBalanceFilter && hasTransactionOrBalanceFilter.value) {
184
+ hasTransactionOrBalanceQuery = 'and (src.totalRow > 1 or src.totalQty <> 0)';
185
+ }
186
+ await tx.query(`
187
+ create temp table temp_products AS
188
+ (
189
+ select prd.*, prd.id::varchar as product_id from products prd
190
+ inner join bizplaces b on b.id = prd.bizplace_id
191
+ inner join companies c on c.domain_id = b.domain_id
192
+ inner join bizplaces b2 on b2.company_id = c.id
193
+ where b2.id = $1
194
+ ${productQuery}
195
+ )`, [bizplace.id]);
196
+ await tx.query(`
197
+ create temp table temp_data_src AS
198
+ (
199
+ SELECT prd.name AS product_name, prd.description AS product_description, prd.type as product_type, prd.aux_value_1 AS product_aux_value_1, trim(invh.batch_id) as batch_id, invh.product_id,
200
+ invh.packing_type, invh.bizplace_id, invh.domain_id,
201
+ invh.ref_order_id, invh.order_no, invh.order_ref_no, invh.transaction_type, invh.created_at,
202
+ invh.qty, invh.opening_qty,
203
+ invh.uom, COALESCE(invh.uom_value, 0) as uom_value, COALESCE(invh.opening_uom_value, 0) as opening_uom_value
204
+ FROM reduced_inventory_histories invh
205
+ INNER JOIN temp_products prd ON prd.id = invh.product_id::uuid
206
+ WHERE
207
+ invh.domain_id = $1
208
+ AND invh.bizplace_id = $2
209
+ AND invh.created_at <= $3::timestamp
210
+ ${batchNoQuery}
211
+ )
212
+ `, [domain.id, bizplace.id, toDate.value]);
213
+ await tx.query(`
214
+ create temp table temp_inv_history as (
215
+ SELECT src.product_name, src.product_description, src.product_type, src.product_aux_value_1, src.batch_id, src.product_id, src.packing_type, src.uom,
216
+ src.bizplace_id, src.domain_id,
217
+ SUM(COALESCE(src.qty,0)) AS qty,
218
+ SUM(COALESCE(src.opening_qty,0)) AS opening_qty,
219
+ SUM(COALESCE(src.uom_value,0)) AS uom_value,
220
+ SUM(COALESCE(src.opening_uom_value,0)) AS opening_uom_value,
221
+ 'Opening Balance' AS order_name,
222
+ '-' AS ref_no,
223
+ 0 AS rn,
224
+ $1::timestamp AS created_at,
225
+ $1::date AS created_date
226
+ FROM temp_data_src src
227
+ WHERE src.created_at < $1::timestamp
228
+ GROUP BY src.product_name, src.product_description, src.product_type, src.product_aux_value_1, src.batch_id, src.product_id, src.packing_type, src.uom,
229
+ src.bizplace_id, src.domain_id
230
+ UNION ALL
231
+ SELECT product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
232
+ domain_id, sum(qty) as qty, sum(opening_qty) as opening_qty, sum(uom_value) as uom_value, sum(opening_uom_value) as opening_uom_value,
233
+ order_name, ref_no, 1 AS rn, MIN(created_at) - $2::interval as created_at, (MIN(created_at) - $2::interval)::DATE as created_date
234
+ FROM (
235
+ SELECT invh.product_name, invh.product_description, invh.product_type, invh.product_aux_value_1, invh.batch_id, invh.product_id, invh.packing_type, invh.bizplace_id,
236
+ invh.domain_id,
237
+ invh.qty, invh.opening_qty, invh.uom_value, invh.uom, invh.opening_uom_value,
238
+ COALESCE(order_no, '-') AS order_name,
239
+ COALESCE(order_ref_no, '-') AS ref_no,
240
+ invh.created_at,
241
+ invh.created_at::date as created_date
242
+ FROM temp_data_src invh
243
+ WHERE (invh.qty <> 0 OR invh.uom_value <> 0) AND
244
+ invh.transaction_type <> 'ADJUSTMENT' AND
245
+ invh.transaction_type <>'NEW'
246
+ AND invh.created_at >= $1::timestamp
247
+ ) AS inv_movement
248
+ GROUP BY product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
249
+ domain_id, order_name, ref_no, rn
250
+ UNION ALL
251
+ SELECT product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
252
+ domain_id, sum(qty) as qty, sum(opening_qty) as opening_qty, sum(uom_value) as uom_value, sum(opening_uom_value) as opening_uom_value,
253
+ order_name, ref_no, 1 AS rn, created_at - $2::interval as created_at, created_at::date as created_date
254
+ FROM (
255
+ SELECT invh.product_name, invh.product_description, invh.product_type, invh.product_aux_value_1, invh.batch_id, invh.product_id, invh.packing_type, invh.uom, invh.bizplace_id,
256
+ invh.domain_id,
257
+ invh.qty, invh.opening_qty, invh.uom_value, invh.opening_uom_value,
258
+ invh.transaction_type AS order_name,
259
+ invh.transaction_type AS ref_no,
260
+ invh.created_at,
261
+ invh.created_at:: date as created_date
262
+ FROM temp_data_src invh
263
+ WHERE (invh.qty <> 0 OR invh.uom_value <> 0) AND
264
+ (invh.transaction_type = 'ADJUSTMENT' OR
265
+ invh.transaction_type = 'NEW')
266
+ AND invh.created_at >= $1::timestamp
267
+ ) AS inv_movement
268
+ GROUP BY product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
269
+ domain_id, order_name, ref_no, rn, created_at
270
+ )`, [fromDate.value, tzoffset]);
271
+ const result = await tx.query(`
272
+ select product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
273
+ domain_id, qty, opening_qty, round(uom_value::decimal,2) as uom_value, opening_uom_value, order_name, ref_no, created_at::date
274
+ from temp_inv_history invh where
275
+ exists (
276
+ select * from (
277
+ select batch_id, product_name, packing_type, sum(qty) as totalQty, count(*) as totalRow from temp_inv_history ih2
278
+ group by batch_id, product_name, packing_type
279
+ ) src
280
+ where src.batch_id = invh.batch_id and src.product_name = invh.product_name and src.packing_type = invh.packing_type
281
+ ${hasTransactionOrBalanceQuery}
282
+ )
283
+ ORDER BY invh.product_name asc, invh.product_description asc, invh.packing_type asc, invh.batch_id asc, invh.uom asc, invh.rn asc, invh.created_at asc
284
+ `);
285
+ tx.query(`
286
+ drop table temp_products, temp_data_src, temp_inv_history
287
+ `);
288
+ let items = result;
289
+ items = items.map(item => {
290
+ return {
291
+ batchId: item.batch_id,
292
+ bizplace: bizplace,
293
+ packingType: item.packing_type,
294
+ product: {
295
+ id: item.product_id,
296
+ name: item.product_name +
297
+ ' ( ' +
298
+ item.product_description +
299
+ ' ) ' +
300
+ (item.product_aux_value_1 === null ? '' : ' [ ' + item.product_aux_value_1 + ' ] '),
301
+ type: item.product_type
302
+ },
303
+ qty: item.qty,
304
+ uom: item.uom,
305
+ uomValue: item.uom_value,
306
+ openingQty: item.opening_qty,
307
+ openingUomValue: item.opening_uom_value,
308
+ orderName: item.order_name,
309
+ orderRefNo: item.ref_no,
310
+ createdAt: item.created_at
311
+ };
312
+ });
313
+ return items;
314
+ }
315
+ catch (error) {
316
+ throw error;
317
+ }
318
+ }
319
+ async inventoryHistoryPalletReport(params, context) {
320
+ try {
321
+ const { domain, tx } = context.state;
322
+ let userFilter = params.filters.find(data => data.name === 'user');
323
+ let bizplaceFilter = { name: '', operator: '', value: '' };
324
+ if (userFilter) {
325
+ const user = await tx.getRepository(auth_base_1.User).findOne({
326
+ where: { id: userFilter.value },
327
+ relations: ['bizplaces']
328
+ });
329
+ const bizplace = user.bizplaces[0];
330
+ if (!bizplace)
331
+ throw 'Invalid input';
332
+ bizplaceFilter = { name: 'bizplace', operator: 'eq', value: bizplace.id };
333
+ }
334
+ else {
335
+ bizplaceFilter = params.filters.find(data => data.name === 'bizplace');
336
+ }
337
+ let fromDate = params.filters.find(data => data.name === 'fromDate');
338
+ let toDate = params.filters.find(data => data.name === 'toDate');
339
+ let product = params.filters.find(data => data.name === 'product');
340
+ if (!fromDate || !toDate)
341
+ throw 'Invalid input';
342
+ let bizplaceQuery = '';
343
+ if (bizplaceFilter) {
344
+ const bizplace = await tx.getRepository(biz_base_1.Bizplace).findOne({
345
+ id: bizplaceFilter.value
346
+ });
347
+ if (bizplace) {
348
+ bizplaceQuery = "AND i2.bizplace_id = '" + bizplace.id + "'";
349
+ }
350
+ else {
351
+ throw 'Invalid input';
352
+ }
353
+ }
354
+ let productQuery = '';
355
+ if (product) {
356
+ productQuery =
357
+ 'AND prd.name ILIKE ANY(ARRAY[' +
358
+ product.value
359
+ .split(',')
360
+ .map(prod => {
361
+ return "'%" + prod.trim().replace(/'/g, "''") + "%'";
362
+ })
363
+ .join(',') +
364
+ '])';
365
+ }
366
+ const result = await tx.getRepository(inventory_history_1.InventoryHistory).query(`
367
+ with invHistory as (
368
+ select case when ar.name is null then 'NEW' else ar.name end as arrival_notice_name,
369
+ case when js.container_size is null then '' else js.container_size end as container_size,
370
+ i2.batch_id,
371
+ bzp.name as bizplace_name,
372
+ i2.pallet_id, ih.seq, ih.status, ih.transaction_type, i2.product_id, prd.name as product_name,
373
+ prd.description as product_description, ih.id as inventory_history_id, ih.packing_type, ih.qty, ih.opening_qty,
374
+ ih.created_at::date
375
+ from inventories i2
376
+ inner join reduced_inventory_histories ih on ih.pallet_id = i2.pallet_id and ih.domain_id = i2.domain_id
377
+ inner join products prd on prd.id = i2.product_id
378
+ inner join bizplaces bzp on bzp.id = ih.bizplace_id
379
+ left join order_inventories oi on oi.inventory_id = i2.id and oi.arrival_notice_id is not null
380
+ left join arrival_notices ar on ar.id = oi.arrival_notice_id
381
+ left join job_sheets js on js.id = ar.job_sheet_id
382
+ where
383
+ i2.domain_id = '${domain.id}'
384
+ and (
385
+ (ih.status = 'STORED' and ih.transaction_type = 'NEW')
386
+ or (ih.status = 'STORED' and ih.transaction_type = 'CANCEL_ORDER')
387
+ or (ih.status = 'STORED' and ih.transaction_type = 'RETURN')
388
+ or (ih.status = 'STORED' and ih.transaction_type = 'PUTAWAY')
389
+ or (ih.status = 'TERMINATED' and ih.transaction_type = 'TERMINATED')
390
+ )
391
+ ${bizplaceQuery}
392
+ ${productQuery}
393
+ order by ih.pallet_id, ih.seq
394
+ ), inventoryHistoryMovement as (
395
+ select bizplace_name, container_size, pallet_id, seq, status, transaction_type, product_id, product_name, product_description, batch_id,
396
+ inventory_history_id, packing_type, qty, opening_qty, created_at, arrival_notice_name from (
397
+ select row_number() over(partition by pallet_id order by created_at asc) as rn, * from invHistory where status = 'STORED'
398
+ )as invIn where rn = 1
399
+ union all
400
+ select bizplace_name, container_size, pallet_id, seq, status, transaction_type, product_id, product_name, product_description, batch_id,
401
+ inventory_history_id, packing_type, qty, opening_qty, created_at, arrival_notice_name from (
402
+ select row_number() over(partition by pallet_id order by created_at desc) as rn, * from invHistory
403
+ )as invOut where rn = 1 and status = 'TERMINATED'
404
+ ), inventoryHistoriesByPallet as (
405
+ select invHistory.bizplace_name, invHistory.container_size, invHistory.product_name, invHistory.product_description, invHistory.arrival_notice_name, invHistory.batch_id,
406
+ SUM(case when invHistory.created_at <= '${new Date(fromDate.value).toLocaleDateString()} 00:00:00' then
407
+ case when invHistory.status = 'STORED' then 1 else -1 end
408
+ else 0 end) as opening_balance,
409
+ SUM(case when invHistory.created_at >= '${new Date(fromDate.value).toLocaleDateString()} 00:00:00'
410
+ and invHistory.created_at <= '${new Date(toDate.value).toLocaleDateString()} 23:59:59' then
411
+ case when invHistory.status = 'STORED' then 1 else 0 end
412
+ else 0 end) as in_balance,
413
+ SUM(case when invHistory.created_at >= '${new Date(fromDate.value).toLocaleDateString()} 00:00:00'
414
+ and invHistory.created_at <= '${new Date(toDate.value).toLocaleDateString()} 23:59:59' then
415
+ case when invHistory.status = 'TERMINATED' then 1 else 0 end
416
+ else 0 end) as out_balance
417
+ from(
418
+ select * from inventoryHistoryMovement
419
+ ) as invHistory group by bizplace_name, container_size, product_name, product_description, arrival_notice_name, batch_id
420
+ )
421
+ select invh.*, invh.opening_balance + invh.in_balance - invh.out_balance as closing_balance
422
+ , (
423
+ select json_agg(json_build_object('created_at', created_at, 'in_balance', in_balance, 'out_balance', out_balance)) as jsonData from
424
+ (
425
+ select bizplace_name, product_name, batch_id, arrival_notice_name, created_at,
426
+ SUM(case when status = 'STORED' then 1 else 0 end) as in_balance,
427
+ SUM(case when status = 'TERMINATED' then 1 else 0 end) as out_balance
428
+ from inventoryHistoryMovement
429
+ where created_at >= '${new Date(fromDate.value).toLocaleDateString()} 00:00:00' and
430
+ created_at <= '${new Date(toDate.value).toLocaleDateString()} 23:59:59' and
431
+ bizplace_name = invh.bizplace_name and product_name = invh.product_name and
432
+ batch_id = invh.batch_id and arrival_notice_name = invh.arrival_notice_name
433
+ group by bizplace_name, product_name, batch_id, arrival_notice_name, created_at
434
+ order by created_at
435
+ )
436
+ as t
437
+ )::varchar as json_date_movement
438
+ from inventoryHistoriesByPallet invh
439
+ where invh.opening_balance >= 0
440
+ and invh.in_balance >= 0
441
+ and invh.out_balance >= 0
442
+ and (invh.opening_balance > 0 or invh.in_balance > 0)
443
+ order by invh.bizplace_name, invh.product_name, invh.batch_id;
444
+ `);
445
+ let items = result;
446
+ items = items.map(item => {
447
+ return {
448
+ bizplace: { name: item.bizplace_name },
449
+ product: {
450
+ name: item.product_name.trim() + ' ( ' + (item.product_description || '-').trim() + ' )'
451
+ },
452
+ arrivalNoticeName: item.arrival_notice_name,
453
+ batchId: item.batch_id,
454
+ openingBalance: item.opening_balance,
455
+ inBalance: item.in_balance,
456
+ outBalance: item.out_balance,
457
+ closingBalance: item.closing_balance,
458
+ jsonDateMovement: item.json_date_movement,
459
+ containerSize: item.container_size
460
+ };
461
+ });
462
+ return items;
463
+ }
464
+ catch (error) {
465
+ throw error;
466
+ }
467
+ }
468
+ async inventoryHistoryPalletDetailReport(params, context) {
469
+ try {
470
+ const { domain, tx } = context.state;
471
+ let userFilter = params.filters.find(data => data.name === 'user');
472
+ let bizplaceFilter = { name: '', operator: '', value: '' };
473
+ if (userFilter) {
474
+ const user = await tx.getRepository(auth_base_1.User).findOne({
475
+ where: { id: userFilter.value },
476
+ relations: ['bizplaces']
477
+ });
478
+ const bizplace = user.bizplaces[0];
479
+ if (!bizplace)
480
+ throw 'Invalid input';
481
+ bizplaceFilter = { name: 'bizplace', operator: 'eq', value: bizplace.id };
482
+ }
483
+ else {
484
+ bizplaceFilter = params.filters.find(data => data.name === 'bizplace');
485
+ }
486
+ let fromDate = params.filters.find(data => data.name === 'fromDate');
487
+ let toDate = params.filters.find(data => data.name === 'toDate');
488
+ let product = params.filters.find(data => data.name === 'product');
489
+ if (!fromDate || !toDate)
490
+ throw 'Invalid input';
491
+ let bizplaceQuery = '';
492
+ if (bizplaceFilter) {
493
+ const bizplace = await tx.getRepository(biz_base_1.Bizplace).findOne({
494
+ id: bizplaceFilter.value
495
+ });
496
+ if (bizplace) {
497
+ bizplaceQuery = "AND i2.bizplace_id = '" + bizplace.id + "'";
498
+ }
499
+ else {
500
+ throw 'Invalid input';
501
+ }
502
+ }
503
+ let productQuery = '';
504
+ if (product) {
505
+ productQuery =
506
+ 'AND prd.name ILIKE ANY(ARRAY[' +
507
+ product.value
508
+ .split(',')
509
+ .map(prod => {
510
+ return "'%" + prod.trim().replace(/'/g, "''") + "%'";
511
+ })
512
+ .join(',') +
513
+ '])';
514
+ }
515
+ const result = await tx.getRepository(inventory_history_1.InventoryHistory).query(`
516
+ with invHistory as (
517
+ select case when ar.name is null then 'NEW' else ar.name end as arrival_notice_name,
518
+ case when js.container_size is null then '' else js.container_size end as container_size,
519
+ i2.batch_id,
520
+ bzp.name as bizplace_name,
521
+ i2.pallet_id, ih.seq, ih.status, ih.transaction_type, i2.product_id, prd.name as product_name,
522
+ prd.description as product_description, ih.id as inventory_history_id, ih.packing_type, ih.qty, ih.opening_qty,
523
+ ih.created_at::date
524
+ from inventories i2
525
+ inner join reduced_inventory_histories ih on ih.pallet_id = i2.pallet_id and ih.domain_id = i2.domain_id
526
+ inner join products prd on prd.id = i2.product_id
527
+ inner join bizplaces bzp on bzp.id = ih.bizplace_id
528
+ left join order_inventories oi on oi.inventory_id = i2.id and oi.arrival_notice_id is not null
529
+ left join arrival_notices ar on ar.id = oi.arrival_notice_id
530
+ left join job_sheets js on js.id = ar.job_sheet_id
531
+ where
532
+ i2.domain_id = '${domain.id}'
533
+ and (
534
+ (ih.status = 'STORED' and ih.transaction_type = 'NEW')
535
+ or (ih.status = 'STORED' and ih.transaction_type = 'CANCEL_ORDER')
536
+ or (ih.status = 'STORED' and ih.transaction_type = 'RETURN')
537
+ or (ih.status = 'STORED' and ih.transaction_type = 'PUTAWAY')
538
+ or (ih.status = 'TERMINATED' and ih.transaction_type = 'TERMINATED')
539
+ )
540
+ ${bizplaceQuery}
541
+ ${productQuery}
542
+ order by ih.pallet_id, ih.seq
543
+ ), inventoryHistoryMovement as (
544
+ select bizplace_name, container_size, pallet_id, seq, status, transaction_type, product_id, product_name, product_description, batch_id,
545
+ inventory_history_id, packing_type, qty, opening_qty, created_at, arrival_notice_name from (
546
+ select row_number() over(partition by pallet_id order by created_at asc) as rn, * from invHistory where status = 'STORED'
547
+ )as invIn where rn = 1
548
+ union all
549
+ select bizplace_name, container_size, pallet_id, seq, status, transaction_type, product_id, product_name, product_description, batch_id,
550
+ inventory_history_id, packing_type, qty, opening_qty, created_at, arrival_notice_name from (
551
+ select row_number() over(partition by pallet_id order by created_at desc) as rn, * from invHistory
552
+ )as invOut where rn = 1 and status = 'TERMINATED'
553
+ ), inventoryHistoriesByPallet as (
554
+ select invHistory.bizplace_name, invHistory.container_size, invHistory.product_name, invHistory.product_description, invHistory.arrival_notice_name, invHistory.batch_id,
555
+ SUM(case when invHistory.created_at <= '${new Date(fromDate.value).toLocaleDateString()} 00:00:00' then
556
+ case when invHistory.status = 'STORED' then 1 else -1 end
557
+ else 0 end) as opening_balance,
558
+ SUM(case when invHistory.created_at >= '${new Date(fromDate.value).toLocaleDateString()} 00:00:00'
559
+ and invHistory.created_at <= '${new Date(toDate.value).toLocaleDateString()} 23:59:59' then
560
+ case when invHistory.status = 'STORED' then 1 else 0 end
561
+ else 0 end) as in_balance,
562
+ SUM(case when invHistory.created_at >= '${new Date(fromDate.value).toLocaleDateString()} 00:00:00'
563
+ and invHistory.created_at <= '${new Date(toDate.value).toLocaleDateString()} 23:59:59' then
564
+ case when invHistory.status = 'TERMINATED' then 1 else 0 end
565
+ else 0 end) as out_balance
566
+ from(
567
+ select * from inventoryHistoryMovement
568
+ ) as invHistory group by bizplace_name, container_size, product_name, product_description, arrival_notice_name, batch_id
569
+ )
570
+ select invh.*, invh.opening_balance + invh.in_balance - invh.out_balance as closing_balance
571
+ , (
572
+ select json_agg(json_build_object('created_at', created_at, 'in_balance', in_balance, 'out_balance', out_balance)) as jsonData from
573
+ (
574
+ select bizplace_name, product_name, batch_id, arrival_notice_name, created_at,
575
+ SUM(case when status = 'STORED' then 1 else 0 end) as in_balance,
576
+ SUM(case when status = 'TERMINATED' then 1 else 0 end) as out_balance
577
+ from inventoryHistoryMovement
578
+ where created_at >= '${new Date(fromDate.value).toLocaleDateString()} 00:00:00' and
579
+ created_at <= '${new Date(toDate.value).toLocaleDateString()} 23:59:59' and
580
+ bizplace_name = invh.bizplace_name and product_name = invh.product_name and
581
+ batch_id = invh.batch_id and arrival_notice_name = invh.arrival_notice_name
582
+ group by bizplace_name, product_name, batch_id, arrival_notice_name, created_at
583
+ order by created_at
584
+ )
585
+ as t
586
+ )::varchar as json_date_movement
587
+ from inventoryHistoriesByPallet invh
588
+ where invh.opening_balance >= 0
589
+ and invh.in_balance >= 0
590
+ and invh.out_balance >= 0
591
+ and (invh.opening_balance > 0 or invh.in_balance > 0)
592
+ order by invh.bizplace_name, invh.product_name, invh.batch_id;
593
+ `);
594
+ let items = result;
595
+ items = items.map(item => {
596
+ return {
597
+ bizplace: { name: item.bizplace_name },
598
+ product: {
599
+ name: item.product_name.trim() + ' ( ' + (item.product_description || '-').trim() + ' )'
600
+ },
601
+ arrivalNoticeName: item.arrival_notice_name,
602
+ batchId: item.batch_id,
603
+ openingBalance: item.opening_balance,
604
+ inBalance: item.in_balance,
605
+ outBalance: item.out_balance,
606
+ closingBalance: item.closing_balance,
607
+ jsonDateMovement: item.json_date_movement,
608
+ containerSize: item.container_size
609
+ };
610
+ });
611
+ return items;
612
+ }
613
+ catch (error) {
614
+ throw error;
615
+ }
616
+ }
617
+ async inventoryHistoryPalletStorageReport(params, context) {
618
+ try {
619
+ const { domain, tx } = context.state;
620
+ let userFilter = params.filters.find(data => data.name === 'user');
621
+ let bizplaceFilter = { name: '', operator: '', value: '' };
622
+ if (userFilter) {
623
+ const user = await tx.getRepository(auth_base_1.User).findOne({
624
+ where: { id: userFilter.value },
625
+ relations: ['bizplaces']
626
+ });
627
+ const bizplace = user.bizplaces[0];
628
+ if (!bizplace)
629
+ throw 'Invalid input';
630
+ bizplaceFilter = { name: 'bizplace', operator: 'eq', value: bizplace.id };
631
+ }
632
+ else {
633
+ bizplaceFilter = params.filters.find(data => data.name === 'bizplace');
634
+ }
635
+ let fromDate = params.filters.find(data => data.name === 'fromDate');
636
+ let toDate = params.filters.find(data => data.name === 'toDate');
637
+ if (!bizplaceFilter || !fromDate || !toDate)
638
+ throw 'Invalid input';
639
+ const bizplace = await tx.getRepository(biz_base_1.Bizplace).findOne({
640
+ id: bizplaceFilter.value
641
+ });
642
+ let queryFilter = ``;
643
+ let queryParams = [fromDate.value, toDate.value];
644
+ let locationType = params.filters.find(data => data.name === 'locationType');
645
+ if (locationType) {
646
+ queryFilter = queryFilter + `AND location_type = $` + (queryParams.length + 1);
647
+ queryParams.push(locationType.value);
648
+ }
649
+ let zone = params.filters.find(data => data.name === 'zone');
650
+ if (zone) {
651
+ queryFilter = queryFilter + `AND LOWER(location_zone) like $` + (queryParams.length + 1);
652
+ queryParams.push(zone.value.toLowerCase());
653
+ }
654
+ await tx.query(`
655
+ create temp table temp_history as (
656
+ select distinct on (ih.pallet_id)
657
+ ih.pallet_id, ih.created_at as in_at, loc.name as location_name, loc."type" as location_type, loc."zone" as location_zone,
658
+ bz.name as bizplace_name
659
+ from reduced_inventory_histories ih
660
+ inner join inventories inv on inv.pallet_id = ih.pallet_id and inv.domain_id = ih.domain_id
661
+ inner join locations loc on loc.id = inv.location_id
662
+ inner join bizplaces bz on bz.id = inv.bizplace_id
663
+ where ih.domain_id = $1
664
+ and inv.bizplace_id = $2
665
+ and not exists(
666
+ SELECT domain_id, pallet_id
667
+ FROM reduced_inventory_histories ih2
668
+ where ih2.domain_id = $1
669
+ and ih2.created_at < $3
670
+ and ih2.transaction_type = 'TERMINATED' and ih2.status ='TERMINATED'
671
+ and ih2.pallet_id = ih.pallet_id
672
+ group by ih2.domain_id , ih2.pallet_id
673
+ )
674
+ and ih.created_at <= $4
675
+ order by ih.pallet_id , ih.seq
676
+ )
677
+ `, [domain.id, bizplace.id, fromDate.value, toDate.value]);
678
+ await tx.query(`
679
+ create temp table temp_pallet_storage_history as (
680
+ select * from (
681
+ select bizplace_name, location_type, location_zone, location_name,
682
+ COUNT(pallet_id) filter (where in_at between $1 and $2) as inbound_qty,
683
+ COUNT(*) as total_qty,
684
+ string_agg(case when in_at between $1 and $2 then pallet_id end, ', ') as inbound_pallet_id,
685
+ string_agg(case when in_at not between $1 and $2 then pallet_id end, ', ') as pallet_id
686
+ from temp_history where location_type = 'SHELF'
687
+ group by bizplace_name, location_name, location_type, location_zone
688
+ union
689
+ select bizplace_name, location_type, location_zone, location_name,
690
+ case when in_at between $1 and $2 then 1 else 0 end as inbound_qty,
691
+ 1 as total_qty,
692
+ case when in_at between $1 and $2 then pallet_id end as inbound_pallet_id,
693
+ case when in_at not between $1 and $2 then pallet_id end pallet_id
694
+ from temp_history where location_type = 'FLOOR'
695
+ ) as src where 1 = 1
696
+ ${queryFilter}
697
+ )
698
+ `, queryParams);
699
+ const total = await tx.query(`select count(*) from temp_pallet_storage_history`);
700
+ const totalWithOpeningBalance = await tx.query(`select count(*) from temp_pallet_storage_history where pallet_id notnull`);
701
+ const result = await tx.query(`
702
+ select * from temp_pallet_storage_history order by location_type OFFSET $1 LIMIT $2
703
+ `, [(params.pagination.page - 1) * params.pagination.limit, params.pagination.limit]);
704
+ tx.query(`
705
+ drop table temp_history, temp_pallet_storage_history
706
+ `);
707
+ let items = result.map(itm => {
708
+ return Object.assign(Object.assign({}, itm), { bizplace: {
709
+ name: itm.bizplace_name
710
+ }, location: {
711
+ name: itm.location_name,
712
+ type: itm.location_type,
713
+ zone: itm.location_zone
714
+ }, palletId: itm.pallet_id, inboundPalletId: itm.inbound_pallet_id, inboundQty: itm.inbound_qty, totalQty: itm.total_qty });
715
+ });
716
+ return { items, total: total[0].count, totalWithOpeningBalance: totalWithOpeningBalance[0].count };
717
+ }
718
+ catch (ex) {
719
+ throw ex;
720
+ }
721
+ }
722
+ async inventoryHistorySummaryReport(params, context) {
723
+ try {
724
+ const { tx } = context.state;
725
+ let bizplaceFilter = { name: '', operator: '', value: '' };
726
+ let userFilter = params.filters.find(data => data.name === 'user');
727
+ let fromDate = params.filters.find(data => data.name === 'fromDate');
728
+ let toDate = params.filters.find(data => data.name === 'toDate');
729
+ let byPallet = params.filters.find(data => data.name === 'byPallet');
730
+ if (userFilter) {
731
+ const user = await tx.getRepository(auth_base_1.User).findOne({
732
+ where: { id: userFilter.value },
733
+ relations: ['bizplaces']
734
+ });
735
+ const bizplace = user.bizplaces[0];
736
+ if (!bizplace)
737
+ throw 'Invalid input';
738
+ bizplaceFilter = { name: 'bizplace', operator: 'eq', value: bizplace.id };
739
+ }
740
+ else {
741
+ bizplaceFilter = params.filters.find(data => data.name === 'bizplace');
742
+ }
743
+ if (!bizplaceFilter || !fromDate || !toDate)
744
+ throw 'Invalid input';
745
+ const bizplace = await tx.getRepository(biz_base_1.Bizplace).findOne({
746
+ id: bizplaceFilter.value
747
+ });
748
+ let [result, total] = byPallet.value
749
+ ? await massageInventoryPalletSummary(tx, params, bizplace, context)
750
+ : await massageInventorySummary(tx, params, bizplace, context);
751
+ let items = result.map(itm => {
752
+ return Object.assign(Object.assign({}, itm), { batchId: itm.batch_id, packingType: itm.packing_type, packingSize: itm.packing_size, openingQty: itm.opening_qty, adjustmentQty: itm.adjustment_qty, closingQty: itm.closing_qty, totalInQty: itm.total_in_qty, totalOutQty: itm.total_out_qty, product: {
753
+ id: itm.product_id,
754
+ sku: itm.product_sku,
755
+ name: itm.product_name,
756
+ description: itm.product_description,
757
+ type: itm.product_type
758
+ } });
759
+ });
760
+ return {
761
+ items,
762
+ total: total[0].count,
763
+ totalInboundQty: total[0].totalinqty || 0,
764
+ totalOpeningBal: total[0].totalopeningbal || 0
765
+ };
766
+ }
767
+ catch (error) {
768
+ throw error;
769
+ }
770
+ }
771
+ async onhandInventories(context, filters, pagination, sortings, locationSortingRules) {
772
+ const { domain, user, tx } = context.state;
773
+ // define all inputs
774
+ let userFilter = filters.find(data => data.name === 'user');
775
+ let product = filters.find(data => data.name === 'product');
776
+ let createdAt = filters.find(data => data.name === 'created_at');
777
+ let location = filters.find(data => data.name === 'location');
778
+ let batchId = filters.find(data => data.name === 'batchId');
779
+ let palletId = filters.find(data => data.name === 'palletId');
780
+ let cartonId = filters.find(data => data.name === 'cartonId');
781
+ let packingType = filters.find(data => data.name === 'packingType');
782
+ let timezoneOffset = filters.find(data => data.name === 'timezoneOffset').value + ' minutes';
783
+ // expiration date filter
784
+ let expiration = filters.find(data => data.name === 'expiration').value;
785
+ let expFromDate = filters.find(data => data.name === 'expFromDate');
786
+ let expToDate = filters.find(data => data.name === 'expToDate');
787
+ let bizplaceFilter = { name: '', operator: '', value: [] };
788
+ // prepare query filters
789
+ if (userFilter) {
790
+ const user = await tx.getRepository(auth_base_1.User).findOne({
791
+ where: { id: userFilter.value },
792
+ relations: ['bizplaces']
793
+ });
794
+ const bizplace = user.bizplaces[0];
795
+ if (!bizplace)
796
+ throw 'Invalid input';
797
+ bizplaceFilter = { name: 'bizplace', operator: 'eq', value: [bizplace.id] };
798
+ }
799
+ else {
800
+ bizplaceFilter = !filters.find((filter) => filter.name === 'bizplace')
801
+ ? {
802
+ name: 'bizplace',
803
+ operator: 'in',
804
+ value: await (0, biz_base_1.getPermittedBizplaceIds)(domain, user),
805
+ relation: true
806
+ }
807
+ : Object.assign(Object.assign({}, filters.find(data => data.name === 'bizplace')), { value: [filters.find(data => data.name === 'bizplace').value] });
808
+ }
809
+ let queryFilter = ``;
810
+ let bizplaces = bizplaceFilter.value.map(id => `('${id}')`).join(',');
811
+ if (product) {
812
+ let products = product.value
813
+ .toLowerCase()
814
+ .split(',')
815
+ .map(prod => {
816
+ return "'%" + prod.trim().replace(/'/g, "''") + "%'";
817
+ })
818
+ .join(',');
819
+ queryFilter =
820
+ queryFilter +
821
+ ` and exists (
822
+ select prd.id as product_id from products prd
823
+ inner join bizplaces b on b.id = prd.bizplace_id
824
+ inner join companies c on c.domain_id = b.domain_id
825
+ inner join bizplaces b2 on b2.company_id = c.id
826
+ where exists (
827
+ SELECT * FROM tmp_bizfilter bizFilter
828
+ WHERE bizFilter.bizplace_id = "b2"."id"
829
+ )
830
+ and (lower(prd.name) like any(array[${products}])
831
+ or lower(prd.description) like any(array[${products}])
832
+ or lower(prd.sku) like any(array[${products}]))
833
+ and prd.id = rih.product_id
834
+ group by prd.id
835
+ )`;
836
+ }
837
+ if (location) {
838
+ let locations = location.value
839
+ .map(loc => {
840
+ return "'" + loc + "'";
841
+ })
842
+ .join(',');
843
+ queryFilter =
844
+ queryFilter +
845
+ `and exists (
846
+ select loc.id from locations loc where
847
+ loc.id = any(array[${locations}]::uuid[])
848
+ and loc.id = rih.location_id
849
+ )`;
850
+ }
851
+ // default sorting
852
+ let queryOrder = 'order by created_at desc';
853
+ if (sortings && sortings.length > 0) {
854
+ const arrObjectMap = [
855
+ { name: 'palletId', value: 'rih.pallet_id' },
856
+ { name: 'cartonId', value: 'rih.carton_id' },
857
+ { name: 'batchId', value: 'rih.batch_id' },
858
+ { name: 'initialInboundAt', value: 'rih.initial_inbound_at' },
859
+ { name: 'bizplace|name', value: 'bz.name' },
860
+ { name: 'product|name', value: 'prd.sku' },
861
+ { name: 'remainQty', value: 'rih.qty' },
862
+ { name: 'location|name', value: 'loc.name' }
863
+ ];
864
+ sortings.forEach((sorting, idx) => {
865
+ let itmIndex = arrObjectMap.findIndex(x => x.name === sorting.name);
866
+ queryOrder = `${idx === 0 ? 'order by' : queryOrder + ','} ${itmIndex >= 0 ? arrObjectMap[itmIndex].value : sorting.name} ${sorting.desc ? 'DESC' : 'ASC'}`;
867
+ });
868
+ }
869
+ if (batchId)
870
+ queryFilter = `${queryFilter} and lower(rih.batch_id) like '${batchId.value.toLowerCase()}' `;
871
+ if (palletId)
872
+ queryFilter = `${queryFilter} and rih.pallet_id like '${palletId.value}' `;
873
+ if (cartonId)
874
+ queryFilter = `${queryFilter} and rih.carton_id like '${cartonId.value}' `;
875
+ if (packingType)
876
+ queryFilter = `${queryFilter} and rih.packing_type like '${packingType.value}' `;
877
+ let expirationQueryFilter = ``;
878
+ if (expiration)
879
+ expirationQueryFilter = ` and iv.expiration_date >= '${expFromDate.value}'::timestamp + '${timezoneOffset}'::INTERVAL and
880
+ iv.expiration_date <= '${expToDate.value}'::timestamp + '${timezoneOffset}'::INTERVAL + '1 day'::INTERVAL`;
881
+ // query the results
882
+ await tx.query(`
883
+ CREATE TEMP TABLE tmp_bizfilter AS (
884
+ SELECT bizplace_id::uuid FROM (VALUES ${bizplaces}) AS bizFilter(bizplace_id)
885
+ );
886
+ `);
887
+ await tx.query(`
888
+ create temp table tmp_src as (
889
+ select domain_id, pallet_id, carton_id, seq, qty, uom_value, packing_type, batch_id, batch_id_ref, created_at, status,
890
+ product_id::uuid as product_id, bizplace_id::uuid as bizplace_id, location_id::uuid as location_id
891
+ from reduced_inventory_histories rih
892
+ where domain_id = $1 and created_at < $2::timestamp + $3::INTERVAL + '1 day'::INTERVAL
893
+ );
894
+ `, [domain.id, createdAt.value, timezoneOffset]);
895
+ await tx.query(`
896
+ create temp table tmp_data as (
897
+ select dt.*, rih.carton_id, rih.batch_id, rih.batch_id_ref, rih.product_id, rih.packing_type, rih.bizplace_id, rih.location_id, iv.uom,
898
+ iv.expiration_date, iv.reusable_pallet_id, iv.remark
899
+ from
900
+ (
901
+ select ih.domain_id, ih.pallet_id, sum(ih.qty) as qty, sum(ih.uom_value) as uom_value, max(ih.seq) as last_seq, max(ih.created_at) as created_at,
902
+ min(ih.created_at) as initial_inbound_at
903
+ from tmp_src ih
904
+ group by ih.domain_id, ih.pallet_id
905
+ ) dt
906
+ inner join tmp_src rih on dt.domain_id = rih.domain_id and dt.pallet_id = rih.pallet_id and dt.last_seq = rih.seq and rih.status <> 'TERMINATED'
907
+ inner join inventories iv on iv.domain_id = dt.domain_id and iv.pallet_id = dt.pallet_id
908
+ where exists (
909
+ SELECT * FROM tmp_bizfilter bizFilter
910
+ WHERE bizFilter.bizplace_id = "rih"."bizplace_id"
911
+ )
912
+ ${queryFilter}
913
+ ${expirationQueryFilter}
914
+ );
915
+ `);
916
+ const total = await tx.query(`select count(*) from tmp_data`);
917
+ const result = await tx.query(`
918
+ select
919
+ rih.domain_id, rih.pallet_id as "palletId", rih.carton_id as "cartonId", rih.qty as "remainQty", rih.uom_value as "uomValue", rih.uom, rih.last_seq, rih.created_at,
920
+ rih.initial_inbound_at as "initialInboundAt",
921
+ case when rih.reusable_pallet_id is not null then concat(rih.batch_id, ' (', plt.name, ')') else rih.batch_id end as "batchId",
922
+ rih.batch_id_ref as "batchIdRef", rih.product_id, rih.packing_type as "packingType", rih.bizplace_id, rih.location_id,
923
+ prd.id as product_id, prd.name as product_name, prd.sku as product_sku, prd.description as product_description,
924
+ bz.id as bizplace_id, bz.name as bizplace_name,
925
+ loc.id as location_id, loc.name as location_name, loc."zone" as location_zone, loc."row" as location_row, loc."column" as location_column, loc.shelf as location_shelf,
926
+ wh.name as warehouse_name, plt.name as reusable_pallet_name,
927
+ rih.remark,
928
+ rih.expiration_date as "expirationDate"
929
+ from tmp_data rih
930
+ left join pallets plt on plt.id = rih.reusable_pallet_id
931
+ inner join products prd on prd.id = rih.product_id
932
+ inner join bizplaces bz on bz.id = rih.bizplace_id
933
+ inner join locations loc on loc.id = rih.location_id
934
+ inner join warehouses wh on wh.id = loc.warehouse_id
935
+ WHERE 1 = 1
936
+ ${queryOrder}
937
+ OFFSET $1 LIMIT $2;
938
+ `, [(pagination.page - 1) * pagination.limit, pagination.limit]);
939
+ tx.query(`
940
+ drop table tmp_src, tmp_data, tmp_bizfilter
941
+ `);
942
+ // map all results
943
+ let items = result.map(itm => {
944
+ return Object.assign(Object.assign({}, itm), { bizplace: {
945
+ id: itm.bizplace_id,
946
+ name: itm.bizplace_name
947
+ }, location: {
948
+ id: itm.location_id,
949
+ name: itm.location_name,
950
+ type: itm.location_type,
951
+ zone: itm.location_zone
952
+ }, product: {
953
+ id: itm.product_id,
954
+ name: itm.product_name,
955
+ description: itm.product_description,
956
+ sku: itm.product_sku
957
+ } });
958
+ });
959
+ return { items, total: total[0].count };
960
+ }
961
+ async domain(inventoryHistory) {
962
+ return await (0, typeorm_1.getRepository)(shell_1.Domain).findOne(inventoryHistory.domainId);
963
+ }
964
+ async updater(inventoryHistory) {
965
+ return await (0, typeorm_1.getRepository)(auth_base_1.User).findOne(inventoryHistory.updaterId);
966
+ }
967
+ async creator(inventoryHistory) {
968
+ return await (0, typeorm_1.getRepository)(auth_base_1.User).findOne(inventoryHistory.creatorId);
969
+ }
970
+ };
971
+ __decorate([
972
+ (0, type_graphql_1.Query)(returns => inventory_history_types_1.InventoryHistoryList),
973
+ __param(0, (0, type_graphql_1.Args)()),
974
+ __param(1, (0, type_graphql_1.Ctx)()),
975
+ __metadata("design:type", Function),
976
+ __metadata("design:paramtypes", [typeof (_a = typeof shell_1.ListParam !== "undefined" && shell_1.ListParam) === "function" ? _a : Object, Object]),
977
+ __metadata("design:returntype", Promise)
978
+ ], InventoryHistoryQuery.prototype, "inventoryHistories", null);
979
+ __decorate([
980
+ (0, type_graphql_1.Query)(returns => inventory_history_1.InventoryHistory),
981
+ __param(0, (0, type_graphql_1.Arg)('name')),
982
+ __param(1, (0, type_graphql_1.Ctx)()),
983
+ __metadata("design:type", Function),
984
+ __metadata("design:paramtypes", [String, Object]),
985
+ __metadata("design:returntype", Promise)
986
+ ], InventoryHistoryQuery.prototype, "inventoryHistory", null);
987
+ __decorate([
988
+ (0, type_graphql_1.Directive)('@transaction'),
989
+ (0, type_graphql_1.Query)(returns => inventory_history_types_1.InventoryHistoryList),
990
+ __param(0, (0, type_graphql_1.Ctx)()),
991
+ __param(1, (0, type_graphql_1.Arg)('inventoryHistory', type => inventory_history_types_1.InventoryHistoryPatch, { nullable: true })),
992
+ __param(2, (0, type_graphql_1.Arg)('filters', type => [shell_1.Filter], { nullable: true })),
993
+ __param(3, (0, type_graphql_1.Arg)('pagination', type => shell_1.Pagination, { nullable: true })),
994
+ __param(4, (0, type_graphql_1.Arg)('sortings', type => [shell_1.Sorting], { nullable: true })),
995
+ __metadata("design:type", Function),
996
+ __metadata("design:paramtypes", [Object, inventory_history_types_1.InventoryHistoryPatch, Array, typeof (_b = typeof shell_1.Pagination !== "undefined" && shell_1.Pagination) === "function" ? _b : Object, Array]),
997
+ __metadata("design:returntype", Promise)
998
+ ], InventoryHistoryQuery.prototype, "bizplaceInventoryHistories", null);
999
+ __decorate([
1000
+ (0, type_graphql_1.Directive)('@transaction'),
1001
+ (0, type_graphql_1.Query)(returns => [inventory_history_1.InventoryHistory]),
1002
+ __param(0, (0, type_graphql_1.Args)()),
1003
+ __param(1, (0, type_graphql_1.Ctx)()),
1004
+ __metadata("design:type", Function),
1005
+ __metadata("design:paramtypes", [typeof (_c = typeof shell_1.ListParam !== "undefined" && shell_1.ListParam) === "function" ? _c : Object, Object]),
1006
+ __metadata("design:returntype", Promise)
1007
+ ], InventoryHistoryQuery.prototype, "inventoryHistoryReport", null);
1008
+ __decorate([
1009
+ (0, type_graphql_1.Directive)('@transaction'),
1010
+ (0, type_graphql_1.Query)(returns => [inventory_history_1.InventoryHistory]),
1011
+ __param(0, (0, type_graphql_1.Args)()),
1012
+ __param(1, (0, type_graphql_1.Ctx)()),
1013
+ __metadata("design:type", Function),
1014
+ __metadata("design:paramtypes", [typeof (_d = typeof shell_1.ListParam !== "undefined" && shell_1.ListParam) === "function" ? _d : Object, Object]),
1015
+ __metadata("design:returntype", Promise)
1016
+ ], InventoryHistoryQuery.prototype, "inventoryHistoryPalletReport", null);
1017
+ __decorate([
1018
+ (0, type_graphql_1.Directive)('@transaction'),
1019
+ (0, type_graphql_1.Query)(returns => [inventory_history_1.InventoryHistory]),
1020
+ __param(0, (0, type_graphql_1.Args)()),
1021
+ __param(1, (0, type_graphql_1.Ctx)()),
1022
+ __metadata("design:type", Function),
1023
+ __metadata("design:paramtypes", [typeof (_e = typeof shell_1.ListParam !== "undefined" && shell_1.ListParam) === "function" ? _e : Object, Object]),
1024
+ __metadata("design:returntype", Promise)
1025
+ ], InventoryHistoryQuery.prototype, "inventoryHistoryPalletDetailReport", null);
1026
+ __decorate([
1027
+ (0, type_graphql_1.Directive)('@transaction'),
1028
+ (0, type_graphql_1.Query)(returns => inventory_history_types_1.InventoryHistoryPalletReportList),
1029
+ __param(0, (0, type_graphql_1.Args)()),
1030
+ __param(1, (0, type_graphql_1.Ctx)()),
1031
+ __metadata("design:type", Function),
1032
+ __metadata("design:paramtypes", [typeof (_f = typeof shell_1.ListParam !== "undefined" && shell_1.ListParam) === "function" ? _f : Object, Object]),
1033
+ __metadata("design:returntype", Promise)
1034
+ ], InventoryHistoryQuery.prototype, "inventoryHistoryPalletStorageReport", null);
1035
+ __decorate([
1036
+ (0, type_graphql_1.Directive)('@transaction'),
1037
+ (0, type_graphql_1.Query)(returns => inventory_history_types_1.InventoryHistorySummaryList),
1038
+ __param(0, (0, type_graphql_1.Args)()),
1039
+ __param(1, (0, type_graphql_1.Ctx)()),
1040
+ __metadata("design:type", Function),
1041
+ __metadata("design:paramtypes", [typeof (_g = typeof shell_1.ListParam !== "undefined" && shell_1.ListParam) === "function" ? _g : Object, Object]),
1042
+ __metadata("design:returntype", Promise)
1043
+ ], InventoryHistoryQuery.prototype, "inventoryHistorySummaryReport", null);
1044
+ __decorate([
1045
+ (0, type_graphql_1.Directive)('@transaction'),
1046
+ (0, type_graphql_1.Query)(returns => inventory_types_1.InventoryList),
1047
+ __param(0, (0, type_graphql_1.Ctx)()),
1048
+ __param(1, (0, type_graphql_1.Arg)('filters', type => [shell_1.Filter], { nullable: true })),
1049
+ __param(2, (0, type_graphql_1.Arg)('pagination', type => shell_1.Pagination, { nullable: true })),
1050
+ __param(3, (0, type_graphql_1.Arg)('sortings', type => [shell_1.Sorting], { nullable: true })),
1051
+ __param(4, (0, type_graphql_1.Arg)('locationSortingRules', type => [shell_1.Sorting], { nullable: true })),
1052
+ __metadata("design:type", Function),
1053
+ __metadata("design:paramtypes", [Object, Array, typeof (_h = typeof shell_1.Pagination !== "undefined" && shell_1.Pagination) === "function" ? _h : Object, Array, Array]),
1054
+ __metadata("design:returntype", Promise)
1055
+ ], InventoryHistoryQuery.prototype, "onhandInventories", null);
1056
+ __decorate([
1057
+ (0, type_graphql_1.FieldResolver)(type => shell_1.Domain),
1058
+ __param(0, (0, type_graphql_1.Root)()),
1059
+ __metadata("design:type", Function),
1060
+ __metadata("design:paramtypes", [inventory_history_1.InventoryHistory]),
1061
+ __metadata("design:returntype", Promise)
1062
+ ], InventoryHistoryQuery.prototype, "domain", null);
1063
+ __decorate([
1064
+ (0, type_graphql_1.FieldResolver)(type => auth_base_1.User),
1065
+ __param(0, (0, type_graphql_1.Root)()),
1066
+ __metadata("design:type", Function),
1067
+ __metadata("design:paramtypes", [inventory_history_1.InventoryHistory]),
1068
+ __metadata("design:returntype", Promise)
1069
+ ], InventoryHistoryQuery.prototype, "updater", null);
1070
+ __decorate([
1071
+ (0, type_graphql_1.FieldResolver)(type => auth_base_1.User),
1072
+ __param(0, (0, type_graphql_1.Root)()),
1073
+ __metadata("design:type", Function),
1074
+ __metadata("design:paramtypes", [inventory_history_1.InventoryHistory]),
1075
+ __metadata("design:returntype", Promise)
1076
+ ], InventoryHistoryQuery.prototype, "creator", null);
1077
+ InventoryHistoryQuery = __decorate([
1078
+ (0, type_graphql_1.Resolver)(inventory_history_1.InventoryHistory)
1079
+ ], InventoryHistoryQuery);
1080
+ exports.InventoryHistoryQuery = InventoryHistoryQuery;
1081
+ async function massageInventorySummary(tx, params, bizplace, context) {
1082
+ await productsQuery(tx, params, bizplace);
1083
+ await filterInventoryQuery(tx, params, bizplace, context);
1084
+ let fromDate = params.filters.find(data => data.name === 'fromDate');
1085
+ let hasTransactionOrBalanceFilter = params.filters.find(data => data.name === 'hasTransactionOrBalance');
1086
+ let hasTransactionOrBalanceQuery = '';
1087
+ if (hasTransactionOrBalanceFilter && hasTransactionOrBalanceFilter.value) {
1088
+ hasTransactionOrBalanceQuery = 'and (opening_qty > 0 or total_in_qty > 0 or adjustment_qty > 0)';
1089
+ }
1090
+ await tx.query(`
1091
+ create temp table temp_inventory_summary as (
1092
+ select src.*,
1093
+ opening_qty + adjustment_qty + total_in_qty + total_out_qty as closing_qty
1094
+ from (
1095
+ select prd.sku AS product_sku, prd.name as product_name, prd.description as product_description, prd.type AS product_type, ih.packing_type, ih.packing_size,
1096
+ sum(case when ih.created_at >= $1 and ih.transaction_type = 'ADJUSTMENT' then ih.qty else 0 end) as adjustment_qty,
1097
+ sum(case when ih.created_at < $1 then qty else 0 end) as opening_qty,
1098
+ sum(case when ih.created_at >= $1 then case when ih.qty > 0 and ih.transaction_type <> 'ADJUSTMENT' then ih.qty else 0 end else 0 end) as total_in_qty,
1099
+ sum(case when ih.created_at >= $1 then case when ih.qty < 0 and ih.transaction_type <> 'ADJUSTMENT' then ih.qty else 0 end else 0 end) as total_out_qty,
1100
+ ih.product_id
1101
+ from temp_inv_history ih
1102
+ inner join temp_products prd on prd.id = ih.product_id
1103
+ group by prd.sku, prd.name, prd.description, prd.type, ih.product_id, ih.packing_type, ih.packing_size
1104
+ ) src
1105
+ where 1=1
1106
+ ${hasTransactionOrBalanceQuery}
1107
+ )
1108
+ `, [fromDate.value]);
1109
+ const total = await tx.query(`select count(*) from temp_inventory_summary`);
1110
+ const result = await tx.query(`
1111
+ select * from temp_inventory_summary ORDER BY product_name, product_description, product_type, packing_type, packing_size OFFSET $1 LIMIT $2
1112
+ `, [(params.pagination.page - 1) * params.pagination.limit, params.pagination.limit]);
1113
+ tx.query(`
1114
+ drop table temp_products, temp_inv_history, temp_inventory_summary
1115
+ `);
1116
+ return [result, total];
1117
+ }
1118
+ async function massageInventoryPalletSummary(tx, params, bizplace, context) {
1119
+ await productsQuery(tx, params, bizplace);
1120
+ await filterInventoryQuery(tx, params, bizplace, context);
1121
+ let fromDate = params.filters.find(data => data.name === 'fromDate');
1122
+ let toDate = params.filters.find(data => data.name === 'toDate');
1123
+ let hasTransactionOrBalanceFilter = params.filters.find(data => data.name === 'hasTransactionOrBalance');
1124
+ let hasTransactionOrBalanceQuery = '';
1125
+ if (hasTransactionOrBalanceFilter && hasTransactionOrBalanceFilter.value) {
1126
+ hasTransactionOrBalanceQuery = 'and (opening_qty > 0 or total_in_qty > 0 or adjustment_qty > 0)';
1127
+ }
1128
+ await tx.query(`
1129
+ create temp table temp_inventory_pallet_summary as (
1130
+ select invh.*,
1131
+ invh.opening_qty + invh.total_in_qty + invh.total_out_qty + invh.adjustment_qty as closing_qty from (
1132
+ select product_sku, product_id, product_name, product_description, product_type,
1133
+ SUM(case when invHistory.created_at < $1 then
1134
+ case when invHistory.status = 'STORED' then 1
1135
+ when invhistory.status = 'TERMINATED' then -1
1136
+ else 0 end
1137
+ else 0 end) as opening_qty,
1138
+ SUM(case when invHistory.created_at >= $1 and invHistory.created_at <= $2 then
1139
+ case when (invHistory.transaction_type = 'UNLOADING' or invHistory.transaction_type = 'NEW') then 1 else 0 end
1140
+ else 0 end) as total_in_qty,
1141
+ SUM(case when invHistory.created_at >= $1 and invHistory.created_at <= $2 then
1142
+ case when invHistory.status = 'TERMINATED' AND invHistory.transaction_type <> 'ADJUSTMENT' then -1 else 0 end
1143
+ else 0 end) as total_out_qty,
1144
+ SUM(case when invHistory.created_at >= $1 and invHistory.created_at <= $2 then
1145
+ case when invHistory.status = 'TERMINATED' AND invHistory.transaction_type = 'ADJUSTMENT' then -1
1146
+ when invHistory.status = 'STORED' AND invHistory.transaction_type = 'ADJUSTMENT' then 1 else 0 end
1147
+ else 0 end) as adjustment_qty
1148
+ from(
1149
+ select pallet_id, seq, status, transaction_type, product_sku, product_id, product_name, product_description, product_type,
1150
+ inventory_history_id, packing_type, packing_size, qty, opening_qty, created_at from (
1151
+ select row_number() over(partition by invh.pallet_id order by invh.created_at asc) as rn, invh.* ,
1152
+ prd.sku as product_sku, prd.name as product_name, prd.description as product_description, prd.type AS product_type
1153
+ from temp_inv_history invh
1154
+ inner join temp_products prd on prd.id = invh.product_id
1155
+ where (transaction_type = 'UNLOADING' or invh.transaction_type = 'NEW')
1156
+ and invh.created_at >= $1
1157
+ ) as invIn where rn = 1
1158
+ union all
1159
+ select pallet_id, seq, status, transaction_type, product_sku, product_id, product_name, product_description, product_type,
1160
+ inventory_history_id, packing_type, packing_size, qty, opening_qty, created_at from (
1161
+ SELECT row_number() over(partition by pallet_id, invh.product_id order by seq asc) as rn,
1162
+ invh.pallet_id, invh.product_id, invh.packing_type, invh.packing_size,
1163
+ invh.batch_id, invh.inventory_history_id,
1164
+ invh.seq, 'STORED' AS status, invh.transaction_type, invh.qty, invh.opening_qty,
1165
+ invh.created_at,
1166
+ prd.sku as product_sku, prd.name as product_name, prd.description as product_description, prd.type AS product_type
1167
+ from temp_inv_history invh
1168
+ inner join temp_products prd on prd.id = invh.product_id
1169
+ where invh.created_at < $1
1170
+ and (invh.status = 'STORED' or invh.status = 'UNLOADED')
1171
+ ) as invStored where rn = 1
1172
+ union all
1173
+ select pallet_id, seq, status, transaction_type, product_sku, product_id, product_name, product_description, product_type,
1174
+ inventory_history_id, packing_type, packing_size, qty, opening_qty, started_at as created_at from (
1175
+ select row_number() over(partition by invh.pallet_id, invh.product_id order by invh.seq desc) as rn, invh.*,
1176
+ prd.sku as product_sku, prd.name as product_name, prd.description as product_description, prd.type AS product_type, repeatedGroup.started_at
1177
+ from temp_inv_history invh
1178
+ inner join (
1179
+ select pallet_id, min(created_at) as started_at, max(created_at) as ended_at, min(seq) as min_seq, max(seq) as max_seq, status from (
1180
+ select startData.*, sum(startflag) over (partition by pallet_id order by seq) as grp from (
1181
+ select s.*,
1182
+ (case when lag(status) over (partition by pallet_id order by seq) = status then 0 else 1 end) as startflag
1183
+ from temp_inv_history s
1184
+ ) startData
1185
+ ) endData
1186
+ group by pallet_id, grp, status
1187
+ ) repeatedGroup on repeatedGroup.pallet_id = invh.pallet_id and repeatedGroup.min_seq <= invh.seq and repeatedGroup.max_seq >= invh.seq
1188
+ inner join temp_products prd on prd.id = invh.product_id
1189
+ ) as invOut where rn = 1 AND status ='TERMINATED'
1190
+ union all
1191
+ SELECT invh.pallet_id, invh.seq, invh.status, invh.transaction_type,
1192
+ prd.sku AS product_sku, invh.product_id, prd.name AS product_name, prd.description AS product_description, prd.type AS product_type,
1193
+ invh.inventory_history_id, invh.packing_type, invh.packing_size, invh.qty, invh.opening_qty, invh.created_at
1194
+ FROM temp_inv_history invh
1195
+ INNER JOIN (
1196
+ SELECT invh.pallet_id, invh.seq AS stored_seq, invh2.seq AS terminated_seq FROM temp_inv_history invh
1197
+ INNER JOIN temp_inv_history invh2 ON invh2.pallet_id = invh.pallet_id AND invh2.status='STORED' AND invh2.seq = invh.seq + 1 AND invh2.product_id <> invh.product_id
1198
+ WHERE invh.transaction_type = 'ADJUSTMENT'
1199
+ ) dt ON dt.pallet_id = invh.pallet_id AND (dt.stored_seq = invh.seq OR dt.terminated_seq = invh.seq)
1200
+ inner join temp_products prd on prd.id = invh.product_id
1201
+ where invh.created_at >= $1
1202
+ ORDER BY product_name, pallet_id, seq
1203
+ ) as invHistory
1204
+ group by product_sku, product_id, product_name, product_description, product_type
1205
+ ) invh
1206
+ where 1=1
1207
+ ${hasTransactionOrBalanceQuery}
1208
+ )
1209
+ `, [fromDate.value, toDate.value]);
1210
+ const total = await tx.query(`select count(*) as count, sum(total_in_qty) as totalInQty, sum(opening_qty) as totalOpeningBal from temp_inventory_pallet_summary`);
1211
+ const result = await tx.query(`
1212
+ select *, 'PALLET' as packing_type from temp_inventory_pallet_summary ORDER BY product_name, product_description OFFSET $1 LIMIT $2
1213
+ `, [(params.pagination.page - 1) * params.pagination.limit, params.pagination.limit]);
1214
+ tx.query(`
1215
+ drop table temp_products, temp_inv_history, temp_inventory_pallet_summary
1216
+ `);
1217
+ return [result, total];
1218
+ }
1219
+ async function productsQuery(tx, params, bizplace) {
1220
+ let product = params.filters.find(data => data.name === 'product');
1221
+ let productDesc = params.filters.find(data => data.name === 'productDescription');
1222
+ let productQuery = '';
1223
+ if (product) {
1224
+ let productValue = product.value
1225
+ .toLowerCase()
1226
+ .split(',')
1227
+ .map(prod => {
1228
+ return "'%" + prod.trim().replace(/'/g, "''") + "%'";
1229
+ })
1230
+ .join(',');
1231
+ productQuery = `AND (
1232
+ Lower(prd.name) LIKE ANY(ARRAY[${productValue}])
1233
+ OR Lower(prd.sku) LIKE ANY(ARRAY[${productValue}])
1234
+ OR Lower(prd.description) LIKE ANY(ARRAY[${productValue}])
1235
+ )`;
1236
+ }
1237
+ let productDescQuery = '';
1238
+ if (productDesc) {
1239
+ productDescQuery = "AND Lower(description) LIKE '%" + productDesc.value.toLowerCase() + "%'";
1240
+ }
1241
+ await tx.query(`
1242
+ create temp table temp_products AS
1243
+ (
1244
+ select prd.id, prd.name, prd.sku, prd.description, prd.id::varchar as product_id, prd.type from products prd
1245
+ inner join bizplaces b on b.id = prd.bizplace_id
1246
+ inner join companies c on c.domain_id = b.domain_id
1247
+ inner join bizplaces b2 on b2.company_id = c.id
1248
+ where b2.id = $1
1249
+ ${productQuery}
1250
+ GROUP BY prd.id, prd.sku, prd.name, prd.description
1251
+ )`, [bizplace.id]);
1252
+ }
1253
+ async function filterInventoryQuery(tx, params, bizplace, context) {
1254
+ let toDate = params.filters.find(data => data.name === 'toDate');
1255
+ let batchNo = params.filters.find(data => data.name === 'batchNo');
1256
+ let batchNoQuery = '';
1257
+ if (batchNo) {
1258
+ batchNoQuery =
1259
+ 'AND Lower(ih.batch_id) LIKE ANY(ARRAY[' +
1260
+ batchNo.value
1261
+ .toLowerCase()
1262
+ .split(',')
1263
+ .map(prod => {
1264
+ return "'%" + prod.trim().replace(/'/g, "''") + "%'";
1265
+ })
1266
+ .join(',') +
1267
+ '])';
1268
+ }
1269
+ await tx.query(`
1270
+ create temp table temp_inv_history as (
1271
+ select i2.pallet_id, ih.product_id::uuid, ih.packing_type, i2.packing_size, ih.batch_id,
1272
+ ih.id as inventory_history_id, ih.seq, ih.status, ih.transaction_type, ih.qty, ih.opening_qty, ih.created_at
1273
+ from inventories i2
1274
+ inner join reduced_inventory_histories ih on ih.pallet_id = i2.pallet_id and ih.domain_id = i2.domain_id
1275
+ where
1276
+ i2.domain_id = $1
1277
+ and i2.bizplace_id = $2
1278
+ and ih.created_at <= $3
1279
+ ${batchNoQuery}
1280
+ )
1281
+ `, [context.state.domain.id, bizplace.id, toDate.value]);
1282
+ }
1283
+ //# sourceMappingURL=inventory-history-query.js.map