Files
InvoiceShelf/app/Http/Controllers/Company/General/SerialNumberController.php
Darko Gjorgjijoski 947d00a9f1 refactor(services): Documents→Document + ExchangeRate→Integrations/ExchangeRate
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.
2026-04-11 11:30:00 +02:00

78 lines
2.2 KiB
PHP

<?php
namespace App\Http\Controllers\Company\General;
use App\Http\Controllers\Controller;
use App\Models\Estimate;
use App\Models\Invoice;
use App\Models\Payment;
use App\Services\Document\SerialNumberService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class SerialNumberController extends Controller
{
public function nextNumber(Request $request, Invoice $invoice, Estimate $estimate, Payment $payment): JsonResponse
{
$key = $request->key;
$nextNumber = null;
$serial = (new SerialNumberService)
->setCompany($request->header('company'))
->setCustomer($request->userId);
try {
switch ($key) {
case 'invoice':
$nextNumber = $serial->setModel($invoice)
->setModelObject($request->model_id)
->getNextNumber();
break;
case 'estimate':
$nextNumber = $serial->setModel($estimate)
->setModelObject($request->model_id)
->getNextNumber();
break;
case 'payment':
$nextNumber = $serial->setModel($payment)
->setModelObject($request->model_id)
->getNextNumber();
break;
default:
return response()->json([
'success' => false,
]);
}
} catch (\Exception $exception) {
return response()->json([
'success' => false,
'message' => $exception->getMessage(),
]);
}
return response()->json([
'success' => true,
'nextNumber' => $nextNumber,
]);
}
public function placeholders(Request $request): JsonResponse
{
if ($request->input('format')) {
$placeholders = SerialNumberService::getPlaceholders($request->input('format'));
} else {
$placeholders = [];
}
return response()->json([
'success' => true,
'placeholders' => $placeholders,
]);
}
}