Browse Source

Merge branch 'project-work-duration-attribute'

pull/18/head
Nafies Luthfi 7 years ago
parent
commit
5cebcbd542
  1. 20
      app/Entities/Projects/Project.php
  2. 14
      app/Entities/Projects/ProjectPresenter.php
  3. 2
      resources/views/customers/projects.blade.php
  4. 2
      resources/views/projects/index.blade.php
  5. 2
      resources/views/users/projects.blade.php
  6. 22
      tests/Unit/Models/ProjectTest.php

20
app/Entities/Projects/Project.php

@ -224,4 +224,24 @@ class Project extends Model
->with('worker', 'tasks')
->get();
}
public function getWorkDurationAttribute()
{
$startDate = $this->start_date;
$endDate = $this->end_date;
if (is_null($endDate)) {
return '-';
}
$workDuration = dateDifference($startDate, $endDate);
if ((int) $workDuration > 365) {
return dateDifference($startDate, $endDate, '%y Year(s) %m Month(s)');
} elseif ((int) $workDuration > 30) {
return dateDifference($startDate, $endDate, '%m Month(s) %d Day(s)');
}
return $workDuration.' Day(s)';
}
}

14
app/Entities/Projects/ProjectPresenter.php

@ -21,18 +21,4 @@ class ProjectPresenter extends Presenter
{
return ProjectStatus::getNameById($this->entity->status_id);
}
public function workDuration()
{
if (is_null($this->entity->end_date)) {
return '-';
}
$workDuration = dateDifference($this->entity->start_date, $this->entity->end_date);
if ((int) $workDuration > 30) {
return dateDifference($this->entity->start_date, $this->entity->end_date, '%m Bulan %d Hari');
}
return $workDuration.' Hari';
}
}

2
resources/views/customers/projects.blade.php

@ -20,7 +20,7 @@
<td>{{ 1 + $key }}</td>
<td>{{ $project->nameLink() }}</td>
<td class="text-center">{{ $project->start_date }}</td>
<td class="text-right">{{ $project->present()->workDuration }}</td>
<td class="text-right">{{ $project->work_duration }}</td>
<td class="text-right">{{ formatRp($project->project_value) }}</td>
<td class="text-center">{{ $project->present()->status }}</td>
<td class="text-center">

2
resources/views/projects/index.blade.php

@ -42,7 +42,7 @@
<td>{{ $projects->firstItem() + $key }}</td>
<td>{{ $project->nameLink() }}</td>
<td class="text-center">{{ $project->start_date }}</td>
<td class="text-right">{{ $project->present()->workDuration }}</td>
<td class="text-right">{{ $project->work_duration }}</td>
@if (request('status_id') == 2)
<td class="text-right">{{ formatDecimal($project->getJobOveralProgress()) }} %</td>
<td class="text-center">{{ $project->due_date }}</td>

2
resources/views/users/projects.blade.php

@ -29,7 +29,7 @@
<td>{{ $projects->firstItem() + $key }}</td>
<td>{{ $project->nameLink() }}</td>
<td class="text-center">{{ $project->start_date }}</td>
<td class="text-right">{{ $project->present()->workDuration }}</td>
<td class="text-right">{{ $project->work_duration }}</td>
<td class="text-right">{{ formatRp($project->project_value) }}</td>
<td class="text-center">{{ $project->present()->status }}</td>
<td>{{ $project->customer->name }}</td>

22
tests/Unit/Models/ProjectTest.php

@ -209,4 +209,26 @@ class ProjectTest extends TestCase
$this->assertInstanceOf(Collection::class, $project->comments);
$this->assertInstanceOf(Comment::class, $project->comments->first());
}
/** @test */
public function project_has_work_duration_attribute()
{
$project = factory(Project::class)->create([
'start_date' => '2016-06-10',
'end_date' => '2016-07-21',
]);
$this->assertEquals('1 Month(s) 11 Day(s)', $project->work_duration);
}
/** @test */
public function project_work_duration_attribute_returns_proper_multi_years_work_duration()
{
$project = factory(Project::class)->create([
'start_date' => '2015-04-10',
'end_date' => '2017-07-21',
]);
$this->assertEquals('2 Year(s) 3 Month(s)', $project->work_duration);
}
}
Loading…
Cancel
Save