mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/unity.git
synced 2026-08-19 04:13:58 +00:00
contract template obligation dependency api
This commit is contained in:
@@ -11,13 +11,28 @@ class ContractTemplateObligation extends Model
|
||||
{
|
||||
protected $table = 'contract_template_obligations';
|
||||
|
||||
protected $appends = ['hash_id', 'contract_template_list'];
|
||||
protected $appends = [
|
||||
'hash_id',
|
||||
'contract_template_list',
|
||||
'contract_template_obligation_dependency_list',
|
||||
'depend_contract_template_obligation_dependency_list'
|
||||
];
|
||||
|
||||
public function contract_template()
|
||||
{
|
||||
return $this->belongsTo('App\Models\ContractTemplate', 'contract_template_id');
|
||||
}
|
||||
|
||||
public function contract_template_obligation_dependency()
|
||||
{
|
||||
return $this->hasMany('App\Models\ContractTemplateObligationDependency', 'contract_template_obligation_id');
|
||||
}
|
||||
|
||||
public function depend_contract_template_obligation_dependency()
|
||||
{
|
||||
return $this->hasMany('App\Models\ContractTemplateObligationDependency', 'depend_contract_template_obligation_id');
|
||||
}
|
||||
|
||||
public function getHashIdAttribute()
|
||||
{
|
||||
return Hasher::encode('contract_template_obligations', $this->id);
|
||||
@@ -28,6 +43,20 @@ class ContractTemplateObligation extends Model
|
||||
return $this->contract_template()->get()->makeHidden(['contract_template_obligation_list']);
|
||||
}
|
||||
|
||||
public function getContractTemplateObligationDependencyListAttribute()
|
||||
{
|
||||
return $this->contract_template_obligation_dependency()
|
||||
->where('status', config('constants.contract_template_obligation.status.active'))
|
||||
->get()->makeHidden(['contract_template_obligation_list', 'depend_contract_template_obligation_list']);
|
||||
}
|
||||
|
||||
public function getDependContractTemplateObligationDependencyListAttribute()
|
||||
{
|
||||
return $this->depend_contract_template_obligation_dependency()
|
||||
->where('status', config('constants.contract_template_obligation.status.active'))
|
||||
->get()->makeHidden(['contract_template_obligation_list', 'depend_contract_template_obligation_list']);
|
||||
}
|
||||
|
||||
public function getUpdatedAtAttribute($date)
|
||||
{
|
||||
return $date ? Carbon::parse($date)->timezone('Asia/Kuala_Lumpur')->format('Y-m-d') : '';
|
||||
@@ -37,4 +66,21 @@ class ContractTemplateObligation extends Model
|
||||
{
|
||||
return $date ? Carbon::parse($date)->timezone('Asia/Kuala_Lumpur')->format('Y-m-d') : '';
|
||||
}
|
||||
|
||||
public function getContractTemplateObligationDependencyStructure($contract_template_obligation_id = [], $contract_template_obligation_id_structure = [])
|
||||
{
|
||||
$contract_template_obligation_id = Hasher::decode('contract_template_obligations', $contract_template_obligation_id[0]);
|
||||
$contract_template_obligation = ContractTemplateObligation::find($contract_template_obligation_id);
|
||||
|
||||
if (!empty($contract_template_obligation->contract_template_obligation_dependency_list)) {
|
||||
foreach ($contract_template_obligation->contract_template_obligation_dependency_list as $key => $row) {
|
||||
$contract_template_obligation_id_structure[] = $row->depend_contract_template_obligation_hash_id;
|
||||
if (!empty($row->depend_contract_template_obligation_list)) {
|
||||
return $this->getContractTemplateObligationDependencyStructure([$row->depend_contract_template_obligation_hash_id], $contract_template_obligation_id_structure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $contract_template_obligation_id_structure;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ContractTemplateObligationDependencies 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 ContractTemplateObligationDependency extends Model
|
||||
{
|
||||
protected $table = 'contract_template_obligation_dependencies';
|
||||
|
||||
protected $appends = [
|
||||
'hash_id',
|
||||
'contract_template_obligation_hash_id',
|
||||
'depend_contract_template_obligation_hash_id',
|
||||
'contract_template_obligation_list',
|
||||
'depend_contract_template_obligation_list'
|
||||
];
|
||||
|
||||
public function contract_template_obligation()
|
||||
{
|
||||
return $this->belongsTo('App\Models\ContractTemplateObligation', 'contract_template_obligation_id');
|
||||
}
|
||||
|
||||
public function depend_contract_template_obligation()
|
||||
{
|
||||
return $this->belongsTo('App\Models\ContractTemplateObligation', 'depend_contract_template_obligation_id');
|
||||
}
|
||||
|
||||
public function getHashIdAttribute()
|
||||
{
|
||||
return Hasher::encode('contract_template_obligation_dependencies', $this->id);
|
||||
}
|
||||
|
||||
public function getContractTemplateObligationHashIdAttribute()
|
||||
{
|
||||
return Hasher::encode('contract_template_obligations', $this->contract_template_obligation_id);
|
||||
}
|
||||
|
||||
public function getDependContractTemplateObligationHashIdAttribute()
|
||||
{
|
||||
return Hasher::encode('contract_template_obligations', $this->depend_contract_template_obligation_id);
|
||||
}
|
||||
|
||||
public function getContractTemplateObligationListAttribute()
|
||||
{
|
||||
return $this->contract_template_obligation()->get()->makeHidden(['contract_template_obligation_dependency_list']);
|
||||
}
|
||||
|
||||
public function getDependContractTemplateObligationListAttribute()
|
||||
{
|
||||
return $this->depend_contract_template_obligation()->get()->makeHidden(['contract_template_obligation_dependency_list']);
|
||||
}
|
||||
|
||||
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') : '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user