Align POS header with other apps: AI assistant, register button, sidebar
Deploy Ladill POS / deploy (push) Successful in 47s
Deploy Ladill POS / deploy (push) Successful in 47s
- Add the Afia AI assistant to the header (topbar AI button + slide-over), matching every other Ladill app. Ports config/afia.php, AfiaService, a POS AiController (pos.ai.chat) scoped to register/sales/products, and includes the slide-over in the app layout. The afia() Alpine component already existed. - Hide the header "Open register" button while on the register page. - Move Settings to a pinned bottom section of the sidebar, like other apps. - Commit the updated POS logo + launcher icon assets. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
b7c7a32ee6
commit
e9a0c92308
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Pos;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Pos\Concerns\ScopesToAccount;
|
||||
use App\Models\PosProduct;
|
||||
use App\Models\PosSale;
|
||||
use App\Services\Afia\AfiaService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AiController extends Controller
|
||||
{
|
||||
use ScopesToAccount;
|
||||
|
||||
public function chat(Request $request, AfiaService $afia): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'message' => ['required', 'string', 'max:2000'],
|
||||
'history' => ['nullable', 'array', 'max:20'],
|
||||
'history.*.role' => ['nullable', 'string'],
|
||||
'history.*.text' => ['nullable', 'string'],
|
||||
]);
|
||||
|
||||
if (! $afia->enabled()) {
|
||||
return response()->json(['message' => 'Afia is not available right now.'], 503);
|
||||
}
|
||||
|
||||
try {
|
||||
$reply = $afia->chat(trim($validated['message']), $validated['history'] ?? [], $this->context($request));
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
|
||||
return response()->json(['message' => 'Afia could not respond right now. Please try again.'], 502);
|
||||
}
|
||||
|
||||
return response()->json(['reply' => $reply]);
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
private function context(Request $request): array
|
||||
{
|
||||
$owner = $this->ownerRef($request);
|
||||
$currency = strtoupper((string) config('pos.default_currency', 'GHS'));
|
||||
|
||||
$todaySales = PosSale::owned($owner)
|
||||
->where('status', PosSale::STATUS_PAID)
|
||||
->where('paid_at', '>=', now()->startOfDay());
|
||||
|
||||
$todayTotalMinor = (int) (clone $todaySales)->sum('total_minor');
|
||||
|
||||
return [
|
||||
'signed_in' => 'yes',
|
||||
'today_takings' => $currency.' '.number_format($todayTotalMinor / 100, 2),
|
||||
'today_sales_count' => (clone $todaySales)->count(),
|
||||
'active_products' => PosProduct::owned($owner)->active()->count(),
|
||||
'pending_sales' => PosSale::owned($owner)->where('status', PosSale::STATUS_PENDING)->count(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user