Merge branch 'r-1902001-01-dev' of gitlab.com:code2lab/SXRestaurant into r-1902001-01-dev

This commit is contained in:
yarzar_code
2020-01-09 15:58:05 +06:30
6 changed files with 64 additions and 65 deletions

View File

@@ -242,7 +242,7 @@ class Origami::PaymentsController < BaseOrigamiController
end end
if path.include? ("credit_payment") if path.include? ("credit_payment")
@sale_payment = SalePayment.get_credit_amount_due_left(sale_id) @sale_payment = SalePayment.where(sale_id: sale_id, payment_method: 'creditnote').select("SUM(payment_amount) as payment_amount")
end end
@member_discount = MembershipSetting.find_by_discount(1) @member_discount = MembershipSetting.find_by_discount(1)

View File

@@ -1438,10 +1438,10 @@ end
cash = 0.0 cash = 0.0
self.sale_payments.each do |pay| self.sale_payments.each do |pay|
if pay.payment_method == 'cash' if pay.payment_method == 'cash'
cash = pay.payment_amount-self.amount_changed cash += pay.payment_amount
end end
end end
return cash return cash - self.amount_changed
end end
def get_credit_amount def get_credit_amount

View File

@@ -637,15 +637,14 @@ 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.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 = sale.amount_received.to_f - sale.grand_total.to_f sale.amount_changed = total_payment_amount - sale.grand_total.to_f
all_received_amount = sale.sale_payments.reload.sum(&:payment_amount)
is_credit = sale.sale_payments.any? { |x| x.payment_method == "creditnote" } is_credit = sale.sale_payments.any? { |x| x.payment_method == "creditnote" }
is_foc = sale.sale_payments.any? { |x| x.payment_method == "foc" } is_foc = sale.sale_payments.any? { |x| x.payment_method == "foc" }
if sale.grand_total <= all_received_amount && sale.sale_status == "new" if 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"
@@ -957,7 +956,6 @@ class SalePayment < ApplicationRecord
def self.get_sale_payment_for_credit(sale_data) def self.get_sale_payment_for_credit(sale_data)
sale_data.sale_payments sale_data.sale_payments
.joins(:sale_audit) .joins(:sale_audit)
.where(created_at: 1.days.ago.beginning_of_day..DateTime::Infinity.new)
end end
def get_credit_payment_left def get_credit_payment_left

View File

@@ -17,7 +17,7 @@ class SeedGenerator < ApplicationRecord
end end
seed = self.update_seed(model_name) seed = self.update_seed(model_name)
length = 15 - prefix.length length = 16 - prefix.length
prefix + seed.to_s.rjust(length, '0') prefix + seed.to_s.rjust(length, '0')
end end
@@ -39,7 +39,7 @@ class SeedGenerator < ApplicationRecord
start = self.update_seed(model_name, count) start = self.update_seed(model_name, count)
stop = start + count - 1 stop = start + count - 1
length = 15 - prefix.length length = 16 - prefix.length
(start..stop).map { |c| prefix + c.to_s.rjust(length, '0') } (start..stop).map { |c| prefix + c.to_s.rjust(length, '0') }
end end

View File

@@ -136,23 +136,24 @@
<% sale_payments = result.sale_payments %> <% sale_payments = result.sale_payments %>
<% if sale_payments.length > 0%> <% if sale_payments.length > 0%>
<% sale_payments.each do |rec| %> <% sale_payments.each do |rec| %>
<% next if rec.payment_method == 'credit_note' && result.payments_for_credits_amount < rec.payment_amount %> <% if rec.payment_amount > 0 %>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>Payment <%= rec.payment_method.upcase %></td>
<td><%= number_format(rec.payment_amount, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) %> ( <%= rec.payment_status %> )</td>
<td>&nbsp;</td>
</tr>
<% if !rec.payment_reference.nil? %>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>Payment Ref.</td> <td>Payment <%= rec.payment_method.upcase %></td>
<td><%= rec.payment_reference %></td> <td><%= number_format(rec.payment_amount, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) %> ( <%= rec.payment_status %> )</td>
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
<% if !rec.payment_reference.nil? %>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>Payment Ref.</td>
<td><%= rec.payment_reference %></td>
<td>&nbsp;</td>
</tr>
<% end %>
<% end %> <% end %>
<% end %> <% end %>
<% if result.amount_changed != 0 %> <% if result.amount_changed != 0 %>

View File

@@ -125,7 +125,7 @@
</tr> </tr>
<% end %> <% end %>
<% sale_payments = SalePayment.get_sale_payments(result) %> <% sale_payments = result.sale_payments %>
<% if sale_payments.length > 0%> <% if sale_payments.length > 0%>
<% sale_payments.each do |rec| %> <% sale_payments.each do |rec| %>
<%if rec.payment_amount.to_f > 0 %> <%if rec.payment_amount.to_f > 0 %>