From 51a243ea7cc00d50855e37dce2966929cd328b93 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Tue, 20 Feb 2018 17:35:54 +0630 Subject: [PATCH] To update close cashier --- app/controllers/application_controller.rb | 14 +- app/controllers/origami/shifts_controller.rb | 3 +- app/models/printer/cashier_station_printer.rb | 4 +- app/models/shift_sale.rb | 7 + ..._pdf.rb => close_cashier_customise_pdf.rb} | 144 ++++++++++++------ 5 files changed, 116 insertions(+), 56 deletions(-) rename app/pdf/{close_cashier_customerize_pdf.rb => close_cashier_customise_pdf.rb} (84%) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 505a38b3..0966a573 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -36,13 +36,13 @@ class ApplicationController < ActionController::Base # redirect_to root_url(:host => request.domain) + "store_error" render :json => [{ status: false, message: 'Invalid Access!'}] end - # else - # # check for license file - # if check_license - # current_license(ENV["SX_PROVISION_URL"]) - # else - # redirect_to activate_path - # end + else + # check for license file + if check_license + current_license(ENV["SX_PROVISION_URL"]) + else + redirect_to activate_path + end end end diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index 8bb684e9..e05922fd 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -75,13 +75,14 @@ class Origami::ShiftsController < BaseOrigamiController @total_member_discount = ShiftSale.get_total_member_discount(@shift) @total_dinein = ShiftSale.get_total_dinein(@shift).total_dinein_amount @total_takeway = ShiftSale.get_total_takeway(@shift).total_takeway_amount + @total_other_charges = ShiftSale.get_total_other_charges(@shift).total_other_charges_amount # get printer info 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) + 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) end end Employee.logout(session[:session_token]) diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index 400a0934..b1cab253 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -22,14 +22,14 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker # end #Bill Receipt Print - def print_close_cashier(printer_settings,cashier_terminal,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway) + 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) #Use CUPS service #Generate PDF #Print 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") - pdf = CloseCashierCustomerizePdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway) + pdf = CloseCashierCustomisePdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges) filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf" pdf.render_file filename self.print(filename, cashier_terminal.printer_name) diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index 0127bd5c..10b2de38 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -149,6 +149,13 @@ class ShiftSale < ApplicationRecord .first() end + 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 + def self.search(filter,from,to) if filter.blank? keyword = '' diff --git a/app/pdf/close_cashier_customerize_pdf.rb b/app/pdf/close_cashier_customise_pdf.rb similarity index 84% rename from app/pdf/close_cashier_customerize_pdf.rb rename to app/pdf/close_cashier_customise_pdf.rb index 45834489..902fede4 100644 --- a/app/pdf/close_cashier_customerize_pdf.rb +++ b/app/pdf/close_cashier_customise_pdf.rb @@ -1,8 +1,8 @@ -class CloseCashierCustomerizePdf < Prawn::Document +class CloseCashierCustomisePdf < 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_dinein,total_takeway) + 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) self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width self.page_height = printer_settings.page_height self.margin = 5 @@ -54,7 +54,7 @@ class CloseCashierCustomerizePdf < 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_dinein,total_takeway) + 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) end def header (shop_details) @@ -70,7 +70,7 @@ class CloseCashierCustomerizePdf < 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_dinein,total_takeway) + def 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) move_down 7 y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do @@ -159,27 +159,76 @@ class CloseCashierCustomerizePdf < Prawn::Document stroke_horizontal_rule move_down 7 - @total_grand_total = shift_sale.grand_total + @overall + @total_foc + shift_sale.total_void + #start total amount by Account Like Food / Beverage /.. + total_discount_account = 0 + total_discount_by_account.each do |amount| + + total_discount_account = total_discount_account.to_f + amount.total_price.to_f + end + #end total amount by Account + + #start total FOC amount + @total_foc = 0 + other_payment.each do |other| + @total_foc = other.foc_amount.round(2) + end + + #end total FOC amount + total_grand_total = shift_sale.grand_total + shift_sale.total_discounts + @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 bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do 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(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_with_precision(total_grand_total, :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 Discount :", :size => self.item_font_size, :align => :right + #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 + end 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 total amount by Account + + if total_member_discount[0].member_discount.present? + @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 + end + 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 Overall 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 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 + if @total_foc.nil? + @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 @@ -248,13 +297,13 @@ class CloseCashierCustomerizePdf < Prawn::Document text "#{ number_with_precision(other.jcb_amount, :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 "Reedem 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 - end + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # text "Reedem 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 + # end end else y_position = cursor @@ -287,26 +336,32 @@ class CloseCashierCustomerizePdf < Prawn::Document move_down -5 stroke_horizontal_rule move_down 7 - + # start Dinein and Takeaway y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Dinein :", :size => self.item_font_size, :align => :right end + if total_dinein.nil? + 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_with_precision(total_dinein, :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 Takeaway :", :size => self.item_font_size, :align => :right 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 + + # stop Dinein and Takeaway move_down -5 stroke_horizontal_rule @@ -352,33 +407,18 @@ class CloseCashierCustomerizePdf < Prawn::Document stroke_horizontal_rule move_down 7 #start total amount by Account Like Food / Beverage /.. - total_discount_by_account.each do |amount| + # 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 - end - end + # 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 + # end + # end #end total amount by Account - if total_member_discount[0].member_discount.present? - @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 - end - else - @overall = shift_sale.total_discounts - end - # y_position = cursor # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do # text "Grand Total :", :size => self.item_font_size, :align => :right @@ -400,6 +440,18 @@ class CloseCashierCustomerizePdf < Prawn::Document end #end total amount by Account + #start total other charges amount + if total_other_charges > 0 + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + 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 + end + end + #end total other charges amount + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Dine-in Count :", :size => self.item_font_size, :align => :right