@things-factory/worksheet-base 4.3.815 → 4.3.817

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.
Files changed (39) hide show
  1. package/dist-server/controllers/index.js +0 -2
  2. package/dist-server/controllers/index.js.map +1 -1
  3. package/dist-server/controllers/render-elccl-grn.js +1 -1
  4. package/dist-server/controllers/render-fm-grn.js +1 -1
  5. package/dist-server/controllers/render-fm-grn.js.map +1 -1
  6. package/dist-server/controllers/render-grn.js +2 -2
  7. package/dist-server/controllers/render-grn.js.map +1 -1
  8. package/dist-server/controllers/render-kimeda-grn.js +1 -1
  9. package/dist-server/controllers/render-kimeda-grn.js.map +1 -1
  10. package/dist-server/controllers/render-manual-do.js +1 -1
  11. package/dist-server/controllers/render-manual-do.js.map +1 -1
  12. package/dist-server/controllers/render-orientage-do.js +1 -1
  13. package/dist-server/controllers/render-orientage-do.js.map +1 -1
  14. package/dist-server/controllers/render-packing-label.js +2 -0
  15. package/dist-server/controllers/render-packing-label.js.map +1 -1
  16. package/dist-server/controllers/render-ro-do.js +11 -9
  17. package/dist-server/controllers/render-ro-do.js.map +1 -1
  18. package/dist-server/index.js +0 -2
  19. package/dist-server/index.js.map +1 -1
  20. package/dist-server/routes.js +0 -8
  21. package/dist-server/routes.js.map +1 -1
  22. package/package.json +3 -3
  23. package/server/controllers/index.ts +0 -2
  24. package/server/controllers/render-elccl-grn.ts +1 -1
  25. package/server/controllers/render-fm-grn.ts +1 -1
  26. package/server/controllers/render-grn.ts +2 -2
  27. package/server/controllers/render-kimeda-grn.ts +1 -1
  28. package/server/controllers/render-manual-do.ts +1 -1
  29. package/server/controllers/render-orientage-do.ts +1 -1
  30. package/server/controllers/render-packing-label.ts +2 -0
  31. package/server/controllers/render-ro-do.ts +11 -12
  32. package/server/index.ts +1 -3
  33. package/server/routes.ts +0 -10
  34. package/dist-server/controllers/render-orientage-grn.js +0 -158
  35. package/dist-server/controllers/render-orientage-grn.js.map +0 -1
  36. package/dist-server/controllers/render-seebuu-grn.js +0 -177
  37. package/dist-server/controllers/render-seebuu-grn.js.map +0 -1
  38. package/server/controllers/render-orientage-grn.ts +0 -178
  39. package/server/controllers/render-seebuu-grn.ts +0 -198
@@ -1,178 +0,0 @@
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, ContactPoint } from '@things-factory/biz-base'
8
- import { config } from '@things-factory/env'
9
- import { ProductDetail } from '@things-factory/product-base'
10
- import {
11
- ArrivalNotice,
12
- GoodsReceivalNote,
13
- ORDER_PRODUCT_STATUS,
14
- ORDER_STATUS,
15
- OrderProduct
16
- } from '@things-factory/sales-base'
17
- import { Domain } from '@things-factory/shell'
18
-
19
- import { TEMPLATE_TYPE } from '../constants'
20
- import { Worksheet } from '../entities'
21
- import { DateTimeConverter } from '../utils/datetime-util'
22
-
23
- const REPORT_API_URL = config.get('reportApiUrl', 'http://localhost:8888/rest/report/show_html')
24
-
25
- export async function renderOrientageGRN({ grnNo }, context: any) {
26
- // 1. find domain
27
- const domain: Domain = await getRepository(Domain).findOne({
28
- where: { id: context.state.domain.id }
29
- })
30
-
31
- // 2. find grn
32
- const foundGRN: GoodsReceivalNote = await getRepository(GoodsReceivalNote).findOne({
33
- where: { domain, name: grnNo },
34
- relations: ['domain', 'bizplace', 'bizplace.domain', 'bizplace.company', 'arrivalNotice']
35
- })
36
-
37
- // 3. find GAN
38
- const foundGAN: ArrivalNotice = foundGRN.arrivalNotice
39
- const ownRefNo = foundGAN.refNo
40
- const ownRefNo2 = foundGAN.refNo2
41
- const ownRefNo3 = foundGAN.refNo3
42
-
43
- // 4. find customer bizplace
44
- const partnerBiz: Bizplace = foundGRN.bizplace
45
-
46
- const partnerDomain: Partner = await getRepository(Partner).findOne({
47
- where: { partnerDomain: partnerBiz.domain, domain },
48
- relations: ['domain']
49
- })
50
-
51
- const domainOwner: Domain = partnerDomain.domain
52
- const domainBizplace: Bizplace = await getRepository(Bizplace).findOne({
53
- where: { domain: domainOwner },
54
- relations: ['company']
55
- })
56
-
57
- // 5. find domain contact point
58
- const foundCP: ContactPoint = await getRepository(ContactPoint).findOne({
59
- where: { domain, bizplace: domainBizplace }
60
- })
61
-
62
- // 6. find unloading worksheet
63
- const foundWS: Worksheet = await getRepository(Worksheet).findOne({
64
- where: { domain, arrivalNotice: foundGAN, type: ORDER_PRODUCT_STATUS.UNLOADING, status: ORDER_STATUS.DONE },
65
- relations: ['worksheetDetails']
66
- })
67
-
68
- const targetProducts: OrderProduct[] = await getRepository(OrderProduct).find({
69
- where: { domain, arrivalNotice: foundGAN, actualPalletQty: Not(IsNull()), actualPackQty: Not(IsNull()) },
70
- relations: ['product', 'product.productDetails']
71
- })
72
-
73
- // 7. find grn template based on category
74
- const foundTemplate: Attachment = await getRepository(Attachment).findOne({
75
- where: { domain, category: TEMPLATE_TYPE.GRN_TEMPLATE }
76
- })
77
-
78
- // 8. find grn logo
79
- const foundLogo: Attachment = await getRepository(Attachment).findOne({
80
- where: {
81
- domain,
82
- category: TEMPLATE_TYPE.LOGO
83
- }
84
- })
85
-
86
- const template = await STORAGE.readFile(foundTemplate.path, 'utf-8')
87
-
88
- let logo = null
89
- if (foundLogo?.path) {
90
- logo = 'data:' + foundLogo.mimetype + ';base64,' + (await STORAGE.readFile(foundLogo.path, 'base64'))
91
- }
92
-
93
- const data = {
94
- logo_url: logo,
95
- customer_biz: partnerBiz.name,
96
- customer_address: partnerBiz.address,
97
- company_name: domainBizplace.company.name,
98
- company_phone: foundCP.phone,
99
- company_fax: foundCP.fax,
100
- company_email: foundCP.email,
101
- company_brn: domainBizplace.company.brn,
102
- company_address: domainBizplace.company.address,
103
- order_no: foundGRN.name,
104
- unload_date: DateTimeConverter.date(foundWS.endedAt),
105
- ref_no: ownRefNo,
106
- ref_no1: ownRefNo2,
107
- ref_no2: ownRefNo3,
108
- received_date: DateTimeConverter.date(foundWS.endedAt),
109
- product_list: targetProducts.map((item, idx) => {
110
- const productDetails: ProductDetail[] = item.product.productDetails
111
- const matchedProductDetail: ProductDetail = productDetails.find(
112
- productDetail => productDetail.packingType === item.packingType
113
- )
114
- return {
115
- list_no: idx + 1,
116
- product_sku: item.product.sku,
117
- product_name: item.product.name,
118
- product_desc: item.product.description,
119
- expiration_date: item.expirationDate ? DateTimeConverter.date(item.expirationDate) : null,
120
- batch_id: item.batchId,
121
- batch_id_ref: item?.batchIdRef ? item.batchIdRef : '',
122
- product_packing_size: matchedProductDetail ? matchedProductDetail.packingSize : item.packingSize,
123
- pack_size: matchedProductDetail
124
- ? matchedProductDetail.uomValue
125
- ? matchedProductDetail.uomValue +
126
- ' ' +
127
- matchedProductDetail.uom +
128
- (item.product.volumeSize ? ' x ' + (parseFloat(item.product.volumeSize) / 100).toFixed(2) + ' L' : '')
129
- : null
130
- : item.product.primaryValue
131
- ? item.product.primaryValue +
132
- ' ' +
133
- item.product.primaryUnit +
134
- (item.product.volumeSize ? ' x ' + (parseFloat(item.product.volumeSize) / 100).toFixed(2) + ' L' : '')
135
- : null,
136
- pack_qty: item.packQty ? item.packQty : 0,
137
- actual_pack_qty: item.actualPackQty ? item.actualPackQty : 0,
138
- container_no: foundGAN.containerNo ? foundGAN.containerNo : '',
139
- aux_value_3: matchedProductDetail?.auxValue3 ? matchedProductDetail.auxValue3 : '',
140
- product_volume: matchedProductDetail
141
- ? matchedProductDetail?.volume
142
- ? matchedProductDetail.volume
143
- : 0
144
- : item?.product?.volume
145
- ? item.product.volume
146
- : 0,
147
- total_volume: matchedProductDetail
148
- ? matchedProductDetail.volume
149
- ? Number((matchedProductDetail.volume * item.actualPackQty).toFixed(4))
150
- : 0
151
- : item?.product?.volume
152
- ? Number((item.product.volume * item.actualPackQty).toFixed(4))
153
- : 0,
154
- manufacture_year: item.manufactureDate ? new Date(item.manufactureDate).getFullYear() : null,
155
- manufacture_date: item.manufactureDate ? item.manufactureDate : null,
156
- literage: matchedProductDetail
157
- ? matchedProductDetail.packingSize
158
- ? parseFloat(matchedProductDetail.packingSize) * parseFloat(item.product.volumeSize)
159
- : 0
160
- : item.packingSize
161
- ? parseFloat(item.packingSize) * parseFloat(item.product.volumeSize)
162
- : 0,
163
- remark: item.remark || ''
164
- }
165
- })
166
- }
167
-
168
- const formData = new FormData()
169
- formData.append('template', template)
170
- formData.append('jsonString', JSON.stringify(data))
171
-
172
- const response = await fetch(REPORT_API_URL, {
173
- method: 'POST',
174
- body: formData
175
- })
176
-
177
- return await response.text()
178
- }
@@ -1,198 +0,0 @@
1
- import FormData from 'form-data'
2
- import fetch from 'node-fetch'
3
- import { EntityManager, getManager, getRepository } from 'typeorm'
4
-
5
- import { Attachment, STORAGE } from '@things-factory/attachment-base'
6
- import { Partner } from '@things-factory/auth-base'
7
- import { Bizplace, ContactPoint } from '@things-factory/biz-base'
8
- import { config } from '@things-factory/env'
9
- import { ArrivalNotice, GoodsReceivalNote, ORDER_STATUS } from '@things-factory/sales-base'
10
- import { Domain } from '@things-factory/shell'
11
-
12
- import { TEMPLATE_TYPE, WORKSHEET_TYPE } from '../constants'
13
- import { Worksheet } from '../entities'
14
- import { DateTimeConverter } from '../utils/datetime-util'
15
-
16
- const REPORT_API_URL = config.get('reportApiUrl', 'http://localhost:8888/rest/report/show_html')
17
-
18
- export async function renderSeebuuGRN({ grnNo }, context: any) {
19
- // 1. find domain
20
- const domain: Domain = await getRepository(Domain).findOne({
21
- where: { id: context.state.domain.id }
22
- })
23
-
24
- // 2. find grn
25
- const foundGRN: GoodsReceivalNote = await getRepository(GoodsReceivalNote).findOne({
26
- where: { domain, name: grnNo },
27
- relations: ['domain', 'bizplace', 'bizplace.domain', 'bizplace.company', 'arrivalNotice']
28
- })
29
-
30
- // 3. find GAN
31
- const foundGAN: ArrivalNotice = foundGRN.arrivalNotice
32
-
33
- // 4. find customer bizplace
34
- const partnerBiz: Bizplace = foundGRN.bizplace
35
-
36
- const partnerDomain: Partner = await getRepository(Partner).findOne({
37
- where: { domain, partnerDomain: partnerBiz.domain },
38
- relations: ['domain']
39
- })
40
-
41
- const domainOwner: Domain = partnerDomain.domain
42
- const domainBizplace: Bizplace = await getRepository(Bizplace).findOne({
43
- where: { domain: domainOwner },
44
- relations: ['company']
45
- })
46
-
47
- // 5. find domain contact point
48
- const foundCP: ContactPoint = await getRepository(ContactPoint).findOne({
49
- where: { domain, bizplace: domainBizplace }
50
- })
51
-
52
- // 6. find unloading worksheet
53
- const foundWS: Worksheet = await getRepository(Worksheet).findOne({
54
- where: { domain, arrivalNotice: foundGAN, type: WORKSHEET_TYPE.UNLOADING, status: ORDER_STATUS.DONE },
55
- relations: ['worksheetDetails', 'updater']
56
- })
57
-
58
- // find putaway worksheet
59
- const foundPutawayWS: Worksheet = await getRepository(Worksheet).findOne({
60
- where: { domain, arrivalNotice: foundGAN, type: WORKSHEET_TYPE.PUTAWAY, status: ORDER_STATUS.DONE },
61
- relations: ['worksheetDetails', 'updater']
62
- })
63
-
64
- let invItems: any
65
-
66
- await getManager().transaction(async (trxMgr: EntityManager) => {
67
- invItems = await trxMgr.query(
68
- `
69
- select op.id, op."name", op.description, op."type", op.batch_id, op.adjusted_batch_id, op.adjusted_pallet_qty, op.packing_type,
70
- ih.uom, op.uom_value, ih.qty, op.pallet_qty, op.actual_pallet_qty, op.total_uom_value, op.release_qty,
71
- coalesce((select nett_weight from product_details prdw where prdw.product_id = op.product_id and prdw.packing_type = op.packing_type and prdw.packing_size = op.packing_size order by nett_weight desc limit 1),0) as unit_nett_weight,
72
- coalesce((select gross_weight from product_details prdw where prdw.product_id = op.product_id and prdw.packing_type = op.packing_type and prdw.packing_size = op.packing_size order by nett_weight desc limit 1),0) as unit_gross_weight,
73
- op.unit_price, op.unpack_uom_value, op.unpack_qty, op.discount_amt, op.tax_rate, op.misc_amt,
74
- op.adjusted_packing_type, op.manufacture_date, op.adjusted_uom, op.adjusted_uom_value, op.adjusted_pack_qty, op.adjusted_total_uom_value,
75
- op.batch_id_ref, op.adjusted_batch_id_ref,
76
- op.adjusted_unit_price, op.packing_size, op.release_uom_value,
77
- ih.expiry_date as expiration_date, p.sku as product_sku, p.name as product_name, p.description as product_description,
78
- case when ih.reusable_pallet_id notnull then concat(ih.qty, ' ', ih.packing_type, '(S) ', plt.name) else concat(ih.pallet, ' PALLET(S)') end as remark
79
- from order_products op
80
- left join (
81
- select product_id, batch_id, reusable_pallet_id, packing_type, sum(qty) as qty,
82
- sum(uom_value) as uom_value, uom, count(distinct pallet_id) as pallet,
83
- string_agg(distinct expiration_date::varchar,', ' order by expiration_date::varchar) as expiry_date
84
- from reduced_inventory_histories rih
85
- where ref_order_id::uuid = $1
86
- and transaction_type = 'UNLOADING'
87
- group by reusable_pallet_id, product_id, batch_id, packing_type, uom
88
- ) ih on op.product_id = ih.product_id and op.batch_id = ih.batch_id and op.packing_type = ih.packing_type and op.uom = ih.uom
89
- left join pallets plt on plt.id = ih.reusable_pallet_id
90
- inner join products p on op.product_id = p.id
91
- where op.arrival_notice_id::uuid = $1
92
- order by p.sku
93
- `,
94
- [foundGAN.id]
95
- )
96
- })
97
-
98
- // 7. find grn template based on category
99
- const foundTemplate: Attachment = await getRepository(Attachment).findOne({
100
- where: { domain, category: TEMPLATE_TYPE.GRN_TEMPLATE }
101
- })
102
-
103
- // 8. find grn logo
104
- const foundLogo: Attachment = await getRepository(Attachment).findOne({
105
- where: {
106
- domain,
107
- category: TEMPLATE_TYPE.LOGO
108
- }
109
- })
110
-
111
- // 9. find signature
112
- const foundSignature: Attachment = await getRepository(Attachment).findOne({
113
- where: {
114
- domain,
115
- category: TEMPLATE_TYPE.SIGNATURE
116
- }
117
- })
118
-
119
- const foundCop: Attachment = await getRepository(Attachment).findOne({
120
- where: {
121
- domain,
122
- category: TEMPLATE_TYPE.COP
123
- }
124
- })
125
-
126
- const template = await STORAGE.readFile(foundTemplate.path, 'utf-8')
127
-
128
- let logo = null
129
- if (foundLogo?.path) {
130
- logo = 'data:' + foundLogo.mimetype + ';base64,' + (await STORAGE.readFile(foundLogo.path, 'base64'))
131
- }
132
-
133
- let signature = null
134
- if (foundSignature?.path) {
135
- signature = 'data:' + foundSignature.mimetype + ';base64,' + (await STORAGE.readFile(foundSignature.path, 'base64'))
136
- }
137
-
138
- let cop = null
139
- if (foundCop?.path) {
140
- cop = 'data:' + foundSignature.mimetype + ';base64,' + (await STORAGE.readFile(foundCop.path, 'base64'))
141
- }
142
-
143
- const data = {
144
- logo_url: logo,
145
- sign_url: signature,
146
- cop_url: cop,
147
- customer_biz: partnerBiz.name,
148
- customer_address: partnerBiz.address,
149
- company_domain: domainBizplace.company.name,
150
- company_phone: foundCP.phone,
151
- company_email: foundCP.email,
152
- company_brn: domainBizplace.company.brn,
153
- company_address: domainBizplace.company.address,
154
- order_no: foundGRN.name,
155
- gan_no: foundGAN.name,
156
- unload_date: DateTimeConverter.date(foundWS.endedAt),
157
- ref_no: `${foundGAN.refNo}`,
158
- ref_no1: foundGAN.refNo2 ? `${foundGAN.refNo2}` : '',
159
- ref_no2: foundGAN.refNo3 ? `${foundGAN.refNo3}` : '',
160
- received_date: DateTimeConverter.date(foundWS.endedAt),
161
- truck_no: foundGAN.truckNo || '',
162
- container_no: foundGAN.containerNo || '',
163
- unloaded_by: foundWS ? foundWS.updater.name : '',
164
- putaway_by: foundPutawayWS ? foundPutawayWS.updater.name : '',
165
- delivery_order_no: foundGAN.deliveryOrderNo ? foundGAN.deliveryOrderNo : '',
166
- product_list: invItems.map((item, idx) => {
167
- return {
168
- list_no: idx + 1,
169
- product_sku: `${item.product_sku}`,
170
- product_name: `${item.product_name}(${item.product_description})`,
171
- product_desc: item.product_description,
172
- product_nameOnly: item.product_name,
173
- product_type: item.packing_type,
174
- product_batch: item.batch_id,
175
- product_qty: item.qty,
176
- product_uom_value: `${Math.round(item.uom_value * 100) / 100} ${item.uom}`,
177
- product_unit_nett_weight: parseFloat(item.unit_nett_weight),
178
- product_total_nett_weight: parseFloat(item.unit_nett_weight) * parseFloat(item.qty),
179
- product_unit_gross_weight: parseFloat(item.unit_gross_weight),
180
- product_total_gross_weight: parseFloat(item.unit_gross_weight) * parseFloat(item.qty),
181
- pallet_qty: item.actual_pallet_qty,
182
- expiry_date: item.expiration_date,
183
- remark: (item.remark ? item.remark : '') + (item.issue ? ' [Issue]: ' + item.issue : '')
184
- }
185
- })
186
- }
187
-
188
- const formData = new FormData()
189
- formData.append('template', template)
190
- formData.append('jsonString', JSON.stringify(data))
191
-
192
- const response = await fetch(REPORT_API_URL, {
193
- method: 'POST',
194
- body: formData
195
- })
196
-
197
- return await response.text()
198
- }