diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index e227d81a..5be0a735 100644 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -30,12 +30,20 @@ class Origami::ShiftsController < BaseOrigamiController unique_code = "CloseCashierPdf" shop_details = Shop.find(1) + #get tax + shift_obj = ShiftSale.where('id =?',@shift.id) + @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') + + puts @sale_taxes.to_a + puts @sale_taxes + puts @sale_taxes.to_json + puts "taxxxxxxxxxxxx" # get printer info print_settings=PrintSetting.find_by_unique_code(unique_code) printer = Printer::CashierStationPrinter.new(print_settings) - printer.print_close_cashier(print_settings,@shift,shop_details) + printer.print_close_cashier(print_settings,@shift,shop_details,@sale_taxes) end diff --git a/app/controllers/reports/dailysale_controller.rb b/app/controllers/reports/dailysale_controller.rb index 280f497c..fc1f150f 100644 --- a/app/controllers/reports/dailysale_controller.rb +++ b/app/controllers/reports/dailysale_controller.rb @@ -2,9 +2,11 @@ class Reports::DailysaleController < BaseReportController authorize_resource :class => false def index - from, to ,report_type = get_date_range_from_params + from, to = get_date_range_from_params @sale_data = Sale.daily_sales_list(from,to) @tax = SaleTax.get_tax(from,to) + @from = from + @to = to respond_to do |format| format.html diff --git a/app/controllers/reports/receipt_no_controller.rb b/app/controllers/reports/receipt_no_controller.rb index d1427e6e..a69177bd 100644 --- a/app/controllers/reports/receipt_no_controller.rb +++ b/app/controllers/reports/receipt_no_controller.rb @@ -17,7 +17,12 @@ authorize_resource :class => false @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) end end - @sale_data = Sale.get_shift_sales_by_receipt_no(@shift_sale_range,@shift,from,to, params[:payment_type]) + payment_type = params[:payment_type] + @sale_data = Sale.get_shift_sales_by_receipt_no(@shift_sale_range,@shift,from,to,payment_type) + @sale_taxes = Sale.get_separate_tax(@shift,from,to,payment_type) + + @from = from + @to = to if @shift.present? @shift.each do |sh| diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index b9f71494..00be65e6 100644 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -29,6 +29,8 @@ class Reports::SaleitemController < BaseReportController @totalByAccount = Hash.new {|hash, key| hash[key] = 0} @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} + @from = from + @to = to if shift.present? shift.each do |sh| diff --git a/app/controllers/reports/shiftsale_controller.rb b/app/controllers/reports/shiftsale_controller.rb index fc3adbf9..5bc2020c 100644 --- a/app/controllers/reports/shiftsale_controller.rb +++ b/app/controllers/reports/shiftsale_controller.rb @@ -9,6 +9,14 @@ class Reports::ShiftsaleController < BaseReportController @shift = ShiftSale.find(params[:shift_name]) end @sale_data = Sale.get_by_shiftsales(from,to,@shift) + @from = from + @to = to + if @shift.present? + + @shift_from = @shift.shift_started_at.nil? ? '-' : @shift.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_to = @shift.shift_closed_at.nil? ? '-' : @shift.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_data = @shift + end respond_to do |format| format.html diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index 267073d8..55bf8c39 100644 --- 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,shift_sale,shop_details) + def print_close_cashier(printer_settings,shift_sale,shop_details,sale_taxes) #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 = CloseCashierPdf.new(printer_settings,shift_sale,shop_details) + pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes) filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf" pdf.render_file filename self.print(filename) diff --git a/app/models/sale.rb b/app/models/sale.rb index 4e47f6cd..05fc2452 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -602,7 +602,6 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_ty payment_type = " and sale_payments.payment_method = '#{payment_type}'" end end - puts payment_type query = Sale.all if shift.present? @@ -610,23 +609,47 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_ty .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .group("sales.sale_id") else - query = query .where("sale_status='completed' #{payment_type} and sale_payments.payment_amount != 0 and sales.shift_sale_id in (?)",shift_sale_range.to_a) + query = query.where("sale_status='completed' #{payment_type} and sale_payments.payment_amount != 0 and sales.shift_sale_id in (?)",shift_sale_range.to_a) .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .group("sales.sale_id") end end +def self.get_separate_tax(shift,from,to,payment_type) -def self.get_separate_tax(from,to,payment_method=nil) - - query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name") - .joins("INNER JOIN sales ON sales.sale_id = sale_taxes.sale_id") - .group("sale_taxes.tax_name") - - return query = query.where("sale_status=? and receipt_date between ? and ?","completed",from,to) + if payment_type.blank? + payment_type = '' + else + if payment_type == 'card' + payment_type = " and 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'" + else + payment_type = " and sale_payments.payment_method = '#{payment_type}'" + end + end + + query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name") + .joins("INNER JOIN sales ON sales.sale_id = sale_taxes.sale_id") + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .group("sale_taxes.tax_name") + .order("sale_taxes.sale_tax_id asc") + + if shift.present? + query = query.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed'", shift.to_a) + else + query = query.where("sales.receipt_date between ? and ? #{payment_type} and sale_status= 'completed' ",from,to) + end end +# def self.get_separate_tax(from,to,payment_method=nil) + +# query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name") +# .joins("INNER JOIN sales ON sales.sale_id = sale_taxes.sale_id") +# .group("sale_taxes.tax_name") + +# return query = query.where("sale_status=? and receipt_date between ? and ?","completed",from,to) +# end + def grand_total_after_rounding return self.old_grand_total.to_f + self.rounding_adjustment.to_f end diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index 82507e67..893746b2 100644 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -1,6 +1,6 @@ class CloseCashierPdf < 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,:text_width - def initialize(printer_settings, shift_sale,shop_details) + def initialize(printer_settings, shift_sale,shop_details,sale_taxes) self.page_width = 210 self.page_height = 7000 self.margin = 5 @@ -32,7 +32,7 @@ class CloseCashierPdf < Prawn::Document stroke_horizontal_rule - shift_detail(shift_sale) + shift_detail(shift_sale,sale_taxes) @@ -51,7 +51,7 @@ class CloseCashierPdf < Prawn::Document stroke_horizontal_rule end - def shift_detail(shift_sale) + def shift_detail(shift_sale,sale_taxes) move_down 7 y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do @@ -190,15 +190,17 @@ class CloseCashierPdf < Prawn::Document bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{shift_sale.total_discounts}", :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 "Commercial Tax :", :size => self.item_font_size, :align => :right + + sale_taxes.each do |tax| + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "#{tax.tax_name} :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{tax.st_amount.round(2)}", :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 "#{shift_sale.commercial_taxes}", :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 "Grand Total :", :size => self.item_font_size, :align => :right diff --git a/app/views/reports/dailysale/_shift_sale_report_filter.html.erb b/app/views/reports/dailysale/_shift_sale_report_filter.html.erb index 28706731..d49d2660 100644 --- a/app/views/reports/dailysale/_shift_sale_report_filter.html.erb +++ b/app/views/reports/dailysale/_shift_sale_report_filter.html.erb @@ -6,6 +6,7 @@
+ diff --git a/app/views/reports/saleitem/index.html.erb b/app/views/reports/saleitem/index.html.erb index 6a9c5620..89c1c076 100644 --- a/app/views/reports/saleitem/index.html.erb +++ b/app/views/reports/saleitem/index.html.erb @@ -29,11 +29,9 @@ - <% if !params[:from].blank?%> - - - <% end %> + + <% if @shift_from %> <% if @shift_data.employee %> diff --git a/app/views/reports/saleitem/index.xls.erb b/app/views/reports/saleitem/index.xls.erb index dfdd77dc..74886913 100644 --- a/app/views/reports/saleitem/index.xls.erb +++ b/app/views/reports/saleitem/index.xls.erb @@ -6,11 +6,9 @@
From Date : <%= params[:from] %> , To Date : <%= params[:to] %>
From Date : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - To Date : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
- <% if !params[:from].blank?%> - - - <% end %> + + <% if @shift_from %> <% if @shift_data.employee %> diff --git a/app/views/reports/shiftsale/index.html.erb b/app/views/reports/shiftsale/index.html.erb index e8f2d1d8..755511ab 100644 --- a/app/views/reports/shiftsale/index.html.erb +++ b/app/views/reports/shiftsale/index.html.erb @@ -27,12 +27,20 @@
From Date : <%= params[:from] %> , To Date : <%= params[:to] %>
From Date : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - To Date : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
- <% if params[:from]%> - - - - <% end %> - + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> @@ -82,7 +90,7 @@ <% grand_total = result.grand_total.to_f %> - + <% cash += result.cash_sales.to_f %> <% credit += result.credit_sales.to_f %> @@ -103,7 +111,7 @@ - +
From Date : <%= params[:from] rescue '-'%> ,To Date : <%= params[:to] rescue '-'%>
From Date : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> + - To Date : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%> + +
Shift Name = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
Cashier Station Cashier Name<%= sprintf "%.2f",grand_tota.to_f.to_d rescue '-'%>
<%= sprintf("%.2f",card) rescue '-'%> <%= sprintf("%.2f",g_total) rescue '-'%><%= sprintf("%.2f",g_total) rescue '-'%>
diff --git a/app/views/reports/shiftsale/index.xls.erb b/app/views/reports/shiftsale/index.xls.erb index c2a8a6d2..951268e9 100644 --- a/app/views/reports/shiftsale/index.xls.erb +++ b/app/views/reports/shiftsale/index.xls.erb @@ -1,11 +1,24 @@ +
+
- <% if params[:from]%> - - - + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + <% end %> @@ -57,7 +70,7 @@ <% grand_total = result.grand_total.to_f %> - + <% cash += result.cash_sales.to_f %> <% credit += result.credit_sales.to_f %> @@ -78,9 +91,10 @@ - +
From Date : <%= params[:from] rescue '-'%> ,To Date : <%= params[:to] rescue '-'%>
From Date : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> + - To Date : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%> + +
Shift Name = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
<%= sprintf "%.2f",grand_tota.to_f.to_d rescue '-'%>
<%= sprintf("%.2f",card) rescue '-'%> <%= sprintf("%.2f",g_total) rescue '-'%><%= sprintf("%.2f",g_total) rescue '-'%>
-
\ No newline at end of file +
+
\ No newline at end of file