Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- order_sheet_controller.rb
- def print_order_sheet_summary
- @order_sheet = @company.order_sheets.friendly.find(params[:id])
- @item_array = []
- @valid_items = []
- @order_sheet.order_sheet_details.each do |order_sheet_detail|
- order_sheet_detail.jobs.first.items.each do |item|
- @item_array << item
- end
- end
- @item_array.each do |item|
- if item.item_present?
- else
- #VALID_ITEMS << item
- @valid_items << item
- end
- end
- respond_to do |format|
- format.pdf do
- pdf = OrderSheetSummaryPdf.new(@order_sheet, @valid_items, @item_array)
- send_data pdf.render, filename:
- "order_sheet_summary_#{@order_sheet.order_sheet_name}_#{@order_sheet.created_at.strftime("%d/%m/%Y")}.pdf",
- type: "application/pdf", disposition: "inline"
- end
- end
- end
- order_sheet_summary_pdf.rb
- class OrderSheetSummaryPdf < Prawn::Document
- def initialize(order_sheet, valid_items, item_array,
- test_instance_array, test_instance_var, test_class_array, test_class_var)
- super()
- @order_sheet = order_sheet
- @@valid_items =[]
- @@valid_items = valid_items
- @@item_array = []
- @@item_array = item_array
- order_sheet_summary
- @test_instance_var = test_instance_var
- @@test_class_var = test_class_var
- @@test_class_array = test_class_array
- @test_instance_array = test_instance_array
- end
- def total_item_quantity_in_item_array(v)
- quantity = 0
- @@item_array.each do |i|
- if i.inventory_item == v.inventory_item
- quantity = quantity + i.total_quantity_with_wastage
- end
- end
- return quantity.round(2)
- end
- def order_sheet_summary
- move_down 10
- table([ [ "Article Name", "Total quantity" ] ], :column_widths => [140, 90]) do
- cells.style(size: 8, :font_style => :bold)
- end
- @@valid_items.each do |v|
- table([ [ "#{v.inventory_item.name}", "#{total_item_quantity_in_item_array(v)} #{v.inventory_item.consumption_unit} " ] ],
- :column_widths => [140, 90])do
- cells.style(size: 8)
- end
- end
- end
Add Comment
Please, Sign In to add comment