diff --git a/client/src/App.jsx b/client/src/App.jsx
index b82b9c7..68191ec 100644
--- a/client/src/App.jsx
+++ b/client/src/App.jsx
@@ -9,6 +9,7 @@ import Customers from './pages/Customers';
import Orders from './pages/Orders';
import OrderNew from './pages/OrderNew';
import OrderDetail from './pages/OrderDetail';
+import Restock from './pages/Restock';
function AuthGate({ children }) {
const [state, setState] = useState({ checked: false, authenticated: false });
@@ -51,6 +52,7 @@ export default function App() {
Loading...
; + + return ( + <> +{error}
} + {success &&{success}
} + + {products.length === 0 ? ( +No products in inventory.
+ ) : ( + + )} + > + ); +} diff --git a/server/routes/orders.js b/server/routes/orders.js index bcbfad3..8ef1e41 100644 --- a/server/routes/orders.js +++ b/server/routes/orders.js @@ -72,7 +72,7 @@ router.get('/:id', (req, res) => { router.post('/', (req, res) => { try { const db = getDb(); - const { customer_id, status = 'pending', notes, items = [] } = req.body; + const { customer_id, walk_in_name, status = 'pending', notes, items = [] } = req.body; if (!Array.isArray(items) || items.length === 0) { return res.status(400).json({ error: 'At least one order item is required' }); } @@ -84,9 +84,14 @@ router.post('/', (req, res) => { } const createOrder = db.transaction(() => { + let resolvedCustomerId = customer_id || null; + if (!resolvedCustomerId && typeof walk_in_name === 'string' && walk_in_name.trim()) { + const custResult = db.prepare('INSERT INTO customers (name) VALUES (?)').run(walk_in_name.trim()); + resolvedCustomerId = custResult.lastInsertRowid; + } const result = db.prepare( 'INSERT INTO orders (customer_id, status, notes) VALUES (?, ?, ?)' - ).run(customer_id || null, status, notes || null); + ).run(resolvedCustomerId, status, notes || null); const orderId = result.lastInsertRowid; for (const it of items) {