FOC fixed
This commit is contained in:
@@ -67,7 +67,6 @@ class CardSaleTran < ApplicationRecord
|
|||||||
shift_closed_at As closing_date,")
|
shift_closed_at As closing_date,")
|
||||||
.order("shift_sales.id DESC")
|
.order("shift_sales.id DESC")
|
||||||
return query = query.where("shift_sales.shift_started_at >= ?" , from)
|
return query = query.where("shift_sales.shift_started_at >= ?" , from)
|
||||||
byebug
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -64,6 +64,5 @@ class CardSettleTran < ApplicationRecord
|
|||||||
shift_closed_at As closing_date,")
|
shift_closed_at As closing_date,")
|
||||||
.order("shift_sales.id DESC")
|
.order("shift_sales.id DESC")
|
||||||
return query = query.where("shift_sales.shift_started_at >= ?" , from)
|
return query = query.where("shift_sales.shift_started_at >= ?" , from)
|
||||||
byebug
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1421,33 +1421,32 @@ def grand_total_after_rounding
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_cash_amount
|
def get_cash_amount
|
||||||
cash = 0.0
|
self.sale_payments.where(payment_method: 'cash', payment_status: 'paid')
|
||||||
self.sale_payments.each do |pay|
|
.pluck(:payment_amount).reduce(:+)
|
||||||
if pay.payment_method == 'cash'
|
|
||||||
cash += pay.payment_amount
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return cash - self.amount_changed
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_credit_amount
|
def get_credit_amount
|
||||||
credit = 0.0
|
self.sale_payments.where(payment_method: 'creditnote')
|
||||||
self.sale_payments.each do |pay|
|
.pluck(:payment_status, :payment_amount)
|
||||||
if pay.payment_method == 'creditnote'
|
.inject(0.0) { |sum, pay|
|
||||||
credit += pay.payment_amount
|
if pay[0] == 'outstanding'
|
||||||
end
|
sum += pay[1]
|
||||||
end
|
else
|
||||||
return credit
|
sum -= pay[1]
|
||||||
|
end
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_other_amount
|
def get_other_amount
|
||||||
other = 0.0
|
self.sale_payments.where.not(payment_method: ['cash', 'creditnote'])
|
||||||
self.sale_payments.each do |pay|
|
.pluck(:payment_status, :payment_amount)
|
||||||
if pay.payment_method != 'cash' && pay.payment_method != 'creditnote'
|
.inject(0.0) { |sum, pay|
|
||||||
other += pay.payment_amount
|
if pay[0] == 'paid'
|
||||||
end
|
sum += pay[1]
|
||||||
end
|
else
|
||||||
return other
|
sum -= pay[1]
|
||||||
|
end
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_commerical_tax
|
def get_commerical_tax
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ class SalePayment < ApplicationRecord
|
|||||||
#get all payment for this invoices
|
#get all payment for this invoices
|
||||||
if payment_for
|
if payment_for
|
||||||
amount_due = SalePayment.get_credit_amount_due_left(self.sale_id).first.payment_amount
|
amount_due = SalePayment.get_credit_amount_due_left(self.sale_id).first.payment_amount
|
||||||
|
elsif payment_method == 'foc'
|
||||||
|
amount_due = invoice.total_amount
|
||||||
else
|
else
|
||||||
amount_due = invoice.sale_payments
|
amount_due = invoice.sale_payments
|
||||||
.map(&:payment_amount).reduce(invoice.grand_total, :-)
|
.map(&:payment_amount).reduce(invoice.grand_total, :-)
|
||||||
@@ -412,6 +414,7 @@ class SalePayment < ApplicationRecord
|
|||||||
def foc_payment
|
def foc_payment
|
||||||
payment_status = false
|
payment_status = false
|
||||||
sale = self.sale
|
sale = self.sale
|
||||||
|
sale.sale_payments.update_all(payment_status: "cancelled")
|
||||||
# add to sale item with foc
|
# add to sale item with foc
|
||||||
sale_items = sale.sale_items
|
sale_items = sale.sale_items
|
||||||
|
|
||||||
@@ -428,7 +431,7 @@ class SalePayment < ApplicationRecord
|
|||||||
self.payment_status = "paid"
|
self.payment_status = "paid"
|
||||||
payment_status = self.save!
|
payment_status = self.save!
|
||||||
# sale_update_payment_status(self.received_amount)
|
# sale_update_payment_status(self.received_amount)
|
||||||
sale_update_payment_status(0)
|
sale_update_payment_status(0, true)
|
||||||
return payment_status
|
return payment_status
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -638,21 +641,28 @@ class SalePayment < ApplicationRecord
|
|||||||
def sale_update_payment_status(paid_amount, check_foc = false)
|
def sale_update_payment_status(paid_amount, check_foc = false)
|
||||||
#update amount_outstanding
|
#update amount_outstanding
|
||||||
sale = self.sale
|
sale = self.sale
|
||||||
total_payment_amount = sale.sale_payments.reload.sum(&:payment_amount)
|
sale_payments = sale.sale_payments.reload
|
||||||
|
|
||||||
|
is_credit = sale_payments.any? { |x| x.payment_method == "creditnote" }
|
||||||
|
is_foc = sale_payments.any? { |x| x.payment_method == "foc" } || check_foc
|
||||||
|
|
||||||
|
if is_foc
|
||||||
|
total_payment_amount = 0.0
|
||||||
|
else
|
||||||
|
total_payment_amount = sale_payments.sum(&:payment_amount)
|
||||||
|
end
|
||||||
|
|
||||||
sale.amount_received = sale.amount_received.to_f + paid_amount.to_f
|
sale.amount_received = sale.amount_received.to_f + paid_amount.to_f
|
||||||
sale.amount_changed = total_payment_amount - sale.grand_total.to_f
|
sale.amount_changed = total_payment_amount - sale.grand_total.to_f
|
||||||
|
|
||||||
is_credit = sale.sale_payments.any? { |x| x.payment_method == "creditnote" }
|
if is_foc
|
||||||
is_foc = sale.sale_payments.any? { |x| x.payment_method == "foc" }
|
sale.payment_status = 'foc'
|
||||||
|
sale.sale_status = 'completed'
|
||||||
if sale.grand_total <= total_payment_amount && sale.sale_status == "new"
|
elsif sale.grand_total <= total_payment_amount && sale.sale_status == "new"
|
||||||
sale.payment_status = "paid"
|
sale.payment_status = "paid"
|
||||||
if is_credit
|
if is_credit
|
||||||
sale.payment_status = "outstanding"
|
sale.payment_status = "outstanding"
|
||||||
end
|
end
|
||||||
if is_foc
|
|
||||||
sale.payment_status = "foc"
|
|
||||||
end
|
|
||||||
|
|
||||||
sale.sale_status = "completed"
|
sale.sale_status = "completed"
|
||||||
|
|
||||||
@@ -679,25 +689,24 @@ class SalePayment < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
sale.save!
|
sale.save!
|
||||||
|
|
||||||
if check_foc
|
if check_foc
|
||||||
table_update_status(sale)
|
table_update_status(sale)
|
||||||
update_shift
|
update_shift
|
||||||
elsif paid_amount.to_f > 0 #|| paid_amount != "0.0"
|
elsif paid_amount.to_f > 0 #|| paid_amount != "0.0"
|
||||||
table_update_status(sale)
|
table_update_status(sale)
|
||||||
update_shift
|
update_shift
|
||||||
elsif paid_amount.to_f == 0 && !is_credit
|
elsif paid_amount.to_f == 0 && !is_credit
|
||||||
table_update_status(sale)
|
table_update_status(sale)
|
||||||
update_shift
|
update_shift
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# update for cashier shift
|
# update for cashier shift
|
||||||
def update_shift
|
def update_shift
|
||||||
|
|
||||||
shift = ShiftSale.current_open_shift(self.action_by.id)
|
shift = ShiftSale.current_open_shift(self.action_by.id)
|
||||||
|
|
||||||
if shift.nil?
|
if shift.nil?
|
||||||
@@ -735,7 +744,6 @@ class SalePayment < ApplicationRecord
|
|||||||
else
|
else
|
||||||
# extra_changed_amount = self.received_amount.to_f + credit_payment_left
|
# extra_changed_amount = self.received_amount.to_f + credit_payment_left
|
||||||
shift.cash_sales = shift.cash_sales.to_f + (self.received_amount.to_f + credit_payment_left)
|
shift.cash_sales = shift.cash_sales.to_f + (self.received_amount.to_f + credit_payment_left)
|
||||||
|
|
||||||
self.sale.amount_received = self.sale.amount_received.to_f - credit_payment_left
|
self.sale.amount_received = self.sale.amount_received.to_f - credit_payment_left
|
||||||
self.sale.amount_changed = self.sale.amount_changed.to_f - credit_payment_left
|
self.sale.amount_changed = self.sale.amount_changed.to_f - credit_payment_left
|
||||||
self.sale.save!
|
self.sale.save!
|
||||||
|
|||||||
Reference in New Issue
Block a user