I have a form created in Light switch HTML Application (Visual C#).

Here is the table:

enter image description here

Which calculates a budget from three fields. One of them is the total that takes value from another screen (By clicking on insert item, one can add new items with their respective amounts).

enter image description here

These get saved in SUBTOTAL (Screen one item). The other two fields are Contingency Factors and Amount that can be added to round off the amount. Then Total to all these three fields must be saved in the fourth field that is TOTAL AMOUNT.

Now the problem which I am facing is:

  1. It is not saving the Total amount when I add items, It only changes when Other amount or Contigency factor are added. How to reflect these values immediately?

  2. This value of Total is to be copied into another text field (disabled- no one can edit it), but it is not being reflected there as well, any ideas how I can improve this?

All these calculations are done in jQuery.

Here is the code for calculations:

function calculateTotal(screen) {

 try {
        if ($('[id$=equipment_varSubTotal]').val() != "0") {
            screen.findContentItem("CapexMain_Equipment_SubTotal").value = $('[id$=equipment_varSubTotal]').val();
            var salesTax = parseFloat(screen.findContentItem("CapexMain_Equipment_SalesTax").value ? screen.findContentItem("CapexMain_Equipment_SalesTax").value : 0);
            var freight = parseFloat(screen.findContentItem("CapexMain_Equipment_Freight").value ? screen.findContentItem("CapexMain_Equipment_Freight").value : 0);
            var contingenceFactor = parseFloat(screen.findContentItem("CapexMain_Equipment_ContingenceFactor").value ? screen.findContentItem("CapexMain_Equipment_ContingenceFactor").value : 0);
            var otherAmount = parseFloat(screen.findContentItem("CapexMain_Equipment_OtherAmount").value ? screen.findContentItem("CapexMain_Equipment_OtherAmount").value : 0);
            var total = parseFloat(screen.findContentItem("CapexMain_Equipment_SubTotal").value ? screen.findContentItem("CapexMain_Equipment_SubTotal").value : $('[id$=equipment_varSubTotal]').val() ? $('[id$=equipment_varTotal]').val() : 0);
            //var total = parseFloat($('[id$=equipment_varTotal]').val());

            total = salesTax + freight + contingenceFactor + otherAmount + total;
            if (total != 0) {
                //$('[id$=equipment_varTotal]').val(total);
                $('[id$=CapexMain_Equipment_TotalCapexAmount]').val(total);
                screen.findContentItem("CapexMain_Equipment_TotalCapexAmount").value = total;
                $('[id$=equipment_varTotal]').val(total);
            }
        }
    }
    catch (e) { }
}

    myapp.AddEditCapexMain.created = function (screen) {


    $('#equipment_varSubTotal').change(function () {
        var a = "a";
    });
    screen.CapexMain.addChangeListener("Equipment_SubTotal", function (e) {
        var amount = parseFloat(screen.findContentItem("CapexMain_Equipment_SubTotal").value);
        if (amount > 0) {
            var total = parseFloat($('[id$=equipment_varTotal]').val());
            total += amount;
            $('[id$=CapexMain_Equipment_TotalCapexAmount]').val(total);
        }
    });
 screen.CapexMain.addChangeListener("Equipment_ContingenceFactor", function (e) {  calculateTotal(screen);
    });
    screen.CapexMain.addChangeListener("Equipment_OtherAmount", function (e) {
   calculateTotal(screen);
    });
screen.details.rootContentItem.handleViewDispose(function () {
        screen.CapexMain.removeChangeListener("Equipment_SubTotal", onPropertyChanged);
        screen.CapexMain.removeChangeListener("Equipment_ContingenceFactor", onPropertyChanged);
        screen.CapexMain.removeChangeListener("Equipment_OtherAmount", onPropertyChanged);
    });
};
0

There are 0 answers