diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 1166a705..56389302 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.product_name = di["name"] sale_item.item_instance_code = origin_sale_item.item_instance_code sale_item.product_alt_name = "" - sale_item.remark = "Discount" + sale_item.status = "Discount" sale_item.qty = -1 sale_item.unit_price = di["price"].to_f * (-1) @@ -123,7 +123,7 @@ class Origami::DiscountsController < BaseOrigamiController discount_items = [] #destroy all discount sale item sale.sale_items.each do |si| - if si.remark == "Discount" && si.price < 0 + if si.status == "Discount" && si.price < 0 sale.total_amount = (sale.total_amount + si.price.abs) discount_items.push(si) end @@ -277,7 +277,7 @@ class Origami::DiscountsController < BaseOrigamiController # sale_item.sale_id = sale_id # sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id # sale_item.product_name = product_name - # sale_item.remark = remark + # sale_item.status = remark # sale_item.qty = 1 # sale_item.unit_price = (0-discount_amount.to_f) diff --git a/app/controllers/origami/other_charges_controller.rb b/app/controllers/origami/other_charges_controller.rb index 51a1f7db..07cd177e 100755 --- a/app/controllers/origami/other_charges_controller.rb +++ b/app/controllers/origami/other_charges_controller.rb @@ -32,7 +32,7 @@ class Origami::OtherChargesController < BaseOrigamiController sale_item.product_code = "Other Charges" sale_item.product_name = "*" + di["name"] sale_item.product_alt_name = "" - sale_item.remark = "Other Charges" + sale_item.status = "Other Charges" sale_item.qty = 1 sale_item.unit_price = di["price"] diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 317743dd..c5418d10 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -307,12 +307,14 @@ class Origami::PaymentsController < BaseOrigamiController if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - + if saleObj.discount_type == "member_discount" saleObj.update_attributes(rounding_adjustment: 0) saleObj.compute_by_sale_items(sale_id, saleObj.sale_items,0) end + saleObj.update_attributes(rounding_adjustment: 0) + sale_payment = SalePayment.new sale_payment.process_payment(saleObj, current_user.name, cash, "foc" ,remark) diff --git a/app/controllers/origami/sale_edit_controller.rb b/app/controllers/origami/sale_edit_controller.rb index c00c35f0..e87deb35 100755 --- a/app/controllers/origami/sale_edit_controller.rb +++ b/app/controllers/origami/sale_edit_controller.rb @@ -10,8 +10,10 @@ class Origami::SaleEditController < BaseOrigamiController # create item void. make duplicate old record and update qty and price def item_void saleitemId = params[:sale_item_id] + remark = params[:remark] saleitemObj = SaleItem.find(saleitemId) - saleitemObj.remark = 'void' + saleitemObj.status = 'void' + saleitemObj.remark = remark saleitemObj.save @newsaleitem = SaleItem.new @newsaleitem = saleitemObj.dup @@ -21,6 +23,7 @@ class Origami::SaleEditController < BaseOrigamiController @newsaleitem.is_taxable = 1 @newsaleitem.taxable_price = saleitemObj.taxable_price * -1 @newsaleitem.product_name = saleitemObj.product_name + ' (VOID)' + @newsaleitem.remark = remark @newsaleitem.save # re-calc tax @@ -36,8 +39,10 @@ class Origami::SaleEditController < BaseOrigamiController def item_foc saleitemId = params[:sale_item_id] + remark = params[:remark] saleitemObj = SaleItem.find(saleitemId) - saleitemObj.remark = 'foc' + saleitemObj.status = 'foc' + saleitemObj.remark = remark saleitemObj.save @newsaleitem = SaleItem.new @newsaleitem = saleitemObj.dup @@ -47,6 +52,7 @@ class Origami::SaleEditController < BaseOrigamiController @newsaleitem.taxable_price = saleitemObj.taxable_price * -1 @newsaleitem.price = saleitemObj.price * -1 @newsaleitem.product_name = saleitemObj.product_name + ' (FOC)' + @newsaleitem.remark = remark @newsaleitem.save # re-calc tax @@ -65,7 +71,7 @@ class Origami::SaleEditController < BaseOrigamiController # update_qty = params[:update_qty] # update_price = params[:update_price] # saleitemObj = SaleItem.find(saleitemId) - # saleitemObj.remark = 'void' + # saleitemObj.status = 'void' # saleitemObj.save # @newsaleitem = SaleItem.new # @newsaleitem = saleitemObj.dup @@ -117,7 +123,7 @@ class Origami::SaleEditController < BaseOrigamiController both = SaleItem.where('product_code=?', saleitemObj.product_code) both.each do |item| if item.qty.to_i > 0 - item.remark = nil + item.status = nil item.save end end @@ -142,7 +148,7 @@ class Origami::SaleEditController < BaseOrigamiController if item.qty.to_i < 0 item.destroy else - item.remark = nil + item.status = nil end item.save ProductCommission.remove_product_commission(item) diff --git a/app/models/sale.rb b/app/models/sale.rb index f0166491..47733557 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -92,7 +92,7 @@ class Sale < ApplicationRecord self.cashier_id = open_cashier[0].id self.cashier_name = open_cashier[0].name shift_id = ShiftSale.current_open_shift(open_cashier[0].id) - self.shift_sale_id = shift_id.id + self.shift_sale_id = current_shift.id else self.cashier_id = current_shift.employee_id self.cashier_name = Employee.find(current_shift.employee_id).name @@ -227,7 +227,7 @@ class Sale < ApplicationRecord sale_item.product_name = item.item_name sale_item.product_alt_name = item.alt_name sale_item.account_id = item.account_id - sale_item.remark = item.remark + sale_item.status = item.remark sale_item.qty = item.qty sale_item.unit_price = item.price @@ -255,7 +255,7 @@ class Sale < ApplicationRecord sale_item.product_name = instance.item_instance_name sale_item.product_alt_name = menu_item.alt_name sale_item.account_id = menu_item.account_id - sale_item.remark = nil + sale_item.status = nil sale_item.qty = item["quantity"] sale_item.unit_price = item["price"] @@ -381,7 +381,7 @@ class Sale < ApplicationRecord rounding_adjustment = 0 sales_items.each do |item| - if item.remark != 'void' && item.remark != 'foc' + if item.status != 'void' && item.status != 'foc' #compute each item and added to total subtotal_price = subtotal_price + item.price @@ -417,35 +417,36 @@ class Sale < ApplicationRecord tax_profiles = TaxProfile.all.order("order_by asc") customer = Customer.find(sale.customer_id) # #Creat new tax records - tax_profiles.each do |tax| - customer.tax_profiles.each do |cus_tax| - if cus_tax.to_i == tax.id - sale_tax = SaleTax.new(:sale => sale) - sale_tax.tax_name = tax.name - sale_tax.tax_rate = tax.rate + if sale.payment_status != 'foc' + tax_profiles.each do |tax| + customer.tax_profiles.each do |cus_tax| + if cus_tax.to_i == tax.id + sale_tax = SaleTax.new(:sale => sale) + sale_tax.tax_name = tax.name + sale_tax.tax_rate = tax.rate - # substract , to give after discount - total_tax = total_taxable - total_discount - #include or execulive - if tax.inclusive - rate = tax.rate - divided_value = (100 + rate)/rate - sale_tax.tax_payable_amount = total_tax / divided_value - else - sale_tax.tax_payable_amount = total_tax * tax.rate / 100 - total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount - end - #new taxable amount is standard rule for step by step - if shop.calc_tax_order - total_taxable = total_taxable + sale_tax.tax_payable_amount - end + # substract , to give after discount + total_tax = total_taxable - total_discount + #include or execulive + if tax.inclusive + rate = tax.rate + divided_value = (100 + rate)/rate + sale_tax.tax_payable_amount = total_tax / divided_value + else + sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount + end + #new taxable amount is standard rule for step by step + if shop.calc_tax_order + total_taxable = total_taxable + sale_tax.tax_payable_amount + end - sale_tax.inclusive = tax.inclusive - sale_tax.save + sale_tax.inclusive = tax.inclusive + sale_tax.save + end end end end - sale.total_tax = total_tax_amount end @@ -757,7 +758,7 @@ end def self.get_item_query() query = Sale.select("acc.title as account_name,mi.account_id, i.item_instance_code as item_code,i.account_id as account_id, " + "SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item,i.qty as qty," + - "i.remark as status_type,"+ + "i.status as status_type,"+ " i.unit_price,i.price as price,i.product_name as product_name, mc.name as" + " menu_category_name,mc.id as menu_category_id ") @@ -776,7 +777,7 @@ end def self.get_other_charges() query = Sale.select("i.account_id as account_id, " + "SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," + - "i.remark as status_type,"+ + "i.status as status_type,"+ " i.unit_price as unit_price,i.product_name as product_name") query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id") query = query.where("i.item_instance_code IS NULL AND i.product_code = 'Other Charges'") @@ -1227,7 +1228,7 @@ end def self.total_foc_items(today) query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + .where("sales.sale_status = 'completed' and a.status='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) .sum("a.qty") end diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index 465af104..64e0ec73 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -28,7 +28,7 @@ class SaleItem < ApplicationRecord def self.update_existing_item(qty, item, sale_id, type, item_price, price) # Original Item to add remark - item.remark = type + item.status = type item.save sale_item = SaleItem.new @@ -37,7 +37,7 @@ class SaleItem < ApplicationRecord sale_item.product_name = item.product_name + " (#{type.upcase})" sale_item.product_alt_name = item.product_alt_name sale_item.account_id = item.account_id - sale_item.remark = type + sale_item.status = type if type == "foc" || type == "promotion" || type == "void" sale_item.qty = qty * (-1) else @@ -99,7 +99,7 @@ class SaleItem < ApplicationRecord discount_account = {:name => a.title, :price => 0} # Check for actual sale items - sale_items.where("remark = 'Discount'").find_each do |si| + sale_items.where("status = 'Discount'").find_each do |si| if si.account_id == a.id discount_account[:price] = (discount_account[:price].abs + si.price.abs) * (1) end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 5b0da284..aff43626 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -194,7 +194,7 @@ class SalePayment < ApplicationRecord payment_status = false # add to sale item with foc - sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }' and remark is null") + sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }' and status is null") sale_items.each do|item| SaleItem.update_existing_item(item.qty, item, self.sale.sale_id, "foc", item.unit_price, item.price) diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index 72f4fd3c..51b1e717 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -38,7 +38,7 @@ <% @sale_data.sale_items.each do |sale_item| %> <% sub_total += sale_item.qty*sale_item.unit_price - if sale_item.price != 0 && sale_item.remark != "void" && sale_item.remark != "foc" + if sale_item.price != 0 && sale_item.status != "void" && sale_item.status != "foc" %>