This commit is contained in:
34
api/app/Rules/Bpa/DataAtendimentoIsValid.php
Normal file
34
api/app/Rules/Bpa/DataAtendimentoIsValid.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules\Bpa;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DataAtendimentoIsValid implements Rule
|
||||
{
|
||||
private $competenciaId;
|
||||
|
||||
public function __construct($competenciaId)
|
||||
{
|
||||
$this->competenciaId = $competenciaId;
|
||||
}
|
||||
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
return self::isValid($this->competenciaId, $value);
|
||||
}
|
||||
|
||||
public static function isValid($competenciaId, $value)
|
||||
{
|
||||
return DB::table('sigtap.competencia')->where('id', $competenciaId)
|
||||
->where('valor', '>=', Str::substr($value, 0, 4))
|
||||
->exists();
|
||||
}
|
||||
|
||||
public function message()
|
||||
{
|
||||
return 'Data de atendimento inválida.';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user