Add expense categories if they do not exist on import

This commit is contained in:
David Bomba 2023-05-25 07:25:17 +10:00
parent e5c3c1b257
commit 524901c872
3 changed files with 11 additions and 2 deletions

View File

@ -600,6 +600,8 @@ class BaseTransformer
*/
public function getExpenseCategoryId($name)
{
/** @var \App\Models\ExpenseCategory $ec */
$ec = ExpenseCategory::where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
@ -607,6 +609,13 @@ class BaseTransformer
])
->first();
if($ec)
return $ec->id;
$ec = \App\Factory\ExpenseCategoryFactory::create($this->company->id, $this->company->owner()->id);
$ec->name = $name;
$ec->save();
return $ec ? $ec->id : null;
}

View File

@ -59,7 +59,7 @@ class CompanyTaxRate implements ShouldQueue
->where('country_id', 840)
->whereNotNull('postal_code')
->whereNull('tax_data')
->whereFalse('is_tax_exempt')
->where('is_tax_exempt', false)
->cursor()
->each(function ($client) {

View File

@ -24,7 +24,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property int|null $created_at
* @property int|null $updated_at
* @property int|null $deleted_at
* @property int $is_deleted
* @property bool $is_deleted
* @property string $color
* @property int|null $bank_category_id
* @property-read \App\Models\Expense|null $expense