1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Http/ValidationRules/ValidPayableInvoicesRule.php
David Bomba fe5a97e174
Activity API fixes + Payments API (#3076)
* 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
2019-11-18 21:46:01 +11:00

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";
}
}