fixed conflict

This commit is contained in:
Nweni
2019-12-09 16:29:09 +06:30
6 changed files with 77 additions and 44 deletions

View File

@@ -2,37 +2,43 @@ module NumberFormattable
extend ActiveSupport::Concern extend ActiveSupport::Concern
def precision def precision
@precision ||= Lookup.number_formats.find { |f| f.name.parameterize.underscore == 'precision'} return @precision if defined? @precision
@number_formats = Lookup.number_formats if !defined? @number_formats
if @number_formats
@precision = @number_formats.find? { |x| x.name.parameterize.underscore == 'precision'}.value.to_i rescue nil
end
if @precision.nil? if @precision.nil?
@print_settings ||= PrintSetting.get_precision_delimiter @print_settings = PrintSetting.get_precision_delimiter if !defined? @number_formats
if @print_settings if @print_settings
@precision = OpenStruct.new(value: @print_settings.precision.to_i) @precision = @print_settings.precision.to_i
else else
@precision = OpenStruct.new(value: 2) @precision = 2
end end
end end
@precison_value ||= @precision.value.to_i
end end
def delimiter def delimiter
@delimiter ||= Lookup.number_formats.find { |f| f.name.parameterize.underscore == 'delimiter'} return @delimiter if defined? @delimiter
@number_formats = Lookup.number_formats if !defined? @number_formats
if @number_formats
@delimiter = @number_formats.find { |f| f.name.parameterize.underscore == 'delimiter'}.value.gsub(/\\u(\h{4})/) { |m| [$1].pack("H*").unpack("n*").pack("U*") } rescue nil
end
if @delimiter.nil? if @delimiter.nil?
@print_settings ||= PrintSetting.get_precision_delimiter @print_settings = PrintSetting.get_precision_delimiter if !defined? @number_formats
if @print_settings && @print_settings.delimiter if @print_settings && @print_settings.delimiter
@delimiter = OpenStruct.new(value: ",") @delimiter = ","
else else
@delimiter = OpenStruct.new(value: "") @delimiter = ","
end end
end end
@delimiter_value ||= @delimiter.value.to_s.gsub(/\\u(\h{4})/) { |m| [$1].pack("H*").unpack("n*").pack("U*") }
end end
def strip_insignificant_zeros def strip_insignificant_zeros
@strip_insignificant_zeros ||= Lookup.number_formats.find { |f| f.name.parameterize.underscore == 'strip_insignificant_zeros'} return @strip_insignificant_zeros if defined? @strip_insignificant_zeros
if @strip_insignificant_zeros.nil? @number_formats = Lookup.number_formats if !defined? @number_formats
@strip_insignificant_zeros = OpenStruct.new(value: false) if @number_formats
@strip_insignificant_zeros = @number_formats.find { |f| f.name.parameterize.underscore == 'strip_insignificant_zeros'}.value.in? ['1', 't', 'true', 'on', 'y', 'yes'] rescue false
end end
@strip_insignificant_zeros_value ||= ['1', 't', 'true', 'on', 'y', 'yes'].include? @strip_insignificant_zeros.value.to_s
end end
def number_format(number, options = {}) def number_format(number, options = {})
@@ -40,14 +46,16 @@ module NumberFormattable
# options[:delimiter] = options[:delimiter] || delimiter # options[:delimiter] = options[:delimiter] || delimiter
options[:strip_insignificant_zeros] = options[:strip_insignificant_zeros] || strip_insignificant_zeros options[:strip_insignificant_zeros] = options[:strip_insignificant_zeros] || strip_insignificant_zeros
number = number.to_f.round(options[:precision])
if options[:precision] > 0 if options[:precision] > 0
if options[:strip_insignificant_zeros] if options[:strip_insignificant_zeros]
formatted = "%.12g" % number.round(options[:precision]) formatted = "%.12g" % number
else else
formatted = "%.#{options[:precision]}f" % number.round(options[:precision]) formatted = "%.#{options[:precision]}f" % number
end end
else else
formatted = number.round(options[:precision]).to_i.to_s formatted = number.to_i.to_s
end end
if options[:delimiter] && !options[:delimiter].empty? if options[:delimiter] && !options[:delimiter].empty?

View File

@@ -2,21 +2,20 @@ class Origami::DashboardController < BaseOrigamiController
def index def index
@shop = Shop.first @shop = Shop.first
today = DateTime.now.strftime('%Y-%m-%d')
@display_type = Lookup.find_by_lookup_type("display_type") @display_type = Lookup.find_by_lookup_type("display_type")
@sale_data = Array.new @sale_data = Array.new
@total_payment_methods = Sale.total_payment_methods(current_user) @total_payment_methods = Sale.total_payment_methods(current_user)
if !@total_payment_methods.nil? if !@total_payment_methods.nil?
@total_payment_methods.each do |payment| @total_payment_methods.each do |payment|
pay = Sale.payment_sale(payment.payment_method, current_user) pay = Sale.payment_sale(payment.payment_method, current_user)
@sale_data.push({payment.payment_method => pay.payment_amount}) @sale_data.push({payment.payment_method => pay.payment_amount})
end end
else else
@sale_data = nil @sale_data = nil
end end
@summ_sale = Sale.summary_sale_receipt(current_user) @summ_sale = Sale.summary_sale_receipt(current_user)
@total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(current_user,@from,@to) @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(current_user,@from,@to)
# @total_other_customer = Sale.total_other_customer(today,current_user) # @total_other_customer = Sale.total_other_customer(today,current_user)
@@ -25,13 +24,13 @@ class Origami::DashboardController < BaseOrigamiController
@total_accounts = Account.select("accounts.id as account_id, accounts.title as title") @total_accounts = Account.select("accounts.id as account_id, accounts.title as title")
@account_data = Array.new @account_data = Array.new
if !@total_accounts.nil? if !@total_accounts.nil?
@total_accounts.each do |account| @total_accounts.each do |account|
acc = Sale.account_data(account.account_id, current_user) acc = Sale.account_data(account.account_id, current_user)
if !acc.nil? if !acc.nil?
@account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc})
end
end end
@total_accounts = @total_accounts.reject.with_index { |x, i| @account_data[i].nil? } end
@total_accounts = @total_accounts.reject.with_index { |x, i| @account_data[i].nil? }
else else
@account_data = nil @account_data = nil
end end
@@ -100,7 +99,7 @@ class Origami::DashboardController < BaseOrigamiController
end end
def get_all_menu def get_all_menu
@menus = Menu.includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).includes(:menu_categories => {:menu_items => {:item_sets => :menu_item_instances}}).active.all @menus = Menu.includes(:menu_categories => :children).includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).includes(:menu_categories => {:menu_items => {:item_sets => :menu_item_instances}}).active.all
@item_attributes = MenuItemAttribute.all.load @item_attributes = MenuItemAttribute.all.load
@item_options = MenuItemOption.all.load @item_options = MenuItemOption.all.load
end end

View File

@@ -1583,6 +1583,8 @@ end
if !from.nil? && !to.nil? if !from.nil? && !to.nil?
query = query.receipt_date_between(from, to) query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1606,6 +1608,8 @@ end
if !from.nil? && !to.nil? if !from.nil? && !to.nil?
query = query.receipt_date_between(from, to) query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1637,6 +1641,8 @@ end
if (!from.nil? && !to.nil?) if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to) query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1654,6 +1660,8 @@ end
if (!from.nil? && !to.nil?) if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to) query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1675,6 +1683,8 @@ end
if (!from.nil? && !to.nil?) if (!from.nil? && !to.nil?)
query = query.merge(Sale.receipt_date_between(from, to)) query = query.merge(Sale.receipt_date_between(from, to))
else
query = query.merge(Sale.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day))
end end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1692,6 +1702,8 @@ end
if (!from.nil? && !to.nil?) if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to) query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1711,6 +1723,8 @@ end
if (!from.nil? && !to.nil?) if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to) query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1738,6 +1752,8 @@ end
if (!from.nil? && !to.nil?) if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to) query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1784,6 +1800,8 @@ end
if (!from.nil? && !to.nil?) if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to) query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1802,6 +1820,8 @@ end
if (!from.nil? && !to.nil?) if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to) query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1866,6 +1886,8 @@ end
if (!from.nil? && !to.nil?) if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to) query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1884,6 +1906,8 @@ end
if (!from.nil? && !to.nil?) if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to) query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1902,6 +1926,8 @@ end
if (!from.nil? && !to.nil?) if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to) query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1921,6 +1947,8 @@ end
if (!from.nil? && !to.nil?) if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to) query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -2073,6 +2101,8 @@ def self.employee_sale(shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
.paid.completed .paid.completed
if !from.nil? && !to.nil? if !from.nil? && !to.nil?
query = query.receipt_date_between(from, to) query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
end end
if !shift.nil? if !shift.nil?

View File

@@ -398,11 +398,12 @@ class SaleItem < ApplicationRecord
stock = StockJournal.where('item_code=?', self.item_instance_code).order("id DESC").first stock = StockJournal.where('item_code=?', self.item_instance_code).order("id DESC").first
unless stock.nil? unless stock.nil?
check_item = StockCheckItem.where('item_code=?', self.item_instance_code).order("id DESC").first check_item = StockCheckItem.where('item_code=?', self.item_instance_code).order("id DESC").first
StockJournal.add_to_journal(self.item_instance_code, qty, stock.balance, remark, inventory_definition, self.id, StockJournal::SALES_TRANS)
check_item.different = check_item.different + qty
check_item.save
end end
end end
StockJournal.add_to_journal(self.item_instance_code, qty, stock.balance, remark, inventory_definition, self.id, StockJournal::SALES_TRANS)
check_item.different = check_item.different + qty
check_item.save
elsif is_foc or cancel_foc elsif is_foc or cancel_foc
qty = StockJournal.where(trans_ref: self.sale_item_id).sum("credit-debit") qty = StockJournal.where(trans_ref: self.sale_item_id).sum("credit-debit")
if stock_journal = StockJournal.where(trans_ref: self.sale_item_id, item_code: self.item_instance_code).order(id: :desc).first if stock_journal = StockJournal.where(trans_ref: self.sale_item_id, item_code: self.item_instance_code).order(id: :desc).first

View File

@@ -344,14 +344,14 @@ class ReceiptBillPdf < Prawn::Document
sale_data.sale_taxes.each do |st| sale_data.sale_taxes.each do |st|
if (st.tax_name.include? "Service") if (st.tax_name.include? "Service")
service_tax_desc = st.tax_name service_tax_desc = st.tax_name
service_tax_amount = number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter) service_tax_amount = st.tax_payable_amount
if incl_tax if incl_tax
service_tax_rate = st.tax_rate.to_i service_tax_rate = st.tax_rate.to_i
end end
end end
if (st.tax_name.include? "Commercial") if (st.tax_name.include? "Commercial")
com_tax_desc = st.tax_name com_tax_desc = st.tax_name
com_tax_amount = number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter) com_tax_amount = st.tax_payable_amount
if incl_tax if incl_tax
com_tax_rate = st.tax_rate.to_i com_tax_rate = st.tax_rate.to_i
end end

View File

@@ -15,15 +15,10 @@ if (menu.menu_categories)
categories = menu.menu_categories categories = menu.menu_categories
json.categories categories do |category| json.categories categories do |category|
if category.is_available if category.is_available
parent_category = category.parent json.sub_category category.children.present?
if !parent_category.nil?
json.sub_category "true"
else
json.sub_category "false"
end
valid_time = category.valid_time valid_time = category.valid_time
json.valid_time valid_time json.valid_time valid_time
json.id category.id json.id category.id
json.code category.code json.code category.code
json.order_by category.order_by json.order_by category.order_by
@@ -80,7 +75,7 @@ if (menu.menu_categories)
alt_name: its.alt_name, alt_name: its.alt_name,
min_selectable_qty: its.min_selectable_qty, min_selectable_qty: its.min_selectable_qty,
max_selectable_qty: its.max_selectable_qty, max_selectable_qty: its.max_selectable_qty,
instances: its.menu_item_instances.map { |id| {id: id}} instances: its.menu_item_instances.map { |i| {id: i.id} }
} }
} }