1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 16:13:20 +01:00
invoiceninja/app/Http/ValidationRules/ValidPayableInvoicesRule.php

60 lines
1.3 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\ValidationRules;
use App\Models\Invoice;
use App\Utils\Traits\MakesHash;
use Illuminate\Contracts\Validation\Rule;
/**
* Class ValidPayableInvoicesRule.
*/
class ValidPayableInvoicesRule implements Rule
{
use MakesHash;
/**
* @param string $attribute
* @param mixed $value
* @return bool
*/
private $error_msg;
public function passes($attribute, $value)
{
/*If no invoices has been sent, then we apply the payment to the client account*/
$invoices = [];
if (is_array($value)) {
2023-08-06 09:03:12 +02:00
$invoices = Invoice::query()->whereIn('id', array_column($value, 'invoice_id'))->company()->get();
}
foreach ($invoices as $invoice) {
if (! $invoice->isPayable()) {
$this->error_msg = ctrans('texts.one_or_more_invoices_paid');
return false;
}
}
return true;
}
/**
* @return string
*/
public function message()
{
return $this->error_msg;
}
}