From 5c8fd3666d9d631a039fed212d55fa602031b539 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 10 Jul 2018 15:16:49 +0630 Subject: [PATCH] update other charge add to recipt bill and close pdf --- app/controllers/origami/payments_controller.rb | 8 ++++++-- app/controllers/origami/shifts_controller.rb | 2 +- app/models/print_setting.rb | 6 +++++- app/models/printer/cashier_station_printer.rb | 8 ++++---- app/models/printer/receipt_printer.rb | 8 ++++---- app/models/sale_item.rb | 13 +++++++++++++ app/pdf/close_cashier_pdf.rb | 14 +++++++++++--- app/pdf/receipt_bill_a5_pdf.rb | 16 +++++++++++++++- app/pdf/receipt_bill_pdf.rb | 16 +++++++++++++++- 9 files changed, 74 insertions(+), 17 deletions(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 2ca8b45a..e420be17 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -77,9 +77,11 @@ class Origami::PaymentsController < BaseOrigamiController item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale_items) discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale_items) + other_amount = SaleItem.calculate_other_charges(sale_items) + printer = Printer::ReceiptPrinter.new(print_settings) - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil,other_amount) result = { :filepath => filename, @@ -209,8 +211,10 @@ class Origami::PaymentsController < BaseOrigamiController item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items) discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) + other_amount = SaleItem.calculate_other_charges(sale_items) + printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Paid",current_balance,card_data) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Paid",current_balance,card_data,other_amount) render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error ", :filename => filename, :receipt_no => sale_receipt_no, :printer_name => printer_name}) diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index fd82d474..81d41565 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -101,7 +101,7 @@ class Origami::ShiftsController < BaseOrigamiController print_settings = PrintSetting.find_by_unique_code(unique_code) printer = Printer::CashierStationPrinter.new(print_settings) - printer.print_close_cashier(print_settings,cashier_terminal,@shift,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) + printer.print_close_cashier(print_settings,cashier_terminal,@shift,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 ) end end Employee.logout(session[:session_token]) diff --git a/app/models/print_setting.rb b/app/models/print_setting.rb index 59c58001..c1a17c5a 100755 --- a/app/models/print_setting.rb +++ b/app/models/print_setting.rb @@ -3,7 +3,11 @@ class PrintSetting < ApplicationRecord validates_presence_of :name, :unique_code, :printer_name, :api_settings, :page_width, :page_height, :print_copies, :header_font_size, :item_font_size def self.get_precision_delimiter - PrintSetting.find_by_unique_code("CloseCashierPdf") + setting = PrintSetting.find_by_unique_code("CloseCashierPdf") + if setting.nil? + setting = PrintSetting.find_by_unique_code("CloseCashierCustomisePdf") + end + return setting end end diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index 73813d1a..f6473df4 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -37,7 +37,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker # pdf.render_file filename # self.print(filename, cashier_terminal.printer_name) # end - + def print_close_cashier(printer_settings,cashier_terminal,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile) #Use CUPS service @@ -46,16 +46,16 @@ 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,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_waste,total_spoile) + pdf = CloseCashierPdf.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) close_cashier_pdf = Lookup.collection_of("print_settings") #print_settings with name:CloseCashierPdf if !close_cashier_pdf.empty? close_cashier_pdf.each do |close_cashier| if close_cashier[0] == 'CloseCashierCustomisePdf' 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) + 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) else - pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_waste,total_spoile) + pdf = CloseCashierPdf.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) end end end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 2c925384..f77fc96c 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -188,19 +188,19 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end #Bill Receipt Print - def print_receipt_bill(printer_settings,cashier_terminal,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details, printed_status,balance,card_data) + def print_receipt_bill(printer_settings,cashier_terminal,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details, printed_status,balance,card_data,other_amount) #Use CUPS service #Generate PDF #Print - pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data) + pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount) receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf if !receipt_bill_a5_pdf.empty? receipt_bill_a5_pdf.each do |receipt_bilA5| if receipt_bilA5[0] == 'ReceiptBillA5Pdf' if receipt_bilA5[1] == '1' - pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data) + pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount) else - pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data) + pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount) end end end diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index 3d5a659c..62db6097 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -150,6 +150,19 @@ class SaleItem < ApplicationRecord return price,type end + # Get Prices for each accounts (eg: food, beverage) + def self.calculate_other_charges(sale_items) + total = 0 + # Check for actual sale items + sale_items.each do |si| + if si.product_code == "Other Charges" && si.item_instance_code == nil + total = total + si.price + end + end + + return total + end + # def self.get_overall_discount(sale_id) # price = 0.0 # item=SaleItem.where("product_code=?", sale_id) diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index 3888c549..461022c1 100755 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -2,7 +2,7 @@ class CloseCashierPdf < Prawn::Document include ActionView::Helpers::NumberHelper 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_waste,total_spoile) + 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) 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 @@ -54,7 +54,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,printer_settings.precision,delimiter,total_waste,total_spoile) + 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) end def header (shop_details) @@ -70,7 +70,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) + 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) move_down 7 y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do @@ -449,6 +449,14 @@ class CloseCashierPdf < Prawn::Document text "#{number_with_precision(amount.total_price, :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 => 20) do + text "Total Other 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 "#{total_other_charges}", :size => self.item_font_size, :align => :right + end #end total amount by Account y_position = cursor diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index 4f6969c5..f6555bcb 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -2,7 +2,7 @@ class ReceiptBillA5Pdf < Prawn::Document include ActionView::Helpers::NumberHelper 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) + 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) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height self.header_font_size = printer_settings.header_font_size.to_i @@ -79,6 +79,9 @@ class ReceiptBillA5Pdf < Prawn::Document if shop_details.show_account_info items_account(item_price_by_accounts,printer_settings.precision,delimiter) + if other_charges_amount + show_other_charges_amount(other_charges_amount,printer_settings.precision,delimiter) + end end #start for individual payment @@ -537,6 +540,17 @@ class ReceiptBillA5Pdf < Prawn::Document end end + def show_other_charges_amount(other_amount,precision,delimiter) + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width) do + 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 + end + move_down line_move + end + #individual payment per person def individual_payment(sale_data, precision, delimiter) per_person = sale_data.grand_total.to_i / sale_data.equal_persons.to_i diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 9a1f92b1..80a57c51 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -3,7 +3,7 @@ class ReceiptBillPdf < Prawn::Document 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) + 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) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height self.header_font_size = printer_settings.header_font_size.to_i @@ -80,6 +80,9 @@ class ReceiptBillPdf < Prawn::Document if shop_details.show_account_info items_account(item_price_by_accounts,printer_settings.precision,delimiter) + if other_charges_amount + show_other_charges_amount(other_charges_amount,printer_settings.precision,delimiter) + end end #start for individual payment @@ -536,6 +539,17 @@ class ReceiptBillPdf < Prawn::Document end end + def show_other_charges_amount(other_amount,precision,delimiter) + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width) do + 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 + end + move_down line_move + end + #individual payment per person def individual_payment(sale_data, survey, precision, delimiter) # per_person = sale_data.grand_total.to_f / survey.total_customer.to_i