sale_items pdf

This commit is contained in:
Zoey
2019-05-22 13:51:55 +06:30
parent 7c58a5a662
commit ae1779adf3
13 changed files with 246 additions and 32 deletions

View File

@@ -11,6 +11,7 @@ class Origami::ShiftsController < BaseOrigamiController
if !bank_integration[0].nil?
@bank_integration = bank_integration[0][1]
end
end
def new
@@ -83,6 +84,11 @@ class Origami::ShiftsController < BaseOrigamiController
shop_details = shop_detail
#get tax
shift_obj = ShiftSale.where('id =?',@shift.id)
sale_items = ''
@lookup = Lookup.shift_sale_items_lookup_value
if @lookup.to_i == 1
@sale_items = Sale.get_shift_sale_items(@shift.id)
end
@sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='')
@total_waste = Sale.get_total_waste(shift_id).sum(:grand_total)
@total_spoile = Sale.get_total_spoile(shift_id).sum(:grand_total)
@@ -98,11 +104,14 @@ class Origami::ShiftsController < BaseOrigamiController
@total_other_charges = ShiftSale.get_total_other_charges(@shift).total_other_charges_amount
@total_credit_payments = ShiftSale.get_shift_sales_with_credit_payment(shift_id).total_credit_payments
# get printer info
print_settings = PrintSetting.find_by_unique_code(unique_code)
printer = Printer::CashierStationPrinter.new(print_settings)
printer.print_close_cashier(print_settings,cashier_terminal,@shift,shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments)
# close_cashier = Lookup.is_print_close_cashier
# if close_cashier
# get printer info
print_settings = PrintSetting.find_by_unique_code(unique_code)
printer = Printer::CashierStationPrinter.new(print_settings)
printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items,shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments)
# end
end
end
Employee.logout(session[:session_token])

View File

@@ -11,6 +11,7 @@ class PrintSettingsController < ApplicationController
# GET /print_settings/1
# GET /print_settings/1.json
def show
@lookup = Lookup.shift_sale_items_lookup_value
end
# GET /print_settings/new
@@ -21,6 +22,7 @@ class PrintSettingsController < ApplicationController
# GET /print_settings/1/edit
def edit
@lookup = Lookup.shift_sale_items_lookup_value
@server_mode = ENV["SERVER_MODE"]
end
@@ -45,6 +47,10 @@ class PrintSettingsController < ApplicationController
def update
respond_to do |format|
if @print_setting.update(print_setting_params)
if @print_setting.unique_code == 'CloseCashierPdf'
Lookup.save_shift_sale_items_settings(params[:shift_sale_items])
end
format.html { redirect_to @print_setting, notice: 'Print setting was successfully updated.' }
format.json { render :show, status: :ok, location: @print_setting }
else

View File

@@ -31,10 +31,9 @@ class Reports::SaleitemController < BaseReportController
@sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil)
@account_cate_count = Hash.new {|hash, key| hash[key] = 0}
@sale_data.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1}
@menu_cate_count = Hash.new {|hash, key| hash[key] = 0}
@sale_data.each {|cate| @menu_cate_count[cate.account_id] += 1}

View File

@@ -25,4 +25,31 @@ class Lookup < ApplicationRecord
Lookup.select("name, value").where("lookup_type" => type ).map { |l| [l.name, l.value] }
end
def self.create_shift_sale_lookup
@lookup = Lookup.new
@lookup.lookup_type = 'shift_sale_items'
@lookup.name = 'Shift Sale Items'
@lookup.value = 0
@lookup.save
return @lookup
end
def self.save_shift_sale_items_settings(val)
@lookup = Lookup.where('lookup_type=?', 'shift_sale_items').last
if @lookup.nil?
@lookup = Lookup.create_shift_sale_lookup
end
@lookup.value = val
@lookup.save
end
def self.shift_sale_items_lookup_value
@lookup = Lookup.where('lookup_type=?', 'shift_sale_items').last
if @lookup.nil?
@lookup = Lookup.create_shift_sale_lookup
end
return @lookup.value
end
end

View File

@@ -38,7 +38,20 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker
# self.print(filename, cashier_terminal.printer_name)
# end
def print_close_cashier(printer_settings,cashier_terminal,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments)
def print_close_cashier(printer_settings,cashier_terminal,shift_sale, sale_items,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments)
if !sale_items.blank? or !sale_items.nil?
@account_cate_count = Hash.new {|hash, key| hash[key] = 0}
sale_items.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1}
@menu_cate_count = Hash.new {|hash, key| hash[key] = 0}
sale_items.each {|cate| @menu_cate_count[cate.account_id] += 1}
@totalByAccount = Hash.new {|hash, key| hash[key] = 0}
sale_items.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total}
end
#Use CUPS service
#Generate PDF
@@ -46,7 +59,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker
cashier = shift_sale.employee.name
shift_name = shift_sale.shift_started_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + "_" + shift_sale.shift_closed_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p")
filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf"
pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments)
pdf = CloseCashierPdf.new(printer_settings,shift_sale, sale_items, @account_cate_count, @menu_cate_count, @totalByAccount, shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments)
close_cashier_pdf = Lookup.collection_of("print_settings") #print_settings with name:CloseCashierPdf
if !close_cashier_pdf.empty?
@@ -55,7 +68,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker
if close_cashier[1] == '1'
pdf = CloseCashierCustomisePdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments)
else
pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments)
pdf = CloseCashierPdf.new(printer_settings,shift_sale, sale_items, shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments)
end
end
end

View File

@@ -1125,6 +1125,15 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou
return query,other_charges, product, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount
end
def self.get_shift_sale_items(sh_id)
query = Sale.select("sales.shift_sale_id as shift_sale_id, i.account_id as account_id, acc.title as account_name, i.item_instance_code as item_code, i.menu_category_name, i.menu_category_code as menu_category_id, i.product_name as product_name, i.unit_price, i.price as price, i.qty as qty, SUM(i.qty) as total_item, SUM(i.qty * i.unit_price) as grand_total, i.status as status_type, i.remark as remark")
.joins("JOIN sale_items i on i.sale_id = sales.sale_id")
.joins("JOIN accounts acc on acc.id = i.account_id")
.where("sales.shift_sale_id=?", sh_id)
.group("acc.title,i.account_id,i.menu_category_code,i.item_instance_code,i.product_name,i.unit_price")
.order("acc.title desc, i.account_id desc, i.menu_category_code desc, i.unit_price asc")
end
def self.get_product_sale()
query = Sale.select("i.account_id as account_id, " +
"SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," +

View File

@@ -2,7 +2,7 @@ class CloseCashierPdf < Prawn::Document
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
def initialize(printer_settings, shift_sale,shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments)
def initialize(printer_settings, shift_sale, sale_items, acc_cate_count, menu_cate_count, total_by_acc, shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments)
self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width
self.page_height = printer_settings.page_height
self.header_font_size = printer_settings.header_font_size.to_i
@@ -55,6 +55,10 @@ class CloseCashierPdf < Prawn::Document
stroke_horizontal_rule
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?
sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc)
end
end
def header (shop_details)
@@ -175,7 +179,7 @@ class CloseCashierPdf < Prawn::Document
bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
text "#{number_with_precision(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right
end
#start other payment details
if shift_sale.other_sales > 0
other_payment.each do |other|
@@ -395,9 +399,9 @@ class CloseCashierPdf < Prawn::Document
text "#{ number_with_precision(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
end
else
@overall = shift_sale.total_discounts
@overall = shift_sale.total_discounts
end
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
text "Total Discount :", :size => self.item_font_size, :align => :right
@@ -497,6 +501,107 @@ class CloseCashierPdf < Prawn::Document
move_down 5
stroke_horizontal_rule
move_down 5
end
def sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc)
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
end
move_down 5
total_items = 0
total_amount = 0
if !acc_cate_count.nil?
acc_cate_count.each do |key, value|
account = Account.find(key)
y_position = cursor
bounding_box([0,y_position], :width =>self.page_width - 10, :height => 20) do
text "#{account.title}", :size => self.header_font_size, :align => :left
end
move_down 5
stroke_horizontal_rule
move_down 2
y_position = cursor
pad_top(15) {
# @item_width.to_i + @half_qty.to_i
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
}
move_down 2
stroke_horizontal_rule
total_qty = 0
sub_total = 0
sale_items.each do |item|
if item.account_id == key
total_qty += item.total_item.to_i
sub_total += item.grand_total.to_i
move_down 5
y_position = cursor
pad_top(15) {
# @item_width.to_i + @half_qty.to_i
text_box "#{item.product_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix
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
}
# move_down 3
end
end
stroke_horizontal_rule
move_down 5
# 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
total_items += total_qty
total_amount += sub_total
y_position = cursor
pad_top(15) {
# @item_width.to_i + @half_qty.to_i
text_box "Sub Total", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix
# 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 "#{total_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 "#{sub_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
}
move_down 10
end
stroke_horizontal_rule
move_down 5
y_position = cursor
pad_top(15) {
# @item_width.to_i + @half_qty.to_i
text_box "Total Amount", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix
# 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 "#{total_items}", :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_amount}", :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
}
move_down 10
end
end
end

View File

@@ -26,7 +26,7 @@
<div class='col-md-6'>
<span style='font-size:20px;'><b><input type='number' class="form-control" id='closing_balance_amount' value='' onkeypress="return isNumberKey(event);" onkeyup="closeCashier(this.value);"></b></span>
</div>
</div>
</div><br>
</div>
<div class="col-lg-2 col-md-2 col-sm-2">
<button type="button" class="btn bg-default btn-block" id='back'><i class="material-icons">reply</i> <%= t("views.btn.back") %> </button>
@@ -59,6 +59,13 @@
</div>
<script>
// $(document).ready(function(){
// var val = $('#sale_items').val()
// if (val == 1) {
// $('#sale_items').prop( "checked", true );
// }
// })
function closeCashier(val){
var aa = parseInt(val);
if(isNaN(aa)) $("#closing_balance_amount").val("");
@@ -81,9 +88,10 @@
$('#close_cashier').on('click',function(){
var amount = $('#closing_balance_amount').val();
var shift_id = "<%= @shift.id rescue ""%>"
$.ajax({type: "POST",
url: "<%= origami_close_shift_path %>",
data: "closing_balance="+ amount + "&shift_id="+ shift_id,
data: "closing_balance="+ amount + "&shift_id="+ shift_id ,
success:function(result){
console.log(result)
window.location.href = '/';

View File

@@ -27,6 +27,22 @@
<%= f.input :precision, input_html: { min: 0, max: 2, :onkeypress => "return isNumberKey(event);", :onkeyup => "greaterThanTwo(this.value);" } %>
<%= f.input :delimiter %>
<%= f.input :heading_space %>
<% if !@print_setting.new_record? and @print_setting.unique_code == 'CloseCashierPdf' %>
<div class="form-group boolean optional sale_items bmd-form-group is-filled">
<div class="checkbox">
<input value="0" type="hidden" name="shift_sale_items">
<label class="boolean optional" for="sale_items">
<input class="boolean optional" type="checkbox" value="<%= @lookup %>" name="shift_sale_items" id="sale_items" onchange="set_value(this)">
<span class="checkbox-decorator">
<span class="check"></span>
<div class="ripple-container"></div>
</span>Shift Sale Items
</label>
</div>
</div>
<% end %>
</div>
<div class="form-actions">
@@ -82,7 +98,11 @@
.attr("value",value.target)
.text(value.deviceName));
});
}
}
if ($('#sale_items').val() == '1') {
$('#sale_items').prop('checked', true);
}
// if selected printer change call and bind
$("#print_setting_printer_name").on("change", function(){
@@ -119,4 +139,12 @@
function greaterThanTwo(val){
if(parseInt(val)>2) $("#print_setting_precision").val(2);
}
function set_value(ele){
if ($(ele).val() == '1'){
$(ele).val(0)
}else{
$(ele).val(1)
}
}
</script>

View File

@@ -58,6 +58,16 @@
<th><%= t("views.right_panel.detail.print_copies") %></th>
<td><%= @print_setting.print_copies %></td>
</tr>
<tr>
<th>Include Shift Sale Items</th>
<td>
<% if @lookup == '1' %>
<%= 'True' %>
<% else %>
<%= 'False' %>
<% end %>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<%= link_to t("views.btn.edit"), edit_print_setting_path(@print_setting),:class => 'btn btn-info btn-sm waves-effect' %>

View File

@@ -20,11 +20,11 @@ class ActionController::Base
end
else
# check for license file
if check_license
current_license(ENV["SX_PROVISION_URL"])
else
redirect_to activate_path
end
# if check_license
# current_license(ENV["SX_PROVISION_URL"])
# else
# redirect_to activate_path
# end
end
end

View File

@@ -1,10 +1,10 @@
application_path="#{File.expand_path("../..", __FILE__)}"
directory application_path
# environment ENV.fetch("RAILS_ENV") { "production" }
environment "production"
pidfile "#{application_path}/tmp/puma/pid"
state_path "#{application_path}/tmp/puma/state"
stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log"
port ENV.fetch("PORT") { 62158 }
workers 2
preload_app!
# application_path="#{File.expand_path("../..", __FILE__)}"
# directory application_path
# # environment ENV.fetch("RAILS_ENV") { "production" }
# environment "production"
# pidfile "#{application_path}/tmp/puma/pid"
# state_path "#{application_path}/tmp/puma/state"
# stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log"
# port ENV.fetch("PORT") { 62158 }
# workers 2
# preload_app!

BIN
dump.rdb

Binary file not shown.