@things-factory/sales-base 4.3.248 → 4.3.249

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.
@@ -1,29 +1,10 @@
1
- import {
2
- EntityManager,
3
- Equal,
4
- getRepository,
5
- In,
6
- Not,
7
- Raw,
8
- Repository,
9
- SelectQueryBuilder
10
- } from 'typeorm'
1
+ import { EntityManager, Equal, getRepository, In, Not, Raw, Repository, SelectQueryBuilder } from 'typeorm'
11
2
 
12
3
  import { User } from '@things-factory/auth-base'
13
4
  import { Bizplace } from '@things-factory/biz-base'
14
- import {
15
- Product,
16
- ProductBundle,
17
- ProductDetail
18
- } from '@things-factory/product-base'
19
- import {
20
- PartnerSetting,
21
- Setting
22
- } from '@things-factory/setting-base'
23
- import {
24
- Domain,
25
- ListParam
26
- } from '@things-factory/shell'
5
+ import { Product, ProductBundle, ProductDetail } from '@things-factory/product-base'
6
+ import { PartnerSetting, Setting } from '@things-factory/setting-base'
7
+ import { Domain, ListParam } from '@things-factory/shell'
27
8
  import {
28
9
  generateInventoryHistory,
29
10
  Inventory,
@@ -122,14 +103,15 @@ export const InventoryUtil = {
122
103
  coalesce(p.brand, '') AS "productBrand",
123
104
  p.id AS "productId",
124
105
  pd.id AS "productDetailId",
125
- COALESCE(SUM(COALESCE(i.qty, 0)) - SUM(COALESCE(i.locked_qty, 0)) - MAX(COALESCE(oi.release_qty, 0)) - MAX(COALESCE(bp.bundle_product_release_qty, 0)),0) AS "remainQty",
126
- COALESCE(SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)),0) AS "remainUomValue",
127
- concat(SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)), ' ', pd.uom) AS "remainUomValueWithUom",
106
+ COALESCE(SUM(COALESCE(i.qty, 0)) - SUM(COALESCE(i.locked_qty, 0)) - SUM(COALESCE(pds.unassigned_qty, 0)) - MAX(COALESCE(oi.release_qty, 0)) - MAX(COALESCE(bp.bundle_product_release_qty, 0)),0) AS "remainQty",
107
+ COALESCE(SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - SUM(COALESCE(pds.unassigned_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)),0) AS "remainUomValue",
108
+ concat(SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - SUM(COALESCE(pds.unassigned_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)), ' ', pd.uom) AS "remainUomValueWithUom",
128
109
  COALESCE(SUM(COALESCE(i.transfer_qty, 0)), 0) AS "transferQty",
129
110
  COALESCE(SUM(COALESCE(i.transfer_uom_value, 0)), 0) AS "transferUomValue",
130
111
  'SINGLE' AS "groupType"
131
112
  FROM products p
132
113
  INNER join product_details pd on pd.product_id = p.id
114
+ LEFT JOIN product_detail_stocks pds on pds.product_detail_id = pd.id
133
115
  LEFT JOIN (
134
116
  SELECT i.* FROM inventories i
135
117
  INNER JOIN locations l2 ON i.location_id = l2.id AND i.domain_id = l2.domain_id
@@ -175,13 +157,14 @@ export const InventoryUtil = {
175
157
  FROM product_bundles pb
176
158
  LEFT JOIN (
177
159
  SELECT pbs.product_id, pbs.product_bundle_id, min(pbs.bundle_qty),
178
- (SUM(COALESCE(i2.qty, 0)) - SUM(COALESCE(i2.locked_qty, 0)) - MAX(COALESCE(oi.release_qty, 0))) / min(pbs.bundle_qty) AS "availableQty",
179
- (SUM(COALESCE(i2.uom_value, 0)) - SUM(COALESCE(i2.locked_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0))) / min(pbs.bundle_qty) AS "availableUomValue",
160
+ (SUM(COALESCE(i2.qty, 0)) - SUM(COALESCE(i2.locked_qty, 0)) - SUM(COALESCE(pds2.unassigned_qty, 0)) - MAX(COALESCE(oi.release_qty, 0))) / min(pbs.bundle_qty) AS "availableQty",
161
+ (SUM(COALESCE(i2.uom_value, 0)) - SUM(COALESCE(i2.locked_uom_value, 0)) - SUM(COALESCE(pds2.unassigned_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0))) / min(pbs.bundle_qty) AS "availableUomValue",
180
162
  (SUM(COALESCE(i2.transfer_qty, 0)) / min(pbs.bundle_qty)) AS "transferQty",
181
163
  (SUM(COALESCE(i2.transfer_uom_value, 0)) / min(pbs.bundle_qty)) AS "transferUomValue",
182
164
  pbs.product_detail_id
183
165
  FROM product_bundle_settings pbs
184
166
  LEFT JOIN inventories i2 ON i2.product_id = pbs.product_id AND i2.domain_id = $1 AND i2.status = 'STORED'
167
+ LEFT JOIN product_detail_stocks pds2 ON pds2.product_detail_id = pbs.product_detail_id
185
168
  INNER JOIN locations l2 ON i2.location_id = l2.id
186
169
  LEFT JOIN oi ON oi.product_id = i2.product_id
187
170
  WHERE l2.type NOT IN ('${LOCATION_TYPE.QUARANTINE}', '${LOCATION_TYPE.RESERVE}')
@@ -305,13 +288,14 @@ export const InventoryUtil = {
305
288
  coalesce(p.brand, '') AS "productBrand",
306
289
  p.id AS "productId",
307
290
  i.product_detail_id AS "productDetailId",
308
- SUM(COALESCE(i.qty, 0)) - SUM(COALESCE(i.locked_qty, 0)) - MAX(COALESCE(oi.release_qty, 0)) - MAX(COALESCE(bp.bundle_product_release_qty, 0)) AS "remainQty",
309
- SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)) AS "remainUomValue",
310
- concat(SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)), ' ', i.uom) AS "remainUomValueWithUom",
291
+ SUM(COALESCE(i.qty, 0)) - SUM(COALESCE(i.locked_qty, 0)) - MAX(COALESCE(oi.release_qty, 0)) - MAX(COALESCE(bp.bundle_product_release_qty, 0)) - SUM(COALESCE(pds.unassigned_qty, 0)) AS "remainQty",
292
+ SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)) - SUM(COALESCE(pds.unassigned_uom_value)) AS "remainUomValue",
293
+ concat(SUM(COALESCE(i.uom_value, 0)) - SUM(COALESCE(i.locked_uom_value, 0)) - MAX(COALESCE(oi.release_uom_value, 0)) - MAX(COALESCE(bp.bundle_product_release_uom_value, 0)) - SUM(COALESCE(pds.unassigned_uom_value)), ' ', i.uom) AS "remainUomValueWithUom",
311
294
  'SINGLE' AS "groupType"
312
295
  FROM
313
296
  inventories i
314
297
  LEFT JOIN products p ON i.product_id = p.id
298
+ LEFT JOIN product_detail_stocks pds ON pds.product_detail_id = i.product_detail_id
315
299
  LEFT JOIN oi ON i.batch_id = oi.batch_id AND p.name = oi.product_name AND i.packing_type = oi.packing_type AND i.packing_size = oi.packing_size AND i.uom = oi.uom
316
300
  LEFT JOIN locations l2 ON i.location_id = l2.id AND i.domain_id = l2.domain_id
317
301
  LEFT JOIN (
@@ -535,7 +519,7 @@ export const InventoryUtil = {
535
519
  validOrderInventories.map(x => {
536
520
  return {
537
521
  product_detail_id: x.productDetail.id,
538
- batch_id: x.batchId.replace(`'`,`''`),
522
+ batch_id: x.batchId.replace(`'`, `''`),
539
523
  release_qty: x.releaseQty,
540
524
  uom: x.uom
541
525
  }
@@ -652,11 +636,10 @@ export const InventoryUtil = {
652
636
  })
653
637
 
654
638
  if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
655
-
656
-
639
+
657
640
  let locationTypes = [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]
658
641
 
659
- if(recall === false){
642
+ if (recall === false) {
660
643
  locationTypes.push(LOCATION_TYPE.DAMAGE)
661
644
  }
662
645
 
@@ -812,7 +795,7 @@ async function getConditions(
812
795
  WHERE pb.status = 'ACTIVATED'
813
796
  `
814
797
 
815
- let whereClause = hasRemainingQty ? ` WHERE "remainQty" > 0` : ` WHERE 1 = 1`
798
+ let whereClause = hasRemainingQty ? ` WHERE "remainQty" > 0 ` : ` WHERE 1 = 1 `
816
799
 
817
800
  let productDetailWhereClause = ``
818
801
 
@@ -845,7 +828,7 @@ async function getConditions(
845
828
 
846
829
  case 'batchId':
847
830
  let batchId = `${value}`
848
- whereClause += `AND LOWER("batchId") LIKE '${batchId.replace(`'`,`''`).toLowerCase()}'`
831
+ whereClause += `AND LOWER("batchId") LIKE '${batchId.replace(`'`, `''`).toLowerCase()}'`
849
832
  break
850
833
 
851
834
  case 'batchIdRef':
@@ -949,7 +932,7 @@ async function getConditions(
949
932
  AND (i.batch_id, p.id, i.packing_type, i.packing_size) ${operator === 'in' ? 'IN' : 'NOT IN'} (${value
950
933
  .map(
951
934
  (v: { batchId: string; productId: string; packingType: string; packingSize: string }) =>
952
- `('${v.batchId.replace(`'`,`''`)}', '${v.productId}', '${v.packingType}', '${v.packingSize}')`
935
+ `('${v.batchId.replace(`'`, `''`)}', '${v.productId}', '${v.packingType}', '${v.packingSize}')`
953
936
  )
954
937
  .join()})
955
938
  `
@@ -1117,6 +1100,7 @@ export function _composeTargetInventories(
1117
1100
  }
1118
1101
 
1119
1102
  orderInventories.push({
1103
+ ...record,
1120
1104
  ...orderInventory,
1121
1105
  inventory,
1122
1106
  packingType,