Problem in each loop

indradaman sharma
indrada...
Participant
116 Points
14 Posts
function CalculateProductTotalRate(ShippingTypeID, ProductTranID, ProductWeight, Stock, MOQ, SOQ, IsRegularProduct, IsNewProduct, txt, RowIndex) {
txt = document.getElementById(txt);
var RateSheetTableID = "tblShippingRate" + ShippingTypeID;
var Quantity = (txt.value == "" ? "0" : txt.value);
var TotalWeight = 0.00;
var Rate = 0.00;
var TotalAmount = 0.00;
var MarginPer = 0.00;
var TotalMarginAmt = 0.00;
var WeightFrom = 0.00;
var WeightTo = 0.00;
var BasicAmount = 0.00;
var WeightMin = 0.00;
var WeightMax = 0.00;
var TempProductTranID = 0;
var UnitShortName = $("#hdnUnitShortName").val();
var IsValidOrder = false;
UnitShortName = "Kg";
TotalWeight = ProductWeight * Quantity;
BasicAmount = parseFloat($("#hdnBasePrice").val());


$("#" + RateSheetTableID + " tr td").each(function (i) {
if ($("#hdnWeightFrom_" + ShippingTypeID + "_" + i).val() == undefined || $("#hdnWeightFrom_" + ShippingTypeID + "_" + i).val() == null) { return false; }
WeightFrom = parseFloat($("#hdnWeightFrom_" + ShippingTypeID + "_" + i).val());
WeightTo = parseFloat($("#hdnWeightTo_" + ShippingTypeID + "_" + i).val());
WeightMin = parseFloat($("#hdnWeightMin_" + ShippingTypeID + "_" + i).val());
WeightMax = parseFloat($("#hdnWeightMax_" + ShippingTypeID + "_" + i).val());
TempProductTranID = parseFloat($("#hdnProductTranID_" + ShippingTypeID + "_" + i).val());
TotalWeight = parseFloat(TotalWeight);
alert(parseFloat($("#hdnShippingAmt_" + ShippingTypeID + "_" + i).val()));
//alert(TotalWeight +">="+ WeightFrom +"&&"+ TotalWeight +"<="+ WeightTo);
if (TotalWeight >= WeightFrom && TotalWeight <= WeightTo && ProductTranID == TempProductTranID) {
//alert(TotalWeight + ">=" + WeightFrom + "&&" + TotalWeight + "<=" + WeightTo);
Rate = parseFloat($("#hdnShippingAmt_" + ShippingTypeID + "_" + i).val());
//alert(Rate);
MarginPer = parseFloat($("#hdnDistributorMarginPer_" + ShippingTypeID + "_" + i).val());
return false;
}
});

if (Rate == 0.00) {
$("#" + RateSheetTableID + " tr td").each(function (i) {
if ($("#hdnWeightFrom_" + ShippingTypeID + "_" + i).val() == undefined || $("#hdnWeightFrom_" + ShippingTypeID + "_" + i).val() == null) { return false; }
WeightFrom = parseFloat($("#hdnWeightFrom_" + ShippingTypeID + "_" + i).val());
WeightTo = parseFloat($("#hdnWeightTo_" + ShippingTypeID + "_" + i).val());
WeightMin = parseFloat($("#hdnWeightMin_" + ShippingTypeID + "_" + i).val());
WeightMax = parseFloat($("#hdnWeightMax_" + ShippingTypeID + "_" + i).val());
TempProductTranID = parseFloat($("#hdnProductTranID_" + ShippingTypeID + "_" + i).val());
TotalWeight = parseFloat(TotalWeight);
alert(parseFloat($("#hdnShippingAmt_" + ShippingTypeID + "_" + i).val()));
//alert(TotalWeight +">="+ WeightFrom +"&&"+ TotalWeight +"<="+ WeightTo);
if (ProductTranID == TempProductTranID) {
Rate = parseFloat($("#hdnShippingAmt_" + ShippingTypeID + "_" + i).val());
//alert('Second rate '+Rate);
MarginPer = parseFloat($("#hdnDistributorMarginPer_" + ShippingTypeID + "_" + i).val());
return false;
}
});
}
Rate = BasicAmount + Rate;
TotalAmount = TotalWeight * Rate;
//alert(TotalAmount);
TotalMarginAmt = TotalAmount * MarginPer / 100;
if (Quantity > SOQ && SOQ>0) {
alert('Max Order Quantity is ' + SOQ + '');
txt.value = "";
txt.focus();
} else if (Quantity >= WeightMin && Quantity <= WeightMax || WeightMin == 0 && WeightMax == 0 || Quantity == 0) {
if (Quantity == 0) {
$("#spanTotalWeight_" + ShippingTypeID + "_" + RowIndex + "").html("");
$("#spanRate_" + ShippingTypeID + "_" + RowIndex + "").html("");
$("#spanTotalAmount_" + ShippingTypeID + "_" + RowIndex + "").html("");
$("#spanMarginPer_" + ShippingTypeID + "_" + RowIndex + "").html("");
$("#spanMarginAmt_" + ShippingTypeID + "_" + RowIndex + "").html("");
$("#spanCalculate_" + ShippingTypeID + "_" + RowIndex + "").css("display", "none");
$("#spanEqualSign_" + ShippingTypeID + "_" + RowIndex + "").css("display", "");
$("#hdnIsUpdateCart_" + ShippingTypeID + "_" + RowIndex + "").val("Y");
CalculateProductTotalRateClear = 0;
} else {
if (IsRegularProduct) {
if (Stock == 0) {
IsValidOrder = confirm('We don’t have this packing available in stock right now. So, we shall need to produce the same. Production takes 3-4 days in general. Please check with us for exact production time');
CalculateProductTotalRateClear = 0;
} else if (Quantity <= Stock) {
IsValidOrder = true;
} else {
//clearTimeout(CalculateProductTotalRateClear);
//IsValidOrder = confirm('upto ' + (Stock * ProductWeight) + ' ' + UnitShortName + ' can be dispatched immediately. Rest needs to be produced. General production time 10-15 days');
IsValidOrder = confirm('Upto ' + (Stock) + ' bags are available in stock. For larger quantity, we shall need to produce the same. Production takes 3-4 days in general. Please check with us for exact production time');
CalculateProductTotalRateClear = 0;
//txt.focus();
}
} else {
if (Quantity <= Stock) {
IsValidOrder = true;
} else if ((Quantity - Stock) - parseInt(MOQ) < 0 && Stock > 0) {
//alert('In stock ' + (Stock * ProductWeight) + ' ' + UnitShortName + ', MOQ for ordering =' + (parseInt(MOQ) * ProductWeight) + ' ' + UnitShortName + '. Order qty needs to be upto ' + (Stock * ProductWeight) + ' ' + UnitShortName + ' or greater than ' + ((Stock * ProductWeight) + (parseInt(MOQ) * ProductWeight)) + ' ' + UnitShortName + '' +
// ' \nUpto ' + (Stock * ProductWeight) + ' ' + UnitShortName + ' can be dispatched immediately. Rest needs to be produced. General production time 10-15 days');
alert('In stock ' + Stock + ' bags, MOQ for ordering =' + parseInt(MOQ) + ' bags. Order qty needs to be upto ' + (Stock * ProductWeight) + ' ' + UnitShortName + ' or greater than ' + (Stock + parseInt(MOQ)) + ' bags ' +
' \nUpto ' + Stock + ' bags can be dispatched immediately. Rest needs to be produced. General production time 10-15 days');
CalculateProductTotalRateClear = 0;
//txt.focus();
} else if ((Quantity - Stock) - parseInt(MOQ) < 0 && Stock == 0) {
alert('MOQ for ordering =' + parseInt(MOQ) + ' bags. Material needs to be produced. General production time 10-15 days');
CalculateProductTotalRateClear = 0;
txt.value = "";
$("#Anchor_" + ProductTranID).click();
} else {
IsValidOrder = true;
//alert(' upto ' + (Stock * ProductWeight) + ' ' + UnitShortName + ' or greater than ' + ((Stock * ProductWeight) + (parseInt(MOQ) * ProductWeight)) + ' ' + UnitShortName + '');
}
}
if (IsValidOrder) {
$("#spanTotalWeight_" + ShippingTypeID + "_" + RowIndex + "").html(TotalWeight.toFixed(3));
$("#spanRate_" + ShippingTypeID + "_" + RowIndex + "").html(Rate.toFixed(2));
$("#spanTotalAmount_" + ShippingTypeID + "_" + RowIndex + "").html(TotalAmount.toFixed(2));
$("#spanMarginPer_" + ShippingTypeID + "_" + RowIndex + "").html(MarginPer.toFixed(2));
$("#spanMarginAmt_" + ShippingTypeID + "_" + RowIndex + "").html(TotalMarginAmt.toFixed(2));
$("#hdnMarginPer_" + ShippingTypeID + "_" + RowIndex + "").val(MarginPer.toFixed(2));
$("#hdnMarginAmt_" + ShippingTypeID + "_" + RowIndex + "").val(TotalMarginAmt.toFixed(2));
$("#hdnIsUpdateCart_" + ShippingTypeID + "_" + RowIndex + "").val("Y");
$("#spanCalculate_" + ShippingTypeID + "_" + RowIndex + "").css("display", "none");
$("#spanEqualSign_" + ShippingTypeID + "_" + RowIndex + "").css("display", "");
CalculateProductTotalRateClear = 0;
} else {
//txt.focus();
txt.value = "";
$("#Anchor_" + ProductTranID).click();
}
if ($("#hdnCustomerIDWithoutLogin").val() != "Y" && IsValidOrder) {
EnableDisable_UpdateCart(true);
}
}
} else {
alert('Quantity should be between ' + WeightMin + ' and ' + WeightMax + '');
txt.value = "";
CalculateProductTotalRateClear = 0;
$("#Anchor_" + ProductTranID).click();
//txt.focus();
}
}
Views: 8524
Total Answered: 1
Total Marked As Answer: 0
Posted On: 09-Jul-2015 03:56

Share:   fb twitter linkedin
Answers
Rahul Maurya
Rahul M...
Teacher
4822 Points
23 Posts
         

Hi Indradaman,

Code looking fine and loop is also fine.

Posted On: 10-Jul-2015 00:50
 Log In to Chat