mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 17:24:10 +00:00
New services: - ExchangeRateProviderService: CRUD, API status checks, currency converter URL resolution (extracted 122 lines from ExchangeRateProvider model) - FileDiskService: create, update, setAsDefault, validateCredentials (extracted 97 lines from FileDisk model) - ItemService: create/update with tax handling (extracted from Item model) - TransactionService: create/complete/fail (extracted from Transaction model) - CustomFieldService: create/update with slug generation (extracted from CustomField model) Controllers updated to use constructor-injected services: ExchangeRateProviderController, DiskController, ItemsController, CustomFieldsController.
50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\CompanySetting;
|
|
use App\Models\Item;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class ItemService
|
|
{
|
|
public function create(Request $request): Item
|
|
{
|
|
$data = $request->validated();
|
|
$data['company_id'] = $request->header('company');
|
|
$data['creator_id'] = Auth::id();
|
|
$data['currency_id'] = CompanySetting::getSetting('currency', $request->header('company'));
|
|
$item = Item::create($data);
|
|
|
|
if ($request->has('taxes')) {
|
|
foreach ($request->taxes as $tax) {
|
|
$item->tax_per_item = true;
|
|
$item->save();
|
|
$tax['company_id'] = $request->header('company');
|
|
$item->taxes()->create($tax);
|
|
}
|
|
}
|
|
|
|
return Item::with('taxes')->find($item->id);
|
|
}
|
|
|
|
public function update(Item $item, Request $request): Item
|
|
{
|
|
$item->update($request->validated());
|
|
|
|
$item->taxes()->delete();
|
|
|
|
if ($request->has('taxes')) {
|
|
foreach ($request->taxes as $tax) {
|
|
$item->tax_per_item = true;
|
|
$item->save();
|
|
$tax['company_id'] = $request->header('company');
|
|
$item->taxes()->create($tax);
|
|
}
|
|
}
|
|
|
|
return Item::with('taxes')->find($item->id);
|
|
}
|
|
}
|