Structure of orders in restaurant

2019-08-30 09:28发布

What would be the best way to structure orders for a restaurant (available languages are php and javascript)? Since there are multiple tables (the ones you keep things on...), I thought of using objects in javascript. But I am quite new to javascript and absolutely new to OOP, so I'm not sure whether this is the best solution, and whether my design is actually ok. Here is what I have come up with:

var order = {
    id: 0,
    table: 0,
    number_of_items: 0,
    item: {
        name: "",
        quantity: 0,
        unit_price: 0
    },
    total: 0
};

9条回答
贪生不怕死
2楼-- · 2019-08-30 09:45

I think you can do away with some redundant elements in your structure:

var order = {
    id: 445221,
    table: 42,
    items: [
        {
            name: "Steak",
            quantity: 1,
            unit_price: 15
        },
        {
            name: "Beer",
            quantity: 1,
            unit_price: 3
        }
    ]
};
查看更多
3楼-- · 2019-08-30 09:45

How about this?

 order = {
     id: <unique identifier>,
     table: <table number>,
     items : <array of objects as declared below> 
 }

 item = {
    item_id: <id of the item in the menu>
    instructions : <text>
 }

Notes:

  • number of items = length of items array.
  • unit price belongs to menu object.
  • total can be calculated any time.
  • Don't forget the instructions (cooking, serving)!
查看更多
Emotional °昔
4楼-- · 2019-08-30 09:47

There are multiple tables, and each table can -over the course of a service- have several orders.

I would think the basic component/object of your system would be the cover itself, consisting of something along the lines of:

order_id, the table, the course (there'll be a minimum of one course), the chosen dish and its cost, the time of ordering (this may not seem important, but it usually is to a -good- maitre d'hotel or service manager) and the drinks.

查看更多
做个烂人
5楼-- · 2019-08-30 09:49

Here is one way.

function item(name, price)
{
    this.name = name;
    this.price = price;
}

function order(id, table)
{
    this.id = id;
    this.table = table;
    this.items = [];
}

order.prototype.countItems = function()
{
    return this.items.length;
}

order.prototype.getTotal = function()
{
    var total = 0.0;
    for(var i = 0;i < this.items.length; i++)
    {
        total += this.items[i].price;
    }
    return total;
}

var myorder = new order(1234, 12);

myorder.items.push(new item("coke", 1.25));
查看更多
聊天终结者
6楼-- · 2019-08-30 09:52

Well, orders should be independent of tables. Really you'd have a table object that consisted of seat/ customer objects and an order object that consisted of one or more items (with items having name, quantity, price or whatever else belongs to an item).

As an additional complication, an order could either belong to a seat (one person) or a table (e.g., shared appetizer). Supporting that relationship would allow you to do different things when trying to compile the bill for the table (like if you had to provide split checks).

查看更多
我只想做你的唯一
7楼-- · 2019-08-30 09:52

In addition to the other answers, what about special preparation directions? Do you want separate Burger items (Burger-medium rare, Burger-well done), or do you want a separate table with the cooking directions linked to that item?

Your answer really depends on your audience. Is it for the screen in the kitchen, for the waitress entering the order, the cashier, the health inspector, or all of the above?

查看更多
登录 后发表回答