2

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);
    });
};
Jhorra
  • 6,233
  • 21
  • 69
  • 123
Riaheen
  • 21
  • 1
  • 3
  • If all the calculations happen in jquery we need to see your jquery code to give you any information. A screenshot of the website is worthless. – Jhorra Dec 19 '16 at 07:22
  • @Jhorra Paradon, I am new to StackOver flow. I have added the code. Please take a look – Riaheen Dec 19 '16 at 09:39
  • Couple thoughts come to mind. Make sure you have valid values and that you aren't adding a number to a non value, which may cancel out your addition. The other is make sure your field name Ids match what's in your function. You could tell if you function is working by doing an `alert(total);` after you do your addition to see what you're actually getting. If you get an unexpected value, it's in your function, if you get the correct value it's probably in your field names. – Jhorra Dec 19 '16 at 15:24

0 Answers0