feat(payments): add customer ledgers and allocations (#744)

This commit is contained in:
Darko Gjorgjijoski
2026-08-05 03:28:35 +02:00
committed by GitHub
parent 8ae82ae91e
commit f322c2b74d
74 changed files with 5693 additions and 693 deletions
@@ -0,0 +1,41 @@
<?php
namespace App\Http\Controllers\Company\Payment;
use App\Http\Controllers\Controller;
use App\Http\Requests\CreditAllocationRequest;
use App\Models\Customer;
use App\Models\Payment;
use App\Services\Document\PaymentAllocationService;
class CreditAllocationsController extends Controller
{
public function __construct(
private readonly PaymentAllocationService $paymentAllocationService,
) {}
public function store(CreditAllocationRequest $request, Customer $customer)
{
$this->authorize('view', $customer);
abort_unless((int) $customer->company_id === (int) $request->header('company'), 404);
$payments = Payment::query()
->where('company_id', $customer->company_id)
->where('customer_id', $customer->id)
->whereIn('id', collect($request->validated('allocations'))->pluck('payment_id')->unique())
->get();
foreach ($payments as $payment) {
$this->authorize('update', $payment);
}
$this->paymentAllocationService->applyCustomerCredits(
(int) $request->header('company'),
$customer->id,
$request->validated('allocations'),
);
return response()->json(['success' => true]);
}
}