Skip to content

Commit

Permalink
FIX: use rounding to compare the amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
atm-florianm committed Jul 29, 2019
1 parent fe9ddd7 commit 858e8a8
Showing 1 changed file with 32 additions and 10 deletions.
Expand Up @@ -105,8 +105,8 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
if ($element->statut == Propal::STATUS_SIGNED || $element->statut == Propal::STATUS_BILLED) $totalonlinkedelements += $element->total_ht;
}
dol_syslog( "Amount of linked proposals = ".$totalonlinkedelements.", of order = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht) );
if ( ($totalonlinkedelements == $object->total_ht) || (! empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) )
{
if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht))
{
foreach($object->linkedObjects['propal'] as $element)
{
$ret=$element->classifyBilled($user);
Expand Down Expand Up @@ -134,7 +134,7 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
if ($element->statut == Commande::STATUS_VALIDATED || $element->statut == Commande::STATUS_SHIPMENTONPROCESS || $element->statut == Commande::STATUS_CLOSED) $totalonlinkedelements += $element->total_ht;
}
dol_syslog( "Amount of linked orders = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht) );
if ( ($totalonlinkedelements == $object->total_ht) || (! empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) )
if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht))
{
foreach($object->linkedObjects['commande'] as $element)
{
Expand All @@ -157,8 +157,8 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
if ($element->statut == Propal::STATUS_SIGNED || $element->statut == Propal::STATUS_BILLED) $totalonlinkedelements += $element->total_ht;
}
dol_syslog( "Amount of linked proposals = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht) );
if ( ($totalonlinkedelements == $object->total_ht) || (! empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) )
{
if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht))
{
foreach($object->linkedObjects['propal'] as $element)
{
$ret=$element->classifyBilled($user);
Expand Down Expand Up @@ -186,8 +186,8 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
if ($element->statut == CommandeFournisseur::STATUS_ACCEPTED || $element->statut == CommandeFournisseur::STATUS_ORDERSENT || $element->statut == CommandeFournisseur::STATUS_RECEIVED_PARTIALLY || $element->statut == CommandeFournisseur::STATUS_RECEIVED_COMPLETELY) $totalonlinkedelements += $element->total_ht;
}
dol_syslog( "Amount of linked orders = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht) );
if ( ($totalonlinkedelements == $object->total_ht) || (! empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) )
{
if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht))
{
foreach($object->linkedObjects['order_supplier'] as $element)
{
$ret=$element->classifyBilled($user);
Expand All @@ -209,8 +209,8 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
if ($element->statut == SupplierProposal::STATUS_SIGNED || $element->statut == SupplierProposal::STATUS_BILLED) $totalonlinkedelements += $element->total_ht;
}
dol_syslog( "Amount of linked supplier proposals = ".$totalonlinkedelements.", of supplier invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht) );
if ( ($totalonlinkedelements == $object->total_ht) || (! empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) )
{
if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht))
{
foreach($object->linkedObjects['supplier_proposal'] as $element)
{
$ret=$element->classifyBilled($user);
Expand All @@ -237,7 +237,7 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
if ($element->statut == Commande::STATUS_VALIDATED || $element->statut == Commande::STATUS_SHIPMENTONPROCESS || $element->statut == Commande::STATUS_CLOSED) $totalonlinkedelements += $element->total_ht;
}
dol_syslog( "Amount of linked orders = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht) );
if ( ($totalonlinkedelements == $object->total_ht) || (! empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) )
if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht))
{
foreach($object->linkedObjects['commande'] as $element)
{
Expand Down Expand Up @@ -310,4 +310,26 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
return 0;
}

/**
* @param Object $conf Dolibarr settings object
* @param float $totalonlinkedelements Sum of total amounts (excl VAT) of
* invoices linked to $object
* @param float $object_total_ht The total amount (excl VAT) of the object
* (an order, a proposal, a bill, etc.)
* @return bool True if the amounts are equal (arithmetic errors within tolerance margin)
* True if the module is configured to skip the amount equality check
* False otherwise.
*/
private function shouldClassify($conf, $totalonlinkedelements, $object_total_ht)
{
// if the configuration allows unmatching amounts, allow classification anyway
if (!empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) {
return true;
}
// if the rounded amount difference is zero, allow classification, else deny
return 0 == round(
$totalonlinkedelements - $object_total_ht,
$conf->global->MAIN_MAX_DECIMALS_UNIT
);
}
}

0 comments on commit 858e8a8

Please sign in to comment.