Wednesday, 25 July 2012

calculation in jquery

<script type="text/javascript">
  
    function calculateTotal() {
        var Amount = 0;
        var TotalPrice = 0;
        var TotalPrice1 = 0;
        $("#GridViewRFPSetPrice").find('.unitprice').each(function (index) {
            var row = $(this).closest("tr");
            var UnitPrice = parseFloat(row.find('.unitprice').val());
            var Vat = parseFloat(row.find('.vat').val());
            var Discount = parseFloat(row.find('.disc').val());
            var qty = parseFloat(row.find("input[type=hidden][id*=HidQty]").val());
           
            if (isNaN(Vat)) {
                Vat = 0;
            }
            if (isNaN(Discount)) {
                Discount = 0;
            }
            if ($.trim(UnitPrice) != "") {
                //Check if number is a valid integer
                if (!isNaN(UnitPrice)) {
                    Amount = UnitPrice * qty;
                    Amount += (Amount * Vat) / 100;
                    Amount -= (Amount * Discount) / 100;
                    row.find('.totalprice').val(Amount.toFixed(2));
                    row.find("input[type=hidden][id*=HidTotalPrice]").val(Amount.toFixed(2))
                    //$('#HidTotalPrice').val(Amount.toFixed(2));
                }
                else {
                    row.find('.totalprice').val('');
                    row.find('.vat').val('');
                    row.find('.disc').val('');
                }
            }
            TotalPrice1 = parseFloat(row.find('.totalprice').val());
            if (!isNaN(TotalPrice1)) {
                TotalPrice = TotalPrice + parseFloat(TotalPrice1);

            }
            $("#TxtGrossFig").val(TotalPrice.toFixed(2));
            $("#HidGrossTotal").val(TotalPrice.toFixed(2));
            $("#TxtGrossWord").val(convert_word(TotalPrice.toFixed(2)));
        });
    }

No comments:

Post a Comment