@things-factory/operato-wms 4.3.59 → 4.3.62

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 (65) hide show
  1. package/client/pages/components/select-inventory-popup.js +626 -0
  2. package/client/pages/inbound/select-product-batch.js +7 -1
  3. package/client/pages/inbound/unload-product.js +75 -25
  4. package/client/pages/inventory/inventory-adjustment.js +1 -1
  5. package/client/pages/inventory/inventory-by-product-detail.js +99 -92
  6. package/client/pages/inventory/inventory-by-product.js +170 -68
  7. package/client/pages/inventory-check/inspecting-product.js +1 -1
  8. package/client/pages/order/release-order/b2b/b2b-order-list.js +76 -80
  9. package/client/pages/order/release-order/b2c/b2c-order-requests.js +93 -81
  10. package/client/pages/order/release-order/batch-picking-popup.js +11 -0
  11. package/client/pages/order/release-order/create-release-order.js +258 -252
  12. package/client/pages/order/release-order/release-extra-product-popup.js +10 -3
  13. package/client/pages/order/release-order/release-order-detail.js +202 -63
  14. package/client/pages/order/transport-order/delivery-note-popup.js +12 -17
  15. package/client/pages/order/transport-order/upload-delivery-note.js +6 -4
  16. package/client/pages/order/transport-order/view-delivery-note.js +0 -1
  17. package/client/pages/outbound/generate-worksheet-popup.js +337 -0
  18. package/client/pages/outbound/inventory-reassign-popup.js +1097 -0
  19. package/client/pages/outbound/loading-product.js +2 -2
  20. package/client/pages/outbound/picking-product.js +174 -100
  21. package/client/pages/outbound/sorting-product.js +5 -5
  22. package/client/pages/outbound/worksheet-batch-picking.js +39 -5
  23. package/client/pages/outbound/worksheet-picking.js +45 -6
  24. package/client/pages/report/outbound-order-details-report.js +181 -49
  25. package/client/pages/report/release-inventory-report.js +503 -0
  26. package/client/route.js +5 -0
  27. package/dist-server/graphql/resolvers/dashboard/outbound-order-by-status.js +3 -3
  28. package/dist-server/graphql/resolvers/extra/add-release-good-products.js +54 -3
  29. package/dist-server/graphql/resolvers/extra/add-release-good-products.js.map +1 -1
  30. package/dist-server/graphql/resolvers/reports/index.js +2 -1
  31. package/dist-server/graphql/resolvers/reports/index.js.map +1 -1
  32. package/dist-server/graphql/resolvers/reports/outbound-order-details-report.js +63 -28
  33. package/dist-server/graphql/resolvers/reports/outbound-order-details-report.js.map +1 -1
  34. package/dist-server/graphql/resolvers/reports/release-inventory-report.js +180 -0
  35. package/dist-server/graphql/resolvers/reports/release-inventory-report.js.map +1 -0
  36. package/dist-server/graphql/types/reports/index.js +6 -1
  37. package/dist-server/graphql/types/reports/index.js.map +1 -1
  38. package/dist-server/graphql/types/reports/outbound-order-details-report.js +14 -1
  39. package/dist-server/graphql/types/reports/outbound-order-details-report.js.map +1 -1
  40. package/dist-server/graphql/types/reports/release-inventory-report-list.js +14 -0
  41. package/dist-server/graphql/types/reports/release-inventory-report-list.js.map +1 -0
  42. package/dist-server/graphql/types/reports/release-inventory-report.js +29 -0
  43. package/dist-server/graphql/types/reports/release-inventory-report.js.map +1 -0
  44. package/dist-server/utils/report-query-util.js +4 -2
  45. package/dist-server/utils/report-query-util.js.map +1 -1
  46. package/helps/release-note.ko.md +13 -7
  47. package/helps/release-note.md +13 -7
  48. package/helps/release-note.ms.md +13 -7
  49. package/helps/release-note.zh.md +13 -7
  50. package/package.json +10 -10
  51. package/server/graphql/resolvers/dashboard/outbound-order-by-status.ts +3 -3
  52. package/server/graphql/resolvers/extra/add-release-good-products.ts +66 -3
  53. package/server/graphql/resolvers/reports/index.ts +3 -1
  54. package/server/graphql/resolvers/reports/outbound-order-details-report.ts +66 -29
  55. package/server/graphql/resolvers/reports/release-inventory-report.ts +202 -0
  56. package/server/graphql/types/reports/index.ts +6 -1
  57. package/server/graphql/types/reports/outbound-order-details-report.ts +14 -1
  58. package/server/graphql/types/reports/release-inventory-report-list.ts +8 -0
  59. package/server/graphql/types/reports/release-inventory-report.ts +23 -0
  60. package/server/utils/report-query-util.ts +4 -2
  61. package/things-factory.config.js +4 -0
  62. package/translations/en.json +73 -16
  63. package/translations/ko.json +157 -110
  64. package/translations/ms.json +65 -16
  65. package/translations/zh.json +79 -29
@@ -0,0 +1,503 @@
1
+ import '@things-factory/form-ui'
2
+ import '@things-factory/grist-ui'
3
+ import '../inventory/inventory-by-product-detail'
4
+
5
+ import gql from 'graphql-tag'
6
+ import { css, html } from 'lit-element'
7
+ import { connect } from 'pwa-helpers/connect-mixin'
8
+
9
+ import { getCodeByName } from '@things-factory/code-base'
10
+ import { i18next, localize } from '@things-factory/i18n-base'
11
+ import { client, gqlContext, PageView, store } from '@things-factory/shell'
12
+ import { flattenObject, isMobileDevice } from '@things-factory/utils'
13
+
14
+ class ReleaseInventoryReport extends connect(store)(localize(i18next)(PageView)) {
15
+ static get styles() {
16
+ return css`
17
+ :host {
18
+ display: flex;
19
+ flex-direction: column;
20
+ width: 100%;
21
+ }
22
+
23
+ data-grist {
24
+ overflow-y: auto;
25
+ flex: 1;
26
+ }
27
+ `
28
+ }
29
+
30
+ static get properties() {
31
+ return {
32
+ _searchFields: Object,
33
+ _config: Object,
34
+ _gristData: Object,
35
+ data: Object
36
+ }
37
+ }
38
+
39
+ get context() {
40
+ return {
41
+ title: i18next.t('title.release_inventory_report'),
42
+ exportable: {
43
+ name: i18next.t('title.release_inventory_report'),
44
+ data: this._exportableData.bind(this)
45
+ },
46
+ help: 'operato-wms/report/release-inventory-report'
47
+ }
48
+ }
49
+
50
+ get dataGrist() {
51
+ return this.shadowRoot.querySelector('data-grist')
52
+ }
53
+
54
+ get searchForm() {
55
+ return this.shadowRoot.querySelector('search-form')
56
+ }
57
+
58
+ get _bizplaceSelector() {
59
+ return this.searchForm.shadowRoot.querySelector('select[name=bizplace]')
60
+ }
61
+
62
+ get _fromDateInput() {
63
+ return this.searchForm.shadowRoot.querySelector('input[name=fromDate]')
64
+ }
65
+
66
+ get _toDateInput() {
67
+ return this.searchForm.shadowRoot.querySelector('input[name=toDate]')
68
+ }
69
+
70
+ render() {
71
+ return html`
72
+ <search-form id="search-form" .fields=${this._searchFields} @submit=${e => this.dataGrist.fetch()}></search-form>
73
+
74
+ <data-grist
75
+ .mode=${isMobileDevice() ? 'LIST' : 'GRID'}
76
+ .config=${this._config}
77
+ .fetchHandler="${this.fetchHandler.bind(this)}"
78
+ ></data-grist>
79
+ `
80
+ }
81
+
82
+ get searchFields() {
83
+ return [
84
+ {
85
+ label: i18next.t('field.company'),
86
+ name: 'bizplace',
87
+ type: 'select',
88
+ options: [
89
+ { value: '' },
90
+ ...this._partners
91
+ .map(partner => {
92
+ return {
93
+ name: `${partner.name} ${partner.description ? `(${partner.description})` : ''}`,
94
+ value: partner.id
95
+ }
96
+ })
97
+ .sort(this._compareValues('name', 'asc'))
98
+ ],
99
+ props: { searchOper: 'eq' }
100
+ },
101
+ {
102
+ label: i18next.t('field.product_info'),
103
+ name: 'product',
104
+ type: 'string',
105
+ props: { searchOper: 'in' }
106
+ },
107
+ {
108
+ label: i18next.t('field.order_info'),
109
+ name: 'order',
110
+ type: 'string',
111
+ props: { searchOper: 'in' }
112
+ },
113
+ {
114
+ label: i18next.t('field.order_date'),
115
+ name: 'orderDate',
116
+ type: 'date',
117
+ props: {
118
+ searchOper: 'eq'
119
+ }
120
+ },
121
+ {
122
+ label: i18next.t('field.lot_id'),
123
+ name: 'palletId',
124
+ type: 'text',
125
+ props: { searchOper: 'eq' }
126
+ },
127
+ {
128
+ label: i18next.t('field.carton_id'),
129
+ name: 'cartonId',
130
+ type: 'text',
131
+ props: { searchOper: 'eq' }
132
+ }
133
+ ]
134
+ }
135
+
136
+ get reportConfig() {
137
+ let columns = [
138
+ { type: 'gutter', gutterName: 'sequence' },
139
+ {
140
+ type: 'string',
141
+ name: 'bizplace|name',
142
+ header: i18next.t('field.company'),
143
+ width: 200
144
+ },
145
+ {
146
+ type: 'string',
147
+ name: 'product|sku',
148
+ header: i18next.t('field.sku'),
149
+ width: 150
150
+ },
151
+ {
152
+ type: 'string',
153
+ name: 'product|name',
154
+ header: i18next.t('field.product_name'),
155
+ width: 200
156
+ },
157
+ {
158
+ type: 'string',
159
+ name: 'product|description',
160
+ header: i18next.t('field.product_description'),
161
+ width: 300
162
+ },
163
+ {
164
+ type: 'string',
165
+ name: 'product|brand',
166
+ header: i18next.t('field.product_brand'),
167
+ width: 150
168
+ },
169
+ {
170
+ type: 'string',
171
+ name: 'packingType',
172
+ header: i18next.t('field.packing_type'),
173
+ width: 150
174
+ },
175
+ {
176
+ type: 'float',
177
+ name: 'assignedQty',
178
+ header: i18next.t('field.assigned_qty'),
179
+ width: 120
180
+ },
181
+ {
182
+ type: 'float',
183
+ name: 'assignedUomValue',
184
+ header: i18next.t('field.assigned_uom_value'),
185
+ width: 120
186
+ },
187
+ {
188
+ type: 'float',
189
+ name: 'assignedUom',
190
+ header: i18next.t('field.assigned_uom'),
191
+ width: 120
192
+ },
193
+ {
194
+ type: 'string',
195
+ name: 'orderNo',
196
+ header: i18next.t('field.order_no'),
197
+ width: 150
198
+ },
199
+ {
200
+ type: 'string',
201
+ name: 'type',
202
+ header: i18next.t('field.order_type'),
203
+ width: 100
204
+ },
205
+ {
206
+ type: 'datetime',
207
+ name: 'orderAt',
208
+ header: i18next.t('field.order_date'),
209
+ width: 170
210
+ },
211
+ {
212
+ type: 'string',
213
+ name: 'releaseDate',
214
+ header: i18next.t('field.execute_date'),
215
+ width: 170
216
+ },
217
+ {
218
+ type: 'string',
219
+ name: 'palletId',
220
+ header: i18next.t('field.lot_id'),
221
+ width: 150
222
+ },
223
+ {
224
+ type: 'string',
225
+ name: 'cartonId',
226
+ header: i18next.t('field.carton_id'),
227
+ width: 150
228
+ },
229
+ {
230
+ type: 'string',
231
+ name: 'batchId',
232
+ header: i18next.t('field.batch_id'),
233
+ width: 150
234
+ },
235
+ {
236
+ type: 'string',
237
+ name: 'batchIdRef',
238
+ header: i18next.t('field.batch_id_ref'),
239
+ width: 150
240
+ },
241
+ {
242
+ type: 'string',
243
+ name: 'expirationDate',
244
+ header: i18next.t('field.exp_date'),
245
+ width: 170
246
+ },
247
+ {
248
+ type: 'string',
249
+ name: 'manufactureDate',
250
+ header: i18next.t('field.manufacture_date'),
251
+ width: 170
252
+ },
253
+ {
254
+ type: 'string',
255
+ name: 'location|name',
256
+ header: i18next.t('field.location'),
257
+ width: 150
258
+ }
259
+ ]
260
+ let list = {
261
+ fields: [
262
+ 'bizplace|name',
263
+ 'product|sku',
264
+ 'product|name',
265
+ 'product|description',
266
+ 'product|brand',
267
+ 'packingType',
268
+ 'assignedQty',
269
+ 'assignedUomValue',
270
+ 'assignedUom',
271
+ 'orderNo',
272
+ 'type',
273
+ 'orderAt',
274
+ 'releaseDate',
275
+ 'palletId',
276
+ 'cartonId',
277
+ 'batchId',
278
+ 'batchIdRef',
279
+ 'expirationDate',
280
+ 'manufactureDate',
281
+ 'location|name'
282
+ ]
283
+ }
284
+
285
+ return {
286
+ columns: columns,
287
+ list,
288
+ pagination: { limit: 100, pages: [100, 200, 500, 1000] },
289
+ rows: {
290
+ selectable: false,
291
+ insertable: false,
292
+ appendable: false
293
+ }
294
+ }
295
+ }
296
+
297
+ async pageInitialized() {
298
+ this._gristData = { total: 0, records: [] }
299
+ this._products = []
300
+
301
+ const [_partnersReq] = await Promise.allSettled([this._fetchPartners()])
302
+
303
+ this._partners = _partnersReq.status == 'fulfilled' ? _partnersReq.value : []
304
+
305
+ this._searchFields = this.searchFields
306
+ this._config = this.reportConfig
307
+ }
308
+
309
+ async pageUpdated(changes, lifecycle) {
310
+ if (this.active) {
311
+ this.dataGrist.fetch()
312
+ }
313
+ }
314
+
315
+ async fetchHandler({ page, limit, sorters = [] }) {
316
+ try {
317
+ this._validate()
318
+ let filters = this.searchForm.queryFilters.map(filter => {
319
+ switch (filter.name) {
320
+ case 'orderDate':
321
+ let orderDt = new Date(filter.value)
322
+ orderDt.setHours(0)
323
+ filter.value = orderDt.toISOString()
324
+ break
325
+ default:
326
+ break
327
+ }
328
+ return filter
329
+ })
330
+
331
+ const pagination = { page, limit }
332
+ const sortings = sorters
333
+
334
+ const response = await client.query({
335
+ query: gql`
336
+ query releaseInventoryReport($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
337
+ releaseInventoryReport(filters: $filters, pagination: $pagination, sortings: $sortings) {
338
+ items {
339
+ bizplace {
340
+ name
341
+ description
342
+ }
343
+ product {
344
+ sku
345
+ name
346
+ description
347
+ brand
348
+ }
349
+ packingType
350
+ assignedQty
351
+ assignedUomValue
352
+ assignedUom
353
+ orderNo
354
+ type
355
+ orderAt
356
+ releaseDate
357
+ palletId
358
+ cartonId
359
+ batchId
360
+ batchIdRef
361
+ expirationDate
362
+ manufactureDate
363
+ location {
364
+ name
365
+ }
366
+ }
367
+ total
368
+ }
369
+ }
370
+ `,
371
+ variables: { filters, pagination, sortings },
372
+ context: gqlContext()
373
+ })
374
+
375
+ const data = {
376
+ total: response.data.releaseInventoryReport.total,
377
+ records:
378
+ response.data.releaseInventoryReport.items.map(itm => {
379
+ return flattenObject({
380
+ ...itm,
381
+ releaseDate: itm.releaseDate ? new Date(itm.releaseDate).toLocaleDateString() : '',
382
+ expirationDate: itm.expirationDate ? new Date(parseInt(itm.expirationDate)).toLocaleDateString() : '',
383
+ manufactureDate: itm.manufactureDate ? new Date(parseInt(itm.manufactureDate)).toLocaleDateString() : ''
384
+ })
385
+ }) || []
386
+ }
387
+
388
+ this._gristData = {
389
+ ...data
390
+ }
391
+
392
+ return data
393
+ } catch (e) {
394
+ this._showToast(e)
395
+ }
396
+ }
397
+
398
+ async _fetchPartners() {
399
+ const filters = []
400
+ const response = await client.query({
401
+ query: gql`
402
+ query partnersBizplaces($filters: [Filter!]) {
403
+ partnersBizplaces(filters: $filters) {
404
+ items {
405
+ id
406
+ name
407
+ description
408
+ }
409
+ }
410
+ }
411
+ `,
412
+ variables: { filters }
413
+ })
414
+
415
+ if (!response.errors) {
416
+ return response.data.partnersBizplaces.items
417
+ }
418
+ }
419
+ _validate() {
420
+ if (!this.searchForm.shadowRoot.querySelector('form').checkValidity())
421
+ throw new Error(i18next.t('text.invalid_form_value'))
422
+ if (!this._bizplaceSelector.value) throw new Error(i18next.t('text.no_company_selected'))
423
+ }
424
+
425
+ _compareValues(key, order = 'asc') {
426
+ return function innerSort(a, b) {
427
+ if (!a.hasOwnProperty(key) || !b.hasOwnProperty(key)) {
428
+ return 0
429
+ }
430
+
431
+ const varA = typeof a[key] === 'string' ? a[key].toUpperCase() : a[key]
432
+ const varB = typeof b[key] === 'string' ? b[key].toUpperCase() : b[key]
433
+
434
+ let comparison = 0
435
+ if (varA > varB) {
436
+ comparison = 1
437
+ } else if (varA < varB) {
438
+ comparison = -1
439
+ }
440
+ return order === 'desc' ? comparison * -1 : comparison
441
+ }
442
+ }
443
+
444
+ _submit(e) {
445
+ this._config = { ...this.reportConfig }
446
+ this.searchForm.submit()
447
+ }
448
+
449
+ async _exportableData() {
450
+ try {
451
+ var headerSetting = [
452
+ { header: i18next.t('field.company'), key: 'bizplace|name', width: 60, type: 'string' },
453
+ { header: i18next.t('field.sku'), key: 'product|sku', width: 25, type: 'string' },
454
+ { header: i18next.t('field.product_name'), key: 'product|name', width: 50, type: 'string' },
455
+ { header: i18next.t('field.product_description'), key: 'product|description', width: 50, type: 'string' },
456
+ { header: i18next.t('field.product_brand'), key: 'product|brand', width: 25, type: 'string' },
457
+ { header: i18next.t('field.packing_type'), key: 'packingType', width: 30, type: 'string' },
458
+ { header: i18next.t('field.assigned_qty'), key: 'assignedQty', width: 20, type: 'string' },
459
+ { header: i18next.t('field.assigned_uom_value'), key: 'assignedUomValue', width: 20, type: 'string' },
460
+ { header: i18next.t('field.assigned_uom'), key: 'assignedUom', width: 20, type: 'string' },
461
+ { header: i18next.t('field.order_no'), key: 'orderNo', width: 30, type: 'string' },
462
+ { header: i18next.t('field.order_type'), key: 'type', width: 20, type: 'string' },
463
+ { header: i18next.t('field.order_date'), key: 'orderAt', width: 15, type: 'string' },
464
+ { header: i18next.t('field.execute_date'), key: 'releaseDate', width: 15, type: 'string' },
465
+ { header: i18next.t('field.lot_id'), key: 'palletId', width: 20, type: 'string' },
466
+ { header: i18next.t('field.carton_id'), key: 'cartonId', width: 20, type: 'string' },
467
+ { header: i18next.t('field.batch_id'), key: 'batchId', width: 20, type: 'string' },
468
+ { header: i18next.t('field.batch_id_ref'), key: 'batchIdRef', width: 20, type: 'string' },
469
+ { header: i18next.t('field.exp_date'), key: 'expirationDate', width: 15, type: 'string' },
470
+ { header: i18next.t('field.manufacture_date'), key: 'manufactureDate', width: 15, type: 'string' },
471
+ { header: i18next.t('field.location'), key: 'location|name', width: 15, type: 'string' }
472
+ ]
473
+
474
+ let data = (await this.fetchHandler({ page: 1, limit: 9999999 })).records.map(itm => {
475
+ return {
476
+ ...itm,
477
+ orderAt: itm.orderAt ? new Date(parseInt(itm.orderAt)).toLocaleString() : ''
478
+ }
479
+ })
480
+ var exportData = {
481
+ header: [...headerSetting],
482
+ data
483
+ }
484
+
485
+ return exportData
486
+ } catch (e) {
487
+ this._showToast(e)
488
+ }
489
+ }
490
+
491
+ _showToast({ type, message }) {
492
+ document.dispatchEvent(
493
+ new CustomEvent('notify', {
494
+ detail: {
495
+ type,
496
+ message
497
+ }
498
+ })
499
+ )
500
+ }
501
+ }
502
+
503
+ window.customElements.define('release-inventory-report', ReleaseInventoryReport)
package/client/route.js CHANGED
@@ -475,6 +475,11 @@ export default function route(page) {
475
475
  case 'costing_report':
476
476
  import('./pages/report/costing-report')
477
477
  return page
478
+
479
+ case 'release_inventory_report':
480
+ import('./pages/report/release-inventory-report')
481
+ return page
482
+
478
483
  /**
479
484
  * Custom ELCCL Menus Section
480
485
  */
@@ -85,20 +85,20 @@ exports.outboundOrderByStatusResolver = {
85
85
  WHERE w."domain_id" = $1
86
86
  AND w."bizplace_id" IN (${bizplaceIds})
87
87
  AND w."type" = 'PICKING'
88
- AND w."status" IN ('DEACTIVATED','EXECUTING','PENDING_CANCEL')
88
+ AND w."status" IN ('DEACTIVATED','EXECUTING')
89
89
  GROUP BY w."status"
90
90
  UNION ALL
91
91
  SELECT 'BATCH PICKING ASSIGNED' AS "status", count(*) FROM worksheets w
92
92
  WHERE w."domain_id" = $1
93
93
  AND w."bizplace_id" IN (${bizplaceIds})
94
94
  AND w."type" = 'BATCH_PICKING'
95
- AND w."status" IN ('DEACTIVATED','EXECUTING','PENDING_CANCEL')
95
+ AND w."status" IN ('DEACTIVATED','EXECUTING')
96
96
  GROUP BY w."status"
97
97
  UNION ALL
98
98
  SELECT 'PACKING' AS "status", count(*) FROM worksheets w
99
99
  WHERE w."domain_id" = $1 AND w."type" = 'PACKING'
100
100
  AND w."bizplace_id" IN (${bizplaceIds})
101
- AND w."status" IN ('DEACTIVATED','EXECUTING','PENDING_CANCEL')
101
+ AND w."status" IN ('DEACTIVATED','EXECUTING')
102
102
  GROUP BY w."status"
103
103
  UNION ALL
104
104
  SELECT 'PENDING MANIFEST CREATION' AS "status", count(*) FROM release_goods rg
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addReleaseGoodProducts = void 0;
4
+ const typeorm_1 = require("typeorm");
4
5
  const product_base_1 = require("@things-factory/product-base");
5
6
  const sales_base_1 = require("@things-factory/sales-base");
6
7
  const warehouse_base_1 = require("@things-factory/warehouse-base");
@@ -12,7 +13,7 @@ exports.addReleaseGoodProducts = {
12
13
  const { tx, user, domain } = context.state;
13
14
  let releaseGood = await tx.getRepository(sales_base_1.ReleaseGood).findOne({
14
15
  where: { domain, name: name },
15
- relations: ['bizplace']
16
+ relations: ['bizplace', 'orderProducts']
16
17
  });
17
18
  const bizplace = releaseGood.bizplace;
18
19
  let pickingWorksheet = await tx.getRepository(worksheet_base_1.Worksheet).findOne({
@@ -135,11 +136,22 @@ exports.addReleaseGoodProducts = {
135
136
  newOrderInv.creator = user;
136
137
  newOrderInv.updater = user;
137
138
  let existingOrderInv;
139
+ let existingOrderProduct = await tx.getRepository(sales_base_1.OrderProduct).findOne({
140
+ where: {
141
+ domain,
142
+ releaseGood,
143
+ batchId: oi.batchId,
144
+ packingType: oi.packingType,
145
+ product: newOrderInv.product
146
+ }
147
+ });
138
148
  // check if it is release by inventory (has inventory value) or product
139
149
  if ((_b = newOrderInv.inventory) === null || _b === void 0 ? void 0 : _b.id) {
140
150
  // if release by inventory, then quantity and uomValue values are updated
141
151
  const foundInv = await tx.getRepository(warehouse_base_1.Inventory).findOne(newOrderInv.inventory.id);
142
152
  newOrderInv.inventory = foundInv;
153
+ newOrderInv.uom = (oi === null || oi === void 0 ? void 0 : oi.uom) || foundInv.uom;
154
+ newOrderInv.batchIdRef = (oi === null || oi === void 0 ? void 0 : oi.batchIdRef) || foundInv.batchIdRef;
143
155
  // check for existing released OrderInventory specifying product, batchId, packingType, and inventory
144
156
  existingOrderInv = await tx.getRepository(sales_base_1.OrderInventory).findOne({
145
157
  where: {
@@ -155,7 +167,9 @@ exports.addReleaseGoodProducts = {
155
167
  foundInv.updater = user;
156
168
  let newOrderProduct = Object.assign(new sales_base_1.OrderProduct(), newOrderInv);
157
169
  newOrderProduct = Object.assign(Object.assign({}, newOrderProduct), { packQty: 0, actualPackQty: 0, palletQty: 0, actualPalletQty: 0, status: sales_base_1.ORDER_PRODUCT_STATUS.ASSIGNED });
158
- newOrderProduct = await tx.getRepository(sales_base_1.OrderProduct).save(newOrderProduct);
170
+ if (!existingOrderProduct)
171
+ newOrderProduct = await tx.getRepository(sales_base_1.OrderProduct).save(newOrderProduct);
172
+ newOrderInv.orderProduct = existingOrderProduct ? existingOrderProduct : newOrderProduct;
159
173
  await tx.getRepository(warehouse_base_1.Inventory).save(foundInv);
160
174
  }
161
175
  else {
@@ -188,7 +202,7 @@ exports.addReleaseGoodProducts = {
188
202
  }
189
203
  });
190
204
  if (existingWorksheetDetail) {
191
- existingWorksheetDetail = Object.assign(Object.assign({}, existingWorksheetDetail), { status: worksheet_base_1.WORKSHEET_STATUS.DEACTIVATED });
205
+ existingWorksheetDetail = Object.assign(Object.assign({}, existingWorksheetDetail), { targetProduct: newOrderInv.orderProduct, status: worksheet_base_1.WORKSHEET_STATUS.DEACTIVATED });
192
206
  await tx.getRepository(worksheet_base_1.WorksheetDetail).save(existingWorksheetDetail);
193
207
  }
194
208
  }
@@ -201,11 +215,14 @@ exports.addReleaseGoodProducts = {
201
215
  savedOrderInv.releaseQty = newOrderInv.releaseQty;
202
216
  savedOrderInv.releaseUomValue = newOrderInv.releaseUomValue;
203
217
  savedOrderInv.batchId = newOrderInv.batchId;
218
+ savedOrderInv.batchIdRef = newOrderInv.batchIdRef;
204
219
  savedOrderInv.packingType = newOrderInv.packingType;
220
+ savedOrderInv.uom = newOrderInv.uom;
205
221
  savedOrderInv.product = newOrderInv.product;
206
222
  savedOrderInv.inventory = newOrderInv.inventory;
207
223
  savedOrderInv.status = newOrderInv.status;
208
224
  savedOrderInv.releaseGood = newOrderInv.releaseGood;
225
+ savedOrderInv.orderProduct = newOrderInv.orderProduct;
209
226
  savedOrderInv.bizplace = newOrderInv.bizplace;
210
227
  savedOrderInv.domain = domain;
211
228
  savedOrderInv.creator = user;
@@ -231,6 +248,40 @@ exports.addReleaseGoodProducts = {
231
248
  loadingWorksheet = Object.assign(Object.assign({}, loadingWorksheet), { status: worksheet_base_1.WORKSHEET_STATUS.DEACTIVATED });
232
249
  await tx.getRepository(worksheet_base_1.Worksheet).save(loadingWorksheet);
233
250
  }
251
+ // Update Order Product Release Qty
252
+ let rgOrderProducts = await tx
253
+ .getRepository(sales_base_1.OrderProduct)
254
+ .find({ where: { domain, releaseGood } });
255
+ await Promise.all(rgOrderProducts.map(async (op) => {
256
+ const orderInventories = await tx.getRepository(sales_base_1.OrderInventory).find({
257
+ where: {
258
+ domain,
259
+ releaseGood,
260
+ orderProduct: op,
261
+ status: (0, typeorm_1.Not)((0, typeorm_1.In)([
262
+ sales_base_1.ORDER_INVENTORY_STATUS.TERMINATED,
263
+ sales_base_1.ORDER_INVENTORY_STATUS.CANCELLED,
264
+ sales_base_1.ORDER_INVENTORY_STATUS.PENDING_CANCEL
265
+ ]))
266
+ }
267
+ });
268
+ let totalReleaseQty = orderInventories.reduce((total, currentValue) => {
269
+ total += currentValue.releaseQty;
270
+ return total;
271
+ }, 0);
272
+ let totalReleaseUomValue = orderInventories.reduce((total, currentValue) => {
273
+ total += currentValue.releaseUomValue;
274
+ return total;
275
+ }, 0);
276
+ let updateOPInfo = {
277
+ releaseQty: totalReleaseQty,
278
+ releaseUomValue: totalReleaseUomValue
279
+ };
280
+ if (totalReleaseQty <= 0) {
281
+ updateOPInfo.status = sales_base_1.ORDER_PRODUCT_STATUS.TERMINATED;
282
+ }
283
+ await tx.getRepository(sales_base_1.OrderProduct).update({ id: op.id }, updateOPInfo);
284
+ }));
234
285
  }
235
286
  catch (error) {
236
287
  throw error;