@things-factory/invoice 0.0.0-stage → 10.1.130
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/README.md +21 -2
- package/dist-client/bootstrap.d.ts +1 -0
- package/dist-client/bootstrap.js +5 -0
- package/dist-client/bootstrap.js.map +1 -0
- package/dist-client/document/document-amount.d.ts +6 -0
- package/dist-client/document/document-amount.js +19 -0
- package/dist-client/document/document-amount.js.map +1 -0
- package/dist-client/document/document-form.d.ts +14 -0
- package/dist-client/document/document-form.js +145 -0
- package/dist-client/document/document-form.js.map +1 -0
- package/dist-client/document/document-lines.d.ts +104 -0
- package/dist-client/document/document-lines.js +61 -0
- package/dist-client/document/document-lines.js.map +1 -0
- package/dist-client/document/document-print.d.ts +15 -0
- package/dist-client/document/document-print.js +60 -0
- package/dist-client/document/document-print.js.map +1 -0
- package/dist-client/entity360/invoice-360.d.ts +19 -0
- package/dist-client/entity360/invoice-360.js +116 -0
- package/dist-client/entity360/invoice-360.js.map +1 -0
- package/dist-client/index.d.ts +6 -0
- package/dist-client/index.js +7 -0
- package/dist-client/index.js.map +1 -0
- package/dist-client/invoice-attach.d.ts +19 -0
- package/dist-client/invoice-attach.js +19 -0
- package/dist-client/invoice-attach.js.map +1 -0
- package/dist-client/pages/invoice-editor.d.ts +48 -0
- package/dist-client/pages/invoice-editor.js +341 -0
- package/dist-client/pages/invoice-editor.js.map +1 -0
- package/dist-client/pages/invoice-list.d.ts +39 -0
- package/dist-client/pages/invoice-list.js +125 -0
- package/dist-client/pages/invoice-list.js.map +1 -0
- package/dist-client/route.d.ts +1 -0
- package/dist-client/route.js +11 -0
- package/dist-client/route.js.map +1 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -0
- package/dist-server/index.d.ts +2 -0
- package/dist-server/index.js +6 -0
- package/dist-server/index.js.map +1 -0
- package/dist-server/routes.d.ts +1 -0
- package/dist-server/routes.js +3 -0
- package/dist-server/routes.js.map +1 -0
- package/dist-server/service/index.d.ts +12 -0
- package/dist-server/service/index.js +19 -0
- package/dist-server/service/index.js.map +1 -0
- package/dist-server/service/invoice/commercial-document.d.ts +44 -0
- package/dist-server/service/invoice/commercial-document.js +200 -0
- package/dist-server/service/invoice/commercial-document.js.map +1 -0
- package/dist-server/service/invoice/index.d.ts +6 -0
- package/dist-server/service/invoice/index.js +10 -0
- package/dist-server/service/invoice/index.js.map +1 -0
- package/dist-server/service/invoice/invoice-mutation.d.ts +8 -0
- package/dist-server/service/invoice/invoice-mutation.js +75 -0
- package/dist-server/service/invoice/invoice-mutation.js.map +1 -0
- package/dist-server/service/invoice/invoice-query.d.ts +16 -0
- package/dist-server/service/invoice/invoice-query.js +117 -0
- package/dist-server/service/invoice/invoice-query.js.map +1 -0
- package/dist-server/service/invoice/invoice-rules.d.ts +83 -0
- package/dist-server/service/invoice/invoice-rules.js +202 -0
- package/dist-server/service/invoice/invoice-rules.js.map +1 -0
- package/dist-server/service/invoice/invoice-service.d.ts +26 -0
- package/dist-server/service/invoice/invoice-service.js +133 -0
- package/dist-server/service/invoice/invoice-service.js.map +1 -0
- package/dist-server/service/invoice/invoice-type.d.ts +40 -0
- package/dist-server/service/invoice/invoice-type.js +146 -0
- package/dist-server/service/invoice/invoice-type.js.map +1 -0
- package/dist-server/service/invoice/invoice.d.ts +30 -0
- package/dist-server/service/invoice/invoice.js +108 -0
- package/dist-server/service/invoice/invoice.js.map +1 -0
- package/dist-server/service/invoice-event/index.d.ts +5 -0
- package/dist-server/service/invoice-event/index.js +9 -0
- package/dist-server/service/invoice-event/index.js.map +1 -0
- package/dist-server/service/invoice-event/invoice-event-query.d.ts +9 -0
- package/dist-server/service/invoice-event/invoice-event-query.js +57 -0
- package/dist-server/service/invoice-event/invoice-event-query.js.map +1 -0
- package/dist-server/service/invoice-event/invoice-event.d.ts +22 -0
- package/dist-server/service/invoice-event/invoice-event.js +98 -0
- package/dist-server/service/invoice-event/invoice-event.js.map +1 -0
- package/dist-server/service/invoice-item/index.d.ts +5 -0
- package/dist-server/service/invoice-item/index.js +9 -0
- package/dist-server/service/invoice-item/index.js.map +1 -0
- package/dist-server/service/invoice-item/invoice-item-query.d.ts +8 -0
- package/dist-server/service/invoice-item/invoice-item-query.js +47 -0
- package/dist-server/service/invoice-item/invoice-item-query.js.map +1 -0
- package/dist-server/service/invoice-item/invoice-item.d.ts +19 -0
- package/dist-server/service/invoice-item/invoice-item.js +80 -0
- package/dist-server/service/invoice-item/invoice-item.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -0
- package/package.json +44 -4
- package/things-factory.config.js +11 -0
- package/translations/en.json +81 -0
- package/translations/ko.json +81 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DocumentTaxGroup = exports.CommercialLine = exports.CommercialDocument = exports.DocumentDirection = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const shell_1 = require("@things-factory/shell");
|
|
6
|
+
const type_graphql_1 = require("type-graphql");
|
|
7
|
+
const typeorm_1 = require("typeorm");
|
|
8
|
+
const invoice_rules_1 = require("./invoice-rules");
|
|
9
|
+
/*
|
|
10
|
+
* The head, the amounts and the line of a commercial document. Invoice and quotation each keep their own table and
|
|
11
|
+
* extend these, so the printed fields and their rules are written once (ADR-0120 decision 1).
|
|
12
|
+
*/
|
|
13
|
+
(0, type_graphql_1.registerEnumType)(invoice_rules_1.TaxKind, { name: 'TaxKind', description: 'taxation of a line — taxable, zero-rated or exempt' });
|
|
14
|
+
var DocumentDirection;
|
|
15
|
+
(function (DocumentDirection) {
|
|
16
|
+
DocumentDirection["SALES"] = "SALES";
|
|
17
|
+
DocumentDirection["PURCHASE"] = "PURCHASE";
|
|
18
|
+
})(DocumentDirection || (exports.DocumentDirection = DocumentDirection = {}));
|
|
19
|
+
(0, type_graphql_1.registerEnumType)(DocumentDirection, { name: 'DocumentDirection', description: 'whether the domain sends the document or receives it' });
|
|
20
|
+
const amount = (0, shell_1.moneyColumn)({ scale: 4 });
|
|
21
|
+
let CommercialDocument = class CommercialDocument {
|
|
22
|
+
};
|
|
23
|
+
exports.CommercialDocument = CommercialDocument;
|
|
24
|
+
tslib_1.__decorate([
|
|
25
|
+
(0, typeorm_1.Column)(),
|
|
26
|
+
(0, type_graphql_1.Field)({ description: 'Document number, unique in the domain' }),
|
|
27
|
+
tslib_1.__metadata("design:type", String)
|
|
28
|
+
], CommercialDocument.prototype, "number", void 0);
|
|
29
|
+
tslib_1.__decorate([
|
|
30
|
+
(0, typeorm_1.Column)({ default: DocumentDirection.SALES }),
|
|
31
|
+
(0, type_graphql_1.Field)(type => DocumentDirection, { description: 'SALES for a document the domain sends, PURCHASE for one it receives' }),
|
|
32
|
+
tslib_1.__metadata("design:type", String)
|
|
33
|
+
], CommercialDocument.prototype, "direction", void 0);
|
|
34
|
+
tslib_1.__decorate([
|
|
35
|
+
(0, typeorm_1.Column)({ default: 'KRW' }),
|
|
36
|
+
(0, type_graphql_1.Field)({ description: 'ISO 4217 currency code' }),
|
|
37
|
+
tslib_1.__metadata("design:type", String)
|
|
38
|
+
], CommercialDocument.prototype, "currency", void 0);
|
|
39
|
+
tslib_1.__decorate([
|
|
40
|
+
(0, typeorm_1.Column)({ default: 'ko' }),
|
|
41
|
+
(0, type_graphql_1.Field)({ description: 'Language the document is printed in: ko or en' }),
|
|
42
|
+
tslib_1.__metadata("design:type", String)
|
|
43
|
+
], CommercialDocument.prototype, "language", void 0);
|
|
44
|
+
tslib_1.__decorate([
|
|
45
|
+
(0, typeorm_1.Column)(),
|
|
46
|
+
(0, type_graphql_1.Field)({ description: 'Supplier name as printed' }),
|
|
47
|
+
tslib_1.__metadata("design:type", String)
|
|
48
|
+
], CommercialDocument.prototype, "supplierName", void 0);
|
|
49
|
+
tslib_1.__decorate([
|
|
50
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
51
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Supplier address as printed' }),
|
|
52
|
+
tslib_1.__metadata("design:type", String)
|
|
53
|
+
], CommercialDocument.prototype, "supplierAddress", void 0);
|
|
54
|
+
tslib_1.__decorate([
|
|
55
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
56
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Supplier business or tax registration number' }),
|
|
57
|
+
tslib_1.__metadata("design:type", String)
|
|
58
|
+
], CommercialDocument.prototype, "supplierRegistrationNumber", void 0);
|
|
59
|
+
tslib_1.__decorate([
|
|
60
|
+
(0, typeorm_1.Column)(),
|
|
61
|
+
(0, type_graphql_1.Field)({ description: 'Buyer name as printed' }),
|
|
62
|
+
tslib_1.__metadata("design:type", String)
|
|
63
|
+
], CommercialDocument.prototype, "buyerName", void 0);
|
|
64
|
+
tslib_1.__decorate([
|
|
65
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
66
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Buyer address as printed' }),
|
|
67
|
+
tslib_1.__metadata("design:type", String)
|
|
68
|
+
], CommercialDocument.prototype, "buyerAddress", void 0);
|
|
69
|
+
tslib_1.__decorate([
|
|
70
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
71
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Buyer business or tax registration number' }),
|
|
72
|
+
tslib_1.__metadata("design:type", String)
|
|
73
|
+
], CommercialDocument.prototype, "buyerRegistrationNumber", void 0);
|
|
74
|
+
tslib_1.__decorate([
|
|
75
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
76
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Issue date, YYYY-MM-DD' }),
|
|
77
|
+
tslib_1.__metadata("design:type", String)
|
|
78
|
+
], CommercialDocument.prototype, "issueDate", void 0);
|
|
79
|
+
tslib_1.__decorate([
|
|
80
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
81
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Buyer purchase order reference' }),
|
|
82
|
+
tslib_1.__metadata("design:type", String)
|
|
83
|
+
], CommercialDocument.prototype, "purchaseOrder", void 0);
|
|
84
|
+
tslib_1.__decorate([
|
|
85
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
86
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Payment terms as printed' }),
|
|
87
|
+
tslib_1.__metadata("design:type", String)
|
|
88
|
+
], CommercialDocument.prototype, "paymentTerms", void 0);
|
|
89
|
+
tslib_1.__decorate([
|
|
90
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
91
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Bank account to pay into, as printed' }),
|
|
92
|
+
tslib_1.__metadata("design:type", String)
|
|
93
|
+
], CommercialDocument.prototype, "bankDetails", void 0);
|
|
94
|
+
tslib_1.__decorate([
|
|
95
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
96
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Notes printed on the document' }),
|
|
97
|
+
tslib_1.__metadata("design:type", String)
|
|
98
|
+
], CommercialDocument.prototype, "notes", void 0);
|
|
99
|
+
tslib_1.__decorate([
|
|
100
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
101
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Reference to the record the document was made from' }),
|
|
102
|
+
tslib_1.__metadata("design:type", String)
|
|
103
|
+
], CommercialDocument.prototype, "sourceReference", void 0);
|
|
104
|
+
tslib_1.__decorate([
|
|
105
|
+
(0, typeorm_1.Column)({ ...amount, default: 0 }),
|
|
106
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Float, { description: 'Sum of the line supply amounts' }),
|
|
107
|
+
tslib_1.__metadata("design:type", Number)
|
|
108
|
+
], CommercialDocument.prototype, "supplyAmount", void 0);
|
|
109
|
+
tslib_1.__decorate([
|
|
110
|
+
(0, typeorm_1.Column)({ ...amount, default: 0 }),
|
|
111
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Float, { description: 'Sum of the tax of each tax kind and rate group' }),
|
|
112
|
+
tslib_1.__metadata("design:type", Number)
|
|
113
|
+
], CommercialDocument.prototype, "taxAmount", void 0);
|
|
114
|
+
tslib_1.__decorate([
|
|
115
|
+
(0, typeorm_1.Column)({ ...amount, default: 0 }),
|
|
116
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Float, { description: 'Supply plus tax' }),
|
|
117
|
+
tslib_1.__metadata("design:type", Number)
|
|
118
|
+
], CommercialDocument.prototype, "totalAmount", void 0);
|
|
119
|
+
tslib_1.__decorate([
|
|
120
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
121
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'How the tax was rounded, written when the document went out' }),
|
|
122
|
+
tslib_1.__metadata("design:type", String)
|
|
123
|
+
], CommercialDocument.prototype, "taxRounding", void 0);
|
|
124
|
+
tslib_1.__decorate([
|
|
125
|
+
(0, typeorm_1.Column)({ type: 'int', nullable: true }),
|
|
126
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: 'Decimal places of the currency, written when the document went out' }),
|
|
127
|
+
tslib_1.__metadata("design:type", Number)
|
|
128
|
+
], CommercialDocument.prototype, "currencyDigits", void 0);
|
|
129
|
+
exports.CommercialDocument = CommercialDocument = tslib_1.__decorate([
|
|
130
|
+
(0, type_graphql_1.ObjectType)({ description: 'The printed head and totals of a commercial document' })
|
|
131
|
+
], CommercialDocument);
|
|
132
|
+
let CommercialLine = class CommercialLine {
|
|
133
|
+
};
|
|
134
|
+
exports.CommercialLine = CommercialLine;
|
|
135
|
+
tslib_1.__decorate([
|
|
136
|
+
(0, typeorm_1.Column)({ type: 'int' }),
|
|
137
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { description: 'Order of the line on the document' }),
|
|
138
|
+
tslib_1.__metadata("design:type", Number)
|
|
139
|
+
], CommercialLine.prototype, "position", void 0);
|
|
140
|
+
tslib_1.__decorate([
|
|
141
|
+
(0, typeorm_1.Column)(),
|
|
142
|
+
(0, type_graphql_1.Field)({ description: 'What the line charges for' }),
|
|
143
|
+
tslib_1.__metadata("design:type", String)
|
|
144
|
+
], CommercialLine.prototype, "description", void 0);
|
|
145
|
+
tslib_1.__decorate([
|
|
146
|
+
(0, typeorm_1.Column)(amount),
|
|
147
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Float, { description: 'Quantity' }),
|
|
148
|
+
tslib_1.__metadata("design:type", Number)
|
|
149
|
+
], CommercialLine.prototype, "quantity", void 0);
|
|
150
|
+
tslib_1.__decorate([
|
|
151
|
+
(0, typeorm_1.Column)(amount),
|
|
152
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Float, { description: 'Price of one unit' }),
|
|
153
|
+
tslib_1.__metadata("design:type", Number)
|
|
154
|
+
], CommercialLine.prototype, "unitPrice", void 0);
|
|
155
|
+
tslib_1.__decorate([
|
|
156
|
+
(0, typeorm_1.Column)(amount),
|
|
157
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Float, { description: 'Discount taken off the line, in the document currency' }),
|
|
158
|
+
tslib_1.__metadata("design:type", Number)
|
|
159
|
+
], CommercialLine.prototype, "discount", void 0);
|
|
160
|
+
tslib_1.__decorate([
|
|
161
|
+
(0, typeorm_1.Column)({ default: invoice_rules_1.TaxKind.TAXABLE }),
|
|
162
|
+
(0, type_graphql_1.Field)(type => invoice_rules_1.TaxKind, { description: 'Taxable, zero-rated or exempt' }),
|
|
163
|
+
tslib_1.__metadata("design:type", String)
|
|
164
|
+
], CommercialLine.prototype, "taxKind", void 0);
|
|
165
|
+
tslib_1.__decorate([
|
|
166
|
+
(0, typeorm_1.Column)(amount),
|
|
167
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Float, { description: 'Tax rate in percent; zero unless taxable' }),
|
|
168
|
+
tslib_1.__metadata("design:type", Number)
|
|
169
|
+
], CommercialLine.prototype, "taxRate", void 0);
|
|
170
|
+
tslib_1.__decorate([
|
|
171
|
+
(0, typeorm_1.Column)(amount),
|
|
172
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Float, { description: 'Quantity times price, less the discount' }),
|
|
173
|
+
tslib_1.__metadata("design:type", Number)
|
|
174
|
+
], CommercialLine.prototype, "supplyAmount", void 0);
|
|
175
|
+
exports.CommercialLine = CommercialLine = tslib_1.__decorate([
|
|
176
|
+
(0, type_graphql_1.ObjectType)({ description: 'One line of a commercial document' })
|
|
177
|
+
], CommercialLine);
|
|
178
|
+
let DocumentTaxGroup = class DocumentTaxGroup {
|
|
179
|
+
};
|
|
180
|
+
exports.DocumentTaxGroup = DocumentTaxGroup;
|
|
181
|
+
tslib_1.__decorate([
|
|
182
|
+
(0, type_graphql_1.Field)(type => invoice_rules_1.TaxKind, { description: 'Taxable, zero-rated or exempt' }),
|
|
183
|
+
tslib_1.__metadata("design:type", String)
|
|
184
|
+
], DocumentTaxGroup.prototype, "taxKind", void 0);
|
|
185
|
+
tslib_1.__decorate([
|
|
186
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Float, { description: 'Tax rate in percent' }),
|
|
187
|
+
tslib_1.__metadata("design:type", Number)
|
|
188
|
+
], DocumentTaxGroup.prototype, "taxRate", void 0);
|
|
189
|
+
tslib_1.__decorate([
|
|
190
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Float, { description: 'Supply of the lines in the group' }),
|
|
191
|
+
tslib_1.__metadata("design:type", Number)
|
|
192
|
+
], DocumentTaxGroup.prototype, "supplyAmount", void 0);
|
|
193
|
+
tslib_1.__decorate([
|
|
194
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Float, { description: 'Tax of the group' }),
|
|
195
|
+
tslib_1.__metadata("design:type", Number)
|
|
196
|
+
], DocumentTaxGroup.prototype, "taxAmount", void 0);
|
|
197
|
+
exports.DocumentTaxGroup = DocumentTaxGroup = tslib_1.__decorate([
|
|
198
|
+
(0, type_graphql_1.ObjectType)({ description: 'The supply and tax of one tax kind and rate on a document' })
|
|
199
|
+
], DocumentTaxGroup);
|
|
200
|
+
//# sourceMappingURL=commercial-document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commercial-document.js","sourceRoot":"","sources":["../../../server/service/invoice/commercial-document.ts"],"names":[],"mappings":";;;;AAAA,iDAAmD;AACnD,+CAA8E;AAC9E,qCAAgC;AAEhC,mDAAyC;AAEzC;;;GAGG;AAEH,IAAA,+BAAgB,EAAC,uBAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,oDAAoD,EAAE,CAAC,CAAA;AAEjH,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,oCAAe,CAAA;IACf,0CAAqB,CAAA;AACvB,CAAC,EAHW,iBAAiB,iCAAjB,iBAAiB,QAG5B;AACD,IAAA,+BAAgB,EAAC,iBAAiB,EAAE,EAAE,IAAI,EAAE,mBAAmB,EAAE,WAAW,EAAE,sDAAsD,EAAE,CAAC,CAAA;AAEvI,MAAM,MAAM,GAAG,IAAA,mBAAW,EAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAA;AAGjC,IAAe,kBAAkB,GAAjC,MAAe,kBAAkB;CAoFvC,CAAA;AApFqB,gDAAkB;AAGtC;IAFC,IAAA,gBAAM,GAAE;IACR,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,uCAAuC,EAAE,CAAC;;kDAClD;AAId;IAFC,IAAA,gBAAM,EAAC,EAAE,OAAO,EAAE,iBAAiB,CAAC,KAAK,EAAE,CAAC;IAC5C,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAiB,EAAE,EAAE,WAAW,EAAE,qEAAqE,EAAE,CAAC;;qDAC7F;AAI5B;IAFC,IAAA,gBAAM,EAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC1B,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,wBAAwB,EAAE,CAAC;;oDACjC;AAIhB;IAFC,IAAA,gBAAM,EAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACzB,I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AK,EAAE,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC;;mDACzC;2BAXN,gBAAgB;IAD5B,IAAA,yBAAU,EAAC,EAAE,WAAW,EAAE,2DAA2D,EAAE,CAAC;GAC5E,gBAAgB,CAY5B","sourcesContent":["import { moneyColumn } from '@things-factory/shell'\nimport { Field, Float, Int, ObjectType, registerEnumType } from 'type-graphql'\nimport { Column } from 'typeorm'\n\nimport { TaxKind } from './invoice-rules'\n\n/*\n * The head, the amounts and the line of a commercial document. Invoice and quotation each keep their own table and\n * extend these, so the printed fields and their rules are written once (ADR-0120 decision 1).\n */\n\nregisterEnumType(TaxKind, { name: 'TaxKind', description: 'taxation of a line — taxable, zero-rated or exempt' })\n\nexport enum DocumentDirection {\n SALES = 'SALES',\n PURCHASE = 'PURCHASE'\n}\nregisterEnumType(DocumentDirection, { name: 'DocumentDirection', description: 'whether the domain sends the document or receives it' })\n\nconst amount = moneyColumn({ scale: 4 })\n\n@ObjectType({ description: 'The printed head and totals of a commercial document' })\nexport abstract class CommercialDocument {\n @Column()\n @Field({ description: 'Document number, unique in the domain' })\n number: string\n\n @Column({ default: DocumentDirection.SALES })\n @Field(type => DocumentDirection, { description: 'SALES for a document the domain sends, PURCHASE for one it receives' })\n direction: DocumentDirection\n\n @Column({ default: 'KRW' })\n @Field({ description: 'ISO 4217 currency code' })\n currency: string\n\n @Column({ default: 'ko' })\n @Field({ description: 'Language the document is printed in: ko or en' })\n language: string\n\n @Column()\n @Field({ description: 'Supplier name as printed' })\n supplierName: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'Supplier address as printed' })\n supplierAddress?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'Supplier business or tax registration number' })\n supplierRegistrationNumber?: string\n\n @Column()\n @Field({ description: 'Buyer name as printed' })\n buyerName: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'Buyer address as printed' })\n buyerAddress?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'Buyer business or tax registration number' })\n buyerRegistrationNumber?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'Issue date, YYYY-MM-DD' })\n issueDate?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'Buyer purchase order reference' })\n purchaseOrder?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'Payment terms as printed' })\n paymentTerms?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'Bank account to pay into, as printed' })\n bankDetails?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'Notes printed on the document' })\n notes?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'Reference to the record the document was made from' })\n sourceReference?: string\n\n @Column({ ...amount, default: 0 })\n @Field(type => Float, { description: 'Sum of the line supply amounts' })\n supplyAmount: number\n\n @Column({ ...amount, default: 0 })\n @Field(type => Float, { description: 'Sum of the tax of each tax kind and rate group' })\n taxAmount: number\n\n @Column({ ...amount, default: 0 })\n @Field(type => Float, { description: 'Supply plus tax' })\n totalAmount: number\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'How the tax was rounded, written when the document went out' })\n taxRounding?: string\n\n @Column({ type: 'int', nullable: true })\n @Field(type => Int, { nullable: true, description: 'Decimal places of the currency, written when the document went out' })\n currencyDigits?: number\n}\n\n@ObjectType({ description: 'One line of a commercial document' })\nexport abstract class CommercialLine {\n @Column({ type: 'int' })\n @Field(type => Int, { description: 'Order of the line on the document' })\n position: number\n\n @Column()\n @Field({ description: 'What the line charges for' })\n description: string\n\n @Column(amount)\n @Field(type => Float, { description: 'Quantity' })\n quantity: number\n\n @Column(amount)\n @Field(type => Float, { description: 'Price of one unit' })\n unitPrice: number\n\n @Column(amount)\n @Field(type => Float, { description: 'Discount taken off the line, in the document currency' })\n discount: number\n\n @Column({ default: TaxKind.TAXABLE })\n @Field(type => TaxKind, { description: 'Taxable, zero-rated or exempt' })\n taxKind: TaxKind\n\n @Column(amount)\n @Field(type => Float, { description: 'Tax rate in percent; zero unless taxable' })\n taxRate: number\n\n @Column(amount)\n @Field(type => Float, { description: 'Quantity times price, less the discount' })\n supplyAmount: number\n}\n\n@ObjectType({ description: 'The supply and tax of one tax kind and rate on a document' })\nexport class DocumentTaxGroup {\n @Field(type => TaxKind, { description: 'Taxable, zero-rated or exempt' })\n taxKind: string\n\n @Field(type => Float, { description: 'Tax rate in percent' })\n taxRate: number\n\n @Field(type => Float, { description: 'Supply of the lines in the group' })\n supplyAmount: number\n\n @Field(type => Float, { description: 'Tax of the group' })\n taxAmount: number\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Invoice } from './invoice';
|
|
2
|
+
import { InvoiceMutation } from './invoice-mutation';
|
|
3
|
+
import { InvoiceQuery } from './invoice-query';
|
|
4
|
+
export declare const entities: (typeof Invoice)[];
|
|
5
|
+
export declare const resolvers: (typeof InvoiceMutation | typeof InvoiceQuery)[];
|
|
6
|
+
export declare const subscribers: any[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.subscribers = exports.resolvers = exports.entities = void 0;
|
|
4
|
+
const invoice_1 = require("./invoice");
|
|
5
|
+
const invoice_mutation_1 = require("./invoice-mutation");
|
|
6
|
+
const invoice_query_1 = require("./invoice-query");
|
|
7
|
+
exports.entities = [invoice_1.Invoice];
|
|
8
|
+
exports.resolvers = [invoice_query_1.InvoiceQuery, invoice_mutation_1.InvoiceMutation];
|
|
9
|
+
exports.subscribers = [];
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/service/invoice/index.ts"],"names":[],"mappings":";;;AAAA,uCAAmC;AACnC,yDAAoD;AACpD,mDAA8C;AACjC,QAAA,QAAQ,GAAG,CAAC,iBAAO,CAAC,CAAA;AACpB,QAAA,SAAS,GAAG,CAAC,4BAAY,EAAE,kCAAe,CAAC,CAAA;AAC3C,QAAA,WAAW,GAAG,EAAE,CAAA","sourcesContent":["import { Invoice } from './invoice'\nimport { InvoiceMutation } from './invoice-mutation'\nimport { InvoiceQuery } from './invoice-query'\nexport const entities = [Invoice]\nexport const resolvers = [InvoiceQuery, InvoiceMutation]\nexport const subscribers = []\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Invoice } from './invoice';
|
|
2
|
+
import { NewInvoice } from './invoice-type';
|
|
3
|
+
export declare class InvoiceMutation {
|
|
4
|
+
createInvoice(invoice: NewInvoice, context: ResolverContext): Promise<Invoice>;
|
|
5
|
+
updateInvoice(id: string, invoice: NewInvoice, context: ResolverContext): Promise<Invoice>;
|
|
6
|
+
issueInvoice(id: string, context: ResolverContext): Promise<Invoice>;
|
|
7
|
+
voidInvoice(id: string, reason: string, context: ResolverContext): Promise<Invoice>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvoiceMutation = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const shell_1 = require("@things-factory/shell");
|
|
6
|
+
const type_graphql_1 = require("type-graphql");
|
|
7
|
+
const invoice_1 = require("./invoice");
|
|
8
|
+
const invoice_service_1 = require("./invoice-service");
|
|
9
|
+
const invoice_type_1 = require("./invoice-type");
|
|
10
|
+
let InvoiceMutation = class InvoiceMutation {
|
|
11
|
+
createInvoice(invoice, context) {
|
|
12
|
+
const { tx, domain, user } = context.state;
|
|
13
|
+
return (0, invoice_service_1.saveInvoice)(tx, domain, user, invoice);
|
|
14
|
+
}
|
|
15
|
+
updateInvoice(id, invoice, context) {
|
|
16
|
+
const { tx, domain, user } = context.state;
|
|
17
|
+
return (0, invoice_service_1.saveInvoice)(tx, domain, user, invoice, id);
|
|
18
|
+
}
|
|
19
|
+
issueInvoice(id, context) {
|
|
20
|
+
const { tx, domain, user } = context.state;
|
|
21
|
+
return (0, invoice_service_1.transitionInvoice)(tx, domain, user, id, 'ISSUED');
|
|
22
|
+
}
|
|
23
|
+
voidInvoice(id, reason, context) {
|
|
24
|
+
const { tx, domain, user } = context.state;
|
|
25
|
+
return (0, invoice_service_1.transitionInvoice)(tx, domain, user, id, 'VOID', reason);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.InvoiceMutation = InvoiceMutation;
|
|
29
|
+
tslib_1.__decorate([
|
|
30
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
31
|
+
(0, type_graphql_1.Directive)('@privilege(category: "invoice", privilege: "mutation", domainOwnerGranted: true)'),
|
|
32
|
+
(0, type_graphql_1.Mutation)(type => invoice_1.Invoice, { description: 'To create an invoice draft' }),
|
|
33
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('invoice')),
|
|
34
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
35
|
+
tslib_1.__metadata("design:type", Function),
|
|
36
|
+
tslib_1.__metadata("design:paramtypes", [invoice_type_1.NewInvoice, Object]),
|
|
37
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
38
|
+
], InvoiceMutation.prototype, "createInvoice", null);
|
|
39
|
+
tslib_1.__decorate([
|
|
40
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
41
|
+
(0, type_graphql_1.Directive)('@privilege(category: "invoice", privilege: "mutation", domainOwnerGranted: true)'),
|
|
42
|
+
(0, type_graphql_1.Mutation)(type => invoice_1.Invoice, { description: 'To replace the head and lines of an invoice draft' }),
|
|
43
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
44
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('invoice')),
|
|
45
|
+
tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
|
|
46
|
+
tslib_1.__metadata("design:type", Function),
|
|
47
|
+
tslib_1.__metadata("design:paramtypes", [String, invoice_type_1.NewInvoice, Object]),
|
|
48
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
49
|
+
], InvoiceMutation.prototype, "updateInvoice", null);
|
|
50
|
+
tslib_1.__decorate([
|
|
51
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
52
|
+
(0, type_graphql_1.Directive)('@privilege(category: "invoice", privilege: "mutation", domainOwnerGranted: true)'),
|
|
53
|
+
(0, type_graphql_1.Mutation)(type => invoice_1.Invoice, { description: 'To issue an invoice draft; its amounts are fixed from then on' }),
|
|
54
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
55
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
56
|
+
tslib_1.__metadata("design:type", Function),
|
|
57
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
58
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
59
|
+
], InvoiceMutation.prototype, "issueInvoice", null);
|
|
60
|
+
tslib_1.__decorate([
|
|
61
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
62
|
+
(0, type_graphql_1.Directive)('@privilege(category: "invoice", privilege: "mutation", domainOwnerGranted: true)'),
|
|
63
|
+
(0, type_graphql_1.Mutation)(type => invoice_1.Invoice, { description: 'To void an invoice, with the reason' }),
|
|
64
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
65
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('reason')),
|
|
66
|
+
tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
|
|
67
|
+
tslib_1.__metadata("design:type", Function),
|
|
68
|
+
tslib_1.__metadata("design:paramtypes", [String, String, Object]),
|
|
69
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
70
|
+
], InvoiceMutation.prototype, "voidInvoice", null);
|
|
71
|
+
exports.InvoiceMutation = InvoiceMutation = tslib_1.__decorate([
|
|
72
|
+
(0, type_graphql_1.UseMiddleware)(shell_1.SpeakRefusals),
|
|
73
|
+
(0, type_graphql_1.Resolver)(invoice_1.Invoice)
|
|
74
|
+
], InvoiceMutation);
|
|
75
|
+
//# sourceMappingURL=invoice-mutation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoice-mutation.js","sourceRoot":"","sources":["../../../server/service/invoice/invoice-mutation.ts"],"names":[],"mappings":";;;;AAAA,iDAAqD;AACrD,+CAAqF;AAErF,uCAAmC;AACnC,uDAAkE;AAClE,iDAA2C;AAIpC,IAAM,eAAe,GAArB,MAAM,eAAe;IAI1B,aAAa,CAAiB,OAAmB,EAAS,OAAwB;QAChF,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1C,OAAO,IAAA,6BAAW,EAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IAC/C,CAAC;IAKD,aAAa,CAAY,EAAU,EAAkB,OAAmB,EAAS,OAAwB;QACvG,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1C,OAAO,IAAA,6BAAW,EAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,CAAA;IACnD,CAAC;IAKD,YAAY,CAAY,EAAU,EAAS,OAAwB;QACjE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1C,OAAO,IAAA,mCAAiB,EAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAA;IAC1D,CAAC;IAKD,WAAW,CAAY,EAAU,EAAiB,MAAc,EAAS,OAAwB;QAC/F,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1C,OAAO,IAAA,mCAAiB,EAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,MA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CAAA;IAAc,mBAAA,IAAA,kBAAG,EAAC,QAAQ,CAAC,CAAA;IAAkB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;kDAGvE;0BA/BU,eAAe;IAF3B,IAAA,4BAAa,EAAC,qBAAa,CAAC;IAC5B,IAAA,uBAAQ,EAAC,iBAAO,CAAC;GACL,eAAe,CAgC3B","sourcesContent":["import { SpeakRefusals } from '@things-factory/shell'\nimport { Arg, Ctx, Directive, Mutation, Resolver, UseMiddleware } from 'type-graphql'\n\nimport { Invoice } from './invoice'\nimport { saveInvoice, transitionInvoice } from './invoice-service'\nimport { NewInvoice } from './invoice-type'\n\n@UseMiddleware(SpeakRefusals)\n@Resolver(Invoice)\nexport class InvoiceMutation {\n @Directive('@transaction')\n @Directive('@privilege(category: \"invoice\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(type => Invoice, { description: 'To create an invoice draft' })\n createInvoice(@Arg('invoice') invoice: NewInvoice, @Ctx() context: ResolverContext) {\n const { tx, domain, user } = context.state\n return saveInvoice(tx, domain, user, invoice)\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"invoice\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(type => Invoice, { description: 'To replace the head and lines of an invoice draft' })\n updateInvoice(@Arg('id') id: string, @Arg('invoice') invoice: NewInvoice, @Ctx() context: ResolverContext) {\n const { tx, domain, user } = context.state\n return saveInvoice(tx, domain, user, invoice, id)\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"invoice\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(type => Invoice, { description: 'To issue an invoice draft; its amounts are fixed from then on' })\n issueInvoice(@Arg('id') id: string, @Ctx() context: ResolverContext) {\n const { tx, domain, user } = context.state\n return transitionInvoice(tx, domain, user, id, 'ISSUED')\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"invoice\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(type => Invoice, { description: 'To void an invoice, with the reason' })\n voidInvoice(@Arg('id') id: string, @Arg('reason') reason: string, @Ctx() context: ResolverContext) {\n const { tx, domain, user } = context.state\n return transitionInvoice(tx, domain, user, id, 'VOID', reason)\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { User } from '@things-factory/auth-base';
|
|
2
|
+
import { Domain, ListParam } from '@things-factory/shell';
|
|
3
|
+
import { InvoiceEvent } from '../invoice-event/invoice-event';
|
|
4
|
+
import { InvoiceItem } from '../invoice-item/invoice-item';
|
|
5
|
+
import { Invoice } from './invoice';
|
|
6
|
+
import { InvoiceList } from './invoice-type';
|
|
7
|
+
export declare class InvoiceQuery {
|
|
8
|
+
invoice(id: string, context: ResolverContext): Promise<Invoice>;
|
|
9
|
+
invoices(params: ListParam, context: ResolverContext): Promise<InvoiceList>;
|
|
10
|
+
invoiceEvents(invoiceId: string, context: ResolverContext): Promise<InvoiceEvent[]>;
|
|
11
|
+
items(invoice: Invoice): Promise<InvoiceItem[]>;
|
|
12
|
+
taxGroups(invoice: Invoice): Promise<import("./invoice-rules").TaxGroup[]>;
|
|
13
|
+
domain(row: Invoice): Domain | Promise<Domain>;
|
|
14
|
+
creator(row: Invoice): User | Promise<User>;
|
|
15
|
+
updater(row: Invoice): User | Promise<User>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvoiceQuery = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const auth_base_1 = require("@things-factory/auth-base");
|
|
6
|
+
const shell_1 = require("@things-factory/shell");
|
|
7
|
+
const type_graphql_1 = require("type-graphql");
|
|
8
|
+
const invoice_event_1 = require("../invoice-event/invoice-event");
|
|
9
|
+
const invoice_item_1 = require("../invoice-item/invoice-item");
|
|
10
|
+
const commercial_document_1 = require("./commercial-document");
|
|
11
|
+
const invoice_1 = require("./invoice");
|
|
12
|
+
const invoice_rules_1 = require("./invoice-rules");
|
|
13
|
+
const invoice_type_1 = require("./invoice-type");
|
|
14
|
+
let InvoiceQuery = class InvoiceQuery {
|
|
15
|
+
invoice(id, context) {
|
|
16
|
+
return (0, shell_1.getRepository)(invoice_1.Invoice).findOne({ where: { id, domain: { id: context.state.domain.id } } });
|
|
17
|
+
}
|
|
18
|
+
async invoices(params, context) {
|
|
19
|
+
const query = (0, shell_1.getQueryBuilderFromListParams)({
|
|
20
|
+
domain: context.state.domain,
|
|
21
|
+
params,
|
|
22
|
+
repository: (0, shell_1.getRepository)(invoice_1.Invoice),
|
|
23
|
+
searchables: ['number', 'supplierName', 'buyerName', 'purchaseOrder', 'notes']
|
|
24
|
+
});
|
|
25
|
+
const [items, total] = await query.getManyAndCount();
|
|
26
|
+
return { items, total };
|
|
27
|
+
}
|
|
28
|
+
invoiceEvents(invoiceId, context) {
|
|
29
|
+
return (0, shell_1.getRepository)(invoice_event_1.InvoiceEvent).find({
|
|
30
|
+
where: { domain: { id: context.state.domain.id }, invoice: { id: invoiceId } },
|
|
31
|
+
order: { createdAt: 'ASC' }
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async items(invoice) {
|
|
35
|
+
return invoice.items ?? (0, shell_1.getRepository)(invoice_item_1.InvoiceItem).find({ where: { invoice: { id: invoice.id } }, order: { position: 'ASC' } });
|
|
36
|
+
}
|
|
37
|
+
async taxGroups(invoice) {
|
|
38
|
+
return (0, invoice_rules_1.taxGroupsOf)({ ...invoice, items: await this.items(invoice) });
|
|
39
|
+
}
|
|
40
|
+
domain(row) {
|
|
41
|
+
return row.domain ?? (row.domainId ? (0, shell_1.getRepository)(shell_1.Domain).findOneBy({ id: row.domainId }) : undefined);
|
|
42
|
+
}
|
|
43
|
+
creator(row) {
|
|
44
|
+
return row.creator ?? (row.creatorId ? (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: row.creatorId }) : undefined);
|
|
45
|
+
}
|
|
46
|
+
updater(row) {
|
|
47
|
+
return row.updater ?? (row.updaterId ? (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: row.updaterId }) : undefined);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
exports.InvoiceQuery = InvoiceQuery;
|
|
51
|
+
tslib_1.__decorate([
|
|
52
|
+
(0, type_graphql_1.Directive)('@privilege(category: "invoice", privilege: "query", domainOwnerGranted: true)'),
|
|
53
|
+
(0, type_graphql_1.Query)(type => invoice_1.Invoice, { nullable: true, description: 'To fetch an invoice' }),
|
|
54
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
55
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
56
|
+
tslib_1.__metadata("design:type", Function),
|
|
57
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
58
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
59
|
+
], InvoiceQuery.prototype, "invoice", null);
|
|
60
|
+
tslib_1.__decorate([
|
|
61
|
+
(0, type_graphql_1.Directive)('@privilege(category: "invoice", privilege: "query", domainOwnerGranted: true)'),
|
|
62
|
+
(0, type_graphql_1.Query)(type => invoice_type_1.InvoiceList, { description: 'To fetch a page of invoices' }),
|
|
63
|
+
tslib_1.__param(0, (0, type_graphql_1.Args)(type => shell_1.ListParam)),
|
|
64
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
65
|
+
tslib_1.__metadata("design:type", Function),
|
|
66
|
+
tslib_1.__metadata("design:paramtypes", [shell_1.ListParam, Object]),
|
|
67
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
68
|
+
], InvoiceQuery.prototype, "invoices", null);
|
|
69
|
+
tslib_1.__decorate([
|
|
70
|
+
(0, type_graphql_1.Directive)('@privilege(category: "invoice", privilege: "query", domainOwnerGranted: true)'),
|
|
71
|
+
(0, type_graphql_1.Query)(type => [invoice_event_1.InvoiceEvent], { description: 'To fetch what happened to an invoice, oldest first' }),
|
|
72
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('invoiceId')),
|
|
73
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
74
|
+
tslib_1.__metadata("design:type", Function),
|
|
75
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
76
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
77
|
+
], InvoiceQuery.prototype, "invoiceEvents", null);
|
|
78
|
+
tslib_1.__decorate([
|
|
79
|
+
(0, type_graphql_1.FieldResolver)(type => [invoice_item_1.InvoiceItem]),
|
|
80
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
81
|
+
tslib_1.__metadata("design:type", Function),
|
|
82
|
+
tslib_1.__metadata("design:paramtypes", [invoice_1.Invoice]),
|
|
83
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
84
|
+
], InvoiceQuery.prototype, "items", null);
|
|
85
|
+
tslib_1.__decorate([
|
|
86
|
+
(0, type_graphql_1.FieldResolver)(type => [commercial_document_1.DocumentTaxGroup]),
|
|
87
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
88
|
+
tslib_1.__metadata("design:type", Function),
|
|
89
|
+
tslib_1.__metadata("design:paramtypes", [invoice_1.Invoice]),
|
|
90
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
91
|
+
], InvoiceQuery.prototype, "taxGroups", null);
|
|
92
|
+
tslib_1.__decorate([
|
|
93
|
+
(0, type_graphql_1.FieldResolver)(type => shell_1.Domain, { nullable: true }),
|
|
94
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
95
|
+
tslib_1.__metadata("design:type", Function),
|
|
96
|
+
tslib_1.__metadata("design:paramtypes", [invoice_1.Invoice]),
|
|
97
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
98
|
+
], InvoiceQuery.prototype, "domain", null);
|
|
99
|
+
tslib_1.__decorate([
|
|
100
|
+
(0, type_graphql_1.FieldResolver)(type => auth_base_1.User, { nullable: true }),
|
|
101
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
102
|
+
tslib_1.__metadata("design:type", Function),
|
|
103
|
+
tslib_1.__metadata("design:paramtypes", [invoice_1.Invoice]),
|
|
104
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
105
|
+
], InvoiceQuery.prototype, "creator", null);
|
|
106
|
+
tslib_1.__decorate([
|
|
107
|
+
(0, type_graphql_1.FieldResolver)(type => auth_base_1.User, { nullable: true }),
|
|
108
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
109
|
+
tslib_1.__metadata("design:type", Function),
|
|
110
|
+
tslib_1.__metadata("design:paramtypes", [invoice_1.Invoice]),
|
|
111
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
112
|
+
], InvoiceQuery.prototype, "updater", null);
|
|
113
|
+
exports.InvoiceQuery = InvoiceQuery = tslib_1.__decorate([
|
|
114
|
+
(0, type_graphql_1.UseMiddleware)(shell_1.SpeakRefusals),
|
|
115
|
+
(0, type_graphql_1.Resolver)(invoice_1.Invoice)
|
|
116
|
+
], InvoiceQuery);
|
|
117
|
+
//# sourceMappingURL=invoice-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoice-query.js","sourceRoot":"","sources":["../../../server/service/invoice/invoice-query.ts"],"names":[],"mappings":";;;;AAAA,yDAAgD;AAChD,iDAAsH;AACtH,+CAA6G;AAE7G,kEAA6D;AAC7D,+DAA0D;AAC1D,+DAAwD;AACxD,uCAAmC;AACnC,mDAA6C;AAC7C,iDAA4C;AAIrC,IAAM,YAAY,GAAlB,MAAM,YAAY;IAGvB,OAAO,CAAY,EAAU,EAAS,OAAwB;QAC5D,OAAO,IAAA,qBAAa,EAAC,iBAAO,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;IACnG,CAAC;IAIK,A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AAa,EAAC,qBAAa,CAAC;IAC5B,IAAA,uBAAQ,EAAC,iBAAO,CAAC;GACL,YAAY,CAqDxB","sourcesContent":["import { User } from '@things-factory/auth-base'\nimport { Domain, getQueryBuilderFromListParams, getRepository, ListParam, SpeakRefusals } from '@things-factory/shell'\nimport { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root, UseMiddleware } from 'type-graphql'\n\nimport { InvoiceEvent } from '../invoice-event/invoice-event'\nimport { InvoiceItem } from '../invoice-item/invoice-item'\nimport { DocumentTaxGroup } from './commercial-document'\nimport { Invoice } from './invoice'\nimport { taxGroupsOf } from './invoice-rules'\nimport { InvoiceList } from './invoice-type'\n\n@UseMiddleware(SpeakRefusals)\n@Resolver(Invoice)\nexport class InvoiceQuery {\n @Directive('@privilege(category: \"invoice\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(type => Invoice, { nullable: true, description: 'To fetch an invoice' })\n invoice(@Arg('id') id: string, @Ctx() context: ResolverContext) {\n return getRepository(Invoice).findOne({ where: { id, domain: { id: context.state.domain.id } } })\n }\n\n @Directive('@privilege(category: \"invoice\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(type => InvoiceList, { description: 'To fetch a page of invoices' })\n async invoices(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<InvoiceList> {\n const query = getQueryBuilderFromListParams({\n domain: context.state.domain,\n params,\n repository: getRepository(Invoice),\n searchables: ['number', 'supplierName', 'buyerName', 'purchaseOrder', 'notes']\n })\n const [items, total] = await query.getManyAndCount()\n return { items, total }\n }\n\n @Directive('@privilege(category: \"invoice\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(type => [InvoiceEvent], { description: 'To fetch what happened to an invoice, oldest first' })\n invoiceEvents(@Arg('invoiceId') invoiceId: string, @Ctx() context: ResolverContext) {\n return getRepository(InvoiceEvent).find({\n where: { domain: { id: context.state.domain.id }, invoice: { id: invoiceId } },\n order: { createdAt: 'ASC' }\n })\n }\n\n @FieldResolver(type => [InvoiceItem])\n async items(@Root() invoice: Invoice) {\n return invoice.items ?? getRepository(InvoiceItem).find({ where: { invoice: { id: invoice.id } }, order: { position: 'ASC' } })\n }\n\n @FieldResolver(type => [DocumentTaxGroup])\n async taxGroups(@Root() invoice: Invoice) {\n return taxGroupsOf({ ...invoice, items: await this.items(invoice) })\n }\n\n @FieldResolver(type => Domain, { nullable: true })\n domain(@Root() row: Invoice) {\n return row.domain ?? (row.domainId ? getRepository(Domain).findOneBy({ id: row.domainId }) : undefined)\n }\n\n @FieldResolver(type => User, { nullable: true })\n creator(@Root() row: Invoice) {\n return row.creator ?? (row.creatorId ? getRepository(User).findOneBy({ id: row.creatorId }) : undefined)\n }\n\n @FieldResolver(type => User, { nullable: true })\n updater(@Root() row: Invoice) {\n return row.updater ?? (row.updaterId ? getRepository(User).findOneBy({ id: row.updaterId }) : undefined)\n }\n}\n"]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export declare enum TaxKind {
|
|
2
|
+
TAXABLE = "TAXABLE",
|
|
3
|
+
ZERO_RATED = "ZERO_RATED",
|
|
4
|
+
EXEMPT = "EXEMPT"
|
|
5
|
+
}
|
|
6
|
+
/** How a document's tax was rounded — written onto the document when it is issued or sent. */
|
|
7
|
+
export declare const TAX_ROUNDING = "HALF_UP";
|
|
8
|
+
export declare const MAX_LINES = 500;
|
|
9
|
+
export interface LineValues {
|
|
10
|
+
description: string;
|
|
11
|
+
quantity: number;
|
|
12
|
+
unitPrice: number;
|
|
13
|
+
discount: number;
|
|
14
|
+
taxKind: TaxKind | string;
|
|
15
|
+
taxRate: number;
|
|
16
|
+
/** The tax the sender printed on the line — only on a received document. */
|
|
17
|
+
receivedTaxAmount?: number | null;
|
|
18
|
+
}
|
|
19
|
+
export interface TaxGroup {
|
|
20
|
+
taxKind: string;
|
|
21
|
+
taxRate: number;
|
|
22
|
+
supplyAmount: number;
|
|
23
|
+
taxAmount: number;
|
|
24
|
+
}
|
|
25
|
+
export declare function validDay(day: string): boolean;
|
|
26
|
+
export declare function currencyDigits(currency: string): number;
|
|
27
|
+
/**
|
|
28
|
+
* The supply of each line, the tax of each (kind, rate) group and the document totals. `received` keeps the line tax
|
|
29
|
+
* the sender printed; otherwise lines carry no tax and the groups reckon it.
|
|
30
|
+
*/
|
|
31
|
+
export declare function calculateDocument(lines: readonly LineValues[], currency: string, received?: boolean): {
|
|
32
|
+
items: {
|
|
33
|
+
description: any;
|
|
34
|
+
quantity: any;
|
|
35
|
+
unitPrice: any;
|
|
36
|
+
discount: any;
|
|
37
|
+
taxKind: TaxKind;
|
|
38
|
+
taxRate: any;
|
|
39
|
+
supplyAmount: number;
|
|
40
|
+
receivedTaxAmount: number;
|
|
41
|
+
position: number;
|
|
42
|
+
}[];
|
|
43
|
+
taxGroups: TaxGroup[];
|
|
44
|
+
supplyAmount: number;
|
|
45
|
+
taxAmount: number;
|
|
46
|
+
totalAmount: number;
|
|
47
|
+
};
|
|
48
|
+
/** The groups of a saved document, read back from its lines. */
|
|
49
|
+
export declare function taxGroupsOf(document: {
|
|
50
|
+
currency: string;
|
|
51
|
+
taxBasis?: string;
|
|
52
|
+
items?: readonly LineValues[];
|
|
53
|
+
}): TaxGroup[];
|
|
54
|
+
/** The fields every commercial document prints in its head, in the order the snapshot keeps them. */
|
|
55
|
+
export declare const HEADER_KEYS: readonly ["number", "direction", "currency", "language", "supplierName", "buyerName", "issueDate", "supplierAddress", "supplierRegistrationNumber", "buyerAddress", "buyerRegistrationNumber", "purchaseOrder", "paymentTerms", "bankDetails", "notes", "sourceReference"];
|
|
56
|
+
/** The head of a document, trimmed and checked. */
|
|
57
|
+
export declare function normalizedHeader(input: Record<string, any>): {
|
|
58
|
+
number: string;
|
|
59
|
+
currency: string;
|
|
60
|
+
direction: any;
|
|
61
|
+
language: any;
|
|
62
|
+
supplierName: any;
|
|
63
|
+
buyerName: any;
|
|
64
|
+
issueDate: any;
|
|
65
|
+
supplierAddress: any;
|
|
66
|
+
supplierRegistrationNumber: any;
|
|
67
|
+
buyerAddress: any;
|
|
68
|
+
buyerRegistrationNumber: any;
|
|
69
|
+
purchaseOrder: any;
|
|
70
|
+
paymentTerms: any;
|
|
71
|
+
bankDetails: any;
|
|
72
|
+
notes: any;
|
|
73
|
+
sourceReference: any;
|
|
74
|
+
};
|
|
75
|
+
export declare function requireDraft(status: string): void;
|
|
76
|
+
/** How much of a total is paid, in the currency's minor unit. */
|
|
77
|
+
export declare function settlement(total: number, paid: number, currency?: string): {
|
|
78
|
+
paidAmount: number;
|
|
79
|
+
remainingAmount: number;
|
|
80
|
+
paymentStatus: string;
|
|
81
|
+
};
|
|
82
|
+
/** The calendar day in a timezone. */
|
|
83
|
+
export declare function calendarDay(timezone: string, now?: Date): string;
|