diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 0c41115f..c0245dc3 100644 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -10,9 +10,10 @@ class Origami::VoidController < BaseOrigamiController sale.save # update count for shift sale - shift = ShiftSale.current_open_shift(sale.cashier_id) - shift.total_void = shift.total_void + 1 - shift.save + if(sale.sale_status == "completed") + shift = ShiftSale.current_open_shift(sale.cashier_id) + shift.calculate(sale, "void") + end bookings = sale.bookings bookings.each do |booking| diff --git a/app/models/sale.rb b/app/models/sale.rb index 0e767ea0..c1c81685 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -604,7 +604,7 @@ end def get_commerical_tax tax = 0.0 self.sale_taxes.each do |taxobj| - if taxobj.tax_name == "Commerical Tax" + if taxobj.tax_name == "Commercial Tax" tax += taxobj.tax_payable_amount end end diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index 5716ed7d..c9a05561 100644 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -52,11 +52,34 @@ class ShiftSale < ApplicationRecord self.cash_sales = self.cash_sales.to_f + cash.to_f self.credit_sales = self.credit_sales.to_i + credit.to_f self.other_sales = self.other_sales.to_i + other_sales.to_f - self.nett_sales = saleobj.total_amount.to_f #self.grand_total.to_i - self.commercial_taxes + self.nett_sales = self.nett_sales + saleobj.total_amount.to_f #self.grand_total.to_i - self.commercial_taxes self.commercial_taxes = self.commercial_taxes.to_i + tax.to_f + self.total_rounding = self.total_rounding + saleobj.rounding_adjustment self.total_receipt = self.total_receipt + 1 self.save + end + # Calculate by type and update + def calculate(sale, type) + saleobj = Sale.find_by_sale_id(sale) + cash = saleobj.get_cash_amount + credit = saleobj.get_credit_amount + other_sales = saleobj.get_other_amount + tax = saleobj.get_commerical_tax + if type == "void" + self.total_revenue = self.total_revenue.to_f - saleobj.total_amount.to_f + self.total_discounts = self.total_discounts - saleobj.total_discount + self.total_taxes = self.total_taxes - saleobj.total_tax + self.grand_total = self.grand_total - saleobj.grand_total + self.cash_sales = self.cash_sales.to_f - cash.to_f + self.credit_sales = self.credit_sales.to_i - credit.to_f + self.other_sales = self.other_sales.to_i - other_sales.to_f + self.nett_sales = self.nett_sales - saleobj.total_amount.to_f #self.grand_total.to_i - self.commercial_taxes + self.commercial_taxes = self.commercial_taxes.to_i - tax.to_f + self.total_rounding = self.total_rounding - saleobj.rounding_adjustment + self.total_void = self.total_void + saleobj.grand_total + self.save + end end def get_closing_balance(shift) diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index fc04b6cc..2a4b365a 100644 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -68,6 +68,22 @@ class CloseCashierPdf < Prawn::Document bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do text "#{ shift_sale.cashier_terminal.name}" , :size => self.item_font_size,:align => :left end + + 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.shift_started_at.utc.getlocal.strftime('%d-%m-%Y %I:%M %p') }" , :size => self.item_font_size,:align => :left + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Closing 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.shift_closed_at.utc.getlocal.strftime('%d-%m-%Y %I:%M %p') }" , :size => self.item_font_size,:align => :left + end y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do @@ -88,6 +104,12 @@ class CloseCashierPdf < Prawn::Document move_down 10 + y_position = cursor + bounding_box([0,y_position], :width =>self.page_width - 10, :height => 20) do + text "Shift Sale Summary", :size => self.header_font_size, :align => :center + end + move_down 10 + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Received Amount :", :size => self.item_font_size, :align => :right @@ -168,6 +190,22 @@ class CloseCashierPdf < Prawn::Document text "#{shift_sale.grand_total}", :size => self.item_font_size, :align => :right end + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Receipts :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{shift_sale.total_receipt}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Void:", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "(#{shift_sale.total_void})", :size => self.item_font_size, :align => :right + end + move_down 5 stroke_horizontal_rule move_down 5 diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index 879dd7ae..6e8b26a8 100644 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -191,7 +191,7 @@