diff --git a/QatarPOS/.gitignore b/QatarPOS/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..f9ba7f8b4901d059a522d76272612aa2a8321bc3 --- /dev/null +++ b/QatarPOS/.gitignore @@ -0,0 +1,6 @@ +node_modules +dist +.DS_Store +server/public +vite.config.ts.* +*.tar.gz \ No newline at end of file diff --git a/QatarPOS/.replit b/QatarPOS/.replit new file mode 100644 index 0000000000000000000000000000000000000000..51f344ffac11f3c19cd01f940721e073a6ab4c1d --- /dev/null +++ b/QatarPOS/.replit @@ -0,0 +1,36 @@ +modules = ["nodejs-20", "web", "postgresql-16"] +run = "npm run dev" +hidden = [".config", ".git", "generated-icon.png", "node_modules", "dist"] + +[nix] +channel = "stable-24_05" + +[deployment] +deploymentTarget = "autoscale" +build = ["npm", "run", "build"] +run = ["npm", "run", "start"] + +[[ports]] +localPort = 5000 +externalPort = 80 + +[workflows] +runButton = "Project" + +[[workflows.workflow]] +name = "Project" +mode = "parallel" +author = "agent" + +[[workflows.workflow.tasks]] +task = "workflow.run" +args = "Start application" + +[[workflows.workflow]] +name = "Start application" +author = "agent" + +[[workflows.workflow.tasks]] +task = "shell.exec" +args = "npm run dev" +waitForPort = 5000 diff --git a/QatarPOS/attached_assets/Pasted-You-are-a-senior-full-stack-developer-Generate-a-multi-tenant-cloud-native-Point-of-Sale-POS-mic-1752578171314_1752578171315.txt b/QatarPOS/attached_assets/Pasted-You-are-a-senior-full-stack-developer-Generate-a-multi-tenant-cloud-native-Point-of-Sale-POS-mic-1752578171314_1752578171315.txt new file mode 100644 index 0000000000000000000000000000000000000000..e0027dc18343b9ee3f854d59f2a8827262b6f423 --- /dev/null +++ b/QatarPOS/attached_assets/Pasted-You-are-a-senior-full-stack-developer-Generate-a-multi-tenant-cloud-native-Point-of-Sale-POS-mic-1752578171314_1752578171315.txt @@ -0,0 +1,36 @@ +You are a senior full‐stack developer. Generate a multi‐tenant, cloud‐native Point-of-Sale (POS) microservice that integrates seamlessly into a GCC-focused ERP system (initial focus: Qatar). + +Functional Requirements: +- Order Management: quick-serve and table-service workflows, table mapping, split/bill transfers +- Inventory Control: real-time stock tracking, barcode/QR scanning, low-stock alerts +- Pricing & Promotions: tiered pricing, time-based discounts (e.g., happy hour), bundle offers, coupon codes +- Payments & Receipts: cash, card, mobile wallet; fiscal receipt formats compliant with Qatari regulations; email/SMS e-receipts +- Offline Mode & Sync: local cache via IndexedDB, automatic two-way data reconciliation when back online +- Multi-store & Terminal: centralized dashboard, individual terminal login with RBAC (cashier, manager) + +Non-Functional Requirements: +- Microservices architecture (Docker, Kubernetes) with API-first design (OpenAPI/Swagger) +- Domain-Driven Design and clear module boundaries +- Multi-tenant support (separate schemas per tenant or tenant_id isolation) +- High availability and horizontal scalability on AWS/Azure/GCP +- JWT authentication, encryption at rest and in transit, OWASP security best practices +- Logging & Monitoring (ELK stack, Prometheus/Grafana) + +Tech Stack: +- Front-end: React + Next.js, TypeScript, react-i18next for bilingual (RTL/LTR) UI, IndexedDB for offline +- Back-end: NestJS (TypeScript) or Django + DRF (Python), PostgreSQL with partitioned tables, Redis for caching & job queuing +- DevOps: Docker & Helm charts, Kubernetes (EKS/AKS/GKE), Terraform for IaC, GitHub Actions CI/CD +- Testing: Jest for unit tests, Cypress for e2e, Supertest for API integration tests + +Deliverables: +1. Project scaffold with folder structure, package manifests, Dockerfiles, Helm charts +2. Database schema (SQL migrations and ER diagrams for stores, terminals, products, orders, payments, promotions) +3. RESTful API endpoints with full Swagger/OpenAPI docs +4. Responsive React/Next.js UI components for desktop/tablet POS screens +5. Offline sync logic with IndexedDB caching and conflict resolution +6. Role-based RBAC middleware and JWT auth flows +7. Automated test suites with coverage reports +8. CI/CD pipeline configurations (build, test, deploy) +9. Deployment guides for cloud environments + +Ensure production-ready code, clear inline comments, and comprehensive README with setup instructions, environment variables, and architectural overview. Localize all UI text and date/number formats for Arabic/English support. \ No newline at end of file diff --git a/QatarPOS/client/index.html b/QatarPOS/client/index.html new file mode 100644 index 0000000000000000000000000000000000000000..4b4d09e3151713b7af7e8d38dd2bac2a27d5a7ee --- /dev/null +++ b/QatarPOS/client/index.html @@ -0,0 +1,13 @@ + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/QatarPOS/client/public/images/butter-chicken.svg b/QatarPOS/client/public/images/butter-chicken.svg new file mode 100644 index 0000000000000000000000000000000000000000..ac29c491a18f3712b050d16df36941365746ddf5 --- /dev/null +++ b/QatarPOS/client/public/images/butter-chicken.svg @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/QatarPOS/client/public/images/chicken-biryani.svg b/QatarPOS/client/public/images/chicken-biryani.svg new file mode 100644 index 0000000000000000000000000000000000000000..0cefae982346435e5e8e1f08ba737e07beb408e1 --- /dev/null +++ b/QatarPOS/client/public/images/chicken-biryani.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/QatarPOS/client/public/images/dal-makhani.svg b/QatarPOS/client/public/images/dal-makhani.svg new file mode 100644 index 0000000000000000000000000000000000000000..56212219b2649e399d88b01d53a2d4d18018ef50 --- /dev/null +++ b/QatarPOS/client/public/images/dal-makhani.svg @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/QatarPOS/client/public/images/garlic-naan.svg b/QatarPOS/client/public/images/garlic-naan.svg new file mode 100644 index 0000000000000000000000000000000000000000..7c58245f764416c56306511067c73162a45ee513 --- /dev/null +++ b/QatarPOS/client/public/images/garlic-naan.svg @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/QatarPOS/client/public/images/gulab-jamun.svg b/QatarPOS/client/public/images/gulab-jamun.svg new file mode 100644 index 0000000000000000000000000000000000000000..f30b632f6f1abb416b6b2215c2261a0688f8f8a1 --- /dev/null +++ b/QatarPOS/client/public/images/gulab-jamun.svg @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/QatarPOS/client/public/images/lamb-rogan-josh.svg b/QatarPOS/client/public/images/lamb-rogan-josh.svg new file mode 100644 index 0000000000000000000000000000000000000000..8705899f12f45ecded3ba23013bfacb54177459b --- /dev/null +++ b/QatarPOS/client/public/images/lamb-rogan-josh.svg @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/QatarPOS/client/public/images/mango-lassi.svg b/QatarPOS/client/public/images/mango-lassi.svg new file mode 100644 index 0000000000000000000000000000000000000000..f26bcfa189bee17617f3f4cb7ab01f52c4217b22 --- /dev/null +++ b/QatarPOS/client/public/images/mango-lassi.svg @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/QatarPOS/client/public/images/masala-tea.svg b/QatarPOS/client/public/images/masala-tea.svg new file mode 100644 index 0000000000000000000000000000000000000000..a60462b9fbe6a100e4b7112304fb50d99ff0f4f6 --- /dev/null +++ b/QatarPOS/client/public/images/masala-tea.svg @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/QatarPOS/client/public/images/pakora.svg b/QatarPOS/client/public/images/pakora.svg new file mode 100644 index 0000000000000000000000000000000000000000..a061eea01a955fc9cd4402a2df2ba0ce7ac0cd84 --- /dev/null +++ b/QatarPOS/client/public/images/pakora.svg @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/QatarPOS/client/public/images/paneer-tikka.svg b/QatarPOS/client/public/images/paneer-tikka.svg new file mode 100644 index 0000000000000000000000000000000000000000..5348073f8c5253aec030473c91b90e757a5d33ca --- /dev/null +++ b/QatarPOS/client/public/images/paneer-tikka.svg @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/QatarPOS/client/public/images/plain-naan.svg b/QatarPOS/client/public/images/plain-naan.svg new file mode 100644 index 0000000000000000000000000000000000000000..205fc27b97142b10c86397eaecad014a93ad0c5e --- /dev/null +++ b/QatarPOS/client/public/images/plain-naan.svg @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/QatarPOS/client/public/images/samosa.svg b/QatarPOS/client/public/images/samosa.svg new file mode 100644 index 0000000000000000000000000000000000000000..609312a27082da41863c7340e7a719081a140d0d --- /dev/null +++ b/QatarPOS/client/public/images/samosa.svg @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/QatarPOS/client/src/App.tsx b/QatarPOS/client/src/App.tsx new file mode 100644 index 0000000000000000000000000000000000000000..17e538222b2a68862a6bb52dec40373552699d0a --- /dev/null +++ b/QatarPOS/client/src/App.tsx @@ -0,0 +1,54 @@ +import { Switch, Route } from "wouter"; +import { queryClient } from "./lib/queryClient"; +import { QueryClientProvider } from "@tanstack/react-query"; +import { Toaster } from "@/components/ui/toaster"; +import { TooltipProvider } from "@/components/ui/tooltip"; +import { useAuth } from "@/hooks/useAuth"; +import { POSProvider } from "@/contexts/POSContext"; +import NotFound from "@/pages/not-found"; +import Landing from "@/pages/Landing"; +import POS from "@/pages/POS"; +import TableService from "@/pages/TableService"; +import Inventory from "@/pages/Inventory"; +import Reports from "@/pages/Reports"; +import { useEffect } from "react"; +import { offlineStore } from "@/lib/offlineStore"; + +function Router() { + const { isAuthenticated, isLoading } = useAuth(); + + return ( + + {isLoading || !isAuthenticated ? ( + + ) : ( + + + + + + + + )} + + + ); +} + +function App() { + useEffect(() => { + // Initialize offline store on app start + offlineStore.init().catch(console.error); + }, []); + + return ( + + + + + + + ); +} + +export default App; diff --git a/QatarPOS/client/src/components/BarcodeScanner.tsx b/QatarPOS/client/src/components/BarcodeScanner.tsx new file mode 100644 index 0000000000000000000000000000000000000000..2b5dd3aa612a4d2796c36947969d97032d500590 --- /dev/null +++ b/QatarPOS/client/src/components/BarcodeScanner.tsx @@ -0,0 +1,196 @@ +import { useState, useEffect, useRef } from "react"; +import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { useTranslation } from "@/lib/i18n"; +import { Camera, X, Type } from "lucide-react"; + +interface BarcodeScannerProps { + onScan: (barcode: string) => void; + onClose: () => void; +} + +export function BarcodeScanner({ onScan, onClose }: BarcodeScannerProps) { + const { t, direction } = useTranslation(); + const [manualEntry, setManualEntry] = useState(""); + const [isManualMode, setIsManualMode] = useState(false); + const [hasCamera, setHasCamera] = useState(true); + const videoRef = useRef(null); + const streamRef = useRef(null); + + useEffect(() => { + if (!isManualMode) { + startCamera(); + } + + return () => { + stopCamera(); + }; + }, [isManualMode]); + + const startCamera = async () => { + try { + const stream = await navigator.mediaDevices.getUserMedia({ + video: { + facingMode: 'environment', + width: { ideal: 1280 }, + height: { ideal: 720 } + } + }); + + streamRef.current = stream; + if (videoRef.current) { + videoRef.current.srcObject = stream; + } + } catch (error) { + console.error('Error accessing camera:', error); + setHasCamera(false); + setIsManualMode(true); + } + }; + + const stopCamera = () => { + if (streamRef.current) { + streamRef.current.getTracks().forEach(track => track.stop()); + streamRef.current = null; + } + }; + + const handleManualSubmit = () => { + if (manualEntry.trim()) { + onScan(manualEntry.trim()); + } + }; + + const handleKeyPress = (e: React.KeyboardEvent) => { + if (e.key === 'Enter') { + handleManualSubmit(); + } + }; + + // Simulate barcode detection (in a real app, you'd use a barcode scanning library) + const simulateBarcodeDetection = () => { + // This is a placeholder for actual barcode scanning + // In production, you would integrate with a library like @zxing/browser + const mockBarcode = "1234567890123"; + onScan(mockBarcode); + }; + + return ( + + + + + {direction === 'rtl' ? 'مسح الباركود' : 'Barcode Scanner'} + + + + +
+ {/* Camera/Manual Toggle */} +
+ + +
+ + {/* Camera View */} + {!isManualMode && hasCamera && ( +
+
+ )} + + {/* Manual Entry */} + {(isManualMode || !hasCamera) && ( +
+
+ + setManualEntry(e.target.value)} + onKeyPress={handleKeyPress} + placeholder={direction === 'rtl' ? 'مثال: 1234567890123' : 'e.g., 1234567890123'} + className="font-mono" + autoFocus + /> +
+ +
+ )} + + {/* Instructions */} +
+ {!isManualMode && hasCamera ? ( +

+ {direction === 'rtl' + ? 'وجه الكاميرا نحو الباركود للمسح التلقائي' + : 'Point camera at barcode for automatic scanning' + } +

+ ) : ( +

+ {direction === 'rtl' + ? 'أدخل رمز الباركود يدوياً أو استخدم قارئ الباركود' + : 'Enter barcode manually or use barcode scanner' + } +

+ )} +
+ + {!hasCamera && ( +
+ {direction === 'rtl' + ? 'لا يمكن الوصول للكاميرا. يرجى استخدام الإدخال اليدوي.' + : 'Camera not available. Please use manual entry.' + } +
+ )} +
+
+
+ ); +} diff --git a/QatarPOS/client/src/components/OrderSummary.tsx b/QatarPOS/client/src/components/OrderSummary.tsx new file mode 100644 index 0000000000000000000000000000000000000000..b9b8112c1112262b93e2c0a8c0c35864f93f77c4 --- /dev/null +++ b/QatarPOS/client/src/components/OrderSummary.tsx @@ -0,0 +1,374 @@ +import { useState } from "react"; +import { Button } from "@/components/ui/button"; +import { Badge } from "@/components/ui/badge"; +import { Input } from "@/components/ui/input"; +import { Textarea } from "@/components/ui/textarea"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; +import { ReceiptModal } from "@/components/ReceiptModal"; +import { usePOS } from "@/contexts/POSContext"; +import { useTranslation } from "@/lib/i18n"; +import { useToast } from "@/hooks/use-toast"; +import { + Trash2, + Edit, + Minus, + Plus, + CreditCard, + Banknote, + Smartphone, + Scissors, + Check, + Pause, + User +} from "lucide-react"; + +export function OrderSummary() { + const { state, actions } = usePOS(); + const { t, direction, formatCurrency } = useTranslation(); + const { toast } = useToast(); + const [showReceipt, setShowReceipt] = useState(false); + const [customerInfo, setCustomerInfo] = useState({ + name: "", + phone: "", + email: "" + }); + const [orderNotes, setOrderNotes] = useState(""); + const [paymentMethod, setPaymentMethod] = useState("cash"); + + const { currentOrder } = state; + + const handleQuantityChange = (itemId: string, newQuantity: number) => { + if (newQuantity <= 0) { + actions.removeFromCart(itemId); + } else { + actions.updateCartItem(itemId, newQuantity); + } + }; + + const handleOrderTypeChange = (type: 'dine_in' | 'takeaway' | 'delivery') => { + actions.setOrderType(type); + }; + + const handleCustomerInfoChange = (field: string, value: string) => { + const updated = { ...customerInfo, [field]: value }; + setCustomerInfo(updated); + actions.setCustomerInfo(updated); + }; + + const handleNotesChange = (notes: string) => { + setOrderNotes(notes); + actions.setOrderNotes(notes); + }; + + const handleCompleteOrder = async () => { + if (!currentOrder || currentOrder.items.length === 0) { + toast({ + title: t('message.error'), + description: direction === 'rtl' ? 'لا توجد عناصر في الطلب' : 'No items in order', + variant: "destructive", + }); + return; + } + + try { + await actions.completeOrder(); + setShowReceipt(true); + // Reset form + setCustomerInfo({ name: "", phone: "", email: "" }); + setOrderNotes(""); + setPaymentMethod("cash"); + } catch (error) { + console.error('Error completing order:', error); + } + }; + + const handleHoldOrder = async () => { + if (!currentOrder || currentOrder.items.length === 0) { + toast({ + title: t('message.error'), + description: direction === 'rtl' ? 'لا توجد عناصر في الطلب' : 'No items in order', + variant: "destructive", + }); + return; + } + + await actions.holdOrder(); + // Reset form + setCustomerInfo({ name: "", phone: "", email: "" }); + setOrderNotes(""); + }; + + const getOrderTypeLabel = (type: string) => { + switch (type) { + case 'dine_in': + return direction === 'rtl' ? 'تناول في المكان' : 'Dine In'; + case 'takeaway': + return direction === 'rtl' ? 'طلبات خارجية' : 'Takeaway'; + case 'delivery': + return direction === 'rtl' ? 'توصيل' : 'Delivery'; + default: + return direction === 'rtl' ? 'تناول في المكان' : 'Dine In'; + } + }; + + if (!currentOrder) { + return ( +
+
+
+ {direction === 'rtl' ? 'لا يوجد طلب نشط' : 'No active order'} +
+

+ {direction === 'rtl' + ? 'أضف منتجات لبدء طلب جديد' + : 'Add products to start a new order' + } +

+
+
+ ); + } + + return ( +
+ {/* Order Header */} +
+
+

+ {t('order.current_order')} +

+ +
+ +
+
+ + + {state.selectedTable ? `${t('order.table')} ${state.selectedTable.name}` : getOrderTypeLabel(currentOrder.type)} + +
+ +
+
+ + {/* Order Type Selection */} +
+ +
+ + {/* Order Items */} +
+ {currentOrder.items.length > 0 ? ( +
+ {currentOrder.items.map((item) => ( +
+
+

+ {direction === 'rtl' && item.nameAr ? item.nameAr : item.name} +

+

+ {formatCurrency(parseFloat(item.price))} +

+ {item.notes && ( +

{item.notes}

+ )} +
+
+ + {item.quantity} + +
+
+ ))} +
+ ) : ( +
+ {direction === 'rtl' ? 'لا توجد عناصر في الطلب' : 'No items in order'} +
+ )} + + {/* Promotions */} + {parseFloat(currentOrder.discountAmount) > 0 && ( +
+
+ + {t('promo.discount_applied')} + + + -{formatCurrency(parseFloat(currentOrder.discountAmount))} + +
+
+ )} + + {/* Customer Information */} +
+

+ {direction === 'rtl' ? 'معلومات العميل' : 'Customer Information'} +

+ handleCustomerInfoChange('name', e.target.value)} + /> + handleCustomerInfoChange('phone', e.target.value)} + /> + handleCustomerInfoChange('email', e.target.value)} + /> +