Remove app/Space folder and extract model business logic into services

Relocate all 14 files from the catch-all app/Space namespace into proper
locations: data providers to Support/Formatters, installation utilities to
Services/Installation, PDF utils to Services/Pdf, module/update classes to
Services/Module and Services/Update, SiteApi trait to Traits, and helpers
to Support.

Extract ~1,400 lines of business logic from 8 fat models (Invoice, Payment,
Estimate, RecurringInvoice, Company, Customer, Expense, User) into 9 new
service classes with constructor injection. Controllers now depend on
services instead of calling static model methods. Shared item/tax creation
logic consolidated into DocumentItemService.
This commit is contained in:
Darko Gjorgjijoski
2026-04-03 15:37:22 +02:00
parent 23ff69026e
commit 0ce88ab817
98 changed files with 1703 additions and 1563 deletions

View File

@@ -232,52 +232,4 @@ class Expense extends Model implements HasMedia
)
->groupBy('expense_category_id');
}
public static function createExpense($request)
{
$expense = self::create($request->getExpensePayload());
$company_currency = CompanySetting::getSetting('currency', $request->header('company'));
if ((string) $expense['currency_id'] !== $company_currency) {
ExchangeRateLog::addExchangeRateLog($expense);
}
if ($request->hasFile('attachment_receipt')) {
$expense->addMediaFromRequest('attachment_receipt')->toMediaCollection('receipts');
}
if ($request->customFields) {
$expense->addCustomFields(json_decode($request->customFields));
}
return $expense;
}
public function updateExpense($request)
{
$data = $request->getExpensePayload();
$this->update($data);
$company_currency = CompanySetting::getSetting('currency', $request->header('company'));
if ((string) $data['currency_id'] !== $company_currency) {
ExchangeRateLog::addExchangeRateLog($this);
}
if (isset($request->is_attachment_receipt_removed) && (bool) $request->is_attachment_receipt_removed) {
$this->clearMediaCollection('receipts');
}
if ($request->hasFile('attachment_receipt')) {
$this->clearMediaCollection('receipts');
$this->addMediaFromRequest('attachment_receipt')->toMediaCollection('receipts');
}
if ($request->customFields) {
$this->updateCustomFields(json_decode($request->customFields));
}
return true;
}
}