diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index b054f77d..501c62be 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -41,7 +41,7 @@ class Origami::DiscountsController < BaseOrigamiController sale_item.remark = "Discount" sale_item.qty = -1 - sale_item.unit_price = di["price"] * -1 + sale_item.unit_price = di["price"].to_f * (-1) sale_item.taxable_price = di["price"] sale_item.is_taxable = 1 sale_item.account_id = origin_sale_item.account_id diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 428dc322..fdd55f06 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -209,7 +209,7 @@ class Origami::PaymentsController < BaseOrigamiController 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") end - def foc + def foc cash = params[:cash] sale_id = params[:sale_id] sub_total = params[:sub_total] @@ -233,6 +233,9 @@ class Origami::PaymentsController < BaseOrigamiController cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + # Re-call Sale Data + saleObj = Sale.find(sale_id) + unique_code = "ReceiptBillPdf" customer= Customer.find(saleObj.customer_id) diff --git a/app/models/sale.rb b/app/models/sale.rb index 0151a0a0..83d49309 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -182,7 +182,7 @@ class Sale < ApplicationRecord sale_item.product_alt_name = "-" sale_item.qty = block_count sale_item.unit_price = chargeObj.unit_price - sale_item.taxable_price = sale_item.qty * sale_item.unit_price + sale_item.taxable_price = diningprice sale_item.is_taxable = chargeObj.taxable sale_item.sale_id = self.id sale_item.price = diningprice @@ -608,19 +608,33 @@ def self.get_by_shift_sale(from,to,status) end def self.get_item_query() + # query = SaleItem.select("acc.title as account_name,account_id, item_instance_code as item_code, " + + # "SUM(qty * unit_price) as grand_total,SUM(qty) as total_item," + + # " unit_price as unit_price,product_name as product_name, 'cat' as" + + # " menu_category_name,'test' as menu_category_id ") + + # query = query.joins("JOIN sales s ON s.sale_id = sale_items.sale_id" + + # " JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id") + # # "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ") + + # query = query.joins(" JOIN accounts acc ON acc.id = account_id") + # query = query.where("item_instance_code is not NULL") + # query = query.group("item_instance_code").order("account_id") + query = Sale.select("acc.title as account_name,mi.account_id, i.item_instance_code as item_code, " + - "(i.qty * i.unit_price) as grand_total,(i.qty) as total_item," + + "SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," + " i.unit_price as unit_price,i.product_name as product_name, mc.name as" + " menu_category_name,mc.id as menu_category_id ") query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" + - " JOIN menu_items mi ON i.product_code = mi.item_code" + + " JOIN menu_item_instances mii ON i.item_instance_code = mii.item_instance_code" + + " JOIN menu_items mi ON mi.id = mii.menu_item_id" + " JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id" + " JOIN menu_categories mc ON mc.id = mi.menu_category_id ") # "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ") query = query.joins(" JOIN accounts acc ON acc.id = mi.account_id") - query = query.where("i.unit_price > 0") + query = query.where("i.item_instance_code IS NOT NULL") query = query.group("i.item_instance_code").order("mi.account_id, mi.menu_category_id") end diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index 08e592d5..a757b7fd 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -17,20 +17,20 @@ class SaleItem < ApplicationRecord @newsaleitem = SaleItem.new @newsaleitem = saleitemObj.dup @newsaleitem.save - @newsaleitem.qty = saleitemObj.qty * -1 - @newsaleitem.unit_price = saleitemObj.unit_price * -1 - @newsaleitem.taxable_price = (saleitemObj.unit_price * saleitemObj.qty) * -1 - @newsaleitem.price = (saleitemObj.unit_price * saleitemObj.qty) * -1 + @newsaleitem.qty = saleitemObj.qty * (-1) + @newsaleitem.unit_price = saleitemObj.unit_price * (-1) + @newsaleitem.taxable_price = (saleitemObj.unit_price * saleitemObj.qty) * (-1) + @newsaleitem.price = (saleitemObj.unit_price * saleitemObj.qty) * (-1) @newsaleitem.product_name = saleitemObj.product_name + ' (FOC)' @newsaleitem.save end end - def self.update_existing_item(qty, item, sale_id, type, item_price) + def self.update_existing_item(qty, item, sale_id, type, item_price, price) sale_item = SaleItem.new - sale_item.product_code = item.item_code - sale_item.product_name = item.item_name + "(#{type})" - sale_item.product_alt_name = item.alt_name + sale_item.product_code = item.product_code + sale_item.product_name = item.product_name + "(#{type})" + sale_item.product_alt_name = item.product_alt_name sale_item.account_id = item.account_id sale_item.remark = type if type == "foc" || type == "promotion" || type == "void" @@ -40,8 +40,8 @@ class SaleItem < ApplicationRecord end sale_item.unit_price = item_price # * (-1) - sale_item.taxable_price = (qty * item_price) * (-1) - sale_item.price = (qty * item_price) * (-1) + sale_item.taxable_price = (price) * (-1) + sale_item.price = (price) * (-1) sale_item.is_taxable = 1 sale_item.sale_id = sale_id @@ -96,7 +96,7 @@ class SaleItem < ApplicationRecord # Check for actual sale items sale_items.where("is_taxable = false AND remark = 'Discount'").find_each do |si| if si.account_id == a.id - discount_account[:price] = (discount_account[:price].abs + si.price.abs) * -1 + discount_account[:price] = (discount_account[:price].abs + si.price.abs) * (-1) end end discount_accounts.push(discount_account) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index afc4c75d..961a556f 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -171,9 +171,10 @@ class SalePayment < ApplicationRecord payment_status = false # add to sale item with foc - sale_items = SaleItem.find_by_sale_id(self.sale) + sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }'") + sale_items.each do|item| - SaleItem.update_existing_item(item.qty, item, self.sale, "foc", item.unit_price) + SaleItem.update_existing_item(item.qty, item, self.sale.sale_id, "foc", item.unit_price, item.price) end self.payment_method = "foc"