File: D:/HostingSpaces/SBogers10/hours.komma.pro/app/Komma/Excel/Types/Row/HourRow.php
<?php
namespace App\Komma\Excel\Types\Row;
use App\Komma\Hours\Hour;
use App\Komma\Subprojects\Subproject;
use App\Komma\Users\User;
use Carbon\Carbon;
class HourRow extends AbstractTypeRow
{
public string $project;
public string $subProject;
public string $task;
public float $hourRate;
public ?float $billableHours;
public ?float $notBillableHours;
public string $description;
public string $internDescription;
public Carbon $date;
public User $user;
public bool $billable;
public bool $billed;
public bool $bug;
public function __construct(Subproject $subProject, Hour $hour)
{
$this->extractAttributesFromSubProject($subProject);
$this->extractAttributesFromHour($hour);
}
/**
* Map the direct values of the Subproject
*
* @param Subproject $subproject
*/
private function extractAttributesFromSubProject(Subproject $subproject)
{
$this->project = $subproject->Project->name;
$this->subProject = $subproject->name;
$this->hourRate = floatval($subproject->hourly_rate);
}
/**
* Map the direct values of the Hour
*
* @param Hour $hour
*/
private function extractAttributesFromHour(Hour $hour)
{
$this->task = $hour->Task->TaskTemplate->name;
$this->description = $hour->description;
$this->internDescription = !empty($hour->intern_description) ? $hour->intern_description : '';
$this->date = $hour->date;
$this->user = $hour->User;
$this->bug = $hour->bug;
$this->billed = !empty($hour->billed_at);
if($hour->billable == 1 && $hour->exceed_subproject == 0) {
$this->billable = true;
$this->billableHours = floatval($hour->value);
$this->notBillableHours = null;
}
else {
$this->billable = false;
$this->billableHours = null;
$this->notBillableHours = floatval($hour->value);
}
}
/**
* Check if row has any styling rules
*
* @return bool
*/
function hasStyling(): bool
{
$hasStyling = false;
if(!$this->billable) $hasStyling = true;
return $hasStyling;
}
/**
* Get the styling properties
*
* @return string
*/
public function getStylingProperties(): string
{
if(!$this->billable) {
// return 'color: #ff0000; background-color: #ffefef;';
return 'color: #ff0000;';
}
return '';
}
}