mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/unity.git
synced 2026-08-19 04:13:58 +00:00
contract active api
This commit is contained in:
@@ -40,6 +40,12 @@ class ContractController extends BaseController
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public function active(Request $request, $hash_id)
|
||||
{
|
||||
$contract = ContractModule::active($request, $hash_id);
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public function delete(Request $request, $hash_id)
|
||||
{
|
||||
$contract = ContractModule::delete($request, $hash_id);
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User\Api;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Modules\User\ContractObligationModule;
|
||||
|
||||
use App\Http\Controllers\User\BaseController;
|
||||
|
||||
class ContractObligationController extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function list(Request $request)
|
||||
{
|
||||
$contract = ContractObligationModule::list($request);
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public function show(Request $request, $hash_id)
|
||||
{
|
||||
$contract = ContractObligationModule::show($request, $hash_id);
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$contract = ContractObligationModule::store($request);
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public function assignContractEntity(Request $request, $hash_id)
|
||||
{
|
||||
$contract = ContractObligationModule::assignContractEntity($request, $hash_id);
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public function delete(Request $request, $hash_id)
|
||||
{
|
||||
$contract = ContractObligationModule::delete($request, $hash_id);
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public function validCheck(Request $request, $hash_id = '')
|
||||
{
|
||||
$method = empty($hash_id) ? 'POST' :'PUT';
|
||||
$valid = ContractObligationModule::validCheck($request, $hash_id, $method);
|
||||
return $valid;
|
||||
}
|
||||
}
|
||||
@@ -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') {
|
||||
|
||||
@@ -82,6 +82,21 @@ class ExistCheck implements Rule
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'contract_active') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
$id = Hasher::decode('contracts', $row);
|
||||
$data = Contract::
|
||||
where('id', $id)
|
||||
->where('status', config('constants.contract.status.active'))
|
||||
->count();
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'contract_entity') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class StatusCheck implements Rule
|
||||
{
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
private $type;
|
||||
private $status;
|
||||
|
||||
public function __construct($type = '', $status = [])
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$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)
|
||||
->whereIn('status', $this->status)
|
||||
->count();
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return config('error_code.status_error');
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ namespace App\Http\Rules\User;
|
||||
use Auth;
|
||||
use App\Models\Contract;
|
||||
use App\Models\ContractEntity;
|
||||
use App\Models\ContractObligation;
|
||||
use App\Models\ContractObligationContractDependency;
|
||||
use App\Models\Entity;
|
||||
use App\Models\ContractTemplate;
|
||||
use App\Models\ContractTemplateObligation;
|
||||
@@ -41,6 +43,7 @@ class UnderCheck implements Rule
|
||||
$value = is_array($value) ? $value : [$value];
|
||||
|
||||
if ($this->type == 'contract') {
|
||||
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
$id = Hasher::decode('contracts', $row);
|
||||
@@ -70,6 +73,38 @@ class UnderCheck implements Rule
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'contract_obligation') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
|
||||
$id = Hasher::decode('contract_obligations', $row);
|
||||
$data = ContractObligation::
|
||||
where('id', $id)
|
||||
->where('user_id', Auth::guard('user-api')->user()->id)
|
||||
->count();
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'contract_obligation_contract_dependency') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
|
||||
$id = Hasher::decode('contract_obligation_contract_dependencies', $row);
|
||||
$data = ContractObligationContractDependency::
|
||||
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)) {
|
||||
|
||||
@@ -16,11 +16,12 @@ class ContractObligation extends Model
|
||||
'contract_list',
|
||||
'contract_obligation_dependency_list',
|
||||
'depend_contract_obligation_dependency_list',
|
||||
'contract_obligation_contract_dependency_list',
|
||||
'contract_entity_list'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'id', 'in_time_contract_obligation_template',
|
||||
'in_time_contract_obligation_template',
|
||||
];
|
||||
|
||||
public function contract()
|
||||
@@ -38,6 +39,11 @@ class ContractObligation extends Model
|
||||
return $this->hasMany('App\Models\ContractObligationDependency', 'depend_contract_obligation_id');
|
||||
}
|
||||
|
||||
public function contract_obligation_contract_dependency()
|
||||
{
|
||||
return $this->hasMany('App\Models\ContractObligationContractDependency', 'contract_obligation_id');
|
||||
}
|
||||
|
||||
public function contract_entity()
|
||||
{
|
||||
return $this->belongsTo('App\Models\ContractEntity', 'contract_entity_id');
|
||||
@@ -67,6 +73,13 @@ class ContractObligation extends Model
|
||||
->get()->makeHidden(['contract_obligation_list', 'depend_contract_obligation_list']);
|
||||
}
|
||||
|
||||
public function getContractObligationContractDependencyListAttribute()
|
||||
{
|
||||
return $this->contract_obligation_contract_dependency()
|
||||
// ->where('status', config('constants.contract_obligation_contract_dependency.status.active'))
|
||||
->get()->makeHidden(['contract_obligation_list']);
|
||||
}
|
||||
|
||||
public function getContractEntityListAttribute()
|
||||
{
|
||||
return $this->contract_entity()->get()->makeHidden(['contract_list']);
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ContractObligationContractDependencies extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Http\Helpers\Hasher;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ContractObligationContractDependency extends Model
|
||||
{
|
||||
protected $table = 'contract_obligation_contract_dependencies';
|
||||
|
||||
protected $appends = [
|
||||
'hash_id',
|
||||
'contract_obligation_hash_id',
|
||||
'depend_contract_hash_id',
|
||||
'contract_obligation_list',
|
||||
'depend_contract_list'
|
||||
];
|
||||
|
||||
public function contract_obligation()
|
||||
{
|
||||
return $this->belongsTo('App\Models\ContractObligation', 'contract_obligation_id');
|
||||
}
|
||||
|
||||
public function depend_contract()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Contract', 'depend_contract_id');
|
||||
}
|
||||
|
||||
public function getHashIdAttribute()
|
||||
{
|
||||
return Hasher::encode('contract_obligation_contract_dependencies', $this->id);
|
||||
}
|
||||
|
||||
public function getContractObligationHashIdAttribute()
|
||||
{
|
||||
return Hasher::encode('contract_obligations', $this->contract_obligation_id);
|
||||
}
|
||||
|
||||
public function getDependContractHashIdAttribute()
|
||||
{
|
||||
return Hasher::encode('contracts', $this->depend_contract_id);
|
||||
}
|
||||
|
||||
public function getContractObligationListAttribute()
|
||||
{
|
||||
return $this->contract_obligation()->get()->makeHidden(['contract_obligation_dependency_list', 'depend_contract_obligation_dependency_list']);
|
||||
}
|
||||
|
||||
public function getDependContractListAttribute()
|
||||
{
|
||||
return $this->depend_contract()->get();
|
||||
}
|
||||
|
||||
public function getUpdatedAtAttribute($date)
|
||||
{
|
||||
return $date ? Carbon::parse($date)->timezone('Asia/Kuala_Lumpur')->format('Y-m-d') : '';
|
||||
}
|
||||
|
||||
public function getCreatedAtAttribute($date)
|
||||
{
|
||||
return $date ? Carbon::parse($date)->timezone('Asia/Kuala_Lumpur')->format('Y-m-d') : '';
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@
|
||||
'pending' => 9
|
||||
]
|
||||
],
|
||||
'contact' => [
|
||||
'contract' => [
|
||||
'status' => [
|
||||
'active' => 1,
|
||||
'delete' => 2,
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
'date' => 'DATE_INVALID',
|
||||
'confirmed' => 'CONFIRM_ERROR',
|
||||
'obligation_depend_error' => 'OBLIGATION_DEPEND_ERROR',
|
||||
'status_error' => 'STATUS_ERROR',
|
||||
'min' => [
|
||||
'string' => 'MIN_ERROR_:min',
|
||||
],
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
status: General.returnAray(General.getURLParam('status[]')),
|
||||
page: General.getURLParam('page')
|
||||
}),
|
||||
colspan: 7,
|
||||
colspan: 8,
|
||||
filter_status: false,
|
||||
loading: true,
|
||||
contract_list: [],
|
||||
|
||||
+30
-4
@@ -301,10 +301,10 @@ Route::group(['namespace' => 'User', 'prefix' => 'user-backsys/api'], function (
|
||||
'middleware' => ['permission:add contract']
|
||||
]
|
||||
);
|
||||
Route::put('assign-entity/{hash_id}',
|
||||
Route::put('active/{hash_id}',
|
||||
[
|
||||
'as' => 'api.contract.assign-entity',
|
||||
'uses' => 'ContractController@assignEntity',
|
||||
'as' => 'api.contract.active',
|
||||
'uses' => 'ContractController@active',
|
||||
'middleware' => ['permission:edit contract']
|
||||
]
|
||||
);
|
||||
@@ -317,7 +317,7 @@ Route::group(['namespace' => 'User', 'prefix' => 'user-backsys/api'], function (
|
||||
);
|
||||
});
|
||||
|
||||
// Contract Entit
|
||||
// Contract Entity
|
||||
Route::prefix('contract-entity')->group(function () {
|
||||
Route::get('list',
|
||||
[
|
||||
@@ -356,6 +356,32 @@ Route::group(['namespace' => 'User', 'prefix' => 'user-backsys/api'], function (
|
||||
);
|
||||
});
|
||||
|
||||
// Contract Obligation
|
||||
Route::prefix('contract-obligation')->group(function () {
|
||||
Route::get('list',
|
||||
[
|
||||
'as' => 'api.contract-entity.list',
|
||||
'uses' => 'ContractObligationController@list',
|
||||
'middleware' => ['permission:view contract_obligation']
|
||||
]
|
||||
);
|
||||
Route::get('show/{hash_id}',
|
||||
[
|
||||
'as' => 'api.contract-entity.show',
|
||||
'uses' => 'ContractObligationController@show',
|
||||
'middleware' => ['permission:view contract_obligation']
|
||||
]
|
||||
);
|
||||
Route::put('assign-contract-entity/{hash_id}',
|
||||
[
|
||||
'as' => 'api.contract-entity.update',
|
||||
'uses' => 'ContractObligationController@assignContractEntity',
|
||||
'middleware' => ['permission:edit contract_obligation']
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
// contract generate
|
||||
// contract assign entity
|
||||
// contract active
|
||||
|
||||
Reference in New Issue
Block a user