From 276e437a070bfb2340c4b17721a46f17993b1c52 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Tue, 23 Jun 2020 10:29:46 +0630 Subject: [PATCH] fix shift_sale double update --- .../transactions/shift_sales_controller.rb | 4 +-- app/models/sale_payment.rb | 14 ++------ app/models/shift_sale.rb | 2 +- .../transactions/shift_sales/show.html.erb | 33 ++++++++----------- 4 files changed, 19 insertions(+), 34 deletions(-) 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 @@ <%= @shift.total_receipt %> <%= @shift.dining_count %> <%= @shift.takeaway_count %> - (<%= @shift.total_void.round(2) %>) + (<%= @shift.total_void %>) @@ -50,7 +50,7 @@ Total <%= amount.account_name %> Amount - <%= amount.total_price.round(2) %> + <%= amount.total_price %> <%end%> @@ -63,7 +63,7 @@ Total <%= amount.account_name %> Discount - <%= amount.total_price.round(2) %> + <%= amount.total_price %> <%end%> @@ -94,7 +94,7 @@ <%= tax.tax_name %> - <%= tax.st_amount.round(2) %> + <%= tax.st_amount %> <%end%> @@ -105,30 +105,28 @@ Rounding Adj - <%= @shift.total_rounding.round(2) %> + <%= @shift.total_rounding %> Grand Total - <%= @shift.grand_total.round(2) %> + <%= @shift.grand_total %> + <% total_other_amount = 0 %> - + - + - <% @total_amount = 0 - @total_other_amount = 0 - @other_payment.each do |other| %> @@ -138,29 +136,26 @@ - - <% @total_other_amount = @total_other_amount + other[method.parameterize.to_sym] rescue 0.0 %> + + <% total_other_amount = total_other_amount + (@other_payment[method.parameterize.to_sym] || 0.0) %> <% end %> - - <% @total_amount = @total_amount + other.foc_amount rescue 0.0 %> + - <%end%> - + - + -
Cash Payment <%=@shift.cash_sales %><%= @shift.cash_sales %>
Credit Payment <%=@shift.credit_sales %><%= @shift.credit_sales %>
Other Payment Detail
<%= method %> Payment<%= other[method.parameterize.to_sym].round(2) rescue '-' %><%= @other_payment[method.parameterize.to_sym] || 0.0 %>
FOC <%=other.foc_amount.round(2) 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 %>