diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 2e8aba2c..27822a17 100644 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -7,6 +7,7 @@ class Origami::HomeController < BaseOrigamiController @complete = Sale.where("sale_status != 'new'") @orders = Order.all.order('date desc') @shop = Shop.find_by_id(1) + # @shift = ShiftSale.current_open_shift(current_user.id) end @@ -39,7 +40,6 @@ class Origami::HomeController < BaseOrigamiController else sale = Sale.find(booking.sale_id) if sale.sale_status != "completed" && sale.sale_status != 'void' - puts "enter" @sale_array.push(sale) if @status_order == 'order' @status_order = 'sale' diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index afb28714..e134a594 100644 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -39,13 +39,13 @@ class Origami::ShiftsController < BaseOrigamiController # Calculate price_by_accounts @total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount') @total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount') - + @total_member_discount = ShiftSale.get_total_member_discount(@shift) # get printer info - print_settings=PrintSetting.find_by_unique_code(unique_code) + print_settings = PrintSetting.find_by_unique_code(unique_code) printer = Printer::CashierStationPrinter.new(print_settings) - printer.print_close_cashier(print_settings,@shift,shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account) + printer.print_close_cashier(print_settings,@shift,shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount) end @@ -72,6 +72,8 @@ class Origami::ShiftsController < BaseOrigamiController # Calculate price_by_accounts @total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount') @total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount') + @total_member_discount = ShiftSale.get_total_member_discount(@shift) + end end diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index b7bc34ae..91100145 100644 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -22,14 +22,14 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker # end #Bill Receipt Print - def print_close_cashier(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount) + def print_close_cashier(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount) #Use CUPS service #Generate PDF #Print 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") - pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount) + pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount) filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf" pdf.render_file filename self.print(filename) diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index 8a8c1469..168e63ff 100644 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -125,6 +125,12 @@ class ShiftSale < ApplicationRecord query = query.where("sales.shift_sale_id =? and sale_status = 'completed'", shift.id) .group("acc.title").order("acc.id") end + end + + def self.get_total_member_discount(shift) + query = Sale.select("SUM(sales.total_discount) as member_discount") + .where("shift_sale_id =? and sale_status = 'completed' and discount_type = 'member_discount'", shift.id) + end end diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index 1955bf74..51f905d6 100644 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -1,6 +1,6 @@ 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,:text_width - def initialize(printer_settings, shift_sale,shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account) + def initialize(printer_settings, shift_sale,shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount) self.page_width = 210 self.page_height = 7000 self.margin = 5 @@ -32,7 +32,7 @@ class CloseCashierPdf < Prawn::Document stroke_horizontal_rule - shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account) + shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount) @@ -51,7 +51,7 @@ class CloseCashierPdf < Prawn::Document stroke_horizontal_rule end - def shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account) + def shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount) move_down 7 y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do @@ -277,9 +277,32 @@ class CloseCashierPdf < Prawn::Document end #end total amount by Account + if total_member_discount[0].member_discount.present? + @member_discount = total_member_discount[0].member_discount rescue 0.0 + @overall = shift_sale.total_discounts - @member_discount + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Member Discount :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{@member_discount}", :size => self.item_font_size, :align => :right + end + else + @overall = shift_sale.total_discounts + end + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Overall Discount Amount :", :size => self.item_font_size, :align => :right + text "Total Overall Discount :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{@overall}", :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 Discount Amount :", :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_discounts}", :size => self.item_font_size, :align => :right diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index cdb76bd0..e3193a98 100644 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -108,7 +108,7 @@ - <%if current_login_employee.role == "cashier" %> + <%if current_login_employee.role == "cashier" && @shop.quick_sale_summary == true%> <%end%> diff --git a/app/views/origami/shifts/sale_summary.html.erb b/app/views/origami/shifts/sale_summary.html.erb index c552d6b0..94e59924 100644 --- a/app/views/origami/shifts/sale_summary.html.erb +++ b/app/views/origami/shifts/sale_summary.html.erb @@ -55,11 +55,29 @@ <%= amount.total_price.round(2) %> <%end%> + + <% if !@total_member_discount[0].member_discount.nil? + @member_discount = @total_member_discount[0].member_discount rescue 0.0 + @overall = @shift.total_discounts - @member_discount + %> - - Overall Discount Amount - <%= @shift.total_discounts %> + + Total Member Discount + <%= @member_discount %> + <%else @overall = @shift.total_discounts %> + + <%end%> + + + Total Overall Discount + <%= @overall %> + + + + Total Discount + <%= @shift.total_discounts %> + <% @sale_taxes.each do |tax| %> @@ -98,6 +116,7 @@ <%=@shift.credit_sales %> <% @total_amount = 0 + @other_payment.each do |other| %> @@ -107,32 +126,32 @@ MPU Payment - <%=other.mpu_amount.round(2) %> - <% @total_amount = @total_amount+other.mpu_amount %> + <%=other.mpu_amount.round(2) rescue 0.0 %> + <% @total_amount = @total_amount+other.mpu_amount rescue 0.0 %> VISA Payment - <%=other.visa_amount.round(2) %> - <% @total_amount = @total_amount+other.visa_amount %> + <%=other.visa_amount.round(2) rescue 0.0 %> + <% @total_amount = @total_amount+other.visa_amount rescue 0.0 %> JCB Payment - <%=other.master_amount.round(2) %> - <% @total_amount = @total_amount+other.master_amount %> + <%=other.master_amount.round(2) rescue 0.0 %> + <% @total_amount = @total_amount+other.master_amount rescue 0.0 %> Master Payment - <%=other.jcb_amount.round(2) %> - <% @total_amount = @total_amount+other.jcb_amount %> + <%=other.jcb_amount.round(2) rescue 0.0 %> + <% @total_amount = @total_amount+other.jcb_amount rescue 0.0 %> Reedem Payment - <%=other.paypar_amount.round(2) %> - <% @total_amount = @total_amount+other.paypar_amount %> + <%=other.paypar_amount.round(2) rescue 0.0 %> + <% @total_amount = @total_amount+other.paypar_amount rescue 0.0 %> <%end%>