myinvois-sdk
Version:
TypeScript SDK for interacting with the Malaysia e-invoicing system (MyInvois) API
96 lines (95 loc) • 3.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DocumentTypeDescriptions = exports.DocumentType = void 0;
exports.isStandardDocument = isStandardDocument;
exports.isSelfBilledDocument = isSelfBilledDocument;
exports.isInvoice = isInvoice;
exports.isCreditNote = isCreditNote;
exports.isDebitNote = isDebitNote;
exports.isRefundNote = isRefundNote;
/**
* Enum for document types supported by MyInvois
* Based on official documentation
*/
var DocumentType;
(function (DocumentType) {
// Standard document types
DocumentType["INVOICE"] = "01";
DocumentType["CREDIT_NOTE"] = "02";
DocumentType["DEBIT_NOTE"] = "03";
DocumentType["REFUND_NOTE"] = "04";
// Self-billed document types
DocumentType["SELF_BILLED_INVOICE"] = "05";
DocumentType["SELF_BILLED_CREDIT_NOTE"] = "06";
DocumentType["SELF_BILLED_DEBIT_NOTE"] = "07";
DocumentType["SELF_BILLED_REFUND_NOTE"] = "08"; // Self-billed refund note
})(DocumentType || (exports.DocumentType = DocumentType = {}));
/**
* Map of document type codes to human-readable descriptions
*/
exports.DocumentTypeDescriptions = {
'01': 'Invoice',
'02': 'Credit Note',
'03': 'Debit Note',
'04': 'Refund Note',
'05': 'Self-Billed Invoice',
'06': 'Self-Billed Credit Note',
'07': 'Self-Billed Debit Note',
'08': 'Self-Billed Refund Note'
};
/**
* Returns true if the document type is a standard (non-self-billed) document
* @param documentType The document type to check
*/
function isStandardDocument(documentType) {
return [
DocumentType.INVOICE,
DocumentType.CREDIT_NOTE,
DocumentType.DEBIT_NOTE,
DocumentType.REFUND_NOTE
].includes(documentType);
}
/**
* Returns true if the document type is a self-billed document
* @param documentType The document type to check
*/
function isSelfBilledDocument(documentType) {
return [
DocumentType.SELF_BILLED_INVOICE,
DocumentType.SELF_BILLED_CREDIT_NOTE,
DocumentType.SELF_BILLED_DEBIT_NOTE,
DocumentType.SELF_BILLED_REFUND_NOTE
].includes(documentType);
}
/**
* Returns true if the document is an invoice (standard or self-billed)
* @param documentType The document type to check
*/
function isInvoice(documentType) {
return documentType === DocumentType.INVOICE ||
documentType === DocumentType.SELF_BILLED_INVOICE;
}
/**
* Returns true if the document is a credit note (standard or self-billed)
* @param documentType The document type to check
*/
function isCreditNote(documentType) {
return documentType === DocumentType.CREDIT_NOTE ||
documentType === DocumentType.SELF_BILLED_CREDIT_NOTE;
}
/**
* Returns true if the document is a debit note (standard or self-billed)
* @param documentType The document type to check
*/
function isDebitNote(documentType) {
return documentType === DocumentType.DEBIT_NOTE ||
documentType === DocumentType.SELF_BILLED_DEBIT_NOTE;
}
/**
* Returns true if the document is a refund note (standard or self-billed)
* @param documentType The document type to check
*/
function isRefundNote(documentType) {
return documentType === DocumentType.REFUND_NOTE ||
documentType === DocumentType.SELF_BILLED_REFUND_NOTE;
}