shareneus 1.5.64 → 1.5.65
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.
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.buildInvoicePartyDetailsSection = buildInvoicePartyDetailsSection;
|
|
7
|
+
const jsbarcode_1 = __importDefault(require("jsbarcode"));
|
|
4
8
|
const pdf_shared_utils_1 = require("../header-footer-section/pdf-shared.utils");
|
|
5
9
|
function buildInvoicePartyDetailsSection(PDFInvoiceData) {
|
|
6
10
|
const invoiceData = PDFInvoiceData || {};
|
|
@@ -9,12 +13,17 @@ function buildInvoicePartyDetailsSection(PDFInvoiceData) {
|
|
|
9
13
|
const insurance = resolveInsuranceDetails(invoiceData);
|
|
10
14
|
const useInsurance = !!insurance.name;
|
|
11
15
|
const secondaryParty = useInsurance ? insurance : shipTo;
|
|
16
|
+
const showBarCode = resolveShowBarCode(invoiceData);
|
|
17
|
+
const billToCode = resolveBillToCode(invoiceData);
|
|
12
18
|
const otherDetails = resolveOtherDetails(invoiceData);
|
|
19
|
+
const shouldShowSecondaryBarcode = !secondaryParty.hasData && showBarCode && !!billToCode;
|
|
13
20
|
const billToStack = billTo.hasData ? buildPartyStack('Bill To', billTo) : [{ text: '' }];
|
|
14
21
|
const secondaryTitle = useInsurance ? 'Insurance' : 'Ship To';
|
|
15
|
-
const secondaryStack = secondaryParty.hasData
|
|
22
|
+
const secondaryStack = secondaryParty.hasData
|
|
23
|
+
? buildPartyStack(secondaryTitle, secondaryParty)
|
|
24
|
+
: (shouldShowSecondaryBarcode ? buildBarcodeStack(billToCode) : [{ text: '' }]);
|
|
16
25
|
const otherDetailsStack = otherDetails.hasData ? buildOtherDetailsStack(otherDetails) : [{ text: '' }];
|
|
17
|
-
const hasAnyData = billTo.hasData || secondaryParty.hasData || otherDetails.hasData;
|
|
26
|
+
const hasAnyData = billTo.hasData || secondaryParty.hasData || shouldShowSecondaryBarcode || otherDetails.hasData;
|
|
18
27
|
if (!hasAnyData) {
|
|
19
28
|
return [{
|
|
20
29
|
text: '',
|
|
@@ -32,7 +41,7 @@ function buildInvoicePartyDetailsSection(PDFInvoiceData) {
|
|
|
32
41
|
}];
|
|
33
42
|
}
|
|
34
43
|
function resolveBillToDetails(invoiceData) {
|
|
35
|
-
var _a, _b, _c, _d, _e, _f;
|
|
44
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
36
45
|
const billTo = (invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.BillTo) || (invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Customer) || (invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Cust) || {};
|
|
37
46
|
const address = normalizeAddress((billTo === null || billTo === void 0 ? void 0 : billTo.Adrs)
|
|
38
47
|
|| ((_a = invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.BillTo) === null || _a === void 0 ? void 0 : _a.Adrs)
|
|
@@ -44,12 +53,14 @@ function resolveBillToDetails(invoiceData) {
|
|
|
44
53
|
const gstin = (0, pdf_shared_utils_1.firstValue)(billTo === null || billTo === void 0 ? void 0 : billTo.GSTIN, billTo === null || billTo === void 0 ? void 0 : billTo.GSTNo);
|
|
45
54
|
const contactInfo = resolvePhoneFromContacts(billTo === null || billTo === void 0 ? void 0 : billTo.Cons);
|
|
46
55
|
const directPhone = (0, pdf_shared_utils_1.firstValue)(billTo === null || billTo === void 0 ? void 0 : billTo.Ph, billTo === null || billTo === void 0 ? void 0 : billTo.Phone, billTo === null || billTo === void 0 ? void 0 : billTo.Mobile);
|
|
56
|
+
const ownerName = (0, pdf_shared_utils_1.firstValue)((_g = invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Cust) === null || _g === void 0 ? void 0 : _g.Name);
|
|
47
57
|
return {
|
|
48
58
|
name,
|
|
49
59
|
addressLines: billTo === null || billTo === void 0 ? void 0 : billTo.Adrs,
|
|
50
60
|
gstin,
|
|
51
61
|
phoneType: contactInfo.type,
|
|
52
62
|
phoneNumber: contactInfo.number || directPhone,
|
|
63
|
+
ownerName,
|
|
53
64
|
hasData: !!(name || gstin || contactInfo.number || directPhone || hasAddress(address))
|
|
54
65
|
};
|
|
55
66
|
}
|
|
@@ -80,20 +91,30 @@ function resolveInsuranceDetails(invoiceData) {
|
|
|
80
91
|
};
|
|
81
92
|
}
|
|
82
93
|
function resolveOtherDetails(invoiceData) {
|
|
83
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
94
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
84
95
|
const invoiceDate = (0, pdf_shared_utils_1.firstValue)(invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.DDate, invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.InvDt, invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Date, invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.CrDate);
|
|
85
96
|
const invoiceNumber = (0, pdf_shared_utils_1.firstValue)(invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData._id, invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Code, invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.InvNo, invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.No);
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
97
|
+
const productName = [
|
|
98
|
+
(_a = invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Product) === null || _a === void 0 ? void 0 : _a.Make,
|
|
99
|
+
(_b = invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Product) === null || _b === void 0 ? void 0 : _b.Model,
|
|
100
|
+
(_c = invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Product) === null || _c === void 0 ? void 0 : _c.Var
|
|
101
|
+
]
|
|
102
|
+
.map((value) => String(value !== null && value !== void 0 ? value : '').trim())
|
|
103
|
+
.filter((value) => !!value)
|
|
104
|
+
.join(' ');
|
|
105
|
+
const vehicleDetails = (0, pdf_shared_utils_1.firstValue)(productName, invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.VehNo, invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.VehicleNo, (_d = invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Vehicle) === null || _d === void 0 ? void 0 : _d.RegNo, (_e = invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Vehicle) === null || _e === void 0 ? void 0 : _e.No, (_f = invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Vehicle) === null || _f === void 0 ? void 0 : _f.Details, invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.VehicleDetails);
|
|
106
|
+
const Milage = (0, pdf_shared_utils_1.firstValue)(invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.MIn, invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.MOut, invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Milage);
|
|
107
|
+
const RegnNo = (_g = invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Product) === null || _g === void 0 ? void 0 : _g.RegNo;
|
|
108
|
+
const EngNo = (_h = invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Product) === null || _h === void 0 ? void 0 : _h.EngNo;
|
|
109
|
+
const ChassisNo = (_j = invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Product) === null || _j === void 0 ? void 0 : _j.VIN;
|
|
90
110
|
const lines = [
|
|
91
111
|
{ label: 'Invoice#', value: invoiceNumber },
|
|
92
112
|
{ label: 'Date', value: invoiceDate ? formatDisplayDate(invoiceDate) : '' },
|
|
113
|
+
{ label: 'Vehicle', value: vehicleDetails },
|
|
93
114
|
{ label: 'Regn. No', value: (0, pdf_shared_utils_1.firstValue)(RegnNo) },
|
|
94
115
|
{ label: 'Engine No', value: (0, pdf_shared_utils_1.firstValue)(EngNo) },
|
|
95
116
|
{ label: 'Chassis No', value: (0, pdf_shared_utils_1.firstValue)(ChassisNo) },
|
|
96
|
-
{ label: '
|
|
117
|
+
{ label: 'Milage', value: Milage }
|
|
97
118
|
].filter((line) => !!line.value);
|
|
98
119
|
return {
|
|
99
120
|
lines,
|
|
@@ -130,6 +151,24 @@ function buildPartyStack(title, party) {
|
|
|
130
151
|
const phoneLabel = (party === null || party === void 0 ? void 0 : party.phoneType) ? `Phone(${party.phoneType})` : 'Phone';
|
|
131
152
|
stack.push({ text: `${phoneLabel} : ${party.phoneNumber}`, fontSize: 8, lineHeight: 1.05 });
|
|
132
153
|
}
|
|
154
|
+
if (title === 'Bill To' && (party === null || party === void 0 ? void 0 : party.ownerName)) {
|
|
155
|
+
stack.push({
|
|
156
|
+
text: [
|
|
157
|
+
{ text: 'Owner Details', bold: true },
|
|
158
|
+
{ text: ' : ', bold: true },
|
|
159
|
+
{ text: party.ownerName, bold: false }
|
|
160
|
+
],
|
|
161
|
+
fontSize: 8.5,
|
|
162
|
+
color: '#111827',
|
|
163
|
+
margin: [0, 3, 0, 1]
|
|
164
|
+
});
|
|
165
|
+
stack.push({
|
|
166
|
+
canvas: [
|
|
167
|
+
{ type: 'line', x1: 0, y1: 0, x2: 170, y2: 0, lineWidth: 0.5, lineColor: '#111827' }
|
|
168
|
+
],
|
|
169
|
+
margin: [0, 2, 0, 0]
|
|
170
|
+
});
|
|
171
|
+
}
|
|
133
172
|
return stack;
|
|
134
173
|
}
|
|
135
174
|
function buildOtherDetailsStack(otherDetails) {
|
|
@@ -150,6 +189,19 @@ function buildOtherDetailsStack(otherDetails) {
|
|
|
150
189
|
}
|
|
151
190
|
return stack;
|
|
152
191
|
}
|
|
192
|
+
function buildBarcodeStack(code) {
|
|
193
|
+
const svg = textToSvgBarcode(code);
|
|
194
|
+
if (!svg) {
|
|
195
|
+
return [{ text: '' }];
|
|
196
|
+
}
|
|
197
|
+
return [
|
|
198
|
+
{
|
|
199
|
+
svg,
|
|
200
|
+
width: 160,
|
|
201
|
+
margin: [0, 8, 0, 0]
|
|
202
|
+
}
|
|
203
|
+
];
|
|
204
|
+
}
|
|
153
205
|
function hasAddress(address) {
|
|
154
206
|
const normalizedAddress = normalizeAddress(address);
|
|
155
207
|
if (!normalizedAddress) {
|
|
@@ -225,6 +277,45 @@ function formatDisplayDate(value) {
|
|
|
225
277
|
}
|
|
226
278
|
return value;
|
|
227
279
|
}
|
|
280
|
+
function resolveShowBarCode(invoiceData) {
|
|
281
|
+
var _a;
|
|
282
|
+
return isTruthy(invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.ShowBarCode) || isTruthy((_a = invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Entity) === null || _a === void 0 ? void 0 : _a.PrCustBar) || isTruthy(invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.PrCustBar);
|
|
283
|
+
}
|
|
284
|
+
function resolveBillToCode(invoiceData) {
|
|
285
|
+
var _a, _b, _c;
|
|
286
|
+
return (0, pdf_shared_utils_1.firstValue)((_a = invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.BillTo) === null || _a === void 0 ? void 0 : _a.Code, (_b = invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Customer) === null || _b === void 0 ? void 0 : _b.Code, (_c = invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Cust) === null || _c === void 0 ? void 0 : _c.Code);
|
|
287
|
+
}
|
|
288
|
+
function isTruthy(value) {
|
|
289
|
+
if (typeof value === 'boolean') {
|
|
290
|
+
return value;
|
|
291
|
+
}
|
|
292
|
+
if (typeof value === 'number') {
|
|
293
|
+
return value !== 0;
|
|
294
|
+
}
|
|
295
|
+
if (typeof value === 'string') {
|
|
296
|
+
const normalized = value.trim().toLowerCase();
|
|
297
|
+
return normalized === 'true' || normalized === '1' || normalized === 'yes';
|
|
298
|
+
}
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
function textToSvgBarcode(text) {
|
|
302
|
+
if (!text || typeof document === 'undefined') {
|
|
303
|
+
return '';
|
|
304
|
+
}
|
|
305
|
+
const svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
306
|
+
(0, jsbarcode_1.default)(svgElement, text, {
|
|
307
|
+
format: "CODE128",
|
|
308
|
+
width: 1.25,
|
|
309
|
+
height: 24,
|
|
310
|
+
margin: 0,
|
|
311
|
+
marginTop: 6,
|
|
312
|
+
displayValue: true,
|
|
313
|
+
fontSize: 7,
|
|
314
|
+
textMargin: 0,
|
|
315
|
+
fontOptions: 'bold'
|
|
316
|
+
});
|
|
317
|
+
return svgElement.outerHTML;
|
|
318
|
+
}
|
|
228
319
|
function resolvePhoneFromContacts(contacts) {
|
|
229
320
|
if (!Array.isArray(contacts)) {
|
|
230
321
|
return { type: '', number: '' };
|
|
@@ -5,6 +5,7 @@ exports.getFirstFieldValue = getFirstFieldValue;
|
|
|
5
5
|
exports.getNumericAlignment = getNumericAlignment;
|
|
6
6
|
exports.getCellAlignment = getCellAlignment;
|
|
7
7
|
const pdf_table_config_1 = require("./pdf-table.config");
|
|
8
|
+
const my_date_1 = require("../../utils/my-date");
|
|
8
9
|
function buildDataRow(item, index, headerConfig, fixedTo = 2) {
|
|
9
10
|
return headerConfig.map((column) => {
|
|
10
11
|
var _a;
|
|
@@ -18,10 +19,10 @@ function buildDataRow(item, index, headerConfig, fixedTo = 2) {
|
|
|
18
19
|
const serial = String(index + 1);
|
|
19
20
|
return { text: serial, fontSize: pdf_table_config_1.pdfTableStyleConfig.bodyFontSize, alignment: getNumericAlignment(serial) };
|
|
20
21
|
}
|
|
21
|
-
const mainValue =
|
|
22
|
+
const mainValue = formatFieldValue(item, header, fixedTo);
|
|
22
23
|
const stackedLines = ((_a = header.stackFields) !== null && _a !== void 0 ? _a : [])
|
|
23
24
|
.map((stackField) => {
|
|
24
|
-
const stackValue =
|
|
25
|
+
const stackValue = formatFieldValue(item, stackField, fixedTo);
|
|
25
26
|
if (!stackValue) {
|
|
26
27
|
return null;
|
|
27
28
|
}
|
|
@@ -43,6 +44,13 @@ function buildDataRow(item, index, headerConfig, fixedTo = 2) {
|
|
|
43
44
|
};
|
|
44
45
|
});
|
|
45
46
|
}
|
|
47
|
+
function formatFieldValue(item, fieldConfig, fixedTo) {
|
|
48
|
+
const rawValue = getFirstFieldValue(item, fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.dbFields);
|
|
49
|
+
if (isExpiryField(fieldConfig)) {
|
|
50
|
+
return formatExpiryDateValue(rawValue);
|
|
51
|
+
}
|
|
52
|
+
return formatNumericLikeValue(rawValue, fixedTo, shouldSkipFixedTo(fieldConfig));
|
|
53
|
+
}
|
|
46
54
|
function getTaxValue(item, taxName, taxKind) {
|
|
47
55
|
const fields = taxKind === 'rate'
|
|
48
56
|
? [`${taxName}Perc`, taxName]
|
|
@@ -126,6 +134,35 @@ function formatNumericLikeValue(value, fixedTo, skipFixedTo = false) {
|
|
|
126
134
|
}
|
|
127
135
|
return normalized.toFixed(fixedTo);
|
|
128
136
|
}
|
|
137
|
+
function isExpiryField(fieldConfig) {
|
|
138
|
+
var _a;
|
|
139
|
+
const text = String((_a = fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.text) !== null && _a !== void 0 ? _a : '').trim().toUpperCase();
|
|
140
|
+
if (text === 'EXPIRY' || text === 'EXPIRY DATE' || text === 'EXDT') {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
const dbFields = Array.isArray(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.dbFields) ? fieldConfig.dbFields : [];
|
|
144
|
+
return dbFields.some((field) => {
|
|
145
|
+
const normalized = String(field !== null && field !== void 0 ? field : '').trim().toUpperCase();
|
|
146
|
+
return normalized === 'EXDT' || normalized.endsWith('.EXDT') || normalized.endsWith('.EXPIRY');
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function formatExpiryDateValue(value) {
|
|
150
|
+
if (!value) {
|
|
151
|
+
return value;
|
|
152
|
+
}
|
|
153
|
+
const input = String(value).trim();
|
|
154
|
+
if (!input) {
|
|
155
|
+
return '';
|
|
156
|
+
}
|
|
157
|
+
if (/^\d{2}\/\d{2}$/.test(input)) {
|
|
158
|
+
return input;
|
|
159
|
+
}
|
|
160
|
+
const parsed = new Date(input);
|
|
161
|
+
if (Number.isNaN(parsed.getTime())) {
|
|
162
|
+
return input;
|
|
163
|
+
}
|
|
164
|
+
return my_date_1.MyDate.ConvertUTCDateToReadableExDate(input) || input;
|
|
165
|
+
}
|
|
129
166
|
function shouldSkipFixedTo(header) {
|
|
130
167
|
var _a;
|
|
131
168
|
const text = String((_a = header === null || header === void 0 ? void 0 : header.text) !== null && _a !== void 0 ? _a : '').trim().toUpperCase();
|