diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 6f4690f0..19a9f087 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -87,7 +87,7 @@ class Origami::DiscountsController < BaseOrigamiController remark = "Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} " sale_audit = SaleAudit.record_audit_discount(sale_item.sale_id,sale.cashier_name, action_by,remark,"ITEMDISCOUNT" ) - + end end diff --git a/app/controllers/origami/others_payments_controller.rb b/app/controllers/origami/others_payments_controller.rb index 964af260..fb75288d 100755 --- a/app/controllers/origami/others_payments_controller.rb +++ b/app/controllers/origami/others_payments_controller.rb @@ -5,7 +5,7 @@ class Origami::OthersPaymentsController < BaseOrigamiController @cashier_type = params[:type] path = request.fullpath if path.include? ("credit_payment") - @payment_method_setting = PaymentMethodSetting.where("LOWER(payment_method) in ('mpu','visa','master','jcb','unionpay','alipay') and is_active='1'") + @payment_method_setting = PaymentMethodSetting.where("is_active='1'") else @payment_method_setting = PaymentMethodSetting.all end diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index f28c1428..be13f2d0 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -112,7 +112,7 @@ class Origami::ShiftsController < BaseOrigamiController @total_takeway = ShiftSale.get_total_takeway(@shift).total_takeway_amount @total_other_charges = ShiftSale.get_total_other_charges(@shift).total_other_charges_amount @total_credit_payments = ShiftSale.get_shift_sales_with_credit_payment(shift_id).total_credit_payments - + @payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method") # get printer info print_settings = PrintSetting.find_by_unique_code(unique_code) printer = Printer::CashierStationPrinter.new(print_settings) @@ -125,7 +125,7 @@ class Origami::ShiftsController < BaseOrigamiController end find_close_cashier_print = Lookup.collection_of('close_cashier_print') if find_close_cashier_print[0][1].to_i > 0 - printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, 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) + printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, 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,@payment_methods) end end end diff --git a/app/controllers/reports/payment_method_controller.rb b/app/controllers/reports/payment_method_controller.rb index 414c4e07..752a2f4e 100644 --- a/app/controllers/reports/payment_method_controller.rb +++ b/app/controllers/reports/payment_method_controller.rb @@ -1,28 +1,30 @@ -class Reports::PaymentMethodController < BaseReportController +class Reports::PaymentMethodController < BaseReportController # authorize_resource :class => false def index - @payments = [["All Payment",''],["Cash Payment","cash"], ["KBZ Payment", KbzPay::KBZ_PAY], ["Credit Payment","creditnote"], - ["FOC Payment","foc"], ["MPU Payment","mpu"], ["Visa Payment","visa"], - ["Master Payment","master"], ["JCB Payment","jcb"],["UnionPay Payment","unionpay"], - ["Alipay Payment","alipay"],["Paymal Payment", "paymal"],["Dinga Payment","dinga"], - ["JunctionPay","junctionpay"],["Redeem Payment","paypar"],["Gift Voucher","giftvoucher"]] + @payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method") + + @payments = [["All Payment",''],["Cash Payment","cash"], ["Credit Payment","creditnote"], + ["FOC Payment","foc"]] + + @payment_methods.each do |m| + @payments.push(["#{m} Payment", m.parameterize]) + end from, to = get_date_range_from_params - @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @shift = '' if params[:shift_name].to_i != 0 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 - @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) end end @payment_type = params[:payment_type] - @sale_data,@pyament_method = Sale.get_payment_method_by_shift(@shift_sale_range,@shift,from,to,@payment_type) + @sale_data,@pyament_method = Sale.get_payment_method_by_shift(@shift,from,to,@payment_type) @from = from @to = to # get printer info @@ -58,10 +60,10 @@ class Reports::PaymentMethodController < BaseReportController 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/shiftsale_controller.rb b/app/controllers/reports/shiftsale_controller.rb index 0c42a05f..ce927f8e 100755 --- a/app/controllers/reports/shiftsale_controller.rb +++ b/app/controllers/reports/shiftsale_controller.rb @@ -80,6 +80,7 @@ class Reports::ShiftsaleController < BaseReportController @total_spoile = Sale.get_total_spoile(shift_id).sum(:grand_total) #other payment details for mpu or visa like card @other_payment = ShiftSale.get_by_shift_other_payment(@shift) + @payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method") # Calculate price_by_accounts @total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount') @@ -95,8 +96,8 @@ class Reports::ShiftsaleController < BaseReportController printer = Printer::CashierStationPrinter.new(print_settings) # printer.print_close_cashier(print_settings,cashier_terminal,@shift, nil, 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) - printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, 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) - + printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, 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,@payment_methods) + respond_to do |format| format.html { redirect_to '/en/reports/shiftsale/', notice: 'Printing Completed.'} format diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index 5e37164f..63ffc53e 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -38,7 +38,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker # self.print(filename, cashier_terminal.printer_name) # end - def print_close_cashier(printer_settings,cashier_terminal,shift_sale, sale_items, total_other_charges_info,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) + def print_close_cashier(printer_settings,cashier_terminal,shift_sale, sale_items, total_other_charges_info,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,payment_methods) if !sale_items.blank? or !sale_items.nil? @account_cate_count = Hash.new {|hash, key| hash[key] = 0} @@ -59,7 +59,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker cashier = shift_sale.employee.name shift_name = shift_sale.shift_started_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + "_" + shift_sale.shift_closed_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf" - pdf = CloseCashierPdf.new(printer_settings,shift_sale, sale_items, total_other_charges_info, @account_cate_count, @menu_cate_count, @totalByAccount, shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) + pdf = CloseCashierPdf.new(printer_settings,shift_sale, sale_items, total_other_charges_info, @account_cate_count, @menu_cate_count, @totalByAccount, shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,payment_methods) close_cashier_pdf = Lookup.collection_of("print_settings") #print_settings with name:CloseCashierPdf if !close_cashier_pdf.empty? @@ -68,7 +68,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker if close_cashier[1] == '1' pdf = CloseCashierCustomisePdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) else - pdf = CloseCashierPdf.new(printer_settings,shift_sale, sale_items, total_other_charges_info, @account_cate_count, @menu_cate_count, @totalByAccount, shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) + pdf = CloseCashierPdf.new(printer_settings,shift_sale, sale_items, total_other_charges_info, @account_cate_count, @menu_cate_count, @totalByAccount, shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,payment_methods) end end end diff --git a/app/models/sale.rb b/app/models/sale.rb index f990c947..aa2b6992 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -748,66 +748,46 @@ class Sale < ApplicationRecord return num end -def self.daily_sales_list(from,to) + def self.daily_sales_list(from,to) + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) + sales = select(" - sales.*, - SUM(case when (sale_payments.payment_method='KBZPay') then sale_payments.payment_amount else 0 end) as kbzpay_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='master') then sale_payments.payment_amount else 0 end) as master_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='jcb') then sale_payments.payment_amount else 0 end) as jcb_amount, - SUM(case when (sale_payments.payment_method='paypar') then sale_payments.payment_amount else 0 end) as paypar_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, - 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='dinga') then sale_payments.payment_amount else 0 end) as dinga_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='cash') then sale_payments.payment_amount else 0 end) as cash_amount, - CASE WHEN SUM(case when sale_payments.payment_method not in('creditnote') - then sale_payments.payment_amount else 0 end) < sales.grand_total - THEN sales.grand_total - SUM(case when sale_payments.payment_method not in('creditnote') - then sale_payments.payment_amount else 0 end) - 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") - .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 + sales.*, + #{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method}"}.join(', ')}, + SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount, + CASE WHEN SUM(case when sale_payments.payment_method not in('creditnote') + then sale_payments.payment_amount else 0 end) < sales.grand_total + THEN sales.grand_total - SUM(case when sale_payments.payment_method not in('creditnote') + then sale_payments.payment_amount else 0 end) + 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") + .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 daily_total = connection.select_all("SELECT - IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as grand_total, - IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as total_sale, - IFNULL(SUM(case when (sale_status='completed') then old_grand_total else 0 end),0) as old_grand_total, - IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0) as total_discount, - IFNULL(SUM(case when (sale_status='completed') then amount_changed else 0 end),0) as total_change_amount, - IFNULL(SUM(case when (sale_status='void') then grand_total else 0 end),0) as void_amount, - IFNULL(SUM(case when (sale_status='completed') then rounding_adjustment else 0 end),0) as rounding_adj, - IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21 as tax, - (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0))-(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21) as net_sale, - (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0)) + (IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0)) as gross_sale, - CAST((CONVERT_TZ(receipt_date,'+00:00','+06:30')) AS DATE) as sale_date, - SUM(kbzpay_amount) as kbzpay_amount, - SUM(mpu_amount) as mpu_amount, - SUM(master_amount) as master_amount, - SUM(visa_amount) as visa_amount, - SUM(jcb_amount) as jcb_amount, - SUM(paypar_amount) as paypar_amount, - SUM(unionpay_amount) as unionpay_amount, - SUM(alipay_amount) as alipay_amount, - SUM(paymal_amount) as paymal_amount, - SUM(dinga_amount) as dinga_amount, - SUM(junctionpay_amount) as junctionpay_amount, - SUM(cash_amount) as cash_amount, - SUM(credit_amount) as credit_amount, - SUM(giftvoucher_amount) as giftvoucher_amount, - SUM(foc_amount) as foc_amount - FROM ( - #{sales} - ) as s - GROUP BY DATE(CONVERT_TZ(receipt_date,'+00:00','+06:30'))").to_hash.map(&:symbolize_keys) + IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as grand_total, + IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as total_sale, + IFNULL(SUM(case when (sale_status='completed') then old_grand_total else 0 end),0) as old_grand_total, + IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0) as total_discount, + IFNULL(SUM(case when (sale_status='completed') then amount_changed else 0 end),0) as total_change_amount, + IFNULL(SUM(case when (sale_status='void') then grand_total else 0 end),0) as void_amount, + IFNULL(SUM(case when (sale_status='completed') then rounding_adjustment else 0 end),0) as rounding_adj, + IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21 as tax, + (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0))-(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21) as net_sale, + (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0)) + (IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0)) as gross_sale, + CAST((CONVERT_TZ(receipt_date,'+00:00','+06:30')) AS DATE) as sale_date, + #{payment_methods.map { |method| "SUM(#{method}) as #{method}"}.join(', ')}, + SUM(cash_amount) as cash_amount, + SUM(credit_amount) as credit_amount, + SUM(foc_amount) as foc_amount + FROM ( + #{sales} + ) as s + GROUP BY DATE(CONVERT_TZ(receipt_date,'+00:00','+06:30'))").to_hash.map(&:symbolize_keys) return daily_total -end + end def self.get_by_range_by_saleitems(from,to,status,report_type) query = Sale.select(" @@ -973,6 +953,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou other_charges = self.get_other_charges() end product = self.get_product_sale() + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) if shift.present? query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift.to_a) @@ -982,7 +963,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou 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, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) 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") @@ -1005,7 +986,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou 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, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) 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") @@ -1029,7 +1010,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou 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, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) 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") @@ -1060,6 +1041,8 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account customer_id = customer_id.to_s customer_id[0] = "" customer_id = customer_id.chomp("]") + else + customer_id = "''" end query = self.get_staff_meal_query() @@ -1076,16 +1059,17 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account # other_charges = self.get_other_charges() # end product = self.get_product_sale() + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) 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) + 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, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) 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") @@ -1101,14 +1085,14 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account ### => 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) + 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, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) 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") @@ -1124,7 +1108,7 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account 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) + 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 @@ -1132,7 +1116,7 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account 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, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) 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") @@ -1343,20 +1327,12 @@ def self.get_separate_tax(shift_sale_range=nil,shift,from,to,payment_type) end end -def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type) +def self.get_payment_method_by_shift(shift,from,to,payment_type) + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) + payments_total = SalePayment.select(" sales.receipt_date as sale_date, - 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='master') then sale_payments.payment_amount else 0 end) as master_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='jcb') then sale_payments.payment_amount else 0 end) as jcb_amount, - SUM(case when (sale_payments.payment_method='paypar') then sale_payments.payment_amount else 0 end) as paypar_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, - SUM(case when (sale_payments.payment_method='KBZPay') then sale_payments.payment_amount else 0 end) as kbzpay_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='dinga') then sale_payments.payment_amount else 0 end) as dinga_amount, - SUM(case when (sale_payments.payment_method='JunctionPay') then sale_payments.payment_amount else 0 end) as junctionpay_amount, + #{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method}"}.join(', ')}, 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='cash') then sales.amount_changed else 0 end) as total_change_amount, @@ -1384,9 +1360,6 @@ def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type if shift.present? payments_total = payments_total.where(sales: {shift_sale_id: shift.to_a}) sale_payment = sale_payment.merge(Sale.where(sales: {shift_sale_id: shift.to_a})) - elsif shift_sale_range.present? - payments_total = payments_total.where(sales: {shift_sale_id: shift_sale_range.to_a}) - sale_payment = sale_payment.merge(Sale.where(sales: {shift_sale_id: shift_sale_range.to_a})) end if payment_type.present? @@ -1513,11 +1486,12 @@ end end payments_for_credits = SalePayment.joins(:sale_audit).to_sql + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) 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' + CASE WHEN sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') }) THEN 'card' ELSE sale_payments.payment_method END AS payment_method, employees.name AS e_name") end @@ -1541,8 +1515,9 @@ end end def self.total_card_sale(current_user=nil,from=nil,to=nil) + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) 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")') + .where("sales.sale_status = 'completed' and (sp.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') }))") if (!from.nil? && !to.nil?) query = query.receipt_date_between(from, to) @@ -1602,10 +1577,11 @@ end end 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") + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) + query = Sale.select("CASE WHEN sp.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') }) 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") - .group("CASE WHEN sp.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' ELSE sp.payment_method END") + .group("CASE WHEN sp.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') }) THEN 'card' ELSE sp.payment_method END") if (!from.nil? && !to.nil?) query = query.receipt_date_between(from, to) @@ -2039,6 +2015,7 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco other_charges = self.get_other_charges() end product = self.get_product_sale() + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) if shift.present? query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift.to_a) @@ -2048,7 +2025,7 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco 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, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) 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") @@ -2071,7 +2048,7 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco 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, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) 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") @@ -2095,7 +2072,7 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco 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, + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) 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") @@ -2255,8 +2232,9 @@ def self.get_daily_sale_data(transaction_date) end def self.get_check_sale_data(transaction_date) + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) sale_receivables_subquery = "SELECT sale_payments.sale_id, - 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' THEN SUM(sale_payments.payment_amount) ELSE SUM(0) END as credit_card_sales, + SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as credit_card_sales, CASE WHEN sale_payments.payment_method = 'giftvoucher' THEN SUM(sale_payments.payment_amount) ELSE SUM(0) END as voucher_sales FROM sale_payments GROUP BY sale_payments.sale_id, sale_payments.payment_method" @@ -2315,7 +2293,9 @@ private self.total_tax = self.total_tax.round(precision) end self.grand_total = (self.total_amount - self.total_discount) + self.total_tax - adjust_rounding + if (!['foc'].include? self.payment_status) + adjust_rounding + end end def update_stock_journal diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 70812e11..9ade9920 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -11,7 +11,7 @@ class SalePayment < ApplicationRecord 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']) } + scope :cards, -> { where(payment_method: PaymentMethodSetting.where("is_active='1'").pluck("payment_method")) } def self.sync_sale_payment_records(sale_payments) if !sale_payments.nil? @@ -364,10 +364,16 @@ class SalePayment < ApplicationRecord # Check for Card Payment def self.get_sale_payments_by_card(sale_payments) # Check for Card Payment + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) sale_payments.each do |sp| - if sp.payment_method == "jcb" || sp.payment_method == "mpu" || sp.payment_method == "visa" || sp.payment_method == "master" || sp.payment_method == "unionpay" || sp.payment_method == "alipay" - return true; + payment_methods.each do |m| + if sp.payment_method == m + return true; + end end + # if sp.payment_method == "jcb" || sp.payment_method == "mpu" || sp.payment_method == "visa" || sp.payment_method == "master" || sp.payment_method == "unionpay" || sp.payment_method == "alipay" + # return true; + # end end end diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index 56db452f..f3280f76 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -150,21 +150,11 @@ class ShiftSale < ApplicationRecord end def self.get_by_shift_other_payment(shift) + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) 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='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, - SUM(case when (sale_payments.payment_method='KBZPay') then (sale_payments.payment_amount) else 0 end) as kbzpay_amount, - 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='paypar') then (sale_payments.payment_amount) else 0 end) as paypar_amount") + #{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method}"}.join(', ')}, + 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 =? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.id) end diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index 976c3d93..e6b594bc 100755 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -2,7 +2,7 @@ class CloseCashierPdf < Prawn::Document 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) + 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,payment_methods) self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width self.page_height = printer_settings.page_height self.header_font_size = printer_settings.header_font_size.to_i @@ -43,7 +43,7 @@ class CloseCashierPdf < Prawn::Document stroke_horizontal_rule - 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) + 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,payment_methods) 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) @@ -63,7 +63,7 @@ class CloseCashierPdf < Prawn::Document stroke_horizontal_rule end - def 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) + def 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,payment_methods) move_down 7 y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do @@ -173,125 +173,138 @@ class CloseCashierPdf < Prawn::Document if shift_sale.other_sales > 0 other_payment.each do |other| @total_foc = other.foc_amount.round(2) - if other.mpu_amount && other.mpu_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - 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_format(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + + if !payment_methods.nil? + payment_methods.each do |method| + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "#{method} 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_format(other[method.parameterize.to_sym], :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end end end - if other.visa_amount && other.visa_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - 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_format(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.master_amount && other.master_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - 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_format(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.jcb_amount && other.jcb_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - 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_format(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.unionpay_amount && other.unionpay_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - 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_format(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.alipay_amount && other.alipay_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - 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_format(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.kbzpay_amount && other.kbzpay_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - 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_format(other.kbzpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.junctionpay_amount && other.junctionpay_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - 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_format(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.dinga_amount && other.dinga_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - 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_format(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.paypar_amount && other.paypar_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - 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_format(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.paymal_amount && other.paymal_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - 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_format(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.giftvoucher_amount && other.giftvoucher_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - 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_format(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end + # if other.mpu_amount && other.mpu_amount.to_f > 0 + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # 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_format(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + # end + # end + # + # if other.visa_amount && other.visa_amount.to_f > 0 + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # 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_format(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + # end + # end + # + # if other.master_amount && other.master_amount.to_f > 0 + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # 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_format(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + # end + # end + # + # if other.jcb_amount && other.jcb_amount.to_f > 0 + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # 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_format(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + # end + # end + # + # if other.unionpay_amount && other.unionpay_amount.to_f > 0 + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # 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_format(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + # end + # end + # + # if other.alipay_amount && other.alipay_amount.to_f > 0 + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # 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_format(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + # end + # end + # + # if other.kbzpay_amount && other.kbzpay_amount.to_f > 0 + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # 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_format(other.kbzpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + # end + # end + # + # if other.junctionpay_amount && other.junctionpay_amount.to_f > 0 + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # 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_format(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + # end + # end + # + # if other.dinga_amount && other.dinga_amount.to_f > 0 + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # 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_format(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + # end + # end + # + # if other.paypar_amount && other.paypar_amount.to_f > 0 + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # 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_format(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + # end + # end + # + # if other.paymal_amount && other.paymal_amount.to_f > 0 + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # 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_format(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + # end + # end + # + # if other.giftvoucher_amount && other.giftvoucher_amount.to_f > 0 + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # 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_format(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + # end + # end end else y_position = cursor diff --git a/app/views/origami/dashboard/index.html.erb b/app/views/origami/dashboard/index.html.erb index 713ba6a5..38df56b3 100644 --- a/app/views/origami/dashboard/index.html.erb +++ b/app/views/origami/dashboard/index.html.erb @@ -96,36 +96,35 @@
| Redeem Sale : | - <% else %> -<%= payment.payment_method.to_s.capitalize %> Sale : | - <% end %> -- <% @sale_data.each do |data| %> - <% pay_mth = payment.payment_method %> - <%= data[""+pay_mth+""] %> + <% @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' %> + |
| Redeem Sale : | + <% else %> +<%= payment.payment_method.to_s.capitalize %> Sale : | + <% end %> ++ <% @sale_data.each do |data| %> + <% pay_mth = payment.payment_method %> + <%= data[""+pay_mth+""] %> + <% end %> + | +
| <%= t("views.right_panel.detail.other_payment") %> : | -- <%= total_card["card"].to_f %> - | -|
| <%= t("views.right_panel.detail.other_payment") %> : | ++ <%= total_card["card"].to_f %> + | +