From 8e7e58f8ac5a3e12cfa63b2d4aad15591190e6d6 Mon Sep 17 00:00:00 2001 From: Aung Kyaw Phyoe Date: Thu, 7 Feb 2019 11:55:55 +0630 Subject: [PATCH 01/15] printer issue for CheckInOutPdf and header css --- app/assets/stylesheets/reset.css | 8 -------- app/models/printer/order_queue_printer.rb | 2 +- app/views/layouts/_header.html.erb | 2 +- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/app/assets/stylesheets/reset.css b/app/assets/stylesheets/reset.css index 5a65a5ae..c82d7cf7 100644 --- a/app/assets/stylesheets/reset.css +++ b/app/assets/stylesheets/reset.css @@ -284,14 +284,6 @@ section.content { } /* End Reset Theme */ -/* shop name margin */ -.shop-name-margin { - text-align: center; - width: 50%; - margin: auto; -} -/* shop name margin */ - /* online order margin */ /*.online-order-margin { margin: auto; diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index b50d83f9..87f2ba1f 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -352,7 +352,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker #no print in cloud server if ENV["SERVER_MODE"] != "cloud" - self.print(filename, cashier_terminal.printer_name) + self.print(filename, print_settings.printer_name) end end end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index fbcbece1..164b6c4f 100755 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -36,7 +36,7 @@ - @@ -33,33 +33,34 @@ - <% if @shift_from %> - <% if @shift_data.employee %> + <% if @shift_data.employee %> <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> - <% end %> + <% end %> - <% end %> + <% end %> - + - + - + + @@ -74,27 +75,27 @@ else delimiter = "" end - %> - <% void = 0%> - <% cash = 0%> - <% credit = 0%> - <% accept_credit = 0%> - <% foc = 0%> + %> + <% void = 0%> + <% cash = 0%> + <% credit = 0%> + <% accept_credit = 0%> + <% foc = 0%> <% card = 0%> - <% total = 0%> - <% rounding_adj = 0%> + <% total = 0%> + <% rounding_adj = 0%> <% g_total = 0 %> <% @sale_data.each do |result|%> - + - @@ -102,23 +103,25 @@ - + --> + - - + + + - <% grand_total = result[:grand_total].to_f %> - + <% grand_total = result[:grand_total].to_f %> + <% cash += result[:cash_sales].to_f %> <% credit += result[:credit_sales].to_f %> - <% card += result[:other_sales].to_f %> - <% foc += result[:foc_sales].to_f %> + <% card += result[:other_sales].to_f %> + <% foc += result[:foc_sales].to_f %> - <% total += result[:grand_total].to_f %> + <% total += result[:grand_total].to_f %> <% g_total += grand_total.to_f %> <% end %> @@ -133,8 +136,8 @@ - - + +
<%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> + <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
<%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
<%= t("views.right_panel.detail.cashier_station") %> <%= t :cashier %> <%= t("views.right_panel.detail.name") %><%= t("views.right_panel.detail.shift_name") %><%= t("views.right_panel.detail.shift_name") %> <%= t("views.right_panel.detail.cash_payment") %> <%= t("views.right_panel.detail.credit_payment") %> <%= t("views.btn.other_payment") %> <%= t("views.btn.foc") %> <%= t :payment %> <%= t("views.right_panel.detail.grand_total") %><%= t("views.right_panel.detail.grand_total") %>Print
- <%= result[:cashier_terminal_name] rescue '-'%> + <%= result[:cashier_terminal_name] rescue '-'%> <%= result[:shift_id].to_i %> <%= result[:employee_name] rescue '-'%> <%= result[:shift_started_at].strftime("%e %b %I:%M%p") rescue '-' %> - + <%= result[:shift_started_at].strftime("%e %b %I:%M%p") rescue '-' %> - <%= result[:shift_closed_at] ? result[:shift_closed_at].strftime("%e %b %I:%M%p") : '-' %> <%= number_with_precision(result[:credit_sales].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(result[:other_sales].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= sprintf "%.2f",result.card_amount.to_f.to_d rescue '-'%><%= number_with_precision(result[:other_sales].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(result[:foc_sales].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <%= number_with_precision(result[:grand_total].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_with_precision(result[:grand_total].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= link_to "Print", reports_get_shift_id_path(result[:shift_id].to_i), class:"btn btn-info wave-effects" %> +
<%= number_with_precision(card, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(foc, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(g_total, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_with_precision(g_total, precision:precision.to_i,delimiter:delimiter) rescue '-'%>
@@ -142,25 +145,32 @@ - - diff --git a/config/routes.rb b/config/routes.rb index f25ff1b8..e9594cce 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,7 +12,7 @@ scope "(:locale)", locale: /en|mm/ do # if ENV["SERVER_MODE"] != "cloud" mount ActionCable.server => "/cable" # end - + #--------- SmartSales Activation ------------# get 'activate' => 'install#index' @@ -92,7 +92,7 @@ scope "(:locale)", locale: /en|mm/ do post "callback/:id" => "order_reservation#update_status" get "get_tax_profile" => "order_reservation#get_tax_profile" end - + post "sound_effect" => "sound_effect#sound_effect" #API for cashier app @@ -105,16 +105,16 @@ scope "(:locale)", locale: /en|mm/ do end #--------- Cashier ------------# - namespace :origami do + namespace :origami do root "home#index" post '/check_emp_access_code/:code' => 'home#check_emp_access_code', :defaults => { :format => 'json' } - get "dashboard" => "dashboard#index" - get "get_all_menu" => "dashboard#get_all_menu" + get "dashboard" => "dashboard#index" + get "get_all_menu" => "dashboard#get_all_menu" get "quick_service" => "quick_service#index" - + get ":type/pending_order" => "pending_order#index" get ":type/pending_order/:sale_id" => "pending_order#show" get ":type/completed_sale/:sale_id" => "pending_order#completed_sale" @@ -122,7 +122,7 @@ scope "(:locale)", locale: /en|mm/ do get "quick_service/modify_order/:id/:sale_id" => "quick_service#modify_order" get "quick_service/modify_order/:sale_id" => "quick_service#modify_order" post 'quick_service/update_modify_order' => "quick_service#update_modify_order", :defaults => { :format => 'json' } - + get ":type/cash_ins" => "pending_order#cash_ins" get ":type/cash_outs" => "pending_order#cash_outs" @@ -135,7 +135,7 @@ scope "(:locale)", locale: /en|mm/ do resources :cash_ins, only: [:new, :create] resources :cash_outs, only: [:new, :create] - + get "table/:dining_id" => "home#show" do #origami/:booking_id will show # resources :discounts, only: [:index,:new, :create ] #add discount type resources :customers #add customer type @@ -268,10 +268,10 @@ scope "(:locale)", locale: /en|mm/ do get '/:addorders/:id' => "addorders#detail" post '/:addorders/create' => "addorders#create",:as => "addorder_create", :defaults => { :format => 'json' } - + get '/addorders/get_item_instance/:id' => "addorders#get_item_instance",:as => "get_item_instance", :defaults => { :format => 'json' } - + resources :commissions resources :commissioners @@ -341,7 +341,7 @@ scope "(:locale)", locale: /en|mm/ do get 'sale/:sale_id/:type/credit_payment/others_payment/Alipay' => "alipay#index" # get 'sale/:sale_id/:type/credit_payment/others_payment/DINGA' => "dinga#index" # get 'sale/:sale_id/:type/credit_payment/others_payment/GiftVoucher' => "gift_voucher#index" - + #------------- Start Reservation -------------------# resources :reservation #------------- End Reservation -------------------# @@ -402,8 +402,8 @@ scope "(:locale)", locale: /en|mm/ do collection do post :import end - resources :menu_categories, only: [:new, :create, :edit, :delete] - end + resources :menu_categories, only: [:new, :create, :edit, :delete] + end get '/menus/:id/export' => 'menus#export' @@ -524,6 +524,7 @@ scope "(:locale)", locale: /en|mm/ do get "receipt_no/get_shift_by_date", to: "receipt_no#get_shift_by_date", as: "get_shift_by_date" get "order_reservation/get_shift_by_date", to: "order_reservation#show", as: "get_shift_by_order_reservation" get "induty/get_shift_by_date", to: "induty#show", as: "get_shift_by_induty" + get "shiftsale_print/:id" , to: "shiftsale#print_close_receipt", as: "get_shift_id" end From ae1779adf37390d8e7c7c5754db8f46fc1bdd56a Mon Sep 17 00:00:00 2001 From: Zoey Date: Wed, 22 May 2019 13:51:55 +0630 Subject: [PATCH 10/15] 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} From 8012bf89683073500149e033cabe1b803e75789e Mon Sep 17 00:00:00 2001 From: Git Code2lab Date: Fri, 24 May 2019 06:47:45 +0000 Subject: [PATCH 11/15] Update puma.rb --- config/puma.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/config/puma.rb b/config/puma.rb index 6ee2721b..6f7c4941 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! From c1d36536125e83981318a55f12f76e4b40737b3f Mon Sep 17 00:00:00 2001 From: Git Code2lab Date: Fri, 24 May 2019 06:48:24 +0000 Subject: [PATCH 12/15] Update action_controller.rb --- config/initializers/action_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index cab8fe5d..5abb412e 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 From 7d105b27897a3d11d5999c52bc7cca4bbe68c617 Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Fri, 24 May 2019 14:56:08 +0630 Subject: [PATCH 13/15] fixed grand total at receipt no report --- app/models/sale.rb | 1 + .../_shift_sale_report_filter.html.erb | 34 ++--- app/views/reports/receipt_no/index.html.erb | 136 +++++++++--------- app/views/reports/shiftsale/index.html.erb | 2 +- config/initializers/action_controller.rb | 61 ++++---- config/puma.rb | 3 +- 6 files changed, 120 insertions(+), 117 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index 7ce7e11e..ef38e8b2 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -879,6 +879,7 @@ def self.daily_sales_list(from,to) total_sale.each do |sale| grand_total = sale.grand_total + amount_received = sale.amount_received old_grand_total = sale.old_grand_total total_discount = sale.total_discount void_amount = sale.void_amount diff --git a/app/views/reports/receipt_no/_shift_sale_report_filter.html.erb b/app/views/reports/receipt_no/_shift_sale_report_filter.html.erb index 6cf8ce02..a54afb7f 100755 --- a/app/views/reports/receipt_no/_shift_sale_report_filter.html.erb +++ b/app/views/reports/receipt_no/_shift_sale_report_filter.html.erb @@ -19,10 +19,10 @@ <% if not defined? payments %> - +
- + -
+ <% end %> -
+
@@ -47,36 +47,36 @@
-
-
+
+ -
-
+
+ <% end %> - <% end %> - + <% end %> + \ No newline at end of file + diff --git a/app/views/reports/shiftsale/index.html.erb b/app/views/reports/shiftsale/index.html.erb index 6068347b..529636b9 100755 --- a/app/views/reports/shiftsale/index.html.erb +++ b/app/views/reports/shiftsale/index.html.erb @@ -90,7 +90,7 @@ - <%= result[:cashier_terminal_name] rescue '-'%> <%= result[:shift_id].to_i %> + <%= result[:cashier_terminal_name] rescue '-'%> <%= result[:employee_name] rescue '-'%> diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index fb212f13..196f8751 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -3,45 +3,45 @@ class ActionController::Base private - def lookup_domain - if request.subdomain.present? && request.subdomain != "www" - from = request.subdomain.downcase + "." + request.domain.downcase + def lookup_domain + if request.subdomain.present? && request.subdomain != "www" + from = request.subdomain.downcase + "." + request.domain.downcase @license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase if (!@license.nil?) - logger.info "Location - " + @license.dbschema - ActiveRecord::Base.establish_connection(website_connection(@license)) - # authenticate_session_token + logger.info "Location - " + @license.dbschema + ActiveRecord::Base.establish_connection(website_connection(@license)) + # authenticate_session_token # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema else # reconnect_default_db logger.info 'License is nil' # redirect_to root_url(:host => request.domain) + "store_error" render :json => [{ status: false, message: 'Invalid Access!'}] - end - else - # check for license file + end + else + check for license file if check_license current_license(ENV["SX_PROVISION_URL"]) else redirect_to activate_path - end - end + end + end end - def current_license(url) + def current_license(url) @license = License.new(url) flag = @license.detail_with_local_file() if (flag == 0) - flash[:notice] = 'Expired or No License!' + flash[:notice] = 'Expired or No License!' elsif (flag == 2) - flash[:notice] = 'Expiring! Please, License extend...' + flash[:notice] = 'Expiring! Please, License extend...' else puts "RUN SAY BYAR" end end - def cache_license(url, lookup) - @license = License.new(url, lookup) + def cache_license(url, lookup) + @license = License.new(url, lookup) if (@license.detail_with_local_cache(lookup) == true) return @license @@ -51,7 +51,7 @@ class ActionController::Base end def check_license - License.check_license_file + License.check_license_file end def check_installation @@ -83,7 +83,7 @@ class ActionController::Base # RESTful url for localize def default_url_options { locale: I18n.locale } - end + end end @@ -92,26 +92,26 @@ class ActionController::API private - def lookup_domain - if request.subdomain.present? && request.subdomain != "www" - from = request.subdomain.downcase + "." + request.domain.downcase + def lookup_domain + if request.subdomain.present? && request.subdomain != "www" + from = request.subdomain.downcase + "." + request.domain.downcase @license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase if (!@license.nil?) - logger.info "Location - " + @license.dbschema - ActiveRecord::Base.establish_connection(website_connection(@license)) - # authenticate_session_token + logger.info "Location - " + @license.dbschema + ActiveRecord::Base.establish_connection(website_connection(@license)) + # authenticate_session_token # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema else # reconnect_default_db logger.info 'License is nil' # redirect_to root_url(:host => request.domain) + "store_error" render :json => [{ status: false, message: 'Invalid Access!'}] - end - end - end + end + end + end - def cache_license(url, lookup) - @license = License.new(url, lookup) + def cache_license(url, lookup) + @license = License.new(url, lookup) if (@license.detail_with_local_cache(lookup) == true) return @license @@ -143,7 +143,6 @@ class ActionController::API # RESTful url for localize def default_url_options { locale: I18n.locale } - end + end end - diff --git a/config/puma.rb b/config/puma.rb index 6f7c4941..7a12c8c2 100755 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,7 +1,6 @@ application_path="#{File.expand_path("../..", __FILE__)}" directory application_path -# environment ENV.fetch("RAILS_ENV") { "production" } -environment "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" From 2f2836b1a2d9a64089281e1f6886e2fc67cfd8bf Mon Sep 17 00:00:00 2001 From: Git Code2lab Date: Fri, 24 May 2019 09:13:31 +0000 Subject: [PATCH 14/15] Update puma.rb --- config/puma.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/puma.rb b/config/puma.rb index 7a12c8c2..363c65ba 100755 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,6 +1,6 @@ application_path="#{File.expand_path("../..", __FILE__)}" directory application_path -#environment "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" From 4328ab1cea78b87ad4573de3cb03ef3fd3a0f58e Mon Sep 17 00:00:00 2001 From: Zoey Date: Tue, 28 May 2019 09:34:05 +0630 Subject: [PATCH 15/15] sx star printer setting rearrangement --- .../origami/payments_controller.rb | 42 +- app/models/order_queue_station.rb | 2 + app/models/printer/order_queue_printer.rb | 6 + app/models/printer/receipt_printer.rb | 15 +- app/pdf/move_table_star_pdf.rb | 117 +++ app/pdf/order_item_star_pdf.rb | 162 ++++ app/pdf/receipt_bill_star_pdf.rb | 756 ++++++++++++++++++ dump.rdb | Bin 810 -> 810 bytes 8 files changed, 1093 insertions(+), 7 deletions(-) create mode 100644 app/pdf/move_table_star_pdf.rb create mode 100644 app/pdf/order_item_star_pdf.rb create mode 100644 app/pdf/receipt_bill_star_pdf.rb diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 11c91a2b..59aaec3a 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -35,13 +35,24 @@ class Origami::PaymentsController < BaseOrigamiController receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf # Print for First Bill to Customer unique_code = "ReceiptBillPdf" + print_settings = PrintSetting.all + if !print_settings.nil? + print_settings.each do |setting| + if setting.unique_code == 'ReceiptBillPdf' + unique_code = "ReceiptBillPdf" + elsif setting.unique_code == 'ReceiptBillStarPdf' + unique_code = "ReceiptBillStarPdf" + end + end + end + if !receipt_bill_a5_pdf.empty? receipt_bill_a5_pdf.each do |receipt_bilA5| if receipt_bilA5[0] == 'ReceiptBillA5Pdf' if receipt_bilA5[1] == '1' unique_code = "ReceiptBillA5Pdf" else - unique_code = "ReceiptBillPdf" + unique_code = unique_code#{}"ReceiptBillPdf" end end end @@ -169,13 +180,24 @@ class Origami::PaymentsController < BaseOrigamiController # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf unique_code = "ReceiptBillPdf" + print_settings = PrintSetting.all + if !print_settings.nil? + print_settings.each do |setting| + if setting.unique_code == 'ReceiptBillPdf' + unique_code = "ReceiptBillPdf" + elsif setting.unique_code == 'ReceiptBillStarPdf' + unique_code = "ReceiptBillStarPdf" + end + end + end + if !receipt_bill_a5_pdf.empty? receipt_bill_a5_pdf.each do |receipt_bilA5| if receipt_bilA5[0] == 'ReceiptBillA5Pdf' if receipt_bilA5[1] == '1' unique_code = "ReceiptBillA5Pdf" - else - unique_code = "ReceiptBillPdf" + # else + end end end @@ -686,13 +708,23 @@ class Origami::PaymentsController < BaseOrigamiController else receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf unique_code = "ReceiptBillPdf" + print_settings = PrintSetting.all + if !print_settings.nil? + print_settings.each do |setting| + if setting.unique_code == 'ReceiptBillPdf' + unique_code = "ReceiptBillPdf" + elsif setting.unique_code == 'ReceiptBillStarPdf' + unique_code = "ReceiptBillStarPdf" + end + end + end if !receipt_bill_a5_pdf.empty? receipt_bill_a5_pdf.each do |receipt_bilA5| if receipt_bilA5[0] == 'ReceiptBillA5Pdf' if receipt_bilA5[1] == '1' unique_code = "ReceiptBillA5Pdf" - else - unique_code = "ReceiptBillPdf" + # else + # unique_code = "ReceiptBillPdf" end end end diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index 42891015..147ebdc4 100755 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -256,6 +256,8 @@ class OrderQueueStation < ApplicationRecord printer.each do |printer_setting| if printer_setting.unique_code == 'OrderItemPdf' unique_code="OrderItemPdf" + elsif printer_setting.unique_code == 'OrderItemStarPdf' + unique_code="OrderItemStarPdf" elsif printer_setting.unique_code == 'OrderItemSlimPdf' unique_code="OrderItemSlimPdf" elsif printer_setting.unique_code == 'OrderSetItemPdf' diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index e9e76a86..25cdef92 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -21,6 +21,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker print_setting.each do |print_settings| if print_settings.unique_code == 'OrderItemPdf' pdf = OrderItemPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) + elsif print_settings.unique_code == 'OrderItemStarPdf' + pdf = OrderItemStarPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) elsif print_settings.unique_code == 'OrderItemSlimPdf' pdf = OrderItemSlimPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) elsif print_settings.unique_code == 'OrderSetItemPdf' @@ -100,6 +102,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker print_setting.each do |print_settings| if print_settings.unique_code == 'OrderItemPdf' pdf = OrderItemPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty) + elsif print_settings.unique_code == 'OrderItemStarPdf' + pdf = OrderItemStarPdfnew(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) elsif print_settings.unique_code == 'OrderItemSlimPdf' pdf = OrderItemSlimPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty) elsif print_settings.unique_code == 'OrderSetItemPdf' @@ -207,6 +211,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker print_setting.each do |print_settings| if print_settings.unique_code == 'OrderItemPdf' pdf = OrderItemPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty) + elsif print_settings.unique_code == 'OrderItemStarPdf' + pdf = OrderItemStarPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty) elsif print_settings.unique_code == 'OrderItemSlimPdf' pdf = OrderItemSlimPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty) elsif print_settings.unique_code == 'OrderSetItemPdf' diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 2b01c174..83a8e6c6 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -195,14 +195,25 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker if !printer_settings.nil? if !printer_settings.unique_code.strip.downcase.include? ("receiptbillorder") pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) + settings = PrintSetting.all + if !settings.nil? + settings.each do |setting| + if setting.unique_code == 'ReceiptBillPdf' + pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) + elsif setting.unique_code == 'ReceiptBillStarPdf' + pdf = ReceiptBillStarPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) + end + end + end + receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf if !receipt_bill_a5_pdf.empty? receipt_bill_a5_pdf.each do |receipt_bilA5| if receipt_bilA5[0] == 'ReceiptBillA5Pdf' if receipt_bilA5[1] == '1' pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) - else - pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) + # else + # pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) end end end diff --git a/app/pdf/move_table_star_pdf.rb b/app/pdf/move_table_star_pdf.rb new file mode 100644 index 00000000..cce17677 --- /dev/null +++ b/app/pdf/move_table_star_pdf.rb @@ -0,0 +1,117 @@ +class MoveTableStarPdf < 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 + def initialize(printer_settings,to,from,shop_detail,date,type,moved_by,order_items) + self.page_width = printer_settings.page_width + self.page_height = printer_settings.page_height + self.header_font_size = printer_settings.header_font_size.to_i + self.item_font_size = printer_settings.item_font_size.to_i + self.margin = 0 + self.price_width = 40 # No Need for item + self.qty_width = 40 + self.total_width = 40 # No Need for item + self.item_width = self.page_width - (self.qty_width - self.margin) + self.item_height = 15 + self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) + self.label_width=90 + + super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) + + # db font setup + if printer_settings.font != "" + font_families.update("#{printer_settings.font}" => { + :normal => "public/fonts/#{printer_settings.font}.ttf", + :italic => "public/fonts/#{printer_settings.font}.ttf", + :bold => "public/fonts/#{printer_settings.font}.ttf", + :bold_italic => "public/fonts/#{printer_settings.font}.ttf" + }) + + font "#{printer_settings.font}" + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + end + + header(printer_settings.name,type) + + call_move_table(to,from,date,type,moved_by) + + move_down 5 + stroke_horizontal_rule + move_down 5 + + add_lining_item(order_items, printer_settings.precision) + + move_down 5 + stroke_horizontal_rule + move_down 5 + + end + + def header (name,type) + text "Move #{type}", :left_margin => -10, :size => self.header_font_size.to_i + 3,:align => :center + # move_down self.item_height + move_down 5 + stroke_horizontal_rule + move_down 5 + end + + def call_move_table (to,from,date,type,moved_by) + move_down 3 + text "Date Time : #{date.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :left_margin => -10, :size => self.header_font_size + text "Change [#{from}] To [#{to}]", :left_margin => -10, :size => self.header_font_size + text "Moved By : #{moved_by}", :left_margin => -10, :size => self.header_font_size + end + + def add_lining_item(order_items, precision) + y_position = cursor + + bounding_box([0,y_position], :width => self.item_width) do + text "Item", :size => self.item_font_size,:align => :left + end + + bounding_box([self.item_width,y_position], :width => self.qty_width) do + text "Qty", :size => self.item_font_size,:align => :left + end + + stroke_horizontal_rule + move_down 5 + + add_item(order_items, precision) + end + + # Add order items under order info + def add_item(order_items, precision) + y_position = cursor + + move_down 5 + + order_items.each do|odi| + # check for item not to show + # if odi.price != 0 + y_position = cursor + + # bounding_box([0,y_position], :width => self.item_width + 60, :height => self.item_height) do + # text "#{odi.item_code} - #{odi.item_name}", :size => self.item_font_size,:align => :left + # end + bounding_box([0,y_position], :width => self.item_width) do + text "#{odi.item_code} - #{odi.item_name}", :size => self.item_font_size,:align => :left + end + + bounding_box([self.item_width,y_position], :width => self.qty_width) do + text "#{number_with_precision(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left + end + + bounding_box([0,y_position], :width => self.item_width) do + text "#{odi.item_code} - #{odi.item_name}", :size => self.item_font_size,:align => :left + end + + if !(odi.alt_name).empty? + move_down 4 + # font("public/fonts/NotoSansCJKtc-Regular.ttf") do + text "(#{odi.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true + # end + end + + end + end + +end diff --git a/app/pdf/order_item_star_pdf.rb b/app/pdf/order_item_star_pdf.rb new file mode 100644 index 00000000..2aaf01ac --- /dev/null +++ b/app/pdf/order_item_star_pdf.rb @@ -0,0 +1,162 @@ +class OrderItemStarPdf < 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 + + def initialize(print_settings,order_item, print_status, options, alt_name, before_updated_qty) + self.page_width = print_settings.page_width + self.page_height = print_settings.page_height + self.header_font_size = print_settings.header_font_size.to_i + self.item_font_size = print_settings.item_font_size.to_i + self.margin = 0 + self.price_width = 40 # No Need for item + self.qty_width = 38 + self.total_width = 40 # No Need for item + self.item_width = self.page_width - (self.qty_width - self.margin) + self.item_height = 15 + self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) + self.label_width=90 + + super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) + # super(:margin => [10, 5, 30, 5], :page_size => [200,400]) + + # db font setup + if print_settings.font != "" + font_families.update("#{print_settings.font}" => { + :normal => "public/fonts/#{print_settings.font}.ttf", + :italic => "public/fonts/#{print_settings.font}.ttf", + :bold => "public/fonts/#{print_settings.font}.ttf", + :bold_italic => "public/fonts/#{print_settings.font}.ttf" + }) + + font "#{print_settings.font}" + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + end + # font "public/fonts/Zawgyi-One.ttf" + # font "public/fonts/padauk.ttf" + #font "public/fonts/Chinese.ttf" + if !order_item.dining.nil? + text "#{ order_item.type + '-' + order_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + else + text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + end + + stroke_horizontal_rule + move_down 3 + + #order_info + order_info(order_item.order_id, order_item.order_by,order_item.order_at) + + # order items + order_items(order_item, options, alt_name, print_settings.precision, before_updated_qty) + end + + # Write Order Information to PDF + def order_info(order_no, order_by, order_at) + #booking ID + booking_id = get_booking_id(order_no) + + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left + end + + move_down 2 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "OrderNo: #{order_no}", :size => self.item_font_size,:align => :left + end + + move_down 2 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + end + + move_down 2 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left + end + + stroke_horizontal_rule + + move_down 10 + end + + # Write Order items to PDF + def order_items(order_item, options, alt_name, precision, before_updated_qty) + y_position = cursor + + #Add Order Item + add_order_items(order_item, options, alt_name, precision) + + dash(1, :space => 1, :phase => 1) + stroke_horizontal_line 0, (self.page_width - self.margin) + add_updated_qty_text(before_updated_qty, order_item.qty, precision) + move_down 5 + end + + # Add order items under order info + def add_order_items(order_item, options, alt_name, precision) + y_position = cursor + + move_down 5 + + bounding_box([0,y_position], :width => self.item_width) do + text "#{order_item.item_code} - #{order_item.item_name}", :size => self.item_font_size,:align => :left + end + + bounding_box([self.item_width,y_position], :width => self.qty_width) do + text "[#{number_with_precision(order_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + end + + bounding_box([0,y_position], :width => self.item_width) do + text "#{order_item.item_code} - #{order_item.item_name}", :size => self.item_font_size,:align => :left + + end + + if alt_name + if order_item.alt_name + move_down 4 + # font("public/fonts/NotoSansCJKtc-Regular.ttf") do + text "(#{order_item.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true + # end + end + end + + if !options.empty? + move_down 5 + + # add option + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "#{options}", :size => self.item_font_size,:align => :left + end + end + + move_down 5 + + end + + #add updated qty text + def add_updated_qty_text(before_updated_qty, updated_qty, precision) + if before_updated_qty.to_i > 0 && !before_updated_qty.nil? + move_down 5 + + # add option + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "* Change quantity [#{number_with_precision(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_with_precision(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + end + end + end + + def get_booking_id(order_no) + booking = Order.joins(" JOIN booking_orders bo ON bo.order_id = orders.order_id") + .joins(" JOIN bookings b ON b.booking_id=bo.booking_id") + .where("orders.order_id='#{order_no}'") + .first() + + return booking.booking_id + end +end diff --git a/app/pdf/receipt_bill_star_pdf.rb b/app/pdf/receipt_bill_star_pdf.rb new file mode 100644 index 00000000..8f155811 --- /dev/null +++ b/app/pdf/receipt_bill_star_pdf.rb @@ -0,0 +1,756 @@ +class ReceiptBillStarPdf < 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, :description_width, :price_num_width, :line_move + + def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data,other_charges_amount,latest_order_no,card_balance_amount) + self.page_width = printer_settings.page_width + self.page_height = printer_settings.page_height + self.header_font_size = printer_settings.header_font_size.to_i + self.item_font_size = printer_settings.item_font_size.to_i + self.margin = 0 + self.price_width = 50 + self.qty_width = 23 + self.total_width = 50 + self.item_width = self.page_width - ((self.qty_width + self.price_width + self.total_width)) + self.item_height = 15 + self.item_description_width = (self.page_width-20) / 2 + self.label_width = 90 + + self.description_width = 140 + self.price_num_width = 40 + self.line_move = 2 + # @item_width = self.page_width.to_i / 2 + # @qty_width = @item_width.to_i / 3 + # @double = @qty_width * 1.3 + # @half_qty = @qty_width / 2 + #setting page margin and width + super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) + + #precision checked + if printer_settings.precision.to_i > 2 + printer_settings.precision = 2 + end + + # db font setup + if printer_settings.font != "" + font_families.update("#{printer_settings.font}" => { + :normal => "public/fonts/#{printer_settings.font}.ttf", + :italic => "public/fonts/#{printer_settings.font}.ttf", + :bold => "public/fonts/#{printer_settings.font}.ttf", + :bold_italic => "public/fonts/#{printer_settings.font}.ttf" + }) + + font "#{printer_settings.font}" + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + end + # font "public/fonts/Zawgyi-One.ttf" + # font "public/fonts/padauk.ttf" + + if printer_settings.delimiter + delimiter = "," + else + delimiter = "" + end + + header(shop_details) + + stroke_horizontal_rule + + cashier_info(sale_data, customer_name, latest_order_no) + line_items(sale_items,printer_settings.precision,delimiter) + all_total(sale_data,printer_settings.precision,delimiter) + + + if member_info != nil + member_info(member_info,customer_name,rebate_amount,sale_data,printer_settings.precision,delimiter,current_balance) + end + + customer(customer_name) + + #start card sale trans data + if card_data != nil + card_sale_data(card_data) + end + #end card sale trans data + #start card blanace amount + if !card_balance_amount.nil? + card_balance_data(card_balance_amount) + end + #end card blanace amount + + if discount_price_by_accounts.length > 0 && shop_details.show_account_info + discount_account(discount_price_by_accounts,printer_settings.precision,delimiter) + end + + if shop_details.show_account_info + items_account(item_price_by_accounts,printer_settings.precision,delimiter) + if other_charges_amount + show_other_charges_amount(other_charges_amount,printer_settings.precision,delimiter) + end + end + + #start for individual payment + if !sale_data.equal_persons.nil? + individual_payment(sale_data,sale_data.equal_persons, printer_settings.precision, delimiter) + end + #end for individual payment + + sign(sale_data) + + if shop_details.note && !shop_details.note.nil? + shop_note(shop_details) + end + + footer(printed_status) + end + + def header (shop_details) + text "#{shop_details.name}", :left_margin => -10, :size => self.header_font_size,:align => :center + move_down line_move + text "#{shop_details.address}", :size => self.item_font_size,:align => :center + # move_down self.item_height + move_down line_move + text "#{shop_details.phone_no}", :size => self.item_font_size,:align => :center + move_down line_move + + stroke_horizontal_rule + end + + def cashier_info(sale_data, customer_name, latest_order_no) + if latest_order_no.nil? + move_down line_move + text "Booking : #{ sale_data.bookings[0].booking_id }", :size => self.header_font_size+2,:align => :left + move_down line_move + end + move_down line_move + if !latest_order_no.nil? + move_down line_move + text "OrderNo : #{ latest_order_no }", :size => self.header_font_size,:align => :left + end + move_down line_move + + # move_down 2 + y_position = cursor + bounding_box([0,y_position], :width =>self.description_width + self.price_num_width, :height => self.item_height) do + text "Receipt No: #{sale_data.receipt_no}", :size => self.item_font_size,:align => :left + end + + if sale_data.bookings[0].dining_facility_id.to_i > 0 + bounding_box([self.description_width - 2,y_position], :width => self.price_num_width, :height => self.item_height) do + text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right + end + end + + move_down line_move + y_position = cursor + bounding_box([0, y_position], :width =>self.label_width, :height => self.item_height) do + text "W: #{sale_data.requested_by}" , :size => self.item_font_size, :align => :left + end + bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do + text "C: #{sale_data.cashier_name}", :size => self.item_font_size,:align => :right + end + move_down line_move + + y_position = cursor + if sale_data.bookings[0].dining_facility_id.to_i > 0 + time = sale_data.receipt_date.strftime('%d-%m-%Y') +"("+ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') +"-"+ sale_data.bookings[0].checkout_at.utc.getlocal.strftime('%I:%M %p')+")" + else + time = sale_data.receipt_date.strftime('%d-%m-%Y %H:%M %p') + end + + bounding_box([0,y_position], :width =>self.page_width - 10, :height => self.item_height) do + text "Date : #{ time }",:size => self.item_font_size,:align => :left + end + + # bounding_box([self.item_description_width,y_position], :width =>self.label_width+5) do + # text "(#{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } + # - #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') })" , + # :size => self.item_font_size,:align => :right + # end + move_down line_move + stroke_horizontal_rule + end + + def line_items(sale_items,precision,delimiter) + if precision.to_i > 0 + item_label_qty_front_width = (self.item_width+self.price_width) + 2 + item_label_qty_end_width = self.qty_width + 1 + item_label_total_front_width = (self.item_width+self.price_width) + 3 + item_label_total_end_width = self.total_width + 3 + else + # self.item_width = self.item_width.to_i + 3 + item_label_qty_front_width = (self.item_width+self.price_width) + 3 + item_label_qty_end_width = self.qty_width + 2 + item_label_total_front_width = (self.item_width+self.price_width) + 2 + item_label_total_end_width = self.total_width + 1 + end + move_down line_move + y_position = cursor + move_down line_move + 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 line_move + stroke_horizontal_rule + add_line_item_row(sale_items,precision,delimiter) + end + + def add_line_item_row(sale_items,precision,delimiter) + + if precision.to_i > 0 + item_name_width = (self.item_width+self.price_width) + item_qty_front_width = (self.item_width+self.price_width) + 2 + item_qty_end_width = self.qty_width + 1 + item_total_front_width = item_name_width + 3 + item_total_end_width = self.total_width + 3 + else + item_name_width = (self.item_width+self.price_width) + item_qty_front_width = item_name_width + 3 + item_qty_end_width = self.qty_width + 2 + item_total_front_width = item_name_width + 2 + item_total_end_width = self.total_width + 1 + end + + y_position = cursor + move_down line_move + sub_total = 0.0 + total_qty = 0.0 + show_price = Lookup.find_by_lookup_type("show_price") + sale_items.each do |item| + # check for item not to show + + if item.status != 'Discount' && item.qty > 0 + if !show_price.nil? && show_price.value.to_i > 0 && item.price == 0 + total_qty += item.qty + else + if item.price != 0 + total_qty += item.qty + end + end + end + + product_name = item.product_name + + # if item.status = 'promotion' && (item.remark =='promotion nett price' || item.remark == 'promotion discount') + # sub_total += -item.price #(item.qty*item.unit_price) - comment for room charges + # qty = -item.qty + # total_price = -item.price #item.qty*item.unit_price - comment for room charges + # price = -item.unit_price + # else + sub_total += item.price #(item.qty*item.unit_price) - comment for room charges + qty = item.qty + total_price = item.price #item.qty*item.unit_price - comment for room charges + price = item.unit_price + + # end + + + if !show_price.nil? && show_price.value.to_i>0 + item_row(item,precision,delimiter,product_name,price,qty ,total_price) + else + if item.price != 0 + item_row(item,precision,delimiter,product_name,price,qty ,total_price) + end + end + + end + + stroke_horizontal_rule + + move_down line_move + y_position = cursor + bounding_box([0,y_position], :width =>self.item_width + self.price_width, :height => self.item_height) do + text "Sub Total", :size => self.item_font_size,:align => :left + end + text_box "#{number_with_precision(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_with_precision(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + end + + def item_row(item,precision,delimiter,product_name,price,qty ,total_price) + if precision.to_i > 0 + item_name_width = (self.item_width+self.price_width) + item_qty_front_width = (self.item_width+self.price_width) + 2 + item_qty_end_width = self.qty_width + 1 + item_total_front_width = item_name_width + 3 + item_total_end_width = self.total_width + 3 + else + item_name_width = (self.item_width+self.price_width) + item_qty_front_width = item_name_width + 3 + item_qty_end_width = self.qty_width + 2 + item_total_front_width = item_name_width + 2 + item_total_end_width = self.total_width + 1 + end + y_position = cursor + + pad_top(15) { + bounding_box([0,y_position], :width =>self.item_width) do + text "#{product_name}", :size => self.item_font_size,:align => :left + end + # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size + text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + + if show_alt_name + if !(item.product_alt_name).empty? + move_down 2 + # font("public/fonts/NotoSansCJKtc-Regular.ttf") do + text "(#{item.product_alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true + # end + end + end + move_down line_move + } + + + end + + def all_total(sale_data,precision,delimiter) + move_down line_move + item_name_width = self.item_width + y_position = cursor + if sale_data.discount_type == 'member_discount' + dis_type = "Member Discount:" + else + dis_type = "Overall Discount:" + end + + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "#{ dis_type }", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "( #{number_with_precision(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right + end + + if sale_data.sale_taxes.length > 0 + incl_tax = "" + if sale_data.tax_type == "inclusive" + incl_tax = "Incl." + end + + sale_data.sale_taxes.each do |st| + move_down line_move + y_position = cursor + + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end + end + else + + end + + # move_down 5 + # y_position = cursor + + # bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + # text "Total Tax", :size => self.item_font_size,:align => :left + # end + # bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + # text "( " +"#{sale_data.total_tax}" +" )" , :size => self.item_font_size,:align => :right + # end + + if sale_data.rounding_adjustment != 0.0 + move_down line_move + y_position = cursor + + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Rounding Adjustment", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{sale_data.rounding_adjustment}", :size => self.item_font_size,:align => :right + end + end + + move_down line_move + y_position = cursor + move_down line_move + bounding_box([0,y_position], :width =>self.item_description_width) do + text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_with_precision(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right + end + move_down line_move + + sale_payment(sale_data,precision,delimiter) + end + + def sale_payment(sale_data,precision,delimiter) + stroke_horizontal_rule + #move_down line_move + sql = "SELECT SUM(payment_amount) + FROM sale_payments where payment_method='creditnote' + and sale_id='#{sale_data.sale_id}'" + sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount) + FROM sale_payments where payment_method='creditnote' + and sale_id='#{sale_data.sale_id}'" + + sale_payments = SalePayment.select("SUM(sale_payments.payment_amount) as payment_amount,sale_payments.payment_method") + .where("(CASE WHEN ((#{sql}) - (#{sql1}) + ELSE SUM(payment_amount) END + FROM sale_payments + JOIN sales s ON s.sale_id=sale_payments.sale_id + JOIN sale_audits sa + ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payment_id + where sa.sale_id='#{sale_data.sale_id}')) = 0 + THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id) + .group("payment_method") + + sale_payments.each do |payment| + y_position = cursor + if payment.payment_method == "paypar" + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Redeem Payment", :size => self.item_font_size,:align => :left + end + else + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left + end + end + + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_with_precision(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end + move_down line_move + end + if sale_data.amount_received > 0 + y_position = cursor + move_down line_move + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Change Amount", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_with_precision(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end + # move_down line_move + end + end + + # show member information + def member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter,current_balance) + if rebate_amount != nil + if rebate_amount["status"] == true + stroke_horizontal_rule + total = 0 + balance = 0 + rebate_balance =0 + redeem = 0 + redeem_count = 0 + rebate_amount["data"].each do |res| + total = total + res["balance"] + #total redeem amount + if res["receipt_no"]== sale_data.receipt_no && res["status"]== "Redeem" + redeem = redeem + res["withdraw"] + balance = balance + res["balance"] + end + #end Total redem + #total Rebate Earn + if res["receipt_no"]== sale_data.receipt_no && res["account_status"]== "RebateAccount" && res["status"]== "Rebate" + + rebate_balance = rebate_balance + res["deposit"] + + move_down line_move + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Rebate Earn", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end + + end + # Total Rebate Amount if birthday + if res["receipt_no"]== sale_data.receipt_no && res["account_status"]== "RebatebonusAccount" && res["status"]== "Rebate" + rebate_balance = rebate_balance + res["deposit"] + move_down line_move + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Rebate Earn Bonus", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end + end + #end Total rebate if birthday + end + + move_down line_move + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Redeem Amount", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_with_precision(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + end + + if current_balance != nil + move_down line_move + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Old Balance", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_with_precision(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + end + end + + end + end + + if member_info["status"] == true && member_info["data"].present? + total_balance = 0 + member_info["data"].each do |res| + + if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount" + total_balance = total_balance + res["balance"] + + end + end + move_down line_move + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Total Balance", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_with_precision(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end + end + + end + + def customer(customer_name) + # move_down line_move + y_position = cursor + #move_down line_move + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Customer Name", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{ customer_name }" , :size => self.item_font_size,:align => :right + end + move_down line_move + stroke_horizontal_rule + end + + + def discount_account(discount_price_by_accounts,precision,delimiter) + + stroke_horizontal_rule + move_down line_move + y_position = cursor + discount_price_by_accounts.each do |ipa| + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "#{ 'Total ' + ipa[:name] + ' Discounts' }", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "(" + "#{ number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right + end + move_down line_move + end + end + + def items_account(item_price_by_accounts,precision,delimiter) + stroke_horizontal_rule + move_down line_move + y_position = cursor + item_price_by_accounts.each do |ipa| + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width) do + text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width =>self.item_description_width) do + text "#{number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end + move_down line_move + end + end + + def show_other_charges_amount(other_amount,precision,delimiter) + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width) do + text "Other Charges", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width =>self.item_description_width) do + text "#{number_with_precision(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end + move_down line_move + end + + #individual payment per person + def individual_payment(sale_data, survey, precision, delimiter) + # per_person = sale_data.grand_total.to_f / survey.total_customer.to_i + per_person = sale_data.grand_total.to_f / survey.to_i + stroke_horizontal_rule + move_down line_move + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width+50) do + text "Split Bill for #{sale_data.equal_persons} persons", :size => self.item_font_size+1,:align => :left + end + + bounding_box([0,y_position], :width =>self.label_width) do + move_down 15 + text "Amount Due (per person)", :size => self.item_font_size,:align => :left + end + + bounding_box([self.label_width,y_position], :width =>self.item_description_width) do + move_down 15 + text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + end + end + + def sign(sale_data) + sql = "SELECT SUM(payment_amount) + FROM sale_payments where payment_method='creditnote' + and sale_id='#{sale_data.sale_id}'" + sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount) + FROM sale_payments where payment_method='creditnote' + and sale_id='#{sale_data.sale_id}'" + + SalePayment.where("(CASE WHEN ((#{sql}) - (#{sql1}) + ELSE SUM(payment_amount) END + FROM sale_payments + JOIN sales s ON s.sale_id=sale_payments.sale_id + JOIN sale_audits sa + ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payment_id + where sa.sale_id='#{sale_data.sale_id}')) = 0 + THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id).each do |payment| + if payment.payment_method == "creditnote" + + y_position = cursor + stroke_horizontal_rule + + bounding_box([self.label_width,y_position], :width =>self.item_description_width) do + move_down 70 + stroke_horizontal_rule + end + + bounding_box([self.label_width,y_position], :width =>self.item_description_width) do + move_down 73 + text "Approved By" , :size => self.item_font_size,:align => :center + end + break; + end + end + if sale_data.payment_status == "foc" || sale_data.payment_status == "waste" || sale_data.payment_status == "spoile" + + y_position = cursor + stroke_horizontal_rule + + bounding_box([self.label_width,y_position], :width =>self.item_description_width) do + move_down 70 + stroke_horizontal_rule + end + + if sale_data.payment_status == "foc" + bounding_box([self.label_width,y_position], :width =>self.item_description_width) do + move_down 73 + text "Acknowledged By" , :size => self.item_font_size,:align => :center + end + elsif sale_data.payment_status == "waste" || sale_data.payment_status == "spoile" + bounding_box([self.label_width,y_position], :width =>self.item_description_width) do + move_down 73 + text "Approved By" , :size => self.item_font_size,:align => :center + end + end + end + + end + + def shop_note(shop) + move_down line_move + stroke_horizontal_rule + move_down line_move + + move_down line_move + y_position = cursor + + text "#{shop.note}", :size => self.item_font_size, :align => :left + + move_down line_move + end + + def footer(printed_status) + move_down line_move + stroke_horizontal_rule + move_down line_move + + move_down line_move + y_position = cursor + bounding_box([0, y_position], :width =>self.label_width) do + text "#{printed_status}",:style => :bold, :size => header_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.item_description_width+20, :height => self.item_height) do + text "Thank You! See you Again", :left_margin => -5, :size => self.item_font_size,:align => :left + end + + move_down line_move + end + + #start card sale trans data + def card_sale_data(card_data) + if card_data != nil && !card_data.empty? + move_down line_move + stroke_horizontal_rule + move_down line_move + + y_position = cursor + card_data.each do |data| + if data['app'] == 'CUP' + data['app'] = 'UNIONPAY' + elsif data['app'] == 'MASTERCARD' + data['app'] = 'MASTER' + end + text "DATE/TIME: #{data['res_date']} #{data['res_time']} ", :size => @item_font_size, :align => :left + text "BATCH NUM: #{data['batch_no']} TRACE#: #{data['trace']}",:size => @item_font_size, :align => :left + text "RREF NUM: #{data['ref_no']} APPR CODE: #{data['app_code']} ",:size => @item_font_size, :align => :left + text "TID: #{data['tid']} ",:size => @item_font_size, :align => :left + text "#{data['app']} #{data['pan']} ",:size => @item_font_size, :align => :left + end + end + end + + #start card balance data + def card_balance_data(card_balance_amount) + if card_balance_amount > 0 + move_down line_move + stroke_horizontal_rule + move_down line_move + + y_position = cursor + bounding_box([0, y_position], :width =>self.label_width) do + text "Card Balance: ",:style => :bold, :size => header_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{card_balance_amount}" , :size => self.item_font_size,:align => :right + end + end + end + + #check ReceiptBillAltName included + def show_alt_name + bill_alt_name = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf + status = false + if !bill_alt_name.empty? + bill_alt_name.each do |alt_name| + if alt_name[0] == 'ReceiptBillAltName' + if alt_name[1] == '1' + status = true + else + status = false + end + end + end + end + return status + end +end \ No newline at end of file diff --git a/dump.rdb b/dump.rdb index d1adde0cb6060d38f9ffece6a9b4342bb3a2d338..f639025a5a56f3c585e8307e72a4d68f02ac4960 100644 GIT binary patch delta 200 zcmZ3*wu)_np^)2+=P|!HN{drdbaPX44>36LO?1{}G@Sg0Np)he_~e(2){_r03A0%0 z8W>K#2@;c?ypB<0@+3xy$upV6IsSa(+h5qv$S`>Vqo_1ck*Ths>A@2WOl*avsimpK zjO;0?X^EvdC6gVPRDcFa0?iZ!nRS4HfxEaQvBWAZF*7GMw;{ae1TB~Bmz{+HgN+B wm|4RpqshcpSejazTFl6vlA4xSnp1+^CIh31|5YazD|7yrJh}4Pv!rT80In-h(*OVf