Skip to content

Commit

Permalink
Merge pull request #3677 from ColoredCow/fix/project-stages-new-migra…
Browse files Browse the repository at this point in the history
…tion-table

#3664 Created new migration table for project stages
  • Loading branch information
P4NK4J authored Jul 4, 2024
2 parents 2e08db2 + ac84fb0 commit 8ea8fe9
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Modules/Project/Entities/ProjectStages.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class ProjectStages extends Model
{
protected $table = 'project_old_stages';
protected $table = 'project_new_stages';
protected $guarded = [];
protected $fillables = ['project_id', 'stage_name', 'status', 'created_at', 'updated_at', 'end_date', 'comments'];

Expand Down
4 changes: 2 additions & 2 deletions Modules/Project/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ public function manageStage(Request $request)
'newStages.*.status' => 'nullable|string',
'newStages.*.expected_end_date' => 'required|date',
'deletedStages' => 'nullable|array',
'deletedStages.*' => 'required|integer|exists:project_old_stages,id',
'deletedStages.*' => 'required|integer|exists:project_new_stages,id',
'updatedStages' => 'nullable|array',
'updatedStages.*.id' => 'required|integer|exists:project_old_stages,id',
'updatedStages.*.id' => 'required|integer|exists:project_new_stages,id',
]);

if (empty($validatedData['deletedStages']) && empty($validatedData['newStages']) && empty($validatedData['updatedStages'])) {
Expand Down
11 changes: 8 additions & 3 deletions Modules/Project/Resources/views/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@
return delay ? `${duration} (<strong>Delay: </strong>${delay})` : duration;
},
calculateDelay(endDate, expectedEndDate) {
const delaySeconds = Math.floor((new Date(endDate) - new Date(expectedEndDate)) / 1000);
return delaySeconds > 0 ? this.convertToDateTime(delaySeconds) : null;
const delayDays = Math.floor((new Date(endDate).setHours(0, 0, 0, 0) - new Date(expectedEndDate).setHours(0, 0, 0, 0)) / 1000);
return delayDays > 0 ? this.convertToDateTime(delayDays) : null;
},
formattedDate(dateTime) {
return dateTime ? new Date(dateTime).toISOString().split('T')[0] : '';
Expand Down Expand Up @@ -420,9 +420,14 @@
const stage = this.stages[index];
stage.status = status;
if (status === 'started') {
stage.start_date = new Date().toISOString();
if (status !== this.stages[index].initialStatus) {
this.stages[index].start_date = new Date().toISOString();
}
stage.end_date = null;
} else if (status === 'completed') {
if ('started' !== this.stages[index].initialStatus) {
this.stages[index].start_date = new Date().toISOString();
}
stage.end_date = new Date().toISOString();
} else if (status === 'pending') {
stage.start_date = null;
Expand Down
2 changes: 1 addition & 1 deletion Modules/Project/Services/ProjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ private function prepareStageData(array $stage): array
'start_date' => $startDate,
'end_date' => $endDate,
'expected_end_date' => $stage['expected_end_date'],
'duration' => $duration,
'duration' => $duration ?: 1,
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateProjectNewStageTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('project_new_stages', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('project_id')->nullable();
$table->text('stage_name');
$table->text('status')->nullable();
$table->unsignedBigInteger('duration')->nullable();
$table->datetime('start_date')->nullable();
$table->datetime('end_date')->nullable();
$table->date('expected_end_date')->nullable();
$table->text('comments')->nullable();
$table->timestamps();
});

Schema::table('project_new_stages', function (Blueprint $table) {
$table->foreign('project_id')->references('id')->on('projects');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('project_new_stages');
}
}

This file was deleted.

0 comments on commit 8ea8fe9

Please sign in to comment.