creating order queue printer

This commit is contained in:
Yan
2017-06-02 19:01:28 +06:30
27 changed files with 688 additions and 6 deletions

View File

@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@@ -0,0 +1,3 @@
// Place all the styles related to the print_settings controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@@ -1,8 +1,25 @@
class Oqs::PrintController < ApplicationController
def print
unique_code=="OrderItemPdf"
assigned_item_id=params[:id]
assigned_order_item=AssignedOrderItem.select("order_id, item_code").where('id='+assigned_item_id)
order_queue_printer= OrderQueuePrinter.new
order_queue_printer.print_order_item(assigned_order_item[0].order_id, assigned_order_item[0].item_code )
print_settings=PrintingSetting.find_by_unique_cod(unique_code)
# order_queue_printer= OrderQueuePrinter.new(print_settings)
order_queue_printer.print_order_item(print_settings,assigned_order_item[0].order_id, assigned_order_item[0].item_code )
unique_code =params[:unique_code]
assigned_item_id=params[:id]
# if unique_code=="OrderItemPdf"
# print_settings=PrintingSetting.find_by_unique_cod(unique_code)
# obj= OrderQueuePrinter.new(print_settings)
# obj.print_order_item(print_settings,assigned_item_id)
# end
# assigned_order_item=AssignedOrderItem.select("order_id, item_code").where('id='+assigned_item_id)
# order_queue_printer.print_order_item(assigned_order_item[0].order_id, assigned_order_item[0].item_code )
end
end

View File

@@ -0,0 +1,74 @@
class PrintSettingsController < ApplicationController
before_action :set_print_setting, only: [:show, :edit, :update, :destroy]
# GET /print_settings
# GET /print_settings.json
def index
@print_settings = PrintSetting.all
end
# GET /print_settings/1
# GET /print_settings/1.json
def show
end
# GET /print_settings/new
def new
@print_setting = PrintSetting.new
end
# GET /print_settings/1/edit
def edit
end
# POST /print_settings
# POST /print_settings.json
def create
@print_setting = PrintSetting.new(print_setting_params)
respond_to do |format|
if @print_setting.save
format.html { redirect_to @print_setting, notice: 'Print setting was successfully created.' }
format.json { render :show, status: :created, location: @print_setting }
else
format.html { render :new }
format.json { render json: @print_setting.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /print_settings/1
# PATCH/PUT /print_settings/1.json
def update
respond_to do |format|
if @print_setting.update(print_setting_params)
format.html { redirect_to @print_setting, notice: 'Print setting was successfully updated.' }
format.json { render :show, status: :ok, location: @print_setting }
else
format.html { render :edit }
format.json { render json: @print_setting.errors, status: :unprocessable_entity }
end
end
end
# DELETE /print_settings/1
# DELETE /print_settings/1.json
def destroy
@print_setting.destroy
respond_to do |format|
format.html { redirect_to print_settings_url, notice: 'Print setting was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_print_setting
@print_setting = PrintSetting.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def print_setting_params
params.require(:print_setting).permit(:name, :unique_code, :template, :db_name, :db_type, :db_username, :db_password, :printer_name, :api_settings, :page_width, :page_height, :print_copies)
end
end

View File

@@ -0,0 +1,2 @@
module PrintSettingsHelper
end

View File

@@ -0,0 +1,2 @@
class PrintSetting < ApplicationRecord
end

View File

@@ -1,10 +1,11 @@
class Printer::OrderQueuePrinter < Printer::PrinterWorker
def print_order_item(order_id, item_code)
def print_order_item(printer_settings,order_id, item_code)
#Use CUPS service
#Generate PDF
#Print
pdf = OrderItemPdf.new
order_item=OrderItem.find_by_item_code(item_code)
pdf = OrderItemPdf.new(printer_settings,order_item)
pdf.render_file "tmp/order_item_queue_#{order_id}_#{item_code}" + ".pdf"
self.print("tmp/receipt.pdf")
end

View File

@@ -0,0 +1,22 @@
<%= simple_form_for(@print_setting) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :name %>
<%= f.input :unique_code %>
<%= f.input :template %>
<%= f.input :db_name %>
<%= f.input :db_type %>
<%= f.input :db_username %>
<%= f.input :db_password %>
<%= f.input :printer_name %>
<%= f.input :api_settings %>
<%= f.input :page_width %>
<%= f.input :page_height %>
<%= f.input :print_copies %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>

View File

@@ -0,0 +1,2 @@
json.extract! print_setting, :id, :name,, :unique_code,, :template,, :db_name,, :db_type,, :db_username,, :db_password,, :printer_name,, :api_settings,, :page_width, :page_height, :print_copies, :created_at, :updated_at
json.url print_setting_url(print_setting, format: :json)

View File

@@ -0,0 +1,6 @@
<h1>Editing Print Setting</h1>
<%= render 'form', print_setting: @print_setting %>
<%= link_to 'Show', @print_setting %> |
<%= link_to 'Back', print_settings_path %>

View File

@@ -0,0 +1,49 @@
<p id="notice"><%= notice %></p>
<h1>Print Settings</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Unique code</th>
<th>Template</th>
<th>Db name</th>
<th>Db type</th>
<th>Db username</th>
<th>Db password</th>
<th>Printer name</th>
<th>Api settings</th>
<th>Page width</th>
<th>Page height</th>
<th>Print copies</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @print_settings.each do |print_setting| %>
<tr>
<td><%= print_setting.name %></td>
<td><%= print_setting.unique_code %></td>
<td><%= print_setting.template %></td>
<td><%= print_setting.db_name %></td>
<td><%= print_setting.db_type %></td>
<td><%= print_setting.db_username %></td>
<td><%= print_setting.db_password %></td>
<td><%= print_setting.printer_name %></td>
<td><%= print_setting.api_settings %></td>
<td><%= print_setting.page_width %></td>
<td><%= print_setting.page_height %></td>
<td><%= print_setting.print_copies %></td>
<td><%= link_to 'Show', print_setting %></td>
<td><%= link_to 'Edit', edit_print_setting_path(print_setting) %></td>
<td><%= link_to 'Destroy', print_setting, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Print Setting', new_print_setting_path %>

View File

@@ -0,0 +1 @@
json.array! @print_settings, partial: 'print_settings/print_setting', as: :print_setting

View File

@@ -0,0 +1,5 @@
<h1>New Print Setting</h1>
<%= render 'form', print_setting: @print_setting %>
<%= link_to 'Back', print_settings_path %>

View File

@@ -0,0 +1,64 @@
<p id="notice"><%= notice %></p>
<p>
<strong>Name:</strong>
<%= @print_setting.name %>
</p>
<p>
<strong>Unique code:</strong>
<%= @print_setting.unique_code %>
</p>
<p>
<strong>Template:</strong>
<%= @print_setting.template %>
</p>
<p>
<strong>Db name:</strong>
<%= @print_setting.db_name %>
</p>
<p>
<strong>Db type:</strong>
<%= @print_setting.db_type %>
</p>
<p>
<strong>Db username:</strong>
<%= @print_setting.db_username %>
</p>
<p>
<strong>Db password:</strong>
<%= @print_setting.db_password %>
</p>
<p>
<strong>Printer name:</strong>
<%= @print_setting.printer_name %>
</p>
<p>
<strong>Api settings:</strong>
<%= @print_setting.api_settings %>
</p>
<p>
<strong>Page width:</strong>
<%= @print_setting.page_width %>
</p>
<p>
<strong>Page height:</strong>
<%= @print_setting.page_height %>
</p>
<p>
<strong>Print copies:</strong>
<%= @print_setting.print_copies %>
</p>
<%= link_to 'Edit', edit_print_setting_path(@print_setting) %> |
<%= link_to 'Back', print_settings_path %>

View File

@@ -0,0 +1 @@
json.partial! "print_settings/print_setting", print_setting: @print_setting