total other amount added to SaleItemsPdf

This commit is contained in:
Zoey
2019-06-03 16:47:49 +06:30
parent fe0ae102f9
commit 4b73920e18
7 changed files with 95 additions and 36 deletions

View File

@@ -117,8 +117,14 @@ class Reports::SaleitemController < BaseReportController
account_type = params[:account_type] account_type = params[:account_type]
@type = params[:period_type] @type = params[:period_type]
period_name = get_period_name(params[:period]) period_name = get_period_name(params[:period])
@sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type)
@sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type)
other_charges = Sale.get_other_charges()
if shift.present?
@total_other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
else
@total_other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to)
end
# get printer info # get printer info
print_settings = PrintSetting.find_by_unique_code('CloseCashierPdf') # SaleItemsPdf print_settings = PrintSetting.find_by_unique_code('CloseCashierPdf') # SaleItemsPdf
@@ -127,11 +133,11 @@ class Reports::SaleitemController < BaseReportController
if print_settings.nil? if print_settings.nil?
if !print_settings_star.nil? if !print_settings_star.nil?
printer = Printer::CashierStationPrinter.new(print_settings_star) printer = Printer::CashierStationPrinter.new(print_settings_star)
printer.print_sale_items_report(print_settings_star, shop_details, period_name, @type, account_type, from, to, shift_name, @sale_data) printer.print_sale_items_report(print_settings_star, shop_details, period_name, @type, account_type, from, to, shift_name, @sale_data, @total_other_charges)
end end
else else
printer = Printer::CashierStationPrinter.new(print_settings) printer = Printer::CashierStationPrinter.new(print_settings)
printer.print_sale_items_report(print_settings, shop_details, period_name, @type, account_type, from, to, shift_name, @sale_data) printer.print_sale_items_report(print_settings, shop_details, period_name, @type, account_type, from, to, shift_name, @sale_data, @total_other_charges)
end end

View File

@@ -81,15 +81,15 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker
end end
end end
def print_sale_items_report(print_settings, shop_details, period_name, type, account, from_date, to_date, shift_name, sale_items) def print_sale_items_report(print_settings, shop_details, period_name, type, account, from_date, to_date, shift_name, sale_items, total_other_charges)
filename = "tmp/reports_sale_items.pdf" filename = "tmp/reports_sale_items.pdf"
if print_settings.unique_code == "CloseCashierPdf" if print_settings.unique_code == "CloseCashierPdf"
pdf = SaleItemsPdf.new(print_settings, shop_details, period_name, type, account, from_date, to_date, shift_name, sale_items, nil, nil, nil) pdf = SaleItemsPdf.new(print_settings, shop_details, period_name, type, account, from_date, to_date, shift_name, sale_items, total_other_charges, nil, nil, nil)
puts 'Printing!!!!' puts 'Printing!!!!'
end end
if print_settings.unique_code == "CloseCashierStarPdf" if print_settings.unique_code == "CloseCashierStarPdf"
pdf = SaleItemsStarPdf.new(print_settings, shop_details, period_name, type, account, from_date, to_date, shift_name, sale_items, nil, nil, nil) pdf = SaleItemsStarPdf.new(print_settings, shop_details, period_name, type, account, from_date, to_date, shift_name, sale_items, total_other_charges, nil, nil, nil)
puts 'PrintingStar!!!!' puts 'PrintingStar!!!!'
end end

View File

@@ -158,6 +158,13 @@ class ShiftSale < ApplicationRecord
.first() .first()
end end
# def self.get_total_other_charges_for_sale_item_report(from, to)
# 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")
# .joins("JOIN shift_sales ss ON ss.id = s.shift_sale_id")
# .where('s.sale_status = "completed" and sale_items.product_code = "Other Charges" and sale_items.item_instance_code is null and s.receipt_date between ? and ?',from, to)
# end
def self.get_total_other_charges(shift) def self.get_total_other_charges(shift)
query = SaleItem.select("sum(sale_items.qty * sale_items.unit_price) as total_other_charges_amount") 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") .joins("JOIN sales as s ON s.sale_id = sale_items.sale_id")

View File

@@ -57,7 +57,7 @@ class CloseCashierPdf < Prawn::Document
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,total_credit_payments) 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,total_credit_payments)
if !sale_items.nil? or !sale_items.blank? if !sale_items.nil? or !sale_items.blank?
sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc) sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc, total_other_charges)
end end
end end
@@ -504,7 +504,7 @@ class CloseCashierPdf < Prawn::Document
end end
def sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc) def sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc, total_other_charges)
self.item_width = 73 self.item_width = 73
self.price_width = 60 self.price_width = 60
item_label_qty_front_width = (self.item_width+self.price_width) + 2 item_label_qty_front_width = (self.item_width+self.price_width) + 2
@@ -521,6 +521,7 @@ class CloseCashierPdf < Prawn::Document
total_amount = 0 total_amount = 0
total_qty = 0 total_qty = 0
sub_total = 0 sub_total = 0
flag = false
arr = Array.new arr = Array.new
@@ -529,12 +530,15 @@ class CloseCashierPdf < Prawn::Document
if !arr.include?(item['menu_category_id']) if !arr.include?(item['menu_category_id'])
unless total_qty == 0 and sub_total == 0 if flag == true
move_down 5
stroke_horizontal_rule
total_details('Sub Total', total_qty, sub_total) total_details('Sub Total', total_qty, sub_total)
end end
total_qty = 0 total_qty = 0
sub_total = 0 sub_total = 0
flag = true
move_down 10 move_down 10
@@ -571,7 +575,7 @@ class CloseCashierPdf < Prawn::Document
text_box "#{item['grand_total'].to_i}", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix text_box "#{item['grand_total'].to_i}", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
} }
if item['total_item'].to_i > 0 if item['total_item'].to_i > 0 or item['status_type'] == 'foc' or item['status_type'] == 'void'
total_qty += item['total_item'].to_i total_qty += item['total_item'].to_i
total_items += item['total_item'].to_i total_items += item['total_item'].to_i
end end
@@ -581,11 +585,17 @@ class CloseCashierPdf < Prawn::Document
arr.push(item['menu_category_id']) arr.push(item['menu_category_id'])
end end
# stroke_horizontal_rule move_down 5
stroke_horizontal_rule
total_details('Sub Total', total_qty, sub_total) total_details('Sub Total', total_qty, sub_total)
move_down 5 move_down 5
move_down 5
stroke_horizontal_rule
total_details('Total Amount', total_items, total_amount) total_details('Total Amount', total_items, total_amount)
move_down 10
# other_charges = get_other_charges(total_other_charges)
total_details('Total Other Amount', nil, total_other_charges)
move_down 20
end end
end end
@@ -597,8 +607,7 @@ class CloseCashierPdf < Prawn::Document
item_label_total_front_width = (self.item_width+self.price_width) + 2 item_label_total_front_width = (self.item_width+self.price_width) + 2
item_label_total_end_width = 64 item_label_total_end_width = 64
move_down 5
stroke_horizontal_rule
y_position = cursor y_position = cursor
pad_top(15) { pad_top(15) {
text_box "#{col_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix text_box "#{col_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix

View File

@@ -2,7 +2,7 @@ class SaleItemsPdf < Prawn::Document
include ActionView::Helpers::NumberHelper 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 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, shop_details, period, type, account, from_date, to_date, shift, sale_items, acc_cate_count, menu_cate_count, total_by_acc) def initialize(printer_settings, shop_details, period, type, account, from_date, to_date, shift, sale_items, total_other_charges, acc_cate_count, menu_cate_count, total_by_acc)
self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width
self.page_height = printer_settings.page_height self.page_height = printer_settings.page_height
self.header_font_size = printer_settings.header_font_size.to_i self.header_font_size = printer_settings.header_font_size.to_i
@@ -58,7 +58,7 @@ class SaleItemsPdf < Prawn::Document
sale_details(period, type, account, from_date, to_date, shift) sale_details(period, type, account, from_date, to_date, shift)
sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc) sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc, total_other_charges)
end end
def header (shop_details) def header (shop_details)
@@ -127,7 +127,7 @@ class SaleItemsPdf < Prawn::Document
move_down 10 move_down 10
end end
def sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc) def sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc, total_other_charges)
self.item_width = 73 self.item_width = 73
self.price_width = 60 self.price_width = 60
item_label_qty_front_width = (self.item_width+self.price_width) + 2 item_label_qty_front_width = (self.item_width+self.price_width) + 2
@@ -144,6 +144,7 @@ class SaleItemsPdf < Prawn::Document
total_amount = 0 total_amount = 0
total_qty = 0 total_qty = 0
sub_total = 0 sub_total = 0
flag = false
arr = Array.new arr = Array.new
@@ -152,10 +153,14 @@ class SaleItemsPdf < Prawn::Document
if !arr.include?(item['menu_category_id']) if !arr.include?(item['menu_category_id'])
unless total_qty == 0 and sub_total == 0 if flag == true
move_down 5
stroke_horizontal_rule
total_details('Sub Total', total_qty, sub_total) total_details('Sub Total', total_qty, sub_total)
end end
flag = true
total_qty = 0 total_qty = 0
sub_total = 0 sub_total = 0
@@ -173,7 +178,7 @@ class SaleItemsPdf < Prawn::Document
y_position = cursor y_position = cursor
pad_top(15) { pad_top(15) {
text_box "Items", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix text_box "Items", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix
text_box "Price", :at =>[(self.item_width),y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :left, :overflow => :shrink_to_fix text_box "Price", :at =>[(self.item_width),y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
text_box "Qty", :at =>[item_label_qty_front_width,y_position], :width => item_label_qty_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix text_box "Qty", :at =>[item_label_qty_front_width,y_position], :width => item_label_qty_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
text_box "Total", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix text_box "Total", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
} }
@@ -194,7 +199,7 @@ class SaleItemsPdf < Prawn::Document
text_box "#{item['grand_total'].to_i}", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix text_box "#{item['grand_total'].to_i}", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
} }
if item['total_item'].to_i > 0 if item['total_item'].to_i > 0 or item['status_type'] == 'foc' or item['status_type'] == 'void'
total_qty += item['total_item'].to_i total_qty += item['total_item'].to_i
total_items += item['total_item'].to_i total_items += item['total_item'].to_i
end end
@@ -204,11 +209,17 @@ class SaleItemsPdf < Prawn::Document
arr.push(item['menu_category_id']) arr.push(item['menu_category_id'])
end end
# stroke_horizontal_rule move_down 5
stroke_horizontal_rule
total_details('Sub Total', total_qty, sub_total) total_details('Sub Total', total_qty, sub_total)
move_down 5 move_down 5
move_down 5
stroke_horizontal_rule
total_details('Total Amount', total_items, total_amount) total_details('Total Amount', total_items, total_amount)
move_down 10
other_charges = get_other_charges(total_other_charges)
total_details('Total Other Amount', nil, other_charges)
move_down 20
end end
end end
@@ -220,8 +231,6 @@ class SaleItemsPdf < Prawn::Document
item_label_total_front_width = (self.item_width+self.price_width) + 2 item_label_total_front_width = (self.item_width+self.price_width) + 2
item_label_total_end_width = 64 item_label_total_end_width = 64
move_down 5
stroke_horizontal_rule
y_position = cursor y_position = cursor
pad_top(15) { pad_top(15) {
text_box "#{col_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix text_box "#{col_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix
@@ -230,4 +239,15 @@ class SaleItemsPdf < Prawn::Document
} }
end end
def get_other_charges(total_other_charges)
other_sub_total = 0
unless total_other_charges.nil?
total_other_charges.each do |charges|
other_sub_total += charges.grand_total
end
end
return other_sub_total
end
end end

View File

@@ -2,7 +2,7 @@ class SaleItemsStarPdf < Prawn::Document
include ActionView::Helpers::NumberHelper 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 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, shop_details, period, type, account, from_date, to_date, shift, sale_items, acc_cate_count, menu_cate_count, total_by_acc) def initialize(printer_settings, shop_details, period, type, account, from_date, to_date, shift, sale_items, total_other_charges, acc_cate_count, menu_cate_count, total_by_acc)
self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width
self.page_height = printer_settings.page_height self.page_height = printer_settings.page_height
self.header_font_size = printer_settings.header_font_size.to_i self.header_font_size = printer_settings.header_font_size.to_i
@@ -58,7 +58,7 @@ class SaleItemsStarPdf < Prawn::Document
sale_details(period, type, account, from_date, to_date, shift) sale_details(period, type, account, from_date, to_date, shift)
sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc) sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc, total_other_charges)
end end
def header (shop_details) def header (shop_details)
@@ -127,7 +127,7 @@ class SaleItemsStarPdf < Prawn::Document
move_down 10 move_down 10
end end
def sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc) def sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc, total_other_charges)
self.item_width = 73 self.item_width = 73
self.price_width = 35 self.price_width = 35
item_label_qty_front_width = (self.item_width+self.price_width) + 2 item_label_qty_front_width = (self.item_width+self.price_width) + 2
@@ -152,7 +152,9 @@ class SaleItemsStarPdf < Prawn::Document
if !arr.include?(item['menu_category_id']) if !arr.include?(item['menu_category_id'])
unless total_qty == 0 and sub_total == 0 if flag == true
move_down 5
stroke_horizontal_rule
total_details('Sub Total', total_qty, sub_total) total_details('Sub Total', total_qty, sub_total)
end end
@@ -194,7 +196,7 @@ class SaleItemsStarPdf < Prawn::Document
text_box "#{item['grand_total'].to_i}", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix text_box "#{item['grand_total'].to_i}", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
} }
if item['total_item'].to_i > 0 if item['total_item'].to_i > 0 or item['status_type'] == 'foc' or item['status_type'] == 'void'
total_qty += item['total_item'].to_i total_qty += item['total_item'].to_i
total_items += item['total_item'].to_i total_items += item['total_item'].to_i
end end
@@ -204,11 +206,17 @@ class SaleItemsStarPdf < Prawn::Document
arr.push(item['menu_category_id']) arr.push(item['menu_category_id'])
end end
# stroke_horizontal_rule move_down 5
stroke_horizontal_rule
total_details('Sub Total', total_qty, sub_total) total_details('Sub Total', total_qty, sub_total)
move_down 5 move_down 5
move_down 5
stroke_horizontal_rule
total_details('Total Amount', total_items, total_amount) total_details('Total Amount', total_items, total_amount)
move_down 10
other_charges = get_other_charges(total_other_charges)
total_details('Total Other Amount', nil, other_charges)
move_down 20
end end
end end
@@ -220,8 +228,6 @@ class SaleItemsStarPdf < Prawn::Document
item_label_total_front_width = (self.item_width+self.price_width) + 2 item_label_total_front_width = (self.item_width+self.price_width) + 2
item_label_total_end_width = 64 item_label_total_end_width = 64
move_down 5
stroke_horizontal_rule
y_position = cursor y_position = cursor
pad_top(15) { pad_top(15) {
text_box "#{col_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix text_box "#{col_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix
@@ -230,4 +236,15 @@ class SaleItemsStarPdf < Prawn::Document
} }
end end
def get_other_charges(total_other_charges)
other_sub_total = 0
unless total_other_charges.nil?
total_other_charges.each do |charges|
other_sub_total += charges.grand_total
end
end
return other_sub_total
end
end end

BIN
dump.rdb

Binary file not shown.