diff --git a/app/Http/Controllers/User/Api/ContractController.php b/app/Http/Controllers/User/Api/ContractController.php
index bd7a0a7..821302f 100644
--- a/app/Http/Controllers/User/Api/ContractController.php
+++ b/app/Http/Controllers/User/Api/ContractController.php
@@ -45,4 +45,11 @@ class ContractController extends BaseController
$contract = ContractModule::delete($request, $hash_id);
return $contract;
}
+
+ public function validCheck(Request $request, $hash_id = '')
+ {
+ $method = empty($hash_id) ? 'POST' :'PUT';
+ $valid = ContractModule::validCheck($request, $hash_id, $method);
+ return $valid;
+ }
}
diff --git a/app/Http/Modules/User/ContractModule.php b/app/Http/Modules/User/ContractModule.php
index 780b598..afc0c4e 100644
--- a/app/Http/Modules/User/ContractModule.php
+++ b/app/Http/Modules/User/ContractModule.php
@@ -230,6 +230,14 @@ class ContractModule extends BaseController
return response()->json($data);
}
+ public static function validCheck(Request $request, $hash_id = '', $method = 'POST')
+ {
+ $id = $hash_id ? Hasher::decode('contracts', $hash_id) : '';
+ $validation = ContractModule::validation($request, $id, $method);
+ if (!$validation->status) {
+ return response()->json($validation, 422);
+ }
+ }
private static function validation(Request $request, $id = '', $method = 'POST')
{
diff --git a/app/Models/Contract.php b/app/Models/Contract.php
index fbf51c3..82ddfac 100644
--- a/app/Models/Contract.php
+++ b/app/Models/Contract.php
@@ -11,7 +11,7 @@ class Contract extends Model
{
protected $table = 'contracts';
- protected $appends = ['hash_id', 'contract_obligation_list'];
+ protected $appends = ['hash_id', 'contract_obligation_list', 'contract_entity_list'];
protected $hidden = [
'id', 'in_time_contract_template',
@@ -22,6 +22,11 @@ class Contract extends Model
return $this->hasMany('App\Models\ContractObligation', 'contract_id');
}
+ public function contract_entity()
+ {
+ return $this->hasMany('App\Models\ContractEntity', 'contract_id');
+ }
+
public function getHashIdAttribute()
{
return Hasher::encode('contracts', $this->id);
@@ -32,6 +37,11 @@ class Contract extends Model
return $this->contract_obligation()->get()->makeHidden(['contract_list']);
}
+ public function getContractEntityListAttribute()
+ {
+ return $this->contract_entity()->get()->makeHidden(['contract_list']);
+ }
+
public function getUpdatedAtAttribute($date)
{
return $date ? Carbon::parse($date)->timezone('Asia/Kuala_Lumpur')->format('Y-m-d') : '';
diff --git a/app/Models/ContractEntity.php b/app/Models/ContractEntity.php
index af1fcd3..c9631be 100644
--- a/app/Models/ContractEntity.php
+++ b/app/Models/ContractEntity.php
@@ -2,10 +2,49 @@
namespace App\Models;
-use Illuminate\Database\Eloquent\Factories\HasFactory;
+use App\Http\Helpers\Hasher;
+
use Illuminate\Database\Eloquent\Model;
+use Carbon\Carbon;
class ContractEntity extends Model
{
- use HasFactory;
+ protected $table = 'contract_entities';
+
+ protected $appends = ['hash_id', 'contract_list', 'entity_list'];
+
+ public function contract()
+ {
+ return $this->belongsTo('App\Models\Contract', 'contract_id');
+ }
+
+ public function entity()
+ {
+ return $this->belongsTo('App\Models\Entity', 'entity_id');
+ }
+
+ public function getHashIdAttribute()
+ {
+ return Hasher::encode('contract_entities', $this->id);
+ }
+
+ public function getContractListAttribute()
+ {
+ return $this->contract()->get()->makeHidden(['contract_entity_list']);
+ }
+
+ public function getEntityListAttribute()
+ {
+ return $this->entity()->get()->makeHidden(['entity_signature_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') : '';
+ }
}
diff --git a/app/Models/ContractObligation.php b/app/Models/ContractObligation.php
index 5985cfb..d260909 100644
--- a/app/Models/ContractObligation.php
+++ b/app/Models/ContractObligation.php
@@ -15,7 +15,8 @@ class ContractObligation extends Model
'hash_id',
'contract_list',
'contract_obligation_dependency_list',
- 'depend_contract_obligation_dependency_list'
+ 'depend_contract_obligation_dependency_list',
+ 'contract_entity_list'
];
protected $hidden = [
@@ -37,6 +38,11 @@ class ContractObligation extends Model
return $this->hasMany('App\Models\ContractObligationDependency', 'depend_contract_obligation_id');
}
+ public function contract_entity()
+ {
+ return $this->belongsTo('App\Models\ContractEntity', 'contract_entity_id');
+ }
+
public function getHashIdAttribute()
{
return Hasher::encode('contract_obligations', $this->id);
@@ -61,6 +67,11 @@ class ContractObligation extends Model
->get()->makeHidden(['contract_obligation_list', 'depend_contract_obligation_list']);
}
+ public function getContractEntityListAttribute()
+ {
+ return $this->contract_entity()->get()->makeHidden(['contract_list']);
+ }
+
public function getUpdatedAtAttribute($date)
{
return $date ? Carbon::parse($date)->timezone('Asia/Kuala_Lumpur')->format('Y-m-d') : '';
diff --git a/database/seeders/PlumberService/PlumberServiceContractEntitiesTableSeeder.php b/database/seeders/PlumberService/PlumberServiceContractEntitiesTableSeeder.php
index c4476b2..677a89f 100644
--- a/database/seeders/PlumberService/PlumberServiceContractEntitiesTableSeeder.php
+++ b/database/seeders/PlumberService/PlumberServiceContractEntitiesTableSeeder.php
@@ -31,8 +31,8 @@ class PlumberServiceContractEntitiesTableSeeder extends Seeder
'id' => 202,
'user_id' => 3,
'contract_id' => 201,
- 'entity_id' => 203,
- 'entity_signature_id' => 203,
+ 'entity_id' => 202,
+ 'entity_signature_id' => 202,
'type' => 1,
'status' => 1,
'created_at' => date('Y-m-d H:i:s'),
diff --git a/database/seeders/PlumberService/PlumberServiceContractObligationsTableSeeder.php b/database/seeders/PlumberService/PlumberServiceContractObligationsTableSeeder.php
index 661d02e..155fdbc 100644
--- a/database/seeders/PlumberService/PlumberServiceContractObligationsTableSeeder.php
+++ b/database/seeders/PlumberService/PlumberServiceContractObligationsTableSeeder.php
@@ -36,6 +36,7 @@ class PlumberServiceContractObligationsTableSeeder extends Seeder
'contract_template_obligation_id' => 201,
'contract_entity_id' => 201,
'name' => 'mushroom kingdom request service from plumber hero company to rescue princess peach',
+ 'sequence' => 1.0,
'reference' => null,
'content' => null,
'must_complete' => 1,
@@ -59,6 +60,7 @@ class PlumberServiceContractObligationsTableSeeder extends Seeder
'contract_template_obligation_id' => 202,
'contract_entity_id' => 203,
'name' => 'plumber hero company rescue princess peach',
+ 'sequence' => 2.0,
'reference' => null,
'content' => null,
'must_complete' => 1,
@@ -82,6 +84,7 @@ class PlumberServiceContractObligationsTableSeeder extends Seeder
'contract_template_obligation_id' => 203,
'contract_entity_id' => 203,
'name' => 'plumber hero company get reward',
+ 'sequence' => 3.0,
'reference' => null,
'content' => null,
'must_complete' => 1,
@@ -105,6 +108,7 @@ class PlumberServiceContractObligationsTableSeeder extends Seeder
'contract_template_obligation_id' => 204,
'contract_entity_id' => 203,
'name' => 'plumber hero company request plumber rescue mission service',
+ 'sequence' => 1.0,
'reference' => null,
'content' => null,
'must_complete' => 1,
@@ -128,6 +132,7 @@ class PlumberServiceContractObligationsTableSeeder extends Seeder
'contract_template_obligation_id' => 205,
'contract_entity_id' => 202,
'name' => 'plumber hero accept rescue mission',
+ 'sequence' => 2.0,
'reference' => null,
'content' => null,
'must_complete' => 1,
@@ -151,6 +156,7 @@ class PlumberServiceContractObligationsTableSeeder extends Seeder
'contract_template_obligation_id' => 206,
'contract_entity_id' => 202,
'name' => 'plumber hero complete castle level',
+ 'sequence' => 3.0,
'reference' => null,
'content' => null,
'must_complete' => 1,
@@ -174,6 +180,7 @@ class PlumberServiceContractObligationsTableSeeder extends Seeder
'contract_template_obligation_id' => 207,
'contract_entity_id' => 202,
'name' => 'plumber hero defeat bowser',
+ 'sequence' => 4.0,
'reference' => null,
'content' => null,
'must_complete' => 1,
@@ -197,6 +204,7 @@ class PlumberServiceContractObligationsTableSeeder extends Seeder
'contract_template_obligation_id' => 208,
'contract_entity_id' => 202,
'name' => 'plumber hero rescue princess peach',
+ 'sequence' => 5.0,
'reference' => null,
'content' => null,
'must_complete' => 1,
@@ -220,6 +228,7 @@ class PlumberServiceContractObligationsTableSeeder extends Seeder
'contract_template_obligation_id' => 209,
'contract_entity_id' => 202,
'name' => 'plumber hero get reward',
+ 'sequence' => 6.0,
'reference' => null,
'content' => null,
'must_complete' => 1,
diff --git a/resources/js/user/langs/en.js b/resources/js/user/langs/en.js
index e5b19d3..a534003 100644
--- a/resources/js/user/langs/en.js
+++ b/resources/js/user/langs/en.js
@@ -6,6 +6,7 @@ const En = {
'password': 'password',
'complete_day_range': 'complete day range',
'sequence': 'sequence',
+ 'contract_template_id': 'contract template',
'depend_contract_template_id': 'depend contract template',
// Error
@@ -23,6 +24,7 @@ const En = {
'the_content_must_be_less_than_100': 'The %(att)s must be less than 100',
'status_error': 'status not allow update',
'obligation_depend_error': 'contract template obligation dependency error',
+ 'under_error': 'This %(att)s not belong to this user',
// toasted
'have_been_successfully_created': '%(value[0].att)s ( %(value[1].att)s ) have been successfully created',
diff --git a/resources/js/user/pages/contracts/Create.vue b/resources/js/user/pages/contracts/Create.vue
index ce67c00..8f0ca25 100644
--- a/resources/js/user/pages/contracts/Create.vue
+++ b/resources/js/user/pages/contracts/Create.vue
@@ -8,15 +8,15 @@
-
+ >