mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/unity.git
synced 2026-08-28 08:44:07 +00:00
contract active api
This commit is contained in:
@@ -82,6 +82,21 @@ class ExistCheck implements Rule
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'contract_active') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
$id = Hasher::decode('contracts', $row);
|
||||
$data = Contract::
|
||||
where('id', $id)
|
||||
->where('status', config('constants.contract.status.active'))
|
||||
->count();
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'contract_entity') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Rules\User;
|
||||
|
||||
use Auth;
|
||||
use App\Models\ContractTemplate;
|
||||
use App\Models\ContractTemplateObligation;
|
||||
use App\Models\Contract;
|
||||
use App\Models\ContractEntity;
|
||||
use App\Models\Entity;
|
||||
|
||||
use App\Http\Helpers\Hasher;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class StatusCheck implements Rule
|
||||
{
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
private $type;
|
||||
private $status;
|
||||
|
||||
public function __construct($type = '', $status = [])
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$this->attribute = $attribute;
|
||||
$value = is_array($value) ? $value : [$value];
|
||||
|
||||
if ($this->type == 'contract') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
$id = Hasher::decode('contracts', $row);
|
||||
$data = Contract::
|
||||
where('id', $id)
|
||||
->whereIn('status', $this->status)
|
||||
->count();
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return config('error_code.status_error');
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ namespace App\Http\Rules\User;
|
||||
use Auth;
|
||||
use App\Models\Contract;
|
||||
use App\Models\ContractEntity;
|
||||
use App\Models\ContractObligation;
|
||||
use App\Models\ContractObligationContractDependency;
|
||||
use App\Models\Entity;
|
||||
use App\Models\ContractTemplate;
|
||||
use App\Models\ContractTemplateObligation;
|
||||
@@ -41,6 +43,7 @@ class UnderCheck implements Rule
|
||||
$value = is_array($value) ? $value : [$value];
|
||||
|
||||
if ($this->type == 'contract') {
|
||||
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
$id = Hasher::decode('contracts', $row);
|
||||
@@ -70,6 +73,38 @@ class UnderCheck implements Rule
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'contract_obligation') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
|
||||
$id = Hasher::decode('contract_obligations', $row);
|
||||
$data = ContractObligation::
|
||||
where('id', $id)
|
||||
->where('user_id', Auth::guard('user-api')->user()->id)
|
||||
->count();
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'contract_obligation_contract_dependency') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
|
||||
$id = Hasher::decode('contract_obligation_contract_dependencies', $row);
|
||||
$data = ContractObligationContractDependency::
|
||||
where('id', $id)
|
||||
->where('user_id', Auth::guard('user-api')->user()->id)
|
||||
->count();
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'entity') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
|
||||
Reference in New Issue
Block a user