mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-15 11:42:15 +01:00
Prevent and remove zero values for billable rates
This commit is contained in:
committed by
Constantin Graf
parent
92dde6a701
commit
bd9cede081
@@ -58,12 +58,14 @@ class ImportDatabaseHelper
|
||||
*/
|
||||
private array $validate;
|
||||
|
||||
private ?Closure $beforeSave;
|
||||
|
||||
/**
|
||||
* @param class-string<TModel> $model
|
||||
* @param array<string> $identifiers
|
||||
* @param array<string, array<int, string>> $validate
|
||||
*/
|
||||
public function __construct(string $model, array $identifiers, bool $attachToExisting = false, ?Closure $queryModifier = null, ?Closure $afterCreate = null, array $validate = [])
|
||||
public function __construct(string $model, array $identifiers, bool $attachToExisting = false, ?Closure $queryModifier = null, ?Closure $afterCreate = null, array $validate = [], ?Closure $beforeSave = null)
|
||||
{
|
||||
$this->model = $model;
|
||||
$this->identifiers = $identifiers;
|
||||
@@ -72,6 +74,7 @@ class ImportDatabaseHelper
|
||||
$this->afterCreate = $afterCreate;
|
||||
$this->createdCount = 0;
|
||||
$this->validate = $validate;
|
||||
$this->beforeSave = $beforeSave;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,6 +102,9 @@ class ImportDatabaseHelper
|
||||
foreach ($data as $key => $value) {
|
||||
$model->{$key} = $value;
|
||||
}
|
||||
if ($this->beforeSave !== null) {
|
||||
($this->beforeSave)($model);
|
||||
}
|
||||
$model->save();
|
||||
|
||||
if ($this->afterCreate !== null) {
|
||||
|
||||
@@ -107,7 +107,11 @@ abstract class DefaultImporter implements ImporterContract
|
||||
'nullable',
|
||||
'integer',
|
||||
],
|
||||
]);
|
||||
], beforeSave: function (Project $project) {
|
||||
if ($project->billable_rate === 0) {
|
||||
$project->billable_rate = null;
|
||||
}
|
||||
});
|
||||
$this->projectMemberImportHelper = new ImportDatabaseHelper(ProjectMember::class, ['project_id', 'member_id'], true, function (Builder $builder) {
|
||||
/** @var Builder<ProjectMember> $builder */
|
||||
return $builder->whereBelongsToOrganization($this->organization);
|
||||
@@ -116,7 +120,11 @@ abstract class DefaultImporter implements ImporterContract
|
||||
'nullable',
|
||||
'integer',
|
||||
],
|
||||
]);
|
||||
], beforeSave: function (ProjectMember $projectMember) {
|
||||
if ($projectMember->billable_rate === 0) {
|
||||
$projectMember->billable_rate = null;
|
||||
}
|
||||
});
|
||||
$this->tagImportHelper = new ImportDatabaseHelper(Tag::class, ['name', 'organization_id'], true, function (Builder $builder) {
|
||||
return $builder->where('organization_id', $this->organization->id);
|
||||
}, validate: [
|
||||
|
||||
Reference in New Issue
Block a user