mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/unity.git
synced 2026-08-19 20:34:01 +00:00
contract obligation complete and accept api
This commit is contained in:
@@ -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