fix shift_sale double update
This commit is contained in:
@@ -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 }
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
<th><%= @shift.total_receipt %></th>
|
||||
<th><%= @shift.dining_count %></th>
|
||||
<th><%= @shift.takeaway_count %></th>
|
||||
<th>(<%= @shift.total_void.round(2) %>)</th>
|
||||
<th>(<%= @shift.total_void %>)</th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
@@ -50,7 +50,7 @@
|
||||
<tr>
|
||||
<th></th>
|
||||
<td style="text-align: right;"> Total <%= amount.account_name %> Amount</td>
|
||||
<td><%= amount.total_price.round(2) %></td>
|
||||
<td><%= amount.total_price %></td>
|
||||
</tr>
|
||||
<%end%>
|
||||
<tr>
|
||||
@@ -63,7 +63,7 @@
|
||||
<tr>
|
||||
<th></th>
|
||||
<td style="text-align: right;"> Total <%= amount.account_name %> Discount</td>
|
||||
<td><%= amount.total_price.round(2) %></td>
|
||||
<td><%= amount.total_price %></td>
|
||||
</tr>
|
||||
<%end%>
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
<tr>
|
||||
<th></th>
|
||||
<td style="text-align: right;"> <%= tax.tax_name %> </td>
|
||||
<td><%= tax.st_amount.round(2) %></td>
|
||||
<td><%= tax.st_amount %></td>
|
||||
</tr>
|
||||
<%end%>
|
||||
<tr>
|
||||
@@ -105,30 +105,28 @@
|
||||
<tr>
|
||||
<th></th>
|
||||
<th style="text-align: right;"> Rounding Adj </th>
|
||||
<th><%= @shift.total_rounding.round(2) %></th>
|
||||
<th><%= @shift.total_rounding %></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th style="text-align: right;"> Grand Total </th>
|
||||
<th><%= @shift.grand_total.round(2) %></th>
|
||||
<th><%= @shift.grand_total %></th>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<td colspan="6">
|
||||
<table width="100%">
|
||||
<% total_other_amount = 0 %>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th style="text-align: right;">Cash Payment </th>
|
||||
<th><%=@shift.cash_sales %></th>
|
||||
<th><%= @shift.cash_sales %></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th style="text-align: right;">Credit Payment </th>
|
||||
<th><%=@shift.credit_sales %></th>
|
||||
<th><%= @shift.credit_sales %></th>
|
||||
</tr>
|
||||
<% @total_amount = 0
|
||||
@total_other_amount = 0
|
||||
@other_payment.each do |other| %>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th style="text-align: right;">Other Payment Detail </th>
|
||||
@@ -138,29 +136,26 @@
|
||||
<tr>
|
||||
<th></th>
|
||||
<td style="text-align: right;"><%= method %> Payment</td>
|
||||
<td><%= other[method.parameterize.to_sym].round(2) rescue '-' %></td>
|
||||
<% @total_other_amount = @total_other_amount + other[method.parameterize.to_sym] rescue 0.0 %>
|
||||
<td><%= @other_payment[method.parameterize.to_sym] || 0.0 %></td>
|
||||
<% total_other_amount = total_other_amount + (@other_payment[method.parameterize.to_sym] || 0.0) %>
|
||||
</tr>
|
||||
<% end %>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td style="text-align: right;"><strong>FOC </strong></td>
|
||||
<td><%=other.foc_amount.round(2) rescue 0.0 %></td>
|
||||
<% @total_amount = @total_amount + other.foc_amount rescue 0.0 %>
|
||||
<td><%= @other_payment.foc_amount rescue 0.0 %></td>
|
||||
</tr>
|
||||
<%end%>
|
||||
|
||||
<tr>
|
||||
<th></th>
|
||||
<th style="text-align: right;">Total Other Payment </th>
|
||||
<th><%= @total_other_amount %></th>
|
||||
<th><%= total_other_amount %></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th style="text-align: right;">Total Payment </th>
|
||||
<th><%= @total_amount+@shift.cash_sales+@shift.credit_sales %></th>
|
||||
<th><%= total_other_amount + @other_payment.foc_amount + @shift.cash_sales + @shift.credit_sales %></th>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user