DocumentItemUtils
🔧 hasKeyRecursive
Check de façon recursiv si il y a une clé particulière dans un array
function hasKeyRecursive(array $array, string $keyToFind): bool {
if (array_key_exists($keyToFind, $array)) {
return true;
}
// Recursive
foreach ($array as $value) {
if (is_array($value)) {
if ($this->hasKeyRecursive($value, $keyToFind)) {
return true;
}
}
// ... (truncated)
⚙️ Parameters
- $array (array) L'array de recherche (dans le cas d'eteko souvent le $global_modified_att)
- $keyToFind (string) la key à chercher
↩️ Returns
(bool) True if the key is found, orther false
Outil de validation d'inputs
function validateInput( $value, $fieldName): void
{
if ($value === null) {
throw new \InvalidArgumentException("{$fieldName} cannot be null.");
}
⚙️ Parameters
- $value (string)
- $fieldName (string)
⚠️ Throws
- \InvalidArgumentException:
Extract numeric VAT rate
function extractVatRate(?string $vatRateString): string
{
if($vatRateString === null) {
return '0';
}
// Remove percentage sign and any spaces
$rate = str_replace(['%', ' '], '', $vatRateString);
return str_replace(',', '.', $rate);
}
⚙️ Parameters
- $vatRateString (string) VAT rate string ("20%")
↩️ Returns
(string) Numeric VAT rate as string ( "20")
🔧 lineItemToArray
Convert a lineItem_callback object to an array
function lineItemToArray(lineItem_callback $lineItem): array
{
return [
'unit_price' => $lineItem->unit_price,
'vat_rate' => $lineItem->vat_rate,
'quantity' => $lineItem->quantity,
'discount_type' => $lineItem->discount_type,
'discount_value' => $lineItem->discount_value,
'total' => [
'total_ht' => $lineItem->total->total_ht,
'tva_amount' => $lineItem->total->tva_amount,
// ... (truncated)
⚙️ Parameters
- $lineItem (lineItem_callback) The line item object
↩️ Returns
(array) The line item as an array