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:
@@ -13,6 +13,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\Helpers\General;
|
||||
use App\Http\Helpers\Hasher;
|
||||
@@ -205,6 +206,35 @@ class ContractModule extends BaseController
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public static function active(Request $request, $hash_id)
|
||||
{
|
||||
$id = Hasher::decode('contracts', $hash_id);
|
||||
$contract = ContractModule::show($request, $hash_id);
|
||||
$this_ = json_decode(json_encode($contract), true);
|
||||
$request->request->add($this_['original']['data']);
|
||||
|
||||
$validation = ContractModule::validation($request, $hash_id, 'ACTIVE');
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$contract = Contract::find($id);
|
||||
$contract->status = config('constants.contract.status.active');
|
||||
$contract->update();
|
||||
|
||||
// log
|
||||
ContractModule::makeLog($contract->id, 'user (' . Auth::guard('user-api')->user()->id . ') status activiated');
|
||||
|
||||
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);
|
||||
@@ -250,13 +280,42 @@ class ContractModule extends BaseController
|
||||
];
|
||||
}
|
||||
|
||||
if ($method == 'PUT') {
|
||||
if ($method == 'ACTIVE') {
|
||||
$data['id'] = $id;
|
||||
$rule = [
|
||||
'id' => [new UnderCheck('contract'), new ExistCheck('contract')],
|
||||
'name' => 'required',
|
||||
'complete_day_range' => 'required|numeric|gt:-1'
|
||||
'id' => [new UnderCheck('contract'), new ExistCheck('contract'), new StatusCheck('contract', [config('constants.contract.status.pending')])],
|
||||
'contract_obligation_list' => ['required'],
|
||||
'contract_entity_list' => ['required']
|
||||
];
|
||||
|
||||
if (!empty($data['contract_obligation_list'])) {
|
||||
foreach ($data['contract_obligation_list'] as $key => $row) {
|
||||
$rule['contract_obligation_list.'.$key.'.contract_entity_id'] = [
|
||||
'required',
|
||||
new UnderCheck('contract_entity'),
|
||||
new ExistCheck('contract_entity')
|
||||
];
|
||||
|
||||
if (!empty($row['contract_obligation_contract_dependency_list'])) {
|
||||
|
||||
foreach ($row['contract_obligation_contract_dependency_list'] as $key_2 => $row_2) {
|
||||
$rule['contract_obligation_list.'.$key.'.contract_obligation_contract_dependency_list.'.$key_2.'.hash_id'] = [
|
||||
new UnderCheck('contract_obligation_contract_dependency'),
|
||||
new ExistCheck('contract_obligation_contract_dependency')
|
||||
];
|
||||
|
||||
$rule['contract_obligation_list.'.$key.'.contract_obligation_contract_dependency_list.'.$key_2.'.depend_contract_id'] = [
|
||||
'required',
|
||||
new UnderCheck('contract'),
|
||||
new ExistCheck('contract'),
|
||||
new StatusCheck('contract', [config('constants.contract.status.active')])
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($method == 'DEL') {
|
||||
@@ -267,7 +326,6 @@ class ContractModule extends BaseController
|
||||
}
|
||||
|
||||
$validator = Validator::make($data, $rule, config('error_code'));
|
||||
|
||||
$errors = $validator->errors();
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
||||
@@ -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