This commit is contained in:
45
api/app/Rules/Sigtap/QuantidadeIsValidForProcedimento.php
Normal file
45
api/app/Rules/Sigtap/QuantidadeIsValidForProcedimento.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules\Sigtap;
|
||||
|
||||
use App\Models\Sigtap\Procedimento;
|
||||
use App\Utils\MaskUtil;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class QuantidadeIsValidForProcedimento implements Rule
|
||||
{
|
||||
private $procedimentoId;
|
||||
|
||||
public function __construct($procedimentoId)
|
||||
{
|
||||
$this->procedimentoId = $procedimentoId;
|
||||
}
|
||||
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
return self::isValid($this->procedimentoId, $value);
|
||||
}
|
||||
|
||||
public static function isValid($procedimentoId, $value)
|
||||
{
|
||||
$procedimento = DB::table('sigtap.procedimento')
|
||||
->where('id', $procedimentoId)
|
||||
->select('quantidade_maxima_execucao')
|
||||
->first();
|
||||
|
||||
return $value >= 0
|
||||
&& $value <= $procedimento->quantidade_maxima_execucao;
|
||||
}
|
||||
|
||||
public function message()
|
||||
{
|
||||
$procedimento = Procedimento::where('id', $this->procedimentoId)
|
||||
->first(['codigo', 'nome', 'quantidade_maxima_execucao']);
|
||||
|
||||
$descricao = MaskUtil::getProcedimentoMasked($procedimento->codigo) . " - {$procedimento->nome}";
|
||||
|
||||
return "A quantidade máxima permitida para o procedimento {$descricao} é "
|
||||
. $procedimento->quantidade_maxima_execucao;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user