diff --git a/app/controllers/transactions/shift_sales_controller.rb b/app/controllers/transactions/shift_sales_controller.rb index 40f64ff4..78af17a4 100644 --- a/app/controllers/transactions/shift_sales_controller.rb +++ b/app/controllers/transactions/shift_sales_controller.rb @@ -39,15 +39,13 @@ class Transactions::ShiftSalesController < ApplicationController shift_obj = ShiftSale.where('id =?',@shift.id) @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') #other payment details for mpu or visa like card - @other_payment = ShiftSale.get_by_shift_other_payment(@shift) + @other_payment = ShiftSale.get_by_shift_other_payment(@shift).first @payment_methods = PaymentMethodSetting.where(is_active: true).pluck(:payment_method) # 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) - - respond_to do |format| format.html # show.html.erb format.json { render json: @shift } diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index db727b38..b3e5e018 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -633,9 +633,10 @@ class SalePayment < ApplicationRecord def sale_update_payment_status(paid_amount, check_foc = false) #update amount_outstanding - if ['completed'].include? sale.sale_status + if !self.sale || ['completed'].include?(self.sale.sale_status) return end + sale = self.sale sale_payments = sale.sale_payments.reload @@ -681,17 +682,8 @@ class SalePayment < ApplicationRecord end end end - end + sale.save! - sale.save! - - if check_foc - table_update_status(sale) - update_shift - elsif paid_amount.to_f > 0 #|| paid_amount != "0.0" - table_update_status(sale) - update_shift - elsif paid_amount.to_f == 0 && !is_credit table_update_status(sale) update_shift end diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index f625cf27..4ad1e94b 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -153,7 +153,7 @@ class ShiftSale < ApplicationRecord payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) Sale.select("sales.sale_id,sale_payments.payment_method as name") - .select("#{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method}"}.join(', ')}") + .select("#{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method == 'paypar' ? 'redeem' : method}"}.join(', ')}") .select("SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .where("sales.shift_sale_id =? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.id) diff --git a/app/views/transactions/shift_sales/show.html.erb b/app/views/transactions/shift_sales/show.html.erb index 2edb7fc8..a1fd7edc 100755 --- a/app/views/transactions/shift_sales/show.html.erb +++ b/app/views/transactions/shift_sales/show.html.erb @@ -40,7 +40,7 @@
| Cash Payment | -<%=@shift.cash_sales %> | +<%= @shift.cash_sales %> | |
|---|---|---|---|
| Credit Payment | -<%=@shift.credit_sales %> | +<%= @shift.credit_sales %> | |
| Other Payment Detail | @@ -138,29 +136,26 @@|||
| <%= method %> Payment | -<%= other[method.parameterize.to_sym].round(2) rescue '-' %> | - <% @total_other_amount = @total_other_amount + other[method.parameterize.to_sym] rescue 0.0 %> +<%= @other_payment[method.parameterize.to_sym] || 0.0 %> | + <% total_other_amount = total_other_amount + (@other_payment[method.parameterize.to_sym] || 0.0) %>|
| FOC | -<%=other.foc_amount.round(2) rescue 0.0 %> | - <% @total_amount = @total_amount + other.foc_amount rescue 0.0 %> +<%= @other_payment.foc_amount rescue 0.0 %> | |
| Total Other Payment | -<%= @total_other_amount %> | +<%= total_other_amount %> | |
| Total Payment | -<%= @total_amount+@shift.cash_sales+@shift.credit_sales %> | +<%= total_other_amount + @other_payment.foc_amount + @shift.cash_sales + @shift.credit_sales %> |