@managesome/eposmatic-toolkit 0.2.382 → 0.2.383
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.
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SRB_TRANSACTION_TYPE_ENUM = exports.ALL_SRB_INVOICE_TYPES = exports.SRB_INVOICE_TYPE_ENUM = void 0;
|
|
4
4
|
var SRB_INVOICE_TYPE_ENUM;
|
|
5
5
|
(function (SRB_INVOICE_TYPE_ENUM) {
|
|
6
|
+
// 1 = Normal Invoice, 2 = Sales Return (per SRB POS Invoice Payload Spec)
|
|
6
7
|
SRB_INVOICE_TYPE_ENUM[SRB_INVOICE_TYPE_ENUM["NEW"] = 1] = "NEW";
|
|
7
|
-
SRB_INVOICE_TYPE_ENUM[SRB_INVOICE_TYPE_ENUM["
|
|
8
|
-
SRB_INVOICE_TYPE_ENUM[SRB_INVOICE_TYPE_ENUM["CREDIT"] = 3] = "CREDIT";
|
|
8
|
+
SRB_INVOICE_TYPE_ENUM[SRB_INVOICE_TYPE_ENUM["SALES_RETURN"] = 2] = "SALES_RETURN";
|
|
9
9
|
})(SRB_INVOICE_TYPE_ENUM || (exports.SRB_INVOICE_TYPE_ENUM = SRB_INVOICE_TYPE_ENUM = {}));
|
|
10
10
|
exports.ALL_SRB_INVOICE_TYPES = Object.values(SRB_INVOICE_TYPE_ENUM);
|
|
11
11
|
// ======================>> <<====================== //
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SRB_TRANSACTION_TYPE_ENUM } from '../../constants/SRB_ENUMS';
|
|
1
2
|
import { IOrder } from '../../schemas';
|
|
2
3
|
import { ISrbInvoice } from '../types/srb-generate-invoice';
|
|
3
4
|
interface IProps {
|
|
@@ -8,6 +9,17 @@ interface IProps {
|
|
|
8
9
|
pos_user: string;
|
|
9
10
|
pos_pass: string;
|
|
10
11
|
store_name: string;
|
|
12
|
+
/**
|
|
13
|
+
* GST rate (%) that denotes a card payment, used to derive `modeOfPay`.
|
|
14
|
+
* Mirrors the convention used by `convertOrderToFbrInvoice` and
|
|
15
|
+
* `convertOrderToPraInvoice` (tenant-level setting).
|
|
16
|
+
*/
|
|
17
|
+
card_gst: number;
|
|
18
|
+
/**
|
|
19
|
+
* Transaction type: "Test" for testing or "Live" for production.
|
|
20
|
+
* Defaults to `SRB_TRANSACTION_TYPE_ENUM.TEST`.
|
|
21
|
+
*/
|
|
22
|
+
transType?: SRB_TRANSACTION_TYPE_ENUM;
|
|
11
23
|
}
|
|
12
|
-
export declare function convertOrderToSrbInvoice({ posId, ntn, order, gmtOffset, pos_user, pos_pass, store_name, }: IProps): ISrbInvoice | null;
|
|
24
|
+
export declare function convertOrderToSrbInvoice({ posId, ntn, order, gmtOffset, pos_user, pos_pass, store_name, card_gst, transType, }: IProps): ISrbInvoice | null;
|
|
13
25
|
export {};
|
|
@@ -4,43 +4,66 @@ exports.convertOrderToSrbInvoice = convertOrderToSrbInvoice;
|
|
|
4
4
|
const constants_1 = require("../../constants");
|
|
5
5
|
const SRB_ENUMS_1 = require("../../constants/SRB_ENUMS");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
|
-
function convertOrderToSrbInvoice({ posId, ntn, order, gmtOffset, pos_user, pos_pass, store_name, }) {
|
|
7
|
+
function convertOrderToSrbInvoice({ posId, ntn, order, gmtOffset, pos_user, pos_pass, store_name, card_gst, transType = SRB_ENUMS_1.SRB_TRANSACTION_TYPE_ENUM.TEST, }) {
|
|
8
|
+
// Invoice type: 1 = Normal Invoice, 2 = Sales Return (per SRB spec).
|
|
8
9
|
let invoiceType = SRB_ENUMS_1.SRB_INVOICE_TYPE_ENUM.NEW;
|
|
9
10
|
if (order.order_status === constants_1.ORDER_STATUS_ENUM.CANCELLED) {
|
|
10
|
-
invoiceType = SRB_ENUMS_1.SRB_INVOICE_TYPE_ENUM.
|
|
11
|
+
invoiceType = SRB_ENUMS_1.SRB_INVOICE_TYPE_ENUM.SALES_RETURN;
|
|
11
12
|
}
|
|
12
|
-
const
|
|
13
|
+
const rateValue = (0, utils_1.parseNum)(order.gst ?? 0);
|
|
13
14
|
const gstAmount = order.gst_amount ?? 0;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
15
|
+
// saleValue = "Gross sale value before discount and tax" (per SRB spec).
|
|
16
|
+
// Mirrors FBR's TotalSaleValue: back out the GST when the order is
|
|
17
|
+
// priced tax-inclusive so the value reflects the pre-tax base.
|
|
18
|
+
let saleValue = order.price;
|
|
19
19
|
if (order.is_gst_inclusive) {
|
|
20
|
-
|
|
20
|
+
saleValue -= gstAmount;
|
|
21
21
|
}
|
|
22
|
+
// When service fee / surcharge are taxable they must be included in
|
|
23
|
+
// saleValue so that netAmount = saleValue + taxAmount − discountAmount
|
|
24
|
+
// reflects the full taxable amount (SRB has no FurtherTax field like FBR).
|
|
22
25
|
if (order.is_service_fee_taxable) {
|
|
23
|
-
|
|
26
|
+
saleValue += order.service_fee_amount ?? 0;
|
|
24
27
|
}
|
|
25
28
|
if (order.is_surcharge_taxable) {
|
|
26
|
-
|
|
29
|
+
saleValue += order.surcharge_amount ?? 0;
|
|
27
30
|
}
|
|
28
|
-
|
|
31
|
+
saleValue = (0, utils_1.parseNum)(saleValue);
|
|
32
|
+
// taxAmount = POS-computed GST (order.gst_amount).
|
|
33
|
+
// Using the POS value instead of the spec formula ensures netAmount
|
|
34
|
+
// matches the POS grand_total exactly.
|
|
35
|
+
const taxAmount = (0, utils_1.parseNum)(order.gst_amount ?? 0);
|
|
36
|
+
// discountAmount = total discount applied on the sale (per SRB spec).
|
|
37
|
+
const discountAmount = (0, utils_1.parseNum)(order.total_discount_applied ?? 0);
|
|
38
|
+
// netAmount = saleValue + taxAmount − discountAmount (per SRB spec formula).
|
|
39
|
+
const netAmount = (0, utils_1.parseNum)(saleValue + taxAmount - discountAmount);
|
|
40
|
+
// modeOfPay = "Card" when the order GST matches the card GST, else "Cash".
|
|
41
|
+
// Mirrors the FBR/PRA pattern (CASH/CREDIT) but using SRB's literal values.
|
|
42
|
+
const modeOfPay = order.gst === card_gst ? 'Card' : 'Cash';
|
|
43
|
+
const consumerName = `${order.consumer.first_name} ${order.consumer.last_name}`.trim() || 'N/A';
|
|
44
|
+
const consumerMobile = order.consumer.phone || 'N/A';
|
|
45
|
+
const consumerEmail = order.consumer.email || 'N/A';
|
|
29
46
|
const srbInvoice = {
|
|
30
47
|
posId: parseInt(posId, 10),
|
|
31
48
|
name: store_name,
|
|
32
49
|
ntn,
|
|
33
50
|
invoiceDateTime: (0, utils_1.formatDateToDateTime)(order.order_settled_at, gmtOffset),
|
|
34
51
|
invoiceType,
|
|
35
|
-
|
|
36
|
-
rateValue
|
|
37
|
-
saleValue
|
|
38
|
-
taxAmount
|
|
52
|
+
invoiceId: String(order._id),
|
|
53
|
+
rateValue,
|
|
54
|
+
saleValue,
|
|
55
|
+
taxAmount,
|
|
56
|
+
discountAmount,
|
|
57
|
+
netAmount,
|
|
58
|
+
modeOfPay,
|
|
39
59
|
consumerName,
|
|
40
60
|
consumerNTN: 'N/A',
|
|
61
|
+
consumerMobile,
|
|
62
|
+
consumerEmail,
|
|
41
63
|
address: 'N/A',
|
|
42
|
-
|
|
64
|
+
cpcCode: 'N/A',
|
|
43
65
|
extraInf: 'N/A',
|
|
66
|
+
transType,
|
|
44
67
|
pos_user,
|
|
45
68
|
pos_pass,
|
|
46
69
|
};
|
|
@@ -5,21 +5,28 @@ export interface ISrbInvoice {
|
|
|
5
5
|
ntn: string;
|
|
6
6
|
invoiceDateTime: string;
|
|
7
7
|
invoiceType: SRB_INVOICE_TYPE_ENUM;
|
|
8
|
-
|
|
8
|
+
invoiceId: string;
|
|
9
9
|
rateValue: number;
|
|
10
10
|
saleValue: number;
|
|
11
11
|
taxAmount: number;
|
|
12
|
+
discountAmount: number;
|
|
13
|
+
netAmount: number;
|
|
14
|
+
modeOfPay: string;
|
|
12
15
|
consumerName: string;
|
|
13
16
|
consumerNTN: string;
|
|
17
|
+
consumerMobile: string;
|
|
18
|
+
consumerEmail: string;
|
|
14
19
|
address: string;
|
|
15
|
-
|
|
20
|
+
cpcCode: string;
|
|
16
21
|
extraInf: string;
|
|
22
|
+
transType: string;
|
|
17
23
|
pos_user: string;
|
|
18
24
|
pos_pass: string;
|
|
19
25
|
}
|
|
20
26
|
export interface ISrbInvoiceResponse {
|
|
21
|
-
resCode: string;
|
|
22
27
|
srbInvoceId: string;
|
|
28
|
+
resCode: string;
|
|
29
|
+
QRCodeLink: string;
|
|
23
30
|
}
|
|
24
31
|
export interface ISrbInvoiceErr {
|
|
25
32
|
status: string;
|