diff --git a/Gemfile b/Gemfile index 479221f0..e0d9e933 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,5 @@ source 'https://rubygems.org' - ruby '2.4.1' #ruby '2.5.7' diff --git a/Gemfile.lock b/Gemfile.lock index 9c92b6e0..633b5965 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -374,5 +374,10 @@ DEPENDENCIES web-console (>= 3.3.0) whenever + +RUBY VERSION + ruby 2.4.1p111 + + BUNDLED WITH 2.0.2 diff --git a/README.md b/README.md index 4d81b144..54474f5e 100755 --- a/README.md +++ b/README.md @@ -279,6 +279,15 @@ For Food Court Settings On/Off ** '0' means can not use food court and '1' means can use food court ** => settings/lookups => { type:food_court, name: FoodCourt, value:'{0 or 1}' } +For Number Formats + Precision + => settings/lookups => { lookup_type: number_format, name: precision, value: {0..2} } + Delimiter + => settings/lookups => { lookup_type: number_format, name: delimiter, value: { ',', '\u0020', '', ... } + Strip insignificant zeros + => settings/lookups => { lookup_type: number_format, name: strip_insignificant_zeros, + value: {true: => ['1', 't', 'true', 'on', 'y', 'yes'], false: => ['0', 'f', 'false', 'off', 'n', 'no', ...] } + /* Customer Types in lookups */ 1) settings/lookups => { type:customer_type, name: Dinein, value:Dinein } 2) settings/lookups => { type:customer_type, name: Takeaway, value: Takeaway } @@ -299,6 +308,9 @@ settings/lookups => {type:display_type, name: Display Type, value: 2} For show total before tax in receipt bill settings/lookups => {type:show_total_before_tax, name:Show Total Before Tax, value: {0 or 1}} +For Using Staff Meal +settings/lookups => { type:customer_type, name: Staff, value:Staff } + * ToDo list 1. Migration diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f1d5f79a..66f20c55 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,6 @@ class ApplicationController < ActionController::Base include LoginVerification - + #before_action :check_installation protect_from_forgery with: :exception @@ -17,7 +17,5 @@ class ApplicationController < ActionController::Base flash[:warning] = exception.message redirect_to root_path end + end - - - diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb index dc93b2de..6940a129 100755 --- a/app/controllers/base_origami_controller.rb +++ b/app/controllers/base_origami_controller.rb @@ -5,7 +5,7 @@ class BaseOrigamiController < ActionController::Base before_action :check_user #before_action :check_installation - protect_from_forgery with: :exception + protect_from_forgery with: :exception helper_method :current_token @@ -15,16 +15,16 @@ class BaseOrigamiController < ActionController::Base redirect_to origami_dashboard_path end - def check_user - if check_mobile + def check_user + if check_mobile if current_user.nil? return render status: 401, json: { - message: "User using other device!" + message: "User using other device!" }.to_json end - else + else if current_user.nil? - redirect_to root_path + redirect_to root_path end end end @@ -41,13 +41,13 @@ class BaseOrigamiController < ActionController::Base #check webview def check_mobile status = false - authenticate_with_http_token do |token, options| + authenticate_with_http_token do |token, options| if token session[:webview] = true session[:session_token] = token - end + end end - + if session[:webview] && request.user_agent =~ /android|blackberry|iphone|ipad|ipod|iemobile|mobile|webos/i status = true end diff --git a/app/controllers/base_report_controller.rb b/app/controllers/base_report_controller.rb index 0875fda5..691ece34 100755 --- a/app/controllers/base_report_controller.rb +++ b/app/controllers/base_report_controller.rb @@ -1,11 +1,11 @@ class BaseReportController < ActionController::Base include LoginVerification - layout "application" + layout "application" - before_action :check_user + before_action :check_user - #before_action :check_installation - protect_from_forgery with: :exception + #before_action :check_installation + protect_from_forgery with: :exception rescue_from CanCan::AccessDenied do |exception| flash[:warning] = exception.message @@ -26,61 +26,51 @@ class BaseReportController < ActionController::Base } def get_date_range_from_params - period_type = params[:period_type] - period = params[:period] - from = params[:from] - to = params[:to] - day_ref = Time.now.utc.getlocal + period_type = params[:period_type] + period = params[:period] - if from.present? && to.present? + if params[:from].present? && params[:to].present? + from = Time.parse(params[:from]) + to = Time.parse(params[:to]) + else + case period.to_i + when PERIOD["today"] + from = Time.now + to = Time.now + when PERIOD["yesterday"] + from = 1.day.ago + to = 1.day.ago + when PERIOD["this_week"] + from = Time.now.beginning_of_week + to = Time.now + when PERIOD["last_week"] + from = 1.week.ago.beginning_of_week + to = 1.week.ago.end_of_week + when PERIOD["last_7"] + from = 7.day.ago + to = Time.now + when PERIOD["this_month"] + from = Time.now.beginning_of_month + to = Time.now + when PERIOD["last_month"] + from = 1.month.ago.beginning_of_month + to = 1.month.ago.end_of_month + when PERIOD["last_30"] + from = 30.day.ago + to = Time.now + when PERIOD["this_year"] + from = Time.now.beginning_of_year + to = Time.now + when PERIOD["last_year"] + from = 1.year.ago.beginning_of_year + to = 1.year.ago.end_of_year + end + end - f_date = DateTime.parse(from) - t_date = DateTime.parse(to) - f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) - t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) - from = f_time.beginning_of_day.utc.getlocal - to = t_time.end_of_day.utc.getlocal - - else - - case period.to_i - when PERIOD["today"] - - from = day_ref.beginning_of_day.utc - to = day_ref.end_of_day.utc - - when PERIOD["yesterday"] - from = (day_ref - 1.day).beginning_of_day.utc - to = (day_ref - 1.day).end_of_day.utc - - when PERIOD["this_week"] - from = Time.now.beginning_of_week.utc - to = Time.now.utc - when PERIOD["last_week"] - from = (day_ref - 7.day).beginning_of_week.utc - to = (day_ref - 7.day).end_of_week.utc - when PERIOD["last_7"] - from = (day_ref - 7.day).utc - to = Time.now.utc - when PERIOD["this_month"] - from = Time.now.beginning_of_month.utc - to = Time.now.utc - when PERIOD["last_month"] - from = (day_ref - 1.month).beginning_of_month.utc - to = (day_ref - 1.month).end_of_month.utc - when PERIOD["last_30"] - from = (day_ref - 30.day).utc - to = Time.now.utc - when PERIOD["this_year"] - from = Time.now.beginning_of_year.utc - to = Time.now.utc - when PERIOD["last_year"] - from = (day_ref - 1.year).beginning_of_year.utc - to = (day_ref - 1.year).end_of_year.utc - end - end - - return from, to + from = from.beginning_of_day + to = to.end_of_day + + return from, to end def check_user diff --git a/app/controllers/concerns/number_formattable.rb b/app/controllers/concerns/number_formattable.rb new file mode 100644 index 00000000..a7b97732 --- /dev/null +++ b/app/controllers/concerns/number_formattable.rb @@ -0,0 +1,60 @@ +module NumberFormattable + extend ActiveSupport::Concern + + def precision + @precision ||= Lookup.number_formats.find { |f| f.name.parameterize.underscore == 'precision'} + if @precision.nil? + @print_settings ||= PrintSetting.get_precision_delimiter + if @print_settings + @precision = OpenStruct.new(value: @print_settings.precision.to_i) + else + @precision = OpenStruct.new(value: 2) + end + end + @precison_value ||= @precision.value.to_i + end + + def delimiter + @delimiter ||= Lookup.number_formats.find { |f| f.name.parameterize.underscore == 'delimiter'} + if @delimiter.nil? + @print_settings ||= PrintSetting.get_precision_delimiter + if @print_settings && @print_settings.delimiter + @delimiter = OpenStruct.new(value: ",") + else + @delimiter = OpenStruct.new(value: "") + end + end + @delimiter_value ||= @delimiter.value.to_s.gsub(/\\u(\h{4})/) { |m| [$1].pack("H*").unpack("n*").pack("U*") } + end + + def strip_insignificant_zeros + @strip_insignificant_zeros ||= Lookup.number_formats.find { |f| f.name.parameterize.underscore == 'strip_insignificant_zeros'} + if @strip_insignificant_zeros.nil? + @strip_insignificant_zeros = OpenStruct.new(value: false) + end + @strip_insignificant_zeros_value ||= ['1', 't', 'true', 'on', 'y', 'yes'].include? @strip_insignificant_zeros.value.to_s + end + + def number_format(number, options = {}) + options[:precision] = options[:precision] || precision + # options[:delimiter] = options[:delimiter] || delimiter + options[:strip_insignificant_zeros] = options[:strip_insignificant_zeros] || strip_insignificant_zeros + + if options[:precision] > 0 + if options[:strip_insignificant_zeros] + formatted = "%.12g" % number.round(options[:precision]) + else + formatted = "%.#{options[:precision]}f" % number.round(options[:precision]) + end + else + formatted = number.round(options[:precision]).to_i.to_s + end + + if options[:delimiter] && !options[:delimiter].empty? + formatted = formatted.gsub(/(\d)(?=\d{3}+(\.\d*)?$)/, "\\1#{options[:delimiter]}") + end + + return formatted + end + +end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 49b4ff5d..a82a6483 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -89,37 +89,28 @@ class HomeController < ApplicationController end def dashboard - @from, @to, @from_time, @to_time = get_date_range_from_params + @from, @to = get_date_range_from_params @shop = Shop.first - today = DateTime.now.strftime('%Y-%m-%d') - if !@from.nil? && !@to.nil? - if !@from_time.nil? && @to_time.nil? - @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count() - else - @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() + @orders = Sale.receipt_date_between(@from, @to).where("payment_status = 'new' and sale_status = 'bill'") + @sales = Sale.receipt_date_between(@from, @to).completed + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + @orders = @orders.where(shift_sale_id: shift.id) + @sales = @sales.where(shift_sale_id: shift.id) end - else - @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() end - if !@from.nil? && !@to.nil? - if !@from_time.nil? && @to_time.nil? - @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count() - else - @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() - end - else - @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() - end - @top_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"top").sum('i.qty') - @bottom_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"bottom").sum('i.qty') - @hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time).sum(:grand_total) + + @top_products = Sale.top_bottom_products(current_user,@from,@to,"top") + @bottom_products = Sale.top_bottom_products(current_user,@from,@to,"bottom") + @hourly_sales = Sale.hourly_sales(current_user,@from,@to) # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') # .sum(:grand_total) logger.debug 'hourly_sales<>><><><<<<<<>><<<><><><><><><><><><<>><' - logger.debug @hourly_sales.to_json - employee_sales = Sale.employee_sales(today,current_user,@from,@to,@from_time,@to_time) + logger.debug @hourly_sales.to_json + employee_sales = Sale.employee_sales(current_user,@from,@to) # .sum("(CASE WHEN sp.payment_method='cash' THEN ((sp.payment_amount) - (sales.amount_changed)) ELSE (sp.payment_amount) END)") @employee_sales = [] if !employee_sales.nil? @@ -132,44 +123,41 @@ class HomeController < ApplicationController end end end - @inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time).sum(:balance) + @inventories = StockJournal.inventory_balances(@from,@to).sum(:balance) - @total_trans = Sale.total_trans(today,current_user,@from,@to,@from_time,@to_time) - @total_card = Sale.total_card_sale(today,current_user,@from,@to,@from_time,@to_time) - @total_credit = Sale.credit_payment(today,current_user,@from,@to,@from_time,@to_time) + @total_trans = Sale.total_trans(current_user,@from,@to) + @total_card = Sale.total_card_sale(current_user,@from,@to) + @total_credit = Sale.credit_payment(current_user,@from,@to) @sale_data = Array.new - @total_payment_methods = Sale.total_payment_methods(today,current_user,@from,@to,@from_time,@to_time) + @total_payment_methods = Sale.total_payment_methods(current_user,@from,@to) if !@total_payment_methods.nil? @total_payment_methods.each do |payment| - if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay" || payment.payment_method == "alipay" - pay = Sale.payment_sale('card', today, current_user,@from,@to,@from_time,@to_time) - @sale_data.push({'card' => pay.payment_amount}) - else - pay = Sale.payment_sale(payment.payment_method, today, current_user,@from,@to,@from_time,@to_time) - @sale_data.push({payment.payment_method => pay.payment_amount}) - end + pay = Sale.payment_sale(payment.payment_method, current_user,@from,@to) + @sale_data.push({payment.payment_method => pay.payment_amount}) end end - @summ_sale = Sale.summary_sale_receipt(today,current_user,@from,@to,@from_time,@to_time) - @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(today,current_user,@from,@to,@from_time,@to_time) + + @summ_sale = Sale.summary_sale_receipt(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_order = Sale.total_order(today,current_user,@from,@to,@from_time,@to_time) - @total_accounts = Sale.total_account(today,current_user,@from,@to,@from_time,@to_time) + @total_order = Sale.total_order(current_user,@from,@to) + @total_accounts = Account.select("accounts.id as account_id, accounts.title as title") @account_data = Array.new if !@total_accounts.nil? @total_accounts.each do |account| - acc = Sale.account_data(account.account_id, today,current_user,@from,@to,@from_time,@to_time) - if !acc.nil? + acc = Sale.account_data(account.account_id,current_user,@from,@to) + if !acc.nil? && acc.cnt_acc > 0 @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) end end + @total_accounts = @total_accounts.reject.with_index { |x, i| @account_data[i].nil? } end - @top_items = Sale.top_items(today,current_user,@from,@to,@from_time,@to_time) - @total_foc_items = Sale.total_foc_items(today,current_user,@from,@to,@from_time,@to_time) + @top_items = Sale.top_items(current_user,@from,@to) + @total_foc_items = Sale.total_foc_items(current_user,@from,@to) # get printer info @print_settings = PrintSetting.get_precision_delimiter() @@ -231,23 +219,18 @@ class HomeController < ApplicationController end def get_date_range_from_params - from = params[:from] - to = params[:to] - from_time = params[:from_time] - to_time = params[:to_time] - - if from.present? && to.present? - # f_date = DateTime.parse(from) - # t_date = DateTime.parse(to) - # f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) - # t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) - # from = f_time.beginning_of_day.utc.getlocal - # to = t_time.end_of_day.utc.getlocal - - from = DateTime.parse(from).utc.getlocal.strftime('%Y-%m-%d') - to = DateTime.parse(to).utc.getlocal.strftime('%Y-%m-%d') + if params[:from].present? && params[:to].present? + if params[:from_time].present? && params[:to_time].present? + from = Time.parse("#{params[:from]} #{params[:from_time]}") + to = Time.parse("#{params[:to]} #{params[:to_time]}") + else + from = Time.parse(params[:from]) + to = Time.parse(params[:to]).end_of_day end - - return from, to, from_time, to_time + else + from = Time.now.beginning_of_day + to = Time.now.end_of_day + end + return from, to end end diff --git a/app/controllers/origami/dashboard_controller.rb b/app/controllers/origami/dashboard_controller.rb index 7ccac407..00766d51 100644 --- a/app/controllers/origami/dashboard_controller.rb +++ b/app/controllers/origami/dashboard_controller.rb @@ -2,46 +2,42 @@ class Origami::DashboardController < BaseOrigamiController def index @shop = Shop.first - + today = DateTime.now.strftime('%Y-%m-%d') @display_type = Lookup.find_by_lookup_type("display_type") @sale_data = Array.new - @total_payment_methods = Sale.total_payment_methods(today,current_user) + @total_payment_methods = Sale.total_payment_methods(current_user) if !@total_payment_methods.nil? @total_payment_methods.each do |payment| - if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay" || payment.payment_method == "alipay" - pay = Sale.payment_sale('card', today, current_user) - @sale_data.push({'card' => pay.payment_amount}) - else - pay = Sale.payment_sale(payment.payment_method, today, current_user) - @sale_data.push({payment.payment_method => pay.payment_amount}) - end + pay = Sale.payment_sale(payment.payment_method, current_user) + @sale_data.push({payment.payment_method => pay.payment_amount}) end else @sale_data = nil end - @summ_sale = Sale.summary_sale_receipt(today,current_user) - @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(today,current_user,@from,@to,@from_time,@to_time) + @summ_sale = Sale.summary_sale_receipt(current_user) + @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_order = Sale.total_order(today,current_user) - @total_accounts = Sale.total_account(today,current_user) + @total_order = Sale.total_order(current_user) + @total_accounts = Account.select("accounts.id as account_id, accounts.title as title") @account_data = Array.new if !@total_accounts.nil? @total_accounts.each do |account| - acc = Sale.account_data(account.account_id, today,current_user) + acc = Sale.account_data(account.account_id, current_user) if !acc.nil? @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) end end + @total_accounts = @total_accounts.reject.with_index { |x, i| @account_data[i].nil? } else @account_data = nil end - @top_items = Sale.top_items(today,current_user) - @total_foc_items = Sale.total_foc_items(today,current_user) + @top_items = Sale.top_items(current_user) + @total_foc_items = Sale.total_foc_items(current_user) # get printer info @print_settings = PrintSetting.get_precision_delimiter() @@ -104,7 +100,9 @@ class Origami::DashboardController < BaseOrigamiController end def get_all_menu - @menus = Menu.active.all + @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 + @item_attributes = MenuItemAttribute.all.load + @item_options = MenuItemOption.all.load end def get_credit_sales diff --git a/app/controllers/origami/sale_edit_controller.rb b/app/controllers/origami/sale_edit_controller.rb index 7f456f35..363791a8 100755 --- a/app/controllers/origami/sale_edit_controller.rb +++ b/app/controllers/origami/sale_edit_controller.rb @@ -163,7 +163,7 @@ class Origami::SaleEditController < BaseOrigamiController # end # end - sale.compute_by_sale_items(saleObj.total_discount, nil, order_source) + # sale.compute_by_sale_items(saleObj.total_discount, nil, order_source) FOR WHAT???? ProductCommission.edit_product_commission(saleitemObj) end @@ -195,7 +195,7 @@ class Origami::SaleEditController < BaseOrigamiController end remark = "Cancle Void Sale Item ID #{saleitemObj.sale_item_id} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}|Receipt No #{saleObj.receipt_no}" sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"ITEMCANCELVOID" ) - + saleObj.compute_by_sale_items(saleObj.total_discount, nil, order_source) ProductCommission.remove_product_commission(saleitemObj) end diff --git a/app/controllers/reports/receipt_no_detail_controller.rb b/app/controllers/reports/receipt_no_detail_controller.rb index d7b018d7..b6e8bb16 100755 --- a/app/controllers/reports/receipt_no_detail_controller.rb +++ b/app/controllers/reports/receipt_no_detail_controller.rb @@ -1,4 +1,4 @@ -class Reports::ReceiptNoDetailController < BaseReportController +class Reports::ReceiptNoDetailController < BaseReportController authorize_resource :class => false def index @payments = [["All Payment",''], ["Cash Payment","cash"], ["Credit Payment","creditnote"], ["FOC Payment","foc"]] @@ -9,11 +9,10 @@ authorize_resource :class => false @shift = '' if params[:shift_name].to_i != 0 - @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @shift_sale = ShiftSale.find(params[:shift_name]) - if to.blank? + if to.blank? @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',@shift_sale.shift_started_at) else if @shift_sale.shift_closed_at.blank? @@ -25,7 +24,7 @@ authorize_resource :class => false end payment_type = params[:payment_type] - @sale_data = Sale.get_shift_sales_by_receipt_no_detail(@shift_sale_range,@shift,from,to,payment_type) + @sale_data = Sale.get_shift_sales_by_receipt_no_detail(@shift_sale_range,@shift,from,to,payment_type) @from = from @to = to @@ -62,10 +61,10 @@ authorize_resource :class => false end out = {:status => 'ok', :message => date_arr} - + respond_to do |format| format.json { render json: out } end end - -end \ No newline at end of file + +end diff --git a/app/controllers/reports/staff_meal_controller.rb b/app/controllers/reports/staff_meal_controller.rb new file mode 100644 index 00000000..b0a8b4d2 --- /dev/null +++ b/app/controllers/reports/staff_meal_controller.rb @@ -0,0 +1,133 @@ +class Reports::StaffMealController < BaseReportController + authorize_resource :class => false + def index + + @account = Account.all + from, to = get_date_range_from_params + + shift_sale_range = '' + + shift = '' + if params[:shift_name].to_i != 0 + + shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + + shift_sale = ShiftSale.find(params[:shift_name]) + if to.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) + else + if shift_sale.shift_closed_at.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',shift_sale.shift_started_at) + else + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) + end + end + end + + staff = Customer.where(customer_type: 'staff') + customer_id = Array.new + staff.each { |s| + customer_id.push(s.customer_id) + } + + account_type = params[:account_type] + + @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_staff_meal_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,account_type,customer_id) + + @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) + + @account_cate_count = Hash.new {|hash, key| hash[key] = 0} + @sale_data.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1} + + + @menu_cate_count = Hash.new {|hash, key| hash[key] = 0} + @sale_data.each {|cate| @menu_cate_count[cate.account_id] += 1} + + + @totalByAccount = Hash.new {|hash, key| hash[key] = 0} + @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} + + @from = from + @to = to + + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + + if shift.present? + shift.each do |sh| + @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_data = sh + end + end + respond_to do |format| + format.html + format.xls + end + end + + def show + from, to, report_type = get_date_range_from_params + @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + + date_arr = Array.new + @sale_data.each do |sale| + local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") + local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") + opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc + closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc + shift_id = sale.id.nil? ? '-' : sale.id + str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} + date_arr.push(str) + end + + # @totalByAccount = Hash.new {|hash, key| hash[key] = 0} + # @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} + + out = {:status => 'ok', :message => date_arr} + + respond_to do |format| + format.json { render json: out } + end + end + + def get_period_name(period) + period_name = '-' + unless period.nil? or period.blank? + case period.to_i + when PERIOD["today"] + period_name = "Today" + + when PERIOD["yesterday"] + period_name = "Yesterday" + + when PERIOD["this_week"] + period_name = "This Week" + + when PERIOD["last_week"] + period_name = "Last Week" + + when PERIOD["last_7"] + period_name = "Last 7 days" + + when PERIOD["this_month"] + period_name = "This Month" + + when PERIOD["last_month"] + period_name = "Last Month" + + when PERIOD["last_30"] + period_name = "Last 30 Days" + + when PERIOD["this_year"] + period_name = "This Year" + + when PERIOD["last_year"] + period_name = "Last Year" + + end + end + return period_name + end + +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 27024d75..16e44953 100755 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,6 @@ module ApplicationHelper + include NumberFormattable + def flash_class(level) case level when :notice then "alert alert-info fade-in" @@ -6,5 +8,6 @@ module ApplicationHelper when :error then "alert alert-error fade-in" when :alert then "alert alert-error fade-in" end - end + end + end diff --git a/app/models/inventory_definition.rb b/app/models/inventory_definition.rb index 4ff649e0..fb247805 100755 --- a/app/models/inventory_definition.rb +++ b/app/models/inventory_definition.rb @@ -32,13 +32,12 @@ class InventoryDefinition < ApplicationRecord end def self.check_balance(item, inventory_definition) # item => saleItemOBj - stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first - unless stock.nil? - modify_balance(item, stock, inventory_definition) - else - puts "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< OUT OF STOCK >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" - StockJournal.add_to_journal(item.item_instance_code, item.qty, 0, "out of stock", inventory_definition, item.id, StockJournal::SALES_TRANS) - end + stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first + unless stock.nil? + modify_balance(item, stock, inventory_definition) + else + StockJournal.add_to_journal(item.item_instance_code, item.qty, 0, "out of stock", inventory_definition, item.id, StockJournal::SALES_TRANS) + end end def self.modify_balance(item, stock, inventory_definition) #saleitemObj @@ -63,6 +62,7 @@ class InventoryDefinition < ApplicationRecord elsif item.is_a? SaleItem trans_type = StockJournal::SALES_TRANS end + # StockJournal.add_to_journal(instance_code, qty, stock.balance, remark, inventory_definition, item.id, trans_type) StockJournal.add_to_journal(item.item_instance_code, qty, stock.balance, remark, inventory_definition, item.id, trans_type) check_item.different = check_item.different - qty check_item.save diff --git a/app/models/lookup.rb b/app/models/lookup.rb index b446d4e8..5b45822c 100755 --- a/app/models/lookup.rb +++ b/app/models/lookup.rb @@ -2,6 +2,8 @@ class Lookup < ApplicationRecord has_many :accounts + scope :number_formats, -> { where(lookup_type: 'number_format')} + def available_types {'Employee Roles' => 'employee_roles', 'Dining Facilities Status' => 'dining_facilities_status', diff --git a/app/models/menu_category.rb b/app/models/menu_category.rb index 746bcb79..d8597afa 100755 --- a/app/models/menu_category.rb +++ b/app/models/menu_category.rb @@ -1,7 +1,7 @@ -class MenuCategory < ApplicationRecord +class MenuCategory < ApplicationRecord # before_create :generate_menu_category_code - belongs_to :menu + belongs_to :menu has_many :children, :class_name => "MenuCategory", foreign_key: "menu_category_id" belongs_to :parent, :class_name => "MenuCategory", foreign_key: "menu_category_id", optional: true has_many :menu_items @@ -38,9 +38,7 @@ class MenuCategory < ApplicationRecord end def valid_time - - menu_category = MenuCategory.find(self.id) - menu = Menu.find(menu_category.menu_id) + menu = self.menu from_t = Time.parse(menu.valid_time_from.strftime("%H:%M:%S")) to_t = Time.parse(menu.valid_time_to.strftime("%H:%M:%S")) @@ -64,7 +62,7 @@ class MenuCategory < ApplicationRecord c +=24 current = c*3600 + current_t.min* 60 + current_t.sec - + end end else # (after) noon @@ -77,8 +75,8 @@ class MenuCategory < ApplicationRecord day = Date.today.wday dayresult = menu.valid_days.include?(day.to_s) - - + + if current.between?(from, to) && menu.valid_days.include?(day.to_s) return true else @@ -104,12 +102,12 @@ class MenuCategory < ApplicationRecord private - # def generate_menu_category_code - # self.code = SeedGenerator.generate_code(self.class.name, "C") + # def generate_menu_category_code + # self.code = SeedGenerator.generate_code(self.class.name, "C") # end def self.to_csv - + mc_attributes = %w{id menu_id code name alt_name order_by created_by menu_category_id is_available created_at updated_at} CSV.generate(headers: true) do |csv| csv << mc_attributes @@ -123,7 +121,3 @@ class MenuCategory < ApplicationRecord end end - - - - diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index 03e90011..59791cb2 100755 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -11,11 +11,11 @@ class MenuItem < ApplicationRecord belongs_to :account has_many :menu_item_sets - has_many :item_sets, through: :menu_item_sets + has_and_belongs_to_many :item_sets, join_table: "menu_item_sets" validates_presence_of :item_code, :name, :type, :min_qty,:account_id validates_uniqueness_of :item_code - + default_scope { order('item_code asc') } scope :simple_menu_item, -> { where(type: 'SimpleMenuItem') } diff --git a/app/models/order_item.rb b/app/models/order_item.rb index f265be2b..3e75ecba 100755 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -125,32 +125,13 @@ class OrderItem < ApplicationRecord end def update_stock_journal - if self.qty != self.qty_before_last_save - found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) - if found - InventoryDefinition.check_balance(self, inventory_definition) + unless MenuItemInstance.where("item_instance_name <> ''").pluck(:item_instance_code).include?(self.item_instance_code) + if self.qty != self.qty_before_last_save + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) + if found + InventoryDefinition.check_balance(self, inventory_definition) + end end end - # if self.qty > self.qty_was - # credit = 0 - # debit = self.qty.to_i - self.qty_was.to_i - # else - # credit = self.qty_was.to_i - self.qty.to_i - # debit = 0 - # end - # if credit != debit - # defination = InventoryDefinition.find_by_item_code(self.item_instance_code) - # stock = StockJournal.where('item_code = ?', self.item_instance_code).order("id DESC").first - # journal = StockJournal.create( - # item_code: self.item_instance_code, - # credit: credit, - # debit: debit, - # balance: stock.balance - debit + credit, - # inventory_definition_id: defination.id, - # remark: 'ok', - # trans_ref: self.order.id, - # trans_type: StockJournal::SALES_TRANS - # ) - # end end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 98457d0e..18be54a9 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1,18 +1,22 @@ class Sale < ApplicationRecord + include NumberFormattable self.primary_key = "sale_id" #primary key - need to be unique generated for multiple shops before_create :generate_custom_id before_create :generate_receipt_no - belongs_to :cashier, :optional => true + belongs_to :cashier, foreign_key: "cashier_id", class_name: "Employee" belongs_to :customer, :optional => true - belongs_to :employees + belongs_to :shift_sale + has_one :survey, foreign_key: "receipt_no" + has_many :sale_audits has_many :sale_items has_many :sale_discount_items has_many :sale_discounts has_many :sale_taxes has_many :sale_payments has_many :sale_orders + has_many :sale_payments_for_credits, through: :sale_audits has_many :orders, through: :sale_orders has_many :order_items, through: :sale_orders has_many :bookings @@ -23,6 +27,10 @@ class Sale < ApplicationRecord scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") } scope :complete_sale, -> { where("sale_status = 'completed' and receipt_date BETWEEN '#{DateTime.now.utc.beginning_of_day}' AND '#{DateTime.now.utc.end_of_day}'") } + scope :paid, -> { where(payment_status: 'paid')} + scope :completed, -> { where(sale_status: 'completed') } + scope :receipt_date_between, -> (from, to) { where(receipt_date: from..to) } + scope :along_with_sale_payments_except_void_between, -> (from, to) { joins(sanitize_sql_array(["LEFT JOIN sale_payments on sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND sale_payments.created_at BETWEEN ? and ?", from, to])) } def qty_of(item_instance_code) order_items.select(:order_items_id, :item_instance_code, 'SUM(qty) as qty').where(item_instance_code: item_instance_code).group(:item_instance_code).first @@ -521,7 +529,7 @@ class Sale < ApplicationRecord tax_profiles = unique_tax_profiles(order_source, self.customer_id) # #Creat new tax records - if self.payment_status != 'foc' + if self.payment_status != 'foc' && tax_type.to_s == "all" tax_profiles.each do |tax| sale_tax = SaleTax.new(:sale => self) sale_tax.tax_name = tax.name @@ -536,16 +544,82 @@ class Sale < ApplicationRecord 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 + sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + end + + sale_tax.inclusive = tax.inclusive + sale_tax.save + + if !tax.inclusive 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 + end + elsif tax_type.to_s == "no_tax" + tax_profiles.each do |tax| + sale_tax = SaleTax.new(:sale => self) + sale_tax.tax_name = tax.name + sale_tax.tax_rate = 0 + sale_tax.tax_payable_amount = 0 sale_tax.inclusive = tax.inclusive sale_tax.save end + elsif tax_type.to_s == "Commercial Tax" + tax_profiles.each do |tax| + if tax.name == tax_type.to_s + sale_tax = SaleTax.new(:sale => self) + 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 + tax_incl_exec = "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 + end + end + elsif tax_type.to_s == "Service Charges" + tax_profiles.each do |tax| + if tax.name == tax_type.to_s + sale_tax = SaleTax.new(:sale => self) + 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 + tax_incl_exec = "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 + end + end end self.tax_type = tax_incl_exec self.total_tax = total_tax_amount @@ -592,6 +666,12 @@ class Sale < ApplicationRecord sale_tax.tax_payable_amount = total_tax / divided_value else sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + end + + sale_tax.inclusive = tax.inclusive + sale_tax.save + + if !tax.inclusive total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount end @@ -599,9 +679,6 @@ class Sale < ApplicationRecord if shop.calc_tax_order total_taxable = total_taxable + sale_tax.tax_payable_amount end - - sale_tax.inclusive = tax.inclusive - sale_tax.save end self.tax_type = tax_incl_exec self.total_tax = total_tax_amount @@ -770,7 +847,7 @@ def self.daily_sales_list(from,to) ELSE 0 END as credit_amount, SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount, SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount") - .joins("LEFT JOIN sale_payments on sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND DATE(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30')) = DATE(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'))") + .along_with_sale_payments_except_void_between(from, to) .where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to) .group("sale_id").to_sql @@ -916,6 +993,28 @@ def self.get_item_query(type) # query = query.order("i.menu_category_name asc, SUM(i.qty) desc") end +def self.get_staff_meal_query() + sale_type = "foc" + query = Sale.select("cus.name as staff_name,sales.sale_id,acc.title as account_name, + 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.status as status_type,i.remark as remark,"+ + "i.unit_price,i.price as price,i.product_name as product_name, " + + "i.menu_category_name,i.menu_category_code as menu_category_id, " + + "date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p') + as date_format") + + query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id " + + "JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id " + + "JOIN customers cus ON cus.customer_id = sales.customer_id ") + query = query.joins(" JOIN accounts acc ON acc.id = i.account_id") + # query = query.where("#{sale_type}") + query = query.group("acc.title,i.account_id,i.menu_category_code,i.item_instance_code,i.product_name,i.unit_price") + .order("acc.title desc, i.account_id desc, i.menu_category_code desc, i.item_instance_code asc, SUM(i.qty) desc, i.unit_price asc") + # query = query.order("i.menu_category_name asc, SUM(i.qty) desc") +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," + @@ -1022,6 +1121,111 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou return query,other_charges, product, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount end +def self.get_staff_meal_items(shift_sale_range, shift, from, to, status,account_type,customer_id) + # date_type_selection = get_sql_function_for_report_type(report_type) + if account_type.blank? + account_type = '' + else + account_type = " and acc.title = '#{account_type}'" + end + + unless customer_id.empty? + customer_id = customer_id.to_s + customer_id[0] = "" + customer_id = customer_id.chomp("]") + else + customer_id = '"CUS-000000000000"' + end + + query = self.get_staff_meal_query() + + discount_query = 0 + total_card_amount = 0 + total_cash_amount = 0 + total_credit_amount = 0 + total_foc_amount = 0 + total_grand_total = 0 + other_charges = 0 + + # if type.nil? || type == 'all' || type == "other" + # other_charges = self.get_other_charges() + # end + product = self.get_product_sale() + + if shift.present? + query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",shift.to_a) + # if type.nil? || type == 'all' || type == "other" + # other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) + # end + product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) + discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount) + change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed) + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, + SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, + SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a) + sale_cash.each do |s_c| + total_cash_amount += s_c.cash_amount.to_f + total_card_amount += s_c.card_amount.to_f + total_credit_amount += s_c.credit_amount.to_f + total_foc_amount += s_c.foc_amount.to_f + end + total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f + + ### => get all sales range in shift_sales + elsif shift_sale_range.present? + query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",shift_sale_range.to_a) + # if type.nil? || type == 'all' || type == "other" + # other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) + # end + product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) + discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount) + change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed) + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, + SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, + SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a) + sale_cash.each do |s_c| + total_cash_amount += s_c.cash_amount.to_f + total_card_amount += s_c.card_amount.to_f + total_credit_amount += s_c.credit_amount.to_f + total_foc_amount += s_c.foc_amount.to_f + end + + total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f + + else + query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",from,to) + # if type.nil? || type == 'all' || type == "other" + # other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) + # end + product = product.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) + + discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount) + change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed) + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, + SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, + SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to) + sale_cash.each do |s_c| + total_cash_amount += s_c.cash_amount.to_f + total_card_amount += s_c.card_amount.to_f + total_credit_amount += s_c.credit_amount.to_f + total_foc_amount += s_c.foc_amount.to_f + end + total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f + + end + + return query, other_charges, product, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount +end + def self.get_product_sale() query = Sale.select("i.account_id as account_id, " + "SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," + @@ -1064,7 +1268,7 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_ty payment_type = " and sale_payments.payment_method = '#{payment_type}'" end - query = Sale.all.select("sales.*,sale_payments.*,df.name,df.type") + query = Sale.includes(:sale_items).select("sales.*,sale_payments.*,df.name,df.type") .where("sale_status= 'completed' and sale_payments.payment_amount != 0 #{payment_type}") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .joins("join bookings on bookings.sale_id = sales.sale_id") @@ -1082,17 +1286,16 @@ end def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,payment_type) ## => left join -> show all sales although no orders - if payment_type.blank? - payment_type = '' - else - payment_type = " and sale_payments.payment_method = '#{payment_type}'" - end - query = Sale.select("sales.*,bookings.dining_facility_id as table_id") - .where("sale_status= 'completed' and sale_payments.payment_amount != 0 #{payment_type}") - .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") - .joins("join bookings on bookings.sale_id = sales.sale_id") - .group("sales.sale_id") + query = Sale.includes([:customer, :survey, :sale_payments]) + .includes(:bookings => :dining_facility) + .select("sales.*, SUM(sale_payments.payment_amount) AS payments_for_credits_amount") + .joins(:bookings) + .left_joins(:sale_payments_for_credits) + .completed + .where.not(total_amount: 0) + .group(:sale_id) + .order(:receipt_date) if shift.present? query = query.where("sales.shift_sale_id in (?)", shift.to_a) elsif shift_sale_range.present? @@ -1100,45 +1303,43 @@ def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,pay else query = query.where("sales.receipt_date between ? and ?",from,to) end + + ActiveRecord::Associations::Preloader.new.preload(query, :sale_items, SaleItem.where.not(price: 0)) + return query end def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter,order_source) - order_sources = Order.select("sale_orders.sale_id, orders.source") - .joins(:sale_orders).to_sql - - credit_payments = SalePayment.select(" + payments_for_credits = SalePayment.select(" sales.sale_id, DATE_FORMAT(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30'),'%d %b %y %h:%i%p') as credit_payment_receipt_date, sale_payments.payment_amount as credit_payment, employees.name as credit_payment_cashier_name, - CONCAT(DATE_FORMAT(CONVERT_TZ(shift_started_at,'+00:00','+06:30'),'%d %b %y %h:%i%p'),' - ',DATE_FORMAT(CONVERT_TZ(shift_closed_at,'+00:00','+06:30'),'%d %b %y %h:%i%p')) as credit_payment_shift_name") - .joins("JOIN sales ON sales.sale_id = sale_payments.sale_id") - .joins("JOIN sale_audits ON sale_audits.sale_id = sales.sale_id AND SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id") - .joins("JOIN shift_sales ON shift_sales.id = sales.shift_sale_id") - .joins("JOIN employees ON employees.id = shift_sales.employee_id").to_sql + CONCAT(DATE_FORMAT(CONVERT_TZ(shift_sales.shift_started_at,'+00:00','+06:30'),'%d %b %y %h:%i%p'),' - ',DATE_FORMAT(CONVERT_TZ(shift_sales.shift_closed_at,'+00:00','+06:30'),'%d %b %y %h:%i%p')) as credit_payment_shift_name") + .joins(:sale_audit) + .joins(:sale => :shift_sale) + .joins(:sale => :cashier).to_sql credits = SalePayment.select(" sale_payments.sale_payment_id, sale_payments.payment_method, sale_payments.payment_amount, sale_payments.payment_status, - sales.sale_id, - sales.receipt_no, - sales.receipt_date as sale_date, - order_sources.source as order_source, - sales.cashier_name, + sales_sale_payments.sale_id, + sales_sale_payments.receipt_no, + sales_sale_payments.receipt_date as sale_date, + sales_sale_payments.cashier_name, + orders.source as order_source, customers.name as customer_name, - IFNULL(credit_payments.credit_payment_receipt_date, '-') as credit_payment_receipt_date, - IFNULL(credit_payments.credit_payment, 0) as credit_payment, - IFNULL(credit_payments.credit_payment_cashier_name, '-') as credit_payment_cashier_name, - IFNULL(credit_payments.credit_payment_shift_name, '-') as credit_payment_shift_name") - .joins("JOIN sales ON sales.sale_id = sale_payments.sale_id") - .joins("JOIN shift_sales ON shift_sales.id = sales.shift_sale_id") - .joins("JOIN customers ON customers.customer_id = sales.customer_id") - .joins("JOIN (#{order_sources}) order_sources ON order_sources.sale_id = sales.sale_id") - .joins("LEFT JOIN (#{credit_payments}) credit_payments ON credit_payments.sale_id = sales.sale_id") - .where("sale_payments.payment_method= ? AND sales.sale_status = ?", 'creditnote', 'completed') + IFNULL(payments_for_credits.credit_payment_receipt_date, '-') as credit_payment_receipt_date, + IFNULL(payments_for_credits.credit_payment, 0) as credit_payment, + IFNULL(payments_for_credits.credit_payment_cashier_name, '-') as credit_payment_cashier_name, + IFNULL(payments_for_credits.credit_payment_shift_name, '-') as credit_payment_shift_name") + .joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales_sale_payments.sale_id") + .joins(:sale => :customer) + .joins(:sale => :orders) + .credits + .where("sales_sale_payments.sale_status = ?", 'completed') if order_source.present? if order_source == "cashier" @@ -1149,19 +1350,19 @@ def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter, end if filter == 'paid' - credits = credits.where("credit_payment IS NOT NULL") + credits = credits.where("payments_for_credits IS NOT NULL") elsif filter == 'unpaid' - credits = credits.where("credit_payment IS NULL") + credits = credits.where("payments_for_credits IS NULL") end if shift.present? - credits = credits.where("sales.shift_sale_id in (?)",shift.to_a) + credits = credits.where("sales_sale_payments.shift_sale_id in (?)",shift.to_a) elsif shift_sale_range.present? - credits = credits.where("sales.shift_sale_id in (?)",shift_sale_range.to_a) + credits = credits.where("sales_sale_payments.shift_sale_id in (?)",shift_sale_range.to_a) else - credits = credits.where("sales.receipt_date between ? and ?",from,to) + credits = credits.where("sales_sale_payments.receipt_date between ? and ?",from,to) end - credits = credits.group("sales.sale_id") + credits = credits.group("sale_payments.sale_payment_id, sales_sale_payments.sale_id") end def self.get_void_sale(shift,from,to) @@ -1374,604 +1575,201 @@ end return tax end - def self.top_bottom_products(today,current_user,from,to,from_time,to_time,type) - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - query = Sale.top_bottom(today,nil,from,to,from_time,to_time) + def self.top_bottom_products(current_user,from,to,type) + query = Sale.joins("JOIN sale_items ON sale_items.sale_id = sales.sale_id") + .completed + .where("qty > 0 AND price > 0") + .group("SUBSTRING_INDEX(product_name, ' - ', 1)") - if type == "top" - query = query.group('i.product_name') - .order("SUM(i.qty) DESC").limit(20) - elsif type == "bottom" - query = query.group('i.product_name') - .order("SUM(i.qty) ASC").limit(20) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = Sale.top_bottom(today,nil,from,to,from_time,to_time) - if type == "top" - query = query.group('i.product_name') - .order("SUM(i.qty) DESC").limit(20) - elsif type == "bottom" - query = query.group('i.product_name') - .order("SUM(i.qty) ASC").limit(20) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = Sale.top_bottom(today,shift,from,to,from_time,to_time) - if type == "top" - query = query.group('i.product_name') - .order("SUM(i.qty) DESC").limit(20) - elsif type == "bottom" - query = query.group('i.product_name') - .order("SUM(i.qty) ASC").limit(20) - end - end - end - end - else - if current_user.nil? - query = Sale.top_bottom(today).group('i.product_name') + if !from.nil? && !to.nil? + query = query.receipt_date_between(from, to) + end - if type == "top" - query = query.order("SUM(i.qty) DESC").limit(20) - elsif type == "bottom" - query = query.order("SUM(i.qty) ASC").limit(20) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = Sale.top_bottom(today).group('i.product_name') - if type == "top" - query = query.order("SUM(i.qty) DESC").limit(20) - elsif type == "bottom" - query = query.order("SUM(i.qty) ASC").limit(20) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = Sale.top_bottom(today,shift).group('i.product_name') - if type == "top" - query = query.order("SUM(i.qty) DESC").limit(20) - elsif type == "bottom" - query = query.order("SUM(i.qty) ASC").limit(20) - end - end - end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("shift_sale_id='#{shift.id}'") end end + + if type == "top" + query = query.order("SUM(qty) DESC") + else + query = query.order("SUM(qty) ASC") + end + + query.limit(20).sum('qty') end - def self.hourly_sales(today,current_user,from,to,from_time,to_time) - logger.debug 'hourly_sales<<<<<<<<<<<<<<<<<<<<<<<<' - logger.debug today - logger.debug current_user.to_json - logger.debug from - logger.debug to - logger.debug from_time - logger.debug to_time - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - query = Sale.hourly_sale_data(today,nil,from,to,from_time,to_time) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = Sale.hourly_sale_data(today,nil,from,to,from_time,to_time) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = Sale.hourly_sale_data(today,shift,from,to,from_time,to_time) - end - end - end - else - if current_user.nil? - query = Sale.hourly_sale_data(today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = Sale.hourly_sale_data(today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = Sale.hourly_sale_data(today,shift) - end - end + def self.hourly_sales(current_user,from,to) + query = Sale.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '#{Time.zone.formatted_offset}'), '%I %p')") + .order('receipt_date').completed + + if !from.nil? && !to.nil? + query = query.receipt_date_between(from, to) + end + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("shift_sale_id='#{shift.id}'") end end + + query.sum(:grand_total) end - def self.employee_sales(today,current_user,from,to,from_time,to_time) - #sub query for credit payment - outstanding_query = "SELECT CASE WHEN SUM(sale_payments.outstanding_amount) < 0 THEN SUM(sale_payments.outstanding_amount) ELSE 0 END - FROM sale_payments - JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id - JOIN sales ON sale_payments.sale_id = sales.sale_id - WHERE sale_payments.outstanding_amount LIKE '%-%' AND sales.sale_status='completed'" - - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if !from_time.nil? && !to_time.nil? - outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" - else - outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'" - end - else - outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" + def self.employee_sales(current_user,from,to) + shift = if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + ShiftSale.current_open_shift(current_user.id) end - sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) + (#{outstanding_query}) ELSE 0 END) - FROM sale_payments - INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id - INNER JOIN sales ON sale_payments.sale_id = sales.sale_id - WHERE sales.sale_status='completed'" + payments_for_credits = SalePayment.joins(:sale_audit).to_sql - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if !from_time.nil? && !to_time.nil? - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" - else - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'" - end - else - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" - end - #sub query for credit payment - - changed_query = "SELECT SUM(s.amount_changed) - FROM `sales` s - WHERE s.sale_status='completed'" - - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if !from_time.nil? && !to_time.nil? - changed_query += " AND DATE_FORMAT(CONVERT_TZ(s.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(s.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" - else - changed_query += " AND DATE_FORMAT(CONVERT_TZ(s.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'" - end - else - changed_query += " AND DATE_FORMAT(CONVERT_TZ(s.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" - end - - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - query = Sale.employee_sale(today,nil,from,to,from_time,to_time) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - changed_query += " AND s.shift_sale_id=sales.shift_sale_id" - query = Sale.employee_sale(today,nil,from,to,from_time,to_time) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - changed_query += " AND s.shift_sale_id=#{shift.id}" - query = Sale.employee_sale(today,shift,from,to,from_time,to_time) - end - end - end - else - if current_user.nil? - query = Sale.employee_sale(today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - changed_query += " AND s.shift_sale_id=sales.shift_sale_id" - query = Sale.employee_sale(today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - changed_query += " AND s.shift_sale_id=#{shift.id}" - query = Sale.employee_sale(today,shift) - end - end - end - end - query = query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - (#{changed_query})) WHEN sp.payment_method='creditnote' THEN (SUM(sp.payment_amount) - (#{sub_query})) ELSE SUM(sp.payment_amount) END) AS payment_amount, (CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay' or sp.payment_method='giftvoucher') THEN 'card' ELSE sp.payment_method END) AS payment_method, e.name AS e_name") + query = employee_sale(shift, from, to) + .joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales.sale_id") + .select("SUM(sale_payments.payment_amount) - CASE WHEN sale_payments.payment_method = 'creditnote' THEN IFNULL(SUM(payments_for_credits.payment_amount), 0) ELSE ABS(SUM(CASE WHEN sale_payments.outstanding_amount < 0 THEN sale_payments.outstanding_amount ELSE 0 END)) END AS payment_amount, + CASE WHEN sale_payments.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' + ELSE sale_payments.payment_method END AS payment_method, employees.name AS e_name") end - def self.total_trans(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.total_trans(current_user=nil,from=nil,to=nil) query = Sale.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count") .where('sale_status = "completed"') - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - total = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - total = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - total = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - total = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - total = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id) - else - total = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id) - end - end - end - end - else - if current_user.nil? - total = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - total = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - total = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',today,today,shift.id) - end - end - end - end - end - def self.total_card_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - query = Sale.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") - .where('sales.sale_status = "completed" and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")') - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id) - end - end - end - end - else - if current_user.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id) - end - end - end - end - query = query.sum("sp.payment_amount") - end - - def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - outstanding_query = "SELECT CASE WHEN SUM(sale_payments.outstanding_amount) < 0 THEN SUM(sale_payments.outstanding_amount) ELSE 0 END - FROM sale_payments - JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id - JOIN sales ON sale_payments.sale_id = sales.sale_id - WHERE sale_payments.outstanding_amount LIKE '%-%' AND sales.sale_status='completed'" - - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if !from_time.nil? && !to_time.nil? - outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" - else - outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'" - end - else - outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) end - sub_query = SalePayment.select("(CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) + (#{outstanding_query}) ELSE 0 END) as total_credit_payment") - .joins(" JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id") - .joins(" JOIN sales ON sale_payments.sale_id = sales.sale_id") - .where("sales.sale_status='completed'") - - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if !from_time.nil? && !to_time.nil? - sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'") - else - sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'") - end - else - sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'") - end - - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote"') - .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - .sum("payment_amount") - if !sub_query.nil? - query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) - end - else - query = query.where('DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - .sum("payment_amount") - if !sub_query.nil? - query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) - end - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - .sum("payment_amount") - if !sub_query.nil? - query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) - end - else - query = query.where('DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - .sum("payment_amount") - if !sub_query.nil? - query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) - end - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and s.shift_sale_id=?',from,to,from_time,to_time,shift.id) - .sum("payment_amount") - if !sub_query.nil? - query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) - end - else - query = query.where('DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and s.shift_sale_id=?',from,to,shift.id) - .sum("payment_amount") - if !sub_query.nil? - query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) - end - end - end - end - end - else - if current_user.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today) - .sum("payment_amount") - if !sub_query.nil? - query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where('DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today) - .sum("payment_amount") - if !sub_query.nil? - query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and s.shift_sale_id=?',today,today,shift.id) - .sum("payment_amount") - if !sub_query.nil? - query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) - end - end - end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end + return query end - def self.summary_sale_receipt(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') - .where('sale_status = "completed"') - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id) - end - end - end - end - else - if current_user.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id) - end - end + def self.total_card_sale(current_user=nil,from=nil,to=nil) + query = Sale.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") + .where('sales.sale_status = "completed" and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")') + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) + end + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end + + query = query.sum("sp.payment_amount") + end + + def self.credit_payment(current_user=nil,from=nil,to=nil) + payments_for_credits = SalePayment.joins(:sale_audit).to_sql + + query = SalePayment.credits + .joins(:sale) + .joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sale_payments.sale_id") + .where("sale_payments.payment_method= ? AND sales.sale_status = ?", 'creditnote', 'completed') + + if (!from.nil? && !to.nil?) + query = query.merge(Sale.receipt_date_between(from, to)) + end + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("sales.shift_sale_id = ?", shift.id) + end + end + + return query.sum("sale_payments.payment_amount - IFNULL(payments_for_credits.payment_amount, 0)") + end + + def self.summary_sale_receipt(current_user=nil,from=nil,to=nil) + query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') + .where('sale_status = "completed"') + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) + end + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("sales.shift_sale_id = ?", shift.id) + end + end + query = query.first() end - def self.total_payment_methods(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - query = Sale.select("distinct sp.payment_method") - .where('sales.sale_status = "completed"') + def self.total_payment_methods(current_user=nil,from=nil,to=nil) + query = Sale.select("CASE WHEN sp.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' ELSE sp.payment_method END as payment_method") + .where("sales.sale_status = 'completed'") .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id) - end - end - end - end - else - if current_user.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) - end - end + .group("CASE WHEN sp.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' ELSE sp.payment_method END") + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) + end + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end + + return query end - def self.payment_sale(payment_method, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - time_query = '' - if !from_time.nil? && !to_time.nil? - time_query = " and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" - end + def self.payment_sale(payment_method, current_user=nil,from=nil,to=nil) + payments_for_credits = SalePayment.joins(:sale_audit).to_sql - outstanding_query = "SELECT CASE WHEN SUM(sale_payments.outstanding_amount) < 0 THEN SUM(sale_payments.outstanding_amount) ELSE 0 END - FROM sale_payments - JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id - JOIN sales ON sale_payments.sale_id = sales.sale_id - WHERE sale_payments.outstanding_amount LIKE '%-%' AND sales.sale_status='completed'" + query = Sale.select("SUM(sale_payments.payment_amount) - CASE WHEN sale_payments.payment_method = 'creditnote' THEN IFNULL(SUM(payments_for_credits.payment_amount), 0) ELSE ABS(SUM(CASE WHEN sale_payments.outstanding_amount < 0 THEN sale_payments.outstanding_amount ELSE 0 END)) END AS payment_amount") + .joins(:sale_payments) + .joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales.sale_id") + .completed - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if !from_time.nil? && !to_time.nil? - outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" - else - outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'" - end - else - outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" - end - - sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) + (#{outstanding_query}) ELSE 0 END) - FROM sale_payments - INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id - INNER JOIN sales ON sale_payments.sale_id = sales.sale_id - WHERE sales.sale_status='completed'" - - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if !from_time.nil? && !to_time.nil? - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" - else - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'" - end - else - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" - end - - changed_query = "SELECT SUM(s.amount_changed) - FROM `sales` s - WHERE s.sale_status='completed'" - - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if !from_time.nil? && !to_time.nil? - changed_query += " AND DATE_FORMAT(CONVERT_TZ(s.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(s.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" - else - changed_query += " AND DATE_FORMAT(CONVERT_TZ(s.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'" - end - else - changed_query += " AND DATE_FORMAT(CONVERT_TZ(s.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" - end - - query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") - where('sales.sale_status = "completed"') if payment_method == 'card' - query = query.where('(sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method="alipay" or sp.payment_method="paymal" or sp.payment_method="dinga" or sp.payment_method="JunctionPay" or sp.payment_method = "giftvoucher")') + query = query.merge(SalePayment.cards) else - query = query.where("sp.payment_method = '#{payment_method}'") + query = query.where("sale_payments.payment_method = ?", payment_method) end - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ?",from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ?",from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - changed_query += " AND s.shift_sale_id = #{shift.id}" - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) - end - end - end - end - else - if current_user.nil? - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - changed_query += " AND s.shift_sale_id = #{shift.id}" - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id) - end - end - end + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) end - query = query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - (#{changed_query})) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first() + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("sales.shift_sale_id = ?", shift.id) + end + end + + query.first end - def self.total_customer(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - total_dinein_takeaway = self.total_dinein_takeaway(today,current_user,from,to,from_time,to_time) + def self.total_customer(current_user=nil,from=nil,to=nil) + total_dinein_takeaway = self.total_dinein_takeaway(current_user,from,to) dinein_cnt = 0 takeaway_cnt = 0 + if !total_dinein_takeaway.nil? if total_dinein_takeaway[0] dinein_cnt = total_dinein_takeaway[0].total_dinein_cus takeaway_cnt = total_dinein_takeaway[0].total_take_cus end end - membership_cnt = self.total_membership(today,current_user,from,to,from_time,to_time) + + membership_cnt = self.total_membership(current_user,from,to) member_cnt = 0 + if !membership_cnt.nil? member_cnt = membership_cnt.total_memb_cus end + total_cus = 0 + if dinein_cnt > dinein_cnt || takeaway_cnt > 0 || !membership_cnt.nil? total_cus = dinein_cnt.to_int + takeaway_cnt.to_int + member_cnt.to_int end @@ -1979,96 +1777,39 @@ end return total_cus, dinein_cnt, takeaway_cnt, member_cnt end - def self.total_dinein_takeaway(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.total_dinein_takeaway(current_user=nil,from=nil,to=nil) query = Sale.select("(CASE WHEN c.customer_type='Dinein' THEN count(sales.customer_id) ELSE 0 END) as total_dinein_cus, (CASE WHEN c.customer_type='Takeaway' THEN count(sales.customer_id) ELSE 0 END) as total_take_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") .where('sales.sale_status = "completed" and c.membership_id is null') - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id) - end - end - end - end - else - if current_user.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) - end - end + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) + end + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end query = query.first() end - def self.total_membership(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.total_membership(current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") .where('sales.sale_status = "completed" and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))') - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?)',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id).first() - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id).first() - end - end - end - end - else - if current_user.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) - end - end + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) + end + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end + query = query.first() end @@ -2118,235 +1859,76 @@ end # query = query.first() # end - def self.total_order(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - query = Sale.select("count(distinct a.order_id) as total_order") - .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") - .joins("JOIN orders as b ON b.order_id = a.order_id") - .where('b.status = "billed"') - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id) - end - end - end - end - else - if current_user.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) - end - end + def self.total_order(current_user=nil,from=nil,to=nil) + query = Sale.select("count(distinct sale_orders.order_id) as total_order") + .joins(:sale_orders) + .completed + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) + end + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end - query = query.first() + + query = query.first end - def self.total_account(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - query = Sale.select("distinct b.id as account_id, b.title as title") - .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .joins("JOIN accounts as b ON b.id = a.account_id") - .where('sales.sale_status = "completed"') - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id) - end - end - end - end - else - if current_user.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) - end - end - end - end - end - - def self.account_data(account_id, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.account_data(account_id, current_user=nil,from=nil,to=nil) query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}'") - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) - end - end - end - end - else - if current_user.nil? - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id) - end - end + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) + end + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end - query = query.first() + + query = query.first end - def self.top_items(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.top_items(current_user=nil,from=nil,to=nil) query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed'") - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) - end - end - end - end - else - if current_user.nil? - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id) - end - end + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) + end + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end + query = query.group("a.product_code") .order("SUM(a.qty) DESC") .first() end - def self.total_foc_items(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.total_foc_items(current_user=nil,from=nil,to=nil) query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .where("sales.sale_status = 'completed' and a.status='foc' and a.product_name like '%FOC%'") - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) - end - end - end - end - else - if current_user.nil? - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id) - end - end + + if (!from.nil? && !to.nil?) + query = query.receipt_date_between(from, to) + end + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end + query = query.count() end @@ -2485,82 +2067,20 @@ def unique_tax_profiles(order_source, customer_id) return tax_data end -def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) +def self.employee_sale(shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) + query = Sale.joins(:cashier) + .joins(:sale_payments) + .paid.completed if !from.nil? && !to.nil? - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + - " i.price as unit_price,i.product_name") - .joins("JOIN sale_items i ON i.sale_id = sales.sale_id") - if !from_time.nil? && !to_time.nil? - query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ - " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'") - else - query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ - " and sale_status= 'completed'") - end - if !shift.nil? - query = query.where("shift_sale_id='#{shift.id}'") - end - else - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + - " i.price as unit_price,i.product_name") - .joins("JOIN sale_items i ON i.sale_id = sales.sale_id") - .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ - " and sale_status= 'completed'") - if !shift.nil? - query = query.where("shift_sale_id='#{shift.id}'") - end - end - return query -end - -def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) - if !from.nil? && !to.nil? - query = Sale.select("grand_total") - if !from_time.nil? && !to_time.nil? - query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) - else - query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - if !shift.nil? - query = query.where("shift_sale_id='#{shift.id}'") - end - query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") - .order('receipt_date') - else - query = Sale.select("grand_total") - .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) - if !shift.nil? - query = query.where("shift_sale_id='#{shift.id}'") - end - query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") - .order('receipt_date') - end - - return query -end - -def self.employee_sale(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) - query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") - .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id") - .where("sales.payment_status='paid' and sales.sale_status = 'completed' ") - if !from.nil? && !to.nil? - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'") - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'") - end - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') = '#{today}'") + query = query.receipt_date_between(from, to) end if !shift.nil? - query = query.where("sales.shift_sale_id ='#{shift.id}'") + query = query.where("sales.shift_sale_id = ?", shift.id) end - query = query.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay' or sp.payment_method='giftvoucher') THEN 'card' ELSE sp.payment_method END)","e.name") - .order("e.name") - - return query + query = query.group("payment_method","employees.name") + .order("employees.name") end # Start hourly sale item report @@ -2705,7 +2225,7 @@ end def grand_total_round print_settings = PrintSetting.get_precision_delimiter() if !print_settings.nil? - self.grand_total =self.grand_total.round(print_settings.precision.to_i) + self.grand_total =self.grand_total.round(precision) end end @@ -2852,8 +2372,6 @@ private def round_to_precision if (self.total_amount != self.total_amount_was || self.total_discount != self.total_discount_was || self.total_tax != self.total_tax_was) if (self.total_amount % 1 > 0 || self.total_discount % 1 > 0 || self.total_tax % 1 > 0) - precision = PrintSetting.get_precision_delimiter().precision.to_i - self.total_amount = self.total_amount.round(precision) self.total_discount = self.total_discount.round(precision) self.total_tax = self.total_tax.round(precision) @@ -2882,7 +2400,11 @@ private found, inventory_definition = InventoryDefinition.find_product_in_inventory(item) if found if stock_journal = StockJournal.find_by_trans_ref(item.order_items_id) - stock_journal.update(remark: self.sale_status) + if self.payment_status == "foc" && self.payment_status_was != "foc" + stock_journal.update(remark: self.payment_status) + else + stock_journal.update(remark: self.sale_status) + end end end end diff --git a/app/models/sale_audit.rb b/app/models/sale_audit.rb index d96034ad..14b952af 100755 --- a/app/models/sale_audit.rb +++ b/app/models/sale_audit.rb @@ -6,6 +6,8 @@ class SaleAudit < ApplicationRecord belongs_to :sale + belongs_to :sale_payments_for_credit, -> { where "SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id" }, foreign_key: "sale_id", primary_key: "sale_id", class_name: "SalePayment" + def self.sync_sale_audit_records(sale_audits) if !sale_audits.nil? sale_audits.each do |sa| @@ -163,7 +165,7 @@ class SaleAudit < ApplicationRecord end end end - + return card_balance_amount end diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index 9a8c3d87..dc03935c 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -1,4 +1,5 @@ class SaleItem < ApplicationRecord + include NumberFormattable self.primary_key = "sale_item_id" #primary key - need to be unique generated for multiple shops @@ -13,6 +14,7 @@ class SaleItem < ApplicationRecord before_validation :round_to_precision after_update :update_stock_journal + after_save :update_stock_journal_set_item # Add Sale Items def self.add_sale_items(sale_items) @@ -225,75 +227,6 @@ class SaleItem < ApplicationRecord return sale_items end - private - def generate_custom_id - if self.sale_item_id.nil? - self.sale_item_id = SeedGenerator.generate_id(self.class.name, "SLI") - end - end - - def round_to_precision - unit_price_fraction = self.unit_price % 1 - price_fraction = self.unit_price % 1 - # is_dining_charge = self.menu_category_code == 'DingingCharge' - - if self.unit_price != self.unit_price_was || self.price != self.price_was - if unit_price_fraction > 0 || price_fraction > 0 - if ['Discount', 'promotion'].include?(self.status) - precision = PrintSetting.get_precision_delimiter().precision.to_i - - self.unit_price = self.unit_price.round(precision) - self.price = (self.unit_price * self.qty).round(precision) - self.taxable_price = self.price - end - end - end - end - - def update_stock_journal - is_void = self.status == "void" && self.status_before_last_save != "void" - cancel_void = self.status_before_last_save == "void" && self.status.nil? - is_edit = self.qty >= 0 && self.qty != self.qty_before_last_save - is_foc = self.status == "foc" && self.status_before_last_save != "foc" - cancel_foc = self.status_before_last_save == "foc" - - if is_void or cancel_void or is_edit or is_foc or cancel_foc - found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) - if found - stock = StockJournal.where('item_code=?', self.item_instance_code).order("id DESC").first - unless stock.nil? - check_item = StockCheckItem.where('item_code=?', self.item_instance_code).order("id DESC").first - if is_void or cancel_void or is_edit - if is_void - qty = -self.qty - remark = "void" - elsif cancel_void - qty = self.qty - remark = "cancel void" - elsif is_edit - qty = self.qty - self.qty_before_last_save - remark = "edit" - 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 - else is_foc or cancel_foc - qty = StockJournal.where(trans_ref: self.sale_item_id).sum("credit-debit") - if order_item_id = self.sale.bookings.first.order_items.where(item_instance_code: self.item_instance_code, qty: self.qty + qty).select(:order_items_id).first.order_items_id - if stock_journal = StockJournal.find_by_trans_ref(order_item_id) - if is_foc - stock_journal.update(remark: "foc") - elsif cancel_foc - stock_journal.update(remark: "cancel_foc") - end - end - end - end - end - end - end - end - # Loader Service SFTP Start # Detail Sale Data def self.get_detail_sale_data(transaction_date) @@ -314,14 +247,14 @@ class SaleItem < ApplicationRecord sale_items.product_name as item_name, sale_items.qty as qty, CASE - WHEN s.sale_status = 'completed' OR s.sale_status = 'void' THEN 'Sales' + WHEN s.sale_status = 'completed' OR s.sale_status = 'void' THEN 'Sales' WHEN s.sale_status = 'waste' THEN 'Waste' WHEN s.sale_status = 'spoile' THEN 'Spoil' END as transaction_type, sale_items.price as gross_sales, '' as discount_code, CASE - WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 + WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END as discount_amt, (sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END)) as sales, ((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END))/21) as tax_amt, @@ -336,7 +269,7 @@ class SaleItem < ApplicationRecord '0' as is_sampling, '1' as tax_able, CASE - WHEN s.sale_status = 'void' THEN 1 ELSE 0 + WHEN s.sale_status = 'void' THEN 1 ELSE 0 END as is_void ") .joins("LEFT JOIN sales s ON s.sale_id = sale_items.sale_id") @@ -347,4 +280,146 @@ class SaleItem < ApplicationRecord # Loader Service SFTP End + private + def generate_custom_id + if self.sale_item_id.nil? + self.sale_item_id = SeedGenerator.generate_id(self.class.name, "SLI") + end + end + + def round_to_precision + unit_price_fraction = self.unit_price % 1 + price_fraction = self.unit_price % 1 + # is_dining_charge = self.menu_category_code == 'DingingCharge' + + if self.unit_price != self.unit_price_was || self.price != self.price_was + if unit_price_fraction > 0 || price_fraction > 0 + if ['Discount', 'promotion'].include?(self.status) + self.unit_price = self.unit_price.round(precision) + self.price = (self.unit_price * self.qty).round(precision) + self.taxable_price = self.price + end + end + end + end + + def update_stock_journal + unless MenuItemInstance.where("item_instance_name <> ''").pluck(:item_instance_code).include?(self.item_instance_code) + is_void = self.status == "void" && self.status_before_last_save != "void" + cancel_void = self.status_before_last_save == "void" && self.status.nil? + is_edit = self.qty >= 0 && self.qty != self.qty_before_last_save + is_foc = self.status == "foc" && self.status_before_last_save != "foc" + cancel_foc = self.status_before_last_save == "foc" + + if is_void or cancel_void or is_edit or is_foc or cancel_foc + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) + if found + stock = StockJournal.where('item_code=?', self.item_instance_code).order("id DESC").first + unless stock.nil? + check_item = StockCheckItem.where('item_code=?', self.item_instance_code).order("id DESC").first + if is_void or cancel_void or is_edit + if is_void + qty = -self.qty + remark = "void" + elsif cancel_void + qty = self.qty + remark = "cancel void" + elsif is_edit + qty = self.qty - self.qty_before_last_save + remark = "edit" + 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 + else is_foc or cancel_foc + qty = StockJournal.where(trans_ref: self.sale_item_id).sum("credit-debit") + if order_item_id = self.sale.bookings.first.order_items.where(item_instance_code: self.item_instance_code, qty: self.qty + qty).select(:order_items_id).first.order_items_id + if stock_journal = StockJournal.find_by_trans_ref(order_item_id) + if is_foc + stock_journal.update(remark: "foc") + elsif cancel_foc + stock_journal.update(remark: "cancel_foc") + end + end + end + end + end + end + end + end + end + + def update_stock_journal_set_item + is_void = self.status == "void" && self.status_before_last_save != "void" && self.qty > 0 + cancel_void = self.status_before_last_save == "void" && self.status.nil? + is_edit = self.qty >= 0 && self.qty != self.qty_before_last_save + is_foc = self.status == "foc" && self.status_before_last_save != "foc" + cancel_foc = self.status_before_last_save == "foc" + is_waste = self.status == "waste" + is_spoile = self.status == "spoile" + + if MenuItemInstance.where("item_instance_name <> ''").pluck(:item_instance_code).include?(self.item_instance_code) + if self.qty == 1 && self.qty != self.qty_before_last_save + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) + if found + stock = StockJournal.where('item_code=?', self.item_instance_code).order("id DESC").first + unless stock.nil? + check_item = StockCheckItem.where('item_code=?', self.item_instance_code).order("id DESC").first + if self.qty.to_i >= 0 + qty = self.qty - self.qty_was + if stock.balance.to_i >= qty + puts ">> stock is greater than order qty" + remark = "ok" + else + puts " << stock is less than order qty" + remark = "out of stock" + 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 + else + StockJournal.add_to_journal(self.item_instance_code, self.qty, 0, "out of stock", inventory_definition, self.id, StockJournal::SALES_TRANS) + end + end + elsif is_void or cancel_void or is_edit + if is_void + qty = -self.qty + remark = "void" + elsif cancel_void + qty = self.qty + remark = "cancel void" + elsif is_edit + qty = self.qty - self.qty_before_last_save + remark = "edit" + end + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) + if found + stock = StockJournal.where('item_code=?', self.item_instance_code).order("id DESC").first + unless stock.nil? + check_item = StockCheckItem.where('item_code=?', self.item_instance_code).order("id DESC").first + 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 + 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 is_foc + stock_journal.update(remark: "foc") + elsif cancel_foc + stock_journal.update(remark: "cancel_foc") + end + end + elsif is_waste or is_spoile + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) + if found + if stock_journal = StockJournal.where(trans_ref: self.sale_item_id, item_code: self.item_instance_code) + stock_journal.update(remark: self.status) + end + end + end + end + end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 5a1fdb72..e0ad2383 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -6,8 +6,13 @@ class SalePayment < ApplicationRecord belongs_to :sale + has_one :sale_audit, -> { where "SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id" }, foreign_key: "sale_id", primary_key: "sale_id" + attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status,:action_by + scope :credits, -> { where(payment_method: 'creditnote') } + scope :cards, -> { where(payment_method: ['mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher']) } + def self.sync_sale_payment_records(sale_payments) if !sale_payments.nil? sale_payments.each do |sp| diff --git a/app/models/sale_tax.rb b/app/models/sale_tax.rb index 2e35d2b5..801c3bf7 100755 --- a/app/models/sale_tax.rb +++ b/app/models/sale_tax.rb @@ -1,4 +1,5 @@ class SaleTax < ApplicationRecord + include NumberFormattable self.primary_key = "sale_tax_id" #primary key - need to be unique generated for multiple shops @@ -44,7 +45,6 @@ class SaleTax < ApplicationRecord def round_to_precision if self.tax_payable_amount != self.tax_payable_amount_was if self.tax_payable_amount % 1 > 0 - precision = PrintSetting.get_precision_delimiter().precision.to_i self.tax_payable_amount = self.tax_payable_amount.round(precision) end end diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index 2d263c21..07217103 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -15,6 +15,7 @@ class ShiftSale < ApplicationRecord belongs_to :cashier_terminal belongs_to :employee, :foreign_key => 'employee_id' + has_many :sales def self.current_shift # today_date = DateTime.now.strftime("%Y-%m-%d") @@ -25,7 +26,7 @@ class ShiftSale < ApplicationRecord def self.current_open_shift(current_user) #if current_user #find open shift where is open today and is not closed and login by current cashier - #DATE(shift_started_at)=? and + #DATE(shift_started_at)=? and today_date = DateTime.now.strftime("%Y-%m-%d") shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}").take return shift @@ -43,7 +44,7 @@ class ShiftSale < ApplicationRecord # status = 'updated' if shift_sale.nil? shift_sale = ShiftSale.new - # status = 'created' + # status = 'created' end shift_sale.id = ss['id'] @@ -118,7 +119,7 @@ class ShiftSale < ApplicationRecord credit = saleobj.get_credit_amount other_sales = saleobj.get_other_amount tax = saleobj.get_commerical_tax - + if type == "void" self.total_revenue = self.total_revenue.to_f - saleobj.total_amount.to_f self.total_discounts = self.total_discounts - saleobj.total_discount @@ -137,7 +138,7 @@ class ShiftSale < ApplicationRecord self.takeaway_count = self.takeaway_count - 1 end - + self.save end end @@ -149,11 +150,11 @@ class ShiftSale < ApplicationRecord end def self.get_by_shift_other_payment(shift) - + other_payment = Sale.select("sale_payments.payment_method as name, - SUM(case when (sale_payments.payment_method='mpu') then (sale_payments.payment_amount) else 0 end) as mpu_amount, - SUM(case when (sale_payments.payment_method='visa') then (sale_payments.payment_amount) else 0 end) as visa_amount, - SUM(case when (sale_payments.payment_method='master') then (sale_payments.payment_amount) else 0 end) as master_amount, + SUM(case when (sale_payments.payment_method='mpu') then (sale_payments.payment_amount) else 0 end) as mpu_amount, + SUM(case when (sale_payments.payment_method='visa') then (sale_payments.payment_amount) else 0 end) as visa_amount, + SUM(case when (sale_payments.payment_method='master') then (sale_payments.payment_amount) else 0 end) as master_amount, SUM(case when (sale_payments.payment_method='jcb') then (sale_payments.payment_amount) else 0 end) as jcb_amount, SUM(case when (sale_payments.payment_method='unionpay') then (sale_payments.payment_amount) else 0 end) as unionpay_amount, SUM(case when (sale_payments.payment_method='alipay') then (sale_payments.payment_amount) else 0 end) as alipay_amount, @@ -161,19 +162,19 @@ class ShiftSale < ApplicationRecord SUM(case when (sale_payments.payment_method='dinga') then (sale_payments.payment_amount) else 0 end) as dinga_amount, SUM(case when (sale_payments.payment_method='giftvoucher') then (sale_payments.payment_amount) else 0 end) as giftvoucher_amount, SUM(case when (sale_payments.payment_method='JunctionPay') then (sale_payments.payment_amount) else 0 end) as junctionpay_amount, - SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount, - SUM(case when (sale_payments.payment_method='paymal') then (sale_payments.payment_amount) else 0 end) as paymal_amount, + SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount, + SUM(case when (sale_payments.payment_method='paymal') then (sale_payments.payment_amount) else 0 end) as paymal_amount, SUM(case when (sale_payments.payment_method='paypar') then (sale_payments.payment_amount) else 0 end) as paypar_amount") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .where("sales.shift_sale_id =? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.id) end def self.calculate_total_price_by_accounts(shift,type) - query = Sale.select("acc.title as account_name," + + query = Sale.select("acc.title as account_name," + "SUM(case when (acc.id=i.account_id) then (i.price) else 0 end) as total_price") - + query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id "+ - "JOIN accounts acc ON acc.id = i.account_id" + + "JOIN accounts acc ON acc.id = i.account_id" + " JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id") if type == 'discount' query = query.where("sales.shift_sale_id =? and sale_status = 'completed' and i.remark = 'Discount'", shift.id) @@ -187,17 +188,17 @@ class ShiftSale < ApplicationRecord def self.get_total_member_discount(shift) query = Sale.select("SUM(sales.total_discount) as member_discount") .where("shift_sale_id =? and sale_status = 'completed' and discount_type = 'member_discount'", shift.id) - - end - def self.get_total_dinein(shift) + end + + def self.get_total_dinein(shift) query = Sale.select("sum(sales.grand_total) as total_dinein_amount") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") .where('shift_sale_id =? and sales.sale_status = "completed" and c.customer_type = "Dinein" and c.membership_id is null',shift.id) .first() - end + end - def self.get_total_takeway(shift) + def self.get_total_takeway(shift) query = Sale.select("sum(sales.grand_total) as total_takeway_amount") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") .where('shift_sale_id =? and sales.sale_status = "completed" and c.customer_type = "Takeaway" and c.membership_id is null',shift.id) @@ -211,12 +212,12 @@ class ShiftSale < ApplicationRecord # .where('s.sale_status = "completed" and sale_items.product_code = "Other Charges" and sale_items.item_instance_code is null and s.receipt_date between ? and ?',from, to) # end - def self.get_total_other_charges(shift) + def self.get_total_other_charges(shift) query = SaleItem.select("sum(sale_items.qty * sale_items.unit_price) as total_other_charges_amount") .joins("JOIN sales as s ON s.sale_id = sale_items.sale_id") .where('shift_sale_id =? and s.sale_status = "completed" and sale_items.product_code = "Other Charges" and sale_items.item_instance_code is null',shift.id) .first() - end + end def self.search(filter,from,to) if filter.blank? diff --git a/app/models/stock_journal.rb b/app/models/stock_journal.rb index 6e72d94a..94cb71d6 100755 --- a/app/models/stock_journal.rb +++ b/app/models/stock_journal.rb @@ -4,6 +4,8 @@ class StockJournal < ApplicationRecord ORDER_TRANS = "order" STOCK_CHECK_TRANS = "stock_check" + scope :created_at_between, -> (from, to) { where(created_at: from..to)} + def self.add_to_journal(item_instance_code, qty, old_balance, stock_message, inventory_definition, trans_ref, trans_type) # item => saleObj | balance => Stock journal balance = calculate_balance(old_balance, qty) @@ -52,23 +54,13 @@ class StockJournal < ApplicationRecord journal.save end - def self.inventory_balances(today,from,to,from_time,to_time) + def self.inventory_balances(from,to) + query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") + .joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code") + .group("mii.item_instance_name") + .order("mii.item_instance_name ASC") if !from.nil? && !to.nil? - query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") - .joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code") - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'") - else - query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'") - end - query = query.group("mii.item_instance_name") - .order("mii.item_instance_name ASC") - else - query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") - .joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code") - .where("DATE_FORMAT(stock_journals.created_at,'%Y-%m-%d') = '#{today}'") - .group("mii.item_instance_name") - .order("mii.item_instance_name ASC") + query = query.created_at_between(from, to) end end diff --git a/app/pdf/check_in_out_pdf.rb b/app/pdf/check_in_out_pdf.rb index 08b9eba8..dfc40c2c 100644 --- a/app/pdf/check_in_out_pdf.rb +++ b/app/pdf/check_in_out_pdf.rb @@ -1,5 +1,5 @@ class CheckInOutPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:order_no_font_size, :item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,booking, table) self.page_width = print_settings.page_width diff --git a/app/pdf/close_cashier_customise_pdf.rb b/app/pdf/close_cashier_customise_pdf.rb index 2b05394d..34c4288d 100644 --- a/app/pdf/close_cashier_customise_pdf.rb +++ b/app/pdf/close_cashier_customise_pdf.rb @@ -1,5 +1,5 @@ class CloseCashierCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width,:text_width def initialize(printer_settings, shift_sale,shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) @@ -39,22 +39,11 @@ class CloseCashierCustomisePdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - #check delimiter - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header( shop_details) stroke_horizontal_rule - shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,printer_settings.precision,delimiter,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) + shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) end def header (shop_details) @@ -103,13 +92,13 @@ class CloseCashierCustomisePdf < Prawn::Document bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do text "#{ shift_sale.shift_closed_at.utc.getlocal.strftime('%d-%m-%Y %I:%M %p') }" , :size => self.item_font_size,:align => :left end - + y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do text "Opening Float : ", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ number_with_precision(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + text "#{ number_format(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left end y_position = cursor @@ -117,8 +106,8 @@ class CloseCashierCustomisePdf < Prawn::Document text "Closing Float : ", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left - # text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}" + text "#{ number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + # text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}" end @@ -135,7 +124,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Received Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end @@ -144,7 +133,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Cash In :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -152,7 +141,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Cash Out :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end move_down -5 @@ -165,7 +154,7 @@ class CloseCashierCustomisePdf < Prawn::Document total_discount_account = total_discount_account.to_f + amount.total_price.to_f end - #end total amount by Account + #end total amount by Account #start total FOC amount @total_foc = 0 @@ -173,7 +162,7 @@ class CloseCashierCustomisePdf < Prawn::Document @total_foc = other.foc_amount.round(2) end - #end total FOC amount + #end total FOC amount total_grand_total = shift_sale.grand_total + @total_foc.to_f + shift_sale.total_void.to_f - total_discount_account.to_f # @total_grand_total = @shift_sale.grand_total + @overall + @total_foc + @shift_sale.total_void y_position = cursor @@ -181,21 +170,21 @@ class CloseCashierCustomisePdf < Prawn::Document text "Grand Total :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(total_grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(total_grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end #start total amount by Account Like Food / Beverage /.. total_discount_by_account.each do |amount| - + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total #{amount.account_name} Discount:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + text "#{ number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end - #end total amount by Account + #end total amount by Account y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do @@ -205,8 +194,8 @@ class CloseCashierCustomisePdf < Prawn::Document @total_foc = 0 end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right - end + text "(#{ number_format(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + end y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do @@ -218,7 +207,7 @@ class CloseCashierCustomisePdf < Prawn::Document move_down -5 stroke_horizontal_rule - move_down 7 + move_down 7 @total_foc = 0 y_position = cursor @@ -226,7 +215,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Cash Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -234,9 +223,9 @@ class CloseCashierCustomisePdf < Prawn::Document text "Credit Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right end - #start other payment details + #start other payment details if shift_sale.other_sales > 0 other_payment.each do |other| @total_foc = other.foc_amount.round(2) @@ -246,7 +235,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "MPU Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -256,7 +245,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "VISA Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -266,7 +255,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Master Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -276,7 +265,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "JCB Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -286,7 +275,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "UNIONPAY Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -296,7 +285,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Alipay Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -306,7 +295,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "JunctionPay Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -316,7 +305,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Dinga Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -326,7 +315,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Redeem Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -336,7 +325,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Paymal Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -346,7 +335,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "GiftVoucher Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end end @@ -356,7 +345,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Other Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -365,8 +354,8 @@ class CloseCashierCustomisePdf < Prawn::Document text "Rounding Adjustments :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - + text "#{ number_format(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end y_position = cursor @@ -374,14 +363,14 @@ class CloseCashierCustomisePdf < Prawn::Document text "Gross Sale :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right + text "#{ number_format(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right end - # end other payment details + # end other payment details move_down -5 stroke_horizontal_rule move_down 7 - + # start Dinein and Takeaway y_position = cursor @@ -392,7 +381,7 @@ class CloseCashierCustomisePdf < Prawn::Document total_dinein = 0 end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(total_dinein, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(total_dinein, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -401,11 +390,11 @@ class CloseCashierCustomisePdf < Prawn::Document end if total_takeway.nil? total_takeway = 0 - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(total_takeway, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end - + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_format(total_takeway, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + # stop Dinein and Takeaway move_down -5 @@ -419,7 +408,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "#{tax.tax_name} :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -428,7 +417,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Total Taxes :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -436,7 +425,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Net Sales :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right + text "#{number_format(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right end if total_credit_payments && total_credit_payments.to_f > 0 @@ -445,7 +434,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Total Credit Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end #end for service charges and commercial tax @@ -463,16 +452,16 @@ class CloseCashierCustomisePdf < Prawn::Document move_down 7 #start total amount by Account Like Food / Beverage /.. # total_discount_by_account.each do |amount| - + # y_position = cursor # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do # text "Total #{amount.account_name} Discount:", :size => self.item_font_size, :align => :right # end # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - # text "#{ number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + # text "#{ number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right # end # end - #end total amount by Account + #end total amount by Account # y_position = cursor # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do @@ -481,19 +470,19 @@ class CloseCashierCustomisePdf < Prawn::Document # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do # text "#{shift_sale.grand_total}", :size => self.item_font_size, :align => :right # end - + #start total amount by Account Like Food / Beverage /.. - total_amount_by_account.each do |amount| + total_amount_by_account.each do |amount| y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total #{amount.account_name} Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + text "#{number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end - #end total amount by Account + #end total amount by Account #start total other charges amount if total_other_charges.present? @@ -502,9 +491,9 @@ class CloseCashierCustomisePdf < Prawn::Document text "Total Other Charges :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(total_other_charges, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(total_other_charges, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end - end + end #end total other charges amount move_down -5 @@ -513,32 +502,32 @@ class CloseCashierCustomisePdf < Prawn::Document #start total over all discount if total_member_discount[0].member_discount.present? - @member_discount = total_member_discount[0].member_discount rescue 0.0 + @member_discount = total_member_discount[0].member_discount rescue 0.0 @overall = shift_sale.total_discounts - @member_discount - + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Member Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end - else - @overall = shift_sale.total_discounts + else + @overall = shift_sale.total_discounts end - + if @overall > 0 y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "-#{ number_with_precision(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end + text "-#{ number_format(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end move_down -5 stroke_horizontal_rule move_down 7 - end + end #end total over all discount if total_waste.to_f > 0 @@ -547,7 +536,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Total Waste :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + text "(#{ number_format(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right end end @@ -557,7 +546,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Total Spoile :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + text "(#{ number_format(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right end end @@ -591,4 +580,3 @@ class CloseCashierCustomisePdf < Prawn::Document move_down 5 end end - diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index d4564291..976c3d93 100755 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -1,5 +1,5 @@ class CloseCashierPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width,:text_width def initialize(printer_settings, shift_sale, sale_items, total_other_charges_info, acc_cate_count, menu_cate_count, total_by_acc, shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) @@ -39,25 +39,14 @@ class CloseCashierPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - #check delimiter - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header( shop_details) stroke_horizontal_rule - shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,printer_settings.precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments) + shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments) if !sale_items.nil? or !sale_items.blank? - sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc, total_other_charges_info) + sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc, total_other_charges_info) end end @@ -107,13 +96,13 @@ class CloseCashierPdf < Prawn::Document bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do text "#{ shift_sale.shift_closed_at.utc.getlocal.strftime('%d-%m-%Y %I:%M %p') }" , :size => self.item_font_size,:align => :left end - + y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do text "Opening Float : ", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ number_with_precision(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + text "#{ number_format(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left end y_position = cursor @@ -121,8 +110,8 @@ class CloseCashierPdf < Prawn::Document text "Closing Float : ", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left - # text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}" + text "#{ number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + # text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}" end @@ -139,7 +128,7 @@ class CloseCashierPdf < Prawn::Document text "Received Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end @@ -148,7 +137,7 @@ class CloseCashierPdf < Prawn::Document text "Cash In:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -156,7 +145,7 @@ class CloseCashierPdf < Prawn::Document text "Cash Out:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end move_down -5 @@ -169,7 +158,7 @@ class CloseCashierPdf < Prawn::Document text "Cash Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -177,10 +166,10 @@ class CloseCashierPdf < Prawn::Document text "Credit Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right end - #start other payment details + #start other payment details if shift_sale.other_sales > 0 other_payment.each do |other| @total_foc = other.foc_amount.round(2) @@ -190,7 +179,7 @@ class CloseCashierPdf < Prawn::Document text "MPU Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -200,7 +189,7 @@ class CloseCashierPdf < Prawn::Document text "VISA Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -210,7 +199,7 @@ class CloseCashierPdf < Prawn::Document text "Master Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -220,7 +209,7 @@ class CloseCashierPdf < Prawn::Document text "JCB Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -230,7 +219,7 @@ class CloseCashierPdf < Prawn::Document text "UNIONPAY Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -240,7 +229,7 @@ class CloseCashierPdf < Prawn::Document text "Alipay Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -250,7 +239,7 @@ class CloseCashierPdf < Prawn::Document text "KBZ Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.kbzpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.kbzpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -260,7 +249,7 @@ class CloseCashierPdf < Prawn::Document text "JunctionPay Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -270,7 +259,7 @@ class CloseCashierPdf < Prawn::Document text "Dinga Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -280,7 +269,7 @@ class CloseCashierPdf < Prawn::Document text "Redeem Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -290,7 +279,7 @@ class CloseCashierPdf < Prawn::Document text "Paymal Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -300,7 +289,7 @@ class CloseCashierPdf < Prawn::Document text "GiftVoucher Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end end @@ -310,7 +299,7 @@ class CloseCashierPdf < Prawn::Document text "Other Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -319,7 +308,7 @@ class CloseCashierPdf < Prawn::Document text "Rounding Adjustments :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -327,10 +316,10 @@ class CloseCashierPdf < Prawn::Document text "Total :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right + text "#{ number_format(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right end - # end other payment details + # end other payment details move_down -5 stroke_horizontal_rule move_down 7 @@ -342,7 +331,7 @@ class CloseCashierPdf < Prawn::Document text "#{tax.tax_name} :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -351,7 +340,7 @@ class CloseCashierPdf < Prawn::Document text "Total Taxes :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -359,7 +348,7 @@ class CloseCashierPdf < Prawn::Document text "Net Sales :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right + text "#{number_format(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right end if total_credit_payments && total_credit_payments.to_f > 0 @@ -368,7 +357,7 @@ class CloseCashierPdf < Prawn::Document text "Total Credit Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end #end for service charges and commercial tax @@ -386,30 +375,30 @@ class CloseCashierPdf < Prawn::Document move_down 7 #start total amount by Account Like Food / Beverage /.. total_discount_by_account.each do |amount| - + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total #{amount.account_name} Discount:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + text "#{ number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end - #end total amount by Account + #end total amount by Account if total_member_discount[0].member_discount.present? - @member_discount = total_member_discount[0].member_discount rescue 0.0 + @member_discount = total_member_discount[0].member_discount rescue 0.0 @overall = shift_sale.total_discounts - @member_discount - + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Member Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end - else - @overall = shift_sale.total_discounts + else + @overall = shift_sale.total_discounts end y_position = cursor @@ -417,18 +406,18 @@ class CloseCashierPdf < Prawn::Document text "Total Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end + text "#{ number_format(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total FOC :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right - end + text "(#{ number_format(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + end - y_position = cursor + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Void :", :size => self.item_font_size, :align => :right end @@ -441,7 +430,7 @@ class CloseCashierPdf < Prawn::Document text "Total Waste :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + text "(#{ number_format(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right end y_position = cursor @@ -449,7 +438,7 @@ class CloseCashierPdf < Prawn::Document text "Total Spoile :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + text "(#{ number_format(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right end # y_position = cursor @@ -459,19 +448,19 @@ class CloseCashierPdf < Prawn::Document # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do # text "#{shift_sale.grand_total}", :size => self.item_font_size, :align => :right # end - + move_down -5 stroke_horizontal_rule move_down 7 #start total amount by Account Like Food / Beverage /.. - total_amount_by_account.each do |amount| + total_amount_by_account.each do |amount| y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total #{amount.account_name} Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + text "#{number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end @@ -482,7 +471,7 @@ class CloseCashierPdf < Prawn::Document bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{total_other_charges}", :size => self.item_font_size, :align => :right end - #end total amount by Account + #end total amount by Account y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do @@ -532,7 +521,7 @@ class CloseCashierPdf < Prawn::Document sale_items.each do |item| if !arr.include?(item['menu_category_id']) - + if flag == true move_down 5 stroke_horizontal_rule @@ -567,7 +556,7 @@ class CloseCashierPdf < Prawn::Document # text_box "#{item['grand_total'].to_i}", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix # } add_item_line(item['product_name'], item['unit_price'].to_i, item['total_item'].to_i, item['grand_total'].to_i) - + if item['total_item'].to_i > 0 or item['status_type'] == 'foc' or item['status_type'] == 'void' total_qty += item['total_item'].to_i total_items += item['total_item'].to_i @@ -657,4 +646,4 @@ class CloseCashierPdf < Prawn::Document text_box "#{sub_total.to_i}", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix } end -end \ No newline at end of file +end diff --git a/app/pdf/close_cashier_pdf_v1.rb b/app/pdf/close_cashier_pdf_v1.rb index 687f0aa8..c241c047 100644 --- a/app/pdf/close_cashier_pdf_v1.rb +++ b/app/pdf/close_cashier_pdf_v1.rb @@ -1,5 +1,5 @@ class CloseCashierPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width,:text_width def initialize(printer_settings, shift_sale, total_by_acc, shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) @@ -39,22 +39,11 @@ class CloseCashierPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - #check delimiter - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header( shop_details) stroke_horizontal_rule - shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,printer_settings.precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments) + shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments) end @@ -104,13 +93,13 @@ class CloseCashierPdf < Prawn::Document bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do text "#{ shift_sale.shift_closed_at.utc.getlocal.strftime('%d-%m-%Y %I:%M %p') }" , :size => self.item_font_size,:align => :left end - + y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do text "Opening Float : ", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ number_with_precision(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + text "#{ number_format(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left end y_position = cursor @@ -118,8 +107,8 @@ class CloseCashierPdf < Prawn::Document text "Closing Float : ", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left - # text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}" + text "#{ number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + # text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}" end @@ -136,7 +125,7 @@ class CloseCashierPdf < Prawn::Document text "Received Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end @@ -145,7 +134,7 @@ class CloseCashierPdf < Prawn::Document text "Cash In:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -153,7 +142,7 @@ class CloseCashierPdf < Prawn::Document text "Cash Out:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end move_down -5 @@ -166,7 +155,7 @@ class CloseCashierPdf < Prawn::Document text "Cash Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -174,10 +163,10 @@ class CloseCashierPdf < Prawn::Document text "Credit Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right end - #start other payment details + #start other payment details if shift_sale.other_sales > 0 other_payment.each do |other| @total_foc = other.foc_amount.round(2) @@ -187,7 +176,7 @@ class CloseCashierPdf < Prawn::Document text "MPU Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -197,7 +186,7 @@ class CloseCashierPdf < Prawn::Document text "VISA Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -207,7 +196,7 @@ class CloseCashierPdf < Prawn::Document text "Master Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -217,7 +206,7 @@ class CloseCashierPdf < Prawn::Document text "JCB Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -227,7 +216,7 @@ class CloseCashierPdf < Prawn::Document text "UNIONPAY Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -237,7 +226,7 @@ class CloseCashierPdf < Prawn::Document text "Alipay Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -247,7 +236,7 @@ class CloseCashierPdf < Prawn::Document text "JunctionPay Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -257,7 +246,7 @@ class CloseCashierPdf < Prawn::Document text "Dinga Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -267,7 +256,7 @@ class CloseCashierPdf < Prawn::Document text "Redeem Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -277,7 +266,7 @@ class CloseCashierPdf < Prawn::Document text "Paymal Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -287,7 +276,7 @@ class CloseCashierPdf < Prawn::Document text "GiftVoucher Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end end @@ -297,7 +286,7 @@ class CloseCashierPdf < Prawn::Document text "Other Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -306,7 +295,7 @@ class CloseCashierPdf < Prawn::Document text "Rounding Adjustments :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -314,10 +303,10 @@ class CloseCashierPdf < Prawn::Document text "Total :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right + text "#{ number_format(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right end - # end other payment details + # end other payment details move_down -5 stroke_horizontal_rule move_down 7 @@ -329,7 +318,7 @@ class CloseCashierPdf < Prawn::Document text "#{tax.tax_name} :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -338,7 +327,7 @@ class CloseCashierPdf < Prawn::Document text "Total Taxes :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -346,7 +335,7 @@ class CloseCashierPdf < Prawn::Document text "Net Sales :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right + text "#{number_format(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right end if total_credit_payments && total_credit_payments.to_f > 0 @@ -355,7 +344,7 @@ class CloseCashierPdf < Prawn::Document text "Total Credit Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end #end for service charges and commercial tax @@ -373,30 +362,30 @@ class CloseCashierPdf < Prawn::Document move_down 7 #start total amount by Account Like Food / Beverage /.. total_discount_by_account.each do |amount| - + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total #{amount.account_name} Discount:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + text "#{ number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end - #end total amount by Account + #end total amount by Account if total_member_discount[0].member_discount.present? - @member_discount = total_member_discount[0].member_discount rescue 0.0 + @member_discount = total_member_discount[0].member_discount rescue 0.0 @overall = shift_sale.total_discounts - @member_discount - + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Member Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end - else - @overall = shift_sale.total_discounts + else + @overall = shift_sale.total_discounts end y_position = cursor @@ -404,18 +393,18 @@ class CloseCashierPdf < Prawn::Document text "Total Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end + text "#{ number_format(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total FOC :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right - end + text "(#{ number_format(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + end - y_position = cursor + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Void :", :size => self.item_font_size, :align => :right end @@ -428,7 +417,7 @@ class CloseCashierPdf < Prawn::Document text "Total Waste :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + text "(#{ number_format(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right end y_position = cursor @@ -436,7 +425,7 @@ class CloseCashierPdf < Prawn::Document text "Total Spoile :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + text "(#{ number_format(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right end # y_position = cursor @@ -446,19 +435,19 @@ class CloseCashierPdf < Prawn::Document # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do # text "#{shift_sale.grand_total}", :size => self.item_font_size, :align => :right # end - + move_down -5 stroke_horizontal_rule move_down 7 #start total amount by Account Like Food / Beverage /.. - total_amount_by_account.each do |amount| + total_amount_by_account.each do |amount| y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total #{amount.account_name} Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + text "#{number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end @@ -469,7 +458,7 @@ class CloseCashierPdf < Prawn::Document bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{total_other_charges}", :size => self.item_font_size, :align => :right end - #end total amount by Account + #end total amount by Account y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do @@ -502,4 +491,4 @@ class CloseCashierPdf < Prawn::Document end -end \ No newline at end of file +end diff --git a/app/pdf/move_table_pdf.rb b/app/pdf/move_table_pdf.rb index 5d44b393..dc55eedc 100644 --- a/app/pdf/move_table_pdf.rb +++ b/app/pdf/move_table_pdf.rb @@ -1,5 +1,5 @@ class MoveTablePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :margin_top, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(printer_settings,to,from,shop_detail,date,type,moved_by,order_items) self.page_width = printer_settings.page_width @@ -39,7 +39,7 @@ class MoveTablePdf < Prawn::Document stroke_horizontal_rule move_down 5 - add_lining_item(order_items, printer_settings.precision) + add_lining_item(order_items, precision) move_down 5 stroke_horizontal_rule @@ -98,7 +98,7 @@ class MoveTablePdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "#{number_with_precision(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left + text "#{number_format(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do diff --git a/app/pdf/move_table_star_pdf.rb b/app/pdf/move_table_star_pdf.rb index 0467cbab..88ea4ef1 100644 --- a/app/pdf/move_table_star_pdf.rb +++ b/app/pdf/move_table_star_pdf.rb @@ -1,5 +1,5 @@ class MoveTableStarPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(printer_settings,to,from,shop_detail,date,type,moved_by,order_items) self.page_width = printer_settings.page_width @@ -38,7 +38,7 @@ class MoveTableStarPdf < Prawn::Document stroke_horizontal_rule move_down 5 - add_lining_item(order_items, printer_settings.precision) + add_lining_item(order_items, precision) move_down 5 stroke_horizontal_rule @@ -97,7 +97,7 @@ class MoveTableStarPdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "#{number_with_precision(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left + text "#{number_format(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do diff --git a/app/pdf/order_item_customise_pdf.rb b/app/pdf/order_item_customise_pdf.rb index b509a01a..32be1928 100644 --- a/app/pdf/order_item_customise_pdf.rb +++ b/app/pdf/order_item_customise_pdf.rb @@ -1,5 +1,5 @@ class OrderItemCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:order_no_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order_item, print_status, options, alt_name, before_updated_qty) self.page_width = print_settings.page_width @@ -47,7 +47,7 @@ class OrderItemCustomisePdf < Prawn::Document order_info(order_item.order_id, order_item.order_by,order_item.order_at) # order items - order_items(order_item, options, alt_name, print_settings.precision, before_updated_qty) + order_items(order_item, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF @@ -107,7 +107,7 @@ class OrderItemCustomisePdf < Prawn::Document end bounding_box([self.item_width - 10,y_position], :width => self.qty_width) do - text "[#{number_with_precision(order_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right + text "[#{number_format(order_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right end bounding_box([0,y_position], :width => self.item_width) do @@ -146,7 +146,7 @@ class OrderItemCustomisePdf < Prawn::Document # add option y_position = cursor bounding_box([0,y_position], :width => self.page_width) do - text "* Change quantity [#{number_with_precision(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_with_precision(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index ed079aeb..d4a05aa2 100755 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -1,5 +1,5 @@ class OrderItemPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :margin_top, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order_item, print_status, options, alt_name, before_updated_qty) @@ -48,7 +48,7 @@ class OrderItemPdf < Prawn::Document order_info(order_item.order_id, order_item.order_by,order_item.order_at) # order items - order_items(order_item, options, alt_name, print_settings.precision, before_updated_qty) + order_items(order_item, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF @@ -108,7 +108,7 @@ class OrderItemPdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "[#{number_with_precision(order_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "[#{number_format(order_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do @@ -147,7 +147,7 @@ class OrderItemPdf < Prawn::Document # add option y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "* Change quantity [#{number_with_precision(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_with_precision(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_item_slim_customise_pdf.rb b/app/pdf/order_item_slim_customise_pdf.rb index c4b1e5c5..f759cbec 100644 --- a/app/pdf/order_item_slim_customise_pdf.rb +++ b/app/pdf/order_item_slim_customise_pdf.rb @@ -1,5 +1,5 @@ class OrderItemSlimCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :item_slim_font_size def initialize(print_settings,order_item_slim, print_status, options, alt_name, before_updated_qty) self.page_width = print_settings.page_width @@ -11,9 +11,9 @@ class OrderItemSlimCustomisePdf < Prawn::Document self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 self.item_slim_font_size=8 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -29,17 +29,17 @@ class OrderItemSlimCustomisePdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end # font "public/fonts/Zawgyi-One.ttf" - # font "public/fonts/padauk.ttf" - #font "public/fonts/Chinese.ttf" + # font "public/fonts/padauk.ttf" + #font "public/fonts/Chinese.ttf" if !order_item_slim.dining.nil? text "#{ order_item_slim.type + '-' + order_item_slim.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 else text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 end - + stroke_horizontal_rule move_down 1 @@ -47,35 +47,35 @@ class OrderItemSlimCustomisePdf < Prawn::Document order_info(order_item_slim.order_id, order_item_slim.order_by,order_item_slim.order_at) # order items slim - order_items_slim(order_item_slim, options, alt_name, print_settings.precision, before_updated_qty) + order_items_slim(order_item_slim, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_slim_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_slim_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no} ", :size => self.item_slim_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.item_slim_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.item_slim_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_slim_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_slim_font_size,:align => :left + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_slim_font_size,:align => :left end stroke_horizontal_rule @@ -88,7 +88,7 @@ class OrderItemSlimCustomisePdf < Prawn::Document def order_items_slim(order_item_slim, options, alt_name, precision, before_updated_qty) y_position = cursor - #Add Order Item + #Add Order Item add_order_items_slim(order_item_slim, options, alt_name, precision) dash(1, :space => 1, :phase => 1) @@ -108,7 +108,7 @@ class OrderItemSlimCustomisePdf < Prawn::Document end bounding_box([self.item_width - 5,y_position], :width => self.qty_width) do - text "[#{number_with_precision(order_item_slim.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right + text "[#{number_format(order_item_slim.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right end bounding_box([0,y_position], :width => self.item_width) do @@ -146,7 +146,7 @@ class OrderItemSlimCustomisePdf < Prawn::Document # add option y_position = cursor bounding_box([0,y_position], :width => self.page_width) do - text "* Change quantity [#{number_with_precision(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_with_precision(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_item_slim_pdf.rb b/app/pdf/order_item_slim_pdf.rb index 3e39644f..a32c1a26 100755 --- a/app/pdf/order_item_slim_pdf.rb +++ b/app/pdf/order_item_slim_pdf.rb @@ -1,7 +1,7 @@ class OrderItemSlimPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width - + def initialize(print_settings,order_item_slim, print_status, options, alt_name, before_updated_qty) self.page_width = print_settings.page_width self.page_height = print_settings.page_height @@ -12,9 +12,9 @@ class OrderItemSlimPdf < Prawn::Document self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) # super(:margin => [10, 5, 30, 5], :page_size => [200,400]) @@ -29,17 +29,17 @@ class OrderItemSlimPdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end # font "public/fonts/Zawgyi-One.ttf" - # font "public/fonts/padauk.ttf" - #font "public/fonts/Chinese.ttf" + # font "public/fonts/padauk.ttf" + #font "public/fonts/Chinese.ttf" if !order_item_slim.dining.nil? text "#{ order_item_slim.type + '-' + order_item_slim.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 else text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 end - + stroke_horizontal_rule move_down 1 @@ -47,35 +47,35 @@ class OrderItemSlimPdf < Prawn::Document order_info(order_item_slim.order_id, order_item_slim.order_by,order_item_slim.order_at) # order items slim - order_items_slim(order_item_slim, options, alt_name, print_settings.precision, before_updated_qty) + order_items_slim(order_item_slim, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left end stroke_horizontal_rule @@ -87,7 +87,7 @@ class OrderItemSlimPdf < Prawn::Document def order_items_slim(order_item_slim, options, alt_name, precision, before_updated_qty) y_position = cursor - #Add Order Item + #Add Order Item add_order_items_slim(order_item_slim, options, alt_name, precision) puts options puts '............PDF OPTIONS...............' @@ -108,7 +108,7 @@ class OrderItemSlimPdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "[#{number_with_precision(order_item_slim.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "[#{number_format(order_item_slim.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do @@ -146,7 +146,7 @@ class OrderItemSlimPdf < Prawn::Document # add option y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "* Change quantity [#{number_with_precision(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_with_precision(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_item_star_pdf.rb b/app/pdf/order_item_star_pdf.rb index 2686efd7..0703c8a2 100644 --- a/app/pdf/order_item_star_pdf.rb +++ b/app/pdf/order_item_star_pdf.rb @@ -1,5 +1,5 @@ class OrderItemStarPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :margin_top, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order_item, print_status, options, alt_name, before_updated_qty) @@ -48,7 +48,7 @@ class OrderItemStarPdf < Prawn::Document order_info(order_item.order_id, order_item.order_by,order_item.order_at) # order items - order_items(order_item, options, alt_name, print_settings.precision, before_updated_qty) + order_items(order_item, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF @@ -108,7 +108,7 @@ class OrderItemStarPdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "[#{number_with_precision(order_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "[#{number_format(order_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do @@ -147,7 +147,7 @@ class OrderItemStarPdf < Prawn::Document # add option y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "* Change quantity [#{number_with_precision(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_with_precision(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_set_item_customise_pdf.rb b/app/pdf/order_set_item_customise_pdf.rb index 2e1d0a2c..f684e275 100644 --- a/app/pdf/order_set_item_customise_pdf.rb +++ b/app/pdf/order_set_item_customise_pdf.rb @@ -1,5 +1,5 @@ class OrderSetItemCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:order_no_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order_set_item, print_status, options, alt_name, before_updated_qty) self.page_width = print_settings.page_width @@ -12,9 +12,9 @@ class OrderSetItemCustomisePdf < Prawn::Document self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) # super(:margin => [10, 5, 30, 5], :page_size => [200,400]) @@ -29,11 +29,11 @@ class OrderSetItemCustomisePdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end # font "public/fonts/Zawgyi-One.ttf" - # font "public/fonts/padauk.ttf" - #font "public/fonts/Chinese.ttf" + # font "public/fonts/padauk.ttf" + #font "public/fonts/Chinese.ttf" if !order_set_item.dining.nil? text "#{ order_set_item.type + '-' + order_set_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 else @@ -46,35 +46,35 @@ class OrderSetItemCustomisePdf < Prawn::Document order_info(order_set_item.order_id, order_set_item.order_by,order_set_item.order_at) # order items - order_set_items(order_set_item, options, alt_name, print_settings.precision, before_updated_qty) + order_set_items(order_set_item, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.order_no_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.order_no_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no} ", :size => self.order_no_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.order_no_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.order_no_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.order_no_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.order_no_font_size,:align => :left + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.order_no_font_size,:align => :left end stroke_horizontal_rule @@ -86,7 +86,7 @@ class OrderSetItemCustomisePdf < Prawn::Document def order_set_items(order_set_item, options, alt_name, precision, before_updated_qty) y_position = cursor - #Add Order Item + #Add Order Item add_order_set_items(order_set_item, options, alt_name, precision) dash(1, :space => 1, :phase => 1) @@ -106,7 +106,7 @@ class OrderSetItemCustomisePdf < Prawn::Document end bounding_box([self.item_width - 5,y_position], :width => self.qty_width) do - text "[#{number_with_precision(order_set_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right + text "[#{number_format(order_set_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right end bounding_box([0,y_position], :width => self.item_width) do @@ -161,7 +161,7 @@ class OrderSetItemCustomisePdf < Prawn::Document # add option y_position = cursor bounding_box([0,y_position], :width => self.page_width) do - text "* Change quantity [#{number_with_precision(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_with_precision(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_set_item_pdf.rb b/app/pdf/order_set_item_pdf.rb index 09cdc6db..cb57c870 100755 --- a/app/pdf/order_set_item_pdf.rb +++ b/app/pdf/order_set_item_pdf.rb @@ -1,5 +1,5 @@ class OrderSetItemPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order_set_item, print_status, options, alt_name, before_updated_qty) self.page_width = print_settings.page_width @@ -11,9 +11,9 @@ class OrderSetItemPdf < Prawn::Document self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) # super(:margin => [10, 5, 30, 5], :page_size => [200,400]) @@ -28,11 +28,11 @@ class OrderSetItemPdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end # font "public/fonts/Zawgyi-One.ttf" - # font "public/fonts/padauk.ttf" - #font "public/fonts/Chinese.ttf" + # font "public/fonts/padauk.ttf" + #font "public/fonts/Chinese.ttf" if !order_set_item.dining.nil? text "#{ order_set_item.type + '-' + order_set_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 else @@ -45,35 +45,35 @@ class OrderSetItemPdf < Prawn::Document order_info(order_set_item.order_id, order_set_item.order_by,order_set_item.order_at) # order items - order_set_items(order_set_item, options, alt_name, print_settings.precision, before_updated_qty) + order_set_items(order_set_item, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left end move_down 2 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left end move_down 2 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left end move_down 2 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left end stroke_horizontal_rule @@ -85,7 +85,7 @@ class OrderSetItemPdf < Prawn::Document def order_set_items(order_set_item, options, alt_name, precision, before_updated_qty) y_position = cursor - #Add Order Item + #Add Order Item add_order_set_items(order_set_item, options, alt_name, precision) dash(1, :space => 1, :phase => 1) @@ -105,7 +105,7 @@ class OrderSetItemPdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "[#{number_with_precision(order_set_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "[#{number_format(order_set_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do @@ -160,7 +160,7 @@ class OrderSetItemPdf < Prawn::Document # add option y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "* Change quantity [#{number_with_precision(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_with_precision(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_summary_customise_pdf.rb b/app/pdf/order_summary_customise_pdf.rb index 8ffedca0..bce29877 100644 --- a/app/pdf/order_summary_customise_pdf.rb +++ b/app/pdf/order_summary_customise_pdf.rb @@ -1,5 +1,5 @@ class OrderSummaryCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:order_no_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width @@ -48,9 +48,9 @@ class OrderSummaryCustomisePdf < Prawn::Document # order items if order_items == nil - order_items(order, alt_name, print_settings.precision) + order_items(order, alt_name, precision) else - order_items(order_items, alt_name, print_settings.precision) + order_items(order_items, alt_name, precision) end end @@ -113,7 +113,7 @@ class OrderSummaryCustomisePdf < Prawn::Document end bounding_box([self.item_width - 10,y_position], :width => self.qty_width) do - text " [#{number_with_precision(odi.qty, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text " [#{number_format(odi.qty, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb index fd446131..f3d25ff1 100755 --- a/app/pdf/order_summary_pdf.rb +++ b/app/pdf/order_summary_pdf.rb @@ -1,5 +1,5 @@ class OrderSummaryPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width @@ -11,9 +11,9 @@ class OrderSummaryPdf < Prawn::Document self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -27,18 +27,18 @@ class OrderSummaryPdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - + if !order[0].dining.nil? text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 else text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 end - + stroke_horizontal_rule move_down 5 @@ -47,38 +47,38 @@ class OrderSummaryPdf < Prawn::Document # order items if order_items == nil - order_items(order, alt_name, print_settings.precision) + order_items(order, alt_name, precision) else - order_items(order_items, alt_name, print_settings.precision) + order_items(order_items, alt_name, precision) end end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left - end - - move_down 5 - y_position = cursor - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no}", :size => self.item_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left end move_down 5 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + text "OrderNo: #{order_no}", :size => self.item_font_size,:align => :left end move_down 5 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + end + + move_down 5 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left end stroke_horizontal_rule @@ -103,7 +103,7 @@ class OrderSummaryPdf < Prawn::Document #Add Order Item add_order_items(order_item, alt_name, precision) - + end # Add order items under order info @@ -113,7 +113,7 @@ class OrderSummaryPdf < Prawn::Document move_down 5 order_item.each do|odi| - # check for item not to show + # check for item not to show # if odi.price != 0 y_position = cursor @@ -123,14 +123,14 @@ class OrderSummaryPdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "#{number_with_precision(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left + text "#{number_format(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do text "#{odi.item_code} - #{odi.item_name}", :size => self.item_font_size,:align => :left end - + if alt_name if !(odi.alt_name).empty? move_down 4 @@ -138,15 +138,15 @@ class OrderSummaryPdf < Prawn::Document text "(#{odi.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true # end end - + end # add option options = odi.options == "[]"? "" : odi.options - + if options != "" move_down 5 - + y_position = cursor bounding_box([0,y_position], :width => self.item_width) do text "#{options}", :size => self.item_font_size,:align => :left @@ -161,7 +161,7 @@ class OrderSummaryPdf < Prawn::Document stroke_horizontal_line 0, (self.page_width - self.margin) move_down 5 # end - end + end end def get_booking_id(order_no) diff --git a/app/pdf/order_summary_set_customise_pdf.rb b/app/pdf/order_summary_set_customise_pdf.rb index 0e33d314..70c116fc 100644 --- a/app/pdf/order_summary_set_customise_pdf.rb +++ b/app/pdf/order_summary_set_customise_pdf.rb @@ -1,5 +1,5 @@ class OrderSummarySetCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:order_no_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width @@ -12,9 +12,9 @@ class OrderSummarySetCustomisePdf < Prawn::Document self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -38,7 +38,7 @@ class OrderSummarySetCustomisePdf < Prawn::Document else text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 end - + stroke_horizontal_rule move_down 5 @@ -47,38 +47,38 @@ class OrderSummarySetCustomisePdf < Prawn::Document # order items if order_items == nil - order_items(order, alt_name, print_settings.precision) + order_items(order, alt_name, precision) else - order_items(order_items, alt_name, print_settings.precision) + order_items(order_items, alt_name, precision) end end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.order_no_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.order_no_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no} ", :size => self.order_no_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.order_no_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.order_no_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.order_no_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.order_no_font_size,:align => :left + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.order_no_font_size,:align => :left end stroke_horizontal_rule @@ -92,7 +92,7 @@ class OrderSummarySetCustomisePdf < Prawn::Document #Add Order Item add_order_items(order_item, alt_name, precision) - + end # Add order items under order info @@ -102,7 +102,7 @@ class OrderSummarySetCustomisePdf < Prawn::Document move_down 5 order_item.each do|odi| - # check for item not to show + # check for item not to show # if odi.price != 0 y_position = cursor @@ -112,14 +112,14 @@ class OrderSummarySetCustomisePdf < Prawn::Document end bounding_box([self.item_width - 5,y_position], :width => self.qty_width) do - text "[#{number_with_precision(odi.qty, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "[#{number_format(odi.qty, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do text "#{odi.item_code} - #{odi.item_name}", :size => self.item_font_size,:align => :left end - + if alt_name if !(odi.alt_name).empty? move_down 4 @@ -127,7 +127,7 @@ class OrderSummarySetCustomisePdf < Prawn::Document text "(#{odi.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true # end end - + end #add set menu items @@ -148,10 +148,10 @@ class OrderSummarySetCustomisePdf < Prawn::Document # add option options = odi.options == "[]"? "" : odi.options - + if options != "" move_down 5 - + y_position = cursor bounding_box([0,y_position], :width => self.item_width) do text "#{options}", :size => self.item_font_size,:align => :left @@ -166,7 +166,7 @@ class OrderSummarySetCustomisePdf < Prawn::Document stroke_horizontal_line 0, (self.page_width - self.margin) move_down 5 # end - end + end end def get_booking_id(order_no) diff --git a/app/pdf/order_summary_set_pdf.rb b/app/pdf/order_summary_set_pdf.rb index 5e27f82b..dd65f0d2 100755 --- a/app/pdf/order_summary_set_pdf.rb +++ b/app/pdf/order_summary_set_pdf.rb @@ -1,5 +1,5 @@ class OrderSummarySetPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width @@ -11,9 +11,9 @@ class OrderSummarySetPdf < Prawn::Document self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -37,7 +37,7 @@ class OrderSummarySetPdf < Prawn::Document else text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 end - + stroke_horizontal_rule move_down 5 @@ -46,38 +46,38 @@ class OrderSummarySetPdf < Prawn::Document # order items if order_items == nil - order_items(order, alt_name, print_settings.precision) + order_items(order, alt_name, precision) else - order_items(order_items, alt_name, print_settings.precision) + order_items(order_items, alt_name, precision) end end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left - end - - move_down 5 - y_position = cursor - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left end move_down 5 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left end move_down 5 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + end + + move_down 5 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left end stroke_horizontal_rule @@ -102,7 +102,7 @@ class OrderSummarySetPdf < Prawn::Document #Add Order Item add_order_items(order_item, alt_name, precision) - + end # Add order items under order info @@ -112,7 +112,7 @@ class OrderSummarySetPdf < Prawn::Document move_down 5 order_item.each do|odi| - # check for item not to show + # check for item not to show # if odi.price != 0 y_position = cursor @@ -122,14 +122,14 @@ class OrderSummarySetPdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "#{number_with_precision(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left + text "#{number_format(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do text "#{odi.item_code} - #{odi.item_name}", :size => self.item_font_size,:align => :left end - + if alt_name if !(odi.alt_name).empty? move_down 4 @@ -137,7 +137,7 @@ class OrderSummarySetPdf < Prawn::Document text "(#{odi.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true # end end - + end #add set menu items @@ -158,10 +158,10 @@ class OrderSummarySetPdf < Prawn::Document # add option options = odi.options == "[]"? "" : odi.options - + if options != "" move_down 5 - + y_position = cursor bounding_box([0,y_position], :width => self.item_width) do text "#{options}", :size => self.item_font_size,:align => :left @@ -176,7 +176,7 @@ class OrderSummarySetPdf < Prawn::Document stroke_horizontal_line 0, (self.page_width - self.margin) move_down 5 # end - end + end end def get_booking_id(order_no) diff --git a/app/pdf/order_summary_slim_customise_pdf.rb b/app/pdf/order_summary_slim_customise_pdf.rb index c641b0c8..e8bd21f2 100644 --- a/app/pdf/order_summary_slim_customise_pdf.rb +++ b/app/pdf/order_summary_slim_customise_pdf.rb @@ -1,5 +1,5 @@ class OrderSummarySlimCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width,:item_slim_font_size def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width @@ -11,10 +11,10 @@ class OrderSummarySlimCustomisePdf < Prawn::Document self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 - self.item_slim_font_size=8 + self.label_width=90 + self.item_slim_font_size=8 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -38,7 +38,7 @@ class OrderSummarySlimCustomisePdf < Prawn::Document else text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 end - + stroke_horizontal_rule move_down 1 @@ -47,38 +47,38 @@ class OrderSummarySlimCustomisePdf < Prawn::Document # order items if order_items == nil - order_items(order, alt_name, print_settings.precision) + order_items(order, alt_name, precision) else - order_items(order_items, alt_name, print_settings.precision) + order_items(order_items, alt_name, precision) end end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_slim_font_size,:align => :left - end - - move_down 1 - y_position = cursor - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no} ", :size => self.item_slim_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_slim_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.item_slim_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.item_slim_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_slim_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_slim_font_size,:align => :left + end + + move_down 1 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_slim_font_size,:align => :left end stroke_horizontal_rule @@ -95,7 +95,7 @@ class OrderSummarySlimCustomisePdf < Prawn::Document #Add Order Item add_order_items(order_item, alt_name, precision) - + end # Add order items under order info @@ -105,7 +105,7 @@ class OrderSummarySlimCustomisePdf < Prawn::Document move_down 1 order_item.each do|odi| - # check for item not to show + # check for item not to show # if odi.price != 0 y_position = cursor @@ -115,14 +115,14 @@ class OrderSummarySlimCustomisePdf < Prawn::Document end bounding_box([self.item_width - 5,y_position], :width => self.qty_width) do - text "[#{number_with_precision(odi.qty, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "[#{number_format(odi.qty, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do text "#{odi.item_name}", :size => self.item_font_size,:align => :left end - + if alt_name if !(odi.alt_name).empty? move_down 1 @@ -134,7 +134,7 @@ class OrderSummarySlimCustomisePdf < Prawn::Document # add option options = odi.options == "[]"? "" : odi.options - + if options != "" move_down 1 @@ -152,7 +152,7 @@ class OrderSummarySlimCustomisePdf < Prawn::Document stroke_horizontal_line 0, (self.page_width - self.margin) move_down 1 # end - end + end end def get_booking_id(order_no) diff --git a/app/pdf/order_summary_slim_pdf.rb b/app/pdf/order_summary_slim_pdf.rb index 1b78cf23..2cbe14d8 100755 --- a/app/pdf/order_summary_slim_pdf.rb +++ b/app/pdf/order_summary_slim_pdf.rb @@ -1,5 +1,5 @@ class OrderSummarySlimPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width @@ -11,9 +11,9 @@ class OrderSummarySlimPdf < Prawn::Document self.qty_width = 40 self.total_width = 40 # No Need for item self.item_width = self.page_width - (self.qty_width - self.margin) - self.item_height = 15 + self.item_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -37,7 +37,7 @@ class OrderSummarySlimPdf < Prawn::Document else text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 end - + stroke_horizontal_rule move_down 1 @@ -46,38 +46,38 @@ class OrderSummarySlimPdf < Prawn::Document # order items if order_items == nil - order_items(order, alt_name, print_settings.precision) + order_items(order, alt_name, precision) else - order_items(order_items, alt_name, print_settings.precision) + order_items(order_items, alt_name, precision) end end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left - end - - move_down 1 - y_position = cursor - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left end move_down 1 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + end + + move_down 1 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left end stroke_horizontal_rule @@ -102,7 +102,7 @@ class OrderSummarySlimPdf < Prawn::Document #Add Order Item add_order_items(order_item, alt_name, precision) - + end # Add order items under order info @@ -112,7 +112,7 @@ class OrderSummarySlimPdf < Prawn::Document move_down 1 order_item.each do|odi| - # check for item not to show + # check for item not to show # if odi.price != 0 y_position = cursor @@ -122,14 +122,14 @@ class OrderSummarySlimPdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "#{number_with_precision(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left + text "#{number_format(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do text "#{odi.item_name}", :size => self.item_font_size,:align => :left end - + if alt_name if !(odi.alt_name).empty? move_down 1 @@ -141,7 +141,7 @@ class OrderSummarySlimPdf < Prawn::Document # add option options = odi.options == "[]"? "" : odi.options - + if options != "" move_down 1 @@ -159,7 +159,7 @@ class OrderSummarySlimPdf < Prawn::Document stroke_horizontal_line 0, (self.page_width - self.margin) move_down 1 # end - end + end end def get_booking_id(order_no) diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index 02443c0c..fbbf51e2 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -1,5 +1,5 @@ class ReceiptBillA5Pdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width, :line_move def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data,other_charges_amount,latest_order_no,card_balance_amount) @@ -26,11 +26,6 @@ class ReceiptBillA5Pdf < Prawn::Document #setting page margin and width super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - # db font setup if printer_settings.font != "" font_families.update("#{printer_settings.font}" => { @@ -46,23 +41,17 @@ class ReceiptBillA5Pdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header(shop_details) stroke_horizontal_rule cashier_info(sale_data, customer_name, latest_order_no) - line_items(sale_items,printer_settings.precision,delimiter) - all_total(sale_data,printer_settings.precision,delimiter) + line_items(sale_items,precision,delimiter) + all_total(sale_data,precision,delimiter) if member_info != nil - member_info(member_info,customer_name,rebate_amount,sale_data,printer_settings.precision,delimiter,current_balance) + member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter,current_balance) end customer(customer_name) @@ -77,21 +66,21 @@ class ReceiptBillA5Pdf < Prawn::Document card_balance_data(card_balance_amount) end #end card blanace amount - + if discount_price_by_accounts.length > 0 && shop_details.show_account_info - discount_account(discount_price_by_accounts,printer_settings.precision,delimiter) + discount_account(discount_price_by_accounts,precision,delimiter) end if shop_details.show_account_info - items_account(item_price_by_accounts,printer_settings.precision,delimiter) + items_account(item_price_by_accounts,precision,delimiter) if other_charges_amount - show_other_charges_amount(other_charges_amount,printer_settings.precision,delimiter) + show_other_charges_amount(other_charges_amount,precision,delimiter) end end #start for individual payment if !sale_data.equal_persons.nil? - individual_payment(sale_data, printer_settings.precision, delimiter) + individual_payment(sale_data, precision, delimiter) end #end for individual payment @@ -100,7 +89,7 @@ class ReceiptBillA5Pdf < Prawn::Document if shop_details.note && !shop_details.note.nil? shop_note(printed_status) end - + footer(printed_status) end @@ -130,7 +119,7 @@ class ReceiptBillA5Pdf < Prawn::Document text "OrderNo : #{ latest_order_no }", :size => self.header_font_size+2,:align => :left end move_down line_move - + # move_down 2 y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do @@ -154,7 +143,7 @@ class ReceiptBillA5Pdf < Prawn::Document bounding_box([self.item_description_width, y_position], :width =>self.item_description_width, :height => self.item_height) do text "W: #{sale_data.requested_by}" , :size => self.item_font_size, :align => :left - end + end bounding_box([self.item_description_width - 2,y_position], :width =>self.item_description_width, :height => self.item_height) do text "C: #{sale_data.cashier_name}", :size => self.item_font_size,:align => :right end @@ -172,7 +161,7 @@ class ReceiptBillA5Pdf < Prawn::Document # bounding_box([self.item_description_width,y_position], :width =>self.label_width+5) do - # text "(#{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } + # text "(#{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } # - #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') })" , # :size => self.item_font_size,:align => :right # end @@ -209,7 +198,7 @@ class ReceiptBillA5Pdf < Prawn::Document end def add_line_item_row(sale_items,precision,delimiter) - + if precision.to_i > 0 item_name_width = (self.item_width+self.price_width) item_qty_front_width = (self.item_width+self.price_width) + 5 @@ -229,17 +218,17 @@ class ReceiptBillA5Pdf < Prawn::Document sub_total = 0.0 total_qty = 0.0 sale_items.each do |item| - # check for item not to show + # check for item not to show show_price = Lookup.find_by_lookup_type("show_price") sub_total += item.price #(item.qty*item.unit_price) - comment for room charges if item.status != 'Discount' && item.qty > 0 if !show_price.nil? && show_price.value.to_i > 0 && item.price == 0 - total_qty += item.qty + total_qty += item.qty else if item.price != 0 - total_qty += item.qty + total_qty += item.qty end end end @@ -265,14 +254,14 @@ class ReceiptBillA5Pdf < Prawn::Document text "Sub Total", :size => self.item_font_size,:align => :left end # bounding_box([self.item_width + self.price_width + 11,y_position], :width =>self.qty_width, :height => self.item_height) do - # text "#{number_with_precision(total_qty, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :center + # text "#{number_format(total_qty, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :center # end # bounding_box([self.item_width + self.price_width + 8,y_position], :width =>self.total_width, :height => self.item_height) do - # text "#{number_with_precision(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + # text "#{number_format(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right # end - text_box "#{number_with_precision(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - + text_box "#{number_format(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + end def item_row(item,precision,delimiter,product_name,price,qty ,total_price) @@ -297,10 +286,10 @@ class ReceiptBillA5Pdf < Prawn::Document bounding_box([0,y_position], :width =>self.item_width) do text "#{product_name}", :size => self.item_font_size,:align => :left end - # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size - text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size + text_box "#{number_format(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix if show_alt_name if !(item.product_alt_name).empty? @@ -328,7 +317,7 @@ class ReceiptBillA5Pdf < Prawn::Document text "#{ dis_type }", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "( #{number_with_precision(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right + text "( #{number_format(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right end if sale_data.sale_taxes.length > 0 @@ -344,7 +333,7 @@ class ReceiptBillA5Pdf < Prawn::Document text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end else @@ -370,7 +359,7 @@ class ReceiptBillA5Pdf < Prawn::Document end bounding_box([self.description_width,y_position], :width =>self.label_width) do text "#{sale_data.rounding_adjustment}", :size => self.item_font_size,:align => :right - end + end end move_down line_move @@ -380,15 +369,15 @@ class ReceiptBillA5Pdf < Prawn::Document text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right + text "#{number_format(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right end move_down line_move - + sale_payment(sale_data,precision,delimiter) - + end - def sale_payment(sale_data,precision,delimiter) + def sale_payment(sale_data,precision,delimiter) stroke_horizontal_rule # move_down 10 sql = "SELECT SUM(payment_amount) @@ -419,28 +408,28 @@ class ReceiptBillA5Pdf < Prawn::Document text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left end end - + bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end - if sale_data.amount_received > 0 + if sale_data.amount_received > 0 y_position = cursor move_down line_move bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do text "Change Amount", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end #move_down line_move - end + end end # show member information def member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter,current_balance) - if rebate_amount != nil + if rebate_amount != nil if rebate_amount["status"] == true stroke_horizontal_rule total = 0 @@ -467,10 +456,10 @@ class ReceiptBillA5Pdf < Prawn::Document text "Rebate Earn", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end - - end + + end # Total Rebate Amount if birthday if res["receipt_no"]== sale_data.receipt_no && res["account_status"]== "RebatebonusAccount" && res["status"]== "Rebate" rebate_balance = rebate_balance + res["deposit"] @@ -480,9 +469,9 @@ class ReceiptBillA5Pdf < Prawn::Document text "Rebate Earn Bonus", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end - end + end #end Total rebate if birthday end @@ -492,7 +481,7 @@ class ReceiptBillA5Pdf < Prawn::Document text "Redeem Amount", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end if current_balance != nil @@ -502,10 +491,10 @@ class ReceiptBillA5Pdf < Prawn::Document text "Old Balance", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end - + end end @@ -515,7 +504,7 @@ class ReceiptBillA5Pdf < Prawn::Document if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount" total_balance = total_balance + res["balance"] - + end end move_down line_move @@ -524,10 +513,10 @@ class ReceiptBillA5Pdf < Prawn::Document text "Total Balance", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end - + end def customer(customer_name) @@ -554,8 +543,8 @@ class ReceiptBillA5Pdf < Prawn::Document text "#{ 'Total ' + ipa[:name] + ' Discounts' }", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "(" + "#{ number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right - end + text "(" + "#{ number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right + end move_down line_move end end @@ -570,8 +559,8 @@ class ReceiptBillA5Pdf < Prawn::Document text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.description_width) do - text "#{number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right - end + text "#{number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end move_down line_move end end @@ -582,9 +571,9 @@ class ReceiptBillA5Pdf < Prawn::Document text "Other Charges", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do - text "#{number_with_precision(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end - move_down line_move + move_down line_move end #individual payment per person @@ -604,7 +593,7 @@ class ReceiptBillA5Pdf < Prawn::Document bounding_box([self.label_width,y_position], :width =>self.item_description_width) do move_down 15 - text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end @@ -623,17 +612,17 @@ class ReceiptBillA5Pdf < Prawn::Document JOIN sale_audits sa ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payment_id where sa.sale_id='#{sale_data.sale_id}')) = 0 - THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id).each do |payment| + THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id).each do |payment| if payment.payment_method == "creditnote" y_position = cursor stroke_horizontal_rule - + bounding_box([self.label_width,y_position], :width =>self.description_width) do move_down 70 stroke_horizontal_rule end - + bounding_box([self.label_width,y_position], :width =>self.description_width) do move_down 73 text "Approved By" , :size => self.item_font_size,:align => :center @@ -650,8 +639,8 @@ class ReceiptBillA5Pdf < Prawn::Document move_down 70 stroke_horizontal_rule end - - if sale_data.payment_status == "foc" + + if sale_data.payment_status == "foc" bounding_box([self.label_width,y_position], :width =>self.description_width) do move_down 73 text "Acknowledged By" , :size => self.item_font_size,:align => :center @@ -661,10 +650,10 @@ class ReceiptBillA5Pdf < Prawn::Document move_down 73 text "Approved By" , :size => self.item_font_size,:align => :center end - end - - end - + end + + end + end def shop_note(shop) @@ -674,8 +663,8 @@ class ReceiptBillA5Pdf < Prawn::Document move_down line_move y_position = cursor - - text "#{shop.note}", :size => self.item_font_size,:align => :left + + text "#{shop.note}", :size => self.item_font_size,:align => :left move_down line_move end @@ -688,10 +677,10 @@ class ReceiptBillA5Pdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.item_description_width) do text "#{printed_status}",:style => :bold, :size => header_font_size,:align => :left - end + end bounding_box([self.item_description_width,y_position], :width =>self.item_description_width, :height => self.item_height) do text "Thank You! See you Again", :left_margin => -5, :size => self.item_font_size,:align => :right - end + end move_down line_move end @@ -729,7 +718,7 @@ class ReceiptBillA5Pdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width) do text "Card Balance: ",:style => :bold, :size => header_font_size,:align => :left - end + end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "#{card_balance_amount}" , :size => self.item_font_size,:align => :right end @@ -753,4 +742,4 @@ class ReceiptBillA5Pdf < Prawn::Document end return status end -end \ No newline at end of file +end diff --git a/app/pdf/receipt_bill_order_pdf.rb b/app/pdf/receipt_bill_order_pdf.rb index e66cb37e..0f2e1fc6 100644 --- a/app/pdf/receipt_bill_order_pdf.rb +++ b/app/pdf/receipt_bill_order_pdf.rb @@ -1,5 +1,5 @@ class ReceiptBillOrderPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width, :line_move @@ -27,11 +27,6 @@ class ReceiptBillOrderPdf < Prawn::Document #setting page margin and width super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - # db font setup if printer_settings.font != "" font_families.update("#{printer_settings.font}" => { @@ -47,19 +42,13 @@ class ReceiptBillOrderPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header(shop_details) stroke_horizontal_rule cashier_info(sale_data, customer_name, latest_order_no,order_reservation) - line_items(sale_items,printer_settings.precision,delimiter,order_reservation) - all_total(sale_data,printer_settings.precision,delimiter,order_reservation) + line_items(sale_items,precision,delimiter,order_reservation) + all_total(sale_data,precision,delimiter,order_reservation) footer(printed_status) end @@ -78,13 +67,13 @@ class ReceiptBillOrderPdf < Prawn::Document def cashier_info(sale_data, customer_name, latest_order_no,order_reservation) move_down line_move - + # move_down 2 - + y_position = cursor bounding_box([0, y_position], :width =>self.label_width , :height => self.item_height) do text "Order Date " , :size => self.item_font_size, :align => :left - end + end bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do text "#{order_reservation.created_at.strftime('%d-%m-%Y %H:%M %p')}", :size => self.item_font_size,:align => :right end @@ -92,7 +81,7 @@ class ReceiptBillOrderPdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width , :height => self.item_height) do text "Requested Date Time " , :size => self.item_font_size, :align => :left - end + end bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do text "#{order_reservation.requested_time.strftime('%d-%m-%Y %H:%M %p')}", :size => self.item_font_size,:align => :right end @@ -100,7 +89,7 @@ class ReceiptBillOrderPdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width , :height => self.item_height) do text "Payment Type" , :size => self.item_font_size, :align => :left - end + end bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do text "#{order_reservation.payment_type}", :size => self.item_font_size,:align => :right end @@ -108,7 +97,7 @@ class ReceiptBillOrderPdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width , :height => self.item_height) do text "#{customer_name} " , :size => self.item_font_size, :align => :left - end + end bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do text "Online Order", :size => self.item_font_size,:align => :right end @@ -167,14 +156,14 @@ class ReceiptBillOrderPdf < Prawn::Document total_qty = 0.0 show_price = Lookup.find_by_lookup_type("show_price") sale_items.each do |item| - # check for item not to show + # check for item not to show if item.status != 'Discount' && item.qty > 0 if !show_price.nil? && show_price.value.to_i > 0 && item.price == 0 - total_qty += item.qty + total_qty += item.qty else if item.price != 0 - total_qty += item.qty + total_qty += item.qty end end end @@ -191,7 +180,7 @@ class ReceiptBillOrderPdf < Prawn::Document qty = item.qty total_price = item.price #item.qty*item.unit_price - comment for room charges price = item.unit_price - + # end if !show_price.nil? && show_price.value.to_i>0 item_row(item,precision,delimiter,product_name,price,qty ,total_price) @@ -209,8 +198,8 @@ class ReceiptBillOrderPdf < Prawn::Document bounding_box([0,y_position], :width =>self.item_width + self.price_width, :height => self.item_height) do text "Sub Total", :size => self.item_font_size,:align => :left end - text_box "#{number_with_precision(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(order_reservation.total_amount, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(order_reservation.total_amount, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix if !order_reservation.delivery_type.nil? && order_reservation.delivery_fee.to_f > 0 y_position = cursor @@ -219,27 +208,27 @@ class ReceiptBillOrderPdf < Prawn::Document end bounding_box([self.description_width - 48,y_position], :width =>self.label_width, :height => self.item_height) do - text "#{number_with_precision(order_reservation.delivery_fee, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right - end + text "#{number_format(order_reservation.delivery_fee, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + end end if order_reservation.total_tax > 0 y_position = cursor bounding_box([0, y_position], :width =>self.item_description_width , :height => self.item_height) do text "Tax " , :size => self.item_font_size, :align => :left - end + end bounding_box([self.item_description_width,y_position], :width =>self.label_width, :height => self.item_height) do - text "#{number_with_precision(order_reservation.total_tax, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right - end - end + text "#{number_format(order_reservation.total_tax, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + end + end y_position = cursor bounding_box([0, y_position], :width =>self.item_description_width , :height => self.item_height) do text "Convenience Charges " , :size => self.item_font_size, :align => :left - end + end bounding_box([self.item_description_width,y_position], :width =>self.label_width, :height => self.item_height) do - text "#{number_with_precision(order_reservation.convenience_charge, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(order_reservation.convenience_charge, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end if order_reservation.discount_amount > 0 @@ -249,9 +238,9 @@ class ReceiptBillOrderPdf < Prawn::Document end bounding_box([self.item_description_width,y_position], :width =>self.label_width, :height => self.item_height) do - text "#{number_with_precision(order_reservation.discount_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right - end - end + text "#{number_format(order_reservation.discount_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + end + end end #Change items rows @@ -277,10 +266,10 @@ class ReceiptBillOrderPdf < Prawn::Document bounding_box([0,y_position], :width =>self.item_width) do text "#{product_name}", :size => self.item_font_size,:align => :left end - # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size - text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size + text_box "#{number_format(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix if show_alt_name if !(item.product_alt_name).empty? @@ -309,11 +298,11 @@ class ReceiptBillOrderPdf < Prawn::Document end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(order_reservation.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right - end + text "#{number_format(order_reservation.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right + end move_down line_move - # sale_payment(sale_data,precision,delimiter) + # sale_payment(sale_data,precision,delimiter) end #Change Footer @@ -326,10 +315,10 @@ class ReceiptBillOrderPdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width) do text "#{printed_status}",:style => :bold, :size => header_font_size - 1,:align => :left - end + end bounding_box([self.item_description_width,y_position], :width =>self.item_description_width, :height => self.item_height) do text "Thank You! See you Again", :left_margin => -5, :size => self.item_font_size - 1,:align => :left - end + end move_down line_move end @@ -351,4 +340,4 @@ class ReceiptBillOrderPdf < Prawn::Document end return status end -end \ No newline at end of file +end diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 2a99e9f9..2d463b38 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -1,7 +1,7 @@ # require 'prawn/qrcode' require 'prawn/measurement_extensions' class ReceiptBillPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width, :line_move @@ -29,11 +29,6 @@ class ReceiptBillPdf < Prawn::Document #setting page margin and width super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - # db font setup if printer_settings.font != "" font_families.update("#{printer_settings.font}" => { @@ -49,23 +44,17 @@ class ReceiptBillPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header(shop_details) stroke_horizontal_rule cashier_info(sale_data, customer_name, latest_order_no) - line_items(sale_items,printer_settings.precision,delimiter) - all_total(sale_data,printer_settings.precision,delimiter) + line_items(sale_items,precision,delimiter) + all_total(sale_data,precision,delimiter) if member_info != nil - member_info(member_info,customer_name,rebate_amount,sale_data,printer_settings.precision,delimiter,current_balance) + member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter,current_balance) end customer(customer_name) @@ -82,19 +71,19 @@ class ReceiptBillPdf < Prawn::Document #end card blanace amount if discount_price_by_accounts.length > 0 && shop_details.show_account_info - discount_account(discount_price_by_accounts,printer_settings.precision,delimiter) + discount_account(discount_price_by_accounts,precision,delimiter) end if shop_details.show_account_info - items_account(item_price_by_accounts,printer_settings.precision,delimiter) + items_account(item_price_by_accounts,precision,delimiter) if other_charges_amount - show_other_charges_amount(other_charges_amount,printer_settings.precision,delimiter) + show_other_charges_amount(other_charges_amount,precision,delimiter) end end #start for individual payment if !sale_data.equal_persons.nil? - individual_payment(sale_data,sale_data.equal_persons, printer_settings.precision, delimiter) + individual_payment(sale_data,sale_data.equal_persons, precision, delimiter) end #end for individual payment @@ -273,8 +262,8 @@ class ReceiptBillPdf < Prawn::Document bounding_box([0,y_position], :width =>self.item_width + self.price_width, :height => self.item_height) do text "Sub Total", :size => self.item_font_size,:align => :left end - text_box "#{number_with_precision(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(@sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(@sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix end def item_row(item,precision,delimiter,product_name,price,qty ,total_price) @@ -298,9 +287,9 @@ class ReceiptBillPdf < Prawn::Document text "#{product_name}", :size => self.item_font_size,:align => :left end # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size - text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix if show_alt_name if !(item.product_alt_name).empty? @@ -330,7 +319,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ dis_type }", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "( #{number_with_precision(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right + text "( #{number_format(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right end service_tax_desc = "" @@ -355,14 +344,14 @@ class ReceiptBillPdf < Prawn::Document sale_data.sale_taxes.each do |st| if (st.tax_name.include? "Service") service_tax_desc = st.tax_name - service_tax_amount = number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter) + service_tax_amount = number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter) if incl_tax service_tax_rate = st.tax_rate.to_i end end if (st.tax_name.include? "Commercial") com_tax_desc = st.tax_name - com_tax_amount = number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter) + com_tax_amount = number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter) if incl_tax com_tax_rate = st.tax_rate.to_i end @@ -374,7 +363,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ service_tax_desc } (#{incl_tax} #{ service_tax_rate }%)", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(service_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(service_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move y_position = cursor @@ -391,7 +380,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ com_tax_desc } (#{incl_tax} #{ com_tax_rate.to_i }%)", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(com_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(com_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end else sale_data.sale_taxes.each do |st| @@ -402,7 +391,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end end @@ -439,7 +428,7 @@ class ReceiptBillPdf < Prawn::Document text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right + text "#{number_format(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right end move_down line_move @@ -480,7 +469,7 @@ class ReceiptBillPdf < Prawn::Document end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -491,7 +480,7 @@ class ReceiptBillPdf < Prawn::Document text "Change Amount", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end # move_down line_move end @@ -526,7 +515,7 @@ class ReceiptBillPdf < Prawn::Document text "Rebate Earn", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end @@ -539,7 +528,7 @@ class ReceiptBillPdf < Prawn::Document text "Rebate Earn Bonus", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end #end Total rebate if birthday @@ -551,7 +540,7 @@ class ReceiptBillPdf < Prawn::Document text "Redeem Amount", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end if current_balance != nil @@ -561,7 +550,7 @@ class ReceiptBillPdf < Prawn::Document text "Old Balance", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end @@ -583,7 +572,7 @@ class ReceiptBillPdf < Prawn::Document text "Total Balance", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end @@ -615,7 +604,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ 'Total ' + ipa[:name] + ' Discounts' }", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "(" + "#{ number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right + text "(" + "#{ number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -631,7 +620,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do - text "#{number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -643,7 +632,7 @@ class ReceiptBillPdf < Prawn::Document text "Other Charges", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do - text "#{number_with_precision(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -666,7 +655,7 @@ class ReceiptBillPdf < Prawn::Document bounding_box([self.label_width,y_position], :width =>self.item_description_width) do move_down 15 - text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end diff --git a/app/pdf/receipt_bill_star_pdf.rb b/app/pdf/receipt_bill_star_pdf.rb index 0b1f8ce2..d9a14d4a 100644 --- a/app/pdf/receipt_bill_star_pdf.rb +++ b/app/pdf/receipt_bill_star_pdf.rb @@ -1,5 +1,5 @@ class ReceiptBillStarPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :margin_top, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width, :line_move @@ -28,11 +28,6 @@ class ReceiptBillStarPdf < Prawn::Document #setting page margin and width super(:margin => [self.margin_top, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - # db font setup if printer_settings.font != "" font_families.update("#{printer_settings.font}" => { @@ -48,23 +43,17 @@ class ReceiptBillStarPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header(shop_details) stroke_horizontal_rule cashier_info(sale_data, customer_name, latest_order_no) - line_items(sale_items,printer_settings.precision,delimiter) - all_total(sale_data,printer_settings.precision,delimiter) + line_items(sale_items,precision,delimiter) + all_total(sale_data,precision,delimiter) if member_info != nil - member_info(member_info,customer_name,rebate_amount,sale_data,printer_settings.precision,delimiter,current_balance) + member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter,current_balance) end customer(customer_name) @@ -81,19 +70,19 @@ class ReceiptBillStarPdf < Prawn::Document #end card blanace amount if discount_price_by_accounts.length > 0 && shop_details.show_account_info - discount_account(discount_price_by_accounts,printer_settings.precision,delimiter) + discount_account(discount_price_by_accounts,precision,delimiter) end if shop_details.show_account_info - items_account(item_price_by_accounts,printer_settings.precision,delimiter) + items_account(item_price_by_accounts,precision,delimiter) if other_charges_amount - show_other_charges_amount(other_charges_amount,printer_settings.precision,delimiter) + show_other_charges_amount(other_charges_amount,precision,delimiter) end end #start for individual payment if !sale_data.equal_persons.nil? - individual_payment(sale_data,sale_data.equal_persons, printer_settings.precision, delimiter) + individual_payment(sale_data,sale_data.equal_persons, precision, delimiter) end #end for individual payment @@ -268,8 +257,8 @@ class ReceiptBillStarPdf < Prawn::Document bounding_box([0,y_position], :width =>self.item_width + self.price_width, :height => self.item_height) do text "Sub Total", :size => self.item_font_size,:align => :left end - text_box "#{number_with_precision(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix end def item_row(item,precision,delimiter,product_name,price,qty ,total_price) @@ -293,9 +282,9 @@ class ReceiptBillStarPdf < Prawn::Document text "#{product_name}", :size => self.item_font_size,:align => :left end # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size - text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix if show_alt_name if !(item.product_alt_name).empty? @@ -325,7 +314,7 @@ class ReceiptBillStarPdf < Prawn::Document text "#{ dis_type }", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "( #{number_with_precision(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right + text "( #{number_format(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right end if sale_data.sale_taxes.length > 0 @@ -342,7 +331,7 @@ class ReceiptBillStarPdf < Prawn::Document text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end else @@ -378,7 +367,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right + text "#{number_format(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right end move_down line_move @@ -419,7 +408,7 @@ class ReceiptBillStarPdf < Prawn::Document end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -430,7 +419,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Change Amount", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end # move_down line_move end @@ -465,7 +454,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Rebate Earn", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end @@ -478,7 +467,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Rebate Earn Bonus", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end #end Total rebate if birthday @@ -490,7 +479,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Redeem Amount", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end if current_balance != nil @@ -500,7 +489,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Old Balance", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end @@ -522,7 +511,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Total Balance", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end @@ -554,7 +543,7 @@ class ReceiptBillStarPdf < Prawn::Document text "#{ 'Total ' + ipa[:name] + ' Discounts' }", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "(" + "#{ number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right + text "(" + "#{ number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -570,7 +559,7 @@ class ReceiptBillStarPdf < Prawn::Document text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do - text "#{number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -582,7 +571,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Other Charges", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do - text "#{number_with_precision(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -605,7 +594,7 @@ class ReceiptBillStarPdf < Prawn::Document bounding_box([self.label_width,y_position], :width =>self.item_description_width) do move_down 15 - text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end diff --git a/app/pdf/sale_items_pdf.rb b/app/pdf/sale_items_pdf.rb index 657b7fe1..af76c427 100644 --- a/app/pdf/sale_items_pdf.rb +++ b/app/pdf/sale_items_pdf.rb @@ -1,5 +1,5 @@ class SaleItemsPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width,:text_width def initialize(printer_settings, shop_details, period, type, account, from_date, to_date, shift, sale_items, total_other_charges) @@ -41,17 +41,6 @@ class SaleItemsPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - #check delimiter - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header( shop_details) stroke_horizontal_rule diff --git a/app/pdf/sale_items_star_pdf.rb b/app/pdf/sale_items_star_pdf.rb index 6860b341..a1181e13 100644 --- a/app/pdf/sale_items_star_pdf.rb +++ b/app/pdf/sale_items_star_pdf.rb @@ -1,5 +1,5 @@ class SaleItemsStarPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width,:text_width def initialize(printer_settings, shop_details, period, type, account, from_date, to_date, shift, sale_items, total_other_charges) @@ -41,17 +41,6 @@ class SaleItemsStarPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - #check delimiter - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header( shop_details) stroke_horizontal_rule diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index 0f9890d7..6cd52f4e 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -3,18 +3,6 @@

<%= t :date_time %> : <%= Time.zone.now.utc.getlocal.strftime("%Y-%m-%d %I:%M %p") %>

- <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %>
@@ -79,24 +67,16 @@
<% if !@from.nil? && @from != "" - from_date = DateTime.parse(@from).utc.getlocal.strftime("%d-%m-%Y") + from_date = @from.strftime("%d-%m-%Y") + from_time = @from.strftime("%H:%M") if @from.strftime("%H:%M") != "00:00" else - from_date = Time.now.utc.getlocal.strftime('%d-%m-%Y') + from_date = Time.now.strftime('%d-%m-%Y') end if !@to.nil? && @to != "" - to_date = DateTime.parse(@to).utc.getlocal.strftime("%d-%m-%Y") + to_date = @to.strftime("%d-%m-%Y") + to_time = @to.strftime("%H:%M") if @to.strftime("%H:%M") != "23:59" else - to_date = Time.now.utc.getlocal.strftime('%d-%m-%Y') - end - if !@from_time.nil? - from_time = @from_time - else - from_time = '' - end - if !@to_time.nil? - to_time = @to_time - else - to_time = '' + to_date = Time.now.strftime('%d-%m-%Y') end %>
@@ -211,49 +191,44 @@ <% revenue = @summ_sale.total_amount - @summ_sale.total_discount%> <%= t("views.right_panel.detail.sale") %> <%= t :revenue %> : - <%= number_with_precision( revenue, precision: precision.to_i ,delimiter: delimiter) %> + <%= number_format( revenue, precision: precision.to_i ,delimiter: delimiter) %> <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.discount") %> : - <%= number_with_precision( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> + <%= number_format( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) rescue number_format(0, precision: precision.to_i ,delimiter: delimiter) %> <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> : - <%= number_with_precision( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> + <%= number_format( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter) rescue number_format(0, precision: precision.to_i ,delimiter: delimiter) %> <%= t("views.right_panel.detail.total_sale") %> : - <%= number_with_precision( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter)%> + <%= number_format( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter)%> <% if !(@total_payment_methods.nil?) %> <% @total_payment_methods.each do |payment| %> - <% if !@sale_data[0].empty? %> - <% if payment.payment_method != 'mpu' && payment.payment_method != 'visa' && payment.payment_method != 'master' && payment.payment_method != 'jcb' && payment.payment_method != 'unionpay' %> - - <% if payment.payment_method == 'paypar' %> - - <% else %> - - <% end %> - - - <% end %> + <% if payment.payment_method != 'card' %> + + <% if payment.payment_method == 'paypar' %> + + <% else %> + + <% end %> + + <% end %> <% end %> - <% total_card = @sale_data.select { |hash| hash["card"]!=nil }.first %> + <% total_card = @sale_data.find {|x| x.key?("card") } %> <% if !total_card.nil? %> <% end %> diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index c948964d..1dbb3b98 100644 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -138,6 +138,9 @@
  • Induty
  • +
  • + Staff Meal +
  • Stock Check
  • @@ -324,6 +327,9 @@
  • Induty
  • +
  • + Staff Meal +
  • Stock Check
  • diff --git a/app/views/origami/addorders/_menu_item.json.jbuilder b/app/views/origami/addorders/_menu_item.json.jbuilder index a18645c8..2768fa9c 100755 --- a/app/views/origami/addorders/_menu_item.json.jbuilder +++ b/app/views/origami/addorders/_menu_item.json.jbuilder @@ -1,53 +1,20 @@ # Format for attributes json attr_format = [] -# Format for attributes json -if item.item_attributes.count > 0 - item.item_attributes.each do|attr_id| - menu_attr = MenuItemAttribute.find(attr_id) - if attr_format.count == 0 - attr_format.push({ type: menu_attr.attribute_type, values: [menu_attr.name] }) - next - end - - attr_format.each do |af| - if menu_attr.attribute_type.in? attr_format.map {|k| k[:type]} - if menu_attr.attribute_type == af[:type] - af[:values].push(menu_attr.name) - end - else - new_attr = {type: menu_attr.attribute_type, values: [ menu_attr.name ] } - attr_format.push(new_attr) - break - end - end - end +# Format for attributes json +if item.item_attributes.count > 0 + item_attributes = MenuItemAttribute.where(id: item.item_attributes) + attr_format = item_attributes.group_by {|att| att.attribute_type }.map { |type, values| {type: type, values: values.map(&:name)} } end # Format for option json opt_format = [] -# Format for attributes json -if item.item_options.count > 0 - item.item_options.each do|opt| - menu_opt = MenuItemOption.find(opt) - if opt_format.count == 0 - opt_format.push({ type: menu_opt.option_type, values: [menu_opt.name] }) - next - end - - opt_format.each do |of| - if menu_opt.option_type.in? opt_format.map {|k| k[:type]} - if menu_opt.option_type == of[:type] - of[:values].push(menu_opt.name) - end - else - new_opt = {type: menu_opt.option_type, values: [ menu_opt.name ] } - opt_format.push(new_opt) - break - end - end - end +# Format for attributes json +if item.item_options.count > 0 + item_options = MenuItemOption.where(id: item.item_options) + opt_format = item_options.group_by {|opt| opt.option_type }.map { |type, values| {type: type, values: values.map(&:name)} } end + #Menu Item Information json.id item.id json.code item.item_code @@ -63,8 +30,8 @@ json.is_available item.is_available json.is_sub_item item.is_sub_item json.unit item.unit -# Item Sets of Menu Item -json.item_sets item.item_sets do |its| +# Item Sets of Menu Item +json.item_sets item.item_sets.includes(:menu_item_instances) do |its| json.id its.id json.name its.name json.alt_name its.alt_name @@ -73,7 +40,7 @@ json.item_sets item.item_sets do |its| json.instances its.menu_item_instances do |i| json.id i.id end -end +end json.attributes attr_format json.options opt_format @@ -92,22 +59,17 @@ json.options opt_format json.instances item.menu_item_instances do |is| if is.is_available # Convert id to name for attributes - instance_attr = [] - is.item_attributes.each do |ia| - mItemAttr = MenuItemAttribute.find(ia).name - instance_attr.push(mItemAttr) - end - - json.id is.id - json.code is.item_instance_code - json.name is.item_instance_name - json.price is.price - json.is_available is.is_available - json.is_default is.is_default - json.is_on_promotion is.is_on_promotion - json.promotion_price is.promotion_price - json.values instance_attr - # json.item_sets is.item_sets + instance_attr = MenuItemAttribute.where(id: item.item_attributes).pluck(:name) + + json.id is.id + json.code is.item_instance_code + json.name is.item_instance_name + json.price is.price + json.is_available is.is_available + json.is_default is.is_default + json.is_on_promotion is.is_on_promotion + json.promotion_price is.promotion_price + json.values instance_attr end end @@ -116,4 +78,4 @@ end # json.set_items item.children.each do |item| # json.partial! 'api/restaurant/menu/menu_item', item: item # end -# end \ No newline at end of file +# end diff --git a/app/views/origami/dashboard/_menu.json.jbuilder b/app/views/origami/dashboard/_menu.json.jbuilder index d558c4ea..dcbff54f 100644 --- a/app/views/origami/dashboard/_menu.json.jbuilder +++ b/app/views/origami/dashboard/_menu.json.jbuilder @@ -12,11 +12,11 @@ if (menu.menu_categories) # else # categories = menu.menu_categories # end - categories = menu.menu_categories + categories = menu.menu_categories json.categories categories do |category| if category.is_available - menu_category = MenuCategory.find_by_menu_category_id(category.id) - if !menu_category.nil? + parent_category = category.parent + if !parent_category.nil? json.sub_category "true" else json.sub_category "false" @@ -34,7 +34,7 @@ if (menu.menu_categories) json.is_available category.is_available if !order_by.nil? && order_by.value == "name" - menu_items = MenuItem.unscoped.where("menu_category_id = ?",category.id).order("name asc") + menu_items = category.menu_items.sort_by(&:name) else menu_items = category.menu_items end @@ -42,7 +42,68 @@ if (menu.menu_categories) if category.menu_items json.items menu_items do |item| if item.is_available - json.partial! 'origami/addorders/menu_item', item: item + # Format for attributes json + attr_format = [] + # Format for attributes json + if item.item_attributes.count > 0 + item_attributes = @item_attributes.select{ |x| item.item_attributes.include?(x.id.to_s) } + attr_format = item_attributes.group_by {|att| att.attribute_type }.map { |type, values| {type: type, values: values.map(&:name)} } + end + + # Format for option json + opt_format = [] + # Format for attributes json + if item.item_options.count > 0 + item_options = @item_options.select{ |x| item.item_options.include?(x.id.to_s) } + opt_format = item_options.group_by {|opt| opt.option_type }.map { |type, values| {type: type, values: values.map(&:name)} } + end + + #Menu Item Information + json.id item.id + json.code item.item_code + json.name item.name + json.alt_name item.alt_name + json.image item.image_path.url + json.description item.description + json.information item.information + json.type item.type + json.account_id item.account_id + json.min_qty item.min_qty + json.is_available item.is_available + json.is_sub_item item.is_sub_item + json.unit item.unit + + # Item Sets of Menu Item + json.item_sets item.item_sets.map { |its| + { id: its.id, + name: its.name, + alt_name: its.alt_name, + min_selectable_qty: its.min_selectable_qty, + max_selectable_qty: its.max_selectable_qty, + instances: its.menu_item_instances.map { |id| {id: id}} + } + } + + json.attributes attr_format + json.options opt_format + + json.instances item.menu_item_instances do |is| + if is.is_available + # Convert id to name for attributes + instance_attr = @item_attributes.select{ |x| item.item_attributes.include?(x.id) }.pluck(:name) + + json.id is.id + json.code is.item_instance_code + json.name is.item_instance_name + json.price is.price + json.is_available is.is_available + json.is_default is.is_default + json.is_on_promotion is.is_on_promotion + json.promotion_price is.promotion_price + json.values instance_attr + end + end + end end end diff --git a/app/views/origami/dashboard/index.html.erb b/app/views/origami/dashboard/index.html.erb index 204ac3d4..713ba6a5 100644 --- a/app/views/origami/dashboard/index.html.erb +++ b/app/views/origami/dashboard/index.html.erb @@ -6,18 +6,6 @@

    <%= t :date_time %> : <%= Time.zone.now.utc.getlocal.strftime("%Y-%m-%d %I:%M %p") %>

    - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %>
    @@ -91,19 +79,19 @@
    <% revenue = @summ_sale.total_amount - @summ_sale.total_discount%> - + - + - + - +
    Redeem Sale : <%= payment.payment_method.to_s.capitalize %> Sale : - <% @sale_data.each do |data| %> - <% pay_mth = payment.payment_method %> - <%= number_with_precision(data[""+pay_mth+""], precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> - <% end %> -
    Redeem Sale : <%= payment.payment_method.to_s.capitalize %> Sale : + <%= number_format(@sale_data.find {|x| x.key?(payment.payment_method) }[payment.payment_method], precision: precision.to_i ,delimiter: delimiter) rescue number_format(0, precision: precision.to_i ,delimiter: delimiter) %> +
    <%= t("views.right_panel.detail.other_payment") %> : - <%= number_with_precision(total_card["card"], precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> + <%= number_format(total_card["card"], precision: precision.to_i ,delimiter: delimiter) rescue number_format(0, precision: precision.to_i ,delimiter: delimiter) %>
    <%= t("views.right_panel.detail.sale") %> <%= t :revenue %> : <%= number_with_precision( revenue, precision: precision.to_i ,delimiter: delimiter) %><%= number_format( revenue, precision: precision.to_i ,delimiter: delimiter) %>
    <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.discount") %> : <%= number_with_precision( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) %><%= number_format( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) %>
    <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> : <%= number_with_precision( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter)%><%= number_format( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter)%>
    <%= t("views.right_panel.detail.total") %> <%= t :sale %> : <%= number_with_precision( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter)%><%= number_format( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter)%>
    diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index abeeb442..5d24c9d1 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -2,20 +2,6 @@ - <% if !@print_settings.nil? %> - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> - <% end %>
    @@ -96,7 +82,7 @@
    - +
    @@ -57,14 +43,14 @@
    - <% @tables.each do |table| %> + <% @tables.each do |table| %> <% if table.status == 'occupied' %> <% if table.get_booking.nil? %> <% if table.get_checkout_booking.nil? %>
    - <% else %> + <% else %>
    - <% end %> + <% end %>
    <%= table.name %>
    <%= table.zone.name %> @@ -72,12 +58,12 @@
    - <% else %> + <% else %> <% if table.get_checkout_booking.nil? %>
    - <% else %> + <% else %>
    - <% end %> + <% end %>
    <%= table.name %>
    <%= table.zone.name %> @@ -111,7 +97,7 @@ <% end %>
    <%= room.name %>
    - <%= room.zone.name %> + <%= room.zone.name %> billed
    @@ -123,7 +109,7 @@ <% end %>
    <%= room.name %>
    - <%= room.zone.name %> + <%= room.zone.name %> new
    @@ -132,8 +118,8 @@
    <%= room.name %>
    - <%= room.zone.name %> - + <%= room.zone.name %> +
    <% end %> @@ -160,8 +146,8 @@ <% else %> <% order_status = order.status %> <% end %> - <%= order.order_id %> - <% if !order_status.empty? %>| <%= order_status %> + <%= order.order_id %> + <% if !order_status.empty? %>| <%= order_status %> <% end %>
    @@ -193,7 +179,7 @@
    - + @@ -245,7 +231,7 @@ <% else %> ORDER DETAILS | Table <%= @dining.name rescue "" %> <% end %> - +
    @@ -335,8 +321,8 @@ <% end %> <% if !order_item.set_menu_items.nil? && order_item.set_menu_items != '[]' - JSON.parse(order_item.set_menu_items).each do |item_instance| - set_item_prices += (item_instance["quantity"].to_f * item_instance["price"].to_f).to_f %> + JSON.parse(order_item.set_menu_items).each do |item_instance| + set_item_prices += (item_instance["quantity"].to_f * item_instance["price"].to_f).to_f %>
    <%= item_instance["item_instance_name"] %> @@ -345,17 +331,17 @@
    <%= set_item_option %> <% end %> <% end %> -
    - <% end + + <% end sub_total += set_item_prices end %>
    - + <% end %> <% end %> - <% end %> + <% end %>
    Sub Total:<%= number_with_precision(sub_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %><%= number_format(sub_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
    <%= t :credit %> <%= t :sale %> <%= t("views.right_panel.detail.date") %> <%= t("views.right_panel.detail.receipt_no") %> <%= t :cashier %> <%= t("views.right_panel.detail.name") %> <%= t :customer %> <%= t("views.right_panel.detail.name") %> <%= t :customer %> <%= t("views.right_panel.detail.name") %> <%= t("views.right_panel.detail.credit_amount") %>
    <%= order_item.qty %> <%= (order_item.qty*order_item.price).to_f + set_item_prices %>
    @@ -364,7 +350,7 @@ - + <%if @obj_sale != nil && @obj_sale.discount_type == 'member_discount'%> @@ -373,7 +359,7 @@ <%end%> - + <% if @status_sale == "sale" %> @@ -396,15 +382,15 @@ <% end %> - + - + - + <% end %> @@ -431,10 +417,10 @@ <% end %> <% end %> - <% if !order_item.set_menu_items.nil? - JSON.parse(order_item.set_menu_items).each do |item_instance| + <% if !order_item.set_menu_items.nil? + JSON.parse(order_item.set_menu_items).each do |item_instance| set_item_prices += (item_instance["quantity"].to_f * item_instance["price"].to_f).to_f - %> + %>
    <%= item_instance["item_instance_name"] %> <% if !item_instance["options"].nil? && item_instance["options"] != "undefined" %> @@ -444,8 +430,8 @@ <% end %> <% end %> - - <% end + + <% end sub_total += set_item_prices end %> @@ -456,7 +442,7 @@ end %>
    Sub Total:<%= number_with_precision(sub_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %><%= number_format(sub_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
    Discount:(<%= number_with_precision(@obj_sale.total_discount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>)(<%= number_format(@obj_sale.total_discount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>)
    <%= number_with_precision(@obj_sale.total_tax, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%><%= number_format(@obj_sale.total_tax, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%>
    Rounding Adj:<%= number_with_precision(@obj_sale.rounding_adjustment, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%><%= number_format(@obj_sale.rounding_adjustment, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%>
    Grand Total:<%= number_with_precision(@obj_sale.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %><%= number_format(@obj_sale.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
    --> - + <% end %> <% if @sale_array.size > 1 %> @@ -496,7 +482,7 @@ - <% if @dining.status != "available" %> + <% if @dining.status != "available" %> <% if @status_order == 'order' && @status_sale != 'sale' %> <%if !@order_items.empty? %> @@ -526,7 +512,7 @@ <% if current_login_employee.role == "cashier" %> - Edit + Edit Void <% else %> @@ -545,19 +531,19 @@ <% end %> <% if current_login_employee.role != "waiter" %> - + <%if @membership.discount && @obj_sale.customer.membership_id %> <%else%> - <%end%> - + <%end%> + <% end %> <% end %> @@ -583,7 +569,7 @@
    - + <% @payment_methods.each_with_index do |pay, pay_index| %> <%if (pay_index+1)%3 == 0 %>
    @@ -625,7 +611,7 @@
    - +
    @@ -638,7 +624,7 @@ - @@ -690,7 +676,7 @@ count += 1 %> - <%= count %> + <%= count %> <%= order_item.item_name %> <% if !order_item.options.nil? && !order_item.options.empty? && order_item.options != "undefined" %> @@ -701,10 +687,10 @@ <% end %> <% end %> - <% if !order_item.set_menu_items.nil? - JSON.parse(order_item.set_menu_items).each do |item_instance| + <% if !order_item.set_menu_items.nil? + JSON.parse(order_item.set_menu_items).each do |item_instance| set_item_prices += (item_instance["quantity"].to_f * item_instance["price"].to_f).to_f - %> + %>
    <%= item_instance["item_instance_name"] %> <% if !item_instance["options"].nil? && item_instance["options"] != "undefined" %> @@ -714,8 +700,8 @@ <% end %> <% end %> - - <% end + + <% end sub_total += set_item_prices end %> @@ -823,7 +809,7 @@ if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){ receipt_no = ($("#receipt_no").html()).trim(); } - + discount="<%= @membership.discount%>" if ($("#server_mode").val() != "cloud") { // first bill not used in cloud if (discount) { @@ -887,7 +873,7 @@ } else { var sale_id = "<%= @dining.id %>"; } - //var table_id = $('.tables').attr("data-id"); + //var table_id = $('.tables').attr("data-id"); window.location.href = '/origami/' + sale_id +"/"+cashier_type+ "/surveys" }); @@ -989,22 +975,22 @@ } location.reload(); } - }); + }); } - }); + }); }); - // click select option icon for add - $(document).on('click', '.payment_btn', function(event){ + // click select option icon for add + $(document).on('click', '.payment_btn', function(event){ active = $(this).hasClass('selected-payment'); value = $(this).data('value'); type = $(this).data('type'); group = $(this).data('group'); payments = $(".payment_btn"); - if (active) { + if (active) { $(this).removeClass('selected-payment'); - }else{ + }else{ $(this).addClass('selected-payment'); } }); //End selecct attribute buttom @@ -1026,7 +1012,7 @@ if(!location.pathname.includes("credit_payment")){ calculate_member_discount(sale_id,"Cash",tax_type); } - } + } } var ajax_url = "/origami/sale/" + sale_id + "/first_bill"; $.ajax({ @@ -1045,7 +1031,7 @@ } location.reload(); } - }); + }); }); function calculate_member_discount(sale_id,type,tax_type) { @@ -1060,10 +1046,10 @@ url: "/origami/" + sale_id + "/member_discount", data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':is_card,'cashier_type':'cashier','tax_type':tax_type }, async: false, - success:function(result){ + success:function(result){ } }); - + } $('#pay').on('click', function () { @@ -1137,11 +1123,11 @@ } }); } - else { + else { location.reload(); } } - }); + }); }else{ swal("Opps","There is no orders!","warning"); } @@ -1151,7 +1137,7 @@ $('#split_bills').click(function(){ var dining_id = "<%= @dining.id %>"; window.location.href = '/origami/table/' + dining_id + "/" + cashier_type +"/split_bills"; - }); + }); $('#move').on('click', function () { if($('#move').is(":visible")) { @@ -1236,7 +1222,7 @@ }else{ swal("Opps","You are not authorized for void","warning") } - + }); $('#commissions').on('click', function () { @@ -1285,7 +1271,7 @@ } }); } - }); + }); }else{ swal("Opps","You are not authorized for void","warning") } @@ -1303,7 +1289,7 @@ window.location.href = '/origami/addorders/' + dining_id; }); - /* check in process */ + /* check in process */ $('#check_in').on('click',function(){ var dining_id = "<%= @dining.id %>"; @@ -1394,7 +1380,7 @@ } }); } - }); + }); } function check_emp_access_code(access_code,type) { @@ -1460,11 +1446,11 @@ type: "POST", url: "/origami/payment/"+cashier_type+"/change_tax", data: {sale_id: sale_id, cashier_type: cashier_type, tax_type: tax_type}, - success:function(data){ + success:function(data){ if(data.status){ localStorage.setItem("tax_type", tax_type); window.location.href = '/origami/table/'+dining_id; - } + } } }); }else{ diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index a40f7f58..a7737724 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -2,20 +2,6 @@ - <% if !@print_settings.nil? %> - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> - <% end %>
    @@ -78,9 +64,9 @@ <% sub_total += sale_item.price%> <%= count %> - <%=sale_item.product_name%>@<%=number_with_precision( sale_item.unit_price, precision: precision.to_i )%> + <%=sale_item.product_name%>@<%=number_format( sale_item.unit_price, precision: precision.to_i )%> <%=sale_item.qty%> - <%=(number_with_precision(sale_item.price, precision: precision.to_i ))%> + <%=(number_format(sale_item.price, precision: precision.to_i ))%> <%end %> @@ -93,7 +79,7 @@ Sub Total - <%=number_with_precision(sub_total, precision: precision.to_i)%> + <%=number_format(sub_total, precision: precision.to_i)%> <%if @sale_data.discount_type == 'member_discount'%> @@ -101,7 +87,7 @@ <%else%> (Discount) <%end%> - (<%= number_with_precision(@sale_data.total_discount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>) + (<%= number_format(@sale_data.total_discount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>) @@ -122,20 +108,20 @@ <% end %> - <%= number_with_precision(@sale_data.total_tax, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%> + <%= number_format(@sale_data.total_tax, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%> Rounding Adj: - <%= number_with_precision(@sale_data.rounding_adjustment, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%> + <%= number_format(@sale_data.rounding_adjustment, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%> Grand Total - <%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%> + <%= number_format(@sale_data.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%> <%if @balance > 0%> <%= @accountable_type %> - <%=number_with_precision(@balance, precision: precision.to_i )%> + <%=number_format(@balance, precision: precision.to_i )%> <% end %> <% if !@individual_total[0].nil? %> @@ -149,7 +135,7 @@ Amount Due (per person) - <%= number_with_precision(@individual_total[0]['per_person_amount'], precision: precision.to_i )%> + <%= number_format(@individual_total[0]['per_person_amount'], precision: precision.to_i )%> <% end %> @@ -171,16 +157,16 @@ <% if @sale_payment.nil? %> - <%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %> + <%= number_format(@sale_data.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %> <% else %> - <%= number_with_precision(@sale_payment[0].payment_amount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i)%> + <%= number_format(@sale_payment[0].payment_amount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i)%> <% end %> @@ -190,13 +176,13 @@
    Cash
    - <%= number_with_precision(@cash, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %> + <%= number_format(@cash, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
    <% if @sale_payment.nil? && @cashier_type != "food_court" %>
    Credit
    -
    <%= number_with_precision(@credit, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(@credit, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
    <% else %> @@ -205,21 +191,21 @@
    Other Payments (KBZ Pay)
    - <%= number_with_precision(@kbz_pay_amount, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %> + <%= number_format(@kbz_pay_amount, precision: precision.to_i) rescue number_format(0, precision: precision.to_i) %>
    <% elsif @other == 0.0 && @ppamount == 0.0 && @visacount == 0.0 && @jcbcount == 0.0 && @mastercount == 0.0 && @unionpaycount == 0.0 && @alipaycount == 0.0 && @paymalcount == 0.0 && @junctionpaycount == 0.0 && @dingacount == 0.0 && @giftvouchercount == 0.0 %>
    Other Payments
    - <%= number_with_precision(@other, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %> + <%= number_format(@other, precision: precision.to_i) rescue number_format(0, precision: precision.to_i) %>
    <% else %>
    Other Payments
    - <%= number_with_precision(@other_payment, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %> + <%= number_format(@other_payment, precision: precision.to_i) rescue number_format(0, precision: precision.to_i) %>
    <% end %> @@ -231,9 +217,9 @@
    MPU
    <% if @other != 0.0 %> -
    <%= number_with_precision(@other, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(@other, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
    <% else %> -
    <%= number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(0, precision: precision.to_i ) %>
    <% end %>
    @@ -242,9 +228,9 @@
    Redeem
    <% if @ppamount != 0.0 %> -
    <%= number_with_precision(@ppamount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(@ppamount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
    <% else %> -
    <%= number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(0, precision: precision.to_i ) %>
    <% end %>
    @@ -253,9 +239,9 @@
    VISA
    <% if @visacount != 0.0 %> -
    <%= number_with_precision(@visacount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(@visacount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
    <% else %> -
    <%= number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(0, precision: precision.to_i ) %>
    <% end %> @@ -264,9 +250,9 @@
    JCB
    <% if @jcbcount != 0.0 %> -
    <%= number_with_precision(@jcbcount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(@jcbcount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
    <% else %> -
    <%= number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(0, precision: precision.to_i ) %>
    <% end %> @@ -275,9 +261,9 @@
    MASTER
    <% if @mastercount != 0.0 %> -
    <%= number_with_precision(@mastercount, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(@mastercount, precision: precision.to_i) rescue number_format(0, precision: precision.to_i ) %>
    <% else %> -
    <%= number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(0, precision: precision.to_i ) %>
    <% end %> @@ -287,9 +273,9 @@
    UNIONPAY
    <% if @unionpaycount != 0.0 %> -
    <%= number_with_precision(@unionpaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(@unionpaycount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
    <% else %> -
    <%= number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(0, precision: precision.to_i ) %>
    <% end %> @@ -298,9 +284,9 @@
    Alipay
    <% if @alipaycount != 0.0 %> -
    <%= number_with_precision(@alipaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(@alipaycount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
    <% else %> -
    <%= number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(0, precision: precision.to_i ) %>
    <% end %> @@ -309,9 +295,9 @@
    PAYMAL
    <% if @paymalcount != 0.0 %> -
    <%= number_with_precision(@paymalcount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(@paymalcount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
    <% else %> -
    <%= number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(0, precision: precision.to_i ) %>
    <% end %> @@ -319,9 +305,9 @@
    DINGA
    <% if @dingacount != 0.0 %> -
    <%= number_with_precision(@dingacount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(@dingacount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
    <% else %> -
    <%= number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(0, precision: precision.to_i ) %>
    <% end %> @@ -330,9 +316,9 @@
    JUNCTION PAY
    <% if @junctionpaycount != 0.0 %> -
    <%= number_with_precision(@junctionpaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(@junctionpaycount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
    <% else %> -
    <%= number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(0, precision: precision.to_i ) %>
    <% end %> @@ -341,15 +327,15 @@
    GIFT VOUCHER
    <% if @giftvouchercount != 0.0 %> -
    <%= number_with_precision(@giftvouchercount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(@giftvouchercount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
    <% else %> -
    <%= number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(0, precision: precision.to_i ) %>
    <% end %>
    Balance
    -
    <%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    +
    <%= number_format(@sale_data.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
    diff --git a/app/views/origami/table_invoices/show.html.erb b/app/views/origami/table_invoices/show.html.erb index 84efbc66..76c65057 100644 --- a/app/views/origami/table_invoices/show.html.erb +++ b/app/views/origami/table_invoices/show.html.erb @@ -1,19 +1,5 @@
    -<% if !@print_settings.nil? %> - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> -<% end %>
    @@ -89,7 +75,7 @@ <%= count %> <%= sale_item.product_name %> <%= sale_item.qty %> - <%= number_with_precision(sale_item.price, precision: precision.to_i ) %> + <%= number_format(sale_item.price, precision: precision.to_i ) %> <% # end @@ -108,7 +94,7 @@ <%= count %> <%= order_item.item_name %> <%= order_item.qty %> - <%= number_with_precision(order_item.qty*order_item.price, precision: precision.to_i ) %> + <%= number_format(order_item.qty*order_item.price, precision: precision.to_i ) %> <% end @@ -124,7 +110,7 @@ - + <%if @sale.discount_type == 'member_discount'%> @@ -132,19 +118,19 @@ <%else%> <%end%> - + - + - + - +
    Sub Total:<%= number_with_precision(sub_total, precision: precision.to_i ) %><%= number_format(sub_total, precision: precision.to_i ) %>
    Discount:(<%= number_with_precision(@sale.total_discount, precision: precision.to_i ) rescue 0%>)(<%= number_format(@sale.total_discount, precision: precision.to_i ) rescue 0%>)
    Tax:<%= number_with_precision(@sale.total_tax, precision: precision.to_i ) rescue 0%><%= number_format(@sale.total_tax, precision: precision.to_i ) rescue 0%>
    Rounding Adj:<%= number_with_precision(@sale.rounding_adjustment, precision: precision.to_i ) rescue 0%><%= number_format(@sale.rounding_adjustment, precision: precision.to_i ) rescue 0%>
    Grand Total:<%= number_with_precision(@sale.grand_total, precision: precision.to_i ) rescue 0%><%= number_format(@sale.grand_total, precision: precision.to_i ) rescue 0%>
    @@ -163,7 +149,7 @@ <%else%> - <%end%> + <%end%> <% end %> @@ -173,7 +159,7 @@ <% else %>
    + + <% end %> + +
    +
    + + diff --git a/app/views/reports/order_reservation/index.html.erb b/app/views/reports/order_reservation/index.html.erb index bb6265e0..7a1c1431 100755 --- a/app/views/reports/order_reservation/index.html.erb +++ b/app/views/reports/order_reservation/index.html.erb @@ -20,9 +20,9 @@
    <%= t("views.btn.exp_to_excel") %> -
    + + -
    @@ -33,12 +33,12 @@ <% if @shift_from %> - <% if @shift_data.employee %> + <% if @shift_data.employee %> <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> - <% end %> + <% end %> <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> ) - <% end %> + <% end %> <%= t("views.right_panel.detail.receipt_date") %> @@ -62,17 +62,6 @@ - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end %> <% discount_amount = 0.0 delivery_fee = 0.0 @@ -94,8 +83,8 @@ %> <% unless @order_reservation_data.blank? %> <% @order_reservation_data.each do |order_reservation| %> - <% - provider = "" + <% + provider = "" discount_amount = order_reservation.discount_amount delivery_fee = order_reservation.delivery_fee ? order_reservation.delivery_fee : 0.0 convenience_charge = order_reservation.convenience_charge @@ -119,9 +108,9 @@ total_tax += order_reservation.total_tax.to_f total_amount += order_reservation.total_amount.to_f grand_total += order_reservation.grand_total.to_f - - total_transaction_fee += order_reservation.transaction_fee.to_f - + + total_transaction_fee += order_reservation.transaction_fee.to_f + if order_reservation.provider == 'pick_up' provider = "Pick-Up" elsif order_reservation.provider == 'direct_delivery' @@ -147,32 +136,32 @@ <%= provider%> <%= payment_type%> <%= order_reservation.payment_status%> - <%= number_with_precision(order_reservation.total_amount, precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - <%= number_with_precision(discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - <%= number_with_precision(delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - <%= number_with_precision(convenience_charge , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - - <%= number_with_precision(order_reservation.total_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - <%= number_with_precision(order_reservation.grand_total , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %> - <%= number_with_precision(order_reservation.transaction_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %> + <%= number_format(order_reservation.total_amount, precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + <%= number_format(discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + <%= number_format(delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + <%= number_format(convenience_charge , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + + <%= number_format(order_reservation.total_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + <%= number_format(order_reservation.grand_total , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %> + <%= number_format(order_reservation.transaction_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %> - <% end + <% end end %> Total - <%= number_with_precision(total_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - <%= number_with_precision(total_discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - <%= number_with_precision(total_delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - <%= number_with_precision(total_convenience_charge , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - - <%= number_with_precision(total_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - <%= number_with_precision(grand_total , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - <%= number_with_precision(total_transaction_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + <%= number_format(total_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + <%= number_format(total_discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + <%= number_format(total_delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + <%= number_format(total_convenience_charge , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + + <%= number_format(total_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + <%= number_format(grand_total , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + <%= number_format(total_transaction_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> @@ -189,16 +178,16 @@ $('#sel_period').change(function(){ search_by_period(); }); - + function search_by_period(){ var period = $('#sel_period').val(); var period_type = 0; var from = ""; var to = ""; - show_shift_name(period,period_type,from,to,'shift_item'); - } - + show_shift_name(period,period_type,from,to,'shift_item'); + } + // OK button is clicked $('#from').bootstrapMaterialDatePicker().on('beforeChange', function(e, date){ new_date = new Date(date) ; @@ -213,50 +202,50 @@ to = new_date.getDate() + "-" + month + "-" + new_date.getFullYear(); $('#to').val(to) search_by_date(); - }); - + }); + function search_by_date(){ - + from = $("#from").val(); to = $("#to").val(); var period = 0; - var period_type = 1; + var period_type = 1; if(to != '' && from != ''){ shift_name = from + ',' + to; check_arr.push(to); - + if(check_arr.length == 1){ - show_shift_name(period,period_type,from,to,'shift_item'); + show_shift_name(period,period_type,from,to,'shift_item'); } if(check_arr.length == 3){ check_arr = []; } } - + } - + function show_shift_name(period,period_type,from,to,shift_item){ var shift = $('#shift_name'); - + shift.empty(); - + var str = ''; - var param_shift = ''; + var param_shift = ''; var param_shift = '<%= params[:shift_name] rescue '-'%>'; if (from == '' && to == '') { from = $("#from").val(); to = $("#to").val(); } url = '<%= reports_get_shift_by_order_reservation_path %>'; - + $.get(url, {period :period, period_type :period_type, from :from, to :to, report_type :shift_item} , function(data){ str = ''; - $(data.message).each(function(index){ - + $(data.message).each(function(index){ + var local_date = data.message[index].local_opening_date + ' - ' + data.message[index].local_closing_date; var sh_date = data.message[index].opening_date + ' - ' + data.message[index].closing_date; var shift_id = data.message[index].shift_id ; @@ -265,18 +254,18 @@ selected = 'selected = "selected"'; } else{ - selected = ''; - } + selected = ''; + } }else{ - selected = ''; - } + selected = ''; + } str += ''; - + // console.log(sh_date) - }) + }) shift.append(str); }); } }); - \ No newline at end of file + diff --git a/app/views/reports/payment_method/index.html.erb b/app/views/reports/payment_method/index.html.erb index 8dd47a94..ed0ffec3 100755 --- a/app/views/reports/payment_method/index.html.erb +++ b/app/views/reports/payment_method/index.html.erb @@ -57,37 +57,25 @@ <%= t("views.right_panel.detail.giftvoucher_sales") %> - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> <% unless @sale_data.empty? %> <% @sale_data.each do |sale| %> - <%= number_with_precision(sale[:mpu_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_with_precision(sale[:master_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_with_precision(sale[:visa_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_with_precision(sale[:jcb_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_with_precision(sale[:unionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_with_precision(sale[:alipay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_with_precision(sale[:kbzpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - - <%= number_with_precision(sale[:dinga_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_with_precision(sale[:junctionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_with_precision(sale[:paypar_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_with_precision(sale[:cash_amount]-sale[:total_change_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_with_precision(sale[:credit_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_with_precision(sale[:foc_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_with_precision(sale[:giftvoucher_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(sale[:mpu_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(sale[:master_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(sale[:visa_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(sale[:jcb_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(sale[:unionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(sale[:alipay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(sale[:kbzpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + + <%= number_format(sale[:dinga_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(sale[:junctionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(sale[:paypar_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(sale[:cash_amount]-sale[:total_change_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(sale[:credit_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(sale[:foc_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(sale[:giftvoucher_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <% end %> @@ -135,11 +123,11 @@ <%= payment.payment_method rescue '-' %> <%= payment.sale.customer.name rescue '-' %> <% if payment.payment_method === 'cash' %> - <%= number_with_precision(payment.payment_amount - payment.change_amount , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(payment.payment_amount - payment.change_amount , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <%else%> - <%= number_with_precision(payment.payment_amount , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(payment.payment_amount , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <%end%> - <%= number_with_precision(payment.sale.grand_total , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(payment.sale.grand_total , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> @@ -147,7 +135,7 @@ <%if total>0%> Total - <%=number_with_precision(total , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%=number_format(total , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <%end%> diff --git a/app/views/reports/payment_method/index.xls.erb b/app/views/reports/payment_method/index.xls.erb index 723a9ffd..a6fcf35d 100755 --- a/app/views/reports/payment_method/index.xls.erb +++ b/app/views/reports/payment_method/index.xls.erb @@ -8,9 +8,9 @@
    - + - <% if @shift_from %> - <% if @shift_data.employee %> + <% if @shift_data.employee %> <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> - <% end %> + <% end %> @@ -44,40 +44,28 @@ - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> <% unless @sale_data.empty? %> <% @sale_data.each do |sale| %> - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + <% end %> - + <% end %>
    + <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%> @@ -18,9 +18,9 @@
    <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> ) <%= t("views.right_panel.detail.giftvoucher_sales") %>
    <%= number_with_precision(sale[:mpu_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_with_precision(sale[:master_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_with_precision(sale[:visa_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_with_precision(sale[:jcb_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_with_precision(sale[:unionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_with_precision(sale[:alipay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_with_precision(sale[:kbzpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_with_precision(sale[:dinga_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_with_precision(sale[:junctionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_with_precision(sale[:paypar_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_with_precision(sale[:cash_amount]-sale[:total_change_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_with_precision(sale[:credit_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_with_precision(sale[:foc_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_with_precision(sale[:giftvoucher_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:mpu_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:master_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:visa_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:jcb_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:unionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:alipay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:kbzpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:dinga_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:junctionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:paypar_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:cash_amount]-sale[:total_change_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:credit_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:foc_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(sale[:giftvoucher_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %>
    @@ -92,7 +80,7 @@ All Payment Details <%end%> - + <%= t("views.right_panel.detail.shift_name") %> <%= t("views.right_panel.detail.receipt_no") %> @@ -109,9 +97,9 @@ <% if payment.payment_method === 'cash' total += payment.payment_amount - payment.change_amount else - total += payment.payment_amount - end%> - + total += payment.payment_amount + end%> + <% if @shift_from.nil? && @shift_to.nil? %> <%= payment.sale_date.utc.getlocal.strftime("%e %b %I:%M%p") rescue '-'%> <% else %> @@ -122,19 +110,19 @@ <%= payment.payment_method rescue '-' %> <%= payment.sale.customer.name rescue '-' %> <% if payment.payment_method === 'cash' %> - <%= number_with_precision(payment.payment_amount - payment.change_amount , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(payment.payment_amount - payment.change_amount , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <%else%> - <%= number_with_precision(payment.payment_amount , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(payment.payment_amount , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <%end%> - <%= number_with_precision(payment.sale.grand_total , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - + <%= number_format(payment.sale.grand_total , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + - + <% end %> <%if total>0%> Total - <%=number_with_precision(total , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%=number_format(total , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <%end%> @@ -142,4 +130,4 @@
    - \ No newline at end of file + diff --git a/app/views/reports/product_sale/index.html.erb b/app/views/reports/product_sale/index.html.erb index 5cd38e52..3b55b28b 100644 --- a/app/views/reports/product_sale/index.html.erb +++ b/app/views/reports/product_sale/index.html.erb @@ -11,7 +11,7 @@
    @@ -25,18 +25,7 @@
    -
    - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end %> +
    @@ -47,7 +36,7 @@ - + <% unless @sale_data.blank? %> @@ -57,7 +46,7 @@ <% total_qty = 0 %> <% total_item = {} %> <% total_data = {} %> - <% @sale_data.each do |sale| + <% @sale_data.each do |sale| if !total_item.has_key?(sale.item_code) grand_total += sale.grand_total total_item[sale.item_code] = sale.total_item @@ -66,25 +55,25 @@ if sale.status_type == "void" total_item[sale.item_code] += sale.total_item end - if sale.status_type == "void" || sale.status_type == "Discount" || sale.status_type == "foc" + if sale.status_type == "void" || sale.status_type == "Discount" || sale.status_type == "foc" total_data[sale.item_code] += sale.grand_total grand_total += sale.grand_total - end - end + end + end end %> <% @sale_data.each do |sale| %> <% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion" - total_qty += sale.total_item + total_qty += sale.total_item end %> <% if sale.status_type == "foc" && sale.price > 0 total_qty += sale.total_item end %> - + <% if sale.status_type != "Discount" && sale.price.to_f >= 0 %> - <% if !cate_arr.include?(sale.menu_category_id) %> + <% if !cate_arr.include?(sale.menu_category_id) %> <% cate_arr.push(sale.menu_category_id) %> <% else %> @@ -96,8 +85,8 @@ - - + + @@ -107,9 +96,9 @@ - + - + <% end %>
    <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %> <%= t("views.right_panel.detail.total") %>
     <%= sale.menu_category_name %><%= sale.item_code rescue '-' %> <%= sale.product_name rescue '-' %> <%= total_item[sale.item_code] rescue '-' %><%= number_with_precision(total_data[sale.item_code] , precision:precision.to_i,delimiter:delimiter) rescue '-' %><%= number_format(total_data[sale.item_code] , precision:precision.to_i,delimiter:delimiter) rescue '-' %>
    Total <%= total_qty %><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %><%= number_format(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %>
    @@ -123,9 +112,9 @@ $(function(){ $('#order_by').val('<%= @order_by %>'); }); - + $('#order_by').on('change', function(){ var order_by = $("#order_by").val(); window.location.href = "?order_by=" + order_by; }); - \ No newline at end of file + diff --git a/app/views/reports/receipt_no/index.html.erb b/app/views/reports/receipt_no/index.html.erb index 419a5b10..264ee13a 100755 --- a/app/views/reports/receipt_no/index.html.erb +++ b/app/views/reports/receipt_no/index.html.erb @@ -60,18 +60,6 @@ - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end %> - <% grand_total = 0 %> <% old_grand_total = 0 %> <% after_rounding = 0 %> @@ -81,40 +69,21 @@ <% discount_amt = 0 %> <% other_amt = 0 %> <% total_nett = 0 %> - <% rounding_adj = 0%> <% gov_tax = 0 %> <% service_charge = 0 %> - <% tax_profile_count = @tax_profiles.length %> + <% rounding_adj = 0%> + <% gov_tax = 0 %> + <% service_charge = 0 %> - <% - ttax_count = tax_profile_count - @sale_taxes.length - ttax_flag = true - @sale_taxes.each do |tax| - if tax.tax_name.downcase.include?("service") - ttax_flag = false - end - end - %> + <% if !@sale_data.nil? %> - - <%if !@sale_data.nil? %> <% @sale_data.each do |result| %> - <% grand_total += result.grand_total.to_f %> <% old_grand_total += result.grand_total.to_f - result.rounding_adjustment.to_f %> <% total_tax += result.total_tax.to_f %> <% total_sum += result.total_amount.to_f %> <% discount_amt += result.total_discount.to_f %> <% rounding_adj += result.rounding_adjustment.to_f %> - <% sale_tax_count = result.sale_taxes.length %> - <% tax_count = tax_profile_count - sale_tax_count %> - <% tax_flag = true %> - <% result.sale_taxes.each do |tax| - if tax.tax_name.downcase.include?("service") - tax_flag = false - end - end %> - <%if result.type %> <%= result.type %> - <%= result.name %> @@ -124,35 +93,18 @@ <%= result.receipt_no rescue '-' %> <%= result.cashier_name rescue '-' %> - <%= number_with_precision(result.total_amount, precision: precision.to_i, delimiter: delimiter) %> - <%= number_with_precision(result.total_discount, precision: precision.to_i, delimiter: delimiter) rescue '0' %> - - <% if !result.sale_taxes.empty? %> - <% num = 1 %> - <% if tax_flag && tax_count > 0 %> - <% while num <= tax_count %> - <%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <% num += 1 %> - <% end %> - <% end %> - <% result.sale_taxes.each do |tax| %> - <%= number_with_precision(tax.tax_payable_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <%end%> - <% num = 1 %> - <% if !tax_flag && tax_count > 0 %> - <% while num <= tax_count %> - <%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <% num += 1 %> - <% end %> - <% end %> - <% else %> - <% @tax_profiles.each do |tax| %> - <%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <% end %> - <%end%> - <%= number_with_precision(result.grand_total - result.rounding_adjustment, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <%= number_with_precision(result.rounding_adjustment.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <%= number_with_precision(result.grand_total, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <%= number_format(result.total_amount, precision: precision.to_i, delimiter: delimiter) %> + <%= number_format(result.total_discount, precision: precision.to_i, delimiter: delimiter) rescue '0' %> + <% @tax_profiles.each do |tax| %> + <% if sale_tax = result.sale_taxes.find { |sale_tax| sale_tax.tax_name == tax.name } %> + <%= number_format(sale_tax.tax_payable_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <% else %> + <%= number_format(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <% end %> + <% end %> + <%= number_format(result.grand_total - result.rounding_adjustment, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <%= number_format(result.rounding_adjustment.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <%= number_format(result.grand_total, precision: precision.to_i, delimiter: delimiter) rescue '-' %> <% if @lookup.value.to_i == 1 %> @@ -170,34 +122,18 @@ <% end %>   - <%= number_with_precision(total_sum, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <%= number_with_precision(discount_amt, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <% if !@sale_taxes.empty? %> - <% num = 1 - if ttax_flag && ttax_count > 0 %> - <% while num <= ttax_count %> - <%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) %> - <% num += 1 - end %> - <% end %> - <% @sale_taxes.each do |tax| %> - <%= number_with_precision(tax.st_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <%end%> - <% num = 1 - if ttax_flag==false && ttax_count > 0 %> - <% while num <= ttax_count %> - <%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) %> - <% num += 1 - end %> - <% end %> - <% else %> - <% @tax_profiles.each do |tax| %> - <%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <% end %> - <%end%> - <%= number_with_precision(old_grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '0' %> - <%= number_with_precision(rounding_adj.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <%= number_with_precision(grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <%= number_format(total_sum, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <%= number_format(discount_amt, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <% @tax_profiles.each do |tax| %> + <% if sale_tax = @sale_taxes.find { |sale_tax| sale_tax.tax_name == tax.name } %> + <%= number_format(sale_tax.st_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <% else %> + <%= number_format(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <% end %> + <% end %> + <%= number_format(old_grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '0' %> + <%= number_format(rounding_adj.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <%= number_format(grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %> diff --git a/app/views/reports/receipt_no/index.xls.erb b/app/views/reports/receipt_no/index.xls.erb index 29d8abe4..ce7f8f8a 100755 --- a/app/views/reports/receipt_no/index.xls.erb +++ b/app/views/reports/receipt_no/index.xls.erb @@ -40,17 +40,6 @@ - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end %> <% grand_total = 0 %> <% old_grand_total = 0 %> @@ -61,20 +50,11 @@ <% discount_amt = 0 %> <% other_amt = 0 %> <% total_nett = 0 %> - <% rounding_adj = 0%> <% gov_tax = 0 %> <% service_charge = 0 %> - <% tax_profile_count = @tax_profiles.length %> + <% rounding_adj = 0%> + <% gov_tax = 0 %> + <% service_charge = 0 %> - <% - ttax_count = tax_profile_count - @sale_taxes.length - ttax_flag = true - @sale_taxes.each do |tax| - if tax.tax_name.downcase.include?("service") - ttax_flag = false - end - end - %> - - <%if @sale_data %> + <% if @sale_data %> <% @sale_data.each do |result| %> <% grand_total += result.grand_total.to_f %> @@ -83,14 +63,7 @@ <% total_sum += result.total_amount.to_f %> <% discount_amt += result.total_discount.to_f %> <% rounding_adj += result.rounding_adjustment.to_f %> - <% sale_tax_count = result.sale_taxes.length %> - <% tax_count = tax_profile_count - sale_tax_count %> - <% tax_flag = true %> - <% result.sale_taxes.each do |tax| - if tax.tax_name.downcase.include?("service") - tax_flag = false - end - end %> + <%if result.type %> @@ -101,66 +74,34 @@ <%= result.receipt_no rescue '-' %> <%= result.cashier_name rescue '-' %> - <%= number_with_precision(result.total_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <%= number_with_precision(result.total_discount, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <% if !result.sale_taxes.empty? %> - <% num = 1 %> - <% if tax_flag && tax_count > 0 %> - <% while num <= tax_count %> - <%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <% num += 1 %> - <% end %> - <% end %> - <% result.sale_taxes.each do |tax| %> - <%= number_with_precision(tax.tax_payable_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(result.total_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <%= number_format(result.total_discount, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <% @tax_profiles.each do |tax| %> + <% if sale_tax = result.sale_taxes.find { |sale_tax| sale_tax.tax_name == tax.name } %> + <%= number_format(sale_tax.tax_payable_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <% else %> + <%= number_format(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %> <% end %> - <% num = 1 - if tax_flag==false && tax_count > 0 %> - <% while num <= tax_count %> - <%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <% num += 1 - end %> - <% end %> - <% else %> - <% @tax_profiles.each do |tax| %> - <%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <% end %> - <%end%> - <%= number_with_precision(result.grand_total - result.rounding_adjustment, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <%= number_with_precision(result.rounding_adjustment.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <%= number_with_precision(result.grand_total, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <% end %> + <%= number_format(result.grand_total - result.rounding_adjustment, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <%= number_format(result.rounding_adjustment.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <%= number_format(result.grand_total, precision: precision.to_i, delimiter: delimiter) rescue '-' %> <% end %>   - <%= number_with_precision(total_sum, precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_with_precision(discount_amt, precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <% if !@sale_taxes.empty? %> - <% num = 1 - if ttax_flag && ttax_count > 0 %> - <% while num <= ttax_count %> - <%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <% num += 1 - end %> - <% end %> - <% @sale_taxes.each do |tax| %> - <%= number_with_precision(tax.st_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%end%> - <% num = 1 - if ttax_flag==false && ttax_count > 0 %> - <% while num <= ttax_count %> - <%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <% num += 1 - end %> - <% end %> - <% else %> - <% @tax_profiles.each do |tax| %> - <%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <% end %> - <%end%> - <%= number_with_precision(old_grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '0' %> - <%= number_with_precision(rounding_adj.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %> - <%= number_with_precision(grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <%= number_format(total_sum, precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <%= number_format(discount_amt, precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <% @tax_profiles.each do |tax| %> + <% if sale_tax = @sale_taxes.find { |sale_tax| sale_tax.tax_name == tax.name } %> + <%= number_format(sale_tax.st_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <% else %> + <%= number_format(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <% end %> + <% end %> + <%= number_format(old_grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '0' %> + <%= number_format(rounding_adj.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <%= number_format(grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %>   diff --git a/app/views/reports/receipt_no_detail/index.html.erb b/app/views/reports/receipt_no_detail/index.html.erb index a0db863b..9f5841a2 100755 --- a/app/views/reports/receipt_no_detail/index.html.erb +++ b/app/views/reports/receipt_no_detail/index.html.erb @@ -34,43 +34,30 @@ <% end %> - <%= t("views.right_panel.detail.shift_name") %> - <%= t("views.right_panel.detail.table") %> - <%= t("views.right_panel.detail.receipt_no") %> - <%= t :cashier %> <%= t("views.right_panel.detail.name") %> - <%= t("views.right_panel.detail.revenue") %> + <%= t("views.right_panel.detail.shift_name") %> + <%= t("views.right_panel.detail.table") %> + <%= t("views.right_panel.detail.receipt_no") %> + <%= t :cashier %> <%= t("views.right_panel.detail.name") %> + <%= t("views.right_panel.detail.revenue") %>   - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> <% grand_total = 0 %> <% @sale_data.each do |result| %> <% table_name=nil table_type =nil - if result.table_id.to_i>0 - table = DiningFacility.find(result.table_id) + if table = result.bookings[0].dining_facility table_type = table.type table_name = table.name end %> - <% grand_total = grand_total.to_f + result.grand_total.to_f%> + <% grand_total = grand_total + result.grand_total %> <%= @shift_from %> - <%= @shift_to %> <%= table_type %> - <%= table_name %> <%= result.receipt_no rescue '-' %> <%= result.cashier_name rescue '-' %> - <%= number_with_precision(result.grand_total, precision:precision.to_i,delimiter:delimiter) %> + <%= number_format(result.grand_total, precision: precision, delimiter: delimiter) %> @@ -85,8 +72,8 @@ <% result.sale_items.each do |item|%> - <% if item.price.to_i < 0.to_i %> - <% if item.qty.to_i < 0.to_i%> + <% if item.price < 0 %> + <% if item.qty < 0 %> [PROMO QTY]<%= item.product_name rescue '-' %> <% else %> [PROMO PRICE]<%= item.product_name rescue '-' %> @@ -96,15 +83,15 @@ <% end %> <%= item.qty rescue '-' %> - <%= number_with_precision(item.unit_price, precision:precision.to_i,delimiter:delimiter) rescue '-' %> - <%= number_with_precision(item.price, precision:precision.to_i,delimiter:delimiter) rescue '-' %> - <%=l item.created_at.utc.getlocal, :format => :short rescue '-' %> + <%= number_format(item.unit_price, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) rescue '-' %> + <%= number_format(item.price, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) rescue '-' %> + <%=l item.created_at.getlocal, :format => :short rescue '-' %> <% end %>   - <%survey = Survey.find_by_receipt_no(result.receipt_no)%> + <%survey = result.survey%> <% if !survey.nil?%>   @@ -120,19 +107,19 @@     <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %> - <%= number_with_precision(result.total_amount, precision:precision.to_i,delimiter:delimiter) %> + <%= number_format(result.total_amount, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) %>   <% end %> - <% if result.total_discount.to_f > 0 %> + <% if result.total_discount > 0 %>     <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> - - <%= number_with_precision(result.total_discount, precision:precision.to_i,delimiter:delimiter) %> + - <%= number_format(result.total_discount, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) %>   <% end %> @@ -142,39 +129,38 @@     Tax Amount - <%= number_with_precision(result.total_tax, precision:precision.to_i,delimiter:delimiter) %> + <%= number_format(result.total_tax, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) %>   <% end %> - <% sale_payments = SalePayment.get_sale_payments(result) %> + <% sale_payments = result.sale_payments %> <% if sale_payments.length > 0%> <% sale_payments.each do |rec| %> - <%if rec.payment_amount.to_f > 0 %> + <% next if rec.payment_method == 'credit_note' && result.payments_for_credits_amount < rec.payment_amount %> + +   +   + Payment <%= rec.payment_method.upcase %> + <%= number_format(rec.payment_amount, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) %> ( <%= rec.payment_status %> ) +   + + + <% if !rec.payment_reference.nil? %>     - Payment <%= rec.payment_method.upcase %> - <%= number_with_precision(rec.payment_amount, precision:precision.to_i,delimiter:delimiter) %> ( <%= rec.payment_status %> ) + Payment Ref. + <%= rec.payment_reference %>   - - <% if !rec.payment_reference.nil? %> - -   -   - Payment Ref. - <%= rec.payment_reference %> -   - - <% end %> <% end %> <% end %> - <% if result.amount_changed != 0 && !result.amount_changed.nil? %> + <% if result.amount_changed != 0 %>     <%= t("views.right_panel.detail.change") %> <%= t("views.right_panel.detail.amount") %> - <%= number_with_precision(result.amount_changed, precision:precision.to_i,delimiter:delimiter) %> + <%= number_format(result.amount_changed, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) %>   <% end %> @@ -196,7 +182,7 @@       - Total Nett - <%= number_with_precision(grand_total, precision:precision.to_i,delimiter:delimiter) %> + Total Nett - <%= number_format(grand_total, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) %>   diff --git a/app/views/reports/saleitem/index.html.erb b/app/views/reports/saleitem/index.html.erb index 5abe8a0b..c9b44db4 100644 --- a/app/views/reports/saleitem/index.html.erb +++ b/app/views/reports/saleitem/index.html.erb @@ -46,18 +46,6 @@ - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> <% acc_arr = Array.new %> <% cate_arr = Array.new %> <% p_qty = 0 %> @@ -111,7 +99,7 @@ <% @totalByAccount.each do |account, total| %> <% if sale.account_id == account %> - <%= number_with_precision(total, precision:precision.to_i,delimiter:delimiter) %> + <%= number_format(total, precision:precision.to_i,delimiter:delimiter) %> <% grand_total += total %> <% end %> <% end %> @@ -135,8 +123,8 @@ <%= sale.total_item*(-1) rescue '-' %> <% end %> - <%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%> @@ -161,7 +149,7 @@ Total <%= sale.account_name %> Qty <%= sub_qty %> <%= t("views.right_panel.detail.sub_total") %> - <%= number_with_precision(sub_total , precision:precision.to_i,delimiter:delimiter)%> + <%= number_format(sub_total , precision:precision.to_i,delimiter:delimiter)%> <% sub_total = 0.0%> <% sub_qty = 0 %> @@ -191,8 +179,8 @@ <%= product.product_code rescue '-' %> <%= product.product_name rescue '-' %> <%= product.total_item rescue '-' %> - <%= number_with_precision(product.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <%= number_with_precision(product.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(product.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(product.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%> @@ -205,7 +193,7 @@ <%= p_qty %> <%= t("views.right_panel.detail.sub_total") %> - <%= number_with_precision(product_sub_total , precision:precision.to_i,delimiter:delimiter)%> + <%= number_format(product_sub_total , precision:precision.to_i,delimiter:delimiter)%> <%end%> @@ -229,8 +217,8 @@ <%= other.item_code rescue '-' %> <%= other.product_name rescue '-' %> <%= other.total_item rescue '-' %> - <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%> @@ -240,7 +228,7 @@   <%= t("views.right_panel.detail.sub_total") %> - <%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%> + <%= number_format(other_sub_total , precision:precision.to_i,delimiter:delimiter)%> <%end%> @@ -249,18 +237,18 @@ <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %> <%= total_qty%> <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %> - <%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter)%> + <%= number_format(grand_total , precision:precision.to_i,delimiter:delimiter)%> <% if @type =="" || @type =="all" || @type.nil? %>   Total FOC Amount - <%= number_with_precision(@foc_data , precision:precision.to_i,delimiter:delimiter)%> + <%= number_format(@foc_data , precision:precision.to_i,delimiter:delimiter)%>   <%= t("views.right_panel.detail.net_amount") %> - <%= number_with_precision(grand_total -@foc_data , precision:precision.to_i,delimiter:delimiter)%> + <%= number_format(grand_total -@foc_data , precision:precision.to_i,delimiter:delimiter)%> <% end %> <% end %> @@ -282,8 +270,8 @@ <%= other.item_code rescue '-' %> <%= other.product_name rescue '-' %> <%= other.total_item rescue '-' %> - <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%> @@ -293,7 +281,7 @@   <%= t("views.right_panel.detail.sub_total") %> - <%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%> + <%= number_format(other_sub_total , precision:precision.to_i,delimiter:delimiter)%> <%end%> diff --git a/app/views/reports/saleitem/index.xls.erb b/app/views/reports/saleitem/index.xls.erb index 799ede63..6c04d8bd 100755 --- a/app/views/reports/saleitem/index.xls.erb +++ b/app/views/reports/saleitem/index.xls.erb @@ -9,7 +9,7 @@
    -
    +
    @@ -17,9 +17,9 @@ <% if @shift_from %> - <% if @shift_data.employee %> + <% if @shift_data.employee %> <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> - <% end %> + <% end %> <% end %> @@ -31,23 +31,11 @@ - + - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> <% acc_arr = Array.new %> - <% cate_arr = Array.new %> + <% cate_arr = Array.new %> <% p_qty = 0 %> <% sub_qty = 0 %> <% sub_total = 0 %> @@ -67,7 +55,7 @@ <% unless @sale_data.blank? %> <% @sale_data.each do |sale| %> - + <% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion" total_qty += sale.total_item end %> @@ -81,20 +69,20 @@ total_qty += sale.total_item end %> - + <% if sale.status_type == "foc" && sale.grand_total < 0 total_item_foc += sale.grand_total*(-1) - end %> + end %> <% if sale.status_type == "Discount" && sale.grand_total < 0 total_item_dis += sale.grand_total*(-1) end %> <% if !acc_arr.include?(sale.account_id) %> - + <% @totalByAccount.each do |account, total| %> <% if sale.account_id == account %> - - <% grand_total += total %> + + <% grand_total += total %> <% end %> <% end %> <% acc_arr.push(sale.account_id) %> @@ -109,15 +97,15 @@ <%else%> <% end %> - - - + + + <% @menu_cate_count.each do |key,value| %> <% if sale.account_id == key %> - <% count = count + 1 %> + <% count = count + 1 %> <% sub_total += sale.grand_total %> <% #sub_qty += sale.total_item %> <% if sale.status_type !="Discount" && (!sale.product_name.include? "FOC") && sale.status_type != "promotion" @@ -130,7 +118,7 @@ <% if sale.remark == "promotion" sub_qty += sale.total_item end %> - <% if count == value %> + <% if count == value %> <% sub_total = 0.0%> <% sub_qty = 0 %> <% count = 0%> @@ -141,7 +129,7 @@ <% end %> <% if @product.present?%> - + @@ -159,13 +147,13 @@ - - + + - + <% product_sub_total += product.grand_total %> - + <% end %> @@ -173,14 +161,14 @@ - + <%end%> <% if @type == "other" || @other_charges.present?%> - + @@ -197,18 +185,18 @@ - - + + - + <% other_sub_total += other.grand_total %> - + <% end %> - + <%end%> @@ -217,23 +205,23 @@ - + <% if @type =="" || @type =="all" %> - + - + <% end %> <% end %> <% if @type == "other"%> - + @@ -250,18 +238,18 @@ - - + + - + <% other_sub_total += other.grand_total %> - + <% end %> - + <%end%> @@ -285,4 +273,4 @@ $('.foc_payment').hide(); } }); - \ No newline at end of file + diff --git a/app/views/reports/saleitem/indexbackup.html.erb b/app/views/reports/saleitem/indexbackup.html.erb index 3c03dec2..54e10304 100644 --- a/app/views/reports/saleitem/indexbackup.html.erb +++ b/app/views/reports/saleitem/indexbackup.html.erb @@ -16,11 +16,11 @@ +
    -
    +
    <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
    <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %> <%= t("views.right_panel.detail.unit_price") %> <%= t("views.right_panel.detail.revenue") %>
    <%= sale.total_item*(-1) rescue '-' %><%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
    Product  <%= product.product_code rescue '-' %> <%= product.product_name rescue '-' %> <%= product.total_item rescue '-' %> <%= number_with_precision(product.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(product.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(product.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(product.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
     <%= p_qty %> <%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(product_sub_total , precision:precision.to_i,delimiter:delimiter)%><%= number_format(product_sub_total , precision:precision.to_i,delimiter:delimiter)%>
    Other Charges  <%= other.item_code rescue '-' %> <%= other.product_name rescue '-' %> <%= other.total_item rescue '-' %> <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
      <%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%><%= number_format(other_sub_total , precision:precision.to_i,delimiter:delimiter)%>
    <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %> <%= total_qty%> <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter)%><%= number_format(grand_total , precision:precision.to_i,delimiter:delimiter)%>
      Total FOC Amount<%= number_with_precision(@foc_data , precision:precision.to_i,delimiter:delimiter)%><%= number_format(@foc_data , precision:precision.to_i,delimiter:delimiter)%>
      <%= t("views.right_panel.detail.net_amount") %><%= number_with_precision(grand_total -@foc_data , precision:precision.to_i,delimiter:delimiter)%><%= number_format(grand_total -@foc_data , precision:precision.to_i,delimiter:delimiter)%>
    Other Charges  <%= other.item_code rescue '-' %> <%= other.product_name rescue '-' %> <%= other.total_item rescue '-' %> <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
      <%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%><%= number_format(other_sub_total , precision:precision.to_i,delimiter:delimiter)%>
    @@ -28,9 +28,9 @@ <% if @shift_from %> - <% if @shift_data.employee %> + <% if @shift_data.employee %> <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> - <% end %> + <% end %> <% end %> @@ -42,24 +42,12 @@ - + - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> <% unless @sale_data.blank? %> <% acc_arr = Array.new %> - <% cate_arr = Array.new %> + <% cate_arr = Array.new %> <% sub_qty = 0 %> <% sub_total = 0 %> @@ -87,7 +75,7 @@ <% if sale.status_type == "foc" && sale.grand_total < 0 total_item_foc += sale.grand_total*(-1) - end %> + end %> <% if sale.status_type == "Discount" && sale.grand_total < 0 total_item_dis += sale.grand_total*(-1) @@ -101,8 +89,8 @@ @@ -111,7 +99,7 @@ <% end %> - <% if !cate_arr.include?(sale.menu_category_id) %> + <% if !cate_arr.include?(sale.menu_category_id) %> <% cate_arr.push(sale.menu_category_id) %> <% else %> @@ -120,27 +108,27 @@ - - + + <% @menu_cate_count.each do |key,value| %> <% if sale.account_id == key %> - <% count = count + 1 %> + <% count = count + 1 %> <% sub_total += sale.grand_total %> <% #sub_qty += sale.total_item %> <% if sale.status_type!="Discount" && (!sale.product_name.include? "FOC") sub_qty += sale.total_item end %> - <% if count == value %> + <% if count == value %> - + <% sub_total = 0.0%> <% sub_qty = 0 %> @@ -168,18 +156,18 @@ - - + + - + <% other_sub_total += other.grand_total %> - + <% end %> - + <%end%> @@ -188,25 +176,25 @@ - + <% end %> - + - + @@ -214,11 +202,11 @@ - - + + <% @sale_taxes.each do |tax| %> - +
    <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
    <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %> <%= t("views.right_panel.detail.unit_price") %> <%= t("views.right_panel.detail.revenue") %>
    <% @totalByAccount.each do |account, total| %> <% if sale.account_id == account %> - <%= number_with_precision(total, precision:precision.to_i,delimiter:delimiter) %> - <% grand_total += total %> + <%= number_format(total, precision:precision.to_i,delimiter:delimiter) %> + <% grand_total += total %> <% end %> <% end %>
     <%= sale.menu_category_name %><%= sale.item_code rescue '-' %> <%= sale.product_name rescue '-' %> <%= sale.total_item rescue '-' %><%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
      Total <%= sale.account_name %> Qty <%= sub_qty %> <%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(sub_total , precision:precision.to_i,delimiter:delimiter)%> <%= number_format(sub_total , precision:precision.to_i,delimiter:delimiter)%>
    <%= other.item_code rescue '-' %> <%= other.product_name rescue '-' %> <%= other.total_item rescue '-' %> <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
      <%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%><%= number_format(other_sub_total , precision:precision.to_i,delimiter:delimiter)%>
    <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %> <%= total_qty%> <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter)%><%= number_format(grand_total , precision:precision.to_i,delimiter:delimiter)%>
      <%= t("views.right_panel.detail.foc_item") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(total_item_foc , precision:precision.to_i,delimiter:delimiter) %><%= number_format(total_item_foc , precision:precision.to_i,delimiter:delimiter) %>
      <%= t("views.right_panel.detail.item_discount") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(total_item_dis , precision:precision.to_i,delimiter:delimiter) %><%= number_format(total_item_dis , precision:precision.to_i,delimiter:delimiter) %>
      <%= t("views.right_panel.detail.foc_sales") %> - <%= number_with_precision(@foc_data, precision:precision.to_i, delimiter:delimiter) %> + <%= number_format(@foc_data, precision:precision.to_i, delimiter:delimiter) %>
    <%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> - <%= number_with_precision(@discount_data , precision: precision.to_i,delimiter: delimiter) %> + <%= number_format(@discount_data , precision: precision.to_i,delimiter: delimiter) %>
    <%= number_with_precision(grand_total.to_f - @discount_data.to_f , precision:precision.to_i,delimiter:delimiter)%><%= number_format(grand_total.to_f - @discount_data.to_f , precision:precision.to_i,delimiter:delimiter)%>
    @@ -259,14 +247,14 @@ if(search){ if(parseInt(search) == 0){ - search_by_period(); + search_by_period(); } else{ - search_by_date(); + search_by_date(); } }else{ - search_by_period(); - } + search_by_period(); + } $('#sel_period').change(function(){ search_by_period(); @@ -278,8 +266,8 @@ var from = ""; var to = ""; - show_shift_name(period,period_type,from,to,'shift_item'); - } + show_shift_name(period,period_type,from,to,'shift_item'); + } // OK button is clicked $('#from').bootstrapMaterialDatePicker().on('beforeChange', function(e, date){ @@ -295,13 +283,13 @@ to = new_date.getDate() + "-" + month + "-" + new_date.getFullYear(); $('#to').val(to) search_by_date(); - }); + }); function search_by_date(){ from = $("#from").val(); to = $("#to").val(); var period = 0; - var period_type = 1; + var period_type = 1; if(to != '' && from != ''){ shift_name = from + ',' + to; @@ -310,7 +298,7 @@ console.log(check_arr.length) if(check_arr.length == 1){ - show_shift_name(period,period_type,from,to,'shift_item'); + show_shift_name(period,period_type,from,to,'shift_item'); } if(check_arr.length == 3){ check_arr = []; @@ -329,13 +317,13 @@ var selected = ''; var str = ''; var param_shift = '<%= params[:shift_name]%>'; - + url = '<%= reports_get_shift_by_date_path %>'; $.get(url, {period :period, period_type :period_type, from :from, to :to, report_type :shift_item} , function(data){ console.log(data) str = ''; - $(data.message).each(function(index){ + $(data.message).each(function(index){ var local_date = data.message[index].local_opening_date + ' - ' + data.message[index].local_closing_date; var sh_date = data.message[index].opening_date + ' - ' + data.message[index].closing_date; @@ -346,21 +334,21 @@ selected = 'selected = "selected"'; } else{ - selected = ''; - } + selected = ''; + } } else{ - selected = ''; - } + selected = ''; + } str += ''; // console.log(sh_date) - }) + }) shift.append(str); }); } }); - \ No newline at end of file + diff --git a/app/views/reports/shiftsale/index.html.erb b/app/views/reports/shiftsale/index.html.erb index 40f928f9..5fb10c71 100755 --- a/app/views/reports/shiftsale/index.html.erb +++ b/app/views/reports/shiftsale/index.html.erb @@ -69,18 +69,6 @@ - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> <% void = 0%> <% cash = 0%> <% credit = 0%> @@ -104,16 +92,16 @@ <%= result[:shift_closed_at] ? result[:shift_closed_at].strftime("%e %b %I:%M%p") : '-' %> - <%= number_with_precision(result[:cash_sales].to_f, precision:precision.to_i,delimiter:delimiter) %> - <%= number_with_precision(result[:credit_sales].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(result[:cash_sales].to_f, precision:precision.to_i,delimiter:delimiter) %> + <%= number_format(result[:credit_sales].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <%= number_with_precision(result[:other_sales].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(result[:other_sales].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <%= number_with_precision(result[:foc_sales].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(result[:foc_sales].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <%= number_with_precision(result[:grand_total].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(result[:grand_total].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= link_to "Print", reports_get_shift_id_path(result[:shift_id].to_i), class:"btn btn-info wave-effects" %> @@ -134,15 +122,15 @@ - <%= number_with_precision(cash, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <%= number_with_precision(credit, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(cash, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(credit, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <%= number_with_precision(card, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <%= number_with_precision(foc, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(card, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(foc, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <%= number_with_precision(g_total, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(g_total, precision:precision.to_i,delimiter:delimiter) rescue '-'%> diff --git a/app/views/reports/staff_meal/_staff_meal_report_filter.html.erb b/app/views/reports/staff_meal/_staff_meal_report_filter.html.erb new file mode 100644 index 00000000..04108f48 --- /dev/null +++ b/app/views/reports/staff_meal/_staff_meal_report_filter.html.erb @@ -0,0 +1,146 @@ +
    + <%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %> + <% if period_type != false %> +
    +
    + + +
    + + +
    + + + +
    +
    + + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + <% end %> + + <% end %> +
    + + diff --git a/app/views/reports/staff_meal/index.html.erb b/app/views/reports/staff_meal/index.html.erb new file mode 100644 index 00000000..bfb5ec43 --- /dev/null +++ b/app/views/reports/staff_meal/index.html.erb @@ -0,0 +1,378 @@ + +
    +
    + <%= render :partial=>'staff_meal_report_filter', + :locals=>{ :period_type => true, :shift_name => true, :report_path =>reports_staff_meal_index_path} %> + +
    + + + +
    +
    +
    + + + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + + + + + <% acc_arr = Array.new %> + <% cate_arr = Array.new %> + <% p_qty = 0 %> + <% sub_qty = 0 %> + <% sub_total = 0 %> + <% other_sub_total = 0 %> + <% product_sub_total = 0 %> + <% count = 0 %> + <% row_count = 0 %> + <% total_price = 0 %> + <% cate_count = 0 %> + <% acc_count = 0 %> + <% grand_total = 0 %> + <% total_qty = 0 %> + <% total_amount = 0 %> + <% discount = 0 %> + <% total_item_foc = 0 %> + <% total_item_dis = 0.0 %> + <% total_tax = 0 %> + <% unless @sale_data.blank? %> + <% @sale_data.each do |sale| %> + <% row_count += 1 %> + + + <% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion" + total_qty += sale.total_item + end %> + <% if sale.status_type == "foc" && sale.price > 0 + total_qty += sale.total_item + end %> + <% if sale.status_type == "Discount" + total_qty += sale.total_item*(-1) + end %> + <% if sale.status_type =="promotion" && @type == "promotion" + total_qty += sale.total_item*(-1) + end %> + + <% if sale.status_type == "foc" && sale.grand_total < 0 + total_item_foc += sale.grand_total*(-1) + end %> + + <% if sale.status_type == "Discount" && sale.grand_total < 0 + total_item_dis += sale.grand_total*(-1) + end %> + + <% if !acc_arr.include?(sale.account_id) %> + + + + + + + <% acc_arr.push(sale.account_id) %> + <% end %> + + + <% if !cate_arr.include?(sale.menu_category_id) %> + + <% cate_arr.push(sale.menu_category_id) %> + <% else %> + + <% end %> + + + <% if sale.status_type != "Discount" %> + + <%else%> + + <% end %> + + + + + + + <% @menu_cate_count.each do |key,value| %> + <% if sale.account_id == key %> + <% count = count + 1 %> + <% sub_total += sale.grand_total %> + <% #sub_qty += sale.total_item %> + <% if sale.status_type !="Discount" && (!sale.product_name.include? "FOC") && sale.status_type != "promotion" + sub_qty += sale.total_item + end %> + <% if sale.status_type =="Discount" + sub_qty += sale.total_item*(-1) + end %> + + <% if sale.status_type == "promotion" && @type == "promotion" + sub_qty += sale.total_item*(-1) + end %> + <% if count == value %> + + + + + + + + <% sub_total = 0.0%> + <% sub_qty = 0 %> + <% count = 0%> + <% end %> + <% end %> + <% end %> + + <% end %> + + <% if @product.present?%> + + + + + + + <% @product.each do |product| %> + <% if product.total_item > 0 + total_qty += product.total_item + end %> + <% grand_total +=product.grand_total + p_qty += product.total_item%> + + + + + + + + + + + + <% product_sub_total += product.grand_total %> + + <% end %> + + + + + + + + + <%end%> + + + + + + + + + + + + + <% if @type =="" || @type =="all" || @type.nil? %> + + + <% end %> + <% end %> + <% if @type == "other"%> + + + + + + + <% @other_charges.each do |other| %> + <% if other.total_item > 0 + total_qty += other.total_item + end %> + <% grand_total +=other.grand_total%> + + + + + + + + + + + + <% other_sub_total += other.grand_total %> + + <% end %> + + + + + + <%end%> + +
    <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
    <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
     <%= t("views.right_panel.header.menu_category") %><%= t("views.right_panel.detail.code") %><%= t("views.right_panel.detail.product") %><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= t("views.right_panel.detail.unit_price") %><%= t("views.right_panel.detail.revenue") %>
    <%= sale.account_name %> <%= t("views.right_panel.detail.total_price_by") %> <%= sale.account_name %> + <% @totalByAccount.each do |account, total| %> + <% if sale.account_id == account %> + <%= number_format(total, precision:precision.to_i,delimiter:delimiter) %> + <% grand_total += total %> + <% end %> + <% end %> +
     <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %><%= sale.product_name rescue '-' %><%= sale.total_item rescue '-' %><%= sale.total_item*(-1) rescue '-' %><%= number_format(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
     Total <%= sale.account_name %> Qty <%= sub_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_format(sub_total , precision:precision.to_i,delimiter:delimiter)%>
    Product 
     Product<%= product.product_code rescue '-' %><%= product.product_name rescue '-' %><%= product.total_item rescue '-' %> <%= number_format(product.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(product.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
     Total Product Qty <%= p_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_format(product_sub_total , precision:precision.to_i,delimiter:delimiter)%>
     <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= total_qty%><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= number_format(grand_total , precision:precision.to_i,delimiter:delimiter)%>
    Other Charges 
     Other Charges<%= other.item_code rescue '-' %><%= other.product_name rescue '-' %><%= other.total_item rescue '-' %> <%= number_format(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
     <%= t("views.right_panel.detail.sub_total") %><%= number_format(other_sub_total , precision:precision.to_i,delimiter:delimiter)%>
    + +
    +
    +
    +
    +
    + + diff --git a/app/views/reports/staff_meal/index.xls.erb b/app/views/reports/staff_meal/index.xls.erb new file mode 100644 index 00000000..50481186 --- /dev/null +++ b/app/views/reports/staff_meal/index.xls.erb @@ -0,0 +1,265 @@ + + + + + + + +
    +
    +
    +
    +
    + + + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + + + + + <% acc_arr = Array.new %> + <% cate_arr = Array.new %> + <% p_qty = 0 %> + <% sub_qty = 0 %> + <% sub_total = 0 %> + <% other_sub_total = 0 %> + <% product_sub_total = 0 %> + <% count = 0 %> + <% row_count = 0 %> + <% total_price = 0 %> + <% cate_count = 0 %> + <% acc_count = 0 %> + <% grand_total = 0 %> + <% total_qty = 0 %> + <% total_amount = 0 %> + <% discount = 0 %> + <% total_item_foc = 0 %> + <% total_item_dis = 0.0 %> + <% total_tax = 0 %> + <% unless @sale_data.blank? %> + <% @sale_data.each do |sale| %> + <% row_count += 1 %> + + + <% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion" + total_qty += sale.total_item + end %> + <% if sale.status_type == "foc" && sale.price > 0 + total_qty += sale.total_item + end %> + <% if sale.status_type == "Discount" + total_qty += sale.total_item*(-1) + end %> + <% if sale.status_type =="promotion" && @type == "promotion" + total_qty += sale.total_item*(-1) + end %> + + <% if sale.status_type == "foc" && sale.grand_total < 0 + total_item_foc += sale.grand_total*(-1) + end %> + + <% if sale.status_type == "Discount" && sale.grand_total < 0 + total_item_dis += sale.grand_total*(-1) + end %> + + <% if !acc_arr.include?(sale.account_id) %> + + + + + + + <% acc_arr.push(sale.account_id) %> + <% end %> + + + <% if !cate_arr.include?(sale.menu_category_id) %> + + <% cate_arr.push(sale.menu_category_id) %> + <% else %> + + <% end %> + + + <% if sale.status_type != "Discount" %> + + <%else%> + + <% end %> + + + + + + + <% @menu_cate_count.each do |key,value| %> + <% if sale.account_id == key %> + <% count = count + 1 %> + <% sub_total += sale.grand_total %> + <% #sub_qty += sale.total_item %> + <% if sale.status_type !="Discount" && (!sale.product_name.include? "FOC") && sale.status_type != "promotion" + sub_qty += sale.total_item + end %> + <% if sale.status_type =="Discount" + sub_qty += sale.total_item*(-1) + end %> + + <% if sale.status_type == "promotion" && @type == "promotion" + sub_qty += sale.total_item*(-1) + end %> + <% if count == value %> + + + + + + + + <% sub_total = 0.0%> + <% sub_qty = 0 %> + <% count = 0%> + <% end %> + <% end %> + <% end %> + + <% end %> + + <% if @product.present?%> + + + + + + + <% @product.each do |product| %> + <% if product.total_item > 0 + total_qty += product.total_item + end %> + <% grand_total +=product.grand_total + p_qty += product.total_item%> + + + + + + + + + + + + <% product_sub_total += product.grand_total %> + + <% end %> + + + + + + + + + <%end%> + + + + + + + + + + + + + <% if @type =="" || @type =="all" || @type.nil? %> + + + <% end %> + <% end %> + <% if @type == "other"%> + + + + + + <% @other_charges.each do |other| %> + <% if other.total_item > 0 + total_qty += other.total_item + end %> + <% grand_total +=other.grand_total%> + + + + + + + + + + + + <% other_sub_total += other.grand_total %> + + <% end %> + + + + + + <%end%> + +
    <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
    <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
     <%= t("views.right_panel.header.menu_category") %><%= t("views.right_panel.detail.code") %><%= t("views.right_panel.detail.product") %><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= t("views.right_panel.detail.unit_price") %><%= t("views.right_panel.detail.revenue") %>
    <%= sale.account_name %> <%= t("views.right_panel.detail.total_price_by") %> <%= sale.account_name %> + <% @totalByAccount.each do |account, total| %> + <% if sale.account_id == account %> + <%= number_format(total, precision:precision.to_i,delimiter:delimiter) %> + <% grand_total += total %> + <% end %> + <% end %> +
     <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %><%= sale.product_name rescue '-' %><%= sale.total_item rescue '-' %><%= sale.total_item*(-1) rescue '-' %><%= number_format(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
     Total <%= sale.account_name %> Qty <%= sub_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_format(sub_total , precision:precision.to_i,delimiter:delimiter)%>
    Product 
     Product<%= product.product_code rescue '-' %><%= product.product_name rescue '-' %><%= product.total_item rescue '-' %> <%= number_format(product.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(product.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
     Total Product Qty <%= p_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_format(product_sub_total , precision:precision.to_i,delimiter:delimiter)%>
     <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= total_qty%><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= number_format(grand_total , precision:precision.to_i,delimiter:delimiter)%>
    Other Charges 
     Other Charges<%= other.item_code rescue '-' %><%= other.product_name rescue '-' %><%= other.total_item rescue '-' %> <%= number_format(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
     <%= t("views.right_panel.detail.sub_total") %><%= number_format(other_sub_total , precision:precision.to_i,delimiter:delimiter)%>
    + +
    +
    +
    +
    +
    + + + diff --git a/app/views/reports/stock_check/index.html.erb b/app/views/reports/stock_check/index.html.erb index fc688d8c..10a24de2 100755 --- a/app/views/reports/stock_check/index.html.erb +++ b/app/views/reports/stock_check/index.html.erb @@ -28,18 +28,6 @@
    - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> @@ -66,14 +54,14 @@ - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> <% total_amount = 0.0 %> <% grand_total = 0.0 %> <% rounding_adjustment = 0.0 %> @@ -73,10 +61,10 @@ - - - - + + + + @@ -88,10 +76,10 @@ <% end %> - - - - + + + +
    <% menu_item = MenuItemInstance.find_by_item_instance_code(result.item_code)%> <% if menu_item.nil? %> - <% if !arr_item_code.include?(result.item_code) %> + <% if !arr_item_code.include?(result.item_code) %> <%= Product.find_by_item_code(result.item_code).name rescue "-" %> <% arr_item_code.push(result.item_code) %> <% else %>   <% end %> <% else %> - <% if !arr_item_code.include?(result.item_code) %> + <% if !arr_item_code.include?(result.item_code) %> <%= menu_item.menu_item.name rescue "-" %> - <%= menu_item.item_instance_name rescue "-" %> <% arr_item_code.push(result.item_code) %> @@ -98,7 +86,7 @@ @@ -108,4 +96,4 @@ - \ No newline at end of file + diff --git a/app/views/reports/stock_check/index.xls.erb b/app/views/reports/stock_check/index.xls.erb index 8fa98977..34f32968 100755 --- a/app/views/reports/stock_check/index.xls.erb +++ b/app/views/reports/stock_check/index.xls.erb @@ -66,7 +66,7 @@ diff --git a/app/views/reports/void_sale/index.html.erb b/app/views/reports/void_sale/index.html.erb index e7ea05ea..3b619848 100755 --- a/app/views/reports/void_sale/index.html.erb +++ b/app/views/reports/void_sale/index.html.erb @@ -52,18 +52,6 @@
    <%= item.receipt_no rescue '-' %> <%= item.receipt_date.utc.getlocal.strftime("%e %b %I:%M%p") rescue '-' %><%= number_with_precision(item.total_amount.to_f, precision: precision.to_i ,delimiter: delimiter) %> <%= number_with_precision(item.grand_total.to_f , precision: precision.to_i ,delimiter: delimiter) rescue '-'%> <%= number_with_precision(item.rounding_adjustment.to_f, precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_with_precision(item.grand_total.to_f + item.rounding_adjustment.to_f , precision: precision.to_i ,delimiter: delimiter) rescue '-'%> <%= number_format(item.total_amount.to_f, precision: precision.to_i ,delimiter: delimiter) %> <%= number_format(item.grand_total.to_f , precision: precision.to_i ,delimiter: delimiter) rescue '-'%> <%= number_format(item.rounding_adjustment.to_f, precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(item.grand_total.to_f + item.rounding_adjustment.to_f , precision: precision.to_i ,delimiter: delimiter) rescue '-'%>
    Total Void Amount :<%= number_with_precision(total_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_with_precision(grand_total, precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_with_precision(rounding_adjustment, precision: precision.to_i ,delimiter: delimiter) rescue '-'%><%= number_with_precision(grand_rounding_adjustment, precision: precision.to_i ,delimiter: delimiter) rescue '-'%><%= number_format(total_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(grand_total, precision: precision.to_i ,delimiter: delimiter) rescue '-' %><%= number_format(rounding_adjustment, precision: precision.to_i ,delimiter: delimiter) rescue '-'%><%= number_format(grand_rounding_adjustment, precision: precision.to_i ,delimiter: delimiter) rescue '-'%>
    diff --git a/app/views/reports/waste_and_spoilage/index.html.erb b/app/views/reports/waste_and_spoilage/index.html.erb index 57259f2c..afd292f9 100755 --- a/app/views/reports/waste_and_spoilage/index.html.erb +++ b/app/views/reports/waste_and_spoilage/index.html.erb @@ -45,18 +45,6 @@ - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> <% receipt_arr = Array.new %> <% menu_cat_arr = Array.new %> <% footer_arr = Array.new %> @@ -79,8 +67,8 @@ <%= sale.product_name %> <%= sale.product_code.to_i %> <%= sale.qty.to_i %> - <%= number_with_precision(sale.unit_price, precision:precision.to_i,delimiter:delimiter) %> - <%= number_with_precision(sale.price, precision:precision.to_i,delimiter:delimiter) %> + <%= number_format(sale.unit_price, precision:precision.to_i,delimiter:delimiter) %> + <%= number_format(sale.price, precision:precision.to_i,delimiter:delimiter) %> @@ -91,13 +79,13 @@ Total Qty: - <%= number_with_precision(waste_and_spoil_item_count, precision:precision.to_i,delimiter:delimiter) %> + <%= number_format(waste_and_spoil_item_count, precision:precision.to_i,delimiter:delimiter) %> <% waste_and_spoil_item_count = 0%> Grand Total: - <%= number_with_precision(grand_total, precision:precision.to_i,delimiter:delimiter) %> + <%= number_format(grand_total, precision:precision.to_i,delimiter:delimiter) %> diff --git a/app/views/transactions/order_reservations/index.html.erb b/app/views/transactions/order_reservations/index.html.erb index d7ba3527..9ccaf08c 100644 --- a/app/views/transactions/order_reservations/index.html.erb +++ b/app/views/transactions/order_reservations/index.html.erb @@ -98,17 +98,6 @@ - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end %> <% discount_amount = 0.0 delivery_fee = 0.0 @@ -158,16 +147,16 @@ <%= order_reservation.status %> <%= order_reservation.payment_type%> <%= order_reservation.payment_status%> - <%= number_with_precision(order_reservation.total_amount, precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - <%= number_with_precision(discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - <%= number_with_precision(delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - <%= number_with_precision(convenience_charge , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - - <%= number_with_precision(order_reservation.total_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> - <%= number_with_precision(order_reservation.grand_total , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %> - <%= number_with_precision(order_reservation.transaction_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %> + <%= number_format(order_reservation.total_amount, precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + <%= number_format(discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + <%= number_format(delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + <%= number_format(convenience_charge , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + + <%= number_format(order_reservation.total_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> + <%= number_format(order_reservation.grand_total , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %> + <%= number_format(order_reservation.transaction_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %> <% end %> diff --git a/app/views/transactions/order_reservations/show.html.erb b/app/views/transactions/order_reservations/show.html.erb index 510fe59e..cae67323 100755 --- a/app/views/transactions/order_reservations/show.html.erb +++ b/app/views/transactions/order_reservations/show.html.erb @@ -9,17 +9,6 @@
    - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end %>
    @@ -70,18 +59,18 @@ <%= t("views.right_panel.detail.created_at") %> - + <% @order_reservation.order_reservation_items.each do |item| %> <%=item.item_name rescue ' '%> <%=item.qty rescue ' '%> - <%= number_with_precision(item.price > 0 ? item.price : item.unit_price, precision:precision.to_i, delimiter:delimiter) rescue ' '%> - <%= number_with_precision(item.price > 0 ? item.qty * item.price : item.qty * item.unit_price, precision:precision.to_i, delimiter:delimiter) rescue ' '%> + <%= number_format(item.price > 0 ? item.price : item.unit_price, precision:precision.to_i, delimiter:delimiter) rescue ' '%> + <%= number_format(item.price > 0 ? item.qty * item.price : item.qty * item.unit_price, precision:precision.to_i, delimiter:delimiter) rescue ' '%> <%=l item.created_at.utc.getlocal , :format => :short rescue ' ' %> - <% end %> + <% end %> <% discount_amount = 0.0 delivery_fee = 0.0 @@ -130,70 +119,70 @@ - <%= t("views.right_panel.detail.sub_total") %> - <%= number_with_precision(total_amount, precision:precision.to_i, delimiter:delimiter) rescue ' '%> + <%= t("views.right_panel.detail.sub_total") %> + <%= number_format(total_amount, precision:precision.to_i, delimiter:delimiter) rescue ' '%> <% if total_discount_amount > 0 %> - <%= t("views.right_panel.detail.discount_amount") %> - <%= number_with_precision(total_discount_amount, precision:precision.to_i, delimiter:delimiter) rescue ' '%> + <%= t("views.right_panel.detail.discount_amount") %> + <%= number_format(total_discount_amount, precision:precision.to_i, delimiter:delimiter) rescue ' '%> <% end %> <% if total_delivery_fee > 0 %> - <%= t("views.right_panel.detail.delivery_fee") %> - <%= number_with_precision(total_delivery_fee, precision:precision.to_i, delimiter:delimiter) rescue ' '%> + <%= t("views.right_panel.detail.delivery_fee") %> + <%= number_format(total_delivery_fee, precision:precision.to_i, delimiter:delimiter) rescue ' '%> <% end %> <% if total_convenience_charge > 0 %> - <%= t("views.right_panel.detail.convenience_charge") %> - <%= number_with_precision(total_convenience_charge, precision:precision.to_i, delimiter:delimiter) rescue ' '%> + <%= t("views.right_panel.detail.convenience_charge") %> + <%= number_format(total_convenience_charge, precision:precision.to_i, delimiter:delimiter) rescue ' '%> <% end %> <% if total_tax > 0 %> - <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> - <%= number_with_precision(total_tax, precision:precision.to_i, delimiter:delimiter) rescue ' '%> + <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> + <%= number_format(total_tax, precision:precision.to_i, delimiter:delimiter) rescue ' '%> <% end %> <% if grand_total > 0 %> - <%= t("views.right_panel.detail.grand_total") %> - <%= number_with_precision(grand_total, precision:precision.to_i, delimiter:delimiter) rescue ' '%> + <%= t("views.right_panel.detail.grand_total") %> + <%= number_format(grand_total, precision:precision.to_i, delimiter:delimiter) rescue ' '%> <% end %> <% if total_transaction_fee > 0 %> - <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.transaction_fee") %> - <%= number_with_precision(total_transaction_fee, precision:precision.to_i, delimiter:delimiter) rescue ' '%> + <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.transaction_fee") %> + <%= number_format(total_transaction_fee, precision:precision.to_i, delimiter:delimiter) rescue ' '%> <% end %> diff --git a/app/views/transactions/sales/show.html.erb b/app/views/transactions/sales/show.html.erb index c6ecbc6b..07ca05b0 100755 --- a/app/views/transactions/sales/show.html.erb +++ b/app/views/transactions/sales/show.html.erb @@ -83,8 +83,8 @@ <%=s.product_name rescue ' '%> <%=s.qty rescue ' '%> - <%= number_with_precision(s.unit_price, :precision => 2, :delimiter => ',') rescue ' '%> - <%= number_with_precision(s.price, :precision => 2, :delimiter => ',') rescue ' '%> + <%= number_format(s.unit_price, :precision => 2, :delimiter => ',') rescue ' '%> + <%= number_format(s.price, :precision => 2, :delimiter => ',') rescue ' '%> <%=l s.created_at.utc.getlocal , :format => :short rescue ' ' %> <%=s.remark rescue ' '%> @@ -92,42 +92,42 @@ <%= t("views.right_panel.detail.total") %> - <%= number_with_precision(@sale.total_amount, :precision => 2, :delimiter => ',') rescue ' '%> + <%= number_format(@sale.total_amount, :precision => 2, :delimiter => ',') rescue ' '%> <%= t("views.right_panel.detail.discount") %> - <%= number_with_precision(@sale.total_discount, :precision => 2, :delimiter => ',') rescue ' '%> + <%= number_format(@sale.total_discount, :precision => 2, :delimiter => ',') rescue ' '%> <% @sale.sale_taxes.each do |r|%> <%= r.tax_name %> - <%= number_with_precision(r.tax_payable_amount, :precision => 2, :delimiter => ',') rescue ' '%> + <%= number_format(r.tax_payable_amount, :precision => 2, :delimiter => ',') rescue ' '%> <% end %> <%= t("views.right_panel.detail.grand_total") %> - <%= number_with_precision(@sale.grand_total, :precision => 2, :delimiter => ',') rescue ' '%> + <%= number_format(@sale.grand_total, :precision => 2, :delimiter => ',') rescue ' '%>   <%= t("views.right_panel.detail.total_pay_amount") %> - <%= number_with_precision(@sale.amount_received, :precision => 2, :delimiter => ',') rescue ' '%> + <%= number_format(@sale.amount_received, :precision => 2, :delimiter => ',') rescue ' '%> <% @sale_receivables.each do |r|%> <%= r.payment_method.capitalize rescue ' '%> Payment - <%= number_with_precision(r.payment_amount, :precision => 2, :delimiter => ',') rescue ' '%> + <%= number_format(r.payment_amount, :precision => 2, :delimiter => ',') rescue ' '%> <% end %> <%= t("views.right_panel.detail.change") %> - <%= number_with_precision(@sale.amount_changed, :precision => 2, :delimiter => ',') rescue ' '%> + <%= number_format(@sale.amount_changed, :precision => 2, :delimiter => ',') rescue ' '%> diff --git a/config/routes.rb b/config/routes.rb index b3c5ff6e..933002d9 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -532,6 +532,7 @@ scope "(:locale)", locale: /en|mm/ do resources :dailysale, :only => [:index, :show] resources :saleitem, :only => [:index, :show] resources :hourly_saleitem, :only => [:index, :show] + resources :staff_meal, :only => [:index, :show] resources :shiftsale, :only => [:index, :show] resources :credit_payment, :only => [:index, :show] resources :void_sale, :only => [:index, :show] diff --git a/db/seeds.rb b/db/seeds.rb index 9d498c2e..208be476 100755 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -107,6 +107,11 @@ units = Lookup.create([{lookup_type:'unit', name: 'PCS', value: 'pcs'}, # Country countries = Lookup.create({lookup_type:'country', name: 'Japan', value: 'Japan'}) +# number formats +number_formats = Lookup.create([{lookup_type: 'number_format', name: 'precision', '2'}, + {lookup_type: 'number_format', name: 'delimiter', ','}, + {lookup_type: 'number_format', name: 'strip_insignificant_zeros', '0'}]) + # Default CUSTOMER customer = Customer.create({name:"WALK-IN", email: "cus1@customer.com", contact_no:"000000000",card_no:"000", customer_type:"Dinein", tax_profiles:["2", "1"]}) customer2 = Customer.create({name:"TAKEAWAY", email: "cus2@customer.com", contact_no:"111111111",card_no:"111", customer_type:"Takeaway", tax_profiles:["1"]}) @@ -133,7 +138,7 @@ product = Account.create({title: "Product", account_type: "2"}) # YGN BBQ # person = Account.create({title: "Person", account_type: "3"}) -# END +# END #Default Menu Options menu_options = MenuItemOption.create([{option_type: "Spicy", name: "Less Spicy", value: "less_spicy"},{option_type: "Spicy", name: "Spicy", value: "spicy"},{option_type: "Spicy", name: "Super Spicy", value: "super_spicy"}])