new Note(taxpayer, customer, isCredit)
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
taxpayer |
module:person~Taxpayer | Taxpayer with all their details ready. |
customer |
module:person~Person | Generic person. |
isCredit |
boolean | Must be boolean to choose between credit as true or false for debit. |
Extends
Members
billingDocumentReference
- Source:
Methods
addDocumentReference(documentReference)
- Description:
Add a document reference and when it is billing reference, set it only once.
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
documentReference |
module:receipt~DocumentReference |
addItem(item, withoutCalculationopt) → {void}
- Description:
Adds an item to the collection or cart.
- Source:
- Overrides:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
item |
module:receipt~Item | The item to be added. |
||
withoutCalculation |
boolean |
<optional> |
false
|
If true, skips recalculating totals after adding the item. |
Returns:
This function does not return a value.
- Type
- void
clearItems()
- Description:
Clear all items setting the array of items to empty.
- Source:
- Overrides:
createXmlWrapper()
- Description:
Create new XML document.
- Source:
- Overrides:
(async) createZip(type, xmlStringopt) → {Promise.<any>}
- Description:
Create a ZIP file containing XML. Default type is base64.
- Source:
- Overrides:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
type |
"base64" | "string" | "text" | "binarystring" | "array" | "uint8array" | "arraybuffer" | "blob" | "nodebuffer" |
base64
|
according JSZip API. |
|
xmlString |
string |
<optional> |
that is raw XML. |
Returns:
A ZIP file containing XML.
- Type
- Promise.<any>
(async) declare(zipStream) → {Promise.<string>}
- Description:
Declare the document sending it to server.
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
zipStream |
string | The zip file. |
Returns:
The proof of the document.
- Type
- Promise.<string>
(async) finalize(cryptoSubtle, canonMethod)
- Description:
Finalize the document signing it.
- Source:
- Overrides:
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
cryptoSubtle |
SubtleCrypto | The crypto subtle to use for signing. |
|
canonMethod |
string |
c14n
|
The canonicalization method to use for signing. |
fromXml()
- Source:
- Overrides:
Returns:
xmlDoc parsed
getCurrencyId() → {string}
- Source:
- Overrides:
Returns:
- Type
- string
getCustomer() → {module:person~Person}
- Source:
- Overrides:
Returns:
The customer set in constructor.
- Type
- module:person~Person
getCustomizationId() → {string}
- Source:
- Overrides:
Returns:
The customization ID.
- Type
- string
getDocumentReference() → {string}
- Source:
- Deprecated:
- Yes
Returns:
- Type
- string
getDocumentReferenceTypeCode(withFormat) → {string}
- Source:
- Deprecated:
- Yes
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
withFormat |
boolean |
false
|
Returns:
- Type
- string
getHash() → {string}
- Source:
- Overrides:
Returns:
The cryptographic hash of the document.
- Type
- string
getId(withType, compacted) → {string}
- Description:
Format serie and number: F000-00000001
- Source:
- Overrides:
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
withType |
boolean |
false
|
Include type code. |
compacted |
boolean |
false
|
Compact format. |
Returns:
- Type
- string
getIssueDate() → {Date}
- Source:
- Overrides:
Returns:
The issue date of the document.
- Type
- Date
getNumeration() → {number}
- Source:
- Overrides:
Returns:
The numeration of the document.
- Type
- number
getOperationAmount(index) → {number}
- Description:
Access to operation amounts array stored in 4 cells.
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
index |
number | from 0 to 3 |
Returns:
- Value of operation amount.
- Type
- number
getQrData() → {string}
- Description:
Gets the QR data that is header of this document separated by pipes.
RUC|Serie|Numero|Igv|Total|Fecha|TipoDoc|NumDoc
- Source:
- Overrides:
Returns:
- Type
- string
getSerie() → {string}
- Source:
- Overrides:
Returns:
The serie of the document.
- Type
- string
getTaxpayer() → {module:person~Taxpayer}
- Source:
- Overrides:
Returns:
The taxpayer set in constructor.
getTypeCode(withFormat) → {number|string}
- Source:
- Overrides:
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
withFormat |
boolean |
false
|
Format the type code. |
Returns:
The type code of the document.
- Type
- number | string
getUblVersion() → {string}
- Source:
- Overrides:
Returns:
The UBL version.
- Type
- string
(async) handleProof(zipStream, isBase64, compacted) → {Promise.<Array.<(number|string)>>}
- Description:
Handle answer that is in a ZIP file.
- Source:
- Overrides:
Example
Handling CDR
const [cdrCode, cdrDescription] = await invoice.handleProof(serverZipStream)
if (cdrCode === 0) {
console.log("OK", cdrDescription)
}
else {
console.log(cdrDescription)
}
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
zipStream |
string | The zip file. |
|
isBase64 |
boolean |
true
|
Whether the zip file is base64. |
compacted |
boolean |
false
|
Whether the document is compacted. |
Returns:
Code and description in the proof of the document.
- Type
- Promise.<Array.<(number|string)>>
recalcMounts()
- Description:
Use it if maybe you have edited an item or removed.
- Source:
- Overrides:
removeItem(index)
- Description:
Recreate items array without an item.
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
index |
number | The index of the item to remove. |
setCurrencyId(cid)
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
cid |
string | ISO 4217 currency code. |
setDocumentReference(reference)
- Description:
Set identifier of document reference like F000-12345678.
- Source:
- Deprecated:
- Yes
Parameters:
| Name | Type | Description |
|---|---|---|
reference |
string |
setDocumentReferenceTypeCode(code)
- Source:
- Deprecated:
- Yes
Parameters:
| Name | Type | Description |
|---|---|---|
code |
number |
setDueDate(date)
- Description:
Empty hook to be overridden by subclasses. Invoice overrides it.
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
date |
Date | The due date. |
setHash(hash)
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
hash |
string | The cryptographic hash of the document. |
setId(serie, numeration)
- Description:
Set serie and number at once.
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
serie |
string | The serie of the document. |
numeration |
number | The numeration of the document. |
setIssueDate(date)
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
date |
Date | The issue date of the document. |
setName(name)
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | The name of the document. |
setNumeration(number)
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
number |
number | The numeration of the document from 1 to 99999999. |
setOperationAmount(index, amount)
- Description:
Store an operation amount in cell of the array.
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
index |
number | from 0 to 3 |
amount |
number | Value of operation amount. |
setSerie(serie)
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
serie |
string | The serie of the document with 4 characters. |
setTaxpayer(taxpayer)
- Description:
Replace the taxpayer.
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
taxpayer |
module:person~Taxpayer | The new taxpayer. |
setTypeCode(code)
- Description:
Set type again for converting note in credit note or debit note.
You don't need it when you set it in constructor.
- Source:
- Overrides:
Examples
Set as credit note
note.setTypeCode(7)
Set as debit note
note.setTypeCode(8)
Parameters:
| Name | Type | Description |
|---|---|---|
code |
number | Number 7 for credit, number 8 for debit. |
setUblVersion(ublVersion)
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
ublVersion |
string |
(async) sign(cryptoSubtle, canonMethod)
- Source:
- Overrides:
- Deprecated:
- Use finalize() instead for better performance and architecture.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
cryptoSubtle |
SubtleCrypto | The crypto subtle to use for signing. |
|
canonMethod |
string |
c14n
|
The canonicalization method to use for signing. |
toString() → {string}
- Description:
Convert the document to XML string.
It includes signature node if the document was finalized.
- Source:
- Overrides:
Returns:
The XML string.
- Type
- string
unsetId()
- Description:
Unset serie and number to set an anonymous document.
- Source:
- Overrides:
(async) validateXmlWithXsd(mainXsdContent, importedXsdContents) → {Promise.<boolean>}
- Description:
Validate own XML against XSD.
- Source:
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
mainXsdContent |
string | Main XSD content. |
importedXsdContents |
Array.<string> | Array of imported XSD contents. |
Returns:
- false if there are errors.
- Type
- Promise.<boolean>