Class: Dolibarr::RecurringInvoices

Inherits:
Resource
  • Object
show all
Defined in:
lib/dolibarr/recurring_invoices.rb

Overview

Recurring / template invoices ("factures modèles"). Read-only: Dolibarr 23.0.3 exposes only GET on /invoices/templates — creating a template or triggering a generation is not available over REST (it happens in the UI or the internal cron).

Returns normalised hashes (amounts coerced); the generated child invoices surface in the ordinary Invoices domain, where the full cycle (validate/pay/close) lives.

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Dolibarr::Resource

Instance Method Details

#all(**filters) ⇒ Array<Hash>

Returns:

  • (Array<Hash>)


38
39
40
# File 'lib/dolibarr/recurring_invoices.rb', line 38

def all(**filters)
  each(**filters).to_a
end

#each(limit: 100, **filters, &block) ⇒ Object

Every matching template, paginating transparently. Enumerator when no block.



32
33
34
35
# File 'lib/dolibarr/recurring_invoices.rb', line 32

def each(limit: 100, **filters, &block)
  enum = paginate(limit: limit) { |page, lim| list(page: page, limit: lim, **filters) }
  block ? enum.each(&block) : enum
end

#find(id:) ⇒ Hash

Fetch a single template invoice by id.

Parameters:

  • id (Integer, String)

Returns:

  • (Hash)

    normalised payload

Raises:



47
48
49
# File 'lib/dolibarr/recurring_invoices.rb', line 47

def find(id:)
  Coerce.amounts(get_one("/invoices/templates/#{encode(id)}", "template invoice #{id}"))
end

#list(thirdparty_id: nil, status: nil, sqlfilters: nil, limit: 100, page: 0, sortfield: 't.rowid', sortorder: 'ASC') ⇒ Array<Hash>

One page of template invoices as normalised hashes.

Parameters:

  • thirdparty_id (Integer, String, nil) (defaults to: nil)

    restrict to a customer

  • status (String, nil) (defaults to: nil)

    Dolibarr status filter

  • sqlfilters (String, nil) (defaults to: nil)

    raw Restler sqlfilter

  • limit (Integer) (defaults to: 100)

    page size

  • page (Integer) (defaults to: 0)

    0-based page index

  • sortfield (String) (defaults to: 't.rowid')
  • sortorder (String) (defaults to: 'ASC')

Returns:

  • (Array<Hash>)


21
22
23
24
25
26
27
28
29
# File 'lib/dolibarr/recurring_invoices.rb', line 21

def list(thirdparty_id: nil, status: nil, sqlfilters: nil,
         limit: 100, page: 0, sortfield: 't.rowid', sortorder: 'ASC')
  get_list(
    '/invoices/templates',
    'sortfield' => sortfield, 'sortorder' => sortorder,
    'limit' => limit, 'page' => page,
    'thirdparty_ids' => thirdparty_id, 'status' => status, 'sqlfilters' => sqlfilters
  ).map { |raw| Coerce.amounts(raw) }
end