I need help to design DB/table for Restaurant Ordering System.
1) Captain will take order on Android device and after Placing an order from Customer, he (captain) will Print Order.
2) Captain can alter/add order based on Customer's demand
3) Finally based on customer's demand captain will finalised bill and Print the bill
Some Cases for Placing Order
1) Place Order and not cancelled and finalised bill
2) Place Order - say 4 Burgers , after finish, again customer Place order - say 3 Burgers, not cancelled, and finalised bill
3) Place Order - say 4 Burgers , after finish , again Place order - say 3 Burgers, and Customer asks to Cancel 1 Burger, then finalised bill
4) Place Order - say 4 Burgers, then, Cancel 2 Burger, then after sometime, Place Order 4 Burgers then finalised bill
5) Place Order - 4 Burgers, after sometime, Cancel 2 Burgers, after sometime, Place Order 4 Burgers, after sometime Cancel 2 and then finalised bill
i have already created , menu_card (i.e item), table_info
Billing Table :
id
table_no
bill_no
item_name
quantity
repeat_quantity
print_status (Printed/Not Printed)
ongoing (Yes/No(if no -then finished) )
date_time
Which field should i add in case 3,4,5 for Placing an order
I am confused what if Customer ask for "Cancel Order" , after finish current Order, he asks for same Item.
New EDIT :
I am showing the List of Ordered Items, where captain can touch to update the order,
I m thinking to add cancelled_items_quantity in table and for every new order i will make new entry to database to add those order,
E.g. Customer has ordered 4 Burgers, then it will add to the DB, now after finishing it off, if he asks for 3 burgers, again new entry will be made rather to modify existing 4 to 7, and even if he cancels the order, suppose 2 from 3 Burgers, then update will be made on same entry i.e. it will update cancelled_items_quantity to 2 from default 0
Pls Help
I'd start with making a separate table for items, orders and bills. Since one bill can contain multiple orders and an order multiple items.
As for your example cases, only write finalised data to the database. Keep non-finalised orders in memory on the app. Once the user clicks 'Ok' or 'Finish' the order is finalised and you can write it to the DB.
If you would change the order every time in the database, you'd do way too much transactions which isn't good.
You probably will want separate tables.
1) billing_info
2) table_info
3) item_info
Then correlate to each other as your requirements. Add a 'status' field or similar in item_info so you can easily update its value whenever user request changes.
EDIT
How about for item_info table, for each individual item that customer has ordered, create an entry. Then any changes, update the status.
I visualize on the android tablet, i can see a whole list of every items that customer has ordered.
Eg.
1 steak
1 ice tea
1 steak
1 coffee
1 coffee
So for each item there can be 2 options.
1) to remove the entry before confirmation
2) to change the status after confirmation
Before confirmation, changes are just on the UI only. So we can use option1 to update the UI. I supposed the complications come after confirmation and customer wants to change the order. So we use option2.
2 steak ordered. Now customer wants to cancel 1. So waiter just change the status of 1 steak to 'cancel'.
Related
QUESTION: Im making a flashcard app and when the user clicks "easy" for example, I want to increase the time of the card, then that card won't appear until the time goes reaches 0.
e.g. "Card 1" has a time of 0 at default , user clicks "I know button" and the time on that card increases to 5 mins (5:00), then that card wont appear again for 5 minutes until timer is back to 0, is this possible to do?
is this possible to do?
I believe that if you consider what SQLite is capable of and what an Android App is capable of then Yes. However using SQLite alone then No.
Typically, to get your outcome, the time would remain constant in the database but you would extract and thus show only the rows that met the criteria e.g. the time stored is less than or equal to the current time.
Clicking I know would then update the respective row and set the value to the current time plus 5 minutes, thus an extract, which could be timer based would then not show the respective row as it's then greater than the current time.
As for the timer SQLite does not have a built in timer. It is a database manager whose job is to store and retrieve structured data.
As an example consider the following, which shows the principle:-
DROP TABLE IF EXISTS flashcard;
CREATE TABLE IF NOT EXISTS flashcard (cardtitle TEXT, cardtimer INTEGER);
INSERT INTO flashcard VALUES ('Card1',strftime('%s','now')),('Card2',strftime('%s','now','+1 minute')),
('Card3',strftime('%s','now','+2 minute'));
SELECT *,strftime('%s','now') FROM flashcard WHERE cardtimer <= strftime('%s','now');
UPDATE flashcard SET cardtimer = strftime('%s','now','+5 minutes') WHERE cardtitle = 'Card1';
SELECT *,strftime('%s','now') FROM flashcard WHERE cardtimer <= strftime('%s','now');
This:-
drops and creates a table with 2 columns,
a column named cardtitle that stores the title of the card
a column named cardtimer for the time when the card can be displayed on or after
adds 3 rows with unique titles the time fors the first being the current time, the time for the second 1 minute later,and for the third another minute later.
An extract (SELECT query) that displays only the rows where the timer is now or earlier (irrespective of when it is run).
this shows just the first of the 3 rows as the others are in the future
An Update that changes the time of the first row to be 5 minutes from now
Another Extract using the same query as per 3
this shows nothing because now all 3 rows are in the future
Running the above results in :-
i.e. just Card1 is extracted
Then :-
i.e. all of the cards are now in the future.
However if the same extract is then run a while later (but sooner then 5 minutes later), as can be seen some 139 seconds later, then :-
If then after 5 minutes and the same extract is run then :-
Inside a list, I have an item : shop.
Shop have the same id, but different group_id.
The primary key is shop_id, group_id
The first time I display the list, I want to group those 2 ( As it is the same shop)
In the next screen.
So, my query is :
SELECT * FROM TABLE_SHOP GROUP BY ID
But then, When I process it, I need to separate the shops with field "done" = 0/1
if done = 1, I will disable the element.
I tried to add a clause :
SELECT * FROM TABLE_SHOP GROUP BY ID HAVING DONE =0
But then, when one is done, the shop doesn't appear anymore in the list. ( instead of showing one disabled, and one enabled)
Any idea of what is failing in the list?
EDIT :
I changed fields name to match picture.
In this case, I want to display the list.
The first time I display it ( all done fields in 0), I want the shop 25975 ( 2 records ) appears just once ( that's why I used GROUP BY)
Then, when I process a shop, it will update his done field to 1.
So in this moment, I don't wan't to group anymore the 2 rows. It it clearer???
The purpose of HAVING clause is to filter using aggregate functions.
Try this instead:
SELECT * FROM TABLE_TIENDA WHERE TIENDA_DONE = 0 GROUP BY TIENDA_ID
I got it working.
The query was :
SELECT * FROM TABLE_TIENDA WHERE TIENDA_DONE = 0 GROUP BY TIENDA_ID, DONE
Tx for your help
I have two tables: Place and Discount with an N<->N relation. I also have another table called place_discount which has two foreign keys (idPlace and idDiscount).
When I add a discount to a place, e.g. discount for a bar, I add it in place_discount table.
So my issue is: I have an android app which queries on that database. when I want to list all the places that I have loaded, I want to show a star on those who have a discount. To list that I do a select * from place. Is there a way to do that query?
Tip: I can not use triggers because I do not have super privileges.
Why not use a join?
SELECT
Place.*,
IF(IFNULL(MIN(place_discount.idDiscount),0)>0,1,0) AS hasDiscount
FROM place
LEFT JOIN place_discount ON Place.id=place_discount.idPlace
GROUP BY Place.id
will give you a 1 in hasDiscount if a discount is available, a 0 if not.
On a side note: You do not need super privilege for a trigger on a table you own.
What I have
I'm working on an Android app with a menu of school canteens. I download data from a remote website and save them to the internal SQLite database to such table (SO Markdown doesn't support tables, hence I'll make it a list):
ID
TEXT - The name of the meal
NUMBER - The number of the meal (we can choose from more)
ORDERED - Boolean, whether the particular meal is ordered or not
DATE - The date (timestamp) when the meal is server
(and a few more unimportant columns)
What I need
I want to provide the user with a list, where for every day when the canteen cooks there is either the meal he has ordered or information, that he hasn't ordered anything for that day.
The question is, how should look my query when I need to get:
Every date that is in the table (once).
For each date either the info about the ordered meal, or (if there isn't any ordered meal) something from which I can tell that the user will be hungry that day.
Because I want my users to be able to see also the meals they didn't order (so that their friends can look, what they might have), I refuse to keep only the ordered meals.
Thanks in advance for any help.
SELECT *, MAX(Ordered) FROM MyTable GROUP BY "Date"
The GROUP BY "Date" ensures that you get one result per day; the MAX(Ordered) ensures that that result is one that is ordered, if possible.
I have a a database with more than 6000 entries. I am using this example http://eshyu.wordpress.com/2010/08/15/cursoradapter-with-alphabet-indexed-section-headers/ to display the contents. But now the activity isn't able to handle it. I get a ANR dialog every time. How do I efficiently handle this circumstance?
It doesn't make sense to go through each entry and ask the indexer on wich section that entry belongs to. In your case, the Indexer might be doing 6000 binary searches. Then puting that result in a map that will have below 30 entries and doing many overwrites.
It's also not a good idea to abuse the sectionToPosition Map to create a section starting postion.
A. You either prepare a table containing the stats, which would be the best way to handle so much data.
B. You can use the database to count number of entries for each section and build your own section starting pos map.
SELECT UPPER(SUBSTR(LTRIM(side_a), 1, 1)), COUNT(*) FROM cards GROUP BY 1 ORDER BY 1 ASC;