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()) {
|
||||
|
||||
Reference in New Issue
Block a user