Files
SGF/app/Modules/Accounting/AssetDepreciation.php
2026-11-11 15:04:01 +02:00

14 lines
1.7 KiB
PHP

<?php
namespace App\Modules\Accounting;
use Brick\Math\{BigInteger,BigRational};
/** Pure proposed QA straight-line policy. No fiscal rate, asset, journal or clock source. */
final class AssetDepreciation
{
public static function quota(?string $cost,?string $residual,?int $months,int $month):array
{
abort_unless($month>=1&&$month<=600,422);foreach([$cost,$residual]as$value)if($value!==null)abort_unless(preg_match('/^[0-9]{1,12}\.[0-9]{2}$/D',$value)===1,422,'Valor documental deve ter duas casas.');if($months!==null)abort_unless($months>=1&&$months<=600&&$month<=$months,422);
if($cost===null||$residual===null||$months===null)return['complete'=>false,'quota_cents'=>null,'accumulated_cents'=>null,'carrying_cents'=>null,'exact_quota_cents'=>null,'difference_cents'=>null,'legal_tax_treatment'=>null];
$c=BigInteger::of(str_replace('.','',$cost));$r=BigInteger::of(str_replace('.','',$residual));abort_if($r->isGreaterThan($c),422,'Residual excede o custo.');$base=$c->minus($r);$standard=$base->quotient($months);$quota=$month===$months?$base->minus($standard->multipliedBy($months-1)):$standard;$accumulated=$month===$months?$base:$standard->multipliedBy($month);$exact=BigRational::of($base)->dividedBy($months)->simplified();return['complete'=>true,'cost_cents'=>(string)$c,'residual_cents'=>(string)$r,'life_months'=>$months,'month'=>$month,'quota_cents'=>(string)$quota,'accumulated_cents'=>(string)$accumulated,'carrying_cents'=>(string)$c->minus($accumulated),'exact_quota_cents'=>(string)$exact,'difference_cents'=>(string)$exact->minus($quota)->simplified(),'policy'=>'QA-straight-line-floor-months-final-residual-adjustment-v1','legal_tax_treatment'=>null];
}
}