oqs printing

This commit is contained in:
Yan
2017-06-04 18:25:09 +06:30
parent 869c574107
commit 8d4086d5e9
7 changed files with 141 additions and 15 deletions

View File

@@ -80,4 +80,14 @@ $(document).ready(function(){
success: function(data){ }
});
});
$('#print_order_summary').on('click',function(){
var assigned_item_id=$('.selected-item').children('.card-block').children('.assigned-order-item').text();
var params = { 'id':assigned_item_id };
$.ajax({
type: 'GET',
url: '/oqs/print/print_order_summary/'+assigned_item_id,
success: function(data){ }
});
});
});

View File

@@ -13,4 +13,19 @@ class Oqs::PrintController < ApplicationController
assigned_item.print_status=true
assigned_item.save
end
def print_order_summary
unique_code="OrderSummaryPdf"
assigned_item_id=params[:id]
assigned_order_item=AssignedOrderItem.select("order_id").where('id='+assigned_item_id)
print_settings=PrintSetting.find_by_unique_code(unique_code)
order_queue_printer= Printer::OrderQueuePrinter.new(print_settings)
order_queue_printer.print_order_summary(print_settings,assigned_order_item[0].order_id)
# update print status when complete click
assigned_item=AssignedOrderItem.find(assigned_item_id)
assigned_item.print_status=true
assigned_item.save
end
end

View File

@@ -10,12 +10,12 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
self.print("tmp/receipt.pdf")
end
def print_order_summary(printer_settings,booking_id)
def print_order_summary(printer_settings,order_id)
#Use CUPS service
#Generate PDF
#Print
order=print_query('booking',booking_id)
filename = "tmp/order_summary_#{booking_id}" + ".pdf"
order=print_query('order_summary',order_id)
filename = "tmp/order_summary_#{order_id}" + ".pdf"
pdf = OrderSummaryPdf.new(order,printer_settings)
pdf.render_file filename
@@ -25,7 +25,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
# Query for OQS with status
def print_query(type, code)
if type == 'order_item'
OrderItem.select("order_items.item_code, order_items.item_name,order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining")
OrderItem.select("order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining")
.joins("left join orders ON orders.id = order_items.order_id
left join booking_orders AS bo ON bo.order_id=order_items.order_id
left join bookings AS b ON b.id = bo.booking_id
@@ -34,12 +34,14 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
.where("order_items.item_code=" + code)
.group("order_items.item_code")
else
OrderItem.select("order_items.item_code, order_items.item_name, df.name as dining")
OrderItem.select("order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining")
.joins("left join orders ON orders.id = order_items.order_id
left join booking_orders AS bo ON bo.order_id=order_items.order_id
left join bookings AS b ON b.id = bo.booking_id
left join dining_facilities AS df ON df.id = b.dining_facility_id")
.where("booking.id=" + code)
left join dining_facilities AS df ON df.id = b.dining_facility_id
left join customers as cus ON cus.id = orders.customer_id")
.where("orders.id=" + code.to_s)
.group("order_items.item_code")
end
end

View File

@@ -11,21 +11,61 @@ class OrderItemPdf < Prawn::Document
stroke_horizontal_rule
move_down 5
cashier_info(order_item.order_by,order_item.order_at, order_item.customer)
#order_info
order_info(order_item.order_by,order_item.order_at, order_item.customer)
# order items
order_items(order_item)
end
def cashier_info(order_by, order_at, customer)
move_down 5
# Write Order Information to PDF
def order_info(order_by, order_at, customer)
y_position = cursor
bounding_box([0,y_position], :width =>200, :height => 20) do
text "OrderBy:#{order_by} Customer:#{customer} Date:#{order_at.strftime("%Y %m %d")}", :size => 7,:align => :left
bounding_box([0,y_position], :width => 200, :height => 15) do
text "OrderBy:#{order_by} Customer:#{customer} Date:#{order_at.strftime("%Y-%m-%d")}", :size => 7,:align => :left
end
stroke_horizontal_rule
move_down 20
end
# Write Order items to PDF
def order_items(order_item)
y_position = cursor
bounding_box([0,y_position], :width => 180, :height => 15) do
text "Item", :size => 7,:align => :left
end
bounding_box([160,y_position], :width => 20, :height => 15) do
text "Qty", :size => 7,:align => :right
end
stroke_horizontal_rule
move_down 5
#Add Order Item
add_order_items(order_item)
end
# Add order items under order info
def add_order_items(order_item)
y_position = cursor
move_down 5
bounding_box([0,y_position], :width => 180, :height => 20) do
text "#{order_item.item_name}", :size => 7,:align => :left
end
bounding_box([160,y_position], :width => 20, :height => 20) do
text "#{order_item.qty}", :size => 7,:align => :right
end
move_down 5
end
end

View File

@@ -7,11 +7,68 @@ class OrderSummaryPdf < Prawn::Document
# font "public/fonts/Zawgyi-One.ttf"
# font "public/fonts/padauk.ttf"
font_size 9
text "#{"table_name"}", :size => 15
text "#{order[0].dining}", :size => 15
stroke_horizontal_rule
move_down 5
#order_info
order_info(order[0].order_by,order[0].order_at, order[0].customer)
# order items
order_items(order)
end
# Write Order Information to PDF
def order_info(order_by, order_at, customer)
y_position = cursor
bounding_box([0,y_position], :width => 200, :height => 15) do
text "OrderBy:#{order_by} Customer:#{customer} Date:#{order_at.strftime("%Y-%m-%d")}", :size => 7,:align => :left
end
stroke_horizontal_rule
move_down 20
end
# Write Order items to PDF
def order_items(order_item)
y_position = cursor
bounding_box([0,y_position], :width => 180, :height => 15) do
text "Item", :size => 7,:align => :left
end
bounding_box([160,y_position], :width => 20, :height => 15) do
text "Qty", :size => 7,:align => :right
end
stroke_horizontal_rule
move_down 5
#Add Order Item
add_order_items(order_item)
end
# Add order items under order info
def add_order_items(order_item)
y_position = cursor
move_down 5
order_item.each do|odi|
bounding_box([0,y_position], :width => 180, :height => 20) do
text "#{odi.item_name}", :size => 7,:align => :left
end
bounding_box([160,y_position], :width => 20, :height => 20) do
text "#{odi.qty}", :size => 7,:align => :right
end
end
move_down 5
end
end

View File

@@ -193,7 +193,7 @@
<div class="col-lg-1 col-md-1 col-sm-1">
<!-- OQS Buttons -->
<button type="button" title="Print Order Item" id="print_order_item" class="btn btn-primary btn-lg btn-block">Print</a>
<button type="button" class="btn btn-primary btn-lg btn-block" id="print_order_item" disabled>Print <br/>Order<br/>Summary</button>
<button type="button" class="btn btn-primary btn-lg btn-block" id="print_order_summary">Print <br/>Order<br/>Summary</button>
</div>
</div>