Added billable flag to projects

This commit is contained in:
Constantin Graf
2024-06-04 14:35:02 +02:00
committed by Constantin Graf
parent 20f9b344f6
commit 86555664c5
10 changed files with 106 additions and 19 deletions

View File

@@ -85,6 +85,7 @@ class ProjectController extends Controller
$project = new Project();
$project->name = $request->input('name');
$project->color = $request->input('color');
$project->is_billable = (bool) $request->input('is_billable');
$project->billable_rate = $request->input('billable_rate');
$project->client_id = $request->input('client_id');
$project->organization()->associate($organization);
@@ -105,6 +106,7 @@ class ProjectController extends Controller
$this->checkPermission($organization, 'projects:update', $project);
$project->name = $request->input('name');
$project->color = $request->input('color');
$project->is_billable = (bool) $request->input('is_billable');
$project->billable_rate = $request->input('billable_rate');
$project->client_id = $request->input('client_id');
$project->save();

View File

@@ -38,6 +38,10 @@ class ProjectStoreRequest extends FormRequest
'max:255',
new ColorRule(),
],
'is_billable' => [
'required',
'boolean',
],
'billable_rate' => [
'nullable',
'integer',

View File

@@ -37,6 +37,10 @@ class ProjectUpdateRequest extends FormRequest
'max:255',
new ColorRule(),
],
'is_billable' => [
'required',
'boolean',
],
'billable_rate' => [
'nullable',
'integer',

View File

@@ -20,6 +20,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
* @property string $organization_id
* @property string $client_id
* @property int|null $billable_rate
* @property bool $is_billable
* @property-read Organization $organization
* @property-read Client|null $client
* @property-read Collection<int, Task> $tasks
@@ -43,6 +44,15 @@ class Project extends Model
'color' => 'string',
];
/**
* Set default values for attributes.
*
* @var array<string, mixed>
*/
protected $attributes = [
'is_billable' => false,
];
/**
* @return BelongsTo<Organization, Project>
*/

View File

@@ -41,6 +41,7 @@ class ClockifyProjectsImporter extends DefaultImporter
], [
'client_id' => $clientId,
'color' => $this->colorService->getRandomColor(),
'is_billable' => $record['Billability'] === 'Yes',
'billable_rate' => $billableRateKey !== null && $record[$billableRateKey] !== '' ? (int) (((float) $record[$billableRateKey]) * 100) : null,
]);
}

View File

@@ -96,6 +96,10 @@ abstract class DefaultImporter implements ImporterContract
'required',
'max:255',
],
'is_billable' => [
'required',
'boolean',
],
'billable_rate' => [
'nullable',
'integer',

View File

@@ -121,6 +121,7 @@ class TogglDataImporter extends DefaultImporter
], [
'client_id' => $clientId,
'color' => $project->color,
'is_billable' => $project->rate !== null,
'billable_rate' => $project->rate !== null ? (int) ($project->rate * 100) : null,
], (string) $project->id);