How to calculate taking input from four fields in yii2 dynamic form

前端 未结 1 960
暖寄归人
暖寄归人 2021-01-26 12:08

I\'ve five fields- rate, qty. discount, cgst_percent, cgst_amount. I want to calculate cgst_amount. The formula should be -

cgst_amount = ((rate*qty - (rate*qty         


        
相关标签:
1条回答
  • 2021-01-26 12:58

    You meshed up with fields and variables, i have updated a script a bit :

    function getGst(item) {
        var index  = item.attr("id").replace(/[^0-9.]/g, "");
        var qtyvar = ratevar = discvar = cgstpercentvar = cgstvar = 0;
    
        var id = item.attr("id");
        var myString = id.split("-").pop();
    
        quantity = index.concat("-qty");
        rate = index.concat("-rate");
        discount = index.concat("-discount");
        cgstRate = index.concat("-cgst_rate");
    
        temp1 = $("#productsales-"+quantity+"").val();
        temp2 = $("#productsales-"+rate+"").val();
        temp3 = $("#productsales-"+discount+"").val();
        temp4 = $("#productsales-"+cgstRate+"").val();
    
        if (isNaN(temp1) || temp1.length != 0) {
            qtyvar = temp1;
        }
    
        if (!isNaN(temp2) && temp2.length != 0) {
            ratevar = temp2;
        }
    
        if (isNaN(temp3) || temp3.length != 0) {
            discvar = temp3;
        }
    
        if (isNaN(temp4) || temp4.length != 0) {
            cgstpercentvar = temp4;
        }
    
        if (!isNaN(qtyvar) && !isNaN(ratevar) && !isNaN(discvar) && !isNaN(cgstpercentvar)) {
            cgstvar = ((((parseFloat(ratevar) * parseFloat(qtyvar)) - (parseFloat(ratevar) * parseFloat(qtyvar) * parseFloat(discvar))/100) * parseFloat(cgstpercentvar))/100).toFixed(2);
        }
    
        cgstField = "productsales-".concat(index).concat("-cgst_amount");
    
        $("#"+cgstField+"").val(cgstvar);
    
    }
    
    0 讨论(0)
提交回复
热议问题