From 3fe0f708bd2e8a158390ee682926d2c69534ec67 Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 7 Jul 2017 17:19:14 +0630 Subject: [PATCH] add req and fix for shift --- app/controllers/origami/void_controller.rb | 7 ++-- app/models/sale.rb | 2 +- app/models/shift_sale.rb | 25 +++++++++++- app/pdf/close_cashier_pdf.rb | 38 +++++++++++++++++++ app/views/origami/discounts/index.html.erb | 2 +- app/views/origami/sales/show.html.erb | 16 ++++++++ .../20170626191519_create_shift_sales.rb | 3 +- db/seeds.rb | 2 +- lib/tasks/clear_data.rake | 34 ++++++++--------- 9 files changed, 104 insertions(+), 25 deletions(-) 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 @@
- + diff --git a/app/views/origami/sales/show.html.erb b/app/views/origami/sales/show.html.erb index ad8a73aa..9a8dc95d 100644 --- a/app/views/origami/sales/show.html.erb +++ b/app/views/origami/sales/show.html.erb @@ -222,6 +222,22 @@ $('#pay').on('click',function() { $('#back').on('click',function(){ window.location.href = '/origami/'; }) + +$('#void').on('click',function () { + var sure = confirm("Are you sure want to Void"); + if (sure == true) { + var sale_id = $('#sale_id').val(); + var ajax_url = "/origami/sale/" + sale_id + '/void'; + $.ajax({ + type: 'POST', + url: ajax_url, + success: function () { + window.location.href = '/origami/'; + } + }); + } + }); + $('#re-print').click(function() { var sale_id = $('#sale_id').val(); window.location.href = '/origami/'+ sale_id + "/reprint" diff --git a/db/migrate/20170626191519_create_shift_sales.rb b/db/migrate/20170626191519_create_shift_sales.rb index 405e497b..d16449d7 100644 --- a/db/migrate/20170626191519_create_shift_sales.rb +++ b/db/migrate/20170626191519_create_shift_sales.rb @@ -21,8 +21,9 @@ class CreateShiftSales < ActiveRecord::Migration[5.1] t.integer :dining_count, :default => 0 t.integer :takeaway_count, :default => 0 t.integer :member_count, :default => 0 + t.integer :total_rounding, :default => 0 t.integer :total_receipt, :default => 0 - t.integer :total_void, :default => 0 + t.decimal :total_void, :default => 0 t.timestamps end end diff --git a/db/seeds.rb b/db/seeds.rb index 3bff75a0..8fe62bde 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -103,7 +103,7 @@ customer2 = Customer.create({name:"TAKEAWAY", email: "cus2@customer.com", contac # room = Room.create({name:"Table 2", zone: zone2, status:"available", seater: 4 , order_by:1, created_by:"SYSTEM DEFAULT"}) #Tax Profile -tax_profiles = TaxProfile.create({id:1, name: "Commerical Tax", rate:5.0, order_by:1, created_by:"SYSTEM DEFAULT"}) +tax_profiles = TaxProfile.create({id:1, name: "Commercial Tax", rate:5.0, order_by:1, created_by:"SYSTEM DEFAULT"}) #Account for Menu Item Type (eg: Food, Beverage) # food = Account.create({title: "Food", account_type: "0"}) diff --git a/lib/tasks/clear_data.rake b/lib/tasks/clear_data.rake index d0bf6ceb..affe76ff 100644 --- a/lib/tasks/clear_data.rake +++ b/lib/tasks/clear_data.rake @@ -1,19 +1,19 @@ namespace :clear do - # desc "Clear Data" - # task :data => :environment do - # BookingOrder.delete_all - # Booking.delete_all - # OrderItem.delete_all - # AssignedOrderItem.delete_all - # Order.delete_all - # SaleOrder.delete_all - # SaleItem.delete_all - # Sale.delete_all - # SaleAudit.delete_all - # SalePayment.delete_all - # ShiftSale.delete_all - # PaymentJournal.delete_all - # DiningFacility.update_all(status:'available') - # puts "Clear Data Done." - # end + desc "Clear Data" + task :data => :environment do + BookingOrder.delete_all + Booking.delete_all + OrderItem.delete_all + AssignedOrderItem.delete_all + Order.delete_all + SaleOrder.delete_all + SaleItem.delete_all + Sale.delete_all + SaleAudit.delete_all + SalePayment.delete_all + ShiftSale.delete_all + PaymentJournal.delete_all + DiningFacility.update_all(status:'available') + puts "Clear Data Done." + end end