Files
sx-fc/app/controllers/origami/table_invoices_controller.rb
2018-03-12 12:10:52 +06:30

79 lines
2.8 KiB
Ruby
Executable File

class Origami::TableInvoicesController < BaseOrigamiController
def index
@table = DiningFacility.find(params[:table_id])
shop = Shop::ShopDetail
puts "table bookig lenght"
@sale_array = Array.new
@table.bookings.each do |booking|
puts booking.sale_id
if booking.sale_id.nil?
else
sale = Sale.find(booking.sale_id)
# rounding adjustment
if shop.is_rounding_adj
a = sale.grand_total % 25 # Modulus
b = sale.grand_total / 25 # Division
#not calculate rounding if modulus is 0 and division is even
#calculate rounding if modulus is zero or not zero and division are not even
if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
new_total = Sale.get_rounding_adjustment(sale.grand_total)
sale.rounding_adjustment = new_total-sale.grand_total
end
end
#end rounding adjustment
if sale.sale_status != "completed"
@sale_array.push(sale)
end
end
end
end
def show
@table = DiningFacility.find(params[:table_id])
shop = Shop::ShopDetail
@sale_array = Array.new
@table.bookings.each do |booking|
if booking.sale_id.nil?
else
sale = Sale.find(booking.sale_id)
# rounding adjustment
if shop.is_rounding_adj
a = sale.grand_total % 25 # Modulus
b = sale.grand_total / 25 # Division
#not calculate rounding if modulus is 0 and division is even
#calculate rounding if modulus is zero or not zero and division are not even
if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
new_total = Sale.get_rounding_adjustment(sale.grand_total)
sale.rounding_adjustment = new_total-sale.grand_total
sale.update_attributes(grand_total: new_total,old_grand_total: sale.grand_total,rounding_adjustment:sale.rounding_adjustment)
end
end
#end rounding adjustment
if sale.sale_status != "completed" && sale.sale_status != 'void'
@sale_array.push(sale)
end
end
end
@sale = Sale.find(params[:invoice_id])
@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
# get printer info
@print_settings = PrintSetting.get_precision_delimiter()
end
#Shop Name in Navbor
helper_method :shop_detail
def shop_detail
@shop = Shop.first
end
end