Javascript计算(产品总额不含增值税)

Javascript计算(产品总额不含增值税),javascript,php,mysql,Javascript,Php,Mysql,您好,我在javascriptsee图像中遇到一些计算问题 用红色边框的单元格计算产品价格和增值税。 我想做的但没有成功的是计算产品的价格和没有VAT的红布罗德电池应该是2000而不是2200 这是我使用的代码 var row_no = (new Date).getTime(); var newTr = $('<tr id="row_' + row_no + '" class="row_' + item_id + '" data-item-id="' + i

您好,我在javascriptsee图像中遇到一些计算问题

用红色边框的单元格计算产品价格和增值税。 我想做的但没有成功的是计算产品的价格和没有VAT的红布罗德电池应该是2000而不是2200

这是我使用的代码

        var row_no = (new Date).getTime();
        var newTr = $('<tr id="row_' + row_no + '" class="row_' + item_id + '" data-item-id="' + item_id + '"></tr>');
        tr_html = '<td><input name="product_id[]" type="hidden" class="rid" value="' + product_id + '"><input name="product[]" type="hidden" class="rcode" value="' + item_code + '"><input name="product_name[]" type="hidden" class="rname" value="' + item_name + '"><input name="product_option[]" type="hidden" class="roption" value="' + item_option + '"><input name="part_no[]" type="hidden" class="rpart_no" value="' + item_supplier_part_no + '"><span class="sname" id="name_' + row_no + '">' + item_code +' - '+ item_name +(sel_opt != '' ? ' ('+sel_opt+')' : '')+' <span class="label label-default">'+item_supplier_part_no+'</span></span> <i class="pull-right fa fa-edit tip edit" id="' + row_no + '" data-item="' + item_id + '" title="Edit" style="cursor:pointer;"></i></td>';
        if (site.settings.product_expiry == 1) {
            tr_html += '<td><input class="form-control date rexpiry" name="expiry[]" type="text" value="' + item_expiry + '" data-id="' + row_no + '" data-item="' + item_id + '" id="expiry_' + row_no + '"></td>';
        }
        tr_html += '<td class="text-right"><input class="form-control input-sm text-right rcost" name="net_cost[]" type="hidden" id="cost_' + row_no + '" value="' + item_cost + '"><input class="rucost" name="unit_cost[]" type="hidden" value="' + unit_cost + '"><input class="realucost" name="real_unit_cost[]" type="hidden" value="' + item.row.real_unit_cost + '"><span class="text-right scost" id="scost_' + row_no + '">' + formatMoney(item_cost) + '</span></td>';
        tr_html += '<td><input name="quantity_balance[]" type="hidden" class="rbqty" value="' + item_bqty + '"><input class="form-control text-center rquantity" name="quantity[]" type="text" tabindex="'+((site.settings.set_focus == 1) ? an : (an+1))+'" value="' + formatQuantity2(item_qty) + '" data-id="' + row_no + '" data-item="' + item_id + '" id="quantity_' + row_no + '" onClick="this.select();"><input name="product_unit[]" type="hidden" class="runit" value="' + product_unit + '"><input name="product_base_quantity[]" type="hidden" class="rbase_quantity" value="' + base_quantity + '"></td>';
        if (po_edit) {
            tr_html += '<td class="rec_con"><input name="ordered_quantity[]" type="hidden" class="oqty" value="' + item_oqty + '"><input class="form-control text-center received" name="received[]" type="text" value="' + formatDecimal(unit_qty_received) + '" data-id="' + row_no + '" data-item="' + item_id + '" id="received_' + row_no + '" onClick="this.select();"><input name="received_base_quantity[]" type="hidden" class="rrbase_quantity" value="' + qty_received + '"></td>';
        }
        if (site.settings.product_discount == 1) {
            tr_html += '<td class="text-right"><input class="form-control input-sm rdiscount" name="product_discount[]" type="hidden" id="discount_' + row_no + '" value="' + item_ds + '"><span class="text-right sdiscount text-danger" id="sdiscount_' + row_no + '">' + formatMoney(0 - (item_discount * item_qty)) + '</span></td>';
        }
        tr_html += '<td class="text-right"><span class="text-right ssubtotal" id="subtotal_' + row_no + '">' + formatMoney((parseFloat(item_cost) * parseFloat(item_qty))) + '</span></td>';
        if (site.settings.tax1 == 1) {
            tr_html += '<td class="text-right"><input class="form-control input-sm text-right rproduct_tax" name="product_tax[]" type="hidden" id="product_tax_' + row_no + '" value="' + pr_tax.id + '"><span class="text-right sproduct_tax" id="sproduct_tax_' + row_no + '">' + (pr_tax_rate ? '(' + pr_tax_rate + ')' : '') + ' ' + formatMoney(pr_tax_val * item_qty) + '</span></td>';
        }

        tr_html += '<td class="text-right"><span class="text-right ssubtotal" id="subtotal_' + row_no + '">' + formatMoney(((parseFloat(item_cost) + parseFloat(pr_tax_val)) * parseFloat(item_qty))) + '</span></td>';
        tr_html += '<td class="text-center"><i class="fa fa-times tip podel" id="' + row_no + '" title="Remove" style="cursor:pointer;"></i></td>';
        newTr.html(tr_html);
        newTr.prependTo("#poTable");
        total += formatDecimal(((parseFloat(item_cost) + parseFloat(pr_tax_val)) * parseFloat(item_qty)), 4);
        count += parseFloat(item_qty);
        an++;
        if(!belong)
            $('#row_' + row_no).addClass('warning');
    });

    var col = 2;
    if (site.settings.product_expiry == 1) { col++; }
    var tfoot = '<tr id="tfoot" class="tfoot active"><th colspan="'+col+'">Total</th><th class="text-center">' + formatQty(parseFloat(count) - 1) + '</th>';
    if (po_edit) {
        tfoot += '<th class="rec_con"></th>';
    }
    if (site.settings.product_discount == 1) {
        tfoot += '<th class="text-right">'+formatMoney(product_discount)+'</th>';
    }
    tfoot += '<th class="text-right">'+formatMoney(total)+'</th>';
    if (site.settings.tax1 == 1) {
        tfoot += '<th class="text-right">'+formatMoney(product_tax)+'</th>';
    }
    tfoot += '<th class="text-right">'+formatMoney(total)+'</th><th class="text-center"><i class="fa fa-trash-o" style="opacity:0.5; filter:alpha(opacity=50);"></i></th></tr>';
    $('#poTable tfoot').html(tfoot);

您可以在此处设置显示的总数:

total += formatDecimal(((parseFloat(item_cost) + parseFloat(pr_tax_val)) * parseFloat(item_qty)), 4);
要显示不含增值税的价格,需要另一个变量

var totalNoVAT = 0;
在循环中:

totalNoVAT += formatDecimal((parseFloat(item_cost) * parseFloat(item_qty)), 4);
最后,通过更改以下内容来显示:

tfoot += '<th class="text-right">'+formatMoney(total)+'</th>';
为此:

tfoot += '<th class="text-right">'+formatMoney(totalNoVAT)+'</th>';

以及此行合计+=FormatDecimalParseFloatite\u成本+parseFloatpr\u税值*parseFloatitem\u数量,4;将税金加到总额中,这就是您在该列中使用的变量,这在某种程度上解释了这一点。是的,我知道的是总计的一个结果。我所需要的是另一个不含增值税的总额。问题是我没有添加另一个var。谢谢您的支持谢谢您的回答!我尝试了此选项,但结果为0。也许我在这方面做错了:totalNoVAT+=FormatDecimalParseFloatite\u成本*parseFloatitem\u数量,4;将此代码放在何处?将其放在total+=formatDecimalparseFloatitem\u cost+parseFloatpr\u tax\u val*parseFloatitem\u数量下,4;把totalNoVAT=0放在最上面谢谢你,先生!现在一切都好了。我感谢你的帮助,上帝保佑你。我不想打扰你,但如果你能在另外两件事上帮助我?谢谢。正如您在图中看到的,我可以输入产品数量,但不能直接输入图片第三列中的产品成本。您能帮我解决这个问题吗?我想对产品成本也这样做。代码在问题中。