@ripwords/myinvois-client 0.3.3 → 0.3.4
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/dist/api/documentManagement.d.ts +1 -1
- package/dist/api/documentSubmission.d.ts +1 -1
- package/dist/api/documentTypeManagement.d.ts +1 -1
- package/dist/api/notificationManagement.d.ts +1 -1
- package/dist/api/platformLogin.d.ts +1 -1
- package/dist/api/taxpayerValidation.d.ts +1 -1
- package/dist/api/taxpayerValidation.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index10.cjs +61 -4
- package/dist/{index16.cjs.map → index10.cjs.map} +1 -1
- package/dist/index11.cjs +531 -21
- package/dist/index11.cjs.map +1 -0
- package/dist/index12.cjs +195 -2
- package/dist/index12.cjs.map +1 -0
- package/dist/index13.cjs +0 -3
- package/dist/index14.cjs +19 -324
- package/dist/index14.cjs.map +1 -1
- package/dist/index15.cjs +0 -193
- package/dist/index16.cjs +0 -62
- package/dist/index17.cjs +23 -526
- package/dist/index17.cjs.map +1 -1
- package/dist/index18.cjs +16 -187
- package/dist/index18.cjs.map +1 -1
- package/dist/index2.cjs +4 -4
- package/dist/index20.cjs +25 -16
- package/dist/index20.cjs.map +1 -1
- package/dist/index21.cjs +24 -0
- package/dist/{index27.cjs.map → index21.cjs.map} +1 -1
- package/dist/index23.cjs +0 -29
- package/dist/index24.cjs +0 -25
- package/dist/index25.cjs +5 -0
- package/dist/index26.cjs +6 -33
- package/dist/index27.cjs +4 -23
- package/dist/index28.cjs +3 -0
- package/dist/index29.cjs +3 -0
- package/dist/index3.cjs +12 -6
- package/dist/index3.cjs.map +1 -0
- package/dist/index30.cjs +6 -0
- package/dist/index4.cjs +4 -4
- package/dist/index5.cjs +21 -2
- package/dist/index6.cjs +2 -2
- package/dist/index7.cjs +2 -5
- package/dist/index8.cjs +329 -4
- package/dist/index8.cjs.map +1 -0
- package/dist/index9.cjs +189 -9
- package/dist/index9.cjs.map +1 -1
- package/dist/{taxpayer-BWpQOlug.d.ts → taxpayer-BAoT73gg.d.ts} +1 -0
- package/dist/{taxpayer-DUFUvBKi.d.cts → taxpayer-DwGzY1IL.d.cts} +2 -1
- package/dist/{taxpayerValidation-y6P-Es0S.js → taxpayerValidation-Xd_EHDvk.js} +6 -3
- package/dist/{taxpayerValidation-D_jGaVty.cjs → taxpayerValidation-j8s6YGED.cjs} +7 -4
- package/dist/taxpayerValidation-j8s6YGED.cjs.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/taxpayer.d.ts +1 -1
- package/dist/utils/document.d.ts +1 -1
- package/dist/utils/signature-diagnostics.d.ts +1 -1
- package/dist/utils/validation.d.ts +1 -1
- package/package.json +1 -1
- package/dist/index15.cjs.map +0 -1
- package/dist/index23.cjs.map +0 -1
- package/dist/index24.cjs.map +0 -1
- package/dist/index26.cjs.map +0 -1
- package/dist/taxpayerValidation-D_jGaVty.cjs.map +0 -1
package/dist/index15.cjs
CHANGED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/utils/validation.ts
|
|
3
|
-
/**
|
|
4
|
-
* Validates TIN format based on registration type
|
|
5
|
-
*/
|
|
6
|
-
const validateTIN = (tin, registrationType) => {
|
|
7
|
-
const errors = [];
|
|
8
|
-
if (!tin) {
|
|
9
|
-
errors.push({
|
|
10
|
-
field: "tin",
|
|
11
|
-
code: "TIN_REQUIRED",
|
|
12
|
-
message: "TIN is required",
|
|
13
|
-
severity: "error"
|
|
14
|
-
});
|
|
15
|
-
return errors;
|
|
16
|
-
}
|
|
17
|
-
if (registrationType === "BRN" && !tin.startsWith("C")) errors.push({
|
|
18
|
-
field: "tin",
|
|
19
|
-
code: "TIN_FORMAT_INVALID",
|
|
20
|
-
message: "Company TIN should start with \"C\" for BRN registration",
|
|
21
|
-
severity: "warning"
|
|
22
|
-
});
|
|
23
|
-
if (registrationType === "NRIC" && !tin.startsWith("IG")) errors.push({
|
|
24
|
-
field: "tin",
|
|
25
|
-
code: "TIN_FORMAT_INVALID",
|
|
26
|
-
message: "Individual TIN should start with \"IG\" for NRIC registration",
|
|
27
|
-
severity: "warning"
|
|
28
|
-
});
|
|
29
|
-
if (tin.length > 14) errors.push({
|
|
30
|
-
field: "tin",
|
|
31
|
-
code: "TIN_LENGTH_INVALID",
|
|
32
|
-
message: "TIN cannot exceed 14 characters",
|
|
33
|
-
severity: "error"
|
|
34
|
-
});
|
|
35
|
-
return errors;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Validates contact number format (E.164 standard)
|
|
39
|
-
*/
|
|
40
|
-
const validateContactNumber = (contactNumber) => {
|
|
41
|
-
const errors = [];
|
|
42
|
-
if (!contactNumber || contactNumber === "NA") return errors;
|
|
43
|
-
const e164Regex = /^\+[1-9]\d{1,14}$/;
|
|
44
|
-
if (!e164Regex.test(contactNumber)) errors.push({
|
|
45
|
-
field: "contactNumber",
|
|
46
|
-
code: "CONTACT_FORMAT_INVALID",
|
|
47
|
-
message: "Contact number must be in E.164 format (e.g., +60123456789)",
|
|
48
|
-
severity: "error"
|
|
49
|
-
});
|
|
50
|
-
if (contactNumber.length < 8) errors.push({
|
|
51
|
-
field: "contactNumber",
|
|
52
|
-
code: "CONTACT_LENGTH_INVALID",
|
|
53
|
-
message: "Contact number must be at least 8 characters",
|
|
54
|
-
severity: "error"
|
|
55
|
-
});
|
|
56
|
-
return errors;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Validates monetary amounts
|
|
60
|
-
*/
|
|
61
|
-
const validateMonetaryAmount = (amount, fieldName, maxDigits = 18, maxDecimals = 2) => {
|
|
62
|
-
const errors = [];
|
|
63
|
-
if (amount < 0) errors.push({
|
|
64
|
-
field: fieldName,
|
|
65
|
-
code: "AMOUNT_NEGATIVE",
|
|
66
|
-
message: `${fieldName} cannot be negative`,
|
|
67
|
-
severity: "error"
|
|
68
|
-
});
|
|
69
|
-
const amountStr = amount.toString();
|
|
70
|
-
const [integerPart, decimalPart] = amountStr.split(".");
|
|
71
|
-
if (integerPart && integerPart.length > maxDigits - maxDecimals) errors.push({
|
|
72
|
-
field: fieldName,
|
|
73
|
-
code: "AMOUNT_DIGITS_EXCEEDED",
|
|
74
|
-
message: `${fieldName} exceeds maximum ${maxDigits} digits`,
|
|
75
|
-
severity: "error"
|
|
76
|
-
});
|
|
77
|
-
if (decimalPart && decimalPart.length > maxDecimals) errors.push({
|
|
78
|
-
field: fieldName,
|
|
79
|
-
code: "AMOUNT_DECIMALS_EXCEEDED",
|
|
80
|
-
message: `${fieldName} exceeds maximum ${maxDecimals} decimal places`,
|
|
81
|
-
severity: "error"
|
|
82
|
-
});
|
|
83
|
-
return errors;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Validates line item tax calculation consistency for both fixed rate and percentage taxation
|
|
87
|
-
*/
|
|
88
|
-
const validateLineItemTax = (item, index) => {
|
|
89
|
-
const errors = [];
|
|
90
|
-
const tolerance = .01;
|
|
91
|
-
const hasFixedRate = item.taxPerUnitAmount !== void 0 && item.baseUnitMeasure !== void 0;
|
|
92
|
-
const hasPercentageRate = item.taxRate !== void 0;
|
|
93
|
-
if (!hasFixedRate && !hasPercentageRate) {
|
|
94
|
-
errors.push({
|
|
95
|
-
field: `lineItem[${index}]`,
|
|
96
|
-
code: "TAX_METHOD_MISSING",
|
|
97
|
-
message: `Line item ${index + 1} must specify either taxRate (for percentage) or taxPerUnitAmount + baseUnitMeasure (for fixed rate)`,
|
|
98
|
-
severity: "error"
|
|
99
|
-
});
|
|
100
|
-
return errors;
|
|
101
|
-
}
|
|
102
|
-
if (hasFixedRate && hasPercentageRate) errors.push({
|
|
103
|
-
field: `lineItem[${index}]`,
|
|
104
|
-
code: "TAX_METHOD_CONFLICT",
|
|
105
|
-
message: `Line item ${index + 1} cannot have both percentage and fixed rate tax methods`,
|
|
106
|
-
severity: "error"
|
|
107
|
-
});
|
|
108
|
-
if (hasFixedRate) {
|
|
109
|
-
if (item.baseUnitMeasureCode === void 0) errors.push({
|
|
110
|
-
field: `lineItem[${index}].baseUnitMeasureCode`,
|
|
111
|
-
code: "UNIT_CODE_MISSING",
|
|
112
|
-
message: `Line item ${index + 1} with fixed rate tax must specify baseUnitMeasureCode`,
|
|
113
|
-
severity: "error"
|
|
114
|
-
});
|
|
115
|
-
const expectedTaxAmount = item.taxPerUnitAmount * item.baseUnitMeasure;
|
|
116
|
-
if (Math.abs(item.taxAmount - expectedTaxAmount) > tolerance) errors.push({
|
|
117
|
-
field: `lineItem[${index}].taxAmount`,
|
|
118
|
-
code: "FIXED_TAX_CALCULATION_MISMATCH",
|
|
119
|
-
message: `Line item ${index + 1} tax amount (${item.taxAmount}) doesn't match fixed rate calculation (${item.taxPerUnitAmount} × ${item.baseUnitMeasure} = ${expectedTaxAmount})`,
|
|
120
|
-
severity: "error"
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
if (hasPercentageRate && !hasFixedRate) {
|
|
124
|
-
const expectedTaxAmount = item.totalTaxableAmountPerLine * item.taxRate / 100;
|
|
125
|
-
if (Math.abs(item.taxAmount - expectedTaxAmount) > tolerance) errors.push({
|
|
126
|
-
field: `lineItem[${index}].taxAmount`,
|
|
127
|
-
code: "PERCENTAGE_TAX_CALCULATION_MISMATCH",
|
|
128
|
-
message: `Line item ${index + 1} tax amount (${item.taxAmount}) doesn't match percentage calculation (${item.totalTaxableAmountPerLine} × ${item.taxRate}% = ${expectedTaxAmount})`,
|
|
129
|
-
severity: "error"
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
return errors;
|
|
133
|
-
};
|
|
134
|
-
/**
|
|
135
|
-
* Validates tax calculation consistency
|
|
136
|
-
*/
|
|
137
|
-
const validateTaxCalculations = (invoice) => {
|
|
138
|
-
const errors = [];
|
|
139
|
-
invoice.invoiceLineItems.forEach((item, index) => {
|
|
140
|
-
errors.push(...validateLineItemTax(item, index));
|
|
141
|
-
});
|
|
142
|
-
const expectedTaxExclusive = invoice.invoiceLineItems.reduce((sum, item) => sum + item.totalTaxableAmountPerLine, 0);
|
|
143
|
-
const expectedTaxAmount = invoice.invoiceLineItems.reduce((sum, item) => sum + item.taxAmount, 0);
|
|
144
|
-
const tolerance = .01;
|
|
145
|
-
if (Math.abs(invoice.legalMonetaryTotal.taxExclusiveAmount - expectedTaxExclusive) > tolerance) errors.push({
|
|
146
|
-
field: "legalMonetaryTotal.taxExclusiveAmount",
|
|
147
|
-
code: "TAX_EXCLUSIVE_MISMATCH",
|
|
148
|
-
message: `Tax exclusive amount (${invoice.legalMonetaryTotal.taxExclusiveAmount}) doesn't match sum of line items (${expectedTaxExclusive})`,
|
|
149
|
-
severity: "error"
|
|
150
|
-
});
|
|
151
|
-
if (Math.abs(invoice.taxTotal.taxAmount - expectedTaxAmount) > tolerance) errors.push({
|
|
152
|
-
field: "taxTotal.taxAmount",
|
|
153
|
-
code: "TAX_AMOUNT_MISMATCH",
|
|
154
|
-
message: `Tax amount (${invoice.taxTotal.taxAmount}) doesn't match sum of line item taxes (${expectedTaxAmount})`,
|
|
155
|
-
severity: "error"
|
|
156
|
-
});
|
|
157
|
-
return errors;
|
|
158
|
-
};
|
|
159
|
-
/**
|
|
160
|
-
* Main validation function for complete invoice
|
|
161
|
-
*/
|
|
162
|
-
const validateInvoice = (invoice) => {
|
|
163
|
-
const allErrors = [];
|
|
164
|
-
allErrors.push(...validateTIN(invoice.supplier.tin, invoice.supplier.registrationType));
|
|
165
|
-
allErrors.push(...validateTIN(invoice.buyer.tin, invoice.buyer.registrationType));
|
|
166
|
-
allErrors.push(...validateContactNumber(invoice.supplier.contactNumber));
|
|
167
|
-
allErrors.push(...validateContactNumber(invoice.buyer.contactNumber));
|
|
168
|
-
allErrors.push(...validateMonetaryAmount(invoice.legalMonetaryTotal.taxExclusiveAmount, "taxExclusiveAmount"));
|
|
169
|
-
allErrors.push(...validateMonetaryAmount(invoice.legalMonetaryTotal.payableAmount, "payableAmount"));
|
|
170
|
-
allErrors.push(...validateMonetaryAmount(invoice.taxTotal.taxAmount, "taxAmount"));
|
|
171
|
-
invoice.invoiceLineItems.forEach((item, index) => {
|
|
172
|
-
allErrors.push(...validateMonetaryAmount(item.unitPrice, `lineItem[${index}].unitPrice`));
|
|
173
|
-
allErrors.push(...validateMonetaryAmount(item.taxAmount, `lineItem[${index}].taxAmount`));
|
|
174
|
-
allErrors.push(...validateMonetaryAmount(item.totalTaxableAmountPerLine, `lineItem[${index}].totalTaxableAmountPerLine`));
|
|
175
|
-
});
|
|
176
|
-
allErrors.push(...validateTaxCalculations(invoice));
|
|
177
|
-
const errors = allErrors.filter((e) => e.severity === "error");
|
|
178
|
-
const warnings = allErrors.filter((e) => e.severity === "warning");
|
|
179
|
-
return {
|
|
180
|
-
isValid: errors.length === 0,
|
|
181
|
-
errors,
|
|
182
|
-
warnings
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
//#endregion
|
|
187
|
-
exports.validateContactNumber = validateContactNumber;
|
|
188
|
-
exports.validateInvoice = validateInvoice;
|
|
189
|
-
exports.validateLineItemTax = validateLineItemTax;
|
|
190
|
-
exports.validateMonetaryAmount = validateMonetaryAmount;
|
|
191
|
-
exports.validateTIN = validateTIN;
|
|
192
|
-
exports.validateTaxCalculations = validateTaxCalculations;
|
|
193
|
-
//# sourceMappingURL=index15.cjs.map
|
package/dist/index16.cjs
CHANGED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/types/classification-codes.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* Enum representing the allowed classification codes with descriptive names.
|
|
5
|
-
* Provides a more readable way to reference classification codes.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* const code = ClassificationCodeEnum.ComputerSmartphoneOrTablet;
|
|
9
|
-
* console.log(code); // Output: "003"
|
|
10
|
-
*/
|
|
11
|
-
let ClassificationCodeEnum = /* @__PURE__ */ function(ClassificationCodeEnum$1) {
|
|
12
|
-
ClassificationCodeEnum$1["BreastfeedingEquipment"] = "001";
|
|
13
|
-
ClassificationCodeEnum$1["ChildCareCentresAndKindergartensFees"] = "002";
|
|
14
|
-
ClassificationCodeEnum$1["ComputerSmartphoneOrTablet"] = "003";
|
|
15
|
-
ClassificationCodeEnum$1["ConsolidatedEInvoice"] = "004";
|
|
16
|
-
ClassificationCodeEnum$1["ConstructionMaterials"] = "005";
|
|
17
|
-
ClassificationCodeEnum$1["Disbursement"] = "006";
|
|
18
|
-
ClassificationCodeEnum$1["Donation"] = "007";
|
|
19
|
-
ClassificationCodeEnum$1["ECommerceEInvoiceToBuyer"] = "008";
|
|
20
|
-
ClassificationCodeEnum$1["ECommerceSelfBilledToSellerLogistics"] = "009";
|
|
21
|
-
ClassificationCodeEnum$1["EducationFees"] = "010";
|
|
22
|
-
ClassificationCodeEnum$1["GoodsOnConsignmentConsignor"] = "011";
|
|
23
|
-
ClassificationCodeEnum$1["GoodsOnConsignmentConsignee"] = "012";
|
|
24
|
-
ClassificationCodeEnum$1["GymMembership"] = "013";
|
|
25
|
-
ClassificationCodeEnum$1["InsuranceEducationMedicalBenefits"] = "014";
|
|
26
|
-
ClassificationCodeEnum$1["InsuranceTakafulLife"] = "015";
|
|
27
|
-
ClassificationCodeEnum$1["InterestFinancingExpenses"] = "016";
|
|
28
|
-
ClassificationCodeEnum$1["InternetSubscription"] = "017";
|
|
29
|
-
ClassificationCodeEnum$1["LandAndBuilding"] = "018";
|
|
30
|
-
ClassificationCodeEnum$1["MedicalExamLearningDisabilities"] = "019";
|
|
31
|
-
ClassificationCodeEnum$1["MedicalExamVaccination"] = "020";
|
|
32
|
-
ClassificationCodeEnum$1["MedicalExpensesSeriousDiseases"] = "021";
|
|
33
|
-
ClassificationCodeEnum$1["Others"] = "022";
|
|
34
|
-
ClassificationCodeEnum$1["PetroleumOperations"] = "023";
|
|
35
|
-
ClassificationCodeEnum$1["PrivateRetirementSchemeDeferredAnnuity"] = "024";
|
|
36
|
-
ClassificationCodeEnum$1["MotorVehicle"] = "025";
|
|
37
|
-
ClassificationCodeEnum$1["SubscriptionBooksJournalsEtc"] = "026";
|
|
38
|
-
ClassificationCodeEnum$1["Reimbursement"] = "027";
|
|
39
|
-
ClassificationCodeEnum$1["RentalOfMotorVehicle"] = "028";
|
|
40
|
-
ClassificationCodeEnum$1["EVChargingFacilities"] = "029";
|
|
41
|
-
ClassificationCodeEnum$1["RepairAndMaintenance"] = "030";
|
|
42
|
-
ClassificationCodeEnum$1["ResearchAndDevelopment"] = "031";
|
|
43
|
-
ClassificationCodeEnum$1["ForeignIncome"] = "032";
|
|
44
|
-
ClassificationCodeEnum$1["SelfBilledBettingGaming"] = "033";
|
|
45
|
-
ClassificationCodeEnum$1["SelfBilledImportationGoods"] = "034";
|
|
46
|
-
ClassificationCodeEnum$1["SelfBilledImportationServices"] = "035";
|
|
47
|
-
ClassificationCodeEnum$1["SelfBilledOthers"] = "036";
|
|
48
|
-
ClassificationCodeEnum$1["SelfBilledMonetaryPaymentToAgents"] = "037";
|
|
49
|
-
ClassificationCodeEnum$1["SportsEquipmentRentalFeesEtc"] = "038";
|
|
50
|
-
ClassificationCodeEnum$1["SupportingEquipmentDisabledPerson"] = "039";
|
|
51
|
-
ClassificationCodeEnum$1["VoluntaryContributionProvidentFund"] = "040";
|
|
52
|
-
ClassificationCodeEnum$1["DentalExamTreatment"] = "041";
|
|
53
|
-
ClassificationCodeEnum$1["FertilityTreatment"] = "042";
|
|
54
|
-
ClassificationCodeEnum$1["TreatmentHomeCareNursingEtc"] = "043";
|
|
55
|
-
ClassificationCodeEnum$1["VouchersGiftCardsLoyaltyPoints"] = "044";
|
|
56
|
-
ClassificationCodeEnum$1["SelfBilledNonMonetaryPaymentToAgents"] = "045";
|
|
57
|
-
return ClassificationCodeEnum$1;
|
|
58
|
-
}({});
|
|
59
|
-
|
|
60
|
-
//#endregion
|
|
61
|
-
exports.ClassificationCodeEnum = ClassificationCodeEnum;
|
|
62
|
-
//# sourceMappingURL=index16.cjs.map
|