mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/unity.git
synced 2026-08-19 12:24:01 +00:00
contract active api
This commit is contained in:
@@ -7,6 +7,10 @@ use App\Models\ContractObligation;
|
||||
use App\Models\ContractObligationLog;
|
||||
use App\Models\Contract;
|
||||
use App\Models\ContractTemplateObligation;
|
||||
use App\Models\ContractEntity;
|
||||
|
||||
use App\Http\Rules\User\UnderCheck;
|
||||
use App\Http\Rules\User\ExistCheck;
|
||||
|
||||
use App\Http\Helpers\General;
|
||||
use App\Http\Helpers\Hasher;
|
||||
@@ -34,7 +38,7 @@ class ContractObligationModule extends BaseController
|
||||
$page = $request->get('page', null);
|
||||
$limit = $request->get('limit', 10);
|
||||
|
||||
$query = Contract::query();
|
||||
$query = ContractObligation::query();
|
||||
|
||||
if (strlen($name) > 0) {
|
||||
$query->where('name', 'like', '%' . $name . '%');
|
||||
@@ -68,9 +72,9 @@ class ContractObligationModule extends BaseController
|
||||
|
||||
public static function show(Request $request, $hash_id)
|
||||
{
|
||||
$id = Hasher::decode('contracts', $hash_id);
|
||||
$id = Hasher::decode('contract_obligations', $hash_id);
|
||||
$user_id = Auth::guard('user-api')->user()->id;
|
||||
$contract = Contract::
|
||||
$contract = ContractObligation::
|
||||
where('id', $id)
|
||||
->where('user_id', $user_id)
|
||||
->first();
|
||||
@@ -104,6 +108,7 @@ class ContractObligationModule extends BaseController
|
||||
$contract_obligation->contract_id = $contract->id;
|
||||
$contract_obligation->contract_template_obligation_id = $contract_template_obligation->id;
|
||||
$contract_obligation->name = $contract_template_obligation->name;
|
||||
$contract_obligation->sequence = $contract_template_obligation->sequence;
|
||||
$contract_obligation->content = json_encode($contract_template_obligation->content);
|
||||
$contract_obligation->must_complete = $contract_template_obligation->must_complete;
|
||||
$contract_obligation->must_accept = $contract_template_obligation->must_accept;
|
||||
@@ -123,6 +128,35 @@ class ContractObligationModule extends BaseController
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public static function assignContractEntity(Request $request, $hash_id)
|
||||
{
|
||||
$id = Hasher::decode('contract_obligations', $hash_id);
|
||||
$validation = ContractObligationModule::validation($request, $hash_id, 'ASSIGN');
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$contract_entity_id = $request->input('contract_entity_id');
|
||||
$contract_entity_id = Hasher::decode('contract_entities', $contract_entity_id[0]);
|
||||
$contract_entity = ContractEntity::find($contract_entity_id);
|
||||
|
||||
$contract_obligation = ContractObligation::find($id);
|
||||
$contract_obligation->contract_entity_id = $contract_entity->id;
|
||||
$contract_obligation->update();
|
||||
|
||||
// log
|
||||
ContractObligationModule::makeLog($contract_obligation->id, 'user (' . Auth::guard('user-api')->user()->id . ') assigned contract entity');
|
||||
|
||||
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();
|
||||
@@ -132,8 +166,12 @@ class ContractObligationModule extends BaseController
|
||||
|
||||
}
|
||||
|
||||
if ($method == 'PUT') {
|
||||
|
||||
if ($method == 'ASSIGN') {
|
||||
$data['id'] = $id;
|
||||
$rule = [
|
||||
'id' => [new UnderCheck('contract_obligation'), new ExistCheck('contract_obligation')],
|
||||
'contract_entity_id' => ['required', new UnderCheck('contract_entity'), new ExistCheck('contract_entity')]
|
||||
];
|
||||
}
|
||||
|
||||
if ($method == 'DEL') {
|
||||
|
||||
Reference in New Issue
Block a user