@things-factory/operato-hub 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,14 +1,40 @@
1
1
  module.exports = {
2
2
  domainType: 'company',
3
3
  domainExtType: 'company',
4
+ useVirtualHostBasedDomain: false,
5
+ fallbackRoute: '/',
4
6
  subdomainOffset: 2,
7
+ port: 3000,
8
+ inspect: '9260',
9
+ // ormconfig: {
10
+ // name: 'default',
11
+ // type: 'postgres',
12
+ // database: 'dev',
13
+ // username: 'postgres',
14
+ // password: 'abcd1234',
15
+ // host: 'operatov3.cluster-cijhm4n1hbst.ap-southeast-1.rds.amazonaws.com',
16
+ // port: 55432,
17
+ // synchronize: false,
18
+ // logging: true
19
+ // },
20
+ // ormconfig: {
21
+ // name: 'default',
22
+ // type: 'postgres',
23
+ // database: 'v3-hub1',
24
+ // username: 'postgres',
25
+ // password: 'hatio',
26
+ // host: 'localhost',
27
+ // port: 15432,
28
+ // synchronize: true,
29
+ // logging: true
30
+ // },
5
31
  ormconfig: {
6
32
  name: 'default',
7
33
  type: 'postgres',
8
- database: 'sum',
34
+ database: 'dev2',
9
35
  username: 'postgres',
10
36
  password: 'hatio',
11
- host: '192.168.0.151',
37
+ host: '192.168.0.161',
12
38
  port: 15432,
13
39
  synchronize: true,
14
40
  logging: true
@@ -16,96 +42,105 @@ module.exports = {
16
42
  // ormconfig: {
17
43
  // name: 'default',
18
44
  // type: 'postgres',
19
- // database: 'postgres',
45
+ // database: 'dev',
20
46
  // username: 'postgres',
21
- // password: 'abcd1234',
22
- // host: 'operatov3.cluster-cijhm4n1hbst.ap-southeast-1.rds.amazonaws.com',
23
- // port: 55432,
24
- // synchronize: false,
25
- // logging: false
47
+ // password: 'hatio',
48
+ // host: 'localhost',
49
+ // port: 15432,
50
+ // synchronize: true,
51
+ // logging: true
26
52
  // },
27
- notification: {
28
- fcm: {
29
- serviceAccount: {
30
- project_id: 'operato',
31
- private_key:
32
- '-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDYNOfyNjPMSeG9\nzU1qs0cpVK5cVfadcUaw5g+hkQZMOMlAA7uqW2eX4vkayj7MzbYUayH+sei8044Q\nJIyl6f26dNX1VT3UgTmSmCS0v48EBEZHCgusrUGFjduLRN6OS6uvrXW1xKA18k9q\nai1C2EHCXF2AE4PTvf239RC1UIOnVePcMtT7rMTdHRO4s8OKVuSDbzIt8k1cV3Zt\nES0YsJlkELqBisYpV//2/ZSILTt39J9JzrVef03X9kkoo9p+YnNyy6tWsfQPfgJO\nybiRGBNxiyJ/E2pxRo/WqU0go9OzYJlGaSUrUx09heNiRD1b0MAOmyPDJz/6AaTk\nkU/A+kLzAgMBAAECggEADQ5s2gtR53VSujk1V/Xe8e0Di99DwaWUj5w6YhcK7/wX\nPdQRN4Fw6RLeLjL7xeG/rCNSwzm6hKSrQJL5zLnWW7XbMdyQRk6jdmnVAEv3zACi\nFH9+eFK3e+Q214XfgWz/v4p/FZdRLCYni5VBNHcwyWxLLS/V1ynzB3KM1sDiTRmI\npcT7+uTtwrKgJq64sXtFE2pYrFxDdCiyqzkhv/2ed4YIowAjpKBbbcCDKeVxVkoz\nC1P4PAzs9EeUuKSWYrWaUjN17lqtRlYeT1ylR1PIJuWqd4cKfgoEgz+lHwRPDCEX\nAYbk3nofiJIPBhSfCHrXS755wK48mY8vMwFdfCPJeQKBgQDsz4tjYTHdat5A25n5\nekwMxZwFQ5OvMV4eulwZUDMypTAYSz1iB6sDlgwKDm5omZIfuneqCEIvrqxV/kx3\n5wV/DANHO3hYxdp/NV7rM23xmqlaKZhHQbDono1Fm/LP6DEmJiD7N2eFKsXYcPpR\nSAIdCv0X3zkDQ4zRi51yJlCXzQKBgQDpufJBxCoXngiQJ2j14lWVAeOOdQ6zh5Ip\nBcDwF0X67cNSN3Wl40bS4yLFdolhEAyj5m0WPuYYXpjzhHhZ0W3V3ItdBkrmwIvy\nWOWu26qN0ZbwxVS2qVpHuj6iHWJKHuDZZUkFtJg3BeeBSOUHSA8TvjnA0xd83xeb\n8ZJasWoFvwKBgQDFs/gQ/gIdcq0exLfluh5nw0qgcmyHpNWJHdjqITS9IX/nqFkU\n0IYLtmdStf2jQiLmbkydHcvz9wZVvLqml67VBHhwLcwpgPULoskd34/4V0Dvzy4c\nv1Esw8H5zVqIDLeLu+VpFjZMzQrjyl6RIWbyTExEc84rVWfpQYAu3qIGOQKBgAFr\nXatEk7TdAtRNSPflTfu/rTAaSeKROjQBkvBiU8x4US1YpOBDBxUUyAtG8wKh5FHC\nfnsaGq+fM3KXJVv2R6J62mXQOfg4xyDLpWlwcBK4aSBBMoiBcsjouqSlZQlqMpdf\nZBgixqHe6U8BsFJg/6ZxC0y+e3AIss4Bo4/lb+1lAoGAFOexvaBh21K6W3inmRW4\nLlkVYJaBJ20OwokXg5aXjBiHxqmk7VLAuFbkpb5LOKH2xPILRQ0OEkn51yVymS3T\n9lLpHOFTQXt5tF2/F7NW7kaQJNlLr/h5jPi3O9XHeFmuaN2z150ZB6zzgjeGKzr8\ni+1fgTsRfDtNw8xkSH9qL1Y=\n-----END PRIVATE KEY-----\n',
33
- client_email: 'firebase-adminsdk-xmm2e@operato.iam.gserviceaccount.com'
34
- },
35
- appConfig: {
36
- apiKey: 'AIzaSyDdTM2BTLHSt2LNS0G5QB8G0i4KBXFiG7U',
37
- projectId: 'operato',
38
- messagingSenderId: 79537064975,
39
- appId: '1:79537064975:web:32f53119e9c8c6ee2a277a'
40
- },
41
- serverKey:
42
- 'AAAAEoTHTA8:APA91bGwt-4HT82Dfwf_VwbQaKT0_qHd0Y3tuW41udjWz5Lz0Ko0mEMD6WbHHSILvQpa6yuoGGKCMsrU7VW2qWRrUm3CYpyG9oSwshNm1tIhljAnOuUfwHCoawbVLwf9qlWpHt4dwCoc'
43
- },
44
- vapidKey: {
45
- subject: 'mailto:heartyoh@hatiolab.com',
46
- publicKey: 'BAkVkITsCXBIsYL1yeaBmx5_dn57we-ZXMjirPPHzC2dan82cdEnAio_53PQ-1_w3ykWCBPrrFAWQ_d9N4cFF0o',
47
- privateKey: '4pmlt3Wk019u7nqU3Q_oGZE6LbUDjjf8DpmAcn9-iss'
48
- }
53
+ password: {
54
+ lowerCase: true,
55
+ upperCase: false,
56
+ digit: false,
57
+ specialCharacter: false,
58
+ allowRepeat: true,
59
+ useTightPattern: false,
60
+ useLoosePattern: true,
61
+ tightCharacterLength: 4,
62
+ looseCharacterLength: 4,
63
+ history: 2
49
64
  },
50
- port: 9002,
65
+ sftpFileStorage: {
66
+ type: 's3',
67
+ accessKeyId: 'AKIAUQEOPWEJKL43OMZA',
68
+ secretAccessKey: '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',
69
+ bucketName: 'operato-sftp'
70
+ },
71
+ // storage: {
72
+ // type: 's3',
73
+ // accessKeyId: 'AKIAUQEOPWEJCDH6AR5H',
74
+ // secretAccessKey: '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',
75
+ // bucketName: 'opa-one',
76
+ // region: 'ap-southeast-1'
77
+ // },
78
+ uploads: 'uploads',
79
+ attachmentsPath: 'attachments',
51
80
  SECRET: '0xD58F835B69D207A76CC5F84a70a1D0d4C79dfC95',
52
- useVirtualHostBasedDomain: false,
81
+ logger: {
82
+ file: {
83
+ filename: 'logs/application-%DATE%.log',
84
+ datePattern: 'YYYY-MM-DD-HH',
85
+ zippedArchive: true,
86
+ maxSize: '200m',
87
+ maxFiles: '1m',
88
+ level: 'info'
89
+ }
90
+ },
53
91
  email: {
54
92
  host: 'smtp.office365.com',
55
93
  port: 587,
56
94
  secure: false, // true for 465, false for other ports
57
95
  auth: {
58
- user: 'no-reply@hatiolab.com', // generated ethereal user
96
+ user: 'noreply@hatiolab.com', // generated ethereal user
59
97
  pass: 'h@ti0LAB1008' // generated ethereal password
60
98
  },
61
99
  secureConnection: false,
62
100
  tls: {
63
101
  ciphers: 'SSLv3'
64
- },
65
- sender: 'no-reply@hatiolab.com'
102
+ }
66
103
  },
67
- // awsSesEmail: 'support@hatio.asia',
68
- awsSesEmail: {
69
- email: 'support@hatio.asia',
70
- accessKeyId: 'AKIAUQEOPWEJKL43OMZA',
71
- secretAccessKey: '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'
104
+ sender: 'noreply@hatiolab.com',
105
+ notification: {
106
+ // fcm: {
107
+ // serviceAccount: {
108
+ // project_id: 'operato',
109
+ // private_key:
110
+ // '-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDYNOfyNjPMSeG9\nzU1qs0cpVK5cVfadcUaw5g+hkQZMOMlAA7uqW2eX4vkayj7MzbYUayH+sei8044Q\nJIyl6f26dNX1VT3UgTmSmCS0v48EBEZHCgusrUGFjduLRN6OS6uvrXW1xKA18k9q\nai1C2EHCXF2AE4PTvf239RC1UIOnVePcMtT7rMTdHRO4s8OKVuSDbzIt8k1cV3Zt\nES0YsJlkELqBisYpV//2/ZSILTt39J9JzrVef03X9kkoo9p+YnNyy6tWsfQPfgJO\nybiRGBNxiyJ/E2pxRo/WqU0go9OzYJlGaSUrUx09heNiRD1b0MAOmyPDJz/6AaTk\nkU/A+kLzAgMBAAECggEADQ5s2gtR53VSujk1V/Xe8e0Di99DwaWUj5w6YhcK7/wX\nPdQRN4Fw6RLeLjL7xeG/rCNSwzm6hKSrQJL5zLnWW7XbMdyQRk6jdmnVAEv3zACi\nFH9+eFK3e+Q214XfgWz/v4p/FZdRLCYni5VBNHcwyWxLLS/V1ynzB3KM1sDiTRmI\npcT7+uTtwrKgJq64sXtFE2pYrFxDdCiyqzkhv/2ed4YIowAjpKBbbcCDKeVxVkoz\nC1P4PAzs9EeUuKSWYrWaUjN17lqtRlYeT1ylR1PIJuWqd4cKfgoEgz+lHwRPDCEX\nAYbk3nofiJIPBhSfCHrXS755wK48mY8vMwFdfCPJeQKBgQDsz4tjYTHdat5A25n5\nekwMxZwFQ5OvMV4eulwZUDMypTAYSz1iB6sDlgwKDm5omZIfuneqCEIvrqxV/kx3\n5wV/DANHO3hYxdp/NV7rM23xmqlaKZhHQbDono1Fm/LP6DEmJiD7N2eFKsXYcPpR\nSAIdCv0X3zkDQ4zRi51yJlCXzQKBgQDpufJBxCoXngiQJ2j14lWVAeOOdQ6zh5Ip\nBcDwF0X67cNSN3Wl40bS4yLFdolhEAyj5m0WPuYYXpjzhHhZ0W3V3ItdBkrmwIvy\nWOWu26qN0ZbwxVS2qVpHuj6iHWJKHuDZZUkFtJg3BeeBSOUHSA8TvjnA0xd83xeb\n8ZJasWoFvwKBgQDFs/gQ/gIdcq0exLfluh5nw0qgcmyHpNWJHdjqITS9IX/nqFkU\n0IYLtmdStf2jQiLmbkydHcvz9wZVvLqml67VBHhwLcwpgPULoskd34/4V0Dvzy4c\nv1Esw8H5zVqIDLeLu+VpFjZMzQrjyl6RIWbyTExEc84rVWfpQYAu3qIGOQKBgAFr\nXatEk7TdAtRNSPflTfu/rTAaSeKROjQBkvBiU8x4US1YpOBDBxUUyAtG8wKh5FHC\nfnsaGq+fM3KXJVv2R6J62mXQOfg4xyDLpWlwcBK4aSBBMoiBcsjouqSlZQlqMpdf\nZBgixqHe6U8BsFJg/6ZxC0y+e3AIss4Bo4/lb+1lAoGAFOexvaBh21K6W3inmRW4\nLlkVYJaBJ20OwokXg5aXjBiHxqmk7VLAuFbkpb5LOKH2xPILRQ0OEkn51yVymS3T\n9lLpHOFTQXt5tF2/F7NW7kaQJNlLr/h5jPi3O9XHeFmuaN2z150ZB6zzgjeGKzr8\ni+1fgTsRfDtNw8xkSH9qL1Y=\n-----END PRIVATE KEY-----\n',
111
+ // client_email: 'firebase-adminsdk-xmm2e@operato.iam.gserviceaccount.com'
112
+ // },
113
+ // appConfig: {
114
+ // apiKey: 'AIzaSyDdTM2BTLHSt2LNS0G5QB8G0i4KBXFiG7U',
115
+ // projectId: 'operato',
116
+ // messagingSenderId: 79537064975,
117
+ // appId: '1:79537064975:web:32f53119e9c8c6ee2a277a'
118
+ // },
119
+ // serverKey:
120
+ // 'AAAAEoTHTA8:APA91bGwt-4HT82Dfwf_VwbQaKT0_qHd0Y3tuW41udjWz5Lz0Ko0mEMD6WbHHSILvQpa6yuoGGKCMsrU7VW2qWRrUm3CYpyG9oSwshNm1tIhljAnOuUfwHCoawbVLwf9qlWpHt4dwCoc'
121
+ // },
122
+ // vapidKey: {
123
+ // subject: 'mailto:heartyoh@hatiolab.com',
124
+ // publicKey: 'BAkVkITsCXBIsYL1yeaBmx5_dn57we-ZXMjirPPHzC2dan82cdEnAio_53PQ-1_w3ykWCBPrrFAWQ_d9N4cFF0o',
125
+ // privateKey: '4pmlt3Wk019u7nqU3Q_oGZE6LbUDjjf8DpmAcn9-iss'
126
+ // }
72
127
  },
73
- attachmentsPath: 'attachment',
74
128
  fulfillmentIntegrationOperato: {
75
- host: 'operato.com:3000',
129
+ host: 'operato-h.com:3000',
76
130
  protocol: 'http',
77
131
  platform: 'operato',
78
132
  application: 'Operato MMS',
79
133
  appKey: 'a9bf751e622bf146662b240d58971051',
80
134
  appSecret: '1c385935dc131c4b902b9bbf6a4798af',
81
- type: 'MMS',
82
- callback: 'http://operato.com:9000/callback-operato'
83
- },
84
- fulfillmentIntegrationOperatoSftp: {
85
- host: 'operato.com:3000',
86
- protocol: 'http',
87
- platform: 'operato',
88
- application: 'Operato SFTP',
89
- appKey: 'd3ebaf18121947931b5902d78adc9a98',
90
- appSecret: '41e5591dd6597a75ae5d54603494525b',
91
- type: 'SFTP',
92
- callback: 'http://operato.com:9000/callback-operato'
135
+ callback: 'http://operato-retail.com:5000/callback-operato'
93
136
  },
94
137
  marketplaceIntegrationShopee: {
95
138
  platform: 'shopee',
96
139
  isUAT: false,
97
140
  application: 'Operato MMS',
98
141
  partnerId: 846025,
99
- partnerKey: 'd34cfd85a603f196a0d74ebe08043280c1a27788bb36bdffd61e7e0bb1c90b64',
100
- v2: true
142
+ partnerKey: 'd34cfd85a603f196a0d74ebe08043280c1a27788bb36bdffd61e7e0bb1c90b64'
101
143
  },
102
- // marketplaceIntegrationShopee: {
103
- // platform: 'shopee',
104
- // isUAT: false,
105
- // application: 'Staging MMS',
106
- // partnerId: 845525,
107
- // partnerKey: '4a3f4214fd0f0bda970b342a99b6f8705fc7bacad2743cffa7ed67b79840665e'
108
- // },
109
144
  marketplaceIntegrationLazada: {
110
145
  platform: 'lazada',
111
146
  application: 'operato-mms',
@@ -113,19 +148,12 @@ module.exports = {
113
148
  appSecret: 'HB3RTNEXHlVSlBr9SmWF8AjbSUT7a825',
114
149
  callback: 'https://maybank.operato-m.com/lazada-callback'
115
150
  },
116
- sellercraftChannelIntegrationConfig: {
117
- tokenCraftApiKey: 'gf2oZbK2rv47qO0bQPbkV8RsqhlHcnSVq267W5I8',
118
- apiKey: 'eqDVmIp0kxakM4sNnzqTkySBM73UGMS1nOPDN5Z1',
119
- tokenCraftUrl: 'https://tokencraft.piggylabs.com/v1/get-shop',
120
- getShopsTokenCraftUrl: 'https://tokencraft.piggylabs.com/v1/get-shops'
121
- },
122
- sellercraftIntegrationConfig: {
123
- apiKey: 'Et0KqtLvA6e92bDvOywy9eCCud4hpAal8akpqI90'
124
- },
125
- sftpFileStorage: {
126
- type: 's3',
127
- accessKeyId: 'AKIAUQEOPWEJKL43OMZA',
128
- secretAccessKey: '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',
129
- bucketName: 'operato-sftp'
151
+ accountingIntegrationXero: {
152
+ platform: 'xero',
153
+ application: 'Operato WMS',
154
+ apiKey: '6B12D1AAC05347DC92159C2AEC812859',
155
+ apiSecret: 'T139_ItMjObC82mmy7iwnNflhd2iV0kUvDBj0P_201EmA7Sj',
156
+ callback: 'http://operato-h.com:3000/callback-xero',
157
+ hostname: 'http://operato-h.com:3000/'
130
158
  }
131
159
  }
@@ -45,6 +45,9 @@ api_1.restfulApiRouter.post(`/${apiVersion}/warehouse/:warehouseId/add-release-o
45
45
  where: { id: customerBizplaceId },
46
46
  relations: ['domain']
47
47
  });
48
+ const worksheetPickingAssignment = await tx.getRepository(setting_base_1.Setting).findOne({
49
+ where: { domain, category: 'id-rule', name: 'enable-worksheet-picking-activation-assignment' }
50
+ });
48
51
  releaseGood = {
49
52
  domain,
50
53
  bizplace: customerBizplace,
@@ -93,7 +96,8 @@ api_1.restfulApiRouter.post(`/${apiVersion}/warehouse/:warehouseId/add-release-o
93
96
  discountAmount: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.discountAmount,
94
97
  taxAmount: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.taxAmount,
95
98
  shippingFee: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.shippingFee,
96
- lmdOption: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.lmdOption
99
+ lmdOption: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.lmdOption,
100
+ assignedInventory: (worksheetPickingAssignment === null || worksheetPickingAssignment === void 0 ? void 0 : worksheetPickingAssignment.value) == 'true' ? false : true
97
101
  };
98
102
  // check existing order
99
103
  await checkExistingOrder(releaseGood, customerBizplace, bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.checkDuplicationValidation, context, tx);
@@ -153,11 +157,11 @@ api_1.restfulApiRouter.post(`/${apiVersion}/warehouse/:warehouseId/add-release-o
153
157
  }
154
158
  // assignment
155
159
  // console.time('assign')
156
- let assignedOrderProducts = await assignToInventory(massagedData.orderProducts, customerBizplace, context, tx);
160
+ let assignedOrderProducts = await assignToInventory(massagedData.orderProducts, customerBizplace, context, tx, worksheetPickingAssignment);
157
161
  // console.timeEnd('assign')
158
162
  // create order
159
163
  // console.time('save')
160
- let result = await createReleaseGood(releaseGood, assignedOrderProducts, customerBizplace, context, tx);
164
+ let result = await createReleaseGood(releaseGood, assignedOrderProducts, customerBizplace, context, tx, worksheetPickingAssignment);
161
165
  // console.timeEnd('save')
162
166
  let addReleaseGood = {
163
167
  id: result.id,
@@ -391,7 +395,7 @@ async function createDraftOrder(releaseGood, orderProducts, context) {
391
395
  return await (0, sales_base_1.createDraftReleaseGoodFunction)(null, releaseGood, orderProducts, null, [], context, tx);
392
396
  });
393
397
  }
394
- async function createReleaseGood(releaseGood, orderProducts, bizplace, context, tx) {
398
+ async function createReleaseGood(releaseGood, orderProducts, bizplace, context, tx, worksheetPickingAssignment) {
395
399
  try {
396
400
  const { domain, user } = context.state;
397
401
  const settingRepo = (tx === null || tx === void 0 ? void 0 : tx.getRepository(setting_base_1.Setting)) || (0, typeorm_1.getRepository)(setting_base_1.Setting);
@@ -485,7 +489,9 @@ async function createReleaseGood(releaseGood, orderProducts, bizplace, context,
485
489
  creator: user,
486
490
  updater: user,
487
491
  acceptedBy: user,
488
- acceptedAt: new Date()
492
+ acceptedAt: new Date(),
493
+ assignedInventory: (worksheetPickingAssignment === null || worksheetPickingAssignment === void 0 ? void 0 : worksheetPickingAssignment.value) == 'true' ? false : true,
494
+ orderMethod: sales_base_1.ORDER_METHOD.SELECT_BY_PRODUCT
489
495
  };
490
496
  let resultReleaseGood = await tx.getRepository(sales_base_1.ReleaseGood).save(newReleaseGood);
491
497
  let combinedOrderInventories = [];
@@ -493,17 +499,19 @@ async function createReleaseGood(releaseGood, orderProducts, bizplace, context,
493
499
  let orderInventories = orderProduct.orderInventories;
494
500
  orderProduct = Object.assign(new sales_base_1.OrderProduct(), Object.assign(Object.assign({}, orderProduct), { name: (0, uuid_1.v4)(), domain: domain, bizplace: bizplace, releaseGood: resultReleaseGood, type: sales_base_1.ORDER_TYPES.RELEASE_OF_GOODS, status: sales_base_1.ORDER_PRODUCT_STATUS.ASSIGNED }));
495
501
  let result = await tx.getRepository(sales_base_1.OrderProduct).save(orderProduct);
496
- for (let oiIdx = 0; oiIdx < orderInventories.length; oiIdx++) {
497
- let orderInventory = Object.assign(new sales_base_1.OrderInventory(), Object.assign(Object.assign({}, orderInventories[oiIdx]), { name: (0, uuid_1.v4)(), domain: domain, bizplace: bizplace, releaseGood: resultReleaseGood, type: sales_base_1.ORDER_TYPES.RELEASE_OF_GOODS, status: sales_base_1.ORDER_INVENTORY_STATUS.PENDING_WORKSHEET, orderProduct: result }));
498
- await tx.getRepository(sales_base_1.OrderInventory).save(orderInventory);
499
- combinedOrderInventories.push({
500
- product: { name: orderInventory.product.name, sku: orderInventory.product.sku },
501
- batchId: orderInventory.batchId,
502
- packingType: orderInventory.packingType,
503
- packingSize: orderInventory.packingSize,
504
- releaseQty: orderInventory.releaseQty,
505
- releaseUomValue: orderInventory.releaseUomValue
506
- });
502
+ if (worksheetPickingAssignment.value !== 'true') {
503
+ for (let oiIdx = 0; oiIdx < orderInventories.length; oiIdx++) {
504
+ let orderInventory = Object.assign(new sales_base_1.OrderInventory(), Object.assign(Object.assign({}, orderInventories[oiIdx]), { name: (0, uuid_1.v4)(), domain: domain, bizplace: bizplace, releaseGood: resultReleaseGood, type: sales_base_1.ORDER_TYPES.RELEASE_OF_GOODS, status: sales_base_1.ORDER_INVENTORY_STATUS.PENDING_WORKSHEET, orderProduct: result }));
505
+ await tx.getRepository(sales_base_1.OrderInventory).save(orderInventory);
506
+ combinedOrderInventories.push({
507
+ product: { name: orderInventory.product.name, sku: orderInventory.product.sku },
508
+ batchId: orderInventory.batchId,
509
+ packingType: orderInventory.packingType,
510
+ packingSize: orderInventory.packingSize,
511
+ releaseQty: orderInventory.releaseQty,
512
+ releaseUomValue: orderInventory.releaseUomValue
513
+ });
514
+ }
507
515
  }
508
516
  return result;
509
517
  }));
@@ -745,102 +753,103 @@ async function massageOrderItems(releaseGood, inputOrderProducts, context) {
745
753
  throw error;
746
754
  }
747
755
  }
748
- async function assignToInventory(orderProducts, customerBizplace, context, tx) {
756
+ async function assignToInventory(orderProducts, customerBizplace, context, tx, worksheetPickingAssignment) {
749
757
  const { client, domain, user } = context.state;
758
+ const pickingProductSetting = await tx.getRepository(setting_base_1.Setting).findOne({
759
+ where: { domain, name: 'rule-for-picking-product' }
760
+ });
750
761
  for (let opIdx = 0; opIdx < orderProducts.length; opIdx++) {
751
762
  let orderProduct = orderProducts[opIdx];
752
763
  let assignedOrderInventories = [];
753
- const pickingProductSetting = await tx.getRepository(setting_base_1.Setting).findOne({
754
- where: { domain, name: 'rule-for-picking-product' }
755
- });
756
764
  for (let oiIdx = 0; oiIdx < orderProducts[opIdx].orderInventories.length; oiIdx++) {
757
765
  const orderInventory = orderProduct.orderInventories[oiIdx];
758
766
  let sortings = [];
759
- switch (orderInventory.product.pickingStrategy) {
760
- case 'LIFO':
761
- sortings.push({ name: 'iv.created_at', desc: true });
762
- if (pickingProductSetting === null || pickingProductSetting === void 0 ? void 0 : pickingProductSetting.value) {
763
- for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
764
- sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false });
767
+ if ((worksheetPickingAssignment === null || worksheetPickingAssignment === void 0 ? void 0 : worksheetPickingAssignment.value) !== 'true') {
768
+ switch (orderInventory.product.pickingStrategy) {
769
+ case 'LIFO':
770
+ sortings.push({ name: 'iv.created_at', desc: true });
771
+ if (pickingProductSetting === null || pickingProductSetting === void 0 ? void 0 : pickingProductSetting.value) {
772
+ for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
773
+ sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false });
774
+ }
765
775
  }
766
- }
767
- else {
768
- sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false });
769
- }
770
- break;
771
- case 'FEFO':
772
- sortings.push({ name: 'iv.expiration_date', desc: false }, { name: 'iv.created_at', desc: false });
773
- if (pickingProductSetting === null || pickingProductSetting === void 0 ? void 0 : pickingProductSetting.value) {
774
- for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
775
- sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false });
776
+ else {
777
+ sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false });
776
778
  }
777
- }
778
- else {
779
- sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false });
780
- }
781
- break;
782
- case 'FMFO':
783
- sortings.push({ name: 'iv.manufacture_date', desc: false }, { name: 'iv.created_at', desc: false });
784
- if (pickingProductSetting === null || pickingProductSetting === void 0 ? void 0 : pickingProductSetting.value) {
785
- for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
786
- sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false });
779
+ break;
780
+ case 'FEFO':
781
+ sortings.push({ name: 'iv.expiration_date', desc: false }, { name: 'iv.created_at', desc: false });
782
+ if (pickingProductSetting === null || pickingProductSetting === void 0 ? void 0 : pickingProductSetting.value) {
783
+ for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
784
+ sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false });
785
+ }
787
786
  }
788
- }
789
- else {
790
- sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false });
791
- }
792
- break;
793
- case 'LOCATION':
794
- if (pickingProductSetting === null || pickingProductSetting === void 0 ? void 0 : pickingProductSetting.value) {
795
- for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
796
- sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false });
787
+ else {
788
+ sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false });
797
789
  }
798
- }
799
- else {
800
- sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false });
801
- }
802
- break;
803
- //Every other case includes 'FIFO' will be applicable for this case
804
- default:
805
- sortings.push({ name: 'iv.created_at', desc: false });
806
- if (pickingProductSetting === null || pickingProductSetting === void 0 ? void 0 : pickingProductSetting.value) {
807
- for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
808
- sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false });
790
+ break;
791
+ case 'FMFO':
792
+ sortings.push({ name: 'iv.manufacture_date', desc: false }, { name: 'iv.created_at', desc: false });
793
+ if (pickingProductSetting === null || pickingProductSetting === void 0 ? void 0 : pickingProductSetting.value) {
794
+ for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
795
+ sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false });
796
+ }
797
+ }
798
+ else {
799
+ sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false });
800
+ }
801
+ break;
802
+ case 'LOCATION':
803
+ if (pickingProductSetting === null || pickingProductSetting === void 0 ? void 0 : pickingProductSetting.value) {
804
+ for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
805
+ sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false });
806
+ }
807
+ }
808
+ else {
809
+ sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false });
809
810
  }
810
- }
811
- else {
812
- sortings.push({ name: 'loc.name', desc: false });
813
- sortings.push({ name: 'iv.pallet_id', desc: false });
814
- }
815
- break;
816
- }
817
- let queryFilters = [];
818
- let queryStrings = queryFilters.reduce((acc, itm, idx, arr) => {
819
- acc.values.push(itm.filters);
820
- switch (itm === null || itm === void 0 ? void 0 : itm.operator) {
821
- case 'notin':
822
- case 'in':
823
- acc.query.push(`${itm.query} ${itm.operator == 'notin' ? 'NOT IN' : 'IN'} (${itm.filtes
824
- .map((itm, idx) => {
825
- return `$${acc.values.length + 1}`;
826
- })
827
- .join(',')})`);
828
811
  break;
812
+ //Every other case includes 'FIFO' will be applicable for this case
829
813
  default:
830
- acc.query.push(`${itm.query} ${(itm === null || itm === void 0 ? void 0 : itm.operator) ? itm.operator : '='} $${acc.values.length + 1}`);
814
+ sortings.push({ name: 'iv.created_at', desc: false });
815
+ if (pickingProductSetting === null || pickingProductSetting === void 0 ? void 0 : pickingProductSetting.value) {
816
+ for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
817
+ sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false });
818
+ }
819
+ }
820
+ else {
821
+ sortings.push({ name: 'loc.name', desc: false });
822
+ sortings.push({ name: 'iv.pallet_id', desc: false });
823
+ }
831
824
  break;
832
825
  }
833
- acc.query.push(`${itm.query} ${(itm === null || itm === void 0 ? void 0 : itm.operator) ? itm.operator : '='} $${acc.values.length + 1}`);
834
- }, {
835
- query: [],
836
- values: []
837
- });
838
- let sortQuery = sortings
839
- .map(itm => {
840
- return `${itm.name} ${itm.desc ? 'DESC' : 'ASC'}`;
841
- })
842
- .join(`,`);
843
- let updatedInventories = await tx.getRepository(warehouse_base_1.Inventory).query(`
826
+ let queryFilters = [];
827
+ let queryStrings = queryFilters.reduce((acc, itm, idx, arr) => {
828
+ acc.values.push(itm.filters);
829
+ switch (itm === null || itm === void 0 ? void 0 : itm.operator) {
830
+ case 'notin':
831
+ case 'in':
832
+ acc.query.push(`${itm.query} ${itm.operator == 'notin' ? 'NOT IN' : 'IN'} (${itm.filtes
833
+ .map((itm, idx) => {
834
+ return `$${acc.values.length + 1}`;
835
+ })
836
+ .join(',')})`);
837
+ break;
838
+ default:
839
+ acc.query.push(`${itm.query} ${(itm === null || itm === void 0 ? void 0 : itm.operator) ? itm.operator : '='} $${acc.values.length + 1}`);
840
+ break;
841
+ }
842
+ acc.query.push(`${itm.query} ${(itm === null || itm === void 0 ? void 0 : itm.operator) ? itm.operator : '='} $${acc.values.length + 1}`);
843
+ }, {
844
+ query: [],
845
+ values: []
846
+ });
847
+ let sortQuery = sortings
848
+ .map(itm => {
849
+ return `${itm.name} ${itm.desc ? 'DESC' : 'ASC'}`;
850
+ })
851
+ .join(`,`);
852
+ let updatedInventories = await tx.getRepository(warehouse_base_1.Inventory).query(`
844
853
  update inventories tgt set locked_qty = coalesce(locked_qty,0) + src.reserve_qty,
845
854
  locked_uom_value = coalesce(locked_uom_value,0) + src.reserve_uom_value,
846
855
  updated_at = NOW(),
@@ -853,12 +862,12 @@ async function assignToInventory(orderProducts, customerBizplace, context, tx) {
853
862
  case when "lock_amount" < 0 then "available_qty" else "available_qty" - "lock_amount" end as "reserve_qty"
854
863
  from (
855
864
  select *,
856
- qty - locked_qty as available_qty,
857
- sum(qty - locked_qty - release_qty) over (order by sort_seq asc rows between unbounded preceding and current row) as lock_amount
865
+ qty - locked_qty - unassigned_qty as available_qty,
866
+ sum(qty - locked_qty - release_qty - unassigned_qty) over (order by sort_seq asc rows between unbounded preceding and current row) as lock_amount
858
867
  from (
859
868
  SELECT 0 as sort_seq, null as id, null as pallet_id, null as batch_id, null as batch_id_ref,
860
869
  null as unit, '${orderInventory.uom}' as uom, '${orderInventory.packingType}' as packing_type, '${orderInventory.packingSize}' as packing_size,
861
- null as manufacture_year, null as carton_id, 0 as uom_value, 0 as locked_uom_value, 0 as qty, 0 as locked_qty, null as created_at,
870
+ null as manufacture_year, null as carton_id, 0 as uom_value, 0 as locked_uom_value, 0 as qty, 0 as locked_qty, 0 as unassigned_uom_value, 0 as unassigned_qty, null as created_at,
862
871
  '${orderInventory.releaseQty}' as release_qty, '${orderInventory.releaseUomValue}' as release_uom_value
863
872
  UNION
864
873
  (
@@ -866,9 +875,10 @@ async function assignToInventory(orderProducts, customerBizplace, context, tx) {
866
875
  iv.id, iv.pallet_id, iv.batch_id, iv.batch_id_ref,
867
876
  iv.unit, iv.uom, iv.packing_type, iv.packing_size,
868
877
  iv.manufacture_year, iv.carton_id, iv.uom_value,
869
- coalesce(iv.locked_uom_value,0) as locked_uom_value, iv.qty, coalesce(iv.locked_qty,0) as locked_qty, iv.created_at,
878
+ coalesce(iv.locked_uom_value,0) as locked_uom_value, iv.qty, coalesce(iv.locked_qty,0) as locked_qty, coalesce(pds.unassigned_uom_value,0) as unassigned_uom_value, coalesce(pds.unassigned_qty,0) as unassigned_qty, iv.created_at,
870
879
  0 as release_qty, 0 as release_uom_value
871
880
  FROM "inventories" "iv"
881
+ LEFT JOIN "product_detail_stocks" "pds" ON "pds"."product_detail_id" = "iv"."product_detail_id"
872
882
  INNER JOIN "locations" "loc" ON "loc"."id"="iv"."location_id"
873
883
  INNER JOIN "products" "p" ON "p"."id"="iv"."product_id"
874
884
  INNER JOIN "warehouse_inventory_assignment_rankings" "wiar" ON "wiar"."location_type"="loc"."type"
@@ -886,42 +896,55 @@ async function assignToInventory(orderProducts, customerBizplace, context, tx) {
886
896
  tgt."id", tgt."qty", tgt."pallet_id", tgt."carton_id", tgt."batch_id", tgt."batch_id_ref", tgt."unit",
887
897
  tgt."uom", tgt."packing_type", tgt."packing_size", tgt."manufacture_year",
888
898
  tgt."locked_qty", tgt."uom_value", tgt."locked_uom_value", src."reserve_qty", src."reserve_uom_value";`, [
889
- user.id,
890
- domain.id,
891
- customerBizplace.id,
892
- orderInventory.packingType,
893
- orderInventory.packingSize,
894
- orderInventory.product.id,
895
- warehouse_base_1.INVENTORY_STATUS.STORED,
896
- warehouse_base_1.LOCATION_TYPE.QUARANTINE,
897
- warehouse_base_1.LOCATION_TYPE.RESERVE,
898
- warehouse_base_1.LOCATION_TYPE.STORAGE,
899
- ...queryStrings.values
900
- ]);
901
- let totalAssigned = updatedInventories[0].reduce((acc, inv) => {
902
- return acc + inv.reserve_qty;
903
- }, 0);
904
- if (orderInventory.releaseQty != totalAssigned) {
905
- throw new index_1.ValidationError({
906
- errorCode: 'INSUFFICIENT_STOCK',
907
- message: 'insufficient stock',
908
- detail: JSON.stringify({
909
- code: 'insufficient stock',
910
- sku: orderInventory.product.sku,
911
- packingType: orderInventory.packingType,
912
- packingSize: orderInventory.packingSize,
913
- uom: orderInventory.uom,
914
- qty: orderInventory.releaseQty,
915
- uom_value: orderInventory.releaseUomValue
916
- })
899
+ user.id,
900
+ domain.id,
901
+ customerBizplace.id,
902
+ orderInventory.packingType,
903
+ orderInventory.packingSize,
904
+ orderInventory.product.id,
905
+ warehouse_base_1.INVENTORY_STATUS.STORED,
906
+ warehouse_base_1.LOCATION_TYPE.QUARANTINE,
907
+ warehouse_base_1.LOCATION_TYPE.RESERVE,
908
+ warehouse_base_1.LOCATION_TYPE.STORAGE,
909
+ ...queryStrings.values
910
+ ]);
911
+ let totalAssigned = updatedInventories[0].reduce((acc, inv) => {
912
+ return acc + inv.reserve_qty;
913
+ }, 0);
914
+ if (orderInventory.releaseQty != totalAssigned) {
915
+ throw new index_1.ValidationError({
916
+ errorCode: 'INSUFFICIENT_STOCK',
917
+ message: 'insufficient stock',
918
+ detail: JSON.stringify({
919
+ code: 'insufficient stock',
920
+ sku: orderInventory.product.sku,
921
+ packingType: orderInventory.packingType,
922
+ packingSize: orderInventory.packingSize,
923
+ uom: orderInventory.uom,
924
+ qty: orderInventory.releaseQty,
925
+ uom_value: orderInventory.releaseUomValue
926
+ })
927
+ });
928
+ }
929
+ updatedInventories[0].forEach(inv => {
930
+ let oi = Object.assign(Object.assign({}, orderInventory), { inventory: { id: inv.id }, uom: inv.uom, packingType: inv.packing_type, batchId: inv.batch_id, releaseQty: inv.reserve_qty, releaseUomValue: inv.reserve_uom_value, pickedQty: 0, packedQty: 0, type: sales_base_1.ORDER_TYPES.RELEASE_OF_GOODS, status: sales_base_1.ORDER_INVENTORY_STATUS.PENDING_WORKSHEET, domain: { id: domain.id }, bizplace: { id: customerBizplace.id } });
931
+ assignedOrderInventories.push(oi);
917
932
  });
933
+ orderProducts[opIdx].orderInventories = assignedOrderInventories;
934
+ }
935
+ else {
936
+ await tx
937
+ .getRepository(warehouse_base_1.ProductDetailStock)
938
+ .createQueryBuilder()
939
+ .update(warehouse_base_1.ProductDetailStock)
940
+ .set({
941
+ unassignedQty: () => `"unassigned_qty" + ${orderInventory.releaseQty}`,
942
+ unassignedUomValue: () => `"unassigned_uom_value" + ${orderInventory.releaseUomValue}`
943
+ })
944
+ .where({ productDetail: orderInventory.productDetail.id })
945
+ .execute();
918
946
  }
919
- updatedInventories[0].forEach(inv => {
920
- let oi = Object.assign(Object.assign({}, orderInventory), { inventory: { id: inv.id }, uom: inv.uom, packingType: inv.packing_type, batchId: inv.batch_id, releaseQty: inv.reserve_qty, releaseUomValue: inv.reserve_uom_value, pickedQty: 0, packedQty: 0, type: sales_base_1.ORDER_TYPES.RELEASE_OF_GOODS, status: sales_base_1.ORDER_INVENTORY_STATUS.PENDING_WORKSHEET, domain: { id: domain.id }, bizplace: { id: customerBizplace.id } });
921
- assignedOrderInventories.push(oi);
922
- });
923
947
  }
924
- orderProducts[opIdx].orderInventories = assignedOrderInventories;
925
948
  }
926
949
  return orderProducts;
927
950
  }