43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Rules\Raas;
|
|
|
|
use App\Models\Raas\Exportacao;
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
|
|
class ExportacaoContainsFinanciamento implements Rule
|
|
{
|
|
private $unidadeId;
|
|
private $competenciaId;
|
|
|
|
public function __construct($unidadeId, $competenciaId)
|
|
{
|
|
$this->unidadeId = $unidadeId;
|
|
$this->competenciaId = $competenciaId;
|
|
}
|
|
|
|
public function passes($attribute, $value)
|
|
{
|
|
$response = true;
|
|
|
|
Exportacao::where('unidade_id', $this->unidadeId)
|
|
->where('competencia_id', $this->competenciaId)
|
|
->whereHas('financiamentos', function($query) use ($value) {
|
|
$query->from('sigtap.financiamento')->whereIn('id', $value);
|
|
})
|
|
->get()
|
|
->map(function($exportacao) use ($value, &$response) {
|
|
if ($exportacao->financiamentos->count() === count($value)) {
|
|
$response = false;
|
|
}
|
|
});
|
|
|
|
return $response;
|
|
}
|
|
|
|
public function message()
|
|
{
|
|
return 'Exportação já existente para os financiamentos selecionados.';
|
|
}
|
|
}
|