mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
fe5a97e174
* Fixes for Store Payment Validation * Tests for Payments * Use custom validator to ensure payments are made ONLY to payable invoices * Working on custom payment validators * Update Client balance * fixes for client balance * Fixes for activity API
57 lines
1.1 KiB
PHP
57 lines
1.1 KiB
PHP
<?php
|
|
/**
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://opensource.org/licenses/AAL
|
|
*/
|
|
|
|
namespace App\Http\ValidationRules;
|
|
|
|
use App\Models\Invoice;
|
|
use App\Utils\Traits\MakesHash;
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
|
|
/**
|
|
* Class ValidPayableInvoicesRule
|
|
* @package App\Http\ValidationRules
|
|
*/
|
|
class ValidPayableInvoicesRule implements Rule
|
|
{
|
|
use MakesHash;
|
|
|
|
/**
|
|
* @param string $attribute
|
|
* @param mixed $value
|
|
* @return bool
|
|
*/
|
|
public function passes($attribute, $value)
|
|
{
|
|
|
|
$invoices = Invoice::whereIn('id', $this->transformKeys(explode(",",$value)))->get();
|
|
|
|
if(!$invoices || $invoices->count() == 0)
|
|
return false;
|
|
|
|
foreach ($invoices as $invoice) {
|
|
|
|
if(! $invoice->isPayable())
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function message()
|
|
{
|
|
return "One or more of these invoices have been paid";
|
|
}
|
|
|
|
}
|