pakdatakit 2.3.0 → 2.5.1
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/DATA.md +212 -3
- package/LICENSE +1 -1
- package/NOTICE +14 -0
- package/README.md +426 -207
- package/dist/address.cjs +5 -4
- package/dist/address.js +3 -2
- package/dist/bills.cjs +19 -0
- package/dist/bills.d.cts +63 -0
- package/dist/bills.d.ts +63 -0
- package/dist/bills.js +2 -0
- package/dist/{chunk-OKMBYX3F.cjs → chunk-33GOK7EE.cjs} +2 -910
- package/dist/chunk-34U2ZMHR.js +194 -0
- package/dist/chunk-4GSBHJX6.js +165 -0
- package/dist/chunk-5DDHO5Z7.cjs +565 -0
- package/dist/chunk-5EY5DQS7.js +51 -0
- package/dist/chunk-5RGX4DWF.js +559 -0
- package/dist/chunk-5UCRHVI4.cjs +302 -0
- package/dist/{chunk-TQP2T33V.js → chunk-B7DOQ5QF.js} +2 -1
- package/dist/chunk-CF6AMRBU.cjs +198 -0
- package/dist/chunk-CZOZB4K3.js +61 -0
- package/dist/chunk-E2XU6NOW.js +909 -0
- package/dist/chunk-E6GWBOKV.cjs +911 -0
- package/dist/chunk-EA3SIHYT.js +313 -0
- package/dist/{chunk-YTSMFGTW.js → chunk-IDTRFOQW.js} +8 -3
- package/dist/chunk-OTI7HY55.js +297 -0
- package/dist/{chunk-J5ARB4TE.cjs → chunk-QFPEFD67.cjs} +5 -4
- package/dist/chunk-SF4ECUZ6.cjs +56 -0
- package/dist/chunk-UYFTXD4P.js +168 -0
- package/dist/{chunk-TBTWZC74.cjs → chunk-XCFZKCV2.cjs} +8 -3
- package/dist/{chunk-N4S22XX3.js → chunk-XOTCIXY6.js} +2 -909
- package/dist/chunk-XVEG53NN.cjs +322 -0
- package/dist/chunk-YDUXIENX.cjs +172 -0
- package/dist/chunk-YPAWNWFD.cjs +168 -0
- package/dist/chunk-YQFI7W3I.cjs +65 -0
- package/dist/class-validator.cjs +16 -8
- package/dist/class-validator.d.cts +7 -1
- package/dist/class-validator.d.ts +7 -1
- package/dist/class-validator.js +15 -8
- package/dist/cli.js +1 -1
- package/dist/courier.cjs +16 -0
- package/dist/courier.d.cts +51 -0
- package/dist/courier.d.ts +51 -0
- package/dist/courier.js +3 -0
- package/dist/fbr-invoice.cjs +25 -0
- package/dist/fbr-invoice.d.cts +170 -0
- package/dist/fbr-invoice.d.ts +170 -0
- package/dist/fbr-invoice.js +4 -0
- package/dist/geo.cjs +11 -10
- package/dist/geo.js +2 -1
- package/dist/incometax.cjs +27 -0
- package/dist/incometax.d.cts +91 -0
- package/dist/incometax.d.ts +91 -0
- package/dist/incometax.js +2 -0
- package/dist/index.cjs +227 -123
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +21 -13
- package/dist/input.cjs +8 -8
- package/dist/input.js +2 -2
- package/dist/joi.cjs +14 -8
- package/dist/joi.d.cts +1 -0
- package/dist/joi.d.ts +1 -0
- package/dist/joi.js +13 -7
- package/dist/quality.cjs +25 -0
- package/dist/quality.d.cts +62 -0
- package/dist/quality.d.ts +62 -0
- package/dist/quality.js +8 -0
- package/dist/salestax.cjs +20 -0
- package/dist/salestax.d.cts +106 -0
- package/dist/salestax.d.ts +106 -0
- package/dist/salestax.js +3 -0
- package/dist/superstruct.cjs +14 -8
- package/dist/superstruct.d.cts +1 -0
- package/dist/superstruct.d.ts +1 -0
- package/dist/superstruct.js +13 -7
- package/dist/text.cjs +21 -5
- package/dist/text.d.cts +90 -1
- package/dist/text.d.ts +90 -1
- package/dist/text.js +1 -1
- package/dist/valibot.cjs +14 -8
- package/dist/valibot.d.cts +1 -0
- package/dist/valibot.d.ts +1 -0
- package/dist/valibot.js +13 -7
- package/dist/yup.cjs +14 -8
- package/dist/yup.d.cts +1 -0
- package/dist/yup.d.ts +1 -0
- package/dist/yup.js +13 -7
- package/dist/zod.cjs +14 -8
- package/dist/zod.d.cts +1 -0
- package/dist/zod.d.ts +1 -0
- package/dist/zod.js +13 -7
- package/package.json +74 -11
- package/dist/chunk-JKE4AMSZ.js +0 -47
- package/dist/chunk-KEHCTYLO.cjs +0 -52
- package/dist/{chunk-A3HBEBXY.js → chunk-7DY26QPN.js} +1 -1
- package/dist/{chunk-FRBPAGEJ.cjs → chunk-TVL6RDAU.cjs} +1 -1
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkCF6AMRBU_cjs = require('./chunk-CF6AMRBU.cjs');
|
|
4
|
+
var chunkSF4ECUZ6_cjs = require('./chunk-SF4ECUZ6.cjs');
|
|
5
|
+
var chunkVPBMIYO2_cjs = require('./chunk-VPBMIYO2.cjs');
|
|
6
|
+
|
|
7
|
+
// src/fbr-invoice.ts
|
|
8
|
+
var FBR_DI_SPEC_VERSION = "1.12";
|
|
9
|
+
var INVOICE_TYPES = /* @__PURE__ */ new Set(["Sale Invoice", "Debit Note"]);
|
|
10
|
+
var REGISTRATION_TYPES = /* @__PURE__ */ new Set(["Registered", "Unregistered"]);
|
|
11
|
+
var NTN_OR_CNIC = /^(?:\d{7}|\d{13})$/;
|
|
12
|
+
var FBR_INVOICE_NUMBER = /^(?:\d{7}|\d{13})DI\d{13}$/;
|
|
13
|
+
var SCENARIO = /^SN0(?:0[1-9]|1\d|2[0-8])$/;
|
|
14
|
+
var PERCENT_RATE = /^(\d+(?:\.\d+)?)%$/;
|
|
15
|
+
var PER_UNIT_RATE = /^rs\.?\s*(\d+(?:\.\d+)?)$/i;
|
|
16
|
+
var isText = (value) => typeof value === "string";
|
|
17
|
+
var filled = (value) => isText(value) && value.trim().length > 0;
|
|
18
|
+
var isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
19
|
+
var saleTypeKey = (value) => isText(value) ? chunkVPBMIYO2_cjs.normalizeKey(value) : "";
|
|
20
|
+
function decimalPlaces(value) {
|
|
21
|
+
if (!Number.isFinite(value)) return null;
|
|
22
|
+
const match = /^-?\d+(?:\.(\d+))?(?:e([+-]\d+))?$/.exec(String(value));
|
|
23
|
+
if (!match) return null;
|
|
24
|
+
const places = (match[1] ?? "").length - Number(match[2] ?? "0");
|
|
25
|
+
return places > 0 ? places : 0;
|
|
26
|
+
}
|
|
27
|
+
function expectedSalesTax(item) {
|
|
28
|
+
if (!isObject(item) || !isText(item.rate)) return null;
|
|
29
|
+
const rate = item.rate.trim();
|
|
30
|
+
const percent = PERCENT_RATE.exec(rate);
|
|
31
|
+
if (percent) {
|
|
32
|
+
const base = saleTypeKey(item.saleType) === "3rd schedule goods" ? item.fixedNotifiedValueOrRetailPrice : item.valueSalesExcludingST;
|
|
33
|
+
if (typeof base !== "number") return null;
|
|
34
|
+
return chunkCF6AMRBU_cjs.calculateSalesTax(base, { rate: Number(percent[1]) })?.tax ?? null;
|
|
35
|
+
}
|
|
36
|
+
const perUnit = PER_UNIT_RATE.exec(rate);
|
|
37
|
+
if (perUnit) {
|
|
38
|
+
if (typeof item.quantity !== "number") return null;
|
|
39
|
+
const quantity = chunkSF4ECUZ6_cjs.toUnits(item.quantity, 4);
|
|
40
|
+
const price = chunkSF4ECUZ6_cjs.toUnits(Number(perUnit[1]), 2);
|
|
41
|
+
if (quantity === null || price === null) return null;
|
|
42
|
+
return chunkSF4ECUZ6_cjs.fromPaisa(chunkSF4ECUZ6_cjs.divideHalfUp(BigInt(quantity) * BigInt(price), 10000n));
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
var NUMBER_FIELDS = [
|
|
47
|
+
"quantity",
|
|
48
|
+
"valueSalesExcludingST",
|
|
49
|
+
"salesTaxApplicable",
|
|
50
|
+
"salesTaxWithheldAtSource",
|
|
51
|
+
"extraTax",
|
|
52
|
+
"furtherTax",
|
|
53
|
+
"fedPayable",
|
|
54
|
+
"discount"
|
|
55
|
+
];
|
|
56
|
+
function columnTotal(items, key) {
|
|
57
|
+
const scale = key === "quantity" ? 4 : 2;
|
|
58
|
+
let sum = 0;
|
|
59
|
+
for (const item of items) {
|
|
60
|
+
const value = item[key];
|
|
61
|
+
if (typeof value !== "number") continue;
|
|
62
|
+
const units = chunkSF4ECUZ6_cjs.toUnits(value, scale);
|
|
63
|
+
if (units !== null) sum += units;
|
|
64
|
+
}
|
|
65
|
+
return sum / (scale === 4 ? 1e4 : 100);
|
|
66
|
+
}
|
|
67
|
+
function buildFbrInvoice(input) {
|
|
68
|
+
if (!isObject(input) || !Array.isArray(input.items)) return null;
|
|
69
|
+
const items = [];
|
|
70
|
+
for (const raw of input.items) {
|
|
71
|
+
if (!isObject(raw)) return null;
|
|
72
|
+
const line = raw;
|
|
73
|
+
const item = {
|
|
74
|
+
...line,
|
|
75
|
+
totalValues: line.totalValues ?? 0,
|
|
76
|
+
fixedNotifiedValueOrRetailPrice: line.fixedNotifiedValueOrRetailPrice ?? 0,
|
|
77
|
+
salesTaxWithheldAtSource: line.salesTaxWithheldAtSource ?? 0
|
|
78
|
+
};
|
|
79
|
+
item.salesTaxApplicable = line.salesTaxApplicable ?? expectedSalesTax(item) ?? 0;
|
|
80
|
+
items.push(item);
|
|
81
|
+
}
|
|
82
|
+
const invoice = {
|
|
83
|
+
...input,
|
|
84
|
+
buyerNTNCNIC: input.buyerNTNCNIC ?? "",
|
|
85
|
+
invoiceRefNo: input.invoiceRefNo ?? "",
|
|
86
|
+
items
|
|
87
|
+
};
|
|
88
|
+
const totals = Object.fromEntries(
|
|
89
|
+
NUMBER_FIELDS.map((key) => [key, columnTotal(items, key)])
|
|
90
|
+
);
|
|
91
|
+
return { invoice, totals };
|
|
92
|
+
}
|
|
93
|
+
function validDate(text) {
|
|
94
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(text);
|
|
95
|
+
if (!match) return false;
|
|
96
|
+
const [y, m, d] = [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
97
|
+
const leap = y % 4 === 0 && y % 100 !== 0 || y % 400 === 0;
|
|
98
|
+
const days = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
99
|
+
return m >= 1 && m <= 12 && d >= 1 && d <= days[m - 1];
|
|
100
|
+
}
|
|
101
|
+
function validateFbrInvoice(invoice, options = {}) {
|
|
102
|
+
const errors = [];
|
|
103
|
+
const add = (code, field, message) => errors.push({ code, field, message });
|
|
104
|
+
if (!isObject(invoice)) {
|
|
105
|
+
add(null, "invoice", "The invoice must be an object");
|
|
106
|
+
return { valid: false, errors };
|
|
107
|
+
}
|
|
108
|
+
const inv = invoice;
|
|
109
|
+
if (!filled(inv.invoiceType)) {
|
|
110
|
+
add("0011", "invoiceType", "Invoice type is empty");
|
|
111
|
+
} else if (!INVOICE_TYPES.has(inv.invoiceType)) {
|
|
112
|
+
add(
|
|
113
|
+
"0003",
|
|
114
|
+
"invoiceType",
|
|
115
|
+
'Invoice type must be "Sale Invoice" or "Debit Note"'
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
if (!filled(inv.invoiceDate)) {
|
|
119
|
+
add("0042", "invoiceDate", "Invoice date is empty");
|
|
120
|
+
} else if (!/^\d{4}-\d{2}-\d{2}$/.test(inv.invoiceDate)) {
|
|
121
|
+
add("0005", "invoiceDate", "Invoice date must be in YYYY-MM-DD format");
|
|
122
|
+
} else if (!validDate(inv.invoiceDate)) {
|
|
123
|
+
add("0113", "invoiceDate", "Invoice date is not a valid date");
|
|
124
|
+
} else if (isText(options?.today) && validDate(options.today) && inv.invoiceDate > options.today) {
|
|
125
|
+
add("0043", "invoiceDate", "Invoice date is later than today");
|
|
126
|
+
}
|
|
127
|
+
if (!isText(inv.sellerNTNCNIC) || !NTN_OR_CNIC.test(inv.sellerNTNCNIC)) {
|
|
128
|
+
add("0401", "sellerNTNCNIC", "Seller NTN or CNIC must be 7 or 13 digits");
|
|
129
|
+
}
|
|
130
|
+
if (!filled(inv.sellerBusinessName)) {
|
|
131
|
+
add(null, "sellerBusinessName", "Seller business name is required");
|
|
132
|
+
}
|
|
133
|
+
if (!filled(inv.sellerProvince)) {
|
|
134
|
+
add("0073", "sellerProvince", "Seller province is empty");
|
|
135
|
+
}
|
|
136
|
+
if (!filled(inv.sellerAddress)) {
|
|
137
|
+
add(null, "sellerAddress", "Seller address is required");
|
|
138
|
+
}
|
|
139
|
+
const registration = inv.buyerRegistrationType;
|
|
140
|
+
if (!isText(registration) || !REGISTRATION_TYPES.has(registration)) {
|
|
141
|
+
add(
|
|
142
|
+
"0012",
|
|
143
|
+
"buyerRegistrationType",
|
|
144
|
+
'Buyer registration type must be "Registered" or "Unregistered"'
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
const buyerId = inv.buyerNTNCNIC;
|
|
148
|
+
if (!filled(buyerId)) {
|
|
149
|
+
if (registration !== "Unregistered") {
|
|
150
|
+
add("0009", "buyerNTNCNIC", "Buyer NTN or CNIC is empty");
|
|
151
|
+
}
|
|
152
|
+
} else if (!NTN_OR_CNIC.test(buyerId)) {
|
|
153
|
+
add("0402", "buyerNTNCNIC", "Buyer NTN or CNIC must be 7 or 13 digits");
|
|
154
|
+
} else if (buyerId === inv.sellerNTNCNIC) {
|
|
155
|
+
add(
|
|
156
|
+
"0058",
|
|
157
|
+
"buyerNTNCNIC",
|
|
158
|
+
"Buyer and seller must be different (self-invoicing is not allowed)"
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
if (!filled(inv.buyerBusinessName)) {
|
|
162
|
+
add("0010", "buyerBusinessName", "Buyer business name is empty");
|
|
163
|
+
}
|
|
164
|
+
if (!filled(inv.buyerProvince)) {
|
|
165
|
+
add("0074", "buyerProvince", "Buyer province is empty");
|
|
166
|
+
}
|
|
167
|
+
if (!filled(inv.buyerAddress)) {
|
|
168
|
+
add(null, "buyerAddress", "Buyer address is required");
|
|
169
|
+
}
|
|
170
|
+
if (filled(inv.invoiceRefNo)) {
|
|
171
|
+
if (!FBR_INVOICE_NUMBER.test(inv.invoiceRefNo.trim())) {
|
|
172
|
+
add(
|
|
173
|
+
null,
|
|
174
|
+
"invoiceRefNo",
|
|
175
|
+
'Invoice reference number must be an FBR invoice number (NTN or CNIC, "DI", 13 digits)'
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
} else if (inv.invoiceType === "Debit Note") {
|
|
179
|
+
add(
|
|
180
|
+
"0026",
|
|
181
|
+
"invoiceRefNo",
|
|
182
|
+
"Invoice reference number is required for a debit note"
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
if (inv.scenarioId !== void 0 && inv.scenarioId !== null && inv.scenarioId !== "") {
|
|
186
|
+
if (!isText(inv.scenarioId) || !SCENARIO.test(inv.scenarioId)) {
|
|
187
|
+
add(null, "scenarioId", "Scenario ID must be SN001 to SN028");
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (!Array.isArray(inv.items) || inv.items.length === 0) {
|
|
191
|
+
add(null, "items", "The invoice needs at least one item");
|
|
192
|
+
return { valid: errors.length === 0, errors };
|
|
193
|
+
}
|
|
194
|
+
inv.items.forEach((raw, index) => {
|
|
195
|
+
const at = (key) => `items[${index}].${key}`;
|
|
196
|
+
if (!isObject(raw)) {
|
|
197
|
+
add(null, `items[${index}]`, "Each item must be an object");
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const item = raw;
|
|
201
|
+
if (!filled(item.hsCode)) add("0044", at("hsCode"), "HS code is empty");
|
|
202
|
+
if (!isText(item.productDescription)) {
|
|
203
|
+
add(null, at("productDescription"), "Product description is required");
|
|
204
|
+
}
|
|
205
|
+
if (!filled(item.rate)) add("0020", at("rate"), "Rate is empty");
|
|
206
|
+
if (!filled(item.uoM)) add(null, at("uoM"), "Unit of measure is required");
|
|
207
|
+
if (!filled(item.saleType))
|
|
208
|
+
add("0013", at("saleType"), "Sale type is empty");
|
|
209
|
+
const missingCodes = {
|
|
210
|
+
quantity: "0098",
|
|
211
|
+
valueSalesExcludingST: "0021",
|
|
212
|
+
salesTaxApplicable: "0023",
|
|
213
|
+
salesTaxWithheldAtSource: "0024",
|
|
214
|
+
totalValues: null,
|
|
215
|
+
fixedNotifiedValueOrRetailPrice: null
|
|
216
|
+
};
|
|
217
|
+
const numbersOk = {};
|
|
218
|
+
for (const key of [
|
|
219
|
+
...Object.keys(missingCodes),
|
|
220
|
+
"extraTax",
|
|
221
|
+
"furtherTax",
|
|
222
|
+
"fedPayable",
|
|
223
|
+
"discount"
|
|
224
|
+
]) {
|
|
225
|
+
const value = item[key];
|
|
226
|
+
const required = key in missingCodes;
|
|
227
|
+
if (value === void 0 || value === null || !required && value === "") {
|
|
228
|
+
if (required) {
|
|
229
|
+
add(missingCodes[key] ?? null, at(key), `${key} is required`);
|
|
230
|
+
}
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
234
|
+
add("0300", at(key), `${key} must be a number, not negative`);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
const places = decimalPlaces(value);
|
|
238
|
+
const limit = key === "quantity" ? 4 : 2;
|
|
239
|
+
if (places > limit) {
|
|
240
|
+
add("0302", at(key), `${key} has more than ${limit} decimal places`);
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
numbersOk[key] = true;
|
|
244
|
+
}
|
|
245
|
+
const rate = isText(item.rate) ? item.rate.trim() : "";
|
|
246
|
+
if (filled(item.rate) && rate !== "18%" && !filled(item.sroScheduleNo)) {
|
|
247
|
+
add(
|
|
248
|
+
"0077",
|
|
249
|
+
at("sroScheduleNo"),
|
|
250
|
+
"SRO/schedule number is required when the rate is not 18%"
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
if (filled(item.sroScheduleNo) && !filled(item.sroItemSerialNo)) {
|
|
254
|
+
add(
|
|
255
|
+
"0078",
|
|
256
|
+
at("sroItemSerialNo"),
|
|
257
|
+
"Item serial number is required when an SRO/schedule number is given"
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
const saleType = saleTypeKey(item.saleType);
|
|
261
|
+
if (saleType === "3rd schedule goods" && numbersOk.fixedNotifiedValueOrRetailPrice === true && item.fixedNotifiedValueOrRetailPrice === 0) {
|
|
262
|
+
add(
|
|
263
|
+
"0090",
|
|
264
|
+
at("fixedNotifiedValueOrRetailPrice"),
|
|
265
|
+
"Retail price is required for Third Schedule goods"
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
if (saleType === "goods at reduced rate" && item.extraTax !== void 0 && item.extraTax !== null && item.extraTax !== "") {
|
|
269
|
+
add(
|
|
270
|
+
"0091",
|
|
271
|
+
at("extraTax"),
|
|
272
|
+
"Extra tax must be empty for goods at a reduced rate"
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
if (numbersOk.salesTaxApplicable === true) {
|
|
276
|
+
const percent = PERCENT_RATE.test(rate);
|
|
277
|
+
const perUnit = PER_UNIT_RATE.test(rate);
|
|
278
|
+
const baseKey = perUnit ? "quantity" : saleType === "3rd schedule goods" ? "fixedNotifiedValueOrRetailPrice" : "valueSalesExcludingST";
|
|
279
|
+
if ((percent || perUnit) && numbersOk[baseKey] === true) {
|
|
280
|
+
const expected = expectedSalesTax(item);
|
|
281
|
+
if (expected !== null) {
|
|
282
|
+
const actual = chunkSF4ECUZ6_cjs.toUnits(item.salesTaxApplicable, 2);
|
|
283
|
+
const wanted = chunkSF4ECUZ6_cjs.toUnits(expected, 2);
|
|
284
|
+
if (actual !== null && wanted !== null && Math.abs(actual - wanted) > 1) {
|
|
285
|
+
const code = perUnit ? "0105" : saleType === "3rd schedule goods" ? "0102" : "0104";
|
|
286
|
+
add(
|
|
287
|
+
code,
|
|
288
|
+
at("salesTaxApplicable"),
|
|
289
|
+
`Sales tax should be ${expected.toFixed(2)} for this rate`
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
return { valid: errors.length === 0, errors };
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
exports.FBR_DI_SPEC_VERSION = FBR_DI_SPEC_VERSION;
|
|
300
|
+
exports.buildFbrInvoice = buildFbrInvoice;
|
|
301
|
+
exports.expectedSalesTax = expectedSalesTax;
|
|
302
|
+
exports.validateFbrInvoice = validateFbrInvoice;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getCityByPostalCode } from './chunk-33QMFE2Z.js';
|
|
2
|
-
import { getProvince, getDistrictProvince,
|
|
2
|
+
import { getProvince, getDistrictProvince, districts_default } from './chunk-XOTCIXY6.js';
|
|
3
|
+
import { cities_default } from './chunk-E2XU6NOW.js';
|
|
3
4
|
import { normalizeWhitespace, normalizeKey, lazy } from './chunk-ENQ7O7VW.js';
|
|
4
5
|
|
|
5
6
|
// src/address.ts
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkSF4ECUZ6_cjs = require('./chunk-SF4ECUZ6.cjs');
|
|
4
|
+
var chunkVPBMIYO2_cjs = require('./chunk-VPBMIYO2.cjs');
|
|
5
|
+
|
|
6
|
+
// data/sales-tax-rates.json
|
|
7
|
+
var sales_tax_rates_default = [
|
|
8
|
+
{
|
|
9
|
+
kind: "goods",
|
|
10
|
+
authority: "FBR",
|
|
11
|
+
province: null,
|
|
12
|
+
rate: 17,
|
|
13
|
+
from: "2019-07-01",
|
|
14
|
+
to: "2023-02-22",
|
|
15
|
+
law: "Sales Tax Act 1990, s. 3(1)",
|
|
16
|
+
source: "https://download1.fbr.gov.pk/Docs/20232231921422957Finance(Supplementary)Act,2023.pdf"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
kind: "goods",
|
|
20
|
+
authority: "FBR",
|
|
21
|
+
province: null,
|
|
22
|
+
rate: 18,
|
|
23
|
+
from: "2023-02-23",
|
|
24
|
+
to: null,
|
|
25
|
+
law: "Sales Tax Act 1990, s. 3(1), as amended by the Finance (Supplementary) Act 2023",
|
|
26
|
+
source: "https://download1.fbr.gov.pk/Docs/20267171373418951SalesTaxAct1990updatedupto30.06.2026.pdf"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
kind: "services",
|
|
30
|
+
authority: "PRA",
|
|
31
|
+
province: "Punjab",
|
|
32
|
+
rate: 16,
|
|
33
|
+
from: "2019-07-01",
|
|
34
|
+
to: null,
|
|
35
|
+
law: "Punjab Sales Tax on Services Act 2012, s. 2(41A) and Second Schedule",
|
|
36
|
+
source: "https://pra.punjab.gov.pk/Downloads/THE-PUNJAB-SALES-TAX-ON-SERVICES-ACT-2012-17th-Edition-2026-2027.pdf"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
kind: "services",
|
|
40
|
+
authority: "SRB",
|
|
41
|
+
province: "Sindh",
|
|
42
|
+
rate: 13,
|
|
43
|
+
from: "2019-07-01",
|
|
44
|
+
to: "2024-06-30",
|
|
45
|
+
law: "Sindh Sales Tax on Services Act 2011, Second Schedule",
|
|
46
|
+
source: "https://www.pas.gov.pk/uploads/acts/Sindh%20Act%20No.II%20of%202024.pdf"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
kind: "services",
|
|
50
|
+
authority: "SRB",
|
|
51
|
+
province: "Sindh",
|
|
52
|
+
rate: 15,
|
|
53
|
+
from: "2024-07-01",
|
|
54
|
+
to: null,
|
|
55
|
+
law: "Sindh Sales Tax on Services Act 2011, s. 8(1), as amended by the Sindh Finance Acts 2024 and 2025",
|
|
56
|
+
source: "https://www.srb.gos.pk/srb/wp-content/uploads/2026/01/Sindh-Sales-Tax-Act-2011-25-26-2.pdf"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
kind: "services",
|
|
60
|
+
authority: "KPRA",
|
|
61
|
+
province: "Khyber Pakhtunkhwa",
|
|
62
|
+
rate: 15,
|
|
63
|
+
from: "2019-07-01",
|
|
64
|
+
to: null,
|
|
65
|
+
law: "Khyber Pakhtunkhwa Finance Act 2019, Second Schedule; Khyber Pakhtunkhwa Sales Tax on Services Act 2022, s. 9(1)",
|
|
66
|
+
source: "https://kpra.gov.pk/wp-content/uploads/2026/09/KPSTSA-2022-Updated-Finance-act-2026.pdf"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
kind: "services",
|
|
70
|
+
authority: "BRA",
|
|
71
|
+
province: "Balochistan",
|
|
72
|
+
rate: 15,
|
|
73
|
+
from: "2019-07-01",
|
|
74
|
+
to: null,
|
|
75
|
+
law: "Balochistan Sales Tax on Services Act 2015, s. 10(1) and Second Schedule",
|
|
76
|
+
source: "https://bra.gob.pk/NewsDirectory/2015_BSTS_Act_Ver01.pdf"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
kind: "services",
|
|
80
|
+
authority: "FBR",
|
|
81
|
+
province: "Islamabad Capital Territory",
|
|
82
|
+
rate: 16,
|
|
83
|
+
from: "2019-07-01",
|
|
84
|
+
to: "2022-06-30",
|
|
85
|
+
law: "Islamabad Capital Territory (Tax on Services) Ordinance 2001, Schedule, Table 1",
|
|
86
|
+
source: "https://fbr.gov.pk/Budget2022-23/FinanceAct/Finance-Act-2022.pdf"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
kind: "services",
|
|
90
|
+
authority: "FBR",
|
|
91
|
+
province: "Islamabad Capital Territory",
|
|
92
|
+
rate: 15,
|
|
93
|
+
from: "2022-07-01",
|
|
94
|
+
to: null,
|
|
95
|
+
law: "Islamabad Capital Territory (Tax on Services) Ordinance 2001, Schedule, Table 1, as amended by the Finance Act 2022",
|
|
96
|
+
source: "https://download1.fbr.gov.pk/Docs/2025711172945966ICTOUpdatedupto30.06.2025.pdf"
|
|
97
|
+
}
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
// src/salestax.ts
|
|
101
|
+
var RATES = sales_tax_rates_default;
|
|
102
|
+
var PROVINCES = {
|
|
103
|
+
punjab: "Punjab",
|
|
104
|
+
sindh: "Sindh",
|
|
105
|
+
"khyber pakhtunkhwa": "Khyber Pakhtunkhwa",
|
|
106
|
+
kp: "Khyber Pakhtunkhwa",
|
|
107
|
+
kpk: "Khyber Pakhtunkhwa",
|
|
108
|
+
balochistan: "Balochistan",
|
|
109
|
+
baluchistan: "Balochistan",
|
|
110
|
+
"islamabad capital territory": "Islamabad Capital Territory",
|
|
111
|
+
ict: "Islamabad Capital Territory",
|
|
112
|
+
islamabad: "Islamabad Capital Territory",
|
|
113
|
+
"azad jammu and kashmir": "Azad Jammu and Kashmir",
|
|
114
|
+
ajk: "Azad Jammu and Kashmir",
|
|
115
|
+
"gilgit-baltistan": "Gilgit-Baltistan",
|
|
116
|
+
"gilgit baltistan": "Gilgit-Baltistan",
|
|
117
|
+
gb: "Gilgit-Baltistan"
|
|
118
|
+
};
|
|
119
|
+
var OUTSIDE_FEDERAL = /* @__PURE__ */ new Set(["Azad Jammu and Kashmir", "Gilgit-Baltistan"]);
|
|
120
|
+
function provinceName(input) {
|
|
121
|
+
if (typeof input !== "string") return null;
|
|
122
|
+
const key = chunkVPBMIYO2_cjs.normalizeKey(input);
|
|
123
|
+
return Object.prototype.hasOwnProperty.call(PROVINCES, key) ? PROVINCES[key] : null;
|
|
124
|
+
}
|
|
125
|
+
function getSalesTaxRate(query) {
|
|
126
|
+
if (query === null || typeof query !== "object") return null;
|
|
127
|
+
const { kind } = query;
|
|
128
|
+
if (kind !== "goods" && kind !== "services") return null;
|
|
129
|
+
const date = query.date === void 0 ? chunkSF4ECUZ6_cjs.isoDate(/* @__PURE__ */ new Date()) : chunkSF4ECUZ6_cjs.isoDate(query.date);
|
|
130
|
+
if (date === null) return null;
|
|
131
|
+
let province = null;
|
|
132
|
+
if (query.province !== void 0 && query.province !== null) {
|
|
133
|
+
province = provinceName(query.province);
|
|
134
|
+
if (province === null) return null;
|
|
135
|
+
}
|
|
136
|
+
if (kind === "goods") {
|
|
137
|
+
if (province !== null && OUTSIDE_FEDERAL.has(province)) return null;
|
|
138
|
+
} else if (province === null) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
const entry = RATES.find(
|
|
142
|
+
(r) => r.kind === kind && (kind === "goods" || r.province === province) && r.from <= date && (r.to === null || date <= r.to)
|
|
143
|
+
);
|
|
144
|
+
return entry ? { ...entry } : null;
|
|
145
|
+
}
|
|
146
|
+
function basisPoints(rate) {
|
|
147
|
+
if (typeof rate !== "number" || !Number.isFinite(rate) || rate < 0 || rate > 100) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
const exact = chunkSF4ECUZ6_cjs.toUnits(rate, 4);
|
|
151
|
+
if (exact === null || exact % 100 !== 0) return null;
|
|
152
|
+
return exact / 100;
|
|
153
|
+
}
|
|
154
|
+
function amounts(netPaisa, taxPaisa, bp) {
|
|
155
|
+
return {
|
|
156
|
+
net: chunkSF4ECUZ6_cjs.fromPaisa(netPaisa),
|
|
157
|
+
tax: chunkSF4ECUZ6_cjs.fromPaisa(taxPaisa),
|
|
158
|
+
gross: chunkSF4ECUZ6_cjs.fromPaisa(netPaisa + taxPaisa),
|
|
159
|
+
rate: bp / 100
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function splitInclusive(gross, rate) {
|
|
163
|
+
const grossPaisa = chunkSF4ECUZ6_cjs.toUnits(gross, 2);
|
|
164
|
+
const bp = basisPoints(rate);
|
|
165
|
+
if (grossPaisa === null || bp === null) return null;
|
|
166
|
+
const netPaisa = chunkSF4ECUZ6_cjs.divideHalfUp(
|
|
167
|
+
BigInt(grossPaisa) * 10000n,
|
|
168
|
+
BigInt(1e4 + bp)
|
|
169
|
+
);
|
|
170
|
+
return amounts(netPaisa, grossPaisa - netPaisa, bp);
|
|
171
|
+
}
|
|
172
|
+
function calculateSalesTax(amount, options) {
|
|
173
|
+
if (options === null || typeof options !== "object") return null;
|
|
174
|
+
let rate;
|
|
175
|
+
if (options.rate !== void 0 && options.rate !== null) {
|
|
176
|
+
rate = options.rate;
|
|
177
|
+
} else {
|
|
178
|
+
const kind = options.kind ?? (options.province !== void 0 ? "services" : void 0);
|
|
179
|
+
if (kind === void 0) return null;
|
|
180
|
+
const found = getSalesTaxRate({
|
|
181
|
+
kind,
|
|
182
|
+
...options.province !== void 0 ? { province: options.province } : {},
|
|
183
|
+
...options.date !== void 0 ? { date: options.date } : {}
|
|
184
|
+
});
|
|
185
|
+
if (found === null) return null;
|
|
186
|
+
rate = found.rate;
|
|
187
|
+
}
|
|
188
|
+
if (options.inclusive === true) return splitInclusive(amount, rate);
|
|
189
|
+
const netPaisa = chunkSF4ECUZ6_cjs.toUnits(amount, 2);
|
|
190
|
+
const bp = basisPoints(rate);
|
|
191
|
+
if (netPaisa === null || bp === null) return null;
|
|
192
|
+
const taxPaisa = chunkSF4ECUZ6_cjs.divideHalfUp(BigInt(netPaisa) * BigInt(bp), 10000n);
|
|
193
|
+
return amounts(netPaisa, taxPaisa, bp);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
exports.calculateSalesTax = calculateSalesTax;
|
|
197
|
+
exports.getSalesTaxRate = getSalesTaxRate;
|
|
198
|
+
exports.splitInclusive = splitInclusive;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { toAsciiDigits } from './chunk-ENQ7O7VW.js';
|
|
2
|
+
|
|
3
|
+
// src/bills.ts
|
|
4
|
+
var SEPARATORS = /[\s\-‐‑‒–—./]/g;
|
|
5
|
+
function parseElectricityRef(input) {
|
|
6
|
+
if (typeof input !== "string") return null;
|
|
7
|
+
let text = toAsciiDigits(input).replace(SEPARATORS, "").toUpperCase();
|
|
8
|
+
let urbanRural = null;
|
|
9
|
+
const letter = /^(\d{14})([UR])$/.exec(text);
|
|
10
|
+
if (letter) {
|
|
11
|
+
text = letter[1];
|
|
12
|
+
urbanRural = letter[2];
|
|
13
|
+
}
|
|
14
|
+
if (!/^\d+$/.test(text)) return null;
|
|
15
|
+
if (text.length === 14) {
|
|
16
|
+
const formatted = `${text.slice(0, 2)} ${text.slice(2, 7)} ${text.slice(7)}`;
|
|
17
|
+
return {
|
|
18
|
+
type: "reference",
|
|
19
|
+
digits: text,
|
|
20
|
+
formatted: urbanRural ? `${formatted} ${urbanRural}` : formatted,
|
|
21
|
+
urbanRural,
|
|
22
|
+
disco: null
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (urbanRural !== null) return null;
|
|
26
|
+
if (text.length === 13 && text.startsWith("04000")) {
|
|
27
|
+
return {
|
|
28
|
+
type: "k-electric",
|
|
29
|
+
digits: text,
|
|
30
|
+
formatted: text,
|
|
31
|
+
urbanRural: null,
|
|
32
|
+
disco: "K-Electric"
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if (text.length === 10 || text.length === 11) {
|
|
36
|
+
return {
|
|
37
|
+
type: "customer-id",
|
|
38
|
+
digits: text,
|
|
39
|
+
formatted: text,
|
|
40
|
+
urbanRural: null,
|
|
41
|
+
disco: null
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
function validateElectricityRef(input) {
|
|
47
|
+
return parseElectricityRef(input) !== null;
|
|
48
|
+
}
|
|
49
|
+
var GAS_DIGITS = {
|
|
50
|
+
SNGPL: 11,
|
|
51
|
+
SSGC: 10
|
|
52
|
+
};
|
|
53
|
+
function validateGasConsumerNumber(input, company) {
|
|
54
|
+
if (typeof input !== "string" || typeof company !== "string") return false;
|
|
55
|
+
const digits = GAS_DIGITS[company.toUpperCase()];
|
|
56
|
+
if (digits === void 0) return false;
|
|
57
|
+
const text = toAsciiDigits(input).replace(SEPARATORS, "");
|
|
58
|
+
return text.length === digits && /^\d+$/.test(text);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { parseElectricityRef, validateElectricityRef, validateGasConsumerNumber };
|