diff --git a/app/Livewire/System/Jcps/JCPCreateForm.php b/app/Livewire/System/Jcps/JCPCreateForm.php
index fe2c48a..560e12d 100644
--- a/app/Livewire/System/Jcps/JCPCreateForm.php
+++ b/app/Livewire/System/Jcps/JCPCreateForm.php
@@ -1,35 +1,25 @@
[
- 'title' => 'Job Competency Profile Information',
- 'description' => 'Make sure the information you enter corresponds to the Job Description.',
- ],
- 2 => [
- 'title' => 'Prerequisite Information',
- 'description' => 'Enter the information regarding required qualifications, certifications, and/or licenses.',
- ],
- 3 => [
- 'title' => 'Skills Information',
- 'description' => 'Enter the information regarding required skills and abilities.',
- ],
- ];
-
- public function nextPage()
- {
- $this->validateForm();
- $this->currentPage++;
- }
-
- public function previousPage()
- {
- $this->currentPage--;
- }
public function addSkill()
{
$this->jcp_skills[] = ['skill_id' => '', 'required_rating' => 1];
}
+
public function removeSkill($index)
{
unset($this->jcp_skills[$index]);
$this->jcp_skills = array_values($this->jcp_skills); // Reindex the array
}
+
public function createJCPInformation()
{
$this->save();
@@ -84,80 +50,66 @@ public function createJCPInformation()
public function save()
{
- dd($this->validateForm());
-
- // Check if a record already exists for the given user_id and assessment_id
- $existingJcp = Jcp::where('user_id', $this->user_id)
- ->where('assessment_id', 1)
- ->first();
-
- if ($existingJcp) {
- session()->flash('error', 'A JCP for this user and assessment already exists.');
-
- return redirect()->route('jcp.index'); // redirect back with an error message
- }
-
+ $this->validateForm();
// Create a new JCP
- $jcp = Jcp::create([
+
+ $jcp = JCP::create([
'position_title' => $this->position_title,
'duty_station' => $this->duty_station,
+ 'user_id' => $this->user_id,
'job_grade' => $this->job_grade,
'job_purpose' => $this->job_purpose,
+ 'is_active' => $this->is_active,
- 'is_active' => is_null($this->is_active) ? null : 0, //Add Frontend for these elements
- 'user_id' => $this->user_id,
- 'assessment_id' => assessment::find(1)->id, //testing
]);
+
// Attach qualifications
- foreach ($this->jcp_qualifications as $qualId) {
- $jcp->qualifications()->attach($qualId);
- }
+ $jcp->qualifications()->sync($this->jcp_qualifications);
+
// Attach prerequisites
- foreach ($this->jcp_prerequisites as $prerequisite_id) {
- $jcp->prerequisites()->attach($prerequisite_id);
- }
+ $jcp->prerequisites()->sync($this->jcp_prerequisites);
// Attach skills with required rating
foreach ($this->jcp_skills as $skill) {
- if (! empty($skill['skill_id'])) {
+ if (!empty($skill['skill_id'])) {
$jcp->skills()->attach($skill['skill_id'], ['required_level' => $skill['required_rating']]);
}
}
- session()->flash('status', 'JCP successfully created.');
+ $this->reset();
- return redirect()->route('jcp.index');
+ return redirect()->route('jcp.index')->with('success','JCP successfully created.');
}
+
public function validateForm()
{
- $rules = [];
- if ($this->currentPage === 1) {
- $rules = [
- 'position_title' => 'required|string|max:255',
- 'duty_station' => 'required|string|max:255',
- 'job_grade' => 'required|string|max:255',
- 'job_purpose' => 'required|string',
- 'user_id' => 'required|exists:users,id',
- ];
- } elseif ($this->currentPage === 2) {
- $rules = [
- 'jcp_qualifications.*' => 'required|exists:qualifications,id',
- 'jcp_prerequisites.*' => 'required|exists:prerequisites,id',
- ];
- } elseif ($this->currentPage === 3) {
- $rules = [
- 'jcp_skills.*.skill_id' => 'required|exists:skills,id',
- 'jcp_skills.*.required_rating' => 'required|integer|min:1|max:5',
- ];
- }
+ $this->validate([
- $this->validate($rules);
- }
+ 'position_title' => 'required|string|max:255',
+ 'duty_station' => 'required|string|max:255',
+
+ 'user_id' => 'required|exists:users,id',
+
+ 'job_grade' => 'required|string',
+
+ 'job_purpose' => 'required|string',
+
+ 'is_active' => 'boolean',
+
+ 'jcp_qualifications' => 'required|array',
+
+ 'jcp_qualifications.*' => 'exists:qualifications,id', // Validate each qualification
+
+ // Add other validations as necessary
+
+ ]);
+
+ }
public function render()
{
return view('livewire.system.jcps.j-c-p-create-form', [
@@ -167,4 +119,5 @@ public function render()
'prerequisites' => Prerequisite::all(),
]);
}
+
}
diff --git a/app/Models/Audit/assessment.php b/app/Models/Audit/assessment.php
index 0340c93..105fc46 100644
--- a/app/Models/Audit/assessment.php
+++ b/app/Models/Audit/assessment.php
@@ -12,11 +12,6 @@ class assessment extends Model
protected $guarded = [];
- public function jcp()
- {
- return $this->hasMany(jcp::class, 'assessment_id');
-
- }
public function enrolled()
{
diff --git a/app/Models/Audit/jcp.php b/app/Models/Audit/jcp.php
index ede2a31..bbbc8d5 100644
--- a/app/Models/Audit/jcp.php
+++ b/app/Models/Audit/jcp.php
@@ -17,10 +17,6 @@ public function employee()
return $this->belongsTo(User::class, 'user_id');
}
- public function assessment()
- {
- return $this->belongsTo(assessment::class, 'assessment_id');
- }
public function skills()
{
diff --git a/database/factories/Audit/jcpFactory.php b/database/factories/Audit/jcpFactory.php
index 8474bef..33a038e 100644
--- a/database/factories/Audit/jcpFactory.php
+++ b/database/factories/Audit/jcpFactory.php
@@ -16,12 +16,10 @@ class jcpFactory extends Factory
*/
public function definition(): array
{
- $assessment_ids = \App\Models\Audit\assessment::select('id')->get();
$user_ids = \App\Models\User::select('id')->get();
return [
//This populates the jcp model fields
- 'assessment_id' => $this->faker->randomElement($assessment_ids),
'user_id' => $this->faker->unique()->randomElement($user_ids),
'position_title' => $this->faker->jobTitle(),
'job_grade' => $this->faker->numerify('B-#'),
diff --git a/database/migrations/2024_03_22_094647_create_jcps_table.php b/database/migrations/2024_03_22_094647_create_jcps_table.php
index d8a1c1a..f72dc3e 100644
--- a/database/migrations/2024_03_22_094647_create_jcps_table.php
+++ b/database/migrations/2024_03_22_094647_create_jcps_table.php
@@ -13,7 +13,6 @@ public function up(): void
{
Schema::create('jcps', function (Blueprint $table) {
$table->id();
- $table->foreignId('assessment_id')->constrained()->cascadeOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->string('position_title');
@@ -23,7 +22,6 @@ public function up(): void
$table->integer('is_active')->default(1);
// Add a unique constraint
- $table->unique(['user_id', 'assessment_id']);
$table->timestamps();
});
diff --git a/resources/views/livewire/system/assessments/assessments-table.blade.php b/resources/views/livewire/system/assessments/assessments-table.blade.php
index 7196c86..a9df2ac 100644
--- a/resources/views/livewire/system/assessments/assessments-table.blade.php
+++ b/resources/views/livewire/system/assessments/assessments-table.blade.php
@@ -6,12 +6,12 @@
-
+
-
+
Assessment
diff --git a/resources/views/livewire/system/jcps/j-c-p-create-form.blade.php b/resources/views/livewire/system/jcps/j-c-p-create-form.blade.php
index 1c2c158..97cb1c5 100644
--- a/resources/views/livewire/system/jcps/j-c-p-create-form.blade.php
+++ b/resources/views/livewire/system/jcps/j-c-p-create-form.blade.php
@@ -1,30 +1,34 @@
- {{ $pages[$currentPage]['title'] }}
+ Create Job Competency Profile (JCP)
- {{ $pages[$currentPage]['description'] }}
+ Fill out the form below to create a new Job Competency Profile.
- @if ($currentPage === 1)
-
+
-
+
+
-
+
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ @foreach (['a1', 'a2', 'a3', 'a4', 'b1', 'b2', 'b3', 'b4', 'bu', 'c1', 'c2', 'c3', 'c4', 'cu', 'd1', 'd2', 'd3', 'd4', 'du'] as $grade)
+
+ @endforeach
@@ -65,110 +55,116 @@
-
+
+
- {{-- Prerequisite Information --}}
- @elseif ($currentPage === 2 )
+
-
-
- @forelse ($qualifications as $qualification)
-
- @empty
-
- @endforelse
-
-
+ @foreach ($qualifications as $qualification)
+
+
+
+
+ @endforeach
+
+
- {{-- Skills Information --}}
- @elseif ($currentPage === 3 )
-
-
-
- Skill Title |
- Required Rating |
+
+
+
+
+
+
+ Skill
+ Title |
+
+ Required Rating |
+
+ Action |
+
- @foreach ($jcp_skills as $index => $skill)
-
-
-
- @foreach ($skills as $availableSkill)
-
- @endforeach
-
- |
-
-
-
-
-
-
-
-
-
- |
-
- Delete
- |
-
- @endforeach
+ @foreach ($jcp_skills as $index => $skill)
+
+
+
+
+ @foreach ($skills as $availableSkill)
+
+ @endforeach
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ |
+
+ Delete
+ |
+
+ @endforeach
+
+ {{ __('Add Skill') }}
+
- @endif
-
- @if($currentPage === 1)
-
- {{ __('Previous') }}
-
- @elseif($currentPage > 1)
-
- {{ __('Previous') }}
-
- @endif
-
- @if($currentPage === count($pages))
-
- {{ __('Register JCP') }}
-
- @else
-
- {{ __('Next') }}
-
- @endif
+
+ {{ __('Register JCP') }}
+
diff --git a/resources/views/livewire/system/jcps/j-c-p-table.blade.php b/resources/views/livewire/system/jcps/j-c-p-table.blade.php
index 483c603..ef21c5a 100644
--- a/resources/views/livewire/system/jcps/j-c-p-table.blade.php
+++ b/resources/views/livewire/system/jcps/j-c-p-table.blade.php
@@ -4,12 +4,12 @@