Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

Commit

Permalink
Send One backend request
Browse files Browse the repository at this point in the history
  • Loading branch information
DCRepublic committed Apr 2, 2024
1 parent cd9a2fd commit c1b4568
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 79 deletions.
37 changes: 27 additions & 10 deletions src/app/(header)/kitchen_display/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export default function Home() {
<Button fullWidth onClick={() => updateOrder(item)}>
Change Status
</Button>
<Button fullWidth onClick={() => completeOrder(item)}>
<Button fullWidth onClick={() => REPRINT(item)}>
<Print></Print>
</Button>
</ButtonGroup>
Expand Down Expand Up @@ -277,21 +277,39 @@ export default function Home() {
const drinkies = Object.assign({}, theitem);
foodies['dishes'] = theitem.dishes.filter((item: any) => item.tag == 'food');
drinkies['dishes'] = theitem.dishes.filter((item: any) => item.tag == 'drink');
if (foodies.dishes.length > 0) {
PRINT2(foodies);
}
if (drinkies.dishes.length > 0) {
PRINT2(drinkies);
}
//RePrintOrder(theitem);

theitem['status'] = 'completed';
theitem['hidden'] = 'true';
//theitem['hidden'] = 'true';

await axios.put(url, theitem).then((response) => {
console.log(response);
});
};

const REPRINT = async (item: any) => {
const order = Object.assign({}, item);

const toPrintServer = {
customerName: order.customerName,
total: order.total,
hidden: false,
notes: '',
payment: 'none',
receipt: true,
dishes: order.dishes,
};

//Send order to print server/tablet
await axios.post('/api/print', toPrintServer).then((response) => {
if (response.status == 200) {
console.log(response);
} else {
console.log(response);
}
});
};

const deleteOrder = async (item: any) => {
//PRINT2(item);

Expand All @@ -313,8 +331,7 @@ export default function Home() {
await axios.put(url, theitem).then((response) => {
console.log(response);
});
}
if (theitem.status == 'in_progress') {
} else if (theitem.status == 'in_progress') {
theitem.status = 'completed';
await axios.put(url, theitem).then((response) => {
console.log(response);
Expand Down
107 changes: 38 additions & 69 deletions src/app/(header)/point_of_sale/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function App() {
const [open, setOpen] = React.useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => {
setOpen(false), setoneopen(false);
setOpen(false);
};
const [Success, setSuccess] = React.useState(false);
const handleSuccess = () => setSuccess(false);
Expand Down Expand Up @@ -325,7 +325,6 @@ export default function App() {

const confirmOrder = async (name: string, paymentType: string) => {
//handleClose();
//Current order should just be a mirror of the dishes array You will attach below each order is simply a dish object.

const thing1 = {
customerName: name,
Expand All @@ -348,27 +347,6 @@ export default function App() {

//break food and drinks into seperate lists so that they can each be on their own recipts.

const foodies = {
customerName: name,
total: runningTotal,
hidden: false,
notes: '',
oc: oneCard,
payment: paymentType,
receipt: true,
dishes: currentOrder.filter((item: any) => item.tag == 'food'),
};
const drinkies = {
customerName: name,
total: runningTotal,
hidden: false,
notes: '',
oc: oneCard,
payment: paymentType,
receipt: true,
dishes: currentOrder.filter((item: any) => item.tag == 'drink'),
};

//PRINT2(foodies);

/*
Expand All @@ -381,8 +359,6 @@ export default function App() {
pay 183, 1169
*/

//console.log(thing1);

//Send order to db
await axios.post('/api/orders', thing1).then((response) => {
if (response.status == 200) {
Expand All @@ -393,35 +369,23 @@ export default function App() {
}
});

//Check if there is still more to pay
if (currentOrder.total - 7 > 0 && paymentType == 'swipe') {
setPayMore(true);
} else {
handleClose();
setSuccess(true);
setTimeout(handleSuccess, 3000);
setCurrentOrder([]);
setName('');
setRunningTotal(0);
setOneCard('');
setOptions(false);
}
//Check if there is still more to pay open up that window

//Send order to print server/tablet
await axios.post('/api/print', foodies).then((response) => {
await axios.post('/api/print', toPrintServer).then((response) => {
if (response.status == 200) {
setSuccess(true);
setTimeout(handleSuccess, 3000);
} else {
setFailure(true);
setTimeout(handleFailure, 3000);
}
});

await axios.post('/api/print', drinkies).then((response) => {
if (response.status == 200) {
setSuccess(true);
setTimeout(handleSuccess, 3000);
if (currentOrder.total - 7 > 0 && paymentType == 'swipe') {
setPayMore(true);
} else {
handleClose();
setSuccess(true);
setTimeout(handleSuccess, 3000);
setCurrentOrder([]);
setName('');
setRunningTotal(0);
setOneCard('');
setOptions(false);
}
} else {
setFailure(true);
setTimeout(handleFailure, 3000);
Expand All @@ -443,7 +407,7 @@ export default function App() {

await axios.post('/api/print', toPrintServer2).then((response) => {
if (response.status == 200) {
handleClose();
setPayMore(false);
setSuccess(true);
setTimeout(handleSuccess, 3000);
setCurrentOrder([]);
Expand All @@ -459,10 +423,9 @@ export default function App() {
};
/*
RenderOptions
When a {dish} is added or selected from list a new set of options will appear.
These options replace the menu items and give the user the oppourtunity to make additions
or add and subtract the number of items being added.
When a {dish} is added or selected from list a new set of options will appear.
These options replace the menu items and give the user the oppourtunity to make additions
or add and subtract the number of items being added.
*/
const RenderOptions = () => {
//console.log(currentDish);
Expand Down Expand Up @@ -525,7 +488,9 @@ export default function App() {
const item = data.dishes.filter((item: any) => item.friendlyName == props.friendlyName);

for (const option of item) {
const temp: any = option.options;
const temp: any = option.options.sort((a: any, b: any) =>
a.friendlyName.localeCompare(b.friendlyName),
);

for (const subOption of temp) {
const multi = subOption.allowQuantity;
Expand Down Expand Up @@ -895,12 +860,14 @@ export default function App() {
</Grid>
);
} else {
const drinks = data.dishes.filter(
(drink: any) =>
drink.dotw.includes(moment().format('dddd').toString()) &&
drink.isOrderable == true &&
drink.tags.includes('drink'),
);
const drinks = data.dishes
.filter(
(drink: any) =>
drink.dotw.includes(moment().format('dddd').toString()) &&
drink.isOrderable == true &&
drink.tags.includes('drink'),
)
.sort((a: any, b: any) => a.friendlyName.localeCompare(b.friendlyName));

return drinks.map((item: any) => (
<>
Expand Down Expand Up @@ -972,12 +939,14 @@ export default function App() {
</Grid>
);
} else {
const food = data.dishes.filter(
(dish: any) =>
dish.isOrderable == true &&
dish.tags.includes('food') &&
dish.dotw.includes(moment().format('dddd').toString()),
);
const food = data.dishes
.filter(
(dish: any) =>
dish.isOrderable == true &&
dish.tags.includes('food') &&
dish.dotw.includes(moment().format('dddd').toString()),
)
.sort((a: any, b: any) => a.friendlyName.localeCompare(b.friendlyName));
//(food);

return food.map((item: any) => (
Expand Down

0 comments on commit c1b4568

Please sign in to comment.