mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-07-17 22:35:19 +00:00
Two follow-ups to the Services reorg that landed in 6d1816bd.
**Documents → Document** (singular). Documents/ was the only plural subdir in app/Services/ — every other bucket (Company, Mail, Module, Pdf, Storage, Update, ExchangeRate) was singular. Renaming to Document/ normalizes the whole tree.
**ExchangeRate → Integrations/ExchangeRate**. Introduces Integrations/ as an umbrella for external-service adapter subsystems. Exchange rate providers move in first; AI providers, payment gateways, and any other driver-pattern integrations land as sibling subdirs (Integrations/Ai/, Integrations/Payment/) without another reorg. Integrations/ was chosen over Providers/ to avoid conceptual collision with Laravel's app/Providers/ — 'check the providers' shouldn't be ambiguous.
17 files moved, 21 consumer files rewritten to point at the new namespaces via literal-string replacement (same approach as the previous reorg). 350 tests pass, Pint clean.
60 lines
1.8 KiB
PHP
60 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Document;
|
|
|
|
use App\Models\CompanySetting;
|
|
use App\Models\ExchangeRateLog;
|
|
use App\Models\Expense;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ExpenseService
|
|
{
|
|
public function create(Request $request): Expense
|
|
{
|
|
$expense = Expense::create($request->getExpensePayload());
|
|
|
|
$companyCurrency = CompanySetting::getSetting('currency', $request->header('company'));
|
|
|
|
if ((string) $expense['currency_id'] !== $companyCurrency) {
|
|
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 update(Expense $expense, Request $request): bool
|
|
{
|
|
$data = $request->getExpensePayload();
|
|
|
|
$expense->update($data);
|
|
|
|
$companyCurrency = CompanySetting::getSetting('currency', $request->header('company'));
|
|
|
|
if ((string) $data['currency_id'] !== $companyCurrency) {
|
|
ExchangeRateLog::addExchangeRateLog($expense);
|
|
}
|
|
|
|
if (isset($request->is_attachment_receipt_removed) && (bool) $request->is_attachment_receipt_removed) {
|
|
$expense->clearMediaCollection('receipts');
|
|
}
|
|
if ($request->hasFile('attachment_receipt')) {
|
|
$expense->clearMediaCollection('receipts');
|
|
$expense->addMediaFromRequest('attachment_receipt')->toMediaCollection('receipts');
|
|
}
|
|
|
|
if ($request->customFields) {
|
|
$expense->updateCustomFields(json_decode($request->customFields));
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|