mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/unity.git
synced 2026-08-19 12:24:01 +00:00
contract entity api
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User\Api;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Modules\User\ContractEntityModule;
|
||||
|
||||
use App\Http\Controllers\User\BaseController;
|
||||
|
||||
class ContractEntityController extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function list(Request $request)
|
||||
{
|
||||
$contract = ContractEntityModule::list($request);
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public function show(Request $request, $hash_id)
|
||||
{
|
||||
$contract = ContractEntityModule::show($request, $hash_id);
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$contract = ContractEntityModule::store($request);
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public function update(Request $request, $hash_id)
|
||||
{
|
||||
$contract = ContractEntityModule::update($request, $hash_id);
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public function delete(Request $request, $hash_id)
|
||||
{
|
||||
$contract = ContractEntityModule::delete($request, $hash_id);
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public function validCheck(Request $request, $hash_id = '')
|
||||
{
|
||||
$method = empty($hash_id) ? 'POST' :'PUT';
|
||||
$valid = ContractEntityModule::validCheck($request, $hash_id, $method);
|
||||
return $valid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Modules\User;
|
||||
|
||||
use Auth;
|
||||
use App\Models\ContractEntity;
|
||||
use App\Models\Contract;
|
||||
use App\Models\Entity;
|
||||
|
||||
use App\Http\Modules\User\ContractModule;
|
||||
|
||||
use App\Http\Rules\User\UnderCheck;
|
||||
use App\Http\Rules\User\ExistCheck;
|
||||
|
||||
use App\Http\Helpers\General;
|
||||
use App\Http\Helpers\Hasher;
|
||||
use Carbon\Carbon;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use App\Http\Controllers\User\BaseController;
|
||||
|
||||
class ContractEntityModule extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public static function list(Request $request)
|
||||
{
|
||||
General::storeCachePerviousQuery($request->query(), 'contract_entity_query');
|
||||
|
||||
$contract_hash_id = $contract_id = $request->get('contract_id', []);
|
||||
|
||||
$status = $request->get('status', []);
|
||||
$page = $request->get('page', null);
|
||||
$limit = $request->get('limit', 10);
|
||||
|
||||
$query = ContractEntity::query();
|
||||
|
||||
if (!empty($contract_id)) {
|
||||
$contract_id = Hasher::decodeArray('contracts', $contract_id);
|
||||
$query->whereIn('contract_id', $contract_id);
|
||||
}
|
||||
|
||||
if (!empty($status) > 0) {
|
||||
$query->whereIn('status', $status);
|
||||
}
|
||||
|
||||
$query->where('user_id', Auth::guard('user-api')->user()->id);
|
||||
|
||||
$query->orderBy('id', 'desc');
|
||||
|
||||
$params = [
|
||||
'contract_id' => $contract_hash_id,
|
||||
'status' => $status,
|
||||
'page' => $page
|
||||
];
|
||||
|
||||
$contract_entity_list = $query->paginate($limit);
|
||||
|
||||
$extract = [];
|
||||
foreach ($contract_entity_list as $key => $row) {
|
||||
$extract[] = $row;
|
||||
|
||||
}
|
||||
$pagination = General::paginationGenerator($contract_entity_list, $params, $extract);
|
||||
|
||||
return $pagination;
|
||||
}
|
||||
|
||||
public static function show(Request $request, $hash_id)
|
||||
{
|
||||
$id = Hasher::decode('contract_entities', $hash_id);
|
||||
$user_id = Auth::guard('user-api')->user()->id;
|
||||
$contract = ContractEntity::
|
||||
where('id', $id)
|
||||
->where('user_id', $user_id)
|
||||
->first();
|
||||
if ($contract) {
|
||||
$data = General::returnData($contract, '');
|
||||
return response()->json($data);
|
||||
}
|
||||
$data = General::returnNotFoundData();
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public static function store(Request $request)
|
||||
{
|
||||
$validation = ContractEntityModule::validation($request);
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$contract_id = $request->input('contract_id');
|
||||
$contract_id = Hasher::decode('contracts', $contract_id[0]);
|
||||
$contarct = Contract::find($contract_id);
|
||||
|
||||
$entity_id = $request->input('entity_id');
|
||||
$entity_id = Hasher::decode('entities', $entity_id[0]);
|
||||
$entity = Entity::find($entity_id);
|
||||
|
||||
$contract_entity = new ContractEntity();
|
||||
$contract_entity->user_id = Auth::guard('user-api')->user()->id;
|
||||
$contract_entity->contract_id = $contarct->id;
|
||||
$contract_entity->entity_id = $entity->id;
|
||||
$contract_entity->entity_signature_id = $entity->entity_signature()->first()->id;
|
||||
$contract_entity->status = config('constants.contact_entity.status.active');
|
||||
$contract_entity->save();
|
||||
|
||||
// log
|
||||
ContractModule::makeLog($contract_entity->contract_id, 'user (' . Auth::guard('user-api')->user()->id . ') contact entity created');
|
||||
|
||||
DB::commit();
|
||||
|
||||
$query_string = General::getCachePerviousQuery('contract_entity_query');
|
||||
$data = General::returnData($contract_entity, $query_string);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public static function delete(Request $request, $hash_id)
|
||||
{
|
||||
$id = Hasher::decode('contract_entities', $hash_id);
|
||||
$validation = ContractEntityModule::validation($request, $hash_id, 'DEL');
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$contract_entity = ContractEntity::find($id);
|
||||
$contract_entity->status = config('constants.contact_entity.status.delete');
|
||||
$contract_entity->update();
|
||||
|
||||
// log
|
||||
ContractModule::makeLog($contract_entity->contract_id, 'user (' . Auth::guard('user-api')->user()->id . ') contact entity deleted');
|
||||
|
||||
DB::commit();
|
||||
|
||||
$query_string = General::getCachePerviousQuery('contract_entity_query');
|
||||
$data = General::returnData($contract_entity, $query_string);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public static function validCheck(Request $request, $hash_id = '', $method = 'POST')
|
||||
{
|
||||
$id = $hash_id ? Hasher::decode('contracts', $hash_id) : '';
|
||||
$validation = ContractEntityModule::validation($request, $id, $method);
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
}
|
||||
|
||||
private static function validation(Request $request, $id = '', $method = 'POST')
|
||||
{
|
||||
$data = $request->all();
|
||||
$rule= [];
|
||||
|
||||
if ($method == 'POST') {
|
||||
$rule = [
|
||||
'contract_id' => ['required', new UnderCheck('contract'), new ExistCheck('contract')],
|
||||
'entity_id' => ['required', new UnderCheck('entity'), new ExistCheck('entity')]
|
||||
];
|
||||
}
|
||||
|
||||
if ($method == 'DEL') {
|
||||
$data['id'] = $id;
|
||||
$rule = [
|
||||
'id' => [new UnderCheck('contract_entity'), new ExistCheck('contract_entity')],
|
||||
];
|
||||
}
|
||||
|
||||
$validator = Validator::make($data, $rule, config('error_code'));
|
||||
|
||||
$errors = $validator->errors();
|
||||
|
||||
if ($validator->fails()) {
|
||||
$data = General::returnErrorData($errors);
|
||||
return $data;
|
||||
}
|
||||
else {
|
||||
return (object)['status' => true];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,7 +220,7 @@ class ContractModule extends BaseController
|
||||
$contract->update();
|
||||
|
||||
// log
|
||||
ContractModule::makeLog($contract->id, 'user (' . Auth::guard('user-api')->user()->id . ') delete');
|
||||
ContractModule::makeLog($contract->id, 'user (' . Auth::guard('user-api')->user()->id . ') deleted');
|
||||
|
||||
DB::commit();
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ class ContractTemplateModule extends BaseController
|
||||
$contract_template->update();
|
||||
|
||||
// log
|
||||
ContractTemplateModule::makeLog($contract_template->id, 'user (' . Auth::guard('user-api')->user()->id . ') delete');
|
||||
ContractTemplateModule::makeLog($contract_template->id, 'user (' . Auth::guard('user-api')->user()->id . ') deleted');
|
||||
|
||||
DB::commit();
|
||||
|
||||
|
||||
+1
-1
@@ -141,7 +141,7 @@ class ContractTemplateObligationContractTemplateDependencyModule extends BaseCon
|
||||
$contract_template_obligation_contract_template_dependency->update();
|
||||
|
||||
// log
|
||||
ContractTemplateObligationModule::makeLog($contract_template_obligation_contract_template_dependency->contract_template_obligation_id, 'user (' . Auth::guard('user-api')->user()->id . ') delete dependency');
|
||||
ContractTemplateObligationModule::makeLog($contract_template_obligation_contract_template_dependency->contract_template_obligation_id, 'user (' . Auth::guard('user-api')->user()->id . ') dependency deleted');
|
||||
|
||||
DB::commit();
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ class ContractTemplateObligationDependencyModule extends BaseController
|
||||
$contract_template_obligation_dependency->update();
|
||||
|
||||
// log
|
||||
ContractTemplateObligationModule::makeLog($contract_template_obligation_dependency->contract_template_obligation_id, 'user (' . Auth::guard('user-api')->user()->id . ') delete dependency');
|
||||
ContractTemplateObligationModule::makeLog($contract_template_obligation_dependency->contract_template_obligation_id, 'user (' . Auth::guard('user-api')->user()->id . ') dependency deleted');
|
||||
|
||||
DB::commit();
|
||||
|
||||
|
||||
@@ -223,7 +223,7 @@ class ContractTemplateObligationModule extends BaseController
|
||||
$contract_template_obligation->update();
|
||||
|
||||
// log
|
||||
ContractTemplateObligationModule::makeLog($contract_template_obligation->id, 'user (' . Auth::guard('user-api')->user()->id . ') delete');
|
||||
ContractTemplateObligationModule::makeLog($contract_template_obligation->id, 'user (' . Auth::guard('user-api')->user()->id . ') deleted');
|
||||
|
||||
DB::commit();
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ class EntityModule extends BaseController
|
||||
$entity->update();
|
||||
|
||||
// log
|
||||
EntityModule::makeLog($entity->id, 'user (' . Auth::guard('user-api')->user()->id . ') delete');
|
||||
EntityModule::makeLog($entity->id, 'user (' . Auth::guard('user-api')->user()->id . ') deleted');
|
||||
|
||||
DB::commit();
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ class EntitySignatureModule extends BaseController
|
||||
$entity_signature->update();
|
||||
|
||||
// log
|
||||
EntityModule::makeLog($entity_signature->entity_id, 'user (' . Auth::guard('user-api')->user()->id . ') sugnature delete');
|
||||
EntityModule::makeLog($entity_signature->entity_id, 'user (' . Auth::guard('user-api')->user()->id . ') sugnature deleted);
|
||||
|
||||
DB::commit();
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@ namespace App\Http\Rules\User;
|
||||
use Auth;
|
||||
use App\Models\ContractTemplate;
|
||||
use App\Models\ContractTemplateObligation;
|
||||
use App\Models\Contract;
|
||||
use App\Models\ContractEntity;
|
||||
use App\Models\Entity;
|
||||
|
||||
use App\Http\Helpers\Hasher;
|
||||
|
||||
@@ -65,6 +68,48 @@ class ExistCheck implements Rule
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'contract') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
$id = Hasher::decode('contracts', $row);
|
||||
$data = Contract::
|
||||
where('id', $id)
|
||||
->count();
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'contract_entity') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
$id = Hasher::decode('contract_entities', $row);
|
||||
$data = ContractEntity::
|
||||
where('id', $id)
|
||||
->count();
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'entity') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
$id = Hasher::decode('entities', $row);
|
||||
$data = Entity::
|
||||
where('id', $id)
|
||||
->count();
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Http\Rules\User;
|
||||
|
||||
use Auth;
|
||||
use App\Models\Contract;
|
||||
use App\Models\ContractEntity;
|
||||
use App\Models\Entity;
|
||||
use App\Models\ContractTemplate;
|
||||
use App\Models\ContractTemplateObligation;
|
||||
@@ -38,6 +40,36 @@ class UnderCheck implements Rule
|
||||
$this->attribute = $attribute;
|
||||
$value = is_array($value) ? $value : [$value];
|
||||
|
||||
if ($this->type == 'contract') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
$id = Hasher::decode('contracts', $row);
|
||||
$data = Contract::
|
||||
where('id', $id)
|
||||
->where('user_id', Auth::guard('user-api')->user()->id)
|
||||
->count();
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'contract_entity') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
$id = Hasher::decode('contract_entities', $row);
|
||||
$data = ContractEntity::
|
||||
where('id', $id)
|
||||
->where('user_id', Auth::guard('user-api')->user()->id)
|
||||
->count();
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'entity') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
|
||||
Reference in New Issue
Block a user