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:
@@ -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 = [
|
||||
|
||||
Reference in New Issue
Block a user