fixed conflix after pull split bill

This commit is contained in:
Aung Myo
2018-02-19 14:21:26 +06:30
24 changed files with 977 additions and 275 deletions

View File

@@ -27,40 +27,37 @@ class Origami::HomeController < BaseOrigamiController
@membership = MembershipSetting::MembershipSetting
@payment_methods = PaymentMethodSetting.all
# bookings = Booking.all
# if !bookings.nil?
# @order_items_count = Hash.new
# bookings.each do |booking|
# if booking.sale_id.nil? && booking.booking_status != 'moved'
# if !booking.booking_orders.empty?
# booking.booking_orders.each do |booking_order|
# order = Order.find(booking_order.order_id)
# if !order.order_items.empty?
# if !@order_items_count.key?(booking.dining_facility_id)
# @order_items_count.store(booking.dining_facility_id, order.order_items.count)
# else
# @order_items_count[booking.dining_facility_id] += order.order_items.count
# end
# end
# end
# end
# else
# if !booking.sale_id.nil?
# sale = Sale.find(booking.sale_id)
# if sale.sale_status !='completed'
# if !@order_items_count.key?(booking.dining_facility_id)
# @order_items_count.store(booking.dining_facility_id, sale.sale_items.count)
# else
# @order_items_count[booking.dining_facility_id] = sale.sale_items.count
# end
# end
# end
# end
# end
# end
puts "@order_items_count"
puts @order_items_count.to_json
bookings = Booking.all
if !bookings.today.nil?
@order_items_count = Hash.new
bookings.each do |booking|
if booking.sale_id.nil? && booking.booking_status != 'moved'
if !booking.booking_orders.empty?
booking.booking_orders.each do |booking_order|
order = Order.find(booking_order.order_id)
if !order.order_items.empty?
if !@order_items_count.key?(booking.dining_facility_id)
@order_items_count.store(booking.dining_facility_id, order.order_items.count)
else
@order_items_count[booking.dining_facility_id] += order.order_items.count
end
end
end
end
else
if !booking.sale_id.nil?
sale = Sale.find(booking.sale_id)
if sale.sale_status !='completed'
if !@order_items_count.key?(booking.dining_facility_id)
@order_items_count.store(booking.dining_facility_id, sale.sale_items.count)
else
@order_items_count[booking.dining_facility_id] = sale.sale_items.count
end
end
end
end
end
end
@dining.bookings.active.each do |booking|
if booking.sale_id.nil? && booking.booking_status != 'moved'
@@ -126,12 +123,12 @@ class Origami::HomeController < BaseOrigamiController
#for bank integration
@checkout_time = Lookup.collection_of('checkout_time')
@checkout_alert_time = Lookup.collection_of('checkout_alert_time')
#for split bill
lookup_spit_bill = Lookup.collection_of('split_bill')
@spit_bill = 0
if !lookup_spit_bill[0].nil?
@spit_bill = lookup_spit_bill[0][1]
end
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
end
private
@@ -140,9 +137,4 @@ def set_dining
@dining = DiningFacility.find(params[:dining_id])
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
end
end

View File

@@ -5,6 +5,23 @@ class Origami::OrdersController < BaseOrigamiController
@complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d'))
@orders = Order.where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
@order = Order.find(params[:order_id])
booking = Booking.select('bookings.booking_id, bookings.dining_facility_id')
.joins(" JOIN booking_orders as bo on bo.booking_id = bookings.booking_id")
.where("bo.order_id='#{params[:order_id]}'").first()
@booking = Array.new
if !booking.nil?
dining_facilities = DiningFacility.find_by_id(booking.dining_facility_id)
@booking.push({'booking_id' => booking.booking_id, 'dining_facility_id' => booking.dining_facility_id, 'type' => dining_facilities.type})
end
#for split bill
lookup_spit_bill = Lookup.collection_of('split_bill')
@split_bill = 0
if !lookup_spit_bill[0].nil?
@split_bill = lookup_spit_bill[0][1]
end
sale_order = SaleOrder.find_by_order_id(@order.order_id)
if sale_order
unless sale_order.sale_id.nil?
@@ -12,9 +29,22 @@ class Origami::OrdersController < BaseOrigamiController
@sale_status = sale.sale_status
end
end
@order.order_items.each_with_index do |item, order_item_index|
if !item.set_menu_items.nil?
instance_item_sets = JSON.parse(item.set_menu_items)
arr_instance_item_sets = Array.new
instance_item_sets.each do |instance_item|
item_instance_name = MenuItemInstance.find_by_item_instance_code(instance_item["item_instance_code"]).item_instance_name
arr_instance_item_sets.push(item_instance_name)
item.price = item.price.to_f + instance_item["price"].to_f
end
@order.order_items[order_item_index].set_menu_items = arr_instance_item_sets
end
end
bookings = Booking.all
if !bookings.nil?
if !bookings.today.nil?
@order_items_count = Hash.new
bookings.each do |booking|
if booking.sale_id.nil? && booking.booking_status != 'moved'

View File

@@ -8,7 +8,8 @@ class Origami::PaymentsController < BaseOrigamiController
sale_data = Sale.find_by_sale_id(sale_id)
sale_items = SaleItem.where("sale_id=?",sale_id)
member_info = nil
survey = Survey.find_by_receipt_no(sale_data.receipt_no)
# For Cashier by Zone
bookings = Booking.where("sale_id='#{sale_id}'")
# if bookings.count > 1
@@ -66,7 +67,7 @@ class Origami::PaymentsController < BaseOrigamiController
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_details, "Frt",current_balance,nil)
printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_details, "Frt",current_balance,nil,survey)
end
end
@@ -78,6 +79,7 @@ class Origami::PaymentsController < BaseOrigamiController
if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id)
shop_details = Shop::ShopDetail
survey = Survey.find_by_receipt_no(saleObj.receipt_no)
# rounding adjustment
if shop_details.is_rounding_adj
a = saleObj.grand_total % 25 # Modulus
@@ -151,7 +153,7 @@ class Origami::PaymentsController < BaseOrigamiController
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Paid",current_balance,card_data)
printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Paid",current_balance,card_data,survey)
if params[:type] == "quick_service"
booking = Booking.find_by_sale_id(sale_id)
@@ -273,7 +275,8 @@ class Origami::PaymentsController < BaseOrigamiController
member_info = nil
saleObj = Sale.find(sale_id)
survey = Survey.find_by_receipt_no(saleObj.receipt_no)
# For Cashier by Zone
bookings = Booking.where("sale_id='#{sale_id}'")
# if bookings.count > 1
@@ -326,7 +329,7 @@ class Origami::PaymentsController < BaseOrigamiController
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Re-print",current_balance,card_data)
printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Re-print",current_balance,card_data,survey)
end
end
@@ -340,7 +343,8 @@ class Origami::PaymentsController < BaseOrigamiController
if(Sale.exists?(sale_id))
saleObj = Sale.find(sale_id)
survey = Survey.find_by_receipt_no(saleObj.receipt_no)
if saleObj.discount_type == "member_discount"
saleObj.update_attributes(rounding_adjustment: 0)
saleObj.compute_by_sale_items(sale_id, saleObj.sale_items,0)
@@ -384,7 +388,7 @@ class Origami::PaymentsController < BaseOrigamiController
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "FOC",nil,nil)
printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "FOC",nil,nil,survey)
end
end
end

View File

@@ -24,7 +24,7 @@ class Origami::RoomsController < BaseOrigamiController
@payment_methods = PaymentMethodSetting.all
bookings = Booking.all
if !bookings.nil?
if !bookings.today.nil?
@order_items_count = Hash.new
bookings.each do |booking|
if booking.sale_id.nil? && booking.booking_status != 'moved'
@@ -125,9 +125,9 @@ class Origami::RoomsController < BaseOrigamiController
# end
lookup_spit_bill = Lookup.collection_of('split_bill')
@spit_bill = 0
@split_bill = 0
if !lookup_spit_bill[0].nil?
@spit_bill = lookup_spit_bill[0][1]
@split_bill = lookup_spit_bill[0][1]
end
end

View File

@@ -18,6 +18,7 @@ class Origami::SplitBillController < BaseOrigamiController
if @booking
@booking.booking_orders.each do |booking_order|
arr_order_items = Array.new
@order = Order.find(booking_order.order_id)
if (@order.status == "new")
@orders.push(@order)
@@ -28,12 +29,44 @@ class Origami::SplitBillController < BaseOrigamiController
arr_instance_item_sets = Array.new
instance_item_sets.each do |instance_item|
item_instance_name = MenuItemInstance.find_by_item_instance_code(instance_item["item_instance_code"]).item_instance_name
item.price = item.price.to_f + instance_item["price"].to_f
arr_instance_item_sets.push(item_instance_name)
end
item.set_menu_items = arr_instance_item_sets
end
@order_items.push(item)
arr_item = Hash.new
if item.qty.to_i > 1
i = 1
while i <= item.qty.to_i do
arr_item = {'order_items_id' => item.order_items_id,
'order_id' => item.order_id,
'order_item_status' => item.order_item_status,
'item_order_by' => item.item_order_by,
'item_code' => item.item_code,
'item_instance_code' => item.item_instance_code,
'item_name' => item.item_name,
'alt_name' => item.alt_name,
'account_id' => item.account_id,
'qty' => '1.0',
'price' => item.price,
'remark' => item.remark,
'options' => item.options,
'set_menu_items' => item.set_menu_items,
'taxable' => item.taxable,
'completed_by' => item.completed_by,
'created_at' => item.created_at,
'updated_at' => item.updated_at}
i += 1
@order_items.push({@order.order_id => arr_item})
arr_order_items.push(arr_item)
end
else
arr_order_items.push(item)
@order_items.push({@order.order_id => item})
end
end
@order_items.push({'all_order' => arr_order_items})
end
end
else
@@ -116,6 +149,8 @@ class Origami::SplitBillController < BaseOrigamiController
if !order_id.nil?
if order_id_count > 1
puts "order_id_count > 1"
updated_order_id = Array.new
order_ids.each do |odr_id|
odr = Order.find(odr_id)
@@ -124,6 +159,9 @@ class Origami::SplitBillController < BaseOrigamiController
end
end
puts "updated_order_id"
puts updated_order_id
if !updated_order_id.empty?
order_ids.each do |odr_id|
unless updated_order_id.include?(odr_id)
@@ -134,30 +172,115 @@ class Origami::SplitBillController < BaseOrigamiController
order_items.each do |order_item|
if updated_order_id.include?(order_item["order_id"])
orderItem = OrderItem.find(order_item["id"])
orderItem.order_id = order_id
orderItem.save!
update_order_item(order_id, order_item)
end
end
else
order_ids.each do |odr_id|
BookingOrder.find_by_order_id(odr_id).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id})
new_order_status = true
order_items.each do |order_item|
orderItem = OrderItem.find_by_order_id(odr_id)
if !orderItem.nil?
if order_item["id"] == orderItem.order_items_id
if orderItem.qty.to_f != order_item['qty'].to_f
new_order_status = false
end
end
end
end
if new_order_status
BookingOrder.find_by_order_id(odr_id).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id})
else
customer = Customer.find(params[:customer_id])
order_type = "dine_in"
if !customer.nil?
if customer.customer_type == "Takeaway"
order_type = "takeaway"
elsif customer.customer_type == "Delivery"
order_type = "delivery"
end
end
# begin
order = Order.new
order.source = "cashier"
order.order_type = order_type
order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
order.item_count = order_items.count
order.status = "new"
order.table_id = params[:dining_id] # this is dining facilities's id
order.waiters = current_user.name
order.employee_name = current_user.name
order.guest_info = nil
order.save!
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
order_items.each do |order_item|
update_order_item(order.order_id, order_item)
end
end
end
end
else
BookingOrder.find_by_order_id(order_id).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_id})
puts "order_id_count < 1"
new_order_status = true
order_items.each do |order_item|
orderItem = OrderItem.find(order_item["id"])
orderItem.order_id = order_id
orderItem.save!
orderItem = OrderItem.find_by_order_id(order_id)
if !orderItem.nil?
if order_item["id"] == orderItem.order_items_id
if orderItem.qty.to_f != order_item['qty'].to_f
new_order_status = false
end
end
end
end
if new_order_status
BookingOrder.find_by_order_id(order_id).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_id})
order_items.each do |order_item|
update_order_item(order_id, order_item)
end
else
customer = Customer.find(params[:customer_id])
order_type = "dine_in"
if !customer.nil?
if customer.customer_type == "Takeaway"
order_type = "takeaway"
elsif customer.customer_type == "Delivery"
order_type = "delivery"
end
end
# begin
order = Order.new
order.source = "cashier"
order.order_type = order_type
order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
order.item_count = order_items.count
order.status = "new"
order.table_id = params[:dining_id] # this is dining facilities's id
order.waiters = current_user.name
order.employee_name = current_user.name
order.guest_info = nil
order.save!
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
order_items.each do |order_item|
update_order_item(order.order_id, order_item)
end
end
end
else
if order_ids.count == 1 && order_id_count > 0 && order_item_count == 1
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_ids[0]})
order_items.each do |order_item|
update_order_item(order_ids[0], order_item)
end
else
customer = Customer.find(params[:customer_id])
order_type = "dine_in"
@@ -185,9 +308,7 @@ class Origami::SplitBillController < BaseOrigamiController
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
order_items.each do |order_item|
orderItem = OrderItem.find(order_item["id"])
orderItem.order_id = order.order_id
orderItem.save!
update_order_item(order.order_id, order_item)
end
end
end
@@ -212,6 +333,29 @@ class Origami::SplitBillController < BaseOrigamiController
end
end
def update_order_item(order_id, order_item)
orderItem = OrderItem.find(order_item["id"])
if orderItem.qty.to_f != order_item['qty'].to_f
OrderItem.processs_item(orderItem.item_code,
orderItem.item_instance_code,
orderItem.item_name,
orderItem.alt_name,
orderItem.account_id,
order_item['qty'],
orderItem.price,
orderItem.options,
orderItem.set_menu_items,
order_id,
orderItem.item_order_by,
orderItem.taxable)
orderItem.qty = orderItem.qty.to_f - order_item['qty'].to_f
else
orderItem.order_id = order_id
end
orderItem.save!
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail

View File

@@ -1,17 +1,25 @@
class Origami::SurveysController < BaseOrigamiController
def new
@survey = Survey.new
@id = params[:id]
@cashier_type = params[:type]
if(@id[0,3] == "SAL")
@sale = Sale.find(@id)
@receipt_no = @sale.receipt_no
@grand_total = @sale.grand_total
@booking = Booking.find_by_sale_id(@id)
if @booking.dining_facility_id.to_i>0
@dining_facility = DiningFacility.find(@booking.dining_facility_id)
@table_type = @dining_facility.type
@dining_facility = DiningFacility.find(@booking.dining_facility_id)
@table_type = @dining_facility.type
@survey_data = Survey.find_by_dining_name(@dining_facility.name)
survey_process = Survey.find_by_receipt_no(@receipt_no)
if !survey_process.nil?
@survey_data = survey_process
end
else
@dining_facility = nil
@table_type = nil
@@ -22,6 +30,7 @@ class Origami::SurveysController < BaseOrigamiController
@table_type = @dining_facility.type
@receipt_no = nil
@grand_total = nil
@survey_data = Survey.find_by_dining_name(@dining_facility.name)
end
end
@@ -36,20 +45,71 @@ class Origami::SurveysController < BaseOrigamiController
else
@url = "/origami/"+@dining_facility.type.downcase+"/"+params[:table_id]
end
@survey = Survey.new(survey_params)
@survey.foreigner = params["survey"]["foreigner"].to_json
# respond_to do |format|
if @survey.save
redirect_to @url
end
# end
cashier_zone = CashierTerminalByZone.find_by_zone_id(@dining_facility.zone_id)
shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil)
if params[:survey_id].nil? || params[:survey_id] == ""
@survey = Survey.new(survey_params)
@survey.shift_id = shift_by_terminal.id
@survey.foreigner = params["survey"]["foreigner"].to_json
# respond_to do |format|
if @survey.save
redirect_to @url
end
# end
else
survey = Survey.find_by_id(params[:survey_id])
survey.child = params["survey"]["child"]
survey.adult = params["survey"]["adult"]
survey.male = params["survey"]["male"]
survey.female = params["survey"]["female"]
survey.local = params["survey"]["local"]
survey.dining_name = params["survey"]["dining_name"]
survey.receipt_no = params["survey"]["receipt_no"]
survey.shift_id = shift_by_terminal.id
survey.created_by = params["survey"]["created_by"]
survey.total_customer = params["survey"]["total_customer"]
survey.total_amount = params["survey"]["total_amount"]
survey.foreigner = params["survey"]["foreigner"].to_json
if survey.save!
redirect_to @url
end
end
end
def create_survey
if shift_by_terminal = ShiftSale.current_open_shift(get_cashier[0].id)
dining_facility = DiningFacility.find(params[:dining_id])
cashier_zone = CashierTerminalByZone.find_by_zone_id(dining_facility.zone_id)
shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil)
survey = Survey.find_by_dining_name(dining_facility.name)
if survey.nil?
survey = Survey.new
survey.dining_name = dining_facility.name
survey.receipt_no = params[:receipt_no]
survey.shift_id = shift_by_terminal.id
survey.created_by = current_user.name
survey.total_customer = params[:total_customer]
survey.total_amount = params[:total_amount]
survey.save!
else
survey.receipt_no = params[:receipt_no]
survey.total_customer = params[:total_customer]
survey.save!
end
render :json => {status: true}
else
render :json => { status: false, error_message: 'No Current Open Shift!'}
end
end
private
# Never trust parameters from the scary internet, only allow the white list through.
def survey_params
params.require(:survey).permit(:child, :adult,:male,:female,:local,:foreigner, :dining_name,:receipt_no,:shift_id,:created_by,:total_customer,:total_amount)
params.require(:survey).permit(:child, :adult,:male,:female,:local,:foreigner, :dining_name,:receipt_no,:shift_id,:created_by,:total_customer,:total_amount,:survey_id)
end
#Shop Name in Navbor

View File

@@ -59,6 +59,12 @@ class Origami::TableInvoicesController < BaseOrigamiController
@date = @sale.created_at
@status_sale = 'sale'
@customer = @sale.customer
#for split bill
lookup_spit_bill = Lookup.collection_of('split_bill')
@split_bill = 0
if !lookup_spit_bill[0].nil?
@split_bill = lookup_spit_bill[0][1]
end
end
#Shop Name in Navbor

View File

@@ -6,6 +6,8 @@ class Origami::VoidController < BaseOrigamiController
if Sale.exists?(sale_id)
sale = Sale.find_by_sale_id(sale_id)
survey = Survey.find_by_receipt_no(sale.receipt_no)
if sale.discount_type == "member_discount"
sale.update_attributes(total_discount: 0)
sale.compute_by_sale_items(sale_id, sale.sale_items,0)
@@ -123,7 +125,7 @@ class Origami::VoidController < BaseOrigamiController
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil)
printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil,survey)
end
#end print