UNPKG

myinvois-sdk

Version:

TypeScript SDK for interacting with the Malaysia e-invoicing system (MyInvois) API

181 lines (180 loc) 5.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Party = void 0; const base_model_1 = require("./base-model"); const address_1 = require("./address"); /** * Represents a party (supplier, customer, etc.) */ class Party extends base_model_1.BaseModel { constructor() { super(...arguments); // Party identification this._name = ''; this._taxId = ''; this._registrationId = ''; // MANDATORY: Business Registration Number or other ID this._registrationType = 'BRN'; // MANDATORY: BRN, SST, NRIC, etc. this._sstRegistrationNo = ''; this._msicCode = ''; this._msicDescription = ''; // Contact details this._phone = ''; this._email = ''; // Address this._address = new address_1.Address(); } // Getter and Setter for name get name() { return this._name; } set name(value) { this._name = value; } // Getter and Setter for taxId get taxId() { return this._taxId; } set taxId(value) { this._taxId = value; } // Getter and Setter for registrationId get registrationId() { return this._registrationId; } set registrationId(value) { this._registrationId = value; } // Getter and Setter for registrationType get registrationType() { return this._registrationType; } set registrationType(value) { this._registrationType = value; } // Getter and Setter for sstRegistrationNo get sstRegistrationNo() { return this._sstRegistrationNo; } set sstRegistrationNo(value) { this._sstRegistrationNo = value; } // Getter and Setter for msicCode get msicCode() { return this._msicCode; } set msicCode(value) { this._msicCode = value; } // Getter and Setter for msicDescription get msicDescription() { return this._msicDescription; } set msicDescription(value) { this._msicDescription = value; } // Getter and Setter for phone get phone() { return this._phone; } set phone(value) { this._phone = value; } // Getter and Setter for email get email() { return this._email; } set email(value) { this._email = value; } // Getter and Setter for address get address() { return this._address; } set address(value) { this._address = value; } /** * Converts the party to a JSON representation * Requires registrationId and registrationType to be set * @throws Error if mandatory fields are not provided */ toJSON() { // Validate mandatory fields if (!this._registrationId) { throw new Error('Party registrationId is mandatory and must be provided'); } if (!this._registrationType) { throw new Error('Party registrationType is mandatory and must be provided'); } const partyIdentifications = []; // Add TIN (tax id) if (this._taxId) { partyIdentifications.push({ "ID": [ { "_": this._taxId, "schemeID": "TIN" } ] }); } // Add registration ID (now mandatory) partyIdentifications.push({ "ID": [ { "_": this._registrationId, "schemeID": this._registrationType } ] }); // Add SST registration number if available if (this._sstRegistrationNo) { partyIdentifications.push({ "ID": [ { "_": this._sstRegistrationNo, "schemeID": "SST" } ] }); } const partyObj = { "PostalAddress": [this._address.toJSON()], "PartyLegalEntity": [ { "RegistrationName": [ { "_": this._name } ] } ], "PartyIdentification": partyIdentifications, "Contact": [ { "Telephone": [ { "_": this._phone } ], "ElectronicMail": [ { "_": this._email } ] } ] }; // Add MSIC code if available (for suppliers) if (this._msicCode) { partyObj["IndustryClassificationCode"] = [ { "_": this._msicCode, "name": this._msicDescription } ]; } return partyObj; } } exports.Party = Party;