Deploy Ladill Mini / deploy (push) Successful in 23s
Staff-facing counter register at pos.ladill.com with catalog cart, cash and MoMo/card checkout via Ladill Pay, CRM timeline/import, invoice prefill, and Merchant catalog import. Co-authored-by: Cursor <cursoragent@cursor.com>
60 lines
1.9 KiB
PHP
60 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\Mini;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\MiniPayment;
|
|
use App\Models\QrCode;
|
|
use App\Services\Billing\BillingClient;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Throwable;
|
|
|
|
class OverviewController extends Controller
|
|
{
|
|
public function __construct(private BillingClient $billing) {}
|
|
|
|
public function __invoke(): JsonResponse
|
|
{
|
|
$account = ladill_account();
|
|
|
|
$qrIds = $account->qrCodes()
|
|
->where('type', QrCode::TYPE_PAYMENT)
|
|
->pluck('id');
|
|
|
|
$todayPayments = MiniPayment::query()
|
|
->whereIn('qr_code_id', $qrIds)
|
|
->where('status', MiniPayment::STATUS_PAID)
|
|
->where('paid_at', '>=', now()->startOfDay());
|
|
|
|
$recentPayments = MiniPayment::query()
|
|
->whereIn('qr_code_id', $qrIds)
|
|
->where('status', MiniPayment::STATUS_PAID)
|
|
->with('qrCode')
|
|
->latest('paid_at')
|
|
->limit(8)
|
|
->get();
|
|
|
|
$balanceMinor = 0;
|
|
try {
|
|
$balanceMinor = $this->billing->balanceMinor($account->public_id);
|
|
} catch (Throwable $e) {
|
|
Log::warning('Mini API overview could not load wallet balance', [
|
|
'user' => $account->public_id,
|
|
'error' => $e->getMessage(),
|
|
]);
|
|
}
|
|
|
|
return response()->json([
|
|
'data' => [
|
|
'currency' => 'GHS',
|
|
'today_takings_minor' => (int) (clone $todayPayments)->sum('merchant_amount_minor'),
|
|
'today_count' => (clone $todayPayments)->count(),
|
|
'payment_qr_count' => $qrIds->count(),
|
|
'wallet_balance_minor' => $balanceMinor,
|
|
'recent_payments' => $recentPayments->map(fn (MiniPayment $p) => PaymentPresenter::present($p))->values(),
|
|
],
|
|
]);
|
|
}
|
|
}
|