简体   繁体   English

Javascript / Codeigniter中的价格计算

[英]Price Calculation in Javascript/Codeigniter

I want to calculate the Total Price for the order. 我要计算订单的总价。 I got a formula:: 我有一个公式:

TotalWithoutTax = (UnitPrice*Quantity)+Transportation+Premium-Discount TotalWithoutTax =(单价*数量)+运输量+特级折扣

TotalAmtInclTax = TotalWithoutTax + TotalTax TotalAmtInclTax = TotalWithoutTax + TotalTax

But I cannot get the output. 但是我无法获得输出。 Please help me and give me some advise on this. 请帮助我,并给我一些建议。 Thank You. 谢谢。

Javascript: 使用Javascript:

function calcPrice(qty[], unit_price[], gp[], discount[], totalwithouttax, totaltax, totalamtincltax) {
  var quantity = document.getElementById('qty[]').value;
  var unitPrice = document.getElementById('unit_price[]').value;
  var premium = document.getElementById('gp[]').value;
  var discount = document.getElementById('discount[]').value;
  var transportation = document.getElementById('transportation[]').value;

  var totalwithouttax = (unitPrice * quantity) + premium + transportation - discount;
  document.getElementById(totalwithouttax).value = Math.round(totalwithouttax);
  return true;
  var totalwithouttax = document.getElementById('totalwithouttax').value;
  var totaltax = document.getElementById('totaltax').value;

  var totalamtincltax = totalwithouttax + totaltax;
  document.getElementById(totalamtincltax).value = Math.round(totalamtincltax);
  return true;
}

View: 视图:

<!-- **************************** START OF ITEM LIST 1 ************************   -->
<tr class="item-details">
  <td><span class="rowNumber">1</span></td>
  <td class="">
    <?php
      $options = array(
                       '' => '~Choose An Item~'
                       );
      foreach ($item as $rows){
          $options[$rows->id] = $rows->item_name;
      }

      $select = array(
                      'id' => 'item_name',
                      'class' => 'form-control'
                      );
      echo form_dropdown('item_name[]', $options,set_value('item_name'),$select);
    ?>
  </td>
  <td class=""><input type="number" class="item-qty" name="qty[]" /></td>
  <td><input type="number" name="weight[]" class="weight" /></td>
  <td><input type="number" name="transportation[]" class="transporation" onkeyup="calcPrice(qty[],unit_price[],gp[],discount[],totalwithouttax,totaltax,totalamtincltax);" /></td>
  <td><input type="text" id="gp[]" name="gp[]" value="" onkeyup="calcPrice(qty[],unit_price[],gp[],discount[],totalwithouttax,totaltax,totalamtincltax);" /></td>
  <td><input type="text" id="discount[]" name="discount[]" value="" onkeyup="calcPrice(qty[],unit_price[],gp[],discount[],totalwithouttax,totaltax,totalamtincltax);" /></td>
  <td><input type="text" id="unit_price[]" name="unit_price[]" value="" onkeyup="calcPrice(qty[],unit_price[],gp[],discount[],totalwithouttax,totaltax,totalamtincltax);" /></td>
  <td align="right">
    <input type="text" id="totalwithouttax" name="totalwithouttax" value="" onkeyup="calcPrice(qty[],unit_price[],gp[],discount[],totalwithouttax,totaltax,totalamtincltax);" readonly>
  </td>
  <td align="right">
    <input type="text" id="totaltax" name="totaltax" value="" onkeyup="calcPrice(qty[],unit_price[],gp[],discount[],totalwithouttax,totaltax,totalamtincltax);" readonly>
  </td>
  <td align="right">
    <input type="text" id="totalamtincltax" name="totalamtincltax" value="" onkeyup="calcPrice(qty[],unit_price[],gp[],discount[],totalwithouttax,totaltax,totalamtincltax);" readonly>
  </td>
</tr><br/>
   document.getElementById("totalwithouttax").value=Math.round(totalwithouttax);

这样可以解决很多问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM