Other Charges added to CloseCashierPdf and SaleItemsPdf

This commit is contained in:
Zoey
2019-06-04 11:29:24 +06:30
parent 77103d0780
commit f4bbcdccea
6 changed files with 124 additions and 77 deletions

View File

@@ -59,6 +59,7 @@ class SaleItemsPdf < Prawn::Document
sale_details(period, type, account, from_date, to_date, shift)
sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc, total_other_charges)
move_down 10
end
def header (shop_details)
@@ -128,13 +129,6 @@ class SaleItemsPdf < Prawn::Document
end
def sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc, total_other_charges)
self.item_width = 73
self.price_width = 60
item_label_qty_front_width = (self.item_width+self.price_width) + 2
item_label_qty_end_width = 32
item_label_total_front_width = (self.item_width+self.price_width) + 2
item_label_total_end_width = 64
y_position = cursor
bounding_box([0,y_position], :width =>self.page_width - 10, :height => 20) do
text "Sale Items Summary", :size => self.header_font_size, :align => :center
@@ -171,33 +165,14 @@ class SaleItemsPdf < Prawn::Document
text "#{item['menu_category_name']}", :size => self.header_font_size, :align => :left
end
# write_stroke_dash
# dash(1, :space => 1, :phase => 1)
# stroke_horizontal_rule
# move_down 2
y_position = cursor
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 "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 "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
}
add_item_line('Items', 'Price', 'Qty', 'Total')
move_down 2
stroke_horizontal_rule
end
move_down 3
y_position = cursor
pad_top(15) {
bounding_box([0,y_position], :width =>self.item_width) do
text "#{item['product_name']}", :size => self.item_font_size, :align => :left#, :overflow => :shrink_to_fix
end
text_box "#{item['unit_price'].to_i}", :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 "#{item['total_item'].to_i}", :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 "#{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
}
add_item_line(item['product_name'], item['unit_price'].to_i, item['total_item'].to_i, item['grand_total'].to_i)
if item['total_item'].to_i > 0 or item['status_type'] == 'foc' or item['status_type'] == 'void'
total_qty += item['total_item'].to_i
@@ -213,13 +188,13 @@ class SaleItemsPdf < Prawn::Document
stroke_horizontal_rule
total_details('Sub Total', total_qty, sub_total)
move_down 5
total_other_amount, total_other_item = other_charges_detail(total_other_charges)
total_items += total_other_item
total_amount += total_other_amount
move_down 5
stroke_horizontal_rule
total_details('Total Amount', total_items, total_amount)
other_charges = get_other_charges(total_other_charges)
total_details('Total Other Amount', nil, other_charges)
move_down 20
end
end
@@ -239,15 +214,53 @@ class SaleItemsPdf < Prawn::Document
}
end
def get_other_charges(total_other_charges)
other_sub_total = 0
def other_charges_detail(total_other_charges)
total_charges = 0
total_charges_items = 0
unless total_other_charges.nil?
y_position = cursor
bounding_box([0,y_position], :width =>self.page_width - 10, :height => 20) do
text "Other Charges", :size => self.header_font_size, :align => :left
end
move_down 5
add_item_line('Items', 'Price', 'Qty', 'Total')
move_down 2
stroke_horizontal_rule
total_other_charges.each do |charges|
other_sub_total += charges.grand_total
move_down 3
add_item_line(charges['product_name'], charges['unit_price'].to_i, charges['total_item'].to_i, charges['grand_total'].to_i)
total_charges_items += charges['total_item'].to_i
total_charges += charges['grand_total'].to_i
end
end
return other_sub_total
move_down 5
stroke_horizontal_rule
total_details('Total Charges Amount', total_charges_items, total_charges)
return total_charges, total_charges_items
end
def add_item_line(product_name, unit_price, total_item, grand_total)
self.item_width = 73
self.price_width = 60
item_label_qty_front_width = (self.item_width+self.price_width) + 2
item_label_qty_end_width = 32
item_label_total_front_width = (self.item_width+self.price_width) + 2
item_label_total_end_width = 64
y_position = cursor
pad_top(15) {
bounding_box([0,y_position], :width =>self.item_width) do
text "#{product_name}", :size => self.item_font_size, :align => :left#, :overflow => :shrink_to_fix
end
text_box "#{unit_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 "#{total_item}", :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 "#{grand_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
}
end
end