|
|
|
@ -52,13 +52,9 @@ module Validations::Sales::SaleInformationValidations |
|
|
|
return unless record.mortgage || record.mortgageused == 2 |
|
|
|
return unless record.mortgage || record.mortgageused == 2 |
|
|
|
return unless record.discount || record.grant || record.type == 29 |
|
|
|
return unless record.discount || record.grant || record.type == 29 |
|
|
|
|
|
|
|
|
|
|
|
discount_amount = record.discount ? record.value * record.discount / 100 : 0 |
|
|
|
if record.mortgage_deposit_and_grand_total != record.value_with_discount && record.discounted_ownership_sale? |
|
|
|
grant_amount = record.grant || 0 |
|
|
|
|
|
|
|
mortgage_amount = record.mortgage || 0 |
|
|
|
|
|
|
|
value_with_discount = (record.value - discount_amount) |
|
|
|
|
|
|
|
if mortgage_amount + record.deposit + grant_amount != value_with_discount && record.discounted_ownership_sale? |
|
|
|
|
|
|
|
%i[mortgage deposit grant value discount ownershipsch].each do |field| |
|
|
|
%i[mortgage deposit grant value discount ownershipsch].each do |field| |
|
|
|
record.errors.add field, I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: sprintf("%.2f", value_with_discount)) |
|
|
|
record.errors.add field, I18n.t("validations.sale_information.discounted_ownership_value", value_with_discount: sprintf("%.2f", record.value_with_discount)) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|