diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 2cdd44b5..80b7eb20 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -41,10 +41,10 @@ class Origami::PaymentsController < BaseOrigamiController sale_payment = SalePayment.new sale_payment.process_payment(saleObj, @user, cash, "cash") - new_total = Sale.get_rounding_adjustment(saleObj.grand_total) - rounding_adj = saleObj.grand_total - new_total + # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) + # rounding_adj = saleObj.grand_total - new_total - saleObj.update_attributes(grand_total: new_total,rounding_adjustment:rounding_adj) + # saleObj.update_attributes(grand_total: new_total,rounding_adjustment:rounding_adj) rebate_amount = nil @@ -144,4 +144,14 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details) end + + def rounding_adj + + saleObj = Sale.find(params[:sale_id]) + new_total = Sale.get_rounding_adjustment(saleObj.grand_total) + rounding_adj = new_total-saleObj.grand_total + + saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + + end end diff --git a/app/models/ability.rb b/app/models/ability.rb index 9a7b5f6f..3e5fc8b6 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -52,6 +52,7 @@ class Ability can :show, :payment can :create, :payment can :reprint, :payment + can :rounding_adj, :payment can :move_dining, :movetable can :moving, :movetable @@ -88,6 +89,7 @@ class Ability can :show, :payment can :create, :payment can :reprint, :payment + can :rounding_adj, :payment can :move_dining, :movetable can :moving, :movetable diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index f8eb46d6..373e05ae 100644 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -80,6 +80,16 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end until count == 0 end + #Bill Receipt Print + def print_close_cashier(printer_settings,shift_sale,shop_details) + #Use CUPS service + #Generate PDF + #Print + pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details) + pdf.render_file "tmp/print_close_cashier.pdf" + self.print("tmp/print_close_cashier.pdf") + end + #Queue No Print def print_queue_no(printer_settings,queue) #Use CUPS service diff --git a/app/models/sale.rb b/app/models/sale.rb index 25a2d714..60b471dd 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -92,7 +92,6 @@ class Sale < ApplicationRecord link_order_sale(order.id) end - self.save! #compute sales summary @@ -379,6 +378,7 @@ class Sale < ApplicationRecord to_date = sale_date.end_of_day.utc - diff total_sale = Sale.select("IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as grand_total, + IFNULL(SUM(case when (sale_status='completed') then old_grand_total else 0 end),0) as old_grand_total, IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0) as total_discount, IFNULL(SUM(case when (sale_status='void') then grand_total else 0 end),0) as void_amount, IFNULL(SUM(case when (sale_status='completed') then rounding_adjustment else 0 end),0) as rounding_adj") @@ -386,6 +386,7 @@ class Sale < ApplicationRecord total_sale.each do |sale| grand_total = sale.grand_total + old_grand_total = sale.old_grand_total total_discount = sale.total_discount void_amount = sale.void_amount total = {:sale_date => pay.sale_date, @@ -399,6 +400,7 @@ class Sale < ApplicationRecord :foc_amount => pay.foc_amount, :total_discount => total_discount, :grand_total => grand_total, + :old_grand_total => old_grand_total, :void_amount => void_amount, :rounding_adj => sale.rounding_adj} daily_total.push(total) diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb new file mode 100644 index 00000000..3223c4b3 --- /dev/null +++ b/app/pdf/close_cashier_pdf.rb @@ -0,0 +1,109 @@ +class CloseCashierPdf < Prawn::Document + 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, shift_sale,shop_details) + self.page_width = 210 + self.page_height = 7000 + self.margin = 5 + self.price_width = 40 + self.qty_width = 20 + self.total_width = 40 + self.item_width = self.page_width - ((self.price_width + self.qty_width + self.total_width)) + self.item_height = 15 + self.item_description_width = (self.page_width-20) / 2 + self.label_width = 100 + # @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 => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) + + # font "public/fonts/#{font_name}".to_s + ".ttf".to_s + # font "public/fonts/Zawgyi-One.ttf" + # font "public/fonts/padauk.ttf" + self.header_font_size = 10 + self.item_font_size = 8 + + + + header( shop_details) + + stroke_horizontal_rule + + cashier_info(shift_sale) + + footer + + + end + + def header (shop_details) + move_down 7 + text "#{shop_details.name}", :left_margin => -10, :size => self.header_font_size,:align => :center + move_down 5 + text "#{shop_details.address}", :size => self.item_font_size,:align => :center + # move_down self.item_height + move_down 5 + text "#{shop_details.phone_no}", :size => self.item_font_size,:align => :center + move_down 5 + + stroke_horizontal_rule + end + + def cashier_info(shift_sale) + move_down 7 + # move_down 2 + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Cashier: #{shift_sale.receipt_no}", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ shift_sale.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right + end + move_down 5 + + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Cashier Station Sta: #{shift_sale.receipt_no}", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ shift_sale.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right + end + + move_down 5 + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Opening Date", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ shift_sale.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right + end + move_down 5 + + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Closing Date: #{shift_sale.receipt_no}", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ shift_sale.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right + end + + + move_down 5 + + end + + + + def footer + move_down 5 + stroke_horizontal_rule + move_down 5 + + text "Thank You! See you Again", :left_margin => -10, :size => self.header_font_size,:align => :center + + move_down 5 + end + +end + diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index f89560f3..a8670e12 100644 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -447,7 +447,16 @@ $("#first_bill").on('click', function(){ $('#pay').on('click',function() { var sale_id = $('#sale_id').val(); - window.location.href = '/origami/sale/'+ sale_id + "/payment"; + var url = '/origami/sale/'+ sale_id + "/rounding_adj" ; + + $.ajax({ + type: "POST", + url: '/origami/sale/'+ sale_id + "/rounding_adj", + success:function(result){ + window.location.href = '/origami/sale/'+ sale_id + "/payment"; + } + }); + }); // Bill Request diff --git a/app/views/origami/orders/show.html.erb b/app/views/origami/orders/show.html.erb index 3a34c1df..e0448009 100644 --- a/app/views/origami/orders/show.html.erb +++ b/app/views/origami/orders/show.html.erb @@ -215,7 +215,16 @@ $(document).ready(function(){ }); $('#pay').on('click',function() { var sale_id = $('#sale_id').val(); - window.location.href = '/origami/sale/'+ sale_id + "/payment"; + var url = '/origami/sale/'+ sale_id + "/rounding_adj" ; + alert(url) + $.ajax({ + type: "POST", + url: '/origami/sale/'+ sale_id + "/rounding_adj", + success:function(result){ + window.location.href = '/origami/sale/'+ sale_id + "/payment"; + } + }); + }); $('#back').on('click',function(){ window.location.href = '/origami/'; diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 4004e9cf..a9a542b6 100644 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -70,14 +70,20 @@ (Discount) (<%=@sale_data.total_discount rescue 0%>) + Tax <%=@sale_data.total_tax rescue 0%> + + Rounding Adj: + <%=@sale_data.rounding_adjustment rescue 0%> + + Grand Total <%=@sale_data.grand_total rescue 0%> <%if @balance > 0%> - + <%= @accountable_type %> <%=@balance%> diff --git a/app/views/origami/room_invoices/index.html.erb b/app/views/origami/room_invoices/index.html.erb index 011aff11..71b9bee7 100644 --- a/app/views/origami/room_invoices/index.html.erb +++ b/app/views/origami/room_invoices/index.html.erb @@ -46,6 +46,10 @@ Tax: <%= @sale.total_tax rescue 0%> + + + Rounding Adj: + <%= @sale.rounding_adjustment rescue 0%> Grand Total: diff --git a/app/views/origami/room_invoices/show.html.erb b/app/views/origami/room_invoices/show.html.erb index 7ea799ae..4b507526 100644 --- a/app/views/origami/room_invoices/show.html.erb +++ b/app/views/origami/room_invoices/show.html.erb @@ -112,6 +112,10 @@ Tax: <%= @sale.total_tax rescue 0%> + + + Rounding Adj: + <%= @sale.rounding_adjustment rescue 0%> Grand Total: @@ -139,7 +143,17 @@ $(document).ready(function(){ }); $('#pay').on('click',function() { - window.location.href = '/origami/sale/<%= @sale.id %>/payment'; + var sale_id = '<%= @sale.id %>'; + var url = '/origami/sale/'+ sale_id + "/rounding_adj" ; + alert(url) + $.ajax({ + type: "POST", + url: '/origami/sale/'+ sale_id + "/rounding_adj", + success:function(result){ + window.location.href = '/origami/sale/'+ sale_id + "/payment"; + } + }); + }); $('#back').on('click',function(){ window.location.href = '/origami/table/<%= @room.id %>'; diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 36ae77c5..76c4da71 100644 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -203,6 +203,10 @@ Tax: <%= @obj.total_tax rescue 0%> + + + Rounding Adj: + <%= @obj.rounding_adjustment rescue 0%> Grand Total: @@ -424,12 +428,19 @@ $("#first_bill").on('click', function(){ }); }); - $('#pay').on('click',function() { var sale_id = $('#sale_id').val(); - window.location.href = '/origami/sale/'+ sale_id + "/payment"; + var url = '/origami/sale/'+ sale_id + "/rounding_adj" ; + alert(url) + $.ajax({ + type: "POST", + url: '/origami/sale/'+ sale_id + "/rounding_adj", + success:function(result){ + window.location.href = '/origami/sale/'+ sale_id + "/payment"; + } + }); + }); - // Bill Request $('#request_bills').click(function() { var order_id = $('#save_order_id').attr('data-order'); diff --git a/app/views/origami/sales/show.html.erb b/app/views/origami/sales/show.html.erb index d768240c..86a82053 100644 --- a/app/views/origami/sales/show.html.erb +++ b/app/views/origami/sales/show.html.erb @@ -171,6 +171,10 @@ Tax: <%= @sale.total_tax rescue 0%> + + Rounding Adj: + <%= @sale.rounding_adjustment rescue 0%> + Grand Total: <%= @sale.grand_total rescue 0%> diff --git a/app/views/origami/table_invoices/index.html.erb b/app/views/origami/table_invoices/index.html.erb index d5cbe84d..95a6ee33 100644 --- a/app/views/origami/table_invoices/index.html.erb +++ b/app/views/origami/table_invoices/index.html.erb @@ -46,6 +46,10 @@ Tax: <%= @sale.total_tax rescue 0%> + + + Rounding Adj: + <%= @obj_sale.rounding_adjustment rescue 0%> Grand Total: diff --git a/app/views/origami/table_invoices/show.html.erb b/app/views/origami/table_invoices/show.html.erb index ade1f021..de43e654 100644 --- a/app/views/origami/table_invoices/show.html.erb +++ b/app/views/origami/table_invoices/show.html.erb @@ -112,6 +112,10 @@ Tax: <%= @sale.total_tax rescue 0%> + + + Rounding Adj: + <%= @obj_sale.rounding_adjustment rescue 0%> Grand Total: @@ -139,8 +143,23 @@ $(document).ready(function(){ }) }); +// $('#pay').on('click',function() { +// window.location.href = '/origami/sale/<%= @sale.id %>/payment'; +// }); + $('#pay').on('click',function() { - window.location.href = '/origami/sale/<%= @sale.id %>/payment'; + var sale_id = '<%= @sale.id %>'; + + var url = '<%= @calculate_rouding_adj_path %>'; + + $.ajax({ + type: "GET", + url: url, + success:function(result){ + // location.reload(); + } + }); + window.location.href = '/origami/sale/'+ sale_id + "/payment"; }); $('#back').on('click',function(){ window.location.href = '/origami/table/<%= @table.id %>'; diff --git a/app/views/reports/dailysale/index.html.erb b/app/views/reports/dailysale/index.html.erb index 5c42d6dc..64565fb5 100644 --- a/app/views/reports/dailysale/index.html.erb +++ b/app/views/reports/dailysale/index.html.erb @@ -74,7 +74,7 @@ <% credit += sale[:credit_amount] %> <% foc += sale[:foc_amount] %> <% discount += sale[:total_discount] %> - <% total += sale[:grand_total].to_f + sale[:rounding_adj].to_f %> + <% total += sale[:old_grand_total].to_f + sale[:rounding_adj].to_f %> <% grand_total += sale[:grand_total].to_f %> <% rounding_adj += sale[:rounding_adj].to_f %> @@ -90,7 +90,7 @@ <%= number_with_delimiter(sprintf("%.2f",sale[:credit_amount]), :delimiter => ',') rescue '-'%> <%= number_with_delimiter(sprintf("%.2f",sale[:foc_amount]), :delimiter => ',') rescue '-'%> (<%= number_with_delimiter(sprintf("%.2f",sale[:total_discount]), :delimiter => ',') rescue '-'%>) - <%= number_with_delimiter(sprintf("%.2f",sale[:grand_total].to_f + sale[:rounding_adj].to_f ), :delimiter => ',') rescue '-'%> + <%= number_with_delimiter(sprintf("%.2f",sale[:old_grand_total].to_f + sale[:rounding_adj].to_f ), :delimiter => ',') rescue '-'%> <%= number_with_delimiter(sprintf("%.2f",sale[:rounding_adj].to_f), :delimiter => ',') rescue '-'%> <%= number_with_delimiter(sprintf("%.2f",sale[:grand_total]), :delimiter => ',') rescue '-'%> diff --git a/config/routes.rb b/config/routes.rb index 35669703..a432c761 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -121,6 +121,7 @@ Rails.application.routes.draw do #payment - Outing payments - Cash only [ *Misc expeness tracking] #--------- Payment ------------# + post 'sale/:sale_id/rounding_adj' => 'payments#rounding_adj',:as => "calculate_rouding_adjs" get 'sale/:sale_id/first_bill' => 'payments#first_bill', :defaults => { :format => 'json' } get 'sale/:sale_id/payment' => 'payments#show' diff --git a/db/migrate/20170403160742_create_sales.rb b/db/migrate/20170701101420_create_sales.rb similarity index 95% rename from db/migrate/20170403160742_create_sales.rb rename to db/migrate/20170701101420_create_sales.rb index ae806472..fc261826 100644 --- a/db/migrate/20170403160742_create_sales.rb +++ b/db/migrate/20170701101420_create_sales.rb @@ -20,7 +20,8 @@ class CreateSales < ActiveRecord::Migration[5.1] t.decimal :rounding_adjustment, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.decimal :amount_received, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.decimal :amount_changed, :precision => 10, :scale => 2, :null => false, :default => 0.00 - t.integer :shift_sale_id, :null => false + t.integer :shift_sale_id + t.decimal :old_grand_total t.timestamps end end