mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-18 09:04:35 +01:00
54 lines
1.1 KiB
PHP
54 lines
1.1 KiB
PHP
<?php
|
|
/**
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://opensource.org/licenses/AAL
|
|
*/
|
|
|
|
namespace App\Http\ValidationRules\Credit;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
|
|
/**
|
|
* Class CreditsSumRule.
|
|
*/
|
|
class CreditsSumRule implements Rule
|
|
{
|
|
use MakesHash;
|
|
|
|
|
|
private $input;
|
|
|
|
public function __construct($input)
|
|
{
|
|
$this->input = $input;
|
|
}
|
|
|
|
public function passes($attribute, $value)
|
|
{
|
|
return $this->checkCreditTotals();
|
|
}
|
|
|
|
private function checkCreditTotals()
|
|
{
|
|
if (array_sum(array_column($this->input['credits'], 'amount')) > array_sum(array_column($this->input['invoices'], 'amount'))) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function message()
|
|
{
|
|
return "Total credits applied cannot be MORE than total of invoices";
|
|
}
|
|
}
|