add req and fix for shift

This commit is contained in:
Yan
2017-07-07 17:19:14 +06:30
parent 1b0bcbffea
commit 3fe0f708bd
9 changed files with 104 additions and 25 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -191,7 +191,7 @@
<button id="remove-all" class="btn btn-warning btn-block action-btn">Remove All</button>
<button id="pay-discount" class="btn btn-danger btn-block action-btn">Enter</button>
<hr />
<button id="member-discount" class="btn green btn-block action-btn">Member Discount</button>
<button id="member-discount" class="btn btn-success btn-block action-btn">Member Discount</button>
</div>
</div>
</div>

View File

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