added option to import payments from csv file
This commit is contained in:
@@ -8,8 +8,8 @@
|
||||
use App\Models\Booking;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentSetting;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
@@ -20,11 +20,12 @@ public function index(Account $account): Response
|
||||
$payments = Payment::query()
|
||||
->where('account_id', $account->id)
|
||||
->orderByDesc('paid_at')
|
||||
->get(['id', 'amount_cents', 'currency', 'reference', 'paid_at', 'created_at'])
|
||||
->get(['id', 'amount', 'balance_before', 'currency', 'reference', 'paid_at', 'created_at'])
|
||||
->map(function (Payment $p) {
|
||||
return [
|
||||
'id' => $p->id,
|
||||
'amount' => $p->amount, // accessor divides cents
|
||||
'amount' => (float) $p->amount,
|
||||
'balance_before' => (float) ($p->balance_before ?? 0),
|
||||
'currency' => $p->currency,
|
||||
'reference' => $p->reference,
|
||||
'paid_at' => $p->paid_at,
|
||||
@@ -43,11 +44,12 @@ public function list(Account $account): JsonResponse
|
||||
$payments = Payment::query()
|
||||
->where('account_id', $account->id)
|
||||
->orderByDesc('paid_at')
|
||||
->get(['id', 'amount_cents', 'currency', 'reference', 'paid_at', 'created_at'])
|
||||
->get(['id', 'amount', 'balance_before', 'currency', 'reference', 'paid_at', 'created_at'])
|
||||
->map(function (Payment $p) {
|
||||
return [
|
||||
'id' => $p->id,
|
||||
'amount' => $p->amount,
|
||||
'amount' => (float) $p->amount,
|
||||
'balance_before' => (float) ($p->balance_before ?? 0),
|
||||
'currency' => $p->currency,
|
||||
'reference' => $p->reference,
|
||||
'paid_at' => optional($p->paid_at)?->toDateString(),
|
||||
@@ -76,7 +78,8 @@ public function store(StorePaymentRequest $request, Account $account): RedirectR
|
||||
|
||||
$payment = Payment::query()->create([
|
||||
'account_id' => $account->id,
|
||||
'amount_cents' => $amountCents,
|
||||
'balance_before' => (float) ($account->balance_amount ?? 0),
|
||||
'amount' => (float) $validated['amount'],
|
||||
'currency' => strtoupper($validated['currency'] ?? $defaultCurrency),
|
||||
'reference' => $validated['reference'] ?? null,
|
||||
'paid_at' => $validated['paid_at'] ?? now(),
|
||||
@@ -94,10 +97,17 @@ public function store(StorePaymentRequest $request, Account $account): RedirectR
|
||||
'booked_at' => $payment->paid_at ?? now(),
|
||||
]);
|
||||
|
||||
// Optionally create an activity entry with default decision/action
|
||||
// Optionally create an activity entry with default decision/action
|
||||
if ($settings && ($settings->create_activity_on_payment ?? false)) {
|
||||
$note = $settings->activity_note_template ?? 'Prejeto plačilo';
|
||||
$note = str_replace(['{amount}', '{currency}'], [number_format($amountCents / 100, 2, ',', '.'), $payment->currency], $note);
|
||||
|
||||
// Append balance context and cause
|
||||
$account->refresh();
|
||||
$beforeStr = number_format((float) ($payment->balance_before ?? 0), 2, ',', '.').' '.$payment->currency;
|
||||
$afterStr = number_format((float) ($account->balance_amount ?? 0), 2, ',', '.').' '.$payment->currency;
|
||||
$note .= " (Stanje pred: {$beforeStr}, Stanje po: {$afterStr}; Izvor: plačilo)";
|
||||
|
||||
$account->loadMissing('contract');
|
||||
$clientCaseId = $account->contract?->client_case_id;
|
||||
if ($clientCaseId) {
|
||||
@@ -139,6 +149,7 @@ public function destroy(Account $account, Payment $payment): RedirectResponse|Js
|
||||
|
||||
if (request()->wantsJson()) {
|
||||
$account->refresh();
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'balance_amount' => $account->balance_amount,
|
||||
|
||||
Reference in New Issue
Block a user