@things-factory/worksheet-base 3.8.28 → 3.8.29

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.
@@ -7,6 +7,7 @@ exports.TEMPLATE_TYPE = {
7
7
  GRN_TEMPLATE: 'GRN_TEMPLATE',
8
8
  JOB_TEMPLATE: 'JOB_TEMPLATE',
9
9
  MANIFEST_TEMPLATE: 'MANIFEST_TEMPLATE',
10
+ INVOICE_TEMPLATE: 'INVOICE_TEMPLATE',
10
11
  COP: 'COP',
11
12
  SIGNATURE: 'SIGNATURE',
12
13
  LOGO: 'LOGO'
@@ -1 +1 @@
1
- {"version":3,"file":"template.js","sourceRoot":"","sources":["../../server/constants/template.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG;IAC3B,WAAW,EAAE,aAAa;IAC1B,WAAW,EAAE,aAAa;IAC1B,YAAY,EAAE,cAAc;IAC5B,YAAY,EAAE,cAAc;IAC5B,iBAAiB,EAAE,mBAAmB;IACtC,GAAG,EAAE,KAAK;IACV,SAAS,EAAE,WAAW;IACtB,IAAI,EAAE,MAAM;CACb,CAAA"}
1
+ {"version":3,"file":"template.js","sourceRoot":"","sources":["../../server/constants/template.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG;IAC3B,WAAW,EAAE,aAAa;IAC1B,WAAW,EAAE,aAAa;IAC1B,YAAY,EAAE,cAAc;IAC5B,YAAY,EAAE,cAAc;IAC5B,iBAAiB,EAAE,mBAAmB;IACtC,gBAAgB,EAAE,kBAAkB;IACpC,GAAG,EAAE,KAAK;IACV,SAAS,EAAE,WAAW;IACtB,IAAI,EAAE,MAAM;CACb,CAAA"}
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.renderInvoices = void 0;
7
+ const form_data_1 = __importDefault(require("form-data"));
8
+ const node_fetch_1 = __importDefault(require("node-fetch"));
9
+ const typeorm_1 = require("typeorm");
10
+ const attachment_base_1 = require("@things-factory/attachment-base");
11
+ const env_1 = require("@things-factory/env");
12
+ const sales_base_1 = require("@things-factory/sales-base");
13
+ const shell_1 = require("@things-factory/shell");
14
+ const constants_1 = require("../constants");
15
+ const datetime_util_1 = require("../utils/datetime-util");
16
+ const REPORT_API_URL = env_1.config.get('reportApiUrl', 'http://localhost:8888/rest/report/show_html');
17
+ async function renderInvoices({ req, timezoneOffSet }, context) {
18
+ try {
19
+ const domain = await (0, typeorm_1.getRepository)(shell_1.Domain).findOne({
20
+ where: { id: context.state.domain.id }
21
+ });
22
+ let result = await Promise.all(req.roIds.map(async (roId) => {
23
+ try {
24
+ const foundReleaseGoods = await (0, typeorm_1.getRepository)(sales_base_1.ReleaseGood).findOne({
25
+ where: { domain, id: roId },
26
+ relations: ['domain', 'bizplace', 'bizplace.domain', 'bizplace.company', 'bizplace.company.domain']
27
+ });
28
+ if (foundReleaseGoods) {
29
+ const foundInvoice = await (0, typeorm_1.getRepository)(sales_base_1.Invoice).findOne({
30
+ where: { releaseGood: foundReleaseGoods },
31
+ relations: ['invoiceProducts', 'invoiceProducts.product', 'domain', 'creator', 'updater']
32
+ });
33
+ const partnerBiz = foundReleaseGoods.bizplace;
34
+ const partnerCompanyDomain = foundReleaseGoods.bizplace.company.domain;
35
+ const foundTemplate = await (0, typeorm_1.getRepository)(attachment_base_1.Attachment).findOne({
36
+ where: { domain: partnerCompanyDomain, category: constants_1.TEMPLATE_TYPE.INVOICE_TEMPLATE }
37
+ });
38
+ const template = await attachment_base_1.STORAGE.readFile(foundTemplate.path, 'utf-8');
39
+ let fullBillingAddress = [
40
+ foundInvoice.billingAddress1,
41
+ foundInvoice.billingAddress2,
42
+ foundInvoice.billingAddress3,
43
+ foundInvoice.billingAddress4,
44
+ foundInvoice.billingAddress5
45
+ ];
46
+ let fullDeliveryAddress = [
47
+ foundInvoice.deliveryAddress1,
48
+ foundInvoice.deliveryAddress2,
49
+ foundInvoice.deliveryAddress3,
50
+ foundInvoice.deliveryAddress4,
51
+ foundInvoice.deliveryAddress5,
52
+ ];
53
+ let date = datetime_util_1.DateTimeConverter.date(new Date((foundInvoice.issuedOn || foundInvoice.createdAt) - timezoneOffSet));
54
+ const data = {
55
+ order_no: foundReleaseGoods.name,
56
+ ref_no: foundReleaseGoods.refNo,
57
+ deliver_to: foundInvoice.deliverTo,
58
+ deliver_to_phone: foundInvoice.deliverToPhone || '',
59
+ bill_to: foundInvoice.billTo,
60
+ bill_to_phone: foundInvoice.billToPhone || '',
61
+ customer_address: partnerBiz.address,
62
+ delivery_date: date,
63
+ store_name: foundInvoice.from,
64
+ billing_address_1: foundInvoice.billingAddress1,
65
+ billing_address_2: foundInvoice.billingAddress2,
66
+ billing_address_3: foundInvoice.billingAddress3,
67
+ billing_address_4: foundInvoice.billingAddress4,
68
+ billing_address_5: foundInvoice.billingAddress5,
69
+ billing_postcode: foundInvoice.billingPostcode,
70
+ billing_city: foundInvoice.billingCity,
71
+ billing_state: foundInvoice.billingState,
72
+ billing_country: foundInvoice.billingCountry,
73
+ full_billing_address: fullBillingAddress.reduce((acc, itm) => {
74
+ if (itm && itm.trim() != '') {
75
+ acc.push(itm);
76
+ }
77
+ return acc;
78
+ }, []).join(' '),
79
+ delivery_address_1: foundInvoice.deliveryAddress1,
80
+ delivery_address_2: foundInvoice.deliveryAddress2,
81
+ delivery_address_3: foundInvoice.deliveryAddress3,
82
+ delivery_address_4: foundInvoice.deliveryAddress4,
83
+ delivery_address_5: foundInvoice.deliveryAddress5,
84
+ delivery_postcode: foundInvoice.deliveryPostcode,
85
+ delivery_city: foundInvoice.deliveryCity,
86
+ delivery_state: foundInvoice.deliveryState,
87
+ delivery_country: foundInvoice.deliveryCountry,
88
+ full_delivery_address: fullDeliveryAddress.reduce((acc, itm) => {
89
+ if (itm && itm.trim() != '') {
90
+ acc.push(itm);
91
+ }
92
+ return acc;
93
+ }, []).join(' '),
94
+ product_list: foundInvoice.invoiceProducts.map((item, idx) => {
95
+ return {
96
+ list_no: idx + 1,
97
+ product_sku: item.sku,
98
+ product_name: item.name,
99
+ product_desc: item.description,
100
+ product_qty: item.qty,
101
+ product_other_charges: item.otherCharges,
102
+ product_paid_price: parseFloat(item.paidPrice || item.unitPrice).toFixed(2),
103
+ product_unit_price: parseFloat(item.unitPrice).toFixed(2),
104
+ product_total_paid_price: (parseFloat(item.paidPrice || item.unitPrice) * parseFloat(item.qty)).toFixed(2),
105
+ product_total_unit_price: (parseFloat(item.unitPrice) * parseFloat(item.qty)).toFixed(2)
106
+ };
107
+ })
108
+ };
109
+ const formData = new form_data_1.default();
110
+ formData.append('template', template);
111
+ formData.append('jsonString', JSON.stringify(data));
112
+ const response = await (0, node_fetch_1.default)(REPORT_API_URL, {
113
+ method: 'POST',
114
+ body: formData
115
+ });
116
+ return await response.text();
117
+ }
118
+ return '';
119
+ }
120
+ catch (ex) {
121
+ return '';
122
+ }
123
+ }));
124
+ if (result.length <= 0) {
125
+ throw Error('No invoice found!');
126
+ }
127
+ return result.join();
128
+ }
129
+ catch (ex) {
130
+ throw ex;
131
+ }
132
+ }
133
+ exports.renderInvoices = renderInvoices;
134
+ //# sourceMappingURL=render-invoices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-invoices.js","sourceRoot":"","sources":["../../server/controllers/render-invoices.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAgC;AAChC,4DAA8B;AAC9B,qCAAoD;AAEpD,qEAAqE;AAGrE,6CAA4C;AAC5C,2DAA+I;AAC/I,iDAA8C;AAG9C,4CAA4D;AAE5D,0DAA0D;AAE1D,MAAM,cAAc,GAAG,YAAM,CAAC,GAAG,CAAC,cAAc,EAAE,6CAA6C,CAAC,CAAA;AAEzF,KAAK,UAAU,cAAc,CAAC,EAAE,GAAG,EAAE,cAAc,EAAE,EAAE,OAAY;IACtE,IAAI;QACA,MAAM,MAAM,GAAW,MAAM,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K,CAAC,mBAAmB,CAAC,CAAA;SACnC;QACD,OAAO,MAAM,CAAC,IAAI,EAAE,CAAA;KACvB;IAAC,OAAO,EAAE,EAAE;QACT,MAAM,EAAE,CAAA;KACX;AACL,CAAC;AAjID,wCAiIC"}
@@ -10,6 +10,7 @@ const render_orientage_do_1 = require("./controllers/render-orientage-do");
10
10
  const render_orientage_grn_1 = require("./controllers/render-orientage-grn");
11
11
  const render_ro_do_1 = require("./controllers/render-ro-do");
12
12
  const render_seebuu_grn_1 = require("./controllers/render-seebuu-grn");
13
+ const render_invoices_1 = require("./controllers/render-invoices");
13
14
  process.on('bootstrap-module-domain-private-route', (app, routes) => {
14
15
  routes.get('/view_document_ro_do/:doNo', async (context, next) => {
15
16
  context.body = await (0, render_ro_do_1.renderRODO)(context.params, context);
@@ -41,5 +42,12 @@ process.on('bootstrap-module-domain-private-route', (app, routes) => {
41
42
  routes.get('/view_manifest/:manifestNo', async (context, next) => {
42
43
  context.body = await (0, render_manifest_1.renderManifest)(context.params, context);
43
44
  });
45
+ routes.post('/view_invoices/:timezoneOffSet', async (context, next) => {
46
+ let req = context.request.body || {};
47
+ let timezoneOffSet = context.params.timezoneOffSet || 0;
48
+ let data = await (0, render_invoices_1.renderInvoices)({ req, timezoneOffSet }, context);
49
+ context.type = 'application/json';
50
+ context.body = data;
51
+ });
44
52
  });
45
53
  //# sourceMappingURL=routes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"routes.js","sourceRoot":"","sources":["../server/routes.ts"],"names":[],"mappings":";;AAAA,qEAA+D;AAC/D,yDAAoD;AACpD,qEAA+D;AAC/D,uEAAiE;AACjE,mEAA8D;AAC9D,qEAA+D;AAC/D,2EAAqE;AACrE,6EAAuE;AACvE,6DAAuD;AACvD,uEAAiE;AAEjE,OAAO,CAAC,EAAE,CAAC,uCAA8C,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;IACzE,MAAM,CAAC,GAAG,CAAC,4BAA4B,EAAE,KAAK,EAAE,OA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ACJ,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/worksheet-base",
3
- "version": "3.8.28",
3
+ "version": "3.8.29",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -25,20 +25,20 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@things-factory/auth-base": "^3.8.0",
28
- "@things-factory/biz-base": "^3.8.26",
29
- "@things-factory/document-template-base": "^3.8.0",
28
+ "@things-factory/biz-base": "^3.8.29",
29
+ "@things-factory/document-template-base": "^3.8.29",
30
30
  "@things-factory/id-rule-base": "^3.8.0",
31
- "@things-factory/integration-lmd": "^3.8.26",
32
- "@things-factory/integration-marketplace": "^3.8.28",
33
- "@things-factory/integration-sellercraft": "^3.8.28",
34
- "@things-factory/integration-sftp": "^3.8.26",
35
- "@things-factory/marketplace-base": "^3.8.28",
31
+ "@things-factory/integration-lmd": "^3.8.29",
32
+ "@things-factory/integration-marketplace": "^3.8.29",
33
+ "@things-factory/integration-sellercraft": "^3.8.29",
34
+ "@things-factory/integration-sftp": "^3.8.29",
35
+ "@things-factory/marketplace-base": "^3.8.29",
36
36
  "@things-factory/notification": "^3.8.0",
37
- "@things-factory/sales-base": "^3.8.28",
37
+ "@things-factory/sales-base": "^3.8.29",
38
38
  "@things-factory/setting-base": "^3.8.0",
39
39
  "@things-factory/shell": "^3.8.0",
40
- "@things-factory/transport-base": "^3.8.26",
41
- "@things-factory/warehouse-base": "^3.8.28"
40
+ "@things-factory/transport-base": "^3.8.29",
41
+ "@things-factory/warehouse-base": "^3.8.29"
42
42
  },
43
- "gitHead": "8bc0e8adad38cec375d701d66f2f198bceafd644"
43
+ "gitHead": "aab48875c1a169b2d75f9fe8aa6af029c3d5b3dd"
44
44
  }
@@ -4,6 +4,7 @@ export const TEMPLATE_TYPE = {
4
4
  GRN_TEMPLATE: 'GRN_TEMPLATE',
5
5
  JOB_TEMPLATE: 'JOB_TEMPLATE',
6
6
  MANIFEST_TEMPLATE: 'MANIFEST_TEMPLATE',
7
+ INVOICE_TEMPLATE: 'INVOICE_TEMPLATE',
7
8
  COP: 'COP',
8
9
  SIGNATURE: 'SIGNATURE',
9
10
  LOGO: 'LOGO'
@@ -0,0 +1,148 @@
1
+ import FormData from 'form-data'
2
+ import fetch from 'node-fetch'
3
+ import { getRepository, IsNull, Not } from 'typeorm'
4
+
5
+ import { Attachment, STORAGE } from '@things-factory/attachment-base'
6
+ import { Partner } from '@things-factory/auth-base'
7
+ import { Bizplace, Company, ContactPoint } from '@things-factory/biz-base'
8
+ import { config } from '@things-factory/env'
9
+ import { ArrivalNotice, GoodsReceivalNote, ORDER_STATUS, OrderProduct, ReleaseGood, Invoice, InvoiceProduct } from '@things-factory/sales-base'
10
+ import { Domain } from '@things-factory/shell'
11
+ import { ReducedInventoryHistory } from '@things-factory/warehouse-base'
12
+
13
+ import { TEMPLATE_TYPE, WORKSHEET_TYPE } from '../constants'
14
+ import { Worksheet } from '../entities'
15
+ import { DateTimeConverter } from '../utils/datetime-util'
16
+
17
+ const REPORT_API_URL = config.get('reportApiUrl', 'http://localhost:8888/rest/report/show_html')
18
+
19
+ export async function renderInvoices({ req, timezoneOffSet }, context: any) {
20
+ try {
21
+ const domain: Domain = await getRepository(Domain).findOne({
22
+ where: { id: context.state.domain.id }
23
+ })
24
+
25
+ let result = await Promise.all(req.roIds.map(async roId => {
26
+ try {
27
+ const foundReleaseGoods: ReleaseGood = await getRepository(ReleaseGood).findOne({
28
+ where: { domain, id: roId },
29
+ relations: ['domain', 'bizplace', 'bizplace.domain', 'bizplace.company', 'bizplace.company.domain']
30
+ })
31
+
32
+ if (foundReleaseGoods) {
33
+ const foundInvoice: Invoice = await getRepository(Invoice).findOne({
34
+ where: { releaseGood: foundReleaseGoods },
35
+ relations: ['invoiceProducts', 'invoiceProducts.product', 'domain', 'creator', 'updater']
36
+ })
37
+
38
+ const partnerBiz: Bizplace = foundReleaseGoods.bizplace
39
+
40
+ const partnerCompanyDomain: Domain = foundReleaseGoods.bizplace.company.domain
41
+
42
+ const foundTemplate: Attachment = await getRepository(Attachment).findOne({
43
+ where: { domain: partnerCompanyDomain, category: TEMPLATE_TYPE.INVOICE_TEMPLATE }
44
+ })
45
+
46
+ const template = await STORAGE.readFile(foundTemplate.path, 'utf-8')
47
+
48
+ let fullBillingAddress = [
49
+ foundInvoice.billingAddress1,
50
+ foundInvoice.billingAddress2,
51
+ foundInvoice.billingAddress3,
52
+ foundInvoice.billingAddress4,
53
+ foundInvoice.billingAddress5
54
+ ]
55
+
56
+ let fullDeliveryAddress = [
57
+ foundInvoice.deliveryAddress1,
58
+ foundInvoice.deliveryAddress2,
59
+ foundInvoice.deliveryAddress3,
60
+ foundInvoice.deliveryAddress4,
61
+ foundInvoice.deliveryAddress5,
62
+ ]
63
+
64
+ let date = DateTimeConverter.date(new Date((foundInvoice.issuedOn || foundInvoice.createdAt) - timezoneOffSet))
65
+ const data = {
66
+ order_no: foundReleaseGoods.name,
67
+ ref_no: foundReleaseGoods.refNo,
68
+ deliver_to: foundInvoice.deliverTo,
69
+ deliver_to_phone: foundInvoice.deliverToPhone || '',
70
+ bill_to: foundInvoice.billTo,
71
+ bill_to_phone: foundInvoice.billToPhone || '',
72
+ customer_address: partnerBiz.address,
73
+ delivery_date: date,
74
+ store_name: foundInvoice.from,
75
+ billing_address_1: foundInvoice.billingAddress1,
76
+ billing_address_2: foundInvoice.billingAddress2,
77
+ billing_address_3: foundInvoice.billingAddress3,
78
+ billing_address_4: foundInvoice.billingAddress4,
79
+ billing_address_5: foundInvoice.billingAddress5,
80
+ billing_postcode: foundInvoice.billingPostcode,
81
+ billing_city: foundInvoice.billingCity,
82
+ billing_state: foundInvoice.billingState,
83
+ billing_country: foundInvoice.billingCountry,
84
+ full_billing_address: fullBillingAddress.reduce((acc, itm) => {
85
+ if (itm && itm.trim() != '') {
86
+ acc.push(itm)
87
+ }
88
+
89
+ return acc
90
+ }, []).join(' '),
91
+ delivery_address_1: foundInvoice.deliveryAddress1,
92
+ delivery_address_2: foundInvoice.deliveryAddress2,
93
+ delivery_address_3: foundInvoice.deliveryAddress3,
94
+ delivery_address_4: foundInvoice.deliveryAddress4,
95
+ delivery_address_5: foundInvoice.deliveryAddress5,
96
+ delivery_postcode: foundInvoice.deliveryPostcode,
97
+ delivery_city: foundInvoice.deliveryCity,
98
+ delivery_state: foundInvoice.deliveryState,
99
+ delivery_country: foundInvoice.deliveryCountry,
100
+ full_delivery_address: fullDeliveryAddress.reduce((acc, itm) => {
101
+ if (itm && itm.trim() != '') {
102
+ acc.push(itm)
103
+ }
104
+
105
+ return acc
106
+ }, []).join(' '),
107
+ product_list: foundInvoice.invoiceProducts.map((item, idx) => {
108
+ return {
109
+ list_no: idx + 1,
110
+ product_sku: item.sku,
111
+ product_name: item.name,
112
+ product_desc: item.description,
113
+ product_qty: item.qty,
114
+ product_other_charges: item.otherCharges,
115
+ product_paid_price: parseFloat(item.paidPrice || item.unitPrice).toFixed(2),
116
+ product_unit_price: parseFloat(item.unitPrice).toFixed(2),
117
+ product_total_paid_price: (parseFloat(item.paidPrice || item.unitPrice) * parseFloat(item.qty)).toFixed(2),
118
+ product_total_unit_price: (parseFloat(item.unitPrice) * parseFloat(item.qty)).toFixed(2)
119
+ }
120
+ })
121
+ }
122
+
123
+ const formData = new FormData()
124
+ formData.append('template', template)
125
+ formData.append('jsonString', JSON.stringify(data))
126
+
127
+ const response = await fetch(REPORT_API_URL, {
128
+ method: 'POST',
129
+ body: formData
130
+ })
131
+
132
+ return await response.text()
133
+ }
134
+ return ''
135
+ } catch (ex) {
136
+ return ''
137
+ }
138
+ }))
139
+
140
+
141
+ if (result.length <= 0) {
142
+ throw Error('No invoice found!')
143
+ }
144
+ return result.join()
145
+ } catch (ex) {
146
+ throw ex
147
+ }
148
+ }
package/server/routes.ts CHANGED
@@ -8,6 +8,7 @@ import { renderOrientageDO } from './controllers/render-orientage-do'
8
8
  import { renderOrientageGRN } from './controllers/render-orientage-grn'
9
9
  import { renderRODO } from './controllers/render-ro-do'
10
10
  import { renderSeebuuGRN } from './controllers/render-seebuu-grn'
11
+ import { renderInvoices } from './controllers/render-invoices'
11
12
 
12
13
  process.on('bootstrap-module-domain-private-route' as any, (app, routes) => {
13
14
  routes.get('/view_document_ro_do/:doNo', async (context, next) => {
@@ -49,4 +50,14 @@ process.on('bootstrap-module-domain-private-route' as any, (app, routes) => {
49
50
  routes.get('/view_manifest/:manifestNo', async (context, next) => {
50
51
  context.body = await renderManifest(context.params, context)
51
52
  })
53
+
54
+ routes.post('/view_invoices/:timezoneOffSet', async (context, next) => {
55
+ let req = context.request.body || {}
56
+ let timezoneOffSet = context.params.timezoneOffSet || 0
57
+
58
+ let data = await renderInvoices({ req, timezoneOffSet }, context)
59
+
60
+ context.type = 'application/json'
61
+ context.body = data
62
+ })
52
63
  })