fixed conflictsale item order order item

This commit is contained in:
Aung Myo
2017-06-04 16:51:38 +06:30
61 changed files with 455 additions and 137 deletions

View File

@@ -1,4 +1,6 @@
class Order < ApplicationRecord
#primary key - need to be unique
before_create :generate_custom_id
before_create :set_order_date
belongs_to :customer
@@ -16,7 +18,7 @@ class Order < ApplicationRecord
# option_values : [],
# sub_order_items : [],
# }
def generate
booking = nil
@@ -180,14 +182,6 @@ class Order < ApplicationRecord
return new_items_list
end
private
def validate_api_inputs
end
def set_order_date
self.date = Time.now.utc
end
#Update Items Count and Quantity changes whenever there is changes
def update_products_and_quantity_count
@@ -235,6 +229,18 @@ class Order < ApplicationRecord
.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")
#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,order_items.id,dining_facilities.name")
end
#Origami: Cashier : to view orders
def self.get_orders
@@ -244,9 +250,11 @@ class Order < ApplicationRecord
.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 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")
@@ -259,4 +267,14 @@ class Order < ApplicationRecord
# .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
private
def generate_custom_id
self.order_id = SeedGenerator.generate_id(self.class.name, "ODR")
end
def set_order_date
self.date = Time.now.utc
end
end