@things-factory/worksheet-base 4.3.631 → 4.3.633

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,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEmptyLocations = exports.recommendQuarantineLocationLevel1 = exports.recommendLocationLevel1 = exports.recommendPutawayLocationResolver = void 0;
3
+ exports.getLevel2Location = exports.getEmptyLocations = exports.recommendQuarantineLocationLevel1 = exports.recommendLocationLevel2 = exports.recommendLocationLevel1 = exports.recommendPutawayLocationResolver = void 0;
4
4
  const typeorm_1 = require("typeorm");
5
5
  const setting_base_1 = require("@things-factory/setting-base");
6
6
  const warehouse_base_1 = require("@things-factory/warehouse-base");
@@ -16,7 +16,8 @@ exports.recommendPutawayLocationResolver = {
16
16
  'worksheet.arrivalNotice',
17
17
  'worksheet.returnOrder',
18
18
  'targetInventory',
19
- 'targetInventory.inventory'
19
+ 'targetInventory.inventory',
20
+ 'targetInventory.inventory.product'
20
21
  ]
21
22
  });
22
23
  const inventory = worksheetDetail.targetInventory.inventory;
@@ -47,6 +48,7 @@ exports.recommendPutawayLocationResolver = {
47
48
  if (isExpiring) {
48
49
  switch (sortingLevel) {
49
50
  case 'level 1':
51
+ case 'level 2':
50
52
  recommendedLocations = await recommendQuarantineLocationLevel1(domain, targetWarehouse, optCnt);
51
53
  break;
52
54
  default:
@@ -60,6 +62,9 @@ exports.recommendPutawayLocationResolver = {
60
62
  case 'level 1':
61
63
  recommendedLocations = await recommendLocationLevel1(domain, targetWarehouse, optCnt);
62
64
  break;
65
+ case 'level 2':
66
+ recommendedLocations = await recommendLocationLevel2(domain, targetWarehouse, optCnt, inventory.product.id);
67
+ break;
63
68
  default:
64
69
  recommendedLocations = await recommendLocationLevel1(domain, targetWarehouse, optCnt);
65
70
  break;
@@ -71,6 +76,10 @@ async function recommendLocationLevel1(domain, warehouse, optCnt) {
71
76
  return await getEmptyLocations(domain, warehouse, optCnt, [warehouse_base_1.LOCATION_TYPE.SHELF, warehouse_base_1.LOCATION_TYPE.FLOOR]);
72
77
  }
73
78
  exports.recommendLocationLevel1 = recommendLocationLevel1;
79
+ async function recommendLocationLevel2(domain, warehouse, optCnt, productId) {
80
+ return await getLevel2Location(domain, warehouse, optCnt, [warehouse_base_1.LOCATION_TYPE.STORAGE, warehouse_base_1.LOCATION_TYPE.SHELF, warehouse_base_1.LOCATION_TYPE.FLOOR], productId);
81
+ }
82
+ exports.recommendLocationLevel2 = recommendLocationLevel2;
74
83
  async function recommendQuarantineLocationLevel1(domain, warehouse, optCnt) {
75
84
  return await getEmptyLocations(domain, warehouse, optCnt, [warehouse_base_1.LOCATION_TYPE.QUARANTINE]);
76
85
  }
@@ -94,4 +103,55 @@ async function getEmptyLocations(domain, warehouse, optCnt, allowedTypes) {
94
103
  });
95
104
  }
96
105
  exports.getEmptyLocations = getEmptyLocations;
106
+ async function getLevel2Location(domain, warehouse, optCnt, allowedTypes, productId) {
107
+ let sortLocation = {};
108
+ let sortInventoryLocation = {};
109
+ let recommendedLocation = [];
110
+ const orderSetting = await (0, typeorm_1.getRepository)(setting_base_1.Setting).findOne({
111
+ where: { domain, name: 'rule-for-storing-product' }
112
+ });
113
+ if (orderSetting === null || orderSetting === void 0 ? void 0 : orderSetting.value) {
114
+ sortLocation = JSON.parse(orderSetting.value);
115
+ sortInventoryLocation = Object.fromEntries(Object.entries(sortLocation).map(([key, value]) => [`location.${key}`, value]));
116
+ }
117
+ for (const type of allowedTypes) {
118
+ const qb = await (0, typeorm_1.getRepository)(warehouse_base_1.Inventory)
119
+ .createQueryBuilder('inventory')
120
+ .leftJoinAndSelect('inventory.location', 'location')
121
+ .leftJoin('inventory.product', 'product')
122
+ .where('inventory.domain = :domain', { domain: domain.id })
123
+ .andWhere('inventory.status = :inventoryStatus', { inventoryStatus: 'STORED' })
124
+ .andWhere('product.id = :productId', { productId: productId })
125
+ .andWhere('location.warehouse = :warehouse', { warehouse: warehouse.id })
126
+ .andWhere('location.status = :status', { status: warehouse_base_1.LOCATION_STATUS.OCCUPIED })
127
+ .andWhere('location.type = :type', { type })
128
+ .orderBy('inventory.qty', 'ASC');
129
+ Object.entries(sortInventoryLocation).forEach(([key, value]) => {
130
+ qb.addOrderBy(key, value);
131
+ });
132
+ qb.take(optCnt);
133
+ const inventories = await qb.getMany();
134
+ if (inventories.length > 0) {
135
+ recommendedLocation = inventories.map(inventory => inventory.location);
136
+ break;
137
+ }
138
+ else {
139
+ recommendedLocation = await (0, typeorm_1.getRepository)(warehouse_base_1.Location).find({
140
+ where: {
141
+ domain,
142
+ warehouse,
143
+ status: warehouse_base_1.LOCATION_STATUS.EMPTY,
144
+ type
145
+ },
146
+ sortLocation,
147
+ take: optCnt
148
+ });
149
+ if (recommendedLocation.length > 0) {
150
+ break;
151
+ }
152
+ }
153
+ }
154
+ return recommendedLocation;
155
+ }
156
+ exports.getLevel2Location = getLevel2Location;
97
157
  //# sourceMappingURL=recommend-putway-location.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"recommend-putway-location.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/worksheet/recommend-putway-location.ts"],"names":[],"mappings":";;;AAAA,qCAA2C;AAG3C,+DAAsD;AAEtD,mEAA+G;AAE/G,kDAAqE;AACrE,gDAA8D;AAC9D,kEAAmE;AAEtD,QAAA,gCAAgC,GAAG;IAC9C,KAAK,CAAC,wBAAwB,CAC5B,CAAO,EACP,EAAE,mBAAmB,EAAE,MAAM,GAAG,CAAC,EAAmD,EACpF,OAAY;QAEZ,MAAM,MAAM,GAAW,OAAO,CAAC,KAAK,CAAC,MAAM,CAAA;QAE3C,MAAM,eAAe,GAAoB,MAAM,IAAA,uBAAa,EAAC,0BAAe,CAAC,CAAC,OAAO,CACnF,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,EAAE,EACrC;YACE,SAAS,EAAE;gBACT,WAAW;gBACX,yBAAyB;gBACzB,uBAAuB;gBACvB,iB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M,YAAY,GAAY,MAAM,IAAA,uBAAa,EAAC,sBAAO,CAAC,CAAC,OAAO,CAAC;QACjE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,0BAA0B,EAAE;KACpD,CAAC,CAAA;IACF,IAAI,KAAK,GAAG,EAAE,CAAA;IACd,IAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,KAAK;QAAE,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;IAE/D,OAAO,MAAM,IAAA,uBAAa,EAAC,yBAAQ,CAAC,CAAC,IAAI,CAAC;QACxC,KAAK,EAAE;YACL,MAAM;YACN,SAAS;YACT,MAAM,EAAE,gCAAe,CAAC,KAAK;YAC7B,IAAI,EAAE,IAAA,YAAE,EAAC,YAAY,CAAC;SACvB;QACD,KAAK;QACL,IAAI,EAAE,MAAM;KACb,CAAC,CAAA;AACJ,CAAC;AAtBD,8CAsBC"}
1
+ {"version":3,"file":"recommend-putway-location.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/worksheet/recommend-putway-location.ts"],"names":[],"mappings":";;;AAAA,qCAA2C;AAG3C,+DAAsD;AAEtD,mEAA+G;AAE/G,kDAAqE;AACrE,gDAA8D;AAC9D,kEAAmE;AAEtD,QAAA,gCAAgC,GAAG;IAC9C,KAAK,CAAC,wBAAwB,CAC5B,CAAO,EACP,EAAE,mBAAmB,EAAE,MAAM,GAAG,CAAC,EAAmD,EACpF,OAAY;QAEZ,MAAM,MAAM,GAAW,OAAO,CAAC,KAAK,CAAC,MAAM,CAAA;QAE3C,MAAM,eAAe,GAAoB,MAAM,IAAA,uBAAa,EAAC,0BAAe,CAAC,CAAC,OAAO,CACnF,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,EAAE,EACrC;YACE,SAAS,EAAE;gBACT,WAAW;gBACX,yBAAyB;gBACzB,uBAAuB;gBACvB,iBAAiB;gBACjB,2BAA2B;gBAC3B,mCAAmC;aACpC;SAC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A;QAEhC,MAAM,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC7D,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,KAAuB,CAAC,CAAA;QAC7C,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAEf,MAAM,WAAW,GAAgB,MAAM,EAAE,CAAC,OAAO,EAAE,CAAA;QAErD,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,mBAAmB,GAAG,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;YACtE,MAAK;SACN;aAAM;YACL,mBAAmB,GAAG,MAAM,IAAA,uBAAa,EAAC,yBAAQ,CAAC,CAAC,IAAI,CAAC;gBACvD,KAAK,EAAE;oBACL,MAAM;oBACN,SAAS;oBACT,MAAM,EAAE,gCAAe,CAAC,KAAK;oBAC7B,IAAI;iBACL;gBACD,YAAY;gBACZ,IAAI,EAAE,MAAM;aACb,CAAC,CAAA;YAEF,IAAI,mBAAmB,CAAC,MAAM,GAAG,CAAC,EAAE;gBAClC,MAAK;aACN;SACF;KACF;IAED,OAAO,mBAAmB,CAAA;AAC5B,CAAC;AA9DD,8CA8DC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/worksheet-base",
3
- "version": "4.3.631",
3
+ "version": "4.3.633",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -36,7 +36,7 @@
36
36
  "@things-factory/integration-sftp": "^4.3.616",
37
37
  "@things-factory/marketplace-base": "^4.3.617",
38
38
  "@things-factory/notification": "^4.3.609",
39
- "@things-factory/sales-base": "^4.3.631",
39
+ "@things-factory/sales-base": "^4.3.632",
40
40
  "@things-factory/setting-base": "^4.3.609",
41
41
  "@things-factory/shell": "^4.3.591",
42
42
  "@things-factory/transport-base": "^4.3.631",
@@ -45,5 +45,5 @@
45
45
  "puppeteer": "21.0.3",
46
46
  "uuid": "^9.0.0"
47
47
  },
48
- "gitHead": "c6f91170d443086dcd3bfd691113fcf08a2f1b89"
48
+ "gitHead": "e550612b9ee56d93020d0ea39b9320c4962dd134"
49
49
  }
@@ -25,7 +25,8 @@ export const recommendPutawayLocationResolver = {
25
25
  'worksheet.arrivalNotice',
26
26
  'worksheet.returnOrder',
27
27
  'targetInventory',
28
- 'targetInventory.inventory'
28
+ 'targetInventory.inventory',
29
+ 'targetInventory.inventory.product'
29
30
  ]
30
31
  }
31
32
  )
@@ -61,6 +62,7 @@ export const recommendPutawayLocationResolver = {
61
62
  if (isExpiring) {
62
63
  switch (sortingLevel) {
63
64
  case 'level 1':
65
+ case 'level 2':
64
66
  recommendedLocations = await recommendQuarantineLocationLevel1(domain, targetWarehouse, optCnt)
65
67
  break
66
68
 
@@ -77,6 +79,10 @@ export const recommendPutawayLocationResolver = {
77
79
  recommendedLocations = await recommendLocationLevel1(domain, targetWarehouse, optCnt)
78
80
  break
79
81
 
82
+ case 'level 2':
83
+ recommendedLocations = await recommendLocationLevel2(domain, targetWarehouse, optCnt, inventory.product.id)
84
+ break
85
+
80
86
  default:
81
87
  recommendedLocations = await recommendLocationLevel1(domain, targetWarehouse, optCnt)
82
88
  break
@@ -94,6 +100,21 @@ export async function recommendLocationLevel1(
94
100
  return await getEmptyLocations(domain, warehouse, optCnt, [LOCATION_TYPE.SHELF, LOCATION_TYPE.FLOOR])
95
101
  }
96
102
 
103
+ export async function recommendLocationLevel2(
104
+ domain: Domain,
105
+ warehouse: Warehouse,
106
+ optCnt: number,
107
+ productId: string
108
+ ): Promise<Location[]> {
109
+ return await getLevel2Location(
110
+ domain,
111
+ warehouse,
112
+ optCnt,
113
+ [LOCATION_TYPE.STORAGE, LOCATION_TYPE.SHELF, LOCATION_TYPE.FLOOR],
114
+ productId
115
+ )
116
+ }
117
+
97
118
  export async function recommendQuarantineLocationLevel1(
98
119
  domain: Domain,
99
120
  warehouse: Warehouse,
@@ -125,3 +146,67 @@ export async function getEmptyLocations(
125
146
  take: optCnt
126
147
  })
127
148
  }
149
+
150
+ export async function getLevel2Location(
151
+ domain: Domain,
152
+ warehouse: Warehouse,
153
+ optCnt: number,
154
+ allowedTypes: LOCATION_TYPE[],
155
+ productId: string
156
+ ): Promise<Location[]> {
157
+ let sortLocation = {}
158
+ let sortInventoryLocation = {}
159
+ let recommendedLocation: Location[] = []
160
+ const orderSetting: Setting = await getRepository(Setting).findOne({
161
+ where: { domain, name: 'rule-for-storing-product' }
162
+ })
163
+
164
+ if (orderSetting?.value) {
165
+ sortLocation = JSON.parse(orderSetting.value)
166
+ sortInventoryLocation = Object.fromEntries(Object.entries(sortLocation).map(([key, value]) => [`location.${key}`, value]))
167
+ }
168
+
169
+ for (const type of allowedTypes) {
170
+ const qb = await getRepository(Inventory)
171
+ .createQueryBuilder('inventory')
172
+ .leftJoinAndSelect('inventory.location', 'location')
173
+ .leftJoin('inventory.product', 'product')
174
+ .where('inventory.domain = :domain', { domain: domain.id })
175
+ .andWhere('inventory.status = :inventoryStatus', { inventoryStatus: 'STORED' })
176
+ .andWhere('product.id = :productId', { productId: productId })
177
+ .andWhere('location.warehouse = :warehouse', { warehouse: warehouse.id })
178
+ .andWhere('location.status = :status', { status: LOCATION_STATUS.OCCUPIED })
179
+ .andWhere('location.type = :type', { type })
180
+ .orderBy('inventory.qty', 'ASC')
181
+
182
+ Object.entries(sortInventoryLocation).forEach(([key, value]) => {
183
+ qb.addOrderBy(key, value as 'ASC' | 'DESC')
184
+ })
185
+
186
+ qb.take(optCnt)
187
+
188
+ const inventories: Inventory[] = await qb.getMany()
189
+
190
+ if (inventories.length > 0) {
191
+ recommendedLocation = inventories.map(inventory => inventory.location)
192
+ break
193
+ } else {
194
+ recommendedLocation = await getRepository(Location).find({
195
+ where: {
196
+ domain,
197
+ warehouse,
198
+ status: LOCATION_STATUS.EMPTY,
199
+ type
200
+ },
201
+ sortLocation,
202
+ take: optCnt
203
+ })
204
+
205
+ if (recommendedLocation.length > 0) {
206
+ break
207
+ }
208
+ }
209
+ }
210
+
211
+ return recommendedLocation
212
+ }