update close cashier pdf

This commit is contained in:
Thein Lin Kyaw
2020-08-24 16:07:25 +06:30
parent c8b0471794
commit bd65edcba3
4 changed files with 137 additions and 148 deletions

View File

@@ -87,13 +87,11 @@ class Origami::ShiftsController < BaseOrigamiController
end
shop_details = shop_detail
#get tax
shift_obj = ShiftSale.where('id =?',@shift.id)
sale_items = ''
shift_obj = ShiftSale.where('id = ?', @shift.id)
@lookup = Lookup.shift_sale_items_lookup_value
if @lookup.to_i == 1
@sale_items = Sale.get_shift_sale_items(@shift.id)
other_charges = Sale.get_other_charges()
@total_other_charges_info = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",@shift)
@sale_items = Sale.get_shift_sale_items(@shift.id)
@total_other_charges_info = ShiftSale.get_other_charges(@shift)
end
@sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='')
@total_waste = Sale.get_total_waste(shift_id).sum(:grand_total)
@@ -108,7 +106,6 @@ class Origami::ShiftsController < BaseOrigamiController
@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
@other_charges = ShiftSale.get_other_charges(@shift)
@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
@@ -116,15 +113,9 @@ class Origami::ShiftsController < BaseOrigamiController
printer = Printer::CashierStationPrinter.new(print_settings)
# print close cashier setting
close_cashier_print = Lookup.collection_of('close_cashier_print')
if close_cashier_print.empty?
@settings_lookup = Lookup.new(lookup_type: "close_cashier_print", name: "CloseCashierPrint", value: "1")
@settings_lookup.save
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,@payment_methods,@other_charges)
end
if Lookup.collection_of('close_cashier_print').any? { |l| l == ['CloseCashierPrint', '1'] }
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

View File

@@ -53,28 +53,31 @@ class Reports::ShiftsaleController < BaseReportController
@shift = ShiftSale.find_by_id(shift_id)
shift_obj = ShiftSale.where('id =?',shift_id)
close_cashier_pdf = Lookup.collection_of("print_settings")
if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
unique_code = "CloseCashierPdf"
close_cashier_pdf = Lookup.collection_of("print_settings")
unique_code = "CloseCashierPdf"
if !close_cashier_pdf.empty?
close_cashier_pdf.each do |close_cashier|
if close_cashier[0] == 'CloseCashierCustomisePdf'
if close_cashier[1] == '1'
unique_code="CloseCashierCustomisePdf"
else
unique_code="CloseCashierPdf"
end
if !close_cashier_pdf.empty?
close_cashier_pdf.each do |close_cashier|
if close_cashier[0] == 'CloseCashierCustomisePdf'
if close_cashier[1] == '1'
unique_code="CloseCashierCustomisePdf"
else
unique_code="CloseCashierPdf"
end
end
end
end
shop_details = shop_detail
cashier_terminal = @shift.cashier_terminal
@lookup = Lookup.shift_sale_items_lookup_value
if @lookup.to_i == 1
@sale_items = Sale.get_shift_sale_items(@shift.id)
@total_other_charges_info = ShiftSale.get_other_charges(@shift)
end
@sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='')
@total_waste = Sale.get_total_waste(shift_id).sum(:grand_total)
@total_spoile = Sale.get_total_spoile(shift_id).sum(:grand_total)
@@ -96,14 +99,10 @@ 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,@payment_methods)
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
end
end
end
end

View File

@@ -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, payment_methods, other_charges)
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 Lookup.collection_of('print_settings').none? { |x| x == ["ActionCable", "1"] }
if !sale_items.blank? or !sale_items.nil?
@account_cate_count = Hash.new {|hash, key| hash[key] = 0}
@@ -71,6 +71,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker
end
end
end
pdf.render_file filename
#no print in cloud server
if ENV["SERVER_MODE"] != "cloud"
@@ -87,6 +88,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker
cashier_terminal: cashier_terminal,
shift_employee: shift_sale.employee,
sale_items: sale_items,
other_charges: total_other_charges_info,
sale_taxes: sale_taxes,
other_payment: other_payment,
total_amount_by_account: amount,
@@ -94,7 +96,6 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker
total_member_discount: member_discount,
total_waste: total_waste,
total_spoile: total_spoile,
other_charges: other_charges,
total_other_charges: total_other_charges,
total_credit_payments: total_credit_payments
}

View File

@@ -309,133 +309,131 @@ class ReceiptBillPdf < Prawn::Document
end
def all_total(sale_data,precision,delimiter,printed_status)
move_down line_move
item_name_width = self.item_width
y_position = cursor
if sale_data.discount_type == 'member_discount'
dis_type = "Member Discount:"
move_down line_move
item_name_width = self.item_width
y_position = cursor
if sale_data.discount_type == 'member_discount'
dis_type = "Member Discount:"
else
dis_type = "Overall Discount:"
end
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "#{ dis_type }", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "( #{number_format(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right
end
service_tax_desc = ""
service_tax_amount = 0
service_tax_rate = 0
com_tax_desc = ""
com_tax_amount = 0
com_tax_rate = 0
if sale_data.sale_taxes.length > 0
incl_tax = ""
if sale_data.tax_type == "inclusive"
incl_tax = "Incl."
end
find_lookup = Lookup.find_by_lookup_type('show_total_before_tax')
if find_lookup.nil? || find_lookup == nil
lookup = Lookup.new(lookup_type: 'show_total_before_tax', name: 'Show Total Before Tax', value: '0')
lookup.save
end
check_lookup_type = Lookup.find_by_lookup_type('show_total_before_tax')
if check_lookup_type.value == '1'
sale_data.sale_taxes.each do |st|
if (st.tax_name.include? "Service")
service_tax_desc = st.tax_name
service_tax_amount = st.tax_payable_amount
if incl_tax
service_tax_rate = st.tax_rate.to_i
end
end
if (st.tax_name.include? "Commercial")
com_tax_desc = st.tax_name
com_tax_amount = st.tax_payable_amount
if incl_tax
com_tax_rate = st.tax_rate.to_i
end
end
end
move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "#{ service_tax_desc } (#{incl_tax} #{ service_tax_rate }%)", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{number_format(service_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
end
move_down line_move
y_position = cursor
stroke_horizontal_rule
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "Total Before Tax", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{service_tax_amount.to_i + @sub_total.to_i}" , :size => self.item_font_size,:align => :right
end
move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "#{ com_tax_desc } (#{incl_tax} #{ com_tax_rate.to_i }%)", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{number_format(com_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
end
else
dis_type = "Overall Discount:"
end
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "#{ dis_type }", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "( #{number_format(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right
end
service_tax_desc = ""
service_tax_amount = 0
service_tax_rate = 0
com_tax_desc = ""
com_tax_amount = 0
com_tax_rate = 0
if sale_data.sale_taxes.length > 0
incl_tax = ""
if sale_data.tax_type == "inclusive"
incl_tax = "Incl."
end
find_lookup = Lookup.find_by_lookup_type('show_total_before_tax')
if find_lookup.nil? || find_lookup == nil
lookup = Lookup.new(lookup_type: 'show_total_before_tax', name: 'Show Total Before Tax', value: '0')
lookup.save
end
check_lookup_type = Lookup.find_by_lookup_type('show_total_before_tax')
if check_lookup_type.value == '1'
sale_data.sale_taxes.each do |st|
if (st.tax_name.include? "Service")
service_tax_desc = st.tax_name
service_tax_amount = st.tax_payable_amount
if incl_tax
service_tax_rate = st.tax_rate.to_i
end
end
if (st.tax_name.include? "Commercial")
com_tax_desc = st.tax_name
com_tax_amount = st.tax_payable_amount
if incl_tax
com_tax_rate = st.tax_rate.to_i
end
end
end
move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "#{ service_tax_desc } (#{incl_tax} #{ service_tax_rate }%)", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{number_format(service_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
end
move_down line_move
y_position = cursor
stroke_horizontal_rule
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "Total Before Tax", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{service_tax_amount.to_i + @sub_total.to_i}" , :size => self.item_font_size,:align => :right
end
move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "#{ com_tax_desc } (#{incl_tax} #{ com_tax_rate.to_i }%)", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{number_format(com_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
end
else
sale_data.sale_taxes.each do |st|
move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
end
end
end
else
end
# move_down 5
# y_position = cursor
# bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
# text "Total Tax", :size => self.item_font_size,:align => :left
# end
# bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
# text "( " +"#{sale_data.total_tax}" +" )" , :size => self.item_font_size,:align => :right
# end
if sale_data.rounding_adjustment != 0.0
move_down line_move
sale_data.sale_taxes.each do |st|
move_down line_move
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "Rounding Adjustment", :size => self.item_font_size,:align => :left
text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{sale_data.rounding_adjustment}", :size => self.item_font_size,:align => :right
text "#{number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
end
end
end
end
# move_down 5
# y_position = cursor
# bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
# text "Total Tax", :size => self.item_font_size,:align => :left
# end
# bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
# text "( " +"#{sale_data.total_tax}" +" )" , :size => self.item_font_size,:align => :right
# end
if sale_data.rounding_adjustment != 0.0
move_down line_move
y_position = cursor
move_down line_move
bounding_box([0,y_position], :width =>self.item_description_width) do
text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "Rounding Adjustment", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{number_format(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right
text "#{sale_data.rounding_adjustment}", :size => self.item_font_size,:align => :right
end
move_down line_move
end
sale_payment(sale_data,precision,delimiter,printed_status)
move_down line_move
y_position = cursor
move_down line_move
bounding_box([0,y_position], :width =>self.item_description_width) do
text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{number_format(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right
end
move_down line_move
sale_payment(sale_data,precision,delimiter,printed_status)
end
def sale_payment(sale_data,precision,delimiter,printed_status)