diff --git a/app/controllers/concerns/license_verification.rb b/app/controllers/concerns/license_verification.rb index bfa40f03..94e9ad91 100644 --- a/app/controllers/concerns/license_verification.rb +++ b/app/controllers/concerns/license_verification.rb @@ -13,7 +13,7 @@ module LicenseVerification if (!@license.nil?) # logger.info "Location - " + @license.name ActiveRecord::Base.establish_connection(website_connection(@license)) - authenticate_session_token + # authenticate_session_token # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema else # reconnect_default_db @@ -29,6 +29,7 @@ module LicenseVerification # redirect_to activate_path # end end + authenticate_session_token end def authenticate_session_token @@ -38,8 +39,12 @@ module LicenseVerification #Rails.logger.debug "token - " + token.to_s @user = Employee.authenticate_by_token(token) - if !@user + if @user + return true + #Maybe log - login? + else flash[:notice] = 'Invalid Access!' + # return false end end end diff --git a/app/controllers/concerns/login_verification.rb b/app/controllers/concerns/login_verification.rb index 7ddf3cec..aa9d8319 100755 --- a/app/controllers/concerns/login_verification.rb +++ b/app/controllers/concerns/login_verification.rb @@ -2,10 +2,25 @@ module LoginVerification extend ActiveSupport::Concern included do - before_action :authenticate + before_action :authenticate_session_token helper_method :current_company,:current_login_employee end + #this is base api base controller to need to inherit. + #all token authentication must be done here + #response format must be set to JSON + def current_company + begin + return Company.first + rescue + return nil + end + + end + + def current_login_employee + @employee = Employee.find_by_token_session(session[:session_token]) + end protected # Authenticate the user with token based authentication @@ -25,6 +40,7 @@ module LoginVerification #Maybe log - login? else flash[:notice] = 'Invalid Access!' + # return false end end end @@ -33,23 +49,6 @@ module LoginVerification redirect_to root_path end - - #this is base api base controller to need to inherit. - #all token authentication must be done here - #response format must be set to JSON - def current_company - begin - return Company.first - rescue - return nil - end - - end - - def current_login_employee - @employee = Employee.find_by_token_session(session[:session_token]) - end - private def check_license License.check_license_file diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 1ba21a5a..600801a8 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -5,7 +5,7 @@ class HomeController < ApplicationController def index # @employees = Employee.all_emp_except_waiter.order("name asc") @employees = Employee.all.order("name asc") - @login_form = LoginForm.new() + @login_form = LoginForm.new() render "layouts/login_dashboard", layout: false end @@ -59,7 +59,7 @@ class HomeController < ApplicationController render :index end else - redirect_to origami_root_path, :notice => "Username and Password doesn't match!" + redirect_to root_path, :notice => "Username and Password doesn't match!" end end diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 46dd65d0..24b2c83f 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -52,7 +52,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) @@ -175,7 +175,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 @@ -343,7 +343,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 d15edb5e..93afc99a 100755 --- a/app/controllers/origami/other_charges_controller.rb +++ b/app/controllers/origami/other_charges_controller.rb @@ -44,7 +44,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 404f8c6b..fa7e5914 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -357,12 +357,13 @@ 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 9c9d98d6..44ec6442 100755 --- a/app/controllers/origami/sale_edit_controller.rb +++ b/app/controllers/origami/sale_edit_controller.rb @@ -16,8 +16,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 @@ -27,6 +29,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 @@ -54,8 +57,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 @@ -65,6 +70,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 @@ -83,7 +89,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 @@ -147,7 +153,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 @@ -172,7 +178,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 8ae6656d..ccc06510 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -97,7 +97,6 @@ class Sale < ApplicationRecord else self.shift_sale_id = current_shift.id end - else self.cashier_id = current_shift.employee_id self.cashier_name = Employee.find(current_shift.employee_id).name @@ -232,7 +231,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 @@ -260,7 +259,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"] @@ -386,7 +385,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 @@ -422,35 +421,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 @@ -762,7 +762,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 ") @@ -781,7 +781,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'") @@ -1232,7 +1232,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 ee5a6a17..bb74c2f2 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 ba03f8d7..7d45fd7c 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -44,7 +44,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" %>