Class: Order

Order()

Represents an order in the system, encapsulating all necessary details and logic to manage items, discounts, and bill calculations. This class provides methods to add, cancel, or modify items in the order, as well as track the status and customer-related information. The class supports the following functionalities: - Add items to the order. - Add extra items to the order. - Cancel items from the order. - Confirm requested items to be added to the order. - Cancel the entire order and reset all related items and status. - Set and apply a discount to the total bill. - Recalculate the bill amount when items or discounts are modified. The order maintains various properties to manage the order's state, including the unique order ID, bill number, status, discount, customer details, and timestamps for creation and updates.

Constructor

new Order()

Creates an order instance.
Source:

Methods

addExtra(items)

Adds extra items to the order and updates the bill amount.
Parameters:
Name Type Description
items Array List of extra items to add.
Source:

addItems(item) → {void}

Adds a new item to the list of items and recalculates the bill amount. This function pushes the provided item to the `items` array and invokes the `calculateBillAmount()` method to ensure the total bill amount is updated whenever a new item is added. It assumes the `items` array is an existing array holding the list of items and `calculateBillAmount()` is a method that performs the necessary calculation based on the current items.
Parameters:
Name Type Description
item Object The item to be added to the bill. This should be an object representing the item, such as an item with properties like `name`, `price`, etc.
Source:
Returns:
Type
void

calculateBillAmount()

Calculates the total bill amount based on items and discount.
Source:

cancelItem(item)

Cancels an item from the order and moves it to the canceled items list.
Parameters:
Name Type Description
item Objects Item to be canceled.
Source:

cancelOrder()

Cancels the order by updating its status.
Source:

confirmRequestedItems()

conforms the requested items and adds them to the main order items.
Source:

setDiscount(amount)

Sets a discounts for the order and calculates the bill amount.
Parameters:
Name Type Description
amount number Discount amount to apply.
Source: