taxRetentions.js

import Resource from './resources';

/**
 * A Tax retention is the amount of money that the payer must
 * deduct from the total amount of a purchase invoice, according
 * to the fiscal institution’s regulations.
 *
 * @extends Resource
 */
class TaxRetentions extends Resource {
  #endpoint = 'api/tax-retentions/'

  /**
   * Retrieve tax retentions information from a specific fiscal link.
   *
   * @async
   * @param {string} link - UUID4 representation of a link Id.
   * @param {string} dateFrom - Required date from, format is YYYY-MM-DD
   * @param {string} dateTo - Required date to, format is YYYY-MM-DD.
   * @param {string} type - Required type, either INFLOW or OUTFLOW
   * @param {object} options - Optional parameters (saveData, attachXML)
   * @returns {object} Response
   * @throws {RequestError}
   */
  async retrieve(link, dateFrom, dateTo, type, options = {}) {
    const {
      saveData, attachXML,
    } = options;

    const data = {
      link,
      date_from: dateFrom,
      date_to: dateTo,
      type,
      save_data: saveData,
      attach_xml: attachXML,
    };

    const result = await this.session.post(this.#endpoint, data);
    return result;
  }
}

export default TaxRetentions;