@things-factory/sales-base 3.8.22 → 3.8.26
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/purchase-order/create-purchase-order.js +5 -5
- package/dist-server/graphql/resolvers/purchase-order/create-purchase-order.js.map +1 -1
- package/dist-server/graphql/resolvers/purchase-order/update-purchase-order.js +12 -23
- package/dist-server/graphql/resolvers/purchase-order/update-purchase-order.js.map +1 -1
- package/dist-server/graphql/resolvers/purchase-order/upsert-purchase-order.js +5 -7
- package/dist-server/graphql/resolvers/purchase-order/upsert-purchase-order.js.map +1 -1
- package/dist-server/graphql/types/purchase-order/index.js +1 -1
- package/dist-server/graphql/types/purchase-order/index.js.map +1 -1
- package/package.json +6 -6
- package/server/graphql/resolvers/purchase-order/create-purchase-order.ts +33 -32
- package/server/graphql/resolvers/purchase-order/update-purchase-order.ts +10 -8
- package/server/graphql/resolvers/purchase-order/upsert-purchase-order.ts +21 -32
- package/server/graphql/types/purchase-order/index.ts +1 -4
|
@@ -8,12 +8,12 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
8
8
|
};
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.createPurchaseOrderFunction = exports.createPurchaseOrder = void 0;
|
|
11
|
+
const typeorm_1 = require("typeorm");
|
|
11
12
|
const attachment_base_1 = require("@things-factory/attachment-base");
|
|
12
13
|
const biz_base_1 = require("@things-factory/biz-base");
|
|
13
|
-
const warehouse_base_1 = require("@things-factory/warehouse-base");
|
|
14
14
|
const id_rule_base_1 = require("@things-factory/id-rule-base");
|
|
15
|
-
const typeorm_1 = require("typeorm");
|
|
16
15
|
const setting_base_1 = require("@things-factory/setting-base");
|
|
16
|
+
const warehouse_base_1 = require("@things-factory/warehouse-base");
|
|
17
17
|
const constants_1 = require("../../../constants");
|
|
18
18
|
const entities_1 = require("../../../entities");
|
|
19
19
|
const order_no_generator_1 = require("../../../utils/order-no-generator");
|
|
@@ -24,7 +24,7 @@ exports.createPurchaseOrder = {
|
|
|
24
24
|
return await tx.getRepository(entities_1.PurchaseOrder).save(Object.assign(Object.assign({ domain }, purchaseOrder), { creator: user, updater: user }));
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
-
async function createPurchaseOrderFunction(_, purchaseOrder,
|
|
27
|
+
async function createPurchaseOrderFunction(_, purchaseOrder, files, context, tx) {
|
|
28
28
|
var e_1, _a;
|
|
29
29
|
var _b, _c, _d;
|
|
30
30
|
const { domain, user } = context.state;
|
|
@@ -92,8 +92,8 @@ async function createPurchaseOrderFunction(_, purchaseOrder, file, context, tx)
|
|
|
92
92
|
finally { if (e_1) throw e_1.error; }
|
|
93
93
|
}
|
|
94
94
|
// // 4. Create Attacments
|
|
95
|
-
if (
|
|
96
|
-
const attachments =
|
|
95
|
+
if (files === null || files === void 0 ? void 0 : files.length) {
|
|
96
|
+
const attachments = files.map(attachment => {
|
|
97
97
|
return {
|
|
98
98
|
file: attachment,
|
|
99
99
|
refBy: createdPurchaseOrder.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-purchase-order.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/purchase-order/create-purchase-order.ts"],"names":[],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"create-purchase-order.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/purchase-order/create-purchase-order.ts"],"names":[],"mappings":";;;;;;;;;;AACA,qCAAkE;AAElE,qEAA+E;AAE/E,uDAMiC;AACjC,+DAAyD;AACzD,+DAAsD;AAEtD,mEAAyD;AAEzD,kDAK2B;AAC3B,gDAAwG;AACxG,0EAAoE;AAEpE,mCAAqD;AAExC,QAAA,mBAAmB,GAAG;IACjC,KAAK,CAAC,mBAAmB,CAAC,CAAM,EAAE,EAAE,aAAa,EAAE,EAAE,OAAY;QAC/D,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAsD,O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E,OAAO,EACb,MAAM,EACN,SAAS,EAAE,CAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,SAAS,EAAC,CAAC,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,EACrE,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,IAAI,IACb,CAAA;IAEF,sCAAsC;IACtC,MAAM,IAAA,mCAA2B,EAAC,MAAM,EAAE,aAAa,CAAC,QAAQ,EAAE,oBAAoB,EAAE,aAAa,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;;QAEhH,2CAA2C;QAC3C,KAAqB,IAAA,iBAAA,cAAA,YAAY,CAAA,kBAAA;YAAtB,IAAI,EAAE,yBAAA,CAAA;YACf,OAAO,EAAE,CAAC,EAAE,CAAA;YACZ,MAAM,EAAE,CAAC,aAAa,CAAC,mCAAwB,CAAC,CAAC,IAAI,iCAChD,EAAE,KACL,MAAM,EACN,aAAa,EAAE,oBAAoB,EACnC,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,IAAI,IACb,CAAA;SACH;;;;;;;;;IAED,0BAA0B;IAC1B,IAAI,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAAM,EAAE;QACjB,MAAM,WAAW,GAAiB,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;YACvD,OAAO;gBACL,IAAI,EAAE,UAAU;gBAChB,KAAK,EAAE,oBAAoB,CAAC,EAAE;gBAC9B,QAAQ,EAAE,2BAAe,CAAC,EAAE;aAC7B,CAAA;QACH,CAAC,CAAC,CAAA;QACF,MAAM,IAAA,mCAAiB,EAAC,CAAC,EAAE,EAAE,WAAW,EAAE,EAAE,OAAO,CAAC,CAAA;KACrD;IAED,OAAO,oBAAoB,CAAA;AAC7B,CAAC;AAhGD,kEAgGC"}
|
|
@@ -8,10 +8,10 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
8
8
|
};
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.updatePurchaseOrderFunction = exports.updatePurchaseOrder = void 0;
|
|
11
|
+
const typeorm_1 = require("typeorm");
|
|
11
12
|
const attachment_base_1 = require("@things-factory/attachment-base");
|
|
12
13
|
const biz_base_1 = require("@things-factory/biz-base");
|
|
13
14
|
const warehouse_base_1 = require("@things-factory/warehouse-base");
|
|
14
|
-
const typeorm_1 = require("typeorm");
|
|
15
15
|
const constants_1 = require("../../../constants");
|
|
16
16
|
const entities_1 = require("../../../entities");
|
|
17
17
|
const index_1 = require("./index");
|
|
@@ -25,24 +25,24 @@ exports.updatePurchaseOrder = {
|
|
|
25
25
|
return await repository.save(Object.assign(Object.assign(Object.assign({}, purchaseOrder), patch), { updater: user }));
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
-
async function updatePurchaseOrderFunction(_, purchaseOrder,
|
|
29
|
-
var e_1, _a
|
|
30
|
-
var _c, _d
|
|
28
|
+
async function updatePurchaseOrderFunction(_, purchaseOrder, files, context, tx) {
|
|
29
|
+
var e_1, _a;
|
|
30
|
+
var _b, _c, _d;
|
|
31
31
|
const { domain, user } = context.state;
|
|
32
32
|
let existingPurchaseOrder = await (0, index_1.getPurchaseOrderFunction)(_, purchaseOrder.name, context, tx);
|
|
33
33
|
let orderProducts = purchaseOrder.orderProducts;
|
|
34
34
|
let otherCharges = purchaseOrder.otherCharges;
|
|
35
|
-
if ((
|
|
35
|
+
if ((_b = purchaseOrder === null || purchaseOrder === void 0 ? void 0 : purchaseOrder.bizplace) === null || _b === void 0 ? void 0 : _b.id) {
|
|
36
36
|
const permittedBizplaces = await (0, biz_base_1.getPermittedBizplaces)(domain, user);
|
|
37
37
|
let foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == purchaseOrder.bizplace.id);
|
|
38
38
|
if (!foundPermittedBizplace)
|
|
39
39
|
throw new Error(`This user does not permitted for this company`);
|
|
40
40
|
purchaseOrder.bizplace = foundPermittedBizplace;
|
|
41
41
|
}
|
|
42
|
-
if ((
|
|
42
|
+
if ((_c = purchaseOrder === null || purchaseOrder === void 0 ? void 0 : purchaseOrder.supplier) === null || _c === void 0 ? void 0 : _c.id) {
|
|
43
43
|
purchaseOrder.supplier = await (0, typeorm_1.getRepository)(biz_base_1.ContactPoint).findOne({ id: purchaseOrder.supplier.id });
|
|
44
44
|
}
|
|
45
|
-
if ((
|
|
45
|
+
if ((_d = purchaseOrder === null || purchaseOrder === void 0 ? void 0 : purchaseOrder.bufferLocation) === null || _d === void 0 ? void 0 : _d.id) {
|
|
46
46
|
purchaseOrder.bufferLocation = await (0, typeorm_1.getRepository)(warehouse_base_1.Location).findOne({ id: purchaseOrder.bufferLocation.id });
|
|
47
47
|
}
|
|
48
48
|
// // 1. Update purchase order
|
|
@@ -79,24 +79,13 @@ async function updatePurchaseOrderFunction(_, purchaseOrder, file, context, tx)
|
|
|
79
79
|
category: constants_1.ATTACHMENT_TYPE.PO
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const file = _g.value;
|
|
86
|
-
await (0, attachment_base_1.deleteAttachment)(_, { id: file.id }, context);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
90
|
-
finally {
|
|
91
|
-
try {
|
|
92
|
-
if (_g && !_g.done && (_b = _f.return)) await _b.call(_f);
|
|
93
|
-
}
|
|
94
|
-
finally { if (e_2) throw e_2.error; }
|
|
82
|
+
// // 6. Remove All Attachment
|
|
83
|
+
if (foundAttachments === null || foundAttachments === void 0 ? void 0 : foundAttachments.length) {
|
|
84
|
+
await (0, attachment_base_1.deleteAttachmentsByRef)(_, { refBys: foundAttachments.map(file => file.refBy) }, context);
|
|
95
85
|
}
|
|
96
86
|
// // 7. Add New Attachment
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const attachments = newAttachments.map(attachment => {
|
|
87
|
+
if ((files === null || files === void 0 ? void 0 : files.length) > 0) {
|
|
88
|
+
const attachments = files.map(attachment => {
|
|
100
89
|
return {
|
|
101
90
|
file: attachment,
|
|
102
91
|
refBy: updatePurchaseOrder.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-purchase-order.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/purchase-order/update-purchase-order.ts"],"names":[],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"update-purchase-order.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/purchase-order/update-purchase-order.ts"],"names":[],"mappings":";;;;;;;;;;AACA,qCAAkE;AAElE,qEAAuG;AAEvG,uDAAwF;AAExF,mEAAyD;AAEzD,kDAAoD;AACpD,gDAAyF;AACzF,mCAA+E;AAElE,QAAA,mBAAmB,GAAG;IACjC,KAAK,CAAC,mBAAmB,CAAC,CAAM,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,OAAY;QAC7D,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAsD,OAAO,CAAC,KAAK,CAAA;QAE7F,MAAM,UAAU,GAAG,EAAE,CAAC,aAAa,CAAC,wBAAa,CAAC,CAAA;QAClD,MAAM,aAAa,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;YAC7C,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;SACxB,CAAC,CAAA;QAEF,OAAO,MAAM,UAAU,CAAC,IAAI,+CACvB,aAAa,GACb,KAAK,KACR,OAAO,EAAE,IAAI,IACb,CAAA;IACJ,CAAC;CACF,CAAA;AAEM,KAAK,UAAU,2BAA2B,CAC/C,CAAM,EACN,aAAkB,EAClB,KAAmB,EACnB,OAAY,EACZ,EAAkB;;;IAElB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAmC,OAAO,CAAC,KAAK,CAAA;IAEtE,IAAI,qBAAqB,GAAQ,MAAM,IAAA,gCAAwB,EAAC,CAAC,EAAE,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,CAAA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E,KAAK,EAAE;YACL,MAAM;YACN,KAAK,EAAE,aAAa,CAAC,EAAE;YACvB,QAAQ,EAAE,2BAAe,CAAC,EAAE;SAC7B;KACF,CAAC,CAAA;IAEF,8BAA8B;IAC9B,IAAI,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,MAAM,EAAE;QAC5B,MAAM,IAAA,wCAAsB,EAAC,CAAC,EAAE,EAAE,MAAM,EAAE,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;KAC/F;IAED,2BAA2B;IAC3B,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAAM,IAAG,CAAC,EAAE;QACrB,MAAM,WAAW,GAAiB,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;YACvD,OAAO;gBACL,IAAI,EAAE,UAAU;gBAChB,KAAK,EAAE,mBAAmB,CAAC,EAAE;gBAC7B,QAAQ,EAAE,2BAAe,CAAC,EAAE;aAC7B,CAAA;QACH,CAAC,CAAC,CAAA;QACF,MAAM,IAAA,mCAAiB,EAAC,CAAC,EAAE,EAAE,WAAW,EAAE,EAAE,OAAO,CAAC,CAAA;KACrD;IAED,OAAO,qBAAqB,CAAA;AAC9B,CAAC;AA5FD,kEA4FC"}
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.upsertPurchaseOrderFunction = exports.upsertPurchaseOrder = void 0;
|
|
4
4
|
const index_1 = require("./index");
|
|
5
5
|
exports.upsertPurchaseOrder = {
|
|
6
|
-
async upsertPurchaseOrder(_, { purchaseOrder,
|
|
6
|
+
async upsertPurchaseOrder(_, { purchaseOrder, files }, context) {
|
|
7
7
|
try {
|
|
8
8
|
const { tx } = context.state;
|
|
9
|
-
const createdPurchaseOrder = await upsertPurchaseOrderFunction(_, purchaseOrder,
|
|
9
|
+
const createdPurchaseOrder = await upsertPurchaseOrderFunction(_, purchaseOrder, files, context, tx);
|
|
10
10
|
return createdPurchaseOrder;
|
|
11
11
|
}
|
|
12
12
|
catch (error) {
|
|
@@ -14,14 +14,12 @@ exports.upsertPurchaseOrder = {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
|
-
async function upsertPurchaseOrderFunction(_, purchaseOrder,
|
|
18
|
-
const { domain, user } = context.state;
|
|
19
|
-
let orderProducts = purchaseOrder.orderProducts;
|
|
17
|
+
async function upsertPurchaseOrderFunction(_, purchaseOrder, files, context, tx) {
|
|
20
18
|
if (!purchaseOrder.id) {
|
|
21
|
-
purchaseOrder = await (0, index_1.createPurchaseOrderFunction)(_, purchaseOrder,
|
|
19
|
+
purchaseOrder = await (0, index_1.createPurchaseOrderFunction)(_, purchaseOrder, files, context, tx);
|
|
22
20
|
}
|
|
23
21
|
else {
|
|
24
|
-
purchaseOrder = await (0, index_1.updatePurchaseOrderFunction)(_, purchaseOrder,
|
|
22
|
+
purchaseOrder = await (0, index_1.updatePurchaseOrderFunction)(_, purchaseOrder, files, context, tx);
|
|
25
23
|
}
|
|
26
24
|
return purchaseOrder;
|
|
27
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upsert-purchase-order.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/purchase-order/upsert-purchase-order.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"upsert-purchase-order.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/purchase-order/upsert-purchase-order.ts"],"names":[],"mappings":";;;AAIA,mCAAkF;AAErE,QAAA,mBAAmB,GAAG;IACjC,KAAK,CAAC,mBAAmB,CAAC,CAAM,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,EAAE,OAAY;QACtE,IAAI;YACF,MAAM,EAAE,EAAE,EAAE,GAA0B,OAAO,CAAC,KAAK,CAAA;YACnD,MAAM,oBAAoB,GAAkB,MAAM,2BAA2B,CAC3E,CAAC,EACD,aAAa,EACb,KAAK,EACL,OAAO,EACP,EAAE,CACH,CAAA;YAED,OAAO,oBAAoB,CAAA;SAC5B;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,KAAK,CAAA;SACZ;IACH,CAAC;CACF,CAAA;AAEM,KAAK,UAAU,2BAA2B,CAC/C,CAAM,EACN,aAAkB,EAClB,KAAmB,EACnB,OAAY,EACZ,EAAkB;IAElB,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE;QACrB,aAAa,GAAG,MAAM,IAAA,mCAA2B,EAAC,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAA;KACxF;SAAM;QACL,aAAa,GAAG,MAAM,IAAA,mCAA2B,EAAC,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAA;KACxF;IAED,OAAO,aAAa,CAAA;AACtB,CAAC;AAdD,kEAcC"}
|
|
@@ -8,7 +8,7 @@ const purchase_order_patch_1 = require("./purchase-order-patch");
|
|
|
8
8
|
exports.Mutation = `
|
|
9
9
|
upsertPurchaseOrder (
|
|
10
10
|
purchaseOrder: PurchaseOrderPatch!
|
|
11
|
-
|
|
11
|
+
files: [Upload!]
|
|
12
12
|
): PurchaseOrder @privilege(category: "order_customer", privilege: "mutation") @transaction
|
|
13
13
|
|
|
14
14
|
approvePurchaseOrder (
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/types/purchase-order/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/types/purchase-order/index.ts"],"names":[],"mappings":";;;AAAA,6DAAuD;AACvD,qDAAgD;AAChD,+DAAyD;AACzD,iEAA2D;AAE9C,QAAA,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BvB,CAAA;AAEY,QAAA,KAAK,GAAG;;;CAGpB,CAAA;AAEY,QAAA,KAAK,GAAG,CAAC,8BAAa,EAAE,qCAAgB,EAAE,yCAAkB,EAAE,uCAAiB,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/sales-base",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.26",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@things-factory/attachment-base": "^3.8.0",
|
|
28
28
|
"@things-factory/auth-base": "^3.8.0",
|
|
29
|
-
"@things-factory/biz-base": "^3.8.
|
|
29
|
+
"@things-factory/biz-base": "^3.8.26",
|
|
30
30
|
"@things-factory/code-base": "^3.8.0",
|
|
31
31
|
"@things-factory/notification": "^3.8.0",
|
|
32
|
-
"@things-factory/product-base": "^3.8.
|
|
32
|
+
"@things-factory/product-base": "^3.8.26",
|
|
33
33
|
"@things-factory/setting-base": "^3.8.0",
|
|
34
34
|
"@things-factory/shell": "^3.8.0",
|
|
35
|
-
"@things-factory/transport-base": "^3.8.
|
|
36
|
-
"@things-factory/warehouse-base": "^3.8.
|
|
35
|
+
"@things-factory/transport-base": "^3.8.26",
|
|
36
|
+
"@things-factory/warehouse-base": "^3.8.26"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "6ca26d91b7dad8eec6bc7859391bbd50374c744b"
|
|
39
39
|
}
|
|
@@ -1,21 +1,30 @@
|
|
|
1
|
+
import { FileUpload } from 'graphql-upload'
|
|
2
|
+
import { EntityManager, getRepository, Repository } from 'typeorm'
|
|
3
|
+
|
|
1
4
|
import { Attachment, createAttachments } from '@things-factory/attachment-base'
|
|
2
|
-
import { Bizplace, ContactPoint, getMyBizplace, getOutletBizplace, getPermittedBizplaces } from '@things-factory/biz-base'
|
|
3
|
-
import { Location } from '@things-factory/warehouse-base'
|
|
4
|
-
import { generateId } from '@things-factory/id-rule-base'
|
|
5
5
|
import { User } from '@things-factory/auth-base'
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import {
|
|
7
|
+
Bizplace,
|
|
8
|
+
ContactPoint,
|
|
9
|
+
getMyBizplace,
|
|
10
|
+
getOutletBizplace,
|
|
11
|
+
getPermittedBizplaces
|
|
12
|
+
} from '@things-factory/biz-base'
|
|
13
|
+
import { generateId } from '@things-factory/id-rule-base'
|
|
8
14
|
import { Setting } from '@things-factory/setting-base'
|
|
15
|
+
import { Domain } from '@things-factory/shell'
|
|
16
|
+
import { Location } from '@things-factory/warehouse-base'
|
|
17
|
+
|
|
9
18
|
import {
|
|
19
|
+
ATTACHMENT_TYPE,
|
|
10
20
|
ORDER_NUMBER_RULE_TYPE,
|
|
11
21
|
ORDER_NUMBER_SETTING_KEY,
|
|
12
|
-
PURCHASE_ORDER_STATUS
|
|
13
|
-
ATTACHMENT_TYPE
|
|
22
|
+
PURCHASE_ORDER_STATUS
|
|
14
23
|
} from '../../../constants'
|
|
15
|
-
import { ArrivalNotice,
|
|
24
|
+
import { ArrivalNotice, OrderProduct, PurchaseOrder, PurchaseOrderOtherCharge } from '../../../entities'
|
|
16
25
|
import { OrderNoGenerator } from '../../../utils/order-no-generator'
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
26
|
+
import { confirmArrivalNoticeFunction, generateArrivalNoticeFunction } from '../arrival-notice/index'
|
|
27
|
+
import { upsertPurchaseOrderProducts } from './index'
|
|
19
28
|
|
|
20
29
|
export const createPurchaseOrder = {
|
|
21
30
|
async createPurchaseOrder(_: any, { purchaseOrder }, context: any) {
|
|
@@ -33,7 +42,7 @@ export const createPurchaseOrder = {
|
|
|
33
42
|
export async function createPurchaseOrderFunction(
|
|
34
43
|
_: any,
|
|
35
44
|
purchaseOrder: any,
|
|
36
|
-
|
|
45
|
+
files: FileUpload[],
|
|
37
46
|
context: any,
|
|
38
47
|
tx?: EntityManager
|
|
39
48
|
): Promise<PurchaseOrder> {
|
|
@@ -54,24 +63,23 @@ export async function createPurchaseOrderFunction(
|
|
|
54
63
|
if (!foundPermittedBizplace) throw new Error(`This user does not permitted for this company`)
|
|
55
64
|
|
|
56
65
|
purchaseOrder.bizplace = foundPermittedBizplace
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
66
|
+
} else {
|
|
59
67
|
arrError.push(`No bizplace was selected`)
|
|
60
68
|
}
|
|
61
69
|
|
|
62
|
-
if(purchaseOrder?.supplier?.id){
|
|
63
|
-
purchaseOrder.supplier = await getRepository(ContactPoint).findOne({id: purchaseOrder.supplier.id})
|
|
64
|
-
}else{
|
|
70
|
+
if (purchaseOrder?.supplier?.id) {
|
|
71
|
+
purchaseOrder.supplier = await getRepository(ContactPoint).findOne({ id: purchaseOrder.supplier.id })
|
|
72
|
+
} else {
|
|
65
73
|
arrError.push(`No supplier was selected`)
|
|
66
74
|
}
|
|
67
75
|
|
|
68
|
-
if(purchaseOrder?.bufferLocation?.id){
|
|
69
|
-
purchaseOrder.bufferLocation = await getRepository(Location).findOne({id: purchaseOrder.bufferLocation.id})
|
|
70
|
-
}else{
|
|
76
|
+
if (purchaseOrder?.bufferLocation?.id) {
|
|
77
|
+
purchaseOrder.bufferLocation = await getRepository(Location).findOne({ id: purchaseOrder.bufferLocation.id })
|
|
78
|
+
} else {
|
|
71
79
|
arrError.push(`No buffer location was selected`)
|
|
72
80
|
}
|
|
73
81
|
|
|
74
|
-
if(arrError.length > 0){
|
|
82
|
+
if (arrError.length > 0) {
|
|
75
83
|
throw new Error(arrError.join(', '))
|
|
76
84
|
}
|
|
77
85
|
|
|
@@ -98,16 +106,9 @@ export async function createPurchaseOrderFunction(
|
|
|
98
106
|
creator: user,
|
|
99
107
|
updater: user
|
|
100
108
|
})
|
|
101
|
-
|
|
109
|
+
|
|
102
110
|
// // 2. Create purchase order product
|
|
103
|
-
await upsertPurchaseOrderProducts(
|
|
104
|
-
domain,
|
|
105
|
-
purchaseOrder.bizplace,
|
|
106
|
-
createdPurchaseOrder,
|
|
107
|
-
orderProducts,
|
|
108
|
-
user,
|
|
109
|
-
tx
|
|
110
|
-
)
|
|
111
|
+
await upsertPurchaseOrderProducts(domain, purchaseOrder.bizplace, createdPurchaseOrder, orderProducts, user, tx)
|
|
111
112
|
|
|
112
113
|
// // 3. Create purchase order misc charges
|
|
113
114
|
for await (let oc of otherCharges) {
|
|
@@ -122,8 +123,8 @@ export async function createPurchaseOrderFunction(
|
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
// // 4. Create Attacments
|
|
125
|
-
if (
|
|
126
|
-
const attachments: Attachment[] =
|
|
126
|
+
if (files?.length) {
|
|
127
|
+
const attachments: Attachment[] = files.map(attachment => {
|
|
127
128
|
return {
|
|
128
129
|
file: attachment,
|
|
129
130
|
refBy: createdPurchaseOrder.id,
|
|
@@ -132,6 +133,6 @@ export async function createPurchaseOrderFunction(
|
|
|
132
133
|
})
|
|
133
134
|
await createAttachments(_, { attachments }, context)
|
|
134
135
|
}
|
|
135
|
-
|
|
136
|
+
|
|
136
137
|
return createdPurchaseOrder
|
|
137
138
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FileUpload } from 'graphql-upload'
|
|
2
|
+
import { EntityManager, getRepository, Repository } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { Attachment, createAttachments, deleteAttachmentsByRef } from '@things-factory/attachment-base'
|
|
2
5
|
import { User } from '@things-factory/auth-base'
|
|
3
6
|
import { Bizplace, ContactPoint, getPermittedBizplaces } from '@things-factory/biz-base'
|
|
4
7
|
import { Domain } from '@things-factory/shell'
|
|
5
8
|
import { Location } from '@things-factory/warehouse-base'
|
|
6
|
-
|
|
9
|
+
|
|
7
10
|
import { ATTACHMENT_TYPE } from '../../../constants'
|
|
8
11
|
import { OrderProduct, PurchaseOrder, PurchaseOrderOtherCharge } from '../../../entities'
|
|
9
12
|
import { getPurchaseOrderFunction, upsertPurchaseOrderProducts } from './index'
|
|
@@ -28,7 +31,7 @@ export const updatePurchaseOrder = {
|
|
|
28
31
|
export async function updatePurchaseOrderFunction(
|
|
29
32
|
_: any,
|
|
30
33
|
purchaseOrder: any,
|
|
31
|
-
|
|
34
|
+
files: FileUpload[],
|
|
32
35
|
context: any,
|
|
33
36
|
tx?: EntityManager
|
|
34
37
|
): Promise<PurchaseOrder> {
|
|
@@ -100,14 +103,13 @@ export async function updatePurchaseOrderFunction(
|
|
|
100
103
|
})
|
|
101
104
|
|
|
102
105
|
// // 6. Remove All Attachment
|
|
103
|
-
|
|
104
|
-
await
|
|
106
|
+
if (foundAttachments?.length) {
|
|
107
|
+
await deleteAttachmentsByRef(_, { refBys: foundAttachments.map(file => file.refBy) }, context)
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
// // 7. Add New Attachment
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const attachments: Attachment[] = newAttachments.map(attachment => {
|
|
111
|
+
if (files?.length > 0) {
|
|
112
|
+
const attachments: Attachment[] = files.map(attachment => {
|
|
111
113
|
return {
|
|
112
114
|
file: attachment,
|
|
113
115
|
refBy: updatePurchaseOrder.id,
|
|
@@ -1,30 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { Setting } from '@things-factory/setting-base'
|
|
7
|
-
import { Domain } from '@things-factory/shell'
|
|
8
|
-
import { Location } from '@things-factory/warehouse-base'
|
|
9
|
-
import { EntityManager, getRepository, Repository } from 'typeorm'
|
|
10
|
-
import {
|
|
11
|
-
ORDER_NUMBER_RULE_TYPE,
|
|
12
|
-
ORDER_NUMBER_SETTING_KEY,
|
|
13
|
-
PURCHASE_ORDER_STATUS,
|
|
14
|
-
ATTACHMENT_TYPE
|
|
15
|
-
} from '../../../constants'
|
|
16
|
-
import { ArrivalNotice, PurchaseOrder, OrderProduct } from '../../../entities'
|
|
17
|
-
import { OrderNoGenerator } from '../../../utils/order-no-generator'
|
|
18
|
-
import { updatePurchaseOrderFunction, createPurchaseOrderFunction} from './index'
|
|
19
|
-
import { generateArrivalNoticeFunction, confirmArrivalNoticeFunction } from '../arrival-notice/index'
|
|
1
|
+
import { FileUpload } from 'graphql-upload'
|
|
2
|
+
import { EntityManager } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { PurchaseOrder } from '../../../entities'
|
|
5
|
+
import { createPurchaseOrderFunction, updatePurchaseOrderFunction } from './index'
|
|
20
6
|
|
|
21
7
|
export const upsertPurchaseOrder = {
|
|
22
|
-
async upsertPurchaseOrder(_: any, { purchaseOrder,
|
|
8
|
+
async upsertPurchaseOrder(_: any, { purchaseOrder, files }, context: any) {
|
|
23
9
|
try {
|
|
24
10
|
const { tx }: { tx: EntityManager } = context.state
|
|
25
|
-
const createdPurchaseOrder: PurchaseOrder = await upsertPurchaseOrderFunction(
|
|
26
|
-
|
|
27
|
-
|
|
11
|
+
const createdPurchaseOrder: PurchaseOrder = await upsertPurchaseOrderFunction(
|
|
12
|
+
_,
|
|
13
|
+
purchaseOrder,
|
|
14
|
+
files,
|
|
15
|
+
context,
|
|
16
|
+
tx
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
return createdPurchaseOrder
|
|
28
20
|
} catch (error) {
|
|
29
21
|
throw error
|
|
30
22
|
}
|
|
@@ -34,18 +26,15 @@ export const upsertPurchaseOrder = {
|
|
|
34
26
|
export async function upsertPurchaseOrderFunction(
|
|
35
27
|
_: any,
|
|
36
28
|
purchaseOrder: any,
|
|
37
|
-
|
|
29
|
+
files: FileUpload[],
|
|
38
30
|
context: any,
|
|
39
31
|
tx?: EntityManager
|
|
40
32
|
): Promise<PurchaseOrder> {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
purchaseOrder = await createPurchaseOrderFunction(_, purchaseOrder, file, context, tx)
|
|
46
|
-
}else{
|
|
47
|
-
purchaseOrder = await updatePurchaseOrderFunction(_, purchaseOrder, file, context, tx)
|
|
33
|
+
if (!purchaseOrder.id) {
|
|
34
|
+
purchaseOrder = await createPurchaseOrderFunction(_, purchaseOrder, files, context, tx)
|
|
35
|
+
} else {
|
|
36
|
+
purchaseOrder = await updatePurchaseOrderFunction(_, purchaseOrder, files, context, tx)
|
|
48
37
|
}
|
|
49
|
-
|
|
38
|
+
|
|
50
39
|
return purchaseOrder
|
|
51
40
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import gql from 'graphql-tag'
|
|
2
|
-
|
|
3
1
|
import { NewPurchaseOrder } from './new-purchase-order'
|
|
4
2
|
import { PurchaseOrder } from './purchase-order'
|
|
5
3
|
import { PurchaseOrderList } from './purchase-order-list'
|
|
6
4
|
import { PurchaseOrderPatch } from './purchase-order-patch'
|
|
7
5
|
|
|
8
|
-
|
|
9
6
|
export const Mutation = `
|
|
10
7
|
upsertPurchaseOrder (
|
|
11
8
|
purchaseOrder: PurchaseOrderPatch!
|
|
12
|
-
|
|
9
|
+
files: [Upload!]
|
|
13
10
|
): PurchaseOrder @privilege(category: "order_customer", privilege: "mutation") @transaction
|
|
14
11
|
|
|
15
12
|
approvePurchaseOrder (
|