From ae1779adf37390d8e7c7c5754db8f46fc1bdd56a Mon Sep 17 00:00:00 2001 From: Zoey Date: Wed, 22 May 2019 13:51:55 +0630 Subject: [PATCH] sale_items pdf --- app/controllers/origami/shifts_controller.rb | 19 ++- app/controllers/print_settings_controller.rb | 6 + .../reports/saleitem_controller.rb | 3 +- app/models/lookup.rb | 27 +++++ app/models/printer/cashier_station_printer.rb | 19 ++- app/models/sale.rb | 9 ++ app/pdf/close_cashier_pdf.rb | 113 +++++++++++++++++- app/views/origami/shifts/show.html.erb | 12 +- app/views/print_settings/_form.html.erb | 30 ++++- app/views/print_settings/show.html.erb | 10 ++ config/initializers/action_controller.rb | 10 +- config/puma.rb | 20 ++-- dump.rdb | Bin 810 -> 810 bytes 13 files changed, 246 insertions(+), 32 deletions(-) diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index 52ac1571..1437dd83 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -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]) diff --git a/app/controllers/print_settings_controller.rb b/app/controllers/print_settings_controller.rb index db6c8848..c1e13727 100755 --- a/app/controllers/print_settings_controller.rb +++ b/app/controllers/print_settings_controller.rb @@ -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 diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index aff7f3c2..5dea45b8 100755 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -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} diff --git a/app/models/lookup.rb b/app/models/lookup.rb index 5434cedd..989f9d08 100755 --- a/app/models/lookup.rb +++ b/app/models/lookup.rb @@ -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 diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index c83a161e..5eef742e 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -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 diff --git a/app/models/sale.rb b/app/models/sale.rb index 47c3790f..6be8bb5a 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -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," + diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index 541c6df4..2e48776d 100755 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -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 \ No newline at end of file diff --git a/app/views/origami/shifts/show.html.erb b/app/views/origami/shifts/show.html.erb index f9e923e8..a752e5b5 100755 --- a/app/views/origami/shifts/show.html.erb +++ b/app/views/origami/shifts/show.html.erb @@ -26,7 +26,7 @@
- +
@@ -59,6 +59,13 @@
\ No newline at end of file diff --git a/app/views/print_settings/show.html.erb b/app/views/print_settings/show.html.erb index 32445b95..0278cfd2 100755 --- a/app/views/print_settings/show.html.erb +++ b/app/views/print_settings/show.html.erb @@ -58,6 +58,16 @@ <%= t("views.right_panel.detail.print_copies") %> <%= @print_setting.print_copies %> + + Include Shift Sale Items + + <% if @lookup == '1' %> + <%= 'True' %> + <% else %> + <%= 'False' %> + <% end %> + + <%= link_to t("views.btn.edit"), edit_print_setting_path(@print_setting),:class => 'btn btn-info btn-sm waves-effect' %> diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index fb212f13..cab8fe5d 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -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 diff --git a/config/puma.rb b/config/puma.rb index 6f7c4941..6ee2721b 100755 --- a/config/puma.rb +++ b/config/puma.rb @@ -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! diff --git a/dump.rdb b/dump.rdb index 3ad69d64503187cb2dcd180818e6aa49d528061d..d1adde0cb6060d38f9ffece6a9b4342bb3a2d338 100644 GIT binary patch delta 177 zcmZ3*wu)_n5!18B6HP3cEp&}17D!DtU}Brh$SA^QscT?(fC0putk1|k`3{rnW0YkvG(C7?av-Dp#1aV>1ET|sK&4`nH!!hGES6>cGwao6U!W?v$&pMF zlSLV2CTBBBOw5&KG1oP;n0QBR@&-l;CS${ih0>ExFp3K@u@#o4mZlanvZth`C6?xt cfXretFq&M-q&jh-GUtEElPj-1OR81`02sA6sQ>@~ delta 192 zcmZ3*wu)_n5!1YT6HP29%QDG|Tj&}a9AIE#D=bYdO)X|*Pf1NnEX^sI{Eta_@TS*NjpV53o)w5o58`H87l5C^MOjNqpifoyij!B`42h5(m*N21W-MfedjL zb6rD=iG}i$*D+cH*+yoQZ!)O@jT7TBvOK`>=NsSt!hS}E$rBhw#et@o>Kd9JJi)-g lU0jk_VwIMdnUk6_Igv?W@&`s?eu(@2U$kS6&$0fx2>>0YK575}