From eedf6c39a1c33abb99fd6e516eb499a45734e8fc Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 23 Aug 2017 10:12:41 +0630 Subject: [PATCH] promotion + merge with master --- app/controllers/api/bill_controller.rb | 1 + app/models/promotion.rb | 3 +-- app/models/sale.rb | 24 ++++++++++++------------ app/views/origami/home/index.html.erb | 14 ++++++-------- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index eba40816..7ee80f00 100644 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -24,6 +24,7 @@ class Api::BillController < Api::ApiController @sale = Sale.new @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee, get_cashier) end + # Promotion.promo_activate(@sale) else @status = false @error_message = "No Current Open Shift" diff --git a/app/models/promotion.rb b/app/models/promotion.rb index 3b4b61ed..778f7638 100644 --- a/app/models/promotion.rb +++ b/app/models/promotion.rb @@ -10,8 +10,7 @@ class Promotion < ApplicationRecord PROMO_TYPE3 = "Net_price" PROMO_TYPE4 = "Percentage" - def self.promo_activate - saleObj = Sale.first # Test + def self.promo_activate(saleObj) current_day = Time.now.strftime("%Y-%m-%d") current_time = Time.now.strftime('%H:%M:%S') day = Date.today.wday diff --git a/app/models/sale.rb b/app/models/sale.rb index 71994ca1..9927251d 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -298,8 +298,8 @@ class Sale < ApplicationRecord 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 + 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 @@ -311,7 +311,7 @@ class Sale < ApplicationRecord rate = tax.rate divided_value = (100 + rate)/rate sale_tax.tax_payable_amount = total_tax / divided_value - else + else sale_tax.tax_payable_amount = total_tax * tax.rate / 100 total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount end @@ -319,7 +319,7 @@ class Sale < ApplicationRecord # total_taxable = total_taxable + sale_tax.tax_payable_amount sale_tax.inclusive = tax.inclusive - sale_tax.save + sale_tax.save end end end @@ -338,13 +338,13 @@ class Sale < ApplicationRecord total_tax_amount = 0 #tax_profile - list by order_by tax_profiles = TaxProfile.all.order("order_by asc") - - customer = Customer.find(self.customer_id) + customer = Customer.find(self.customer_id) + puts customer #Create new tax records tax_profiles.each do |tax| - customer.tax_profiles.each do |cus_tax| - if cus_tax.to_i == tax.id + customer.tax_profiles.each do |cus_tax| + if cus_tax.to_i == tax.id sale_tax = SaleTax.new(:sale => self) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate @@ -356,16 +356,16 @@ class Sale < ApplicationRecord rate = tax.rate divided_value = (100 + rate)/rate sale_tax.tax_payable_amount = total_tax / divided_value - else + 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 # total_taxable = total_taxable + sale_tax.tax_payable_amount sale_tax.inclusive = tax.inclusive - sale_tax.save + sale_tax.save end end end @@ -596,7 +596,7 @@ def self.get_item_query() query = query.joins(" JOIN accounts acc ON acc.id = mi.account_id") query = query.group('i.product_code ').order("mi.account_id, mi.menu_category_id") -end +end def self.get_by_shift_items(shift_sale_range, shift, from, to, status) # date_type_selection = get_sql_function_for_report_type(report_type) diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 05094504..2742f249 100644 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -108,17 +108,15 @@ - <%if current_login_employee.role == "cashier" && @shop.quick_sale_summary == true%> - - <%end%> + - - - <%if current_login_employee.role == "administrator" || current_login_employee.role == "manager" %> - <%end%> - +