Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #3420, editing Order Product Quantity, recalculation subtotals #3555

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model AddProductToOrderModel
@model AddProductToOrderModel

@using Nop.Core.Domain.Catalog

Expand All @@ -10,7 +10,6 @@
}

@*we add enctype = "multipart/form-data" because "File upload" attribute control type requires it*@

<form asp-controller="Order" asp-action="AddProductToOrderDetails" asp-route-orderId="@Model.OrderId"
asp-route-productId="@Model.ProductId" enctype="multipart/form-data" method="post" id="product-details-form">

Expand Down Expand Up @@ -53,7 +52,7 @@
<nop-label asp-for="UnitPriceInclTax" />
</div>
<div class="col-md-9">
<nop-editor asp-for="UnitPriceInclTax" />
<nop-editor asp-for="UnitPriceInclTax" class="UnitPriceInclTax" />
</div>
</div>
<div class="form-group">
Expand Down Expand Up @@ -142,4 +141,24 @@
</div>
</div>
</div>
</form>
</form>

<script type="text/javascript">
$(document).ready(function () {
$("#Quantity, #UnitPriceInclTax, #UnitPriceExclTax").TouchSpin().on('change', function () {
updateTotal();
});
});

function updateTotal() {
var quantity = $("#Quantity").val();
var unitPriceInclTax = $("#UnitPriceInclTax").val();
var unitPriceExclTax = $("#UnitPriceExclTax").val();

var priceInclTax = unitPriceInclTax * quantity;
$("#SubTotalInclTax").val(priceInclTax.toFixed(4));

var priceExclTax = unitPriceExclTax * quantity;
$("#SubTotalExclTax").val(priceExclTax.toFixed(4));
}
</script>
Original file line number Diff line number Diff line change
@@ -1,18 +1,86 @@
@model OrderModel
@model OrderModel

@using Nop.Core.Domain.Tax;
@using Nop.Core.Domain.Orders;
@using Nop.Services

@if (!Model.IsLoggedInAsVendor)
{
<script>
$(document).ready(function () {
<script type="text/javascript">

$(document).ready(function () {
toggleChangeOrderStatus(false);
toggleOrderTotals(false);
toggleCC(false);

$("#OrderSubtotalInclTaxValue, #OrderSubTotalDiscountInclTaxValue, #OrderShippingInclTaxValue, #PaymentMethodAdditionalFeeInclTaxValue, #TaxValue, #OrderTotalDiscountValue").on('change', function () {
updateTotal();
});
});

function updateTotal() {

var TaxRatesValue = $("#TaxRatesValue").val();

// Get taxRate from TaxRatesValue
var TaxRatesValue = $("#TaxRatesValue").val().split(":");

var taxRate = 0;
if (TaxRatesValue.length > 1)
taxRate = parseFloat(TaxRatesValue[0]);

// Order subtotal with tax
var orderSubtotalInclTaxValue = parseFloat($("#OrderSubtotalInclTaxValue").val());

// Order subtotal without tax
var orderSubtotalExclTaxValue = orderSubtotalInclTaxValue / ((100 + taxRate) / 100);
$("#OrderSubtotalExclTaxValue").val(orderSubtotalExclTaxValue.toFixed(4));


// Order subTotal discount with tax
var orderSubTotalDiscountInclTaxValue = parseFloat($("#OrderSubTotalDiscountInclTaxValue").val());

// Order subtotal discount without tax
var orderSubTotalDiscountExclTaxValue = orderSubTotalDiscountInclTaxValue / ((100 + taxRate) / 100);
$("#OrderSubTotalDiscountExclTaxValue").val(orderSubTotalDiscountExclTaxValue.toFixed(4));


// Order shipping with tax
var orderShippingInclTaxValue = parseFloat($("#OrderShippingInclTaxValue").val());

// Order shipping without tax
var orderShippingExclTaxValue = orderShippingInclTaxValue / ((100 + taxRate) / 100);
$("#OrderShippingExclTaxValue").val(orderShippingExclTaxValue.toFixed(4));


// Payment method additional fee with tax
var paymentMethodAdditionalFeeInclTaxValue = parseFloat($("#PaymentMethodAdditionalFeeInclTaxValue").val());

// Order shipping without tax
var paymentMethodAdditionalFeeExclTaxValue = paymentMethodAdditionalFeeInclTaxValue / ((100 + taxRate) / 100);
$("#PaymentMethodAdditionalFeeExclTaxValue").val(paymentMethodAdditionalFeeExclTaxValue.toFixed(4));

// Total order without tax
var orderTotalExclTaxValue = orderSubtotalExclTaxValue - orderSubTotalDiscountExclTaxValue + orderShippingExclTaxValue + paymentMethodAdditionalFeeExclTaxValue;

// Total order with tax
var orderTotalInclTaxValue = orderSubtotalInclTaxValue - orderSubTotalDiscountInclTaxValue + orderShippingInclTaxValue + paymentMethodAdditionalFeeInclTaxValue;

// Tax value
var taxValue = orderTotalInclTaxValue - orderTotalExclTaxValue;
$("#TaxValue").val(taxValue.toFixed(4));

// Discount
var orderTotalDiscountValue = parseFloat($("#OrderTotalDiscountValue").val());

// orderTotalInclTaxValue = orderTotalInclTaxValue - orderTotalDiscountValue
orderTotalInclTaxValue -= orderTotalDiscountValue;

// Total order with tax
$("#OrderTotalValue").val(orderTotalInclTaxValue.toFixed(4));

}

function toggleChangeOrderStatus(editmode) {
if (editmode) {
$('#pnlChangeOrderStatus').show();
Expand Down Expand Up @@ -74,7 +142,8 @@
}
</script>
}
<div class="panel-body">
<div class="panel-group">
@await Component.InvokeAsync("AdminWidget", new { widgetZone = "admin_order_details_info_top", additionalData = Model.Id })
<div class="panel panel-default">
<div class="panel-body">
@if (!Model.IsLoggedInAsVendor)
Expand Down Expand Up @@ -402,7 +471,7 @@
<nop-label asp-for="RedeemedRewardPoints" />
</div>
<div class="col-md-9">
<div class="form-text-row">@($"{Model.RedeemedRewardPoints}{T("Admin.Orders.Fields.RedeemedRewardPoints.Points")} {Model.RedeemedRewardPointsAmount}")</div>
<div class="form-text-row">@Model.RedeemedRewardPoints + @T("Admin.Orders.Fields.RedeemedRewardPoints.Points").Text + "/" + @Model.RedeemedRewardPointsAmount</div>
</div>
</div>
}
Expand Down Expand Up @@ -822,4 +891,5 @@
</div>
</div>
</div>
</div>
@await Component.InvokeAsync("AdminWidget", new { widgetZone = "admin_order_details_info_bottom", additionalData = Model.Id })
</div>