Despatch

receipt~ Despatch

new Despatch()

Source:

Extends

Methods

addDocumentReference(documentReference)

Description:
  • Add document reference according internal type code.
    Stores documents in its own array by its reference type.

Source:
Overrides:
Parameters:
Name Type Description
documentReference module:receipt~DocumentReference

addItem(item)

Source:
Overrides:
Parameters:
Name Type Description
item module:receipt~Item

The item to add.

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(xmlContent)

Description:
  • Parse receipt header.

Source:
Overrides:
Parameters:
Name Type Description
xmlContent string

The XML content of the document.

Returns:

xmlDoc parsed.

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

getDespatchAddress(real)

Source:
Parameters:
Name Type Default Description
real false

in true to force getting what was set instead fiscal address.

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

getSerie() → {string}

Source:
Overrides:
Returns:

The serie of the document.

Type
string

getTaxpayer() → {module:person~Taxpayer}

Source:
Overrides:
Returns:

The taxpayer set in constructor.

Type
module:person~Taxpayer

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)>>

removeItem(index)

Description:
  • Recreate items array without an item.

Source:
Overrides:
Parameters:
Name Type Description
index number

The index of the item to remove.

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.

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)

Source:
Overrides:
Parameters:
Name Type Description
code number

The type code of the document.

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>