<?php
 namespace App\Utils\Invoices; class DetermineClientInvoiceCashedStatus { protected $invoiceTotal; protected $tolerancePercent; public function __construct(float $invoiceTotal) { $this->invoiceTotal = round($invoiceTotal, 3); $CFG = \Engine\Loader_Cfg::getInstance()->getGlobal(); $this->tolerancePercent = $CFG['invoiceCashing']['statusTolerancePercent']; } public function getStatus(float $cashedValue) :string { $statusTolerance = abs($this->invoiceTotal * $this->tolerancePercent); $cashedStatus = null; if ($this->invoiceTotal==0) { $cashedStatus = 't'; } elseif ($this->invoiceTotal>=0) { if ($cashedValue<$statusTolerance) $cashedStatus='n'; elseif ($cashedValue<($this->invoiceTotal-$statusTolerance)) $cashedStatus='p'; elseif ($cashedValue<($this->invoiceTotal+$statusTolerance)) $cashedStatus='t'; else $cashedStatus='o'; } else { if ($cashedValue>-$statusTolerance) $cashedStatus='n'; elseif ($cashedValue>($this->invoiceTotal+$statusTolerance)) $cashedStatus='p'; elseif ($cashedValue>($this->invoiceTotal-$statusTolerance)) $cashedStatus='t'; else $cashedStatus='o'; } return $cashedStatus; } } 