143 lines
4.6 KiB
Ruby
Executable File
143 lines
4.6 KiB
Ruby
Executable File
class Origami::VoidController < BaseOrigamiController
|
|
authorize_resource :class => false
|
|
def overall_void
|
|
|
|
sale_id = params[:sale_id]
|
|
remark = params[:remark]
|
|
if Sale.exists?(sale_id)
|
|
sale = Sale.find_by_sale_id(sale_id)
|
|
|
|
if sale.discount_type == "member_discount"
|
|
sale.update_attributes(total_discount: 0)
|
|
sale.compute_by_sale_items(sale_id, sale.sale_items,0)
|
|
end
|
|
|
|
# update count for shift sale
|
|
if(sale.sale_status == "completed")
|
|
if sale.shift_sale_id != nil
|
|
shift = ShiftSale.find(sale.shift_sale_id)
|
|
shift.calculate(sale_id, "void")
|
|
end
|
|
else
|
|
# void before sale payment complete
|
|
if sale.shift_sale_id != nil
|
|
shift = ShiftSale.find(sale.shift_sale_id)
|
|
shift.total_void = shift.total_void + sale.grand_total
|
|
shift.save
|
|
end
|
|
end
|
|
|
|
sale.payment_status = 'void'
|
|
sale.sale_status = 'void'
|
|
sale.save
|
|
|
|
# No Need
|
|
# bookings = sale.bookings
|
|
# bookings.each do |booking|
|
|
# orders = booking.orders
|
|
# orders.each do |order|
|
|
# # order.status = 'void'
|
|
# end
|
|
# end
|
|
|
|
if sale.bookings[0].dining_facility_id.to_i > 0
|
|
table_avaliable = true
|
|
table_count = 0
|
|
table = sale.bookings[0].dining_facility
|
|
table.bookings.each do |booking|
|
|
if booking.booking_status != 'moved'
|
|
if booking.sale_id
|
|
if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void'
|
|
table_avaliable = false
|
|
table_count += 1
|
|
else
|
|
table_avaliable = true
|
|
end
|
|
else
|
|
table_avaliable = false
|
|
table_count += 1
|
|
end
|
|
end
|
|
end
|
|
|
|
if table_avaliable && table_count == 0
|
|
table.status = 'available'
|
|
table.save
|
|
end
|
|
else
|
|
table = nil
|
|
end
|
|
|
|
# FOr Sale Audit
|
|
action_by = current_user.name
|
|
# remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}"
|
|
sale_audit = SaleAudit.record_audit_for_edit(sale_id,sale.cashier_id, action_by,remark,"SALEVOID" )
|
|
|
|
# For Print
|
|
|
|
member_info = nil
|
|
rebate_amount = nil
|
|
current_balance = nil
|
|
|
|
# For Cashier by Zone
|
|
bookings = Booking.where("sale_id='#{sale_id}'")
|
|
if bookings.count > 1
|
|
# for Multiple Booking
|
|
if bookings[0].dining_facility_id.to_i>0
|
|
table = DiningFacility.find(bookings[0].dining_facility_id)
|
|
end
|
|
|
|
|
|
end
|
|
|
|
if bookings[0].dining_facility_id.to_i > 0
|
|
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
|
|
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
|
|
else
|
|
shift = ShiftSale.find(sale.shift_sale_id)
|
|
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
|
|
end
|
|
|
|
|
|
if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
|
|
unique_code = "ReceiptBillPdf"
|
|
customer= Customer.find(sale.customer_id)
|
|
|
|
#shop detail
|
|
shop_details = Shop.find(1)
|
|
# get member information
|
|
rebate = MembershipSetting.find_by_rebate(1)
|
|
if customer.membership_id != nil && rebate
|
|
member_info = Customer.get_member_account(customer)
|
|
rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no)
|
|
current_balance = SaleAudit.paymal_search(sale_id)
|
|
end
|
|
|
|
# get printer info
|
|
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
|
# Calculate Food and Beverage Total
|
|
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items)
|
|
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)
|
|
end
|
|
|
|
#end print
|
|
|
|
# update complete order items in oqs
|
|
SaleOrder.where("sale_id = '#{ sale_id }'").find_each do |sodr|
|
|
AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi|
|
|
aoi.delivery_status = 1
|
|
aoi.save
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
#Shop Name in Navbor
|
|
helper_method :shop_detail
|
|
def shop_detail
|
|
@shop = Shop.first
|
|
end
|
|
end |