Sale Save
This commit is contained in:
@@ -193,7 +193,7 @@ class Order < ApplicationRecord
|
||||
# Count number of different items
|
||||
self.item_count = self.order_items.item_count
|
||||
self.quantity_count = quantity_count
|
||||
# Counter number of quantity
|
||||
# Counter number of quantityf
|
||||
end
|
||||
|
||||
#Process order items and send to order queue
|
||||
@@ -203,38 +203,48 @@ class Order < ApplicationRecord
|
||||
end
|
||||
|
||||
#Origami: Cashier : to view order type Table
|
||||
def self.get_order_table
|
||||
order_table = Order.select("orders.id as order_id,sum(order_items.qty*order_items.price) as total_price,
|
||||
order_items.id as order_items_id,dining_facilities.name as table_name")
|
||||
.joins("left join booking_orders on booking_orders.order_id = orders.id
|
||||
left join bookings on bookings.id = booking_orders.id
|
||||
left join dining_facilities on dining_facilities.id = bookings.dining_facility_id
|
||||
left join order_items on order_items.order_id = orders.id")
|
||||
.where("dining_facilities.type=? and orders.order_type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,"dine_in",true)
|
||||
.group("orders.id")
|
||||
def self.get_booking_order_table
|
||||
booking_orders = Booking.select("sales.receipt_no,orders.status as order_status,bookings.id,sales.id as sale_id,dining_facilities.name as table_name")
|
||||
.joins("left join booking_orders on booking_orders.booking_id = bookings.id")
|
||||
.joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id")
|
||||
.joins("left join orders on orders.id = booking_orders.order_id")
|
||||
.joins("left join sale_orders on sale_orders.order_id = orders.id")
|
||||
.joins("left join sales on sales.id = sale_orders.sale_id")
|
||||
.where("booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,true)
|
||||
.group("bookings.id")
|
||||
end
|
||||
#Origami: Cashier : to view order type Room
|
||||
def self.get_order_rooms
|
||||
order_rooms = Order.select("orders.id as order_id,sum(order_items.qty*order_items.price) as total_price,
|
||||
order_items.id as order_items_id,dining_facilities.name as room_name")
|
||||
.joins("left join booking_orders on booking_orders.order_id = orders.id
|
||||
left join bookings on bookings.id = booking_orders.id
|
||||
left join dining_facilities on dining_facilities.id = bookings.dining_facility_id
|
||||
left join order_items on order_items.order_id = orders.id")
|
||||
.where("dining_facilities.type=? and orders.order_type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,"dine_in",true)
|
||||
.group("orders.id")
|
||||
def self.get_booking_order_rooms
|
||||
booking_rooms = Booking.select("sales.receipt_no,orders.status as order_status,bookings.id,sales.id as sale_id,dining_facilities.name as room_name")
|
||||
.joins("left join booking_orders on booking_orders.booking_id = bookings.id")
|
||||
.joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id")
|
||||
.joins("left join orders on orders.id = booking_orders.order_id")
|
||||
.joins("left join sale_orders on sale_orders.order_id = orders.id")
|
||||
.joins("left join sales on sales.id = sale_orders.sale_id")
|
||||
.where("booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,true)
|
||||
.group("bookings.id")
|
||||
end
|
||||
#Origami: Cashier : to view orders
|
||||
def self.get_orders
|
||||
from = Time.now.beginning_of_day.utc
|
||||
to = Time.now.end_of_day.utc
|
||||
orders = Order.select("orders.id as order_id,sum(order_items.qty*order_items.price) as total_price,
|
||||
order_items.id as order_items_id,dining_facilities.name as table_or_room_name")
|
||||
orders = Order.select("orders.id as order_id,sales.receipt_no,orders.status as order_status,bookings.id,sales.id as sale_id,dining_facilities.name as table_name")
|
||||
.joins("left join booking_orders on booking_orders.order_id = orders.id
|
||||
left join bookings on bookings.id = booking_orders.id
|
||||
left join dining_facilities on dining_facilities.id = bookings.dining_facility_id
|
||||
left join order_items on order_items.order_id = orders.id")
|
||||
left join order_items on order_items.order_id = orders.id
|
||||
left join sale_orders on sale_orders.order_id = orders.id
|
||||
left join sales on sales.id = sale_orders.sale_id")
|
||||
.where("dining_facilities.is_active=? and orders.date between ? and ?",true,from,to)
|
||||
.group("orders.id")
|
||||
|
||||
# Booking.select("sales.receipt_no,orders.status as order_status,bookings.id,sales.id as sale_id,dining_facilities.name as table_name")
|
||||
# .joins("left join booking_orders on booking_orders.booking_id = bookings.id")
|
||||
# .joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id")
|
||||
# .joins("left join orders on orders.id = booking_orders.order_id")
|
||||
# .joins("left join sale_orders on sale_orders.order_id = orders.id")
|
||||
# .joins("left join sales on sales.id = sale_orders.sale_id")
|
||||
# .where("booking_orders.order_id IS NOT NULL and dining_facilities.is_active=? and orders.date between ? and ?",true,from,to)
|
||||
# .group("orders.id")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,9 +34,17 @@ class OrderItem < ApplicationRecord
|
||||
|
||||
end
|
||||
#Origami : Cashier : to show order items details
|
||||
def self.get_order_items_details(order_id)
|
||||
order_details = OrderItem.select("order_items.item_name,order_items.qty,order_items.price,(order_items.qty*order_items.price) as total_price")
|
||||
.joins("left join orders on orders.id = order_items.order_id")
|
||||
.where("order_items.order_id=?",order_id)
|
||||
def self.get_order_items_details(booking_id)
|
||||
booking_orders = BookingOrder.where("booking_id=?",booking_id)
|
||||
if booking_orders
|
||||
booking_orders.each do |book_order|
|
||||
order_details = OrderItem.select("order_items.item_name,order_items.qty,order_items.price,(order_items.qty*order_items.price) as total_price")
|
||||
.joins("left join orders on orders.id = order_items.order_id")
|
||||
.where("order_items.order_id=?",book_order.order_id)
|
||||
return order_details
|
||||
end
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,9 +20,9 @@ class Sale < ApplicationRecord
|
||||
#get all order attached to this booking and combine into 1 invoice
|
||||
booking.booking_orders.each do |order|
|
||||
if booking.sale_id
|
||||
status, sale_id = generate_invoice_from_order(order.order_id, nil, requested_by)
|
||||
status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by)
|
||||
else
|
||||
status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, requested_by)
|
||||
status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, booking, requested_by)
|
||||
end
|
||||
booking.sale_id = sale_id
|
||||
end
|
||||
@@ -31,7 +31,7 @@ class Sale < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def generate_invoice_from_order (order_id, sale_id, requested_by)
|
||||
def generate_invoice_from_order (order_id, sale_id, booking, requested_by)
|
||||
taxable = true
|
||||
#if sale_id is exsit and validate
|
||||
#add order to that invoice
|
||||
@@ -62,8 +62,8 @@ class Sale < ApplicationRecord
|
||||
add_item(item)
|
||||
end
|
||||
|
||||
link_order_sale(order.id)
|
||||
|
||||
link_order_sale(order.id)
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -73,6 +73,11 @@ class Sale < ApplicationRecord
|
||||
|
||||
#Update the order items that is billed
|
||||
order.update_items_status_to_billed(nil)
|
||||
order.status = "billed"
|
||||
order.save
|
||||
|
||||
booking.sale_id = self.id
|
||||
booking.save
|
||||
|
||||
return true, self.id
|
||||
end
|
||||
|
||||
@@ -4,4 +4,18 @@ class SaleItem < ApplicationRecord
|
||||
#compute items - discount, tax, price_change
|
||||
def compute_item
|
||||
end
|
||||
|
||||
def self.get_order_items_details(sale_id)
|
||||
sale_orders = SaleOrder.where("sale_id=?",sale_id)
|
||||
if sale_orders
|
||||
sale_orders.each do |sale_order|
|
||||
order_details = SaleItem.select("sales.total_discount as discount_amount,DATE_FORMAT(sales.receipt_date,'%Y-%m-%d %h:%m') as receipt_date,sales.cashier_name,sales.receipt_no,sale_items.product_name as item_name,sale_items.qty,sale_items.price,sale_items.unit_price as total_price")
|
||||
.joins("left join sales on sales.id = sale_items.sale_id")
|
||||
.where("sale_items.sale_id=?",sale_order.sale_id)
|
||||
return order_details
|
||||
end
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user