@things-factory/worksheet-base 4.3.76 → 4.3.77
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.
- package/dist-server/graphql/resolvers/worksheet/confirm-cancellation-release-order.js +12 -0
- package/dist-server/graphql/resolvers/worksheet/confirm-cancellation-release-order.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/pending-cancellation-release-order.js +87 -79
- package/dist-server/graphql/resolvers/worksheet/pending-cancellation-release-order.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/reject-cancellation-release-order.js +92 -150
- package/dist-server/graphql/resolvers/worksheet/reject-cancellation-release-order.js.map +1 -1
- package/package.json +2 -2
- package/server/graphql/resolvers/worksheet/confirm-cancellation-release-order.ts +13 -0
- package/server/graphql/resolvers/worksheet/pending-cancellation-release-order.ts +99 -94
- package/server/graphql/resolvers/worksheet/reject-cancellation-release-order.ts +98 -214
|
@@ -67,6 +67,18 @@ exports.confirmCancellationReleaseOrder = {
|
|
|
67
67
|
})
|
|
68
68
|
.where('id = :id', { id: inventory.id })
|
|
69
69
|
.execute();
|
|
70
|
+
// @ChrisLim-git commented for further review as it causes qty to add into inventory
|
|
71
|
+
// await tx
|
|
72
|
+
// .createQueryBuilder()
|
|
73
|
+
// .update(Inventory)
|
|
74
|
+
// .set({
|
|
75
|
+
// qty: () => `COALESCE("qty", 0) + ${orderInventory.releaseQty}`,
|
|
76
|
+
// uomValue: () => `COALESCE("uom_value", 0) + ${orderInventory.releaseUomValue}`,
|
|
77
|
+
// status: INVENTORY_STATUS.STORED,
|
|
78
|
+
// updater: user
|
|
79
|
+
// })
|
|
80
|
+
// .where('id = :id', { id: inventory.id })
|
|
81
|
+
// .execute()
|
|
70
82
|
}
|
|
71
83
|
return orderInventory;
|
|
72
84
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"confirm-cancellation-release-order.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/worksheet/confirm-canc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MAAM,CAAC,0BAAS,CAAC;yBACjB,GAAG,CAAC;wBACH,SAAS,EAAE,GAAG,EAAE,CAAC,+BAA+B,cAAc,CAAC,UAAU,EAAE;wBAC3E,cAAc,EAAE,GAAG,EAAE,CAAC,qCAAqC,cAAc,CAAC,eAAe,EAAE;wBAC3F,OAAO,EAAE,IAAI;qBACd,CAAC;yBACD,KAAK,CAAC,UAAU,EAAE,EAAE,EAAE,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC;yBACvC,OAAO,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"confirm-cancellation-release-order.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/worksheet/confirm-cancellation-release-order.ts"],"names":[],"mappings":";;;AAAA,qCAA2C;AAG3C,2DAQmC;AAEnC,mEAAkH;AAElH,gDAA8D;AAC9D,0CAAyD;AAE5C,QAAA,+BAA+B,GAAG;IAC7C,KAAK,CAAC,+BAA+B,CAAC,CAAM,EAAE,EAAE,IAAI,EAAE,EAAE,OAAY;QAClE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAsD,OAAO,CAAC,KAAK,CAAA;QAC7F,IAAI,WAAW,GAAgB,MAAM,EAAE,CAAC,aAAa,CAAC,wBAAW,CAAC,CAAC,OAAO,CAAC;YACzE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,yBAAY,CAAC,cAAc,EAAE;YAC5D,SAAS,EAAE;gBACT,UAAU;gBACV,kBAAkB;gBAClB,4BAA4B;gBAC5B,qCAAqC;gBACrC,WAAW;aACZ;SACF,CAAC,CAAA;QAEF,IAAI,CAAC,WAAW;YAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;QACvE,IAAI,SAAS,GAAqB,WAAW,CAAC,gBAAgB,CAAA;QAC9D,IAAI,QAAQ,GAAe,WAAW,CAAC,SAAS,CAAA;QAEhD,kCAAkC;QAClC,8FAA8F;QAC9F,IAAI,SAAS,GAAqB,+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B,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,KAAK,MAAM,CAAC;SACpD,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE;QAClB,IAAI,cAAc,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,eAAC,OAAA,CAAA,MAAA,CAAC,CAAC,SAAS,0CAAE,EAAE,MAAI,MAAA,EAAE,CAAC,SAAS,0CAAE,EAAE,CAAA,CAAA,EAAA,CAAC,CAAA;QACjG,IAAI,cAAc,IAAI,CAAC,EAAE;YACvB,GAAG,CAAC,cAAc,CAAC,CAAC,UAAU,IAAI,EAAE,CAAC,UAAU,CAAA;YAC/C,GAAG,CAAC,cAAc,CAAC,CAAC,eAAe,IAAI,EAAE,CAAC,UAAU,CAAA;SACrD;aAAM;YACL,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;SACb;QACD,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAAE,CAAC,CAAA;AACV,CAAC"}
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.pendingCancellationReleaseOrder = void 0;
|
|
4
4
|
const typeorm_1 = require("typeorm");
|
|
5
|
-
const auth_base_1 = require("@things-factory/auth-base");
|
|
6
5
|
const sales_base_1 = require("@things-factory/sales-base");
|
|
7
6
|
const entities_1 = require("../../../entities");
|
|
8
7
|
exports.pendingCancellationReleaseOrder = {
|
|
9
8
|
async pendingCancellationReleaseOrder(_, { name }, context) {
|
|
10
|
-
var _a;
|
|
11
9
|
const { tx, domain, user } = context.state;
|
|
12
10
|
const foundRO = await tx.getRepository(sales_base_1.ReleaseGood).findOne({
|
|
13
11
|
where: { domain, name },
|
|
14
12
|
relations: ['bizplace', 'orderInventories', 'orderVass']
|
|
15
13
|
});
|
|
14
|
+
if (foundRO.status === "DONE")
|
|
15
|
+
throw new Error('Release good has been completed!');
|
|
16
16
|
if (!foundRO)
|
|
17
17
|
throw new Error(`Release good order doesn't exists.`);
|
|
18
18
|
let targetOIs = foundRO.orderInventories;
|
|
@@ -58,54 +58,62 @@ exports.pendingCancellationReleaseOrder = {
|
|
|
58
58
|
});
|
|
59
59
|
await tx.getRepository(sales_base_1.OrderVas).save(foundOVs);
|
|
60
60
|
}
|
|
61
|
-
if (pickedOIs && pickedOIs.length) {
|
|
62
|
-
let pickedWSD = await tx.getRepository(entities_1.WorksheetDetail).find({
|
|
63
|
-
where: {
|
|
64
|
-
domain,
|
|
65
|
-
targetInventory: (0, typeorm_1.In)(pickedOIs.map(oi => oi.id)),
|
|
66
|
-
status: sales_base_1.ORDER_INVENTORY_STATUS.DONE
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
pickedWSD = pickedWSD.map((wsd) => {
|
|
70
|
-
return Object.assign(Object.assign({}, wsd), { status: sales_base_1.ORDER_INVENTORY_STATUS.PENDING_CANCEL, updater: user });
|
|
71
|
-
});
|
|
72
|
-
await tx.getRepository(entities_1.WorksheetDetail).save(pickedWSD);
|
|
73
|
-
let replacedWSD = await tx.getRepository(entities_1.WorksheetDetail).find({
|
|
74
|
-
where: {
|
|
75
|
-
domain,
|
|
76
|
-
targetInventory: (0, typeorm_1.In)(pickedOIs.map(oi => oi.id)),
|
|
77
|
-
status: sales_base_1.ORDER_INVENTORY_STATUS.REPLACED
|
|
78
|
-
},
|
|
79
|
-
relations: ['targetInventory']
|
|
80
|
-
});
|
|
81
|
-
if (replacedWSD && replacedWSD.length) {
|
|
82
|
-
let replacedOI = replacedWSD.map((wsd) => wsd.targetInventory);
|
|
83
|
-
replacedOI = replacedOI.map((oi) => {
|
|
84
|
-
return Object.assign(Object.assign({}, oi), { status: sales_base_1.ORDER_INVENTORY_STATUS.REPLACED, updater: user });
|
|
85
|
-
});
|
|
86
|
-
await tx.getRepository(sales_base_1.OrderInventory).save(replacedOI);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (pickingOIs && pickingOIs.length) {
|
|
90
|
-
let pickingWSD = await tx.getRepository(entities_1.WorksheetDetail).find({
|
|
91
|
-
where: { domain, targetInventory: (0, typeorm_1.In)(pickingOIs.map(oi => oi.id)) }
|
|
92
|
-
});
|
|
93
|
-
pickingWSD = pickingWSD.map((wsd) => {
|
|
94
|
-
return Object.assign(Object.assign({}, wsd), { status: sales_base_1.ORDER_INVENTORY_STATUS.PENDING_CANCEL, updater: user });
|
|
95
|
-
});
|
|
96
|
-
await tx.getRepository(entities_1.WorksheetDetail).save(pickingWSD);
|
|
97
|
-
}
|
|
98
61
|
// find worksheet and update status to PENDING_CANCEL
|
|
99
|
-
let foundWS = await tx.getRepository(entities_1.Worksheet).
|
|
62
|
+
let foundWS = await tx.getRepository(entities_1.Worksheet).findOne({
|
|
100
63
|
where: {
|
|
101
64
|
domain,
|
|
102
65
|
releaseGood: foundRO
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
foundWS = foundWS.map((ws) => {
|
|
106
|
-
return Object.assign(Object.assign({}, ws), { status: sales_base_1.ORDER_INVENTORY_STATUS.PENDING_CANCEL, updater: user });
|
|
66
|
+
},
|
|
67
|
+
order: { 'createdAt': 'DESC' }
|
|
107
68
|
});
|
|
108
|
-
|
|
69
|
+
if (foundWS) {
|
|
70
|
+
await tx.getRepository(entities_1.Worksheet).update({ id: foundWS.id }, {
|
|
71
|
+
status: sales_base_1.ORDER_INVENTORY_STATUS.PENDING_CANCEL,
|
|
72
|
+
updater: user
|
|
73
|
+
});
|
|
74
|
+
if (pickedOIs && pickedOIs.length) {
|
|
75
|
+
let pickedWSD = await tx.getRepository(entities_1.WorksheetDetail).find({
|
|
76
|
+
where: {
|
|
77
|
+
domain,
|
|
78
|
+
targetInventory: (0, typeorm_1.In)(pickedOIs.map(oi => oi.id)),
|
|
79
|
+
status: sales_base_1.ORDER_INVENTORY_STATUS.DONE,
|
|
80
|
+
worksheet: foundWS
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
pickedWSD = pickedWSD.map((wsd) => {
|
|
84
|
+
return Object.assign(Object.assign({}, wsd), { status: sales_base_1.ORDER_INVENTORY_STATUS.PENDING_CANCEL, updater: user });
|
|
85
|
+
});
|
|
86
|
+
await tx.getRepository(entities_1.WorksheetDetail).save(pickedWSD);
|
|
87
|
+
let replacedWSD = await tx.getRepository(entities_1.WorksheetDetail).find({
|
|
88
|
+
where: {
|
|
89
|
+
domain,
|
|
90
|
+
targetInventory: (0, typeorm_1.In)(pickedOIs.map(oi => oi.id)),
|
|
91
|
+
status: sales_base_1.ORDER_INVENTORY_STATUS.REPLACED,
|
|
92
|
+
worksheet: foundWS
|
|
93
|
+
},
|
|
94
|
+
relations: ['targetInventory']
|
|
95
|
+
});
|
|
96
|
+
if (replacedWSD && replacedWSD.length) {
|
|
97
|
+
let replacedOI = replacedWSD.map((wsd) => wsd.targetInventory);
|
|
98
|
+
replacedOI = replacedOI.map((oi) => {
|
|
99
|
+
return Object.assign(Object.assign({}, oi), { status: sales_base_1.ORDER_INVENTORY_STATUS.REPLACED, updater: user });
|
|
100
|
+
});
|
|
101
|
+
await tx.getRepository(sales_base_1.OrderInventory).save(replacedOI);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (pickingOIs && pickingOIs.length) {
|
|
105
|
+
let pickingWSD = await tx.getRepository(entities_1.WorksheetDetail).find({
|
|
106
|
+
where: {
|
|
107
|
+
domain, targetInventory: (0, typeorm_1.In)(pickingOIs.map(oi => oi.id)),
|
|
108
|
+
worksheet: foundWS
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
pickingWSD = pickingWSD.map((wsd) => {
|
|
112
|
+
return Object.assign(Object.assign({}, wsd), { status: sales_base_1.ORDER_INVENTORY_STATUS.PENDING_CANCEL, updater: user });
|
|
113
|
+
});
|
|
114
|
+
await tx.getRepository(entities_1.WorksheetDetail).save(pickingWSD);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
109
117
|
// find DO and change status to pending cancel
|
|
110
118
|
let foundDO = await tx.getRepository(sales_base_1.DeliveryOrder).find({
|
|
111
119
|
where: { domain, releaseGood: foundRO }
|
|
@@ -115,40 +123,40 @@ exports.pendingCancellationReleaseOrder = {
|
|
|
115
123
|
});
|
|
116
124
|
await tx.getRepository(sales_base_1.DeliveryOrder).save(foundDO);
|
|
117
125
|
await tx.getRepository(sales_base_1.ReleaseGood).save(Object.assign(Object.assign({}, foundRO), { status: sales_base_1.ORDER_STATUS.PENDING_CANCEL, updater: user }));
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
//
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
126
|
+
/**
|
|
127
|
+
* @notes Temporary off sendNotification due to suspect of causing wms down
|
|
128
|
+
*/
|
|
129
|
+
// // notification logics
|
|
130
|
+
// // get Office Admin Users
|
|
131
|
+
// const users: any[] = await tx
|
|
132
|
+
// .getRepository('users_roles')
|
|
133
|
+
// .createQueryBuilder('ur')
|
|
134
|
+
// .select('ur.users_id', 'id')
|
|
135
|
+
// .where(qb => {
|
|
136
|
+
// const subQuery = qb
|
|
137
|
+
// .subQuery()
|
|
138
|
+
// .select('role.id')
|
|
139
|
+
// .from(Role, 'role')
|
|
140
|
+
// .where("role.name = 'Office Admin'")
|
|
141
|
+
// .andWhere('role.domain_id = :domain', { domain: domain.id })
|
|
142
|
+
// .getQuery()
|
|
143
|
+
// return 'ur.roles_id IN ' + subQuery
|
|
144
|
+
// })
|
|
145
|
+
// .getRawMany()
|
|
146
|
+
// // send notification to Office Admin Users
|
|
147
|
+
// if (users?.length && context.header?.referer) {
|
|
148
|
+
// const receivers: any[] = users.map(user => user.id)
|
|
149
|
+
// const msg = {
|
|
150
|
+
// title: `${foundRO.name} cancellation`,
|
|
151
|
+
// body: `${customerBizplace.name} is requesting to cancel order`,
|
|
152
|
+
// url: context.header.referer,
|
|
153
|
+
// data: { url: context.header.referer }
|
|
154
|
+
// }
|
|
155
|
+
// await sendNotification({
|
|
156
|
+
// receivers,
|
|
157
|
+
// message: { ...msg }
|
|
158
|
+
// })
|
|
159
|
+
// }
|
|
152
160
|
return;
|
|
153
161
|
}
|
|
154
162
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pending-cancellation-release-order.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/worksheet/pending-cancellation-release-order.ts"],"names":[],"mappings":";;;AAAA,qCAA2C;
|
|
1
|
+
{"version":3,"file":"pending-cancellation-release-order.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/worksheet/pending-cancellation-release-order.ts"],"names":[],"mappings":";;;AAAA,qCAA2C;AAK3C,2DAQmC;AAGnC,gDAA8D;AAEjD,QAAA,+BAA+B,GAAG;IAC7C,KAAK,CAAC,+BAA+B,CAAC,CAAM,EAAE,EAAE,IAAI,EAAE,EAAE,OAAY;QAClE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAsD,OAAO,CAAC,KAAK,CAAA;QAC7F,MAAM,OAAO,GAAgB,MAAM,EAAE,CAAC,aAAa,CAAC,wBAAW,CAAC,CAAC,OAAO,CAAC;YACvE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;YACvB,SAAS,EAAE,CAAC,UAAU,EAAE,kBAAkB,EAAE,WAAW,CAAC;SACzD,CAAC,CAAA;QAEF,IAAI,OAAO,CAAC,MAAM,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xC,CAAC,CAAA;QAEF,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,aAA4B,EAAE,EAAE;YACrD,uCACK,aAAa,KAChB,MAAM,EAAE,yBAAY,CAAC,cAAc,EACnC,OAAO,EAAE,IAAI,IACd;QACH,CAAC,CAAC,CAAA;QACF,MAAM,EAAE,CAAC,aAAa,CAAC,0BAAa,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAEnD,MAAM,EAAE,CAAC,aAAa,CAAC,wBAAW,CAAC,CAAC,IAAI,iCACnC,OAAO,KACV,MAAM,EAAE,yBAAY,CAAC,cAAc,EACnC,OAAO,EAAE,IAAI,IACb,CAAA;QAGF;;WAEG;QACH,yBAAyB;QACzB,4BAA4B;QAC5B,gCAAgC;QAChC,kCAAkC;QAClC,8BAA8B;QAC9B,iCAAiC;QACjC,mBAAmB;QACnB,0BAA0B;QAC1B,oBAAoB;QACpB,2BAA2B;QAC3B,4BAA4B;QAC5B,6CAA6C;QAC7C,qEAAqE;QACrE,oBAAoB;QACpB,0CAA0C;QAC1C,OAAO;QACP,kBAAkB;QAElB,6CAA6C;QAC7C,kDAAkD;QAClD,wDAAwD;QACxD,kBAAkB;QAClB,6CAA6C;QAC7C,sEAAsE;QACtE,mCAAmC;QACnC,4CAA4C;QAC5C,MAAM;QAEN,6BAA6B;QAC7B,iBAAiB;QACjB,0BAA0B;QAC1B,OAAO;QACP,IAAI;QAEJ,OAAM;IACR,CAAC;CACF,CAAA"}
|
|
@@ -1,168 +1,110 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rejectCancellationReleaseOrder = void 0;
|
|
4
|
-
const
|
|
4
|
+
const env_1 = require("@things-factory/env");
|
|
5
5
|
const sales_base_1 = require("@things-factory/sales-base");
|
|
6
6
|
const constants_1 = require("../../../constants");
|
|
7
7
|
const entities_1 = require("../../../entities");
|
|
8
8
|
exports.rejectCancellationReleaseOrder = {
|
|
9
9
|
async rejectCancellationReleaseOrder(_, { name }, context) {
|
|
10
10
|
const { tx, domain, user } = context.state;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
throw new Error(`Release order doesn't exists.`);
|
|
24
|
-
let targetOIs = foundRO.orderInventories;
|
|
25
|
-
let foundOVs = foundRO.orderVass;
|
|
26
|
-
let isDeactivatedPicking = false;
|
|
27
|
-
foundRO.status = sales_base_1.ORDER_STATUS.PENDING_WORKSHEET;
|
|
28
|
-
// get the worksheet based on RO number
|
|
29
|
-
let foundWS = await tx.getRepository(entities_1.Worksheet).find({
|
|
30
|
-
where: {
|
|
31
|
-
domain,
|
|
32
|
-
releaseGood: foundRO
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
// check worksheet table if started_at is not null to indicate that the worksheet has been activated
|
|
36
|
-
if (foundWS && (foundWS === null || foundWS === void 0 ? void 0 : foundWS.length)) {
|
|
37
|
-
foundWS = foundWS.map((ws) => {
|
|
38
|
-
if (ws.startedAt && !ws.endedAt) {
|
|
39
|
-
return Object.assign(Object.assign({}, ws), { status: constants_1.WORKSHEET_STATUS.EXECUTING, updater: user });
|
|
40
|
-
}
|
|
41
|
-
else if (ws.startedAt && ws.endedAt) {
|
|
42
|
-
return Object.assign(Object.assign({}, ws), { status: constants_1.WORKSHEET_STATUS.DONE, updater: user });
|
|
43
|
-
}
|
|
44
|
-
else if (!ws.startedAt && !ws.endedAt && ws.type === constants_1.WORKSHEET_TYPE.PICKING) {
|
|
45
|
-
isDeactivatedPicking = true;
|
|
46
|
-
return Object.assign(Object.assign({}, ws), { status: constants_1.WORKSHEET_STATUS.DEACTIVATED, updater: user });
|
|
47
|
-
}
|
|
11
|
+
try {
|
|
12
|
+
// find release order
|
|
13
|
+
let foundRO = await tx.getRepository(sales_base_1.ReleaseGood).findOne({
|
|
14
|
+
where: { domain, name, status: sales_base_1.ORDER_STATUS.PENDING_CANCEL },
|
|
15
|
+
relations: [
|
|
16
|
+
'bizplace',
|
|
17
|
+
'orderInventories',
|
|
18
|
+
'orderInventories.inventory',
|
|
19
|
+
'orderInventories.inventory.location',
|
|
20
|
+
'orderInventories.deliveryOrder',
|
|
21
|
+
'orderVass'
|
|
22
|
+
]
|
|
48
23
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
case sales_base_1.ORDER_INVENTORY_STATUS.PICKING:
|
|
89
|
-
wsd.status = constants_1.WORKSHEET_STATUS.EXECUTING;
|
|
90
|
-
break;
|
|
91
|
-
case sales_base_1.ORDER_INVENTORY_STATUS.REPLACED:
|
|
92
|
-
wsd.status = constants_1.WORKSHEET_STATUS.REPLACED;
|
|
93
|
-
break;
|
|
94
|
-
case sales_base_1.ORDER_INVENTORY_STATUS.PICKED:
|
|
95
|
-
wsd.status = constants_1.WORKSHEET_STATUS.DONE;
|
|
96
|
-
break;
|
|
97
|
-
case sales_base_1.ORDER_INVENTORY_STATUS.LOADING:
|
|
98
|
-
wsd.status = constants_1.WORKSHEET_STATUS.DONE;
|
|
99
|
-
break;
|
|
100
|
-
case sales_base_1.ORDER_INVENTORY_STATUS.LOADED:
|
|
101
|
-
wsd.status = constants_1.WORKSHEET_STATUS.DONE;
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
else if (((_b = wsd.targetInventory) === null || _b === void 0 ? void 0 : _b.id) === oi.id && wsd.type === constants_1.WORKSHEET_TYPE.LOADING) {
|
|
106
|
-
switch (oi.status) {
|
|
107
|
-
case sales_base_1.ORDER_INVENTORY_STATUS.LOADING:
|
|
108
|
-
wsd.status = constants_1.WORKSHEET_STATUS.EXECUTING;
|
|
109
|
-
break;
|
|
110
|
-
case sales_base_1.ORDER_INVENTORY_STATUS.LOADED:
|
|
111
|
-
wsd.status = constants_1.WORKSHEET_STATUS.DONE;
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
24
|
+
if (!foundRO)
|
|
25
|
+
throw new Error(`Release order doesn't exists.`);
|
|
26
|
+
let targetOIs = foundRO.orderInventories;
|
|
27
|
+
// perform update on all order inventories and worksheet
|
|
28
|
+
let worksheetDetails = await Promise.all(targetOIs.map(async (orderInventory) => {
|
|
29
|
+
let existingWorksheetDetail = await tx.getRepository(entities_1.WorksheetDetail).createQueryBuilder('wd')
|
|
30
|
+
.innerJoinAndSelect('wd.worksheet', 'ws')
|
|
31
|
+
.where('wd.target_inventory_id = :orderInventoryId', { orderInventoryId: orderInventory.id })
|
|
32
|
+
.orderBy('ws.created_at', 'DESC')
|
|
33
|
+
.addOrderBy('wd.name')
|
|
34
|
+
.getOne();
|
|
35
|
+
if (existingWorksheetDetail) {
|
|
36
|
+
const startedAt = existingWorksheetDetail.worksheet.startedAt;
|
|
37
|
+
const wdType = existingWorksheetDetail.worksheet.type;
|
|
38
|
+
let wdStatus, oiStatus, roStatus, wStatus;
|
|
39
|
+
switch (wdType) {
|
|
40
|
+
case 'PICKING':
|
|
41
|
+
case 'BATCH_PICKING':
|
|
42
|
+
wdStatus = !startedAt ? constants_1.WORKSHEET_STATUS.DEACTIVATED : orderInventory.pickedQty == orderInventory.releaseQty ? constants_1.WORKSHEET_STATUS.DONE : constants_1.WORKSHEET_STATUS.EXECUTING;
|
|
43
|
+
oiStatus = !startedAt ? sales_base_1.ORDER_INVENTORY_STATUS.READY_TO_PICK : orderInventory.pickedQty == orderInventory.releaseQty ? sales_base_1.ORDER_INVENTORY_STATUS.PICKED : sales_base_1.ORDER_INVENTORY_STATUS.PICKING;
|
|
44
|
+
roStatus = !startedAt ? sales_base_1.ORDER_INVENTORY_STATUS.READY_TO_PICK : sales_base_1.ORDER_INVENTORY_STATUS.PICKING;
|
|
45
|
+
break;
|
|
46
|
+
case 'PACKING':
|
|
47
|
+
wdStatus = !startedAt ? constants_1.WORKSHEET_STATUS.DEACTIVATED : orderInventory.packedQty == orderInventory.releaseQty ? constants_1.WORKSHEET_STATUS.DONE : constants_1.WORKSHEET_STATUS.EXECUTING;
|
|
48
|
+
oiStatus = !startedAt ? sales_base_1.ORDER_INVENTORY_STATUS.READY_TO_PACK : orderInventory.packedQty == orderInventory.releaseQty ? sales_base_1.ORDER_INVENTORY_STATUS.PACKED : sales_base_1.ORDER_INVENTORY_STATUS.PACKING;
|
|
49
|
+
roStatus = !startedAt ? sales_base_1.ORDER_INVENTORY_STATUS.READY_TO_PACK : sales_base_1.ORDER_INVENTORY_STATUS.PACKING;
|
|
50
|
+
break;
|
|
51
|
+
case 'SORTING':
|
|
52
|
+
wdStatus = !startedAt ? constants_1.WORKSHEET_STATUS.DEACTIVATED : orderInventory.sortedQty == orderInventory.releaseQty ? constants_1.WORKSHEET_STATUS.DONE : constants_1.WORKSHEET_STATUS.EXECUTING;
|
|
53
|
+
oiStatus = !startedAt ? sales_base_1.ORDER_INVENTORY_STATUS.READY_TO_SORT : orderInventory.sortedQty == orderInventory.releaseQty ? sales_base_1.ORDER_INVENTORY_STATUS.PICKED : sales_base_1.ORDER_INVENTORY_STATUS.SORTING;
|
|
54
|
+
roStatus = !startedAt ? sales_base_1.ORDER_INVENTORY_STATUS.READY_TO_SORT : sales_base_1.ORDER_INVENTORY_STATUS.SORTING;
|
|
55
|
+
break;
|
|
56
|
+
case 'LOADING':
|
|
57
|
+
wdStatus = !startedAt ? constants_1.WORKSHEET_STATUS.DEACTIVATED : (orderInventory === null || orderInventory === void 0 ? void 0 : orderInventory.deliveryOrder) ? constants_1.WORKSHEET_STATUS.DONE : constants_1.WORKSHEET_STATUS.EXECUTING;
|
|
58
|
+
oiStatus = !startedAt ? sales_base_1.ORDER_INVENTORY_STATUS.READY_TO_LOAD : (orderInventory === null || orderInventory === void 0 ? void 0 : orderInventory.deliveryOrder) ? sales_base_1.ORDER_INVENTORY_STATUS.LOADED : sales_base_1.ORDER_INVENTORY_STATUS.LOADING;
|
|
59
|
+
roStatus = !startedAt ? sales_base_1.ORDER_INVENTORY_STATUS.READY_TO_LOAD : sales_base_1.ORDER_INVENTORY_STATUS.LOADING;
|
|
60
|
+
break;
|
|
61
|
+
default:
|
|
62
|
+
break;
|
|
114
63
|
}
|
|
64
|
+
wStatus = !startedAt ? constants_1.WORKSHEET_STATUS.DEACTIVATED : constants_1.WORKSHEET_STATUS.EXECUTING;
|
|
65
|
+
await tx.getRepository(entities_1.WorksheetDetail).update({ id: existingWorksheetDetail.id }, { status: wdStatus, updatedAt: new Date(), updater: user });
|
|
66
|
+
await tx.getRepository(sales_base_1.OrderInventory).update({ id: orderInventory.id }, { status: oiStatus, updatedAt: new Date(), updater: user });
|
|
67
|
+
return { worksheet: existingWorksheetDetail.worksheet, wStatus, roStatus };
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
await tx.getRepository(sales_base_1.OrderInventory).update({ id: orderInventory.id }, { status: sales_base_1.ORDER_INVENTORY_STATUS.PENDING_WORKSHEET, updatedAt: new Date(), updater: user });
|
|
71
|
+
return { worksheet: null, wStatus: null, roStatus: sales_base_1.ORDER_STATUS.PENDING_WORKSHEET };
|
|
72
|
+
}
|
|
73
|
+
}));
|
|
74
|
+
if (worksheetDetails[0].worksheet) {
|
|
75
|
+
await tx.getRepository(entities_1.Worksheet).update({ id: worksheetDetails[0].worksheet.id }, {
|
|
76
|
+
status: worksheetDetails[0].wStatus,
|
|
77
|
+
updatedAt: new Date(),
|
|
78
|
+
updater: user
|
|
115
79
|
});
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// update status of order vass to accordingly
|
|
122
|
-
foundOVs = foundOVs.map((orderVas) => {
|
|
123
|
-
if (!isLoadingStage)
|
|
124
|
-
orderVas.status = sales_base_1.ORDER_VAS_STATUS.READY_TO_PROCESS;
|
|
125
|
-
else
|
|
126
|
-
orderVas.status = sales_base_1.ORDER_VAS_STATUS.COMPLETED;
|
|
127
|
-
return Object.assign(Object.assign({}, orderVas), { updater: user });
|
|
128
|
-
});
|
|
129
|
-
await tx.getRepository(sales_base_1.OrderVas).save(foundOVs);
|
|
130
|
-
}
|
|
131
|
-
// find DO and change status to previous status
|
|
132
|
-
let foundDO = await tx.getRepository(sales_base_1.DeliveryOrder).find({
|
|
133
|
-
where: { domain, releaseGood: foundRO, status: sales_base_1.ORDER_STATUS.PENDING_CANCEL },
|
|
134
|
-
relations: ['transportVehicle']
|
|
135
|
-
});
|
|
136
|
-
if (foundDO && (foundDO === null || foundDO === void 0 ? void 0 : foundDO.length)) {
|
|
137
|
-
foundDO = foundDO.map((deliveryOrder) => {
|
|
138
|
-
return Object.assign(Object.assign({}, deliveryOrder), { status: sales_base_1.ORDER_STATUS.READY_TO_DISPATCH, updater: user });
|
|
80
|
+
}
|
|
81
|
+
await tx.getRepository(sales_base_1.ReleaseGood).update({ id: foundRO.id }, {
|
|
82
|
+
status: worksheetDetails[0].roStatus,
|
|
83
|
+
updatedAt: new Date(),
|
|
84
|
+
updater: user
|
|
139
85
|
});
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
ws.status === constants_1.WORKSHEET_STATUS.EXECUTING);
|
|
144
|
-
if (isLoadingRO)
|
|
145
|
-
foundRO.status = sales_base_1.ORDER_STATUS.LOADING;
|
|
146
|
-
else {
|
|
147
|
-
var isReadyToLoadRO = foundWS.some((ws) => ws.type === constants_1.WORKSHEET_TYPE.LOADING &&
|
|
148
|
-
ws.status === constants_1.WORKSHEET_STATUS.DEACTIVATED);
|
|
149
|
-
}
|
|
150
|
-
if (isReadyToLoadRO)
|
|
151
|
-
foundRO.status = sales_base_1.ORDER_STATUS.READY_TO_LOAD;
|
|
152
|
-
else {
|
|
153
|
-
var isPickingRO = foundWS.some((ws) => ws.type === constants_1.WORKSHEET_TYPE.PICKING &&
|
|
154
|
-
ws.status === constants_1.WORKSHEET_STATUS.EXECUTING);
|
|
86
|
+
// reverse DO status
|
|
87
|
+
await reverseDO(foundRO, context);
|
|
88
|
+
return;
|
|
155
89
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
var isReadyToPickRO = foundWS.some((ws) => ws.type === constants_1.WORKSHEET_TYPE.PICKING &&
|
|
160
|
-
ws.status === constants_1.WORKSHEET_STATUS.DEACTIVATED);
|
|
90
|
+
catch (error) {
|
|
91
|
+
env_1.logger.error(`reject-cancellation-release-order[rejectCancellationReleaseOrder]:(data:${JSON.stringify({ name, tx, domain, user })}) ${error}`);
|
|
92
|
+
throw new Error('Something went wrong. Please contact support.');
|
|
161
93
|
}
|
|
162
|
-
if (isReadyToPickRO)
|
|
163
|
-
foundRO.status = sales_base_1.ORDER_STATUS.READY_TO_PICK;
|
|
164
|
-
await tx.getRepository(sales_base_1.ReleaseGood).save(Object.assign(Object.assign({}, foundRO), { updater: user }));
|
|
165
|
-
return;
|
|
166
94
|
}
|
|
167
95
|
};
|
|
96
|
+
async function reverseDO(releaseGood, context) {
|
|
97
|
+
const { tx, domain, user } = context.state;
|
|
98
|
+
// find DO and change status to previous status
|
|
99
|
+
let foundDO = await tx.getRepository(sales_base_1.DeliveryOrder).find({
|
|
100
|
+
where: { domain, releaseGood, status: sales_base_1.ORDER_STATUS.PENDING_CANCEL },
|
|
101
|
+
relations: ['transportVehicle']
|
|
102
|
+
});
|
|
103
|
+
if (foundDO && (foundDO === null || foundDO === void 0 ? void 0 : foundDO.length)) {
|
|
104
|
+
foundDO = foundDO.map((deliveryOrder) => {
|
|
105
|
+
return Object.assign(Object.assign({}, deliveryOrder), { status: sales_base_1.ORDER_STATUS.READY_TO_DISPATCH, updater: user });
|
|
106
|
+
});
|
|
107
|
+
await tx.getRepository(sales_base_1.DeliveryOrder).save(foundDO);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
168
110
|
//# sourceMappingURL=reject-cancellation-release-order.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reject-cancellation-release-order.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/worksheet/reject-cancellation-release-order.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"reject-cancellation-release-order.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/worksheet/reject-cancellation-release-order.ts"],"names":[],"mappings":";;;AAGA,6CAA4C;AAC5C,2DAQmC;AACnC,kDAAqE;AACrE,gDAA8D;AAEjD,QAAA,8BAA8B,GAAG;IAC5C,KAAK,CAAC,8BAA8B,CAAC,CAAM,EAAE,EAAE,IAAI,EAAE,EAAE,OAAY;QACjE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAsD,OAAO,CAAC,KAAK,CAAA;QAE7F,IAAI;YACF,qBAAqB;YACrB,IAAI,OAAO,GAAgB,MAAM,EAAE,CAAC,aAAa,CAAC,wBAAW,CAAC,CAAC,OAAO,CAAC;gBACrE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,yBAAY,CAAC,cAAc,EAAE;gBAC5D,SAAS,EAAE;oBACT,UAAU;oBACV,kBAAkB;oBAClB,4BAA4B;oBAC5B,qCAAqC;oBACrC,gCAAgC;oBAChC,WAAW;iBACZ;aACF,CAAC,CAAA;YAEF,IAAI,CAAC,OAAO;gBAAE,MAAM,IAAI,KAAK,CAA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AM,CAAC,KAAK,CAAC,2EAA2E,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,CAAA;YAC/I,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;SACjE;IACH,CAAC;CACF,CAAA;AAED,KAAK,UAAU,SAAS,CAAC,WAAwB,EAAE,OAAY;IAC7D,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAsD,OAAO,CAAC,KAAK,CAAA;IAE7F,+CAA+C;IAC/C,IAAI,OAAO,GAAoB,MAAM,EAAE,CAAC,aAAa,CAAC,0BAAa,CAAC,CAAC,IAAI,CAAC;QACxE,KAAK,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,yBAAY,CAAC,cAAc,EAAE;QACnE,SAAS,EAAE,CAAC,kBAAkB,CAAC;KAChC,CAAC,CAAA;IACF,IAAI,OAAO,KAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAA,EAAE;QAC9B,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,aAA4B,EAAE,EAAE;YACrD,uCACK,aAAa,KAChB,MAAM,EAAE,yBAAY,CAAC,iBAAiB,EACtC,OAAO,EAAE,IAAI,IACd;QACH,CAAC,CAAC,CAAA;QAEF,MAAM,EAAE,CAAC,aAAa,CAAC,0BAAa,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;KACpD;AAEH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/worksheet-base",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.77",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"@things-factory/transport-base": "^4.3.76",
|
|
41
41
|
"@things-factory/warehouse-base": "^4.3.76"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "365b598107863f454289eda70828ae7ac171f0c9"
|
|
44
44
|
}
|
|
@@ -96,6 +96,19 @@ export const confirmCancellationReleaseOrder = {
|
|
|
96
96
|
})
|
|
97
97
|
.where('id = :id', { id: inventory.id })
|
|
98
98
|
.execute()
|
|
99
|
+
|
|
100
|
+
// @ChrisLim-git commented for further review as it causes qty to add into inventory
|
|
101
|
+
// await tx
|
|
102
|
+
// .createQueryBuilder()
|
|
103
|
+
// .update(Inventory)
|
|
104
|
+
// .set({
|
|
105
|
+
// qty: () => `COALESCE("qty", 0) + ${orderInventory.releaseQty}`,
|
|
106
|
+
// uomValue: () => `COALESCE("uom_value", 0) + ${orderInventory.releaseUomValue}`,
|
|
107
|
+
// status: INVENTORY_STATUS.STORED,
|
|
108
|
+
// updater: user
|
|
109
|
+
// })
|
|
110
|
+
// .where('id = :id', { id: inventory.id })
|
|
111
|
+
// .execute()
|
|
99
112
|
}
|
|
100
113
|
|
|
101
114
|
return orderInventory
|
|
@@ -24,6 +24,7 @@ export const pendingCancellationReleaseOrder = {
|
|
|
24
24
|
relations: ['bizplace', 'orderInventories', 'orderVass']
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
+
if (foundRO.status === "DONE") throw new Error('Release good has been completed!');
|
|
27
28
|
if (!foundRO) throw new Error(`Release good order doesn't exists.`)
|
|
28
29
|
let targetOIs: OrderInventory[] = foundRO.orderInventories
|
|
29
30
|
let foundOVs: OrderVas[] = foundRO.orderVass
|
|
@@ -94,77 +95,81 @@ export const pendingCancellationReleaseOrder = {
|
|
|
94
95
|
await tx.getRepository(OrderVas).save(foundOVs)
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
98
|
+
// find worksheet and update status to PENDING_CANCEL
|
|
99
|
+
let foundWS: Worksheet = await tx.getRepository(Worksheet).findOne({
|
|
100
|
+
where: {
|
|
101
|
+
domain,
|
|
102
|
+
releaseGood: foundRO
|
|
103
|
+
},
|
|
104
|
+
order: { 'createdAt': 'DESC' }
|
|
105
|
+
})
|
|
105
106
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
updater: user
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
await tx.getRepository(WorksheetDetail).save(pickedWSD)
|
|
114
|
-
|
|
115
|
-
let replacedWSD: WorksheetDetail[] = await tx.getRepository(WorksheetDetail).find({
|
|
116
|
-
where: {
|
|
117
|
-
domain,
|
|
118
|
-
targetInventory: In(pickedOIs.map(oi => oi.id)),
|
|
119
|
-
status: ORDER_INVENTORY_STATUS.REPLACED
|
|
120
|
-
},
|
|
121
|
-
relations: ['targetInventory']
|
|
107
|
+
if (foundWS) {
|
|
108
|
+
await tx.getRepository(Worksheet).update({ id: foundWS.id }, {
|
|
109
|
+
status: ORDER_INVENTORY_STATUS.PENDING_CANCEL,
|
|
110
|
+
updater: user
|
|
122
111
|
})
|
|
123
112
|
|
|
124
|
-
if (
|
|
125
|
-
let
|
|
126
|
-
|
|
113
|
+
if (pickedOIs && pickedOIs.length) {
|
|
114
|
+
let pickedWSD: WorksheetDetail[] = await tx.getRepository(WorksheetDetail).find({
|
|
115
|
+
where: {
|
|
116
|
+
domain,
|
|
117
|
+
targetInventory: In(pickedOIs.map(oi => oi.id)),
|
|
118
|
+
status: ORDER_INVENTORY_STATUS.DONE,
|
|
119
|
+
worksheet: foundWS
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
pickedWSD = pickedWSD.map((wsd: WorksheetDetail) => {
|
|
127
124
|
return {
|
|
128
|
-
...
|
|
129
|
-
status: ORDER_INVENTORY_STATUS.
|
|
125
|
+
...wsd,
|
|
126
|
+
status: ORDER_INVENTORY_STATUS.PENDING_CANCEL,
|
|
130
127
|
updater: user
|
|
131
128
|
}
|
|
132
129
|
})
|
|
133
|
-
await tx.getRepository(
|
|
134
|
-
}
|
|
135
|
-
}
|
|
130
|
+
await tx.getRepository(WorksheetDetail).save(pickedWSD)
|
|
136
131
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
132
|
+
let replacedWSD: WorksheetDetail[] = await tx.getRepository(WorksheetDetail).find({
|
|
133
|
+
where: {
|
|
134
|
+
domain,
|
|
135
|
+
targetInventory: In(pickedOIs.map(oi => oi.id)),
|
|
136
|
+
status: ORDER_INVENTORY_STATUS.REPLACED,
|
|
137
|
+
worksheet: foundWS
|
|
138
|
+
},
|
|
139
|
+
relations: ['targetInventory']
|
|
140
|
+
})
|
|
141
141
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
142
|
+
if (replacedWSD && replacedWSD.length) {
|
|
143
|
+
let replacedOI: OrderInventory[] = replacedWSD.map((wsd: WorksheetDetail) => wsd.targetInventory)
|
|
144
|
+
replacedOI = replacedOI.map((oi: OrderInventory) => {
|
|
145
|
+
return {
|
|
146
|
+
...oi,
|
|
147
|
+
status: ORDER_INVENTORY_STATUS.REPLACED,
|
|
148
|
+
updater: user
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
await tx.getRepository(OrderInventory).save(replacedOI)
|
|
147
152
|
}
|
|
148
|
-
})
|
|
149
|
-
await tx.getRepository(WorksheetDetail).save(pickingWSD)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// find worksheet and update status to PENDING_CANCEL
|
|
153
|
-
let foundWS: Worksheet[] = await tx.getRepository(Worksheet).find({
|
|
154
|
-
where: {
|
|
155
|
-
domain,
|
|
156
|
-
releaseGood: foundRO
|
|
157
153
|
}
|
|
158
|
-
})
|
|
159
154
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
155
|
+
if (pickingOIs && pickingOIs.length) {
|
|
156
|
+
let pickingWSD: WorksheetDetail[] = await tx.getRepository(WorksheetDetail).find({
|
|
157
|
+
where: {
|
|
158
|
+
domain, targetInventory: In(pickingOIs.map(oi => oi.id)),
|
|
159
|
+
worksheet: foundWS
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
pickingWSD = pickingWSD.map((wsd: WorksheetDetail) => {
|
|
164
|
+
return {
|
|
165
|
+
...wsd,
|
|
166
|
+
status: ORDER_INVENTORY_STATUS.PENDING_CANCEL,
|
|
167
|
+
updater: user
|
|
168
|
+
}
|
|
169
|
+
})
|
|
170
|
+
await tx.getRepository(WorksheetDetail).save(pickingWSD)
|
|
165
171
|
}
|
|
166
|
-
}
|
|
167
|
-
await tx.getRepository(Worksheet).save(foundWS)
|
|
172
|
+
}
|
|
168
173
|
|
|
169
174
|
// find DO and change status to pending cancel
|
|
170
175
|
let foundDO: DeliveryOrder[] = await tx.getRepository(DeliveryOrder).find({
|
|
@@ -186,43 +191,43 @@ export const pendingCancellationReleaseOrder = {
|
|
|
186
191
|
updater: user
|
|
187
192
|
})
|
|
188
193
|
|
|
189
|
-
// notification logics
|
|
190
|
-
// get Office Admin Users
|
|
191
|
-
const users: any[] = await tx
|
|
192
|
-
.getRepository('users_roles')
|
|
193
|
-
.createQueryBuilder('ur')
|
|
194
|
-
.select('ur.users_id', 'id')
|
|
195
|
-
.where(qb => {
|
|
196
|
-
const subQuery = qb
|
|
197
|
-
.subQuery()
|
|
198
|
-
.select('role.id')
|
|
199
|
-
.from(Role, 'role')
|
|
200
|
-
.where("role.name = 'Office Admin'")
|
|
201
|
-
.andWhere('role.domain_id = :domain', { domain: domain.id })
|
|
202
|
-
.getQuery()
|
|
203
|
-
return 'ur.roles_id IN ' + subQuery
|
|
204
|
-
})
|
|
205
|
-
.getRawMany()
|
|
206
|
-
|
|
207
|
-
// send notification to Office Admin Users
|
|
208
|
-
if (users?.length && context.header?.referer) {
|
|
209
|
-
const receivers: any[] = users.map(user => user.id)
|
|
210
|
-
const msg = {
|
|
211
|
-
title: `${foundRO.name} cancellation`,
|
|
212
|
-
body: `${customerBizplace.name} is requesting to cancel order`,
|
|
213
|
-
url: context.header.referer,
|
|
214
|
-
data: { url: context.header.referer }
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* @notes Temporary off sendNotification due to suspect of causing wms down
|
|
219
|
-
*/
|
|
220
194
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
195
|
+
/**
|
|
196
|
+
* @notes Temporary off sendNotification due to suspect of causing wms down
|
|
197
|
+
*/
|
|
198
|
+
// // notification logics
|
|
199
|
+
// // get Office Admin Users
|
|
200
|
+
// const users: any[] = await tx
|
|
201
|
+
// .getRepository('users_roles')
|
|
202
|
+
// .createQueryBuilder('ur')
|
|
203
|
+
// .select('ur.users_id', 'id')
|
|
204
|
+
// .where(qb => {
|
|
205
|
+
// const subQuery = qb
|
|
206
|
+
// .subQuery()
|
|
207
|
+
// .select('role.id')
|
|
208
|
+
// .from(Role, 'role')
|
|
209
|
+
// .where("role.name = 'Office Admin'")
|
|
210
|
+
// .andWhere('role.domain_id = :domain', { domain: domain.id })
|
|
211
|
+
// .getQuery()
|
|
212
|
+
// return 'ur.roles_id IN ' + subQuery
|
|
213
|
+
// })
|
|
214
|
+
// .getRawMany()
|
|
215
|
+
|
|
216
|
+
// // send notification to Office Admin Users
|
|
217
|
+
// if (users?.length && context.header?.referer) {
|
|
218
|
+
// const receivers: any[] = users.map(user => user.id)
|
|
219
|
+
// const msg = {
|
|
220
|
+
// title: `${foundRO.name} cancellation`,
|
|
221
|
+
// body: `${customerBizplace.name} is requesting to cancel order`,
|
|
222
|
+
// url: context.header.referer,
|
|
223
|
+
// data: { url: context.header.referer }
|
|
224
|
+
// }
|
|
225
|
+
|
|
226
|
+
// await sendNotification({
|
|
227
|
+
// receivers,
|
|
228
|
+
// message: { ...msg }
|
|
229
|
+
// })
|
|
230
|
+
// }
|
|
226
231
|
|
|
227
232
|
return
|
|
228
233
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EntityManager, In } from 'typeorm'
|
|
2
2
|
import { User } from '@things-factory/auth-base'
|
|
3
3
|
import { Domain } from '@things-factory/shell'
|
|
4
|
+
import { logger } from '@things-factory/env'
|
|
4
5
|
import {
|
|
5
6
|
ORDER_INVENTORY_STATUS,
|
|
6
7
|
ORDER_STATUS,
|
|
@@ -16,236 +17,119 @@ import { Worksheet, WorksheetDetail } from '../../../entities'
|
|
|
16
17
|
export const rejectCancellationReleaseOrder = {
|
|
17
18
|
async rejectCancellationReleaseOrder(_: any, { name }, context: any) {
|
|
18
19
|
const { tx, domain, user }: { tx: EntityManager; domain: Domain; user: User } = context.state
|
|
19
|
-
let foundRO: ReleaseGood = await tx.getRepository(ReleaseGood).findOne({
|
|
20
|
-
where: { domain, name, status: ORDER_STATUS.PENDING_CANCEL },
|
|
21
|
-
relations: [
|
|
22
|
-
'bizplace',
|
|
23
|
-
'orderInventories',
|
|
24
|
-
'orderInventories.inventory',
|
|
25
|
-
'orderInventories.inventory.location',
|
|
26
|
-
'orderInventories.deliveryOrder',
|
|
27
|
-
'orderVass'
|
|
28
|
-
]
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
if (!foundRO) throw new Error(`Release order doesn't exists.`)
|
|
32
|
-
let targetOIs: OrderInventory[] = foundRO.orderInventories
|
|
33
|
-
let foundOVs: OrderVas[] = foundRO.orderVass
|
|
34
|
-
let isDeactivatedPicking = false
|
|
35
|
-
|
|
36
|
-
foundRO.status = ORDER_STATUS.PENDING_WORKSHEET
|
|
37
|
-
// get the worksheet based on RO number
|
|
38
|
-
let foundWS: Worksheet[] = await tx.getRepository(Worksheet).find({
|
|
39
|
-
where: {
|
|
40
|
-
domain,
|
|
41
|
-
releaseGood: foundRO
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
// check worksheet table if started_at is not null to indicate that the worksheet has been activated
|
|
46
|
-
if (foundWS && foundWS?.length) {
|
|
47
|
-
foundWS = foundWS.map((ws: Worksheet) => {
|
|
48
|
-
if (ws.startedAt && !ws.endedAt) {
|
|
49
|
-
return {
|
|
50
|
-
...ws,
|
|
51
|
-
status: WORKSHEET_STATUS.EXECUTING,
|
|
52
|
-
updater: user
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else if (ws.startedAt && ws.endedAt) {
|
|
56
|
-
return {
|
|
57
|
-
...ws,
|
|
58
|
-
status: WORKSHEET_STATUS.DONE,
|
|
59
|
-
updater: user
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
else if (!ws.startedAt && !ws.endedAt && ws.type === WORKSHEET_TYPE.PICKING) {
|
|
63
|
-
isDeactivatedPicking = true
|
|
64
|
-
return {
|
|
65
|
-
...ws,
|
|
66
|
-
status: WORKSHEET_STATUS.DEACTIVATED,
|
|
67
|
-
updater: user
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
await tx.getRepository(Worksheet).save(foundWS)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// check if the worksheet is in Loading stage
|
|
75
|
-
const isLoadingStage = foundWS.some((ws: Worksheet) => ws.type === WORKSHEET_TYPE.LOADING)
|
|
76
|
-
|
|
77
|
-
// change the order inventory status accordingly
|
|
78
|
-
let newOrderInventories: OrderInventory[] = targetOIs.map(
|
|
79
|
-
(oi: OrderInventory) => {
|
|
80
|
-
if (isLoadingStage && oi.deliveryOrder && oi.status === ORDER_INVENTORY_STATUS.PENDING_REVERSE)
|
|
81
|
-
oi.status = ORDER_INVENTORY_STATUS.LOADED
|
|
82
|
-
|
|
83
|
-
else if (isLoadingStage && !oi.deliveryOrder && oi.status === ORDER_INVENTORY_STATUS.PENDING_REVERSE)
|
|
84
|
-
oi.status = ORDER_INVENTORY_STATUS.LOADING
|
|
85
20
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
...oi,
|
|
100
|
-
updater: user
|
|
101
|
-
}
|
|
21
|
+
try {
|
|
22
|
+
// find release order
|
|
23
|
+
let foundRO: ReleaseGood = await tx.getRepository(ReleaseGood).findOne({
|
|
24
|
+
where: { domain, name, status: ORDER_STATUS.PENDING_CANCEL },
|
|
25
|
+
relations: [
|
|
26
|
+
'bizplace',
|
|
27
|
+
'orderInventories',
|
|
28
|
+
'orderInventories.inventory',
|
|
29
|
+
'orderInventories.inventory.location',
|
|
30
|
+
'orderInventories.deliveryOrder',
|
|
31
|
+
'orderVass'
|
|
32
|
+
]
|
|
102
33
|
})
|
|
103
|
-
await tx.getRepository(OrderInventory).save(newOrderInventories)
|
|
104
|
-
|
|
105
|
-
// find the worksheet details based on order inventories
|
|
106
|
-
let foundWSD: WorksheetDetail[] = await tx.getRepository(WorksheetDetail).find({
|
|
107
|
-
where: {
|
|
108
|
-
domain,
|
|
109
|
-
targetInventory: In(newOrderInventories.map((oi: OrderInventory) => oi.id))
|
|
110
|
-
},
|
|
111
|
-
relations: ['targetInventory']
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
if (foundWSD && foundWSD?.length) {
|
|
115
|
-
foundWSD = foundWSD.map((wsd: WorksheetDetail) => {
|
|
116
34
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
35
|
+
if (!foundRO) throw new Error(`Release order doesn't exists.`)
|
|
36
|
+
|
|
37
|
+
let targetOIs: OrderInventory[] = foundRO.orderInventories
|
|
38
|
+
|
|
39
|
+
// perform update on all order inventories and worksheet
|
|
40
|
+
let worksheetDetails = await Promise.all(targetOIs.map(async (orderInventory) => {
|
|
41
|
+
let existingWorksheetDetail: WorksheetDetail = await tx.getRepository(WorksheetDetail).createQueryBuilder('wd')
|
|
42
|
+
.innerJoinAndSelect('wd.worksheet', 'ws')
|
|
43
|
+
.where('wd.target_inventory_id = :orderInventoryId', { orderInventoryId: orderInventory.id })
|
|
44
|
+
.orderBy('ws.created_at', 'DESC')
|
|
45
|
+
.addOrderBy('wd.name')
|
|
46
|
+
.getOne()
|
|
47
|
+
|
|
48
|
+
if (existingWorksheetDetail) {
|
|
49
|
+
const startedAt = existingWorksheetDetail.worksheet.startedAt
|
|
50
|
+
const wdType = existingWorksheetDetail.worksheet.type
|
|
51
|
+
let wdStatus, oiStatus, roStatus, wStatus
|
|
52
|
+
switch (wdType) {
|
|
53
|
+
case 'PICKING':
|
|
54
|
+
case 'BATCH_PICKING':
|
|
55
|
+
wdStatus = !startedAt ? WORKSHEET_STATUS.DEACTIVATED : orderInventory.pickedQty == orderInventory.releaseQty ? WORKSHEET_STATUS.DONE : WORKSHEET_STATUS.EXECUTING
|
|
56
|
+
oiStatus = !startedAt ? ORDER_INVENTORY_STATUS.READY_TO_PICK : orderInventory.pickedQty == orderInventory.releaseQty ? ORDER_INVENTORY_STATUS.PICKED : ORDER_INVENTORY_STATUS.PICKING
|
|
57
|
+
roStatus = !startedAt ? ORDER_INVENTORY_STATUS.READY_TO_PICK : ORDER_INVENTORY_STATUS.PICKING
|
|
58
|
+
break;
|
|
59
|
+
case 'PACKING':
|
|
60
|
+
wdStatus = !startedAt ? WORKSHEET_STATUS.DEACTIVATED : orderInventory.packedQty == orderInventory.releaseQty ? WORKSHEET_STATUS.DONE : WORKSHEET_STATUS.EXECUTING
|
|
61
|
+
oiStatus = !startedAt ? ORDER_INVENTORY_STATUS.READY_TO_PACK : orderInventory.packedQty == orderInventory.releaseQty ? ORDER_INVENTORY_STATUS.PACKED : ORDER_INVENTORY_STATUS.PACKING
|
|
62
|
+
roStatus = !startedAt ? ORDER_INVENTORY_STATUS.READY_TO_PACK : ORDER_INVENTORY_STATUS.PACKING
|
|
63
|
+
break;
|
|
64
|
+
case 'SORTING':
|
|
65
|
+
wdStatus = !startedAt ? WORKSHEET_STATUS.DEACTIVATED : orderInventory.sortedQty == orderInventory.releaseQty ? WORKSHEET_STATUS.DONE : WORKSHEET_STATUS.EXECUTING
|
|
66
|
+
oiStatus = !startedAt ? ORDER_INVENTORY_STATUS.READY_TO_SORT : orderInventory.sortedQty == orderInventory.releaseQty ? ORDER_INVENTORY_STATUS.PICKED : ORDER_INVENTORY_STATUS.SORTING
|
|
67
|
+
roStatus = !startedAt ? ORDER_INVENTORY_STATUS.READY_TO_SORT : ORDER_INVENTORY_STATUS.SORTING
|
|
68
|
+
break;
|
|
69
|
+
case 'LOADING':
|
|
70
|
+
wdStatus = !startedAt ? WORKSHEET_STATUS.DEACTIVATED : orderInventory?.deliveryOrder ? WORKSHEET_STATUS.DONE : WORKSHEET_STATUS.EXECUTING
|
|
71
|
+
oiStatus = !startedAt ? ORDER_INVENTORY_STATUS.READY_TO_LOAD : orderInventory?.deliveryOrder ? ORDER_INVENTORY_STATUS.LOADED : ORDER_INVENTORY_STATUS.LOADING
|
|
72
|
+
roStatus = !startedAt ? ORDER_INVENTORY_STATUS.READY_TO_LOAD : ORDER_INVENTORY_STATUS.LOADING
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
break;
|
|
146
76
|
}
|
|
147
77
|
|
|
148
|
-
|
|
149
|
-
switch (oi.status) {
|
|
150
|
-
case ORDER_INVENTORY_STATUS.LOADING:
|
|
151
|
-
wsd.status = WORKSHEET_STATUS.EXECUTING
|
|
152
|
-
break
|
|
78
|
+
wStatus = !startedAt ? WORKSHEET_STATUS.DEACTIVATED : WORKSHEET_STATUS.EXECUTING
|
|
153
79
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
break
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
})
|
|
80
|
+
await tx.getRepository(WorksheetDetail).update({ id: existingWorksheetDetail.id }, { status: wdStatus, updatedAt: new Date(), updater: user })
|
|
81
|
+
await tx.getRepository(OrderInventory).update({ id: orderInventory.id }, { status: oiStatus, updatedAt: new Date(), updater: user })
|
|
160
82
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
updater: user
|
|
83
|
+
return { worksheet: existingWorksheetDetail.worksheet, wStatus, roStatus }
|
|
84
|
+
} else {
|
|
85
|
+
await tx.getRepository(OrderInventory).update({ id: orderInventory.id }, { status: ORDER_INVENTORY_STATUS.PENDING_WORKSHEET, updatedAt: new Date(), updater: user })
|
|
86
|
+
return { worksheet: null, wStatus: null, roStatus: ORDER_STATUS.PENDING_WORKSHEET }
|
|
164
87
|
}
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
await tx.getRepository(WorksheetDetail).save(foundWSD)
|
|
168
|
-
}
|
|
88
|
+
}))
|
|
169
89
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (!isLoadingStage)
|
|
175
|
-
orderVas.status = ORDER_VAS_STATUS.READY_TO_PROCESS
|
|
176
|
-
|
|
177
|
-
else
|
|
178
|
-
orderVas.status = ORDER_VAS_STATUS.COMPLETED
|
|
179
|
-
|
|
180
|
-
return {
|
|
181
|
-
...orderVas,
|
|
90
|
+
if (worksheetDetails[0].worksheet) {
|
|
91
|
+
await tx.getRepository(Worksheet).update({ id: worksheetDetails[0].worksheet.id }, {
|
|
92
|
+
status: worksheetDetails[0].wStatus,
|
|
93
|
+
updatedAt: new Date(),
|
|
182
94
|
updater: user
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
await tx.getRepository(OrderVas).save(foundOVs)
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// find DO and change status to previous status
|
|
190
|
-
let foundDO: DeliveryOrder[] = await tx.getRepository(DeliveryOrder).find({
|
|
191
|
-
where: { domain, releaseGood: foundRO, status: ORDER_STATUS.PENDING_CANCEL },
|
|
192
|
-
relations: ['transportVehicle']
|
|
193
|
-
})
|
|
95
|
+
})
|
|
96
|
+
}
|
|
194
97
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
status: ORDER_STATUS.READY_TO_DISPATCH,
|
|
200
|
-
updater: user
|
|
201
|
-
}
|
|
98
|
+
await tx.getRepository(ReleaseGood).update({ id: foundRO.id }, {
|
|
99
|
+
status: worksheetDetails[0].roStatus,
|
|
100
|
+
updatedAt: new Date(),
|
|
101
|
+
updater: user
|
|
202
102
|
})
|
|
203
|
-
await tx.getRepository(DeliveryOrder).save(foundDO)
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const isLoadingRO = foundWS.some((ws: Worksheet) =>
|
|
207
|
-
ws.type === WORKSHEET_TYPE.LOADING &&
|
|
208
|
-
ws.status === WORKSHEET_STATUS.EXECUTING
|
|
209
|
-
)
|
|
210
|
-
|
|
211
|
-
if (isLoadingRO)
|
|
212
|
-
foundRO.status = ORDER_STATUS.LOADING
|
|
213
103
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
ws.type === WORKSHEET_TYPE.LOADING &&
|
|
217
|
-
ws.status === WORKSHEET_STATUS.DEACTIVATED
|
|
218
|
-
)
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (isReadyToLoadRO)
|
|
222
|
-
foundRO.status = ORDER_STATUS.READY_TO_LOAD
|
|
104
|
+
// reverse DO status
|
|
105
|
+
await reverseDO(foundRO, context)
|
|
223
106
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
)
|
|
107
|
+
return
|
|
108
|
+
} catch (error) {
|
|
109
|
+
logger.error(`reject-cancellation-release-order[rejectCancellationReleaseOrder]:(data:${JSON.stringify({ name, tx, domain, user })}) ${error}`)
|
|
110
|
+
throw new Error('Something went wrong. Please contact support.')
|
|
229
111
|
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
230
114
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
updater: user
|
|
115
|
+
async function reverseDO(releaseGood: ReleaseGood, context: any) {
|
|
116
|
+
const { tx, domain, user }: { tx: EntityManager; domain: Domain; user: User } = context.state
|
|
117
|
+
|
|
118
|
+
// find DO and change status to previous status
|
|
119
|
+
let foundDO: DeliveryOrder[] = await tx.getRepository(DeliveryOrder).find({
|
|
120
|
+
where: { domain, releaseGood, status: ORDER_STATUS.PENDING_CANCEL },
|
|
121
|
+
relations: ['transportVehicle']
|
|
122
|
+
})
|
|
123
|
+
if (foundDO && foundDO?.length) {
|
|
124
|
+
foundDO = foundDO.map((deliveryOrder: DeliveryOrder) => {
|
|
125
|
+
return {
|
|
126
|
+
...deliveryOrder,
|
|
127
|
+
status: ORDER_STATUS.READY_TO_DISPATCH,
|
|
128
|
+
updater: user
|
|
129
|
+
}
|
|
247
130
|
})
|
|
248
131
|
|
|
249
|
-
|
|
132
|
+
await tx.getRepository(DeliveryOrder).save(foundDO)
|
|
250
133
|
}
|
|
251
|
-
|
|
134
|
+
|
|
135
|
+
}
|