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 @@