contract obligation complete and accept api

This commit is contained in:
glovetleong
2021-07-27 13:36:51 +08:00
parent 7f209db917
commit 93b13a8f46
17 changed files with 550 additions and 20 deletions
+68
View File
@@ -0,0 +1,68 @@
<?php
namespace App\Http\Rules\User;
use Auth;
use App\Models\Contract;
use App\Http\Helpers\Hasher;
use Illuminate\Contracts\Validation\Rule;
class ContractDoneCheck implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
}
/**
* 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];
$allow = true;
foreach ($value as $key => $row) {
if(!empty($row)) {
$id = Hasher::decode('contracts', $row);
$contract = Contract::
where('id', $id)
->first();
foreach ($contract->contract_obligation_list as $key => $row) {
echo $row->status;
if ($row->status != config('constants.contract_obligation.status.active')) {
$allow = false;
}
}
}
}
return $allow;
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
if ($this->type == 'complete') {
return config('error_code.contract_done_error');
}
}
}
@@ -0,0 +1,91 @@
<?php
namespace App\Http\Rules\User;
use Auth;
use App\Models\ContractObligation;
use App\Http\Helpers\Hasher;
use Illuminate\Contracts\Validation\Rule;
class ContractObligationCompleteOrAcceptCheck implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
private $type;
public function __construct($type = '')
{
$this->type = $type;
}
/**
* 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];
foreach ($value as $key => $row) {
if(!empty($row)) {
$id = Hasher::decode('contract_obligations', $row);
$contract_obligation = ContractObligation::
where('id', $id)
->first();
if (!empty($contract_obligation->contract_obligation_dependency_list)) {
foreach ($contract_obligation->contract_obligation_dependency_list as $key_2 => $row_2) {
$depend_id = Hasher::decode('contract_obligations', $row_2->depend_contract_obligation_hash_id);
$depend_contract_obligation = ContractObligation::
where('id', $depend_id)
->first();
if ($this->type == 'complete') {
$depend_contract_obligation_must_complete = $depend_contract_obligation->must_complete;
$depend_contract_obligation_complete_status = $depend_contract_obligation->complete_status;
if ($depend_contract_obligation_must_complete == config('constants.contract_obligation.must_complete.complete')) {
if ($depend_contract_obligation_complete_status != config('constants.contract_obligation.complete_status.completed')) {
return false;
}
}
}
if ($this->type == 'accept') {
$depend_contract_obligation_must_accept = $depend_contract_obligation->must_accept;
$depend_contract_obligation_accept_status = $depend_contract_obligation->accept_status;
if ($depend_contract_obligation_must_accept == config('constants.contract_obligation.must_accept.accept')) {
if ($depend_contract_obligation_accept_status != config('constants.contract_obligation.accept_status.accepted')) {
return false;
}
}
}
}
}
}
}
return true;
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
if ($this->type == 'complete') {
return config('error_code.contract_obligation_complete_error');
}
}
}
@@ -0,0 +1,80 @@
<?php
namespace App\Http\Rules\User;
use Auth;
use App\Models\ContractObligation;
use App\Http\Helpers\Hasher;
use Illuminate\Contracts\Validation\Rule;
class ContractObligationDoneCheck implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
private $type;
public function __construct()
{
}
/**
* 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];
$allow = true;
foreach ($value as $key => $row) {
if(!empty($row)) {
$id = Hasher::decode('contract_obligations', $row);
$contract_obligation = ContractObligation::
where('id', $id)
->first();
$contract_obligation_must_complete = $contract_obligation->must_complete;
$contract_obligation_complete_status = $contract_obligation->complete_status;
if ($contract_obligation_must_complete == config('constants.contract_obligation.must_complete.complete')) {
if ($contract_obligation_complete_status != config('constants.contract_obligation.complete_status.completed')) {
$allow = false;
}
}
$contract_obligation_must_accept = $contract_obligation->must_accept;
$contract_obligation_accept_status = $contract_obligation->accept_status;
if ($contract_obligation_must_accept == config('constants.contract_obligation.must_accept.accept')) {
if ($contract_obligation_accept_status != config('constants.contract_obligation.accept_status.accepted')) {
$allow = false;
}
}
}
}
return $allow;
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
if ($this->type == 'complete') {
return config('error_code.contract_obligation_done_error');
}
}
}
@@ -0,0 +1,68 @@
<?php
namespace App\Http\Rules\User;
use Auth;
use App\Models\ContractObligation;
use App\Models\EntitySignature;
use App\Http\Helpers\Hasher;
use Illuminate\Contracts\Validation\Rule;
class ContractObligationEntitySignatureCheck implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
private $contract_obligation_id;
public function __construct($contract_obligation_id = '')
{
$this->contract_obligation_id = $contract_obligation_id;
}
/**
* 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];
$entity_signature_id = Hasher::decode('entity_signatures', $value[0]);
$entity_signature = EntitySignature::find($entity_signature_id);
if ($entity_signature) {
if ($entity_signature->type == config('constants.entity.signature.master')) {
return true;
}
}
$contract_obligation_id = Hasher::decode('contract_obligations', $this->contract_obligation_id);
$contract_obligation = ContractObligation::find($contract_obligation_id);
if ($contract_obligation->contract_entity_list[0]->entity_signature_hash_id == $value[0]) {
return true;
}
return false;
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return config('error_code.obligation_signature_error');
}
}
+16 -4
View File
@@ -3,11 +3,8 @@
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\Models\ContractObligation;
use App\Http\Helpers\Hasher;
@@ -57,6 +54,21 @@ class StatusCheck 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)
->whereIn('status', $this->status)
->count();
if (!$data) {
return false;
}
}
}
}
return true;
}