@accounter/server
Version:
110 lines • 3.39 kB
JavaScript
import { footerBuilder, headerBuilder, headerHandler, transactionBuilder, transactionHandler, } from './utils/index.js';
export var EntryType;
(function (EntryType) {
/**
* Sales – "regular" sale
* identified commercial customer
* עסקה רגילה - מזוהה
* */
EntryType["SALE_REGULAR"] = "S1";
/**
* Sales – "Zero Value/Exempt" sale
* not export
* עסקה אפס - מזוהה
* */
EntryType["SALE_ZERO_OR_EXEMPT"] = "S2";
/**
* Sales – for unidentified (private) customer
* /unidentified-cash
* register aggregation etc
* עסקה רגילה - לא מזוהה
* */
EntryType["SALE_UNIDENTIFIED_CUSTOMER"] = "L1";
/**
* Sales – for unidentified Zero Value/Exempt
* private customer – aggregated
* עסקה אפס - לא מזוהה
* */
EntryType["SALE_UNIDENTIFIED_ZERO_OR_EXEMPT"] = "L2";
/**
* Sales – self invoice
* חשבונית עצמית (עסקה)
* */
EntryType["SALE_SELF_INVOICE"] = "M";
/**
* Sales – export
* */
EntryType["SALE_EXPORT"] = "Y";
/**
* Sales – Palestinian Authority customer. Palestinian customer – Invoice I
* לקוח רש"פ
* */
EntryType["SALE_PALESTINIAN_CUSTOMER"] = "I";
/**
* Input – "regular" from Israeli Supplier
* תשומה רגילה
* */
EntryType["INPUT_REGULAR"] = "T";
/**
* Input – Petty Cash. Various suppliers – Petty Cash
* קופה קטנה
* */
EntryType["INPUT_PETTY_CASH"] = "K";
/**
* Input – Import. Overseas supplier
* רשימון יבוא
* */
EntryType["INPUT_IMPORT"] = "R";
/**
* Input – Supplier from Palestinian Authority. Palestinian supplier – Invoice P
* ספק רש"פ
* */
EntryType["INPUT_PALESTINIAN_SUPPLIER"] = "P";
/**
* Input – Single document by law. Such as Import entry, bank document etc.
* מסמך אחר
* */
EntryType["INPUT_SINGLE_DOC_BY_LAW"] = "H";
/**
* Input – self invoice
* חשבונית עצמית (תשומה)
* */
EntryType["INPUT_SELF_INVOICE"] = "C";
})(EntryType || (EntryType = {}));
export const pcnGenerator = (header, transactions, options = {}) => {
let textFile = '';
// handle header
try {
header = headerHandler(header, options);
}
catch (e) {
throw new Error(`Header validation error: ${e.message}`);
}
textFile += headerBuilder(header);
// sort transactions
const sortedTransactions = options.sort
? transactions.sort((a, b) => {
if (a.entryType > b.entryType) {
return 1;
}
if (a.entryType < b.entryType) {
return -1;
}
return a.invoiceDate > b.invoiceDate ? 1 : -1;
})
: transactions;
// handle transactions
sortedTransactions.map((transaction, i) => {
try {
transaction = transactionHandler(transaction, options);
}
catch (e) {
throw new Error(`Transaction index ${i} validation error: ${e.message}`);
}
textFile += transactionBuilder(transaction);
});
// handle footer
textFile += footerBuilder(header);
return textFile;
};
//# sourceMappingURL=index.js.map