TalerTaxMap
extends CommonObject
in package
Class TalerTaxMap
Maintains a mapping between Taler-side tax definitions and Dolibarr's VAT dictionary
(c_tva). Provides CRUD, finders, and idempotent upsert helpers used by sync flows.
Table of Contents
Properties
- $datec : mixed
- $element : string
- $entity : mixed
- $fields : mixed
- $fk_c_tva : mixed
- $isextrafieldmanaged : int
- $ismultientitymanaged : int|string
- $module : string
- $picto : string
- $rowid : mixed
- $table_element : string
- $taler_instance : mixed
- $taler_tax_amount_hint : mixed
- $taler_tax_name : mixed
- $tms : mixed
- $vat_rate : mixed
Methods
- __construct() : mixed
- Constructor.
- create() : int
- Create record.
- delete() : int
- Delete record.
- fetch() : int
- Fetch a record by id/ref.
- fetchByCtvA() : int
- Fetch first row for a given fk_c_tva (many-to-one; convenience).
- fetchByInstanceName() : int
- Fetch by unique key (entity, taler_instance, taler_tax_name).
- getLabelForList() : string
- Human-friendly label for list rows.
- getNomUrl() : string
- Build object link for lists and cards.
- guessVatRateFromName() : float|null
- Try to guess VAT rate (percent) from "VAT 7%"-like names.
- normalizeRate() : float
- Normalize a float rate to 3 decimals as stored in DB (e.g., 7 -> 7.000).
- parseAmountHint() : array{currency: string, amount: string}|null
- Parse a "CUR:amount" hint (e.g., "EUR:0.70").
- resolveCtvAByRate() : int|null
- Try to resolve a c_tva id by exact/nearest taux.
- update() : int
- Update record.
- upsert() : int
- Idempotent upsert by unique key (entity, instance, tax_name).
- upsertFromDolibarr() : int
- Sync one Dolibarr VAT line into the mapping table.
- upsertFromTaler() : int
- Sync one Tax object coming from Taler into the mapping table.
Properties
$datec
public
mixed
$datec
$element
public
string
$element
= 'talertaxmap'
$entity
public
mixed
$entity
$fields
public
mixed
$fields
= array('rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'visible' => 0, 'notnull' => 1, 'index' => 1, 'position' => 1), 'entity' => array('type' => 'integer', 'label' => 'Entity', 'visible' => 0, 'notnull' => 1, 'default' => 1, 'index' => 1, 'position' => 5), 'taler_instance' => array('type' => 'varchar(64)', 'label' => 'TalerInstance', 'visible' => 1, 'notnull' => 1, 'index' => 1, 'position' => 10), 'taler_tax_name' => array('type' => 'varchar(128)', 'label' => 'TalerTaxName', 'visible' => 1, 'notnull' => 1, 'index' => 1, 'position' => 11), 'taler_tax_amount_hint' => array('type' => 'varchar(64)', 'label' => 'TalerTaxAmountHint', 'visible' => 1, 'notnull' => 0, 'position' => 12, 'help' => 'e.g. EUR:0.70'), 'vat_rate' => array('type' => 'double(6,3)', 'label' => 'VatRate', 'visible' => 1, 'notnull' => 0, 'position' => 20, 'help' => 'e.g. 7.000'), 'fk_c_tva' => array('type' => 'integer', 'label' => 'FkCTva', 'visible' => 1, 'notnull' => 0, 'index' => 1, 'position' => 21), 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'visible' => -2, 'notnull' => 0, 'position' => 500), 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'visible' => -2, 'notnull' => 1, 'position' => 501))
$fk_c_tva
public
mixed
$fk_c_tva
$isextrafieldmanaged
public
int
$isextrafieldmanaged
= 0
$ismultientitymanaged
public
int|string
$ismultientitymanaged
= 1
$module
public
string
$module
= 'talerbarr'
$picto
public
string
$picto
= 'fa-percent'
$rowid
public
mixed
$rowid
$table_element
public
string
$table_element
= 'talerbarr_tax_map'
$taler_instance
public
mixed
$taler_instance
$taler_tax_amount_hint
public
mixed
$taler_tax_amount_hint
$taler_tax_name
public
mixed
$taler_tax_name
$tms
public
mixed
$tms
$vat_rate
public
mixed
$vat_rate
Methods
__construct()
Constructor.
public
__construct(DoliDB $db) : mixed
Parameters
- $db : DoliDB
-
Database handler.
create()
Create record.
public
create(User $user[, int $notrigger = 1 ]) : int
Parameters
- $user : User
-
User performing the creation (used by triggers/audit).
- $notrigger : int = 1
-
Set to 1 to disable triggers.
Return values
int —0 on success, <0 on error.
delete()
Delete record.
public
delete(User $user[, int $notrigger = 1 ]) : int
Parameters
- $user : User
-
User performing the deletion.
- $notrigger : int = 1
-
Set to 1 to disable triggers.
Return values
int —0 on success, <0 on error.
fetch()
Fetch a record by id/ref.
public
fetch(int|string $id[, string|null $ref = null ][, int $noextrafields = 1 ][, int $nolines = 1 ]) : int
Parameters
- $id : int|string
-
Row ID (preferred) or technical ref.
- $ref : string|null = null
-
Optional ref if fetching by reference.
- $noextrafields : int = 1
-
1 to skip extrafields fetch for performance.
- $nolines : int = 1
-
Unused here (CommonObject compatibility).
Return values
int —0 if OK, 0 if not found, <0 on error.
fetchByCtvA()
Fetch first row for a given fk_c_tva (many-to-one; convenience).
public
fetchByCtvA(int $fkCTva) : int
Parameters
- $fkCTva : int
-
Rowid in c_tva.
Return values
int —0 if loaded, 0 if not found, <0 on SQL error.
fetchByInstanceName()
Fetch by unique key (entity, taler_instance, taler_tax_name).
public
fetchByInstanceName(string $instance, string $taxName) : int
Parameters
- $instance : string
-
Taler instance identifier.
- $taxName : string
-
Tax name on the Taler side.
Return values
int —0 if loaded, 0 if not found, <0 on SQL error.
getLabelForList()
Human-friendly label for list rows.
public
getLabelForList() : string
Return values
string —Readable label: "
getNomUrl()
Build object link for lists and cards.
public
getNomUrl([int $withpicto = 0 ][, string $option = '' ][, int $notooltip = 0 ][, string $morecss = '' ][, int $save_lastsearch_value = -1 ]) : string
Parameters
- $withpicto : int = 0
-
0 = no picto, 1 = picto + label, 2 = picto only.
- $option : string = ''
-
'nolink' to disable anchor; anything else enables link.
- $notooltip : int = 0
-
1 to disable tooltip (kept for API compatibility).
- $morecss : string = ''
-
Extra CSS classes to add to the link.
- $save_lastsearch_value : int = -1
-
Keep -1 to use default behavior.
Return values
string —HTML for object link.
guessVatRateFromName()
Try to guess VAT rate (percent) from "VAT 7%"-like names.
public
static guessVatRateFromName(string $name) : float|null
Parameters
- $name : string
-
Tax name possibly containing a percentage.
Return values
float|null —Rate in percent (e.g., 7.0) or null if no match.
normalizeRate()
Normalize a float rate to 3 decimals as stored in DB (e.g., 7 -> 7.000).
public
normalizeRate(float $rate) : float
Parameters
- $rate : float
-
Raw rate in percent.
Return values
float —Normalized rate with 3 decimals.
parseAmountHint()
Parse a "CUR:amount" hint (e.g., "EUR:0.70").
public
static parseAmountHint(string|null $s) : array{currency: string, amount: string}|null
Parameters
- $s : string|null
-
Raw hint string or null.
Return values
array{currency: string, amount: string}|null —Parsed result or null if invalid.
resolveCtvAByRate()
Try to resolve a c_tva id by exact/nearest taux.
public
resolveCtvAByRate(float $ratePercent[, float $tolerance = 0.001 ][, int|null $countryId = null ]) : int|null
Parameters
- $ratePercent : float
-
Rate in percent, e.g., 7.0.
- $tolerance : float = 0.001
-
Allowed absolute delta, e.g., 0.001 for exact.
- $countryId : int|null = null
-
Optional country filter (fk_pays); defaults to company country.
Return values
int|null —Matching c_tva.rowid or null if none within tolerance.
update()
Update record.
public
update(User $user[, int $notrigger = 1 ]) : int
Parameters
- $user : User
-
User performing the update.
- $notrigger : int = 1
-
Set to 1 to disable triggers.
Return values
int —0 on success, 0 if no change, <0 on error.
upsert()
Idempotent upsert by unique key (entity, instance, tax_name).
public
upsert(User $user, string $instance, string $taxName[, string|null $amountHint = null ][, float|null $vatRate = null ][, int|null $fkCTva = null ]) : int
Any parameter can be null to "leave as-is" on update.
Parameters
- $user : User
-
User performing the upsert.
- $instance : string
-
Taler instance identifier.
- $taxName : string
-
Tax name on Taler side.
- $amountHint : string|null = null
-
Optional amount hint "CUR:amount" (e.g., "EUR:0.70").
- $vatRate : float|null = null
-
VAT rate in percent (e.g., 7.0) or null.
- $fkCTva : int|null = null
-
Optional FK to c_tva row.
Return values
int —0 row id, <0 on error.
upsertFromDolibarr()
Sync one Dolibarr VAT line into the mapping table.
public
static upsertFromDolibarr(DoliDB $db, User $user, int $fkCTva, string $instance[, string|null $amountHint = null ]) : int
Parameters
- $db : DoliDB
-
Database handler.
- $user : User
-
Current user.
- $fkCTva : int
-
Rowid in c_tva.
- $instance : string
-
Taler instance.
- $amountHint : string|null = null
-
Optional “CUR:amount” hint (rarely used).
Return values
int —0 rowid of talerbarr_tax_map, 0 ignored, <0 error.
upsertFromTaler()
Sync one Tax object coming from Taler into the mapping table.
public
static upsertFromTaler(DoliDB $db, User $user, string $instance, array<string|int, mixed>|object $tax[, string|null $priceHint = null ]) : int
Parameters
- $db : DoliDB
-
Database handler.
- $user : User
-
Current user.
- $instance : string
-
Taler instance.
- $tax : array<string|int, mixed>|object
-
One element of Taler’s “taxes” array (name/tax fields expected).
- $priceHint : string|null = null
-
Optional price string "CUR:amount" of the product to guess rate from tax amount.
Return values
int —0 rowid, 0 ignored, <0 error.