Skip to content

Commit 0790a69

Browse files
authored
Merge pull request #5 from wes4m/dev
Experimental release v0.1.1 release
2 parents 242fc60 + 4a9e7a6 commit 0790a69

File tree

7 files changed

+21
-26
lines changed

7 files changed

+21
-26
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const egsunit: EGSUnitInfo = {/*...*/};
5959
// Init EGS unit
6060
const egs = new EGS(egsunit);
6161
// New Keys & CSR for the EGS
62-
await egs.generateNewKeysAndCSR(false);
62+
await egs.generateNewKeysAndCSR(false, "solution_name");
6363
// Issue a new compliance cert for the EGS
6464
const compliance_rid = await egs.issueComplianceCertificate("123345");
6565
// Sign invoice

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "zatca-xml-js",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "An implementation of Saudi Arabia ZATCA's E-Invocing requirements, processes, and standards.",
55
"main": "lib/index.js",
66
"files": ["lib/**/*"],
77
"scripts": {
88
"build": "tsc --project tsconfig.build.json",
99
"test": "tsc && node testing_lib/tests/test.js",
10-
"example": "tsc && node lib/examples/full.js",
10+
"example": "tsc --project tsconfig.build.json && node lib/examples/full.js",
1111
"prepare": "npm run build"
1212
},
1313
"devDependencies": {

src/examples/full.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const main = async () => {
6363
const egs = new EGS(egsunit);
6464

6565
// New Keys & CSR for the EGS
66-
await egs.generateNewKeysAndCSR(false);
66+
await egs.generateNewKeysAndCSR(false, "solution_name");
6767

6868
// Issue a new compliance cert for the EGS
6969
const compliance_request_id = await egs.issueComplianceCertificate("123345");

src/zatca/ZATCASimplifiedTaxInvoice.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { XMLDocument } from "../parser";
22
import { generateSignedXMLString } from "./signing";
3-
import defaultSimplifiedTaxInvoice, { ZATCASimplifiedInvoiceLineItem, ZATCASimplifiedInvoiceProps } from "./templates/simplified_tax_invoice_template";
4-
5-
export {ZATCASimplifiedInvoiceLineItem, ZATCASimplifiedInvoiceProps};
3+
import defaultSimplifiedTaxInvoice, {
4+
ZATCASimplifiedInvoiceLineItem,
5+
ZATCASimplifiedInvoiceProps,
6+
ZATCAInvoiceTypes,
7+
ZATCAPaymentMethods
8+
} from "./templates/simplified_tax_invoice_template";
9+
10+
export {ZATCASimplifiedInvoiceLineItem, ZATCASimplifiedInvoiceProps, ZATCAInvoiceTypes, ZATCAPaymentMethods};
611
export class ZATCASimplifiedTaxInvoice {
712

813
private invoice_xml: XMLDocument;
@@ -29,8 +34,6 @@ export class ZATCASimplifiedTaxInvoice {
2934
}
3035

3136
private constructLineItemTotals = (line_item: ZATCASimplifiedInvoiceLineItem) => {
32-
33-
// TODO: decimal fixing according to ZATCA
3437

3538
let line_item_total_discounts = 0;
3639
let line_item_total_taxes = 0;
@@ -121,32 +124,25 @@ export class ZATCASimplifiedTaxInvoice {
121124

122125
return {
123126
line_item_xml: {
124-
// .. TODO
125127
"cbc:ID": line_item.id,
126-
// .. TODO
127128
"cbc:InvoicedQuantity": {
128129
"@_unitCode": "PCE",
129130
"#text": line_item.quantity
130131
},
131-
// .. TODO
132132
"cbc:LineExtensionAmount": {
133133
"@_currencyID": "SAR",
134134
"#text": line_item_total_tax_exclusive
135135
},
136-
// .. TODO
137136
"cac:TaxTotal": cacTaxTotal,
138-
// .. TODO
139137
"cac:Item": {
140138
"cbc:Name": line_item.name,
141139
"cac:ClassifiedTaxCategory": cacClassifiedTaxCategories
142140
},
143-
// .. TODO
144141
"cac:Price": {
145142
"cbc:PriceAmount": {
146143
"@_currencyID": "SAR",
147144
"#text": line_item.tax_exclusive_price
148145
},
149-
// .. TODO
150146
"cac:AllowanceCharge": cacAllowanceCharges
151147
}
152148
},
@@ -161,7 +157,6 @@ export class ZATCASimplifiedTaxInvoice {
161157

162158
private constructLegalMonetaryTotal = (tax_exclusive_subtotal: number, taxes_total: number) => {
163159

164-
// TODO: amount decimals according to ZATCA
165160
return {
166161
"cbc:LineExtensionAmount": {
167162
"@_currencyID": "SAR",
@@ -276,7 +271,7 @@ export class ZATCASimplifiedTaxInvoice {
276271

277272

278273
if(props.cancelation) {
279-
// Invoice canceled. Make it a credit/debit note
274+
// Invoice canceled. Tunred into credit/debit note. Must have PaymentMeans
280275
// BR-KSA-17
281276
this.invoice_xml.set("Invoice/cac:PaymentMeans", false, {
282277
"cbc:PaymentMeansCode": props.cancelation.payment_method,

src/zatca/api/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import axios from "axios";
22
import { cleanUpCertificateString } from "../signing";
3-
import { ZATCASimplifiedTaxInvoice } from "../ZATCASimplifiedTaxInvoice";
43

54

65
const settings = {

src/zatca/egs/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const generateSecp256k1KeyPair = async (): Promise<string> => {
7878

7979
// Generate a signed ecdsaWithSHA256 CSR
8080
// 2.2.2 Profile specification of the Cryptographic Stamp identifiers. & CSR field contents / RDNs.
81-
const generateCSR = async (egs_info: EGSUnitInfo, production: boolean): Promise<string> => {
81+
const generateCSR = async (egs_info: EGSUnitInfo, production: boolean, solution_name: string): Promise<string> => {
8282
if (!egs_info.private_key) throw new Error("EGS has no private key");
8383

8484
// This creates a temporary private file, and csr config file to pass to OpenSSL in order to create and sign the CSR.
@@ -90,7 +90,7 @@ const generateCSR = async (egs_info: EGSUnitInfo, production: boolean): Promise<
9090
fs.writeFileSync(csr_config_file, defaultCSRConfig({
9191
egs_model: egs_info.model,
9292
egs_serial_number: egs_info.uuid,
93-
solution_name: "TODONAME",
93+
solution_name: solution_name,
9494
vat_number: egs_info.VAT_number,
9595
branch_location: `${egs_info.location.building} ${egs_info.location.street}, ${egs_info.location.city}`,
9696
branch_industry: egs_info.branch_industry,
@@ -151,15 +151,16 @@ export class EGS {
151151
* Generates a new secp256k1 Public/Private key pair for the EGS.
152152
* Also generates and signs a new CSR.
153153
* `Note`: This functions uses OpenSSL thus requires it to be installed on whatever system the package is running in.
154-
* @param Boolean Production CSR or Compliance CSR
154+
* @param production Boolean CSR or Compliance CSR
155+
* @param solution_name String name of solution generating certs.
155156
* @returns Promise void on success, throws error on fail.
156157
*/
157-
async generateNewKeysAndCSR(production: boolean): Promise<any> {
158+
async generateNewKeysAndCSR(production: boolean, solution_name: string): Promise<any> {
158159
try {
159160
const new_private_key = await generateSecp256k1KeyPair();
160161
this.egs_info.private_key = new_private_key;
161162

162-
const new_csr = await generateCSR(this.egs_info, production);
163+
const new_csr = await generateCSR(this.egs_info, production, solution_name);
163164
this.egs_info.csr = new_csr;
164165
} catch (error) {
165166
throw error;

src/zatca/templates/simplified_tax_invoice_template.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export interface ZATCASimplifiedInvoiceLineItem {
109109
export interface ZATCASimplifiedInvoicCancelation{
110110
canceled_invoice_number: number,
111111
payment_method: ZATCAPaymentMethods,
112+
cancelation_type: ZATCAInvoiceTypes,
112113
reason: string
113114
}
114115

@@ -126,8 +127,7 @@ export interface ZATCASimplifiedInvoiceProps {
126127
export default function populate(props: ZATCASimplifiedInvoiceProps): string {
127128
let populated_template = template;
128129

129-
// TODO Debit or Credit selection
130-
populated_template = populated_template.replace("SET_INVOICE_TYPE", props.cancelation ? ZATCAInvoiceTypes.CREDIT_NOTE : ZATCAInvoiceTypes.INVOICE);
130+
populated_template = populated_template.replace("SET_INVOICE_TYPE", props.cancelation ? props.cancelation.cancelation_type : ZATCAInvoiceTypes.INVOICE);
131131
// if canceled (BR-KSA-56) set reference number to canceled invoice
132132
if(props.cancelation) {
133133
populated_template = populated_template.replace("SET_BILLING_REFERENCE", defaultBillingReference(props.cancelation.canceled_invoice_number));

0 commit comments

Comments
 (0)