mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/unity.git
synced 2026-08-19 12:24:01 +00:00
contract obligation complete and accept api
This commit is contained in:
@@ -40,6 +40,12 @@ class ContractObligationController extends BaseController
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public function updateComplete(Request $request, $hash_id)
|
||||
{
|
||||
$contract = ContractObligationModule::updateComplete($request, $hash_id);
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public function delete(Request $request, $hash_id)
|
||||
{
|
||||
$contract = ContractObligationModule::delete($request, $hash_id);
|
||||
|
||||
@@ -14,6 +14,7 @@ use App\Http\Modules\User\ContractObligationDependencyModule;
|
||||
use App\Http\Rules\User\UnderCheck;
|
||||
use App\Http\Rules\User\ExistCheck;
|
||||
use App\Http\Rules\User\StatusCheck;
|
||||
use App\Http\Rules\User\ContractDoneCheck;
|
||||
|
||||
use App\Http\Helpers\General;
|
||||
use App\Http\Helpers\Hasher;
|
||||
@@ -107,7 +108,7 @@ class ContractModule extends BaseController
|
||||
$contract->contract_template_id = $contarct_template->id;
|
||||
$contract->name = $contarct_template->name;
|
||||
$contract->in_time_contract_template = json_encode($contarct_template);
|
||||
$contract->status = config('constants.contact.status.pending');
|
||||
$contract->status = config('constants.contract.status.pending');
|
||||
$contract->save();
|
||||
|
||||
// generate contract obligation
|
||||
@@ -125,7 +126,6 @@ class ContractModule extends BaseController
|
||||
$contract_obligation = ContractObligationModule::generate($request);
|
||||
}
|
||||
|
||||
|
||||
// generate contract obligation dependency
|
||||
foreach ($contract_template_obligation_list as $key => $row) {
|
||||
$contract_template_obligation_dependency = $row->contract_template_obligation_dependency()
|
||||
@@ -235,6 +235,33 @@ class ContractModule extends BaseController
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
|
||||
public static function updateDone(Request $request, $hash_id)
|
||||
{
|
||||
$id = Hasher::decode('contracts', $hash_id);
|
||||
$validation = ContractModule::validation($request, $hash_id, 'DONE');
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$contract = Contract::find($id);
|
||||
$contract->status = config('constants.contract.status.done');
|
||||
$contract->update();
|
||||
dd($contract);
|
||||
|
||||
// log
|
||||
ContractModule::makeLog($contract->id, 'user (' . Auth::guard('user-api')->user()->id . ') status done updated');
|
||||
|
||||
DB::commit();
|
||||
|
||||
$query_string = General::getCachePerviousQuery('contract_query');
|
||||
$data = General::returnData($contract, $query_string);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public static function delete(Request $request, $hash_id)
|
||||
{
|
||||
$id = Hasher::decode('contracts', $hash_id);
|
||||
@@ -318,6 +345,17 @@ class ContractModule extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
if ($method == 'DONE') {
|
||||
$data['id'] = $id;
|
||||
$rule = [
|
||||
'id' => [
|
||||
new UnderCheck('contract'),
|
||||
new ExistCheck('contract'),
|
||||
new ContractDoneCheck()
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
if ($method == 'DEL') {
|
||||
$data['id'] = $id;
|
||||
$rule = [
|
||||
|
||||
@@ -9,8 +9,14 @@ use App\Models\Contract;
|
||||
use App\Models\ContractTemplateObligation;
|
||||
use App\Models\ContractEntity;
|
||||
|
||||
use App\Http\Modules\User\ContractModule;
|
||||
|
||||
use App\Http\Rules\User\UnderCheck;
|
||||
use App\Http\Rules\User\ExistCheck;
|
||||
use App\Http\Rules\User\ContractObligationCompleteOrAcceptCheck;
|
||||
use App\Http\Rules\User\ContractObligationEntitySignatureCheck;
|
||||
use App\Http\Rules\User\ContractObligationDoneCheck;
|
||||
use App\Http\Rules\User\StatusCheck;
|
||||
|
||||
use App\Http\Helpers\General;
|
||||
use App\Http\Helpers\Hasher;
|
||||
@@ -114,7 +120,7 @@ class ContractObligationModule extends BaseController
|
||||
$contract_obligation->must_accept = $contract_template_obligation->must_accept;
|
||||
$contract_obligation->in_time_contract_obligation_template = json_encode($contract_template_obligation);
|
||||
$contract_obligation->type = $contract_template_obligation->type;
|
||||
$contract_obligation->status = config('constants.contact.status.pending');
|
||||
$contract_obligation->status = config('constants.contarct.status.active');
|
||||
$contract_obligation->save();
|
||||
|
||||
// log
|
||||
@@ -157,6 +163,87 @@ class ContractObligationModule extends BaseController
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public static function updateComplete(Request $request, $hash_id)
|
||||
{
|
||||
$id = Hasher::decode('contract_obligations', $hash_id);
|
||||
$validation = ContractObligationModule::validation($request, $hash_id, 'COMPLETE');
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$contract_obligation = ContractObligation::find($id);
|
||||
$contract_obligation->complete_status = config('constants.contract_obligation.complete_status.completed');
|
||||
$contract_obligation->update();
|
||||
|
||||
// log
|
||||
ContractObligationModule::makeLog($contract_obligation->id, 'user (' . Auth::guard('user-api')->user()->id . ') complete status updated');
|
||||
|
||||
ContractObligationModule::updateDone($request, $hash_id);
|
||||
|
||||
DB::commit();
|
||||
|
||||
$query_string = General::getCachePerviousQuery('contract_obligation_query');
|
||||
$data = General::returnData($contract_obligation, $query_string);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public static function updateAccept(Request $request, $hash_id)
|
||||
{
|
||||
$id = Hasher::decode('contract_obligations', $hash_id);
|
||||
$validation = ContractObligationModule::validation($request, $hash_id, 'ACCEPT');
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$contract_obligation = ContractObligation::find($id);
|
||||
$contract_obligation->accept_status = config('constants.contract_obligation.accept_status.accepted');
|
||||
$contract_obligation->update();
|
||||
|
||||
// log
|
||||
ContractObligationModule::makeLog($contract_obligation->id, 'user (' . Auth::guard('user-api')->user()->id . ') accept status updated');
|
||||
|
||||
ContractObligationModule::updateDone($request, $hash_id);
|
||||
|
||||
DB::commit();
|
||||
|
||||
$query_string = General::getCachePerviousQuery('contract_obligation_query');
|
||||
$data = General::returnData($contract_obligation, $query_string);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public static function updateDone(Request $request, $hash_id)
|
||||
{
|
||||
$id = Hasher::decode('contract_obligations', $hash_id);
|
||||
$validation = ContractObligationModule::validation($request, $hash_id, 'DONE');
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$contract_obligation = ContractObligation::find($id);
|
||||
$contract_obligation->status = config('constants.contract_obligation.status.done');
|
||||
$contract_obligation->update();
|
||||
|
||||
// log
|
||||
ContractObligationModule::makeLog($contract_obligation->id, 'user (' . Auth::guard('user-api')->user()->id . ') done status updated');
|
||||
|
||||
ContractModule::updateDone($request, $contract_obligation->contract_hash_id);
|
||||
|
||||
DB::commit();
|
||||
|
||||
$query_string = General::getCachePerviousQuery('contract_obligation_query');
|
||||
$data = General::returnData($contract_obligation, $query_string);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
private static function validation(Request $request, $id = '', $method = 'POST')
|
||||
{
|
||||
$data = $request->all();
|
||||
@@ -174,6 +261,45 @@ class ContractObligationModule extends BaseController
|
||||
];
|
||||
}
|
||||
|
||||
if ($method == 'COMPLETE') {
|
||||
$data['id'] = $id;
|
||||
$rule = [
|
||||
'id' => [
|
||||
new UnderCheck('contract_obligation'),
|
||||
new ExistCheck('contract_obligation'),
|
||||
new ContractObligationCompleteOrAcceptCheck('complete'),
|
||||
new StatusCheck('contract_obligation', [config('constants.contract_obligation.status.active')])
|
||||
|
||||
],
|
||||
'entity_signature_id' => ['required', new ContractObligationEntitySignatureCheck($data['id'] ?? '')]
|
||||
];
|
||||
}
|
||||
|
||||
if ($method == 'ACCEPT') {
|
||||
$data['id'] = $id;
|
||||
$rule = [
|
||||
'id' => [
|
||||
new UnderCheck('contract_obligation'),
|
||||
new ExistCheck('contract_obligation'),
|
||||
new ContractObligationCompleteOrAcceptCheck('accept'),
|
||||
new StatusCheck('contract_obligation', [config('constants.contract_obligation.status.active')])
|
||||
|
||||
],
|
||||
'entity_signature_id' => ['required', new ContractObligationEntitySignatureCheck($data['id'] ?? '')]
|
||||
];
|
||||
}
|
||||
|
||||
if ($method == 'DONE') {
|
||||
$data['id'] = $id;
|
||||
$rule = [
|
||||
'id' => [
|
||||
new UnderCheck('contract_obligation'),
|
||||
new ExistCheck('contract_obligation'),
|
||||
new ContractObligationDoneCheck()
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
if ($method == 'DEL') {
|
||||
$data['id'] = $id;
|
||||
$rule = [
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user