Prevent and remove zero values for billable rates

This commit is contained in:
Constantin Graf
2024-06-10 19:19:51 +02:00
committed by Constantin Graf
parent 92dde6a701
commit bd9cede081
20 changed files with 343 additions and 9 deletions

View File

@@ -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) {