@things-factory/operato-wms 4.3.258 → 4.3.261

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.
@@ -52,10 +52,8 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
52
52
  customerBizplaceId: String,
53
53
  partnerBizplaceId: String,
54
54
  inventoryGristConfig: Object,
55
- vasGristConfig: Object,
56
55
  inventoryData: Object,
57
56
  orderInventoryData: Object,
58
- vasData: Object,
59
57
  _attachments: Array,
60
58
  _status: String,
61
59
  _mimetype: String,
@@ -108,7 +106,12 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
108
106
  _showExportInfo: Boolean,
109
107
  _showVasInfo: Boolean,
110
108
  _showVasSummary: Boolean,
111
- currentTab: Object
109
+ currentTab: Object,
110
+
111
+ // Vas //
112
+ vasGristConfig: Object,
113
+ vasData: Object,
114
+ deletedVas: Array
112
115
  }
113
116
  }
114
117
 
@@ -746,26 +749,13 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
746
749
  .data="${this.vasData}"
747
750
  @record-change="${this._onVasChangeHandler.bind(this)}"
748
751
  ></data-grist>
749
- <!-- disable editing of vas -->
750
- <!-- <div class="vas-button-container">
751
- ${this._editVasStatus.indexOf(this._status) >= 0
752
- ? html`
753
- <mwc-button
754
- raised
755
- @click="${this._updateVass.bind(this)}"
756
- label="${i18next.t('button.update_vas')}"
757
- }
758
- ></mwc-button>
759
- `
760
- : ''}
761
- </div> -->
762
752
  </div>
763
753
  </div>
764
754
 
765
755
  <div class="container" ?hidden=${this._showVasSummary}>
766
756
  <!-- <search-form id="search-form" .fields=${this._searchFields} @submit=${e =>
767
757
  this.report.fetch()}></search-form> -->
768
- <data-report .config=${this.vasSummaryConfig} .data=${this.vasData}></data-report>
758
+ <data-report .config=${this.vasSummaryConfig} .data=${this.vasGrist?.dirtyData}></data-report>
769
759
  </div>
770
760
  `
771
761
  }
@@ -801,6 +791,7 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
801
791
  this._showExportInfo = true
802
792
  this._showVasInfo = true
803
793
  this._showVasSummary = true
794
+ this.deletedVas = []
804
795
  }
805
796
 
806
797
  _openTrackingInformation() {
@@ -904,6 +895,14 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
904
895
  }
905
896
  }
906
897
 
898
+ if (this.isUserBelongsDomain && this._editVasStatus.indexOf(this._status) >= 0) {
899
+ actions.push({
900
+ title: i18next.t('button.edit_vas'),
901
+ action: this.editVas.bind(this),
902
+ ...CommonButtonStyles.edit
903
+ })
904
+ }
905
+
907
906
  if (this._status === ORDER_STATUS.PENDING.value) {
908
907
  actions.push(
909
908
  {
@@ -1143,7 +1142,6 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
1143
1142
  ]
1144
1143
  }
1145
1144
 
1146
- const enableVasEditing = false
1147
1145
  this.vasGristConfig = {
1148
1146
  list: {
1149
1147
  fields: [
@@ -1168,12 +1166,12 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
1168
1166
  handlers: {
1169
1167
  click: (columns, data, column, record, rowIndex) => {
1170
1168
  this._selectedVasRecordIdx = rowIndex
1171
- if (enableVasEditing && this._editVasStatus.indexOf(this._status) >= 0) {
1169
+ if (this._editVasStatus.indexOf(this._status) >= 0) {
1172
1170
  if (column.name === 'productSKU') {
1173
1171
  this._openTargetProductVasPopup(record)
1174
1172
  }
1175
1173
  if (column.name === 'newSku') {
1176
- this._openBulkProductSelectionForVas(this._selectBy, rowIndex)
1174
+ this._openBulkProductSelectionForVas(this._selectBy, rowIndex, record)
1177
1175
  }
1178
1176
  if (column.name === 'vas') {
1179
1177
  try {
@@ -1196,16 +1194,17 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
1196
1194
  type: 'gutter',
1197
1195
  gutterName: 'button',
1198
1196
  icon: 'close',
1199
- hidden: !enableVasEditing,
1200
1197
  handlers: {
1201
1198
  click: (columns, data, column, record, rowIndex) => {
1202
- if (enableVasEditing && this._editVasStatus.indexOf(this._status) >= 0) {
1199
+ if (this._editVasStatus.indexOf(this._status) >= 0) {
1200
+ this.deletedVas.push({ ...record, cuFlag: '-' })
1203
1201
  this.vasData = {
1204
1202
  ...this.vasData,
1205
1203
  records: data.records.filter((rec, idx) =>
1206
- record?.id ? record.group !== rec.group : idx !== rowIndex
1204
+ record.productSKU ? rec.group !== record.group : idx !== rowIndex
1207
1205
  )
1208
1206
  }
1207
+ const test = this.vasData
1209
1208
  }
1210
1209
  }
1211
1210
  }
@@ -1226,7 +1225,7 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
1226
1225
  type: 'integer',
1227
1226
  name: 'qty',
1228
1227
  header: i18next.t('field.qty'),
1229
- record: { editable: enableVasEditing, options: { min: 0 } },
1228
+ record: { editable: true, options: { min: 0 } }, // try to make a condition
1230
1229
  width: 80
1231
1230
  },
1232
1231
  {
@@ -1258,17 +1257,17 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
1258
1257
  hidden: true
1259
1258
  },
1260
1259
  {
1261
- type: 'string',
1260
+ type: 'object',
1262
1261
  name: 'vas',
1263
1262
  header: i18next.t('field.vas'),
1264
- record: { editable: enableVasEditing },
1263
+ record: { editable: true },
1265
1264
  width: 250
1266
1265
  },
1267
1266
  {
1268
1267
  type: 'integer',
1269
1268
  name: 'vasQty',
1270
1269
  header: i18next.t('field.vas_qty'),
1271
- record: { editable: enableVasEditing, options: { min: 0 } },
1270
+ record: { editable: true, options: { min: 0 } },
1272
1271
  width: 80
1273
1272
  },
1274
1273
  {
@@ -1278,35 +1277,41 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
1278
1277
  width: 200
1279
1278
  },
1280
1279
  {
1281
- type: 'string',
1280
+ type: 'code',
1282
1281
  name: 'newPackingType',
1283
1282
  header: i18next.t('field.packing_type_sku', { sku: 'N.SKU' }),
1283
+ record: {
1284
+ editable: true,
1285
+ codeName: 'PACKING_TYPES'
1286
+ },
1284
1287
  width: 150
1285
1288
  },
1286
1289
  {
1287
- type: 'string',
1290
+ type: 'code',
1288
1291
  name: 'newUom',
1289
1292
  header: i18next.t('field.uom_sku', { sku: 'N.SKU' }),
1293
+ record: { editable: true, codeName: 'UOM' },
1290
1294
  width: 80
1291
1295
  },
1292
1296
  {
1293
1297
  type: 'integer',
1294
1298
  name: 'newUomValue',
1295
1299
  header: i18next.t('field.uom_value_sku', { sku: 'N.SKU' }),
1300
+ record: { editable: true, options: { min: 0 } },
1296
1301
  width: 80
1297
1302
  },
1298
1303
  {
1299
1304
  type: 'integer',
1300
1305
  name: 'outputQty',
1301
1306
  header: i18next.t('field.output_qty'),
1302
- record: { editable: enableVasEditing, options: { min: 0 } },
1307
+ record: { editable: true, options: { min: 0 } },
1303
1308
  width: 80
1304
1309
  },
1305
1310
  {
1306
1311
  type: 'string',
1307
1312
  name: 'remark',
1308
1313
  header: i18next.t('field.remark'),
1309
- record: { editable: enableVasEditing },
1314
+ record: { editable: true },
1310
1315
  width: 150
1311
1316
  }
1312
1317
  ]
@@ -1392,6 +1397,10 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
1392
1397
  name
1393
1398
  description
1394
1399
  }
1400
+ productDetail {
1401
+ id
1402
+ name
1403
+ }
1395
1404
  uom
1396
1405
  releaseQty
1397
1406
  releaseUomValue
@@ -1445,13 +1454,13 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
1445
1454
  id
1446
1455
  name
1447
1456
  orderVasItems {
1457
+ id
1448
1458
  vas {
1449
1459
  id
1450
1460
  name
1451
1461
  }
1452
1462
  vasQty
1453
1463
  }
1454
- targetBatchId
1455
1464
  batchId
1456
1465
  product {
1457
1466
  id
@@ -1459,19 +1468,25 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
1459
1468
  description
1460
1469
  sku
1461
1470
  }
1471
+ productDetail {
1472
+ id
1473
+ name
1474
+ uom
1475
+ }
1462
1476
  newProduct {
1463
1477
  id
1464
1478
  name
1479
+ description
1465
1480
  sku
1466
1481
  }
1467
1482
  newProductDetail {
1483
+ id
1484
+ name
1468
1485
  packingType
1469
1486
  uomValue
1470
1487
  uom
1471
1488
  }
1472
- productDetail {
1473
- uom
1474
- }
1489
+ productName
1475
1490
  outputQty
1476
1491
  packingType
1477
1492
  qty
@@ -1613,6 +1628,7 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
1613
1628
  records: orderInventories
1614
1629
  }
1615
1630
 
1631
+ this.deletedVas = []
1616
1632
  this.vasData = {
1617
1633
  records: orderVass
1618
1634
  .sort((a, b) => a.set - b.set)
@@ -1633,16 +1649,16 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
1633
1649
  if (idx == 0) {
1634
1650
  acc[acc.length - 1] = {
1635
1651
  ...acc[acc.length - 1],
1636
- orderVasItemId: itm.vas.id,
1652
+ orderVasItemId: itm.id,
1637
1653
  group: groupIdx,
1638
- vas: itm.vas.name,
1654
+ vas: { id: itm.vas.id, name: itm.vas.name },
1639
1655
  vasQty: itm.vasQty
1640
1656
  }
1641
1657
  } else {
1642
1658
  acc.push({
1643
- orderVasItemId: itm.vas.id,
1659
+ orderVasItemId: itm.id,
1644
1660
  group: groupIdx,
1645
- vas: itm.vas.name,
1661
+ vas: { id: itm.vas.id, name: itm.vas.name },
1646
1662
  vasQty: itm.vasQty
1647
1663
  })
1648
1664
  }
@@ -2075,72 +2091,54 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
2075
2091
  _openTargetProductVasPopup(record) {
2076
2092
  try {
2077
2093
  // marked for refactor 15 Jun 2023 by @ChrisLim-git
2094
+ let targetList = this.formatVasTargetproductData()
2078
2095
  this.checkInventoryValidity()
2079
2096
  openPopup(
2080
2097
  html`
2081
2098
  <vas-target-product-popup
2082
- .targetList="${this.inventoryGrist.dirtyData.records
2083
- .map(record => {
2084
- const unitUomValue = record.releaseUomValue / record.releaseQty
2085
- let packQty = record.releaseQty
2086
-
2087
- if (this.vasData.records?.length) {
2088
- const existVasData = this.vasData.records.filter(vasRecord => {
2089
- const isSamePackingType = !!(record.packingType === vasRecord.packingType)
2090
- switch (vasRecord.targetType) {
2091
- case VAS_BATCH_AND_PRODUCT_TYPE:
2092
- return (
2093
- record.batchId === vasRecord.target.batchId &&
2094
- record.product.id === vasRecord.target.productId &&
2095
- isSamePackingType
2096
- )
2097
- case VAS_BATCH_NO_TYPE:
2098
- return record.batchId === vasRecord.target && isSamePackingType
2099
- case VAS_PRODUCT_TYPE:
2100
- return record.product.id === vasRecord.target && isSamePackingType
2101
- }
2102
- })
2103
-
2104
- if (existVasData?.length) {
2105
- let assignedQty = 0
2106
-
2107
- existVasData.forEach(dt => {
2108
- assignedQty += dt.qty
2109
- })
2110
-
2111
- packQty -= assignedQty
2112
- }
2113
- }
2114
-
2115
- delete record.__dirty__
2116
- delete record.__dirtyfields__
2117
- return {
2118
- ...record,
2119
- packQty,
2120
- unitUomValue,
2121
- totalUomValue: record.releaseUomValue * packQty
2122
- }
2123
- })
2124
- .filter(record => record.packQty > 0)}"
2099
+ .targetList="${targetList}"
2125
2100
  .vasList="${this.vasData.records}"
2126
2101
  .record="${record}"
2127
2102
  @selected="${selected => {
2128
- let group = this.vasGrist.data.records[this.vasGrist.data.records.length - 1].group
2103
+ let group = this.vasGrist.data.records[this.vasGrist.data.records.length - 1]?.group
2104
+ ? this.vasGrist.data.records[this.vasGrist.data.records.length - 1]?.group
2105
+ : 0
2129
2106
 
2130
2107
  const newRecords = selected.detail.map(d => {
2131
2108
  return {
2132
- ...d,
2133
- id: null,
2109
+ ...record,
2110
+ batchId: d.batchId,
2111
+ id: record.id,
2134
2112
  sku: d.productSKU,
2135
2113
  maxQty: d.releaseQty,
2136
2114
  uomValue: d.releaseUomValue / d.releaseQty,
2137
- group: ++group
2115
+ group: record.group ? record.group : ++group,
2116
+ unitUomValue: d.unitUomValue,
2117
+ packingSize: d.packingSize,
2118
+ packingType: d.packingType,
2119
+ product: d.product,
2120
+ productDetail: d.productDetail,
2121
+ productSKU: d.productSKU,
2122
+ uom: d.uom,
2123
+ status: record.status,
2124
+ cuFlag: 'M',
2125
+ __dirty__: 'M',
2126
+ __dirtyfields__:
2127
+ record.__dirtyfields__ === {}
2128
+ ? { ...record.__dirtyfields__, productSKU: { before: record.productSKU, after: d.productSKU } }
2129
+ : {
2130
+ productSKU: { before: record.productSKU, after: d.productSKU }
2131
+ // qty: { before: record.qty, after: d.qty }
2132
+ }
2133
+
2134
+ // group: ++group
2138
2135
  }
2139
2136
  })
2140
2137
 
2141
2138
  if (this.vasGrist.dirtyData.records.length !== this._selectedVasRecordIdx) {
2142
2139
  // update existing vasData records
2143
2140
  this.vasGrist.dirtyData.records.splice(this._selectedVasRecordIdx, 1, ...newRecords)
2141
+ this.vasGrist.dirtyRecords.push(newRecords)
2144
2142
 
2145
2143
  this.vasData = {
2146
2144
  ...this.vasData,
@@ -2169,7 +2167,7 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
2169
2167
  }
2170
2168
  }
2171
2169
 
2172
- _openBulkProductSelectionForVas(type, rowIndex) {
2170
+ _openBulkProductSelectionForVas(type, rowIndex, record) {
2173
2171
  openPopup(
2174
2172
  html`
2175
2173
  <select-product-popup
@@ -2186,22 +2184,34 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
2186
2184
  newUom: e.detail.uom,
2187
2185
  newProductId: e.detail.product.id,
2188
2186
  newUomValue: e.detail.uomValue,
2189
- newProductDetailId: e.detail.productDetailId
2187
+ newProductDetailId: e.detail.productDetailId,
2188
+ cuFlag: 'M',
2189
+ __dirty__: 'M',
2190
+ __dirtyfields__:
2191
+ record.__dirtyfields__ === {}
2192
+ ? { ...record.__dirtyfields_, newSku: { before: record.newSku, after: e.detail.product.sku } }
2193
+ : { newSku: { before: record.newSku, after: e.detail.product.sku } }
2194
+ }
2195
+ // for (let i = 0; i < e.detail.multipleProducts.length; i++) {
2196
+ // newRecords.push(e.detail.multipleProducts[i])
2197
+ // }
2198
+ // update existing vas data records
2199
+ if (!record.product?.id) {
2200
+ rowIndex = this.vasGrist.dirtyData.records.findIndex(d => d.group === record.group)
2190
2201
  }
2191
-
2192
2202
  this.vasGrist.dirtyData.records.splice(rowIndex, 1, {
2193
2203
  ...this.vasGrist.dirtyData.records[rowIndex],
2194
2204
  ...newRecords
2195
2205
  })
2196
-
2197
2206
  this.vasGrist.dirtyData.records.map(record => {
2198
2207
  record.newSku
2199
- ? record.qty
2208
+ ? record.outputQty
2209
+ ? (record.newUomValue = record.outputQty * record.newUomValue)
2210
+ : record.qty
2200
2211
  ? (record.newUomValue = record.qty * record.newUomValue)
2201
2212
  : record.newUomValue
2202
2213
  : (record.newUomValue = null)
2203
2214
  })
2204
-
2205
2215
  this.vasData = {
2206
2216
  ...this.vasData,
2207
2217
  records: [...this.vasGrist.dirtyData.records]
@@ -2226,49 +2236,76 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
2226
2236
  html`
2227
2237
  <select-vas-popup
2228
2238
  @selected="${e => {
2229
- let newRecords = e.detail
2230
-
2231
- let currentData = this.vasData.filter(vd => vd.group == record.group)
2232
- // for (let i = 0; i < e.detail.length; i++) {
2233
- // newRecords.push({ ...record, vas: e.detail[i] })
2234
- // }
2235
- // if (newRecords.length == 1) {
2236
- // // update existing inventory data records
2237
- // this.vasGrist.dirtyData.records.splice(rowIndex, 1, {
2238
- // ...this.vasGrist.dirtyData.records[rowIndex],
2239
- // ...newRecords[0]
2240
- // })
2241
- // this.vasData = {
2242
- // ...this.vasData,
2243
- // records: [...this.vasGrist.dirtyData.records]
2244
- // }
2245
- // } else {
2246
- // // update existing inventory data records
2247
- // this.vasGrist.dirtyData.records.splice(rowIndex, 1, {
2248
- // ...this.vasGrist.dirtyData.records[rowIndex],
2249
- // ...newRecords[0]
2250
- // })
2251
- // this.vasData = {
2252
- // ...this.vasData,
2253
- // records: [...this.vasGrist.dirtyData.records]
2254
- // }
2255
- // // add new data
2256
- // newRecords = newRecords.slice(1).map(nrecord => {
2257
- // return {
2258
- // vasGristId: record.vasGristId,
2259
- // vasQty: nrecord.vasQty,
2260
- // vas: nrecord.vas
2261
- // }
2262
- // })
2263
- // this.vasData = {
2264
- // ...this.vasData,
2265
- // records: [...this.vasGrist.dirtyData.records, ...newRecords]
2266
- // }
2267
- // }
2268
- // this.vasData = {
2269
- // ...this.vasData,
2270
- // records: this.sortByNameField(this.vasData.records, 'vasGristId')
2271
- // }
2239
+ let newRecords = []
2240
+ for (let i = 0; i < e.detail.length; i++) {
2241
+ newRecords.push({ ...record, vas: e.detail[i] })
2242
+ }
2243
+ if (!record.vas) {
2244
+ // if no VAS data, it will update the vas and add new rows
2245
+ if (newRecords.length == 1) {
2246
+ // update existing inventory data records
2247
+ this.vasGrist.dirtyData.records.splice(rowIndex, 1, {
2248
+ ...this.vasGrist.dirtyData.records[rowIndex],
2249
+ ...newRecords[0]
2250
+ })
2251
+ this.vasData = {
2252
+ ...this.vasData,
2253
+ records: [...this.vasGrist.dirtyData.records]
2254
+ }
2255
+ } else {
2256
+ // update existing inventory data records
2257
+ this.vasGrist.dirtyData.records.splice(rowIndex, 1, {
2258
+ ...this.vasGrist.dirtyData.records[rowIndex],
2259
+ ...newRecords[0]
2260
+ })
2261
+ this.vasData = {
2262
+ ...this.vasData,
2263
+ records: [...this.vasGrist.dirtyData.records]
2264
+ }
2265
+ // add new data
2266
+ newRecords = newRecords.slice(1).map(nrecord => {
2267
+ return {
2268
+ group: record.group,
2269
+ vasQty: nrecord.vasQty,
2270
+ vas: nrecord.vas
2271
+ }
2272
+ })
2273
+ this.vasData = {
2274
+ ...this.vasData,
2275
+ records: [...this.vasGrist.dirtyData.records, ...newRecords]
2276
+ }
2277
+ }
2278
+ } else {
2279
+ // if vas column is already there add new data ONLY
2280
+ newRecords = newRecords.map(nrecord => {
2281
+ if (this.vasData.records.find(v => v.group === nrecord.group && v.vas.id === nrecord.vas.id)) {
2282
+ throw new Error(
2283
+ this._showToast({
2284
+ message: i18next.t('text.duplicated_value_field', { field: i18next.t('field.vas') })
2285
+ })
2286
+ )
2287
+ }
2288
+ return {
2289
+ group: record.group,
2290
+ vasQty: nrecord.vasQty,
2291
+ vas: nrecord.vas,
2292
+ cuFlag: '+',
2293
+ __dirty__: '+',
2294
+ __dirtyfields__:
2295
+ record.__dirtyfields__ === {}
2296
+ ? { ...record.__dirtyfields_, vas: { before: record.vas, after: nrecord.vas } }
2297
+ : { vas: { before: record.vas, after: nrecord.vas } }
2298
+ }
2299
+ })
2300
+ this.vasData = {
2301
+ ...this.vasData,
2302
+ records: [...this.vasGrist.dirtyData.records, ...newRecords]
2303
+ }
2304
+ }
2305
+ this.vasData = {
2306
+ ...this.vasData,
2307
+ records: this.sortByNameField(this.vasData.records, 'group', 'product')
2308
+ }
2272
2309
  }}"
2273
2310
  ></select-vas-popup>
2274
2311
  `,
@@ -2293,7 +2330,7 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
2293
2330
  { column: 'releaseQty' },
2294
2331
  { column: 'packingType' },
2295
2332
  { column: 'uom' },
2296
- { column: 'releaseUomValue' }
2333
+ { column: 'uomValue' }
2297
2334
  ],
2298
2335
  totals: []
2299
2336
  },
@@ -2339,10 +2376,10 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
2339
2376
  },
2340
2377
  {
2341
2378
  type: 'number',
2342
- name: 'releaseUomValue',
2379
+ name: 'uomValue',
2343
2380
  header: i18next.t('field.release_uom_value'),
2344
2381
  sortable: false,
2345
- imex: { header: i18next.t('field.release_uom_value'), key: 'releaseUomValue', width: 25, type: 'string' },
2382
+ imex: { header: i18next.t('field.release_uom_value'), key: 'uomValue', width: 25, type: 'string' },
2346
2383
  width: 150
2347
2384
  },
2348
2385
  {
@@ -2363,10 +2400,10 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
2363
2400
  },
2364
2401
  {
2365
2402
  type: 'string',
2366
- name: 'newSKU',
2403
+ name: 'newSku',
2367
2404
  header: i18next.t('field.new_sku'),
2368
2405
  sortable: false,
2369
- imex: { header: i18next.t('field.new_sku'), key: 'newSKU', width: 25, type: 'string' },
2406
+ imex: { header: i18next.t('field.new_sku'), key: 'newSku', width: 25, type: 'string' },
2370
2407
  width: 150
2371
2408
  },
2372
2409
  {
@@ -2447,51 +2484,113 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
2447
2484
  }
2448
2485
 
2449
2486
  _onVasChangeHandler(event) {
2450
- // this._updateVasTargets()
2451
2487
  const initialRecord = event.detail.before
2452
2488
  const changeRecord = event.detail.after
2453
2489
  const changedColumn = event.detail.column.name
2454
-
2490
+ const inventoryData = this.inventoryData.records.find(
2491
+ invData =>
2492
+ invData.productId === event.detail.after.productId &&
2493
+ invData.productDetailId === event.detail.after.productDetailId &&
2494
+ invData.batchId === event.detail.after.batchId
2495
+ )
2496
+ const totalQtyVas = this.vasGrist.dirtyData.records.reduce(
2497
+ (total, vas) =>
2498
+ vas.qty &&
2499
+ vas.productId === changeRecord.productId &&
2500
+ vas.productDetailId === changeRecord.productDetailId &&
2501
+ vas.batchId === changeRecord.batchId
2502
+ ? total + vas.qty
2503
+ : total,
2504
+ 0
2505
+ )
2506
+ const totalReleaseQty = this.inventoryData.records.reduce(
2507
+ (total, inv) =>
2508
+ inv.releaseQty &&
2509
+ inv.productId === changeRecord.productId &&
2510
+ inv.productDetailId === changeRecord.productDetailId &&
2511
+ inv.batchId === changeRecord.batchId
2512
+ ? total + inv.releaseQty
2513
+ : total,
2514
+ 0
2515
+ )
2516
+ //
2455
2517
  try {
2518
+ if (
2519
+ changedColumn === 'qty' ||
2520
+ changedColumn === 'newPackingType' ||
2521
+ changedColumn === 'newUom' ||
2522
+ changedColumn === 'newUomValue' ||
2523
+ changedColumn === 'outputQty' ||
2524
+ changedColumn === 'remark'
2525
+ )
2526
+ if (!changeRecord.productId && !changeRecord.productDetailId && !changeRecord.batchId) {
2527
+ delete event.detail.after[event.detail.column.name]
2528
+ const index = this.vasGrist.dirtyData.records.findIndex(
2529
+ d => d.group === changeRecord.group && d.product?.id && d.productDetail?.id && d.batchId
2530
+ )
2531
+ throw new Error(
2532
+ i18next.t('text.please_enter_value_on_row_row', {
2533
+ row: `[ ${index + 1} ] ${this.vasGrist.dirtyData.records[index].product.sku} (${
2534
+ this.vasGrist.dirtyData.records[index].batchId
2535
+ }) `
2536
+ })
2537
+ )
2538
+ }
2456
2539
  if (changedColumn === 'qty') {
2457
2540
  if (changeRecord.qty === undefined) throw new Error(i18next.t('text.there_is_no_selected_items'))
2458
2541
  // total up the qty
2459
- if (
2460
- this.vasData.records
2461
- .filter(vas => vas.sku === changeRecord.sku && vas.batchId == changeRecord.batchId && vas.qty)
2462
- .map(a => a.qty)
2463
- .reduce((a, b) => a + b, 0) > initialRecord.maxQty
2464
- ) {
2465
- throw new Error(i18next.t('text.qty_exceed_release_qty'))
2542
+ if (changeRecord.qty <= 0 || isNaN(changeRecord.qty)) {
2543
+ throw new Error(i18next.t('text.invalid_quantity_input'))
2466
2544
  }
2467
- if (changeRecord.qty > initialRecord.maxQty) {
2545
+ if (totalQtyVas > totalReleaseQty) {
2468
2546
  throw new Error(i18next.t('text.qty_exceed_release_qty'))
2469
- } else if (changeRecord.qty <= 0) {
2470
- throw new Error(i18next.t('text.invalid_quantity_input'))
2471
- } else {
2472
- let uomValue = initialRecord.releaseUomValue / initialRecord.releaseQty
2473
- let newUomValue = initialRecord.newUomValue
2474
- ? initialRecord.qty
2475
- ? initialRecord.newUomValue / initialRecord.qty
2476
- : initialRecord.newUomValue
2477
- : null
2478
- changeRecord.uomValue = uomValue * changeRecord.qty
2479
- changeRecord.newUomValue ? (changeRecord.newUomValue = changeRecord.qty * newUomValue) : null
2480
- changeRecord.vasQty = changeRecord.qty
2481
- changeRecord.outputQty = changeRecord.qty
2482
- }
2483
- } else if (changedColumn === 'outputQty' || changedColumn === 'vasQty' || changedColumn === 'newUomValue') {
2484
- if (changeRecord.outputQty === undefined || changeRecord.vasQty === undefined)
2485
- throw new Error(i18next.t('text.there_is_no_selected_items'))
2486
- if (
2547
+ }
2548
+
2549
+ //to change uom, vasQty
2550
+ let uomValue = inventoryData.releaseUomValue / inventoryData.releaseQty
2551
+ let newUomValue = initialRecord.newUomValue
2552
+ ? initialRecord.qty
2553
+ ? initialRecord.newUomValue / initialRecord.qty
2554
+ : initialRecord.newUomValue
2555
+ : null
2556
+ changeRecord.uomValue = uomValue * changeRecord.qty
2557
+ changeRecord.newUomValue
2558
+ ? initialRecord.outputQty
2559
+ ? initialRecord.outputQty
2560
+ : (changeRecord.newUomValue = changeRecord.qty * newUomValue)
2561
+ : null
2562
+ changeRecord.vasQty = changeRecord.qty
2563
+ changeRecord.outputQty = initialRecord.outputQty ? initialRecord.outputQty : null
2564
+ //
2565
+ } else if (changedColumn === 'outputQty' || changedColumn === 'newUomValue') {
2566
+ if (changeRecord.outputQty === undefined) throw new Error(i18next.t('text.there_is_no_selected_items'))
2567
+ else if (
2487
2568
  changeRecord.outputQty <= 0 ||
2488
- changeRecord.vasQty <= 0 ||
2569
+ isNaN(changeRecord.outputQty) ||
2489
2570
  (initialRecord.newProductId && initialRecord.productId && changeRecord.newUomValue <= 0)
2490
2571
  ) {
2491
2572
  throw new Error(i18next.t('text.invalid_quantity_input'))
2573
+ } else if (changedColumn === 'outputQty' && changeRecord.newProductId && changeRecord.newProductDetailId) {
2574
+ if (initialRecord.outputQty == null) {
2575
+ const totalUomValue = changeRecord.outputQty * (changeRecord.newUomValue / changeRecord.qty)
2576
+ changeRecord.newUomValue = totalUomValue
2577
+ } else {
2578
+ const totalUomValue = changeRecord.outputQty * (initialRecord.newUomValue / initialRecord.outputQty)
2579
+ changeRecord.newUomValue = totalUomValue
2580
+ }
2581
+ }
2582
+ } else if (changedColumn === 'vasQty') {
2583
+ if (changeRecord.vasQty <= 0 || isNaN(changeRecord.vasQty)) {
2584
+ throw new Error(i18next.t('text.invalid_quantity_input'))
2585
+ }
2586
+ } else if (changedColumn === 'outputQty') {
2587
+ if (changeRecord.outputQty <= 0 || isNaN(changeRecord.outputQty)) {
2588
+ throw new Error(i18next.t('text.invalid_quantity_input'))
2492
2589
  }
2493
2590
  }
2494
- // this._updateVasTargets()
2591
+
2592
+ //
2593
+ debugger
2495
2594
  } catch (e) {
2496
2595
  const beforeValue = event.detail.before && event.detail.before[event.detail.column.name]
2497
2596
  if (beforeValue) {
@@ -2623,61 +2722,6 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
2623
2722
  }
2624
2723
  }
2625
2724
 
2626
- _updateVass() {
2627
- try {
2628
- let patches = this.vasGrist.data.records
2629
-
2630
- // const result = await CustomAlert({
2631
- // title: i18next.t('title.are_you_sure'),
2632
- // text: i18next.t('text.update_vas_order'),
2633
- // confirmButton: { text: i18next.t('button.submit') },
2634
- // cancelButton: { text: i18next.t('button.cancel') }
2635
- // })
2636
-
2637
- // if (!result.value) return
2638
-
2639
- // if (patches.length === 0) {
2640
- // throw new Error(i18next.t('text.nothing_changed'))
2641
- // }
2642
-
2643
- // patches = patches.map(patch => {
2644
- // return {
2645
- // id: patch.id,
2646
- // name: patch.name,
2647
- // product: { id: patch.product.id },
2648
- // qty: patch.qty,
2649
- // uomValue: patch.totalUomValue,
2650
- // // vas: { id: patch.orderVasItems.reduce((vasList = [], ovi) => [...vasList.push(ovi.vas.id)]) }
2651
- // vas: { id: patch.orderVasItems.map(ovi => ovi.vas.id) },
2652
- // vasQty: patch.orderVasItems.map(ovi => ovi.vasQty),
2653
- // newProduct: patch.newProduct?.id,
2654
- // outputQty: patch.outputQty,
2655
- // remark: patch.remark,
2656
- // cuFlag: 'M'
2657
- // }
2658
- // })
2659
-
2660
- // const response = await client.mutate({
2661
- // mutation: gql`
2662
- // mutation updateMultipleOrderVas($patches: [OrderVasPatch!]!) {
2663
- // updateMultipleOrderVas(patches: $patches) {
2664
- // id
2665
- // name
2666
- // }
2667
- // }
2668
- // `,
2669
- // variables: { patches }
2670
- // })
2671
-
2672
- // if (!response.errors) {
2673
- // this._showToast({ message: i18next.t('text.vas_order_updated') })
2674
- // await this._fetchReleaseOrder()
2675
- // }
2676
- } catch (e) {
2677
- this._showToast(e)
2678
- }
2679
- }
2680
-
2681
2725
  _openContactPointSelector() {
2682
2726
  openPopup(
2683
2727
  html`
@@ -2937,6 +2981,127 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
2937
2981
  this._fillupForm(this.shippingInfoForm, remapData)
2938
2982
  }
2939
2983
 
2984
+ async editVas() {
2985
+ try {
2986
+ this._validateVas()
2987
+ let orderVasPatch = []
2988
+ let orderVasItemPatch = []
2989
+ let vasStatus = this._releaseOrder.status === 'READY_TO_PICK' ? 'READY_TO_PROCESS' : 'PENDING_RECEIVE'
2990
+
2991
+ orderVasPatch = this.vasGrist.dirtyRecords.filter(
2992
+ p =>
2993
+ p.__dirtyfields__.qty ||
2994
+ p.__dirtyfields__.outputQty ||
2995
+ p.__dirtyfields__.productSKU ||
2996
+ p.__dirtyfields__.newSku
2997
+ )
2998
+ orderVasItemPatch = orderVasItemPatch = this.vasGrist.dirtyRecords.filter(
2999
+ p =>
3000
+ p.__dirtyfields__.vasQty ||
3001
+ (p.__dirtyfields__.vas &&
3002
+ (!p.__dirtyfields__.qty ||
3003
+ !p.__dirtyfields__.outputQty ||
3004
+ !p.__dirtyfields__.productSKU ||
3005
+ !p.__dirtyfields__.newSku))
3006
+ )
3007
+ // new Data
3008
+ // can include below since only
3009
+ // remove this
3010
+ // orderVasPatch = orderVasPatch.concat(
3011
+ // this.vasGrist.dirtyData.records
3012
+ // .filter(v => !v.id)
3013
+ // .map(v => {
3014
+ // return { ...v, cuFlag: '+' }
3015
+ // })
3016
+ // )
3017
+
3018
+ // deleted Data
3019
+ orderVasPatch = orderVasPatch.concat(this.deletedVas.filter(del => del.id))
3020
+ orderVasItemPatch = orderVasItemPatch.concat(this.deletedVas.filter(del => !del.id && del.orderVasItemId))
3021
+
3022
+ orderVasPatch = orderVasPatch.map(ov => {
3023
+ return {
3024
+ id: ov.id,
3025
+ bizplace: !ov.id && ov.cuFlag !== '-' ? this._releaseOrder.bizplace : undefined,
3026
+ releaseGood: !ov.id && ov.cuFlag !== '-' ? { id: this._releaseOrderId } : undefined,
3027
+ batchId: ov.batchId,
3028
+ qty: ov.qty,
3029
+ product: { id: ov.product.id, name: ov.product.name },
3030
+ name: !ov.name ? `${ov.batchId} (${ov.sku})- ${new Date().toISOString()}` : undefined,
3031
+ productName: !ov.productName ? ov.product.name : undefined,
3032
+ productDetail: { id: ov.productDetail.id, name: ov.productDetail.name },
3033
+ status: !ov.id && ov.cuFlag !== '-' ? vasStatus : undefined,
3034
+ packingType: ov.packingType,
3035
+ uom: ov.uom,
3036
+ uomValue: ov.uomValue,
3037
+ newProduct: ov.newProductId,
3038
+ newProductDetail: ov.newProductDetailId,
3039
+ newPackingType: ov.newPackingType,
3040
+ newUom: ov.newUom,
3041
+ newUomValue: ov.newUomValue,
3042
+ outputQty: ov.outputQty ? ov.outputQty : ov.qty,
3043
+ orderVasItemsPatch:
3044
+ !ov.id && ov.cuFlag !== '-'
3045
+ ? this.vasGrist.dirtyData.records.reduce((acc, cur) => {
3046
+ if (cur.group === ov.group) {
3047
+ return [...acc, { vas: { id: cur.vas.id, name: cur.vas.name }, vasQty: cur.vasQty, cuFlag: '+' }]
3048
+ } else {
3049
+ return acc
3050
+ }
3051
+ }, [])
3052
+ : undefined,
3053
+ cuFlag: !ov.id ? '+' : ov.cuFlag ? ov.cuFlag : ov.__dirty__
3054
+ }
3055
+ })
3056
+
3057
+ orderVasItemPatch = orderVasItemPatch
3058
+ .map(ovi => {
3059
+ return {
3060
+ id: ovi.orderVasItemId,
3061
+ vas: { id: ovi.vas.id, name: ovi.vas.name },
3062
+ orderVas: { id: this.vasData.records.find(vasData => ovi.group === vasData.group && vasData.id)?.id },
3063
+ vasQty: ovi.vasQty,
3064
+ cuFlag: !ovi.orderVasItemId ? '+' : ovi.cuFlag ? ovi.cuFlag : ovi.__dirty__
3065
+ }
3066
+ })
3067
+ .filter(ovi => ovi.orderVas.id)
3068
+
3069
+ // delete ovi ; if ov ? (1)delete ovi based on ov , (2) delete wd based on ov and then (3) delete ov
3070
+ // delete worksheet if no data anymore
3071
+ // if (this.vasGrist.dirtyData.records.length) {
3072
+ // debugger
3073
+ // }
3074
+ const result = await CustomAlert({
3075
+ title: i18next.t('title.are_you_sure'),
3076
+ text: i18next.t('text.edit_vas'),
3077
+ confirmButton: { text: i18next.t('button.confirm') },
3078
+ cancelButton: { text: i18next.t('button.cancel') }
3079
+ })
3080
+
3081
+ if (!result.value) return
3082
+
3083
+ const response = await client.mutate({
3084
+ mutation: gql`
3085
+ mutation editVas($orderVasPatch: [OrderVasPatch], $orderVasItemPatch: [OrderVasItemPatch], $orderNo: String) {
3086
+ editVas(orderVasPatch: $orderVasPatch, orderVasItemPatch: $orderVasItemPatch, orderNo: $orderNo)
3087
+ }
3088
+ `,
3089
+ variables: {
3090
+ orderVasPatch: orderVasPatch,
3091
+ orderVasItemPatch: orderVasItemPatch,
3092
+ orderNo: this._releaseOrderNo
3093
+ }
3094
+ })
3095
+
3096
+ if (!response.errors) {
3097
+ this._showToast({ message: i18next.t('text.vas_edited') })
3098
+ this._fetchReleaseOrder()
3099
+ }
3100
+ } catch (e) {
3101
+ this._showToast(e)
3102
+ }
3103
+ }
3104
+
2940
3105
  _validateCountry(e) {
2941
3106
  if (e.target.value != 'MY') {
2942
3107
  this._selectedCountry = e.target.value
@@ -2953,6 +3118,122 @@ class ReleaseOrderDetail extends connect(store)(localize(i18next)(PageView)) {
2953
3118
  }
2954
3119
  }
2955
3120
 
3121
+ _validateVas() {
3122
+ const roData = this.inventoryData.records
3123
+ roData.find(ro => {
3124
+ let newSku = []
3125
+ this.vasGrist.dirtyData.records.map(vas => {
3126
+ if (vas.sku === ro.productSKU && vas.batchId === ro.batchId && vas.newSku) {
3127
+ newSku.push(vas)
3128
+ }
3129
+ })
3130
+ if (newSku.length > 1) {
3131
+ const totalVasReleaseQty = newSku.map(vas => vas.qty).reduce((a, b) => a + b, 0)
3132
+ if (totalVasReleaseQty > ro.releaseQty) {
3133
+ throw new Error(i18next.t('text.qty_vas_exceed_release_qty_sku', { sku: `${ro.productSKU} (${ro.batchId})` }))
3134
+ }
3135
+ }
3136
+ })
3137
+ this.vasGrist.dirtyData.records.find(record => {
3138
+ if (!record.qty && record.productSKU)
3139
+ throw new Error(i18next.t('text.empty_field_field', { field: i18next.t('field.qty') }))
3140
+ if ((record.newPackingType || record.newUomValue || record.newUom) && !record.newSku)
3141
+ throw new Error(i18next.t('text.empty_field_field', { field: i18next.t('field.new_sku') }))
3142
+ if (!record.vasQty) throw new Error(i18next.t('text.empty_field_field', { field: i18next.t('field.vas_qty') }))
3143
+ if (!record.vas) throw new Error(i18next.t('text.empty_field_field', { field: i18next.t('field.vas') }))
3144
+ if (record.newSku) {
3145
+ if (!record.newPackingType) {
3146
+ throw new Error(
3147
+ i18next.t('text.empty_field_field', { field: i18next.t('field.packing_type_sku', { sku: 'NEW SKU' }) })
3148
+ )
3149
+ }
3150
+ if (!record.newUom) {
3151
+ throw new Error(
3152
+ i18next.t('text.empty_field_field', { field: i18next.t('field.uom_sku', { sku: 'NEW SKU' }) })
3153
+ )
3154
+ }
3155
+ if (!record.newUomValue) {
3156
+ throw new Error(
3157
+ i18next.t('text.empty_field_field', { field: i18next.t('field.uom_value_sku', { sku: 'NEW SKU' }) })
3158
+ )
3159
+ }
3160
+ }
3161
+ if (record.newUomValue < 0) {
3162
+ throw new Error(
3163
+ i18next.t('text.negative_value_field', { field: i18next.t('field.uom_value_sku', { sku: 'NEW SKU' }) })
3164
+ )
3165
+ }
3166
+ })
3167
+ }
3168
+
3169
+ formatVasTargetproductData() {
3170
+ let data = []
3171
+ data = this.inventoryGrist.dirtyData.records
3172
+ .map(record => {
3173
+ const unitUomValue = record.releaseUomValue / record.releaseQty
3174
+ let packQty = record.releaseQty
3175
+
3176
+ if (this.vasData.records?.length) {
3177
+ const existVasData = this.vasData.records.filter(vasRecord => {
3178
+ const isSamePackingType = !!(record.packingType === vasRecord.packingType)
3179
+ switch (vasRecord.targetType) {
3180
+ case VAS_BATCH_AND_PRODUCT_TYPE:
3181
+ return (
3182
+ record.batchId === vasRecord.target.batchId &&
3183
+ record.product.id === vasRecord.target.productId &&
3184
+ isSamePackingType
3185
+ )
3186
+ case VAS_BATCH_NO_TYPE:
3187
+ return record.batchId === vasRecord.target && isSamePackingType
3188
+ case VAS_PRODUCT_TYPE:
3189
+ return record.product.id === vasRecord.target && isSamePackingType
3190
+ }
3191
+ })
3192
+
3193
+ if (existVasData?.length) {
3194
+ let assignedQty = 0
3195
+
3196
+ existVasData.forEach(dt => {
3197
+ assignedQty += dt.qty
3198
+ })
3199
+
3200
+ packQty -= assignedQty
3201
+ }
3202
+ }
3203
+
3204
+ delete record.__dirty__
3205
+ delete record.__dirtyfields__
3206
+ return {
3207
+ ...record,
3208
+ packQty,
3209
+ unitUomValue,
3210
+ totalUomValue: record.releaseUomValue * packQty
3211
+ }
3212
+ })
3213
+ .filter(record => record.packQty > 0)
3214
+
3215
+ if (this._orderMethod === 'SELECT_BY_PRODUCT') {
3216
+ this.vasFormattedData = data
3217
+ } else if ((this._orderMethod = 'SELECT_BY_PALLET')) {
3218
+ // this is a function to group by product Id, productDetail Id and batchId and sum up qty and total uomvalue
3219
+ const groupBy = data =>
3220
+ Object.values(
3221
+ data.reduce((d, e) => {
3222
+ const key = e.productId + e.productDetailId + e.batchId
3223
+ d[key] = d[key] ? d[key] : { ...e, releaseQty: 0, releaseUomValue: 0 }
3224
+ d[key].releaseQty = d[key] ? d[key].releaseQty + e.releaseQty : e.releaseQty
3225
+ d[key].releaseUomValue = d[key].releaseUomValue
3226
+ ? d[key].releaseUomValue + e.releaseUomValue
3227
+ : e.releaseUomValue
3228
+ return d
3229
+ }, {})
3230
+ )
3231
+
3232
+ this.vasFormattedData = groupBy(data)
3233
+ }
3234
+ return this.vasFormattedData
3235
+ }
3236
+
2956
3237
  sortByNameField(items, nameField, nameField2) {
2957
3238
  if (nameField2) {
2958
3239
  items?.sort((a, b) => {