[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/include/js/ -> Inventory.js (source)

   1  /*********************************************************************************
   2  
   3  ** The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   ********************************************************************************/
  10  
  11  function copyAddressRight(form) {
  12  
  13      form.ship_street.value = form.bill_street.value;
  14  
  15      form.ship_city.value = form.bill_city.value;
  16  
  17      form.ship_state.value = form.bill_state.value;
  18  
  19      form.ship_code.value = form.bill_code.value;
  20  
  21      form.ship_country.value = form.bill_country.value;
  22  
  23      form.ship_pobox.value = form.bill_pobox.value;
  24      
  25      return true;
  26  
  27  }
  28  
  29  function copyAddressLeft(form) {
  30  
  31      form.bill_street.value = form.ship_street.value;
  32  
  33      form.bill_city.value = form.ship_city.value;
  34  
  35      form.bill_state.value = form.ship_state.value;
  36  
  37      form.bill_code.value =    form.ship_code.value;
  38  
  39      form.bill_country.value = form.ship_country.value;
  40  
  41      form.bill_pobox.value = form.ship_pobox.value;
  42  
  43      return true;
  44  
  45  }
  46  
  47  function settotalnoofrows() {
  48      var max_row_count = document.getElementById('proTab').rows.length;
  49          max_row_count = eval(max_row_count)-2;
  50  
  51      //set the total number of products
  52      document.EditView.totalProductCount.value = max_row_count;    
  53  }
  54  
  55  function productPickList(currObj,module, row_no) {
  56      var trObj=currObj.parentNode.parentNode
  57      var rowId=row_no;//parseInt(trObj.id.substr(trObj.id.indexOf("w")+1,trObj.id.length))
  58  
  59      popuptype = 'inventory_prod';
  60      if(module == 'PurchaseOrder')
  61          popuptype = 'inventory_prod_po';
  62  
  63      window.open("index.php?module=Products&action=Popup&html=Popup_picker&form=HelpDeskEditView&popuptype="+popuptype+"&curr_row="+rowId,"productWin","width=640,height=565,resizable=0,scrollbars=0,status=1,top=150,left=200");
  64  }
  65  
  66  function priceBookPickList(currObj, row_no) {
  67      var trObj=currObj.parentNode.parentNode
  68      var rowId=row_no;//parseInt(trObj.id.substr(trObj.id.indexOf("w")+1,trObj.id.length))
  69      window.open("index.php?module=PriceBooks&action=Popup&html=Popup_picker&form=EditView&popuptype=inventory_pb&fldname=listPrice"+rowId+"&productid="+getObj("hdnProductId"+rowId).value,"priceBookWin","width=640,height=565,resizable=0,scrollbars=0,top=150,left=200");
  70  }
  71  
  72  
  73  function getProdListBody() {
  74      if (browser_ie) {
  75          var prodListBody=getObj("productList").children[0].children[0]
  76      } else if (browser_nn4 || browser_nn6) {
  77          if (getObj("productList").childNodes.item(0).tagName=="TABLE") {
  78              var prodListBody=getObj("productList").childNodes.item(0).childNodes.item(0)
  79          } else {
  80              var prodListBody=getObj("productList").childNodes.item(1).childNodes.item(1)
  81          }
  82      }
  83      return prodListBody;
  84  }
  85  
  86  
  87  function deleteRow(module,i)
  88  {
  89      rowCnt--;
  90      var tableName = document.getElementById('proTab');
  91      var prev = tableName.rows.length;
  92  //    document.getElementById('proTab').deleteRow(i);
  93      document.getElementById("row"+i).style.display = 'none';
  94      document.getElementById("hdnProductId"+i).value = "";
  95      //document.getElementById("productName"+i).value = "";
  96      document.getElementById('deleted'+i).value = 1;
  97      calcTotal()
  98  }
  99  /*  End */
 100  
 101  
 102  
 103  function calcTotal() {
 104  
 105      var max_row_count = document.getElementById('proTab').rows.length;
 106      max_row_count = eval(max_row_count)-2;//Because the table has two header rows. so we will reduce two from row length
 107      var netprice = 0.00;
 108      for(var i=1;i<=max_row_count;i++)
 109      {
 110          rowId = i;
 111          
 112          if(document.getElementById('deleted'+rowId).value == 0)
 113          {
 114              
 115              var total=eval(getObj("qty"+rowId).value*getObj("listPrice"+rowId).value);
 116              getObj("productTotal"+rowId).innerHTML=roundValue(total.toString())
 117  
 118              var totalAfterDiscount = eval(total-document.getElementById("discountTotal"+rowId).innerHTML);
 119              getObj("totalAfterDiscount"+rowId).innerHTML=roundValue(totalAfterDiscount.toString())
 120  
 121              
 122              var tax_type = document.getElementById("taxtype").value;
 123              //if the tax type is individual then add the tax with net price
 124              if(tax_type == 'individual')
 125                  netprice = totalAfterDiscount+eval(document.getElementById("taxTotal"+rowId).innerHTML);
 126              else
 127                  netprice = totalAfterDiscount;
 128              
 129              getObj("netPrice"+rowId).innerHTML=roundValue(netprice.toString())
 130  
 131          }
 132      }
 133      calcGrandTotal()
 134  }
 135  
 136  function calcGrandTotal() {
 137      var netTotal = 0.0, grandTotal = 0.0;
 138      var discountTotal_final = 0.0, finalTax = 0.0, sh_amount = 0.0, sh_tax = 0.0, adjustment = 0.0;
 139  
 140      var taxtype = document.getElementById("taxtype").value;
 141  
 142      var max_row_count = document.getElementById('proTab').rows.length;
 143      max_row_count = eval(max_row_count)-2;//Because the table has two header rows. so we will reduce two from row length
 144  
 145      for (var i=1;i<=max_row_count;i++) 
 146      {
 147          if(document.getElementById('deleted'+i).value == 0)
 148          {
 149              
 150              if (document.getElementById("netPrice"+i).innerHTML=="") 
 151                  document.getElementById("netPrice"+i).innerHTML = 0.0
 152              if (!isNaN(document.getElementById("netPrice"+i).innerHTML))
 153                  netTotal += parseFloat(document.getElementById("netPrice"+i).innerHTML)
 154          }
 155      }
 156  //    alert(netTotal);
 157      document.getElementById("netTotal").innerHTML = netTotal;
 158      document.getElementById("subtotal").value = netTotal;
 159  
 160      //Tax and Adjustment values will be taken when they are valid integer or decimal values
 161      //if(/^-?(0|[1-9]{1}\d{0,})(\.(\d{1}\d{0,}))?$/.test(document.getElementById("txtTax").value))
 162      //    txtTaxVal = parseFloat(getObj("txtTax").value);    
 163      //if(/^-?(0|[1-9]{1}\d{0,})(\.(\d{1}\d{0,}))?$/.test(document.getElementById("txtAdjustment").value))
 164      //    txtAdjVal = parseFloat(getObj("txtAdjustment").value);
 165  
 166      discountTotal_final = document.getElementById("discountTotal_final").innerHTML
 167  
 168      //get the final tax based on the group or individual tax selection
 169      var taxtype = document.getElementById("taxtype").value;
 170      if(taxtype == 'group')
 171          finalTax = document.getElementById("tax_final").innerHTML
 172  
 173      sh_amount = getObj("shipping_handling_charge").value
 174      sh_tax = document.getElementById("shipping_handling_tax").innerHTML
 175  
 176      adjustment = getObj("adjustment").value
 177  
 178      //Add or substract the adjustment based on selection
 179      adj_type = document.getElementById("adjustmentType").value;
 180      if(adj_type == '+')
 181          grandTotal = eval(netTotal)-eval(discountTotal_final)+eval(finalTax)+eval(sh_amount)+eval(sh_tax)+eval(adjustment)
 182      else
 183          grandTotal = eval(netTotal)-eval(discountTotal_final)+eval(finalTax)+eval(sh_amount)+eval(sh_tax)-eval(adjustment)
 184  
 185      document.getElementById("grandTotal").innerHTML = roundValue(grandTotal.toString())
 186      document.getElementById("total").value = roundValue(grandTotal.toString())
 187  }
 188  
 189  //Method changed as per advice by jon http://forums.vtiger.com/viewtopic.php?t=4162
 190  function roundValue(val) {
 191     val = parseFloat(val);
 192     val = Math.round(val*100)/100;
 193     val = val.toString();
 194     
 195     if (val.indexOf(".")<0) {
 196        val+=".00"
 197     } else {
 198        var dec=val.substring(val.indexOf(".")+1,val.length)
 199        if (dec.length>2)
 200           val=val.substring(0,val.indexOf("."))+"."+dec.substring(0,2)
 201        else if (dec.length==1)
 202           val=val+"0"
 203     }
 204     
 205     return val;
 206  } 
 207  
 208  //This function is used to validate the Inventory modules 
 209  function validateInventory(module) 
 210  {
 211      if(!formValidate())
 212          return false
 213  
 214      //for products, vendors and pricebook modules we won't validate the product details. here return the control
 215      if(module == 'Products' || module == 'Vendors' || module == 'PriceBooks')
 216      {
 217          return true;
 218      }
 219  
 220      var max_row_count = document.getElementById('proTab').rows.length;
 221      max_row_count = eval(max_row_count)-2;//As the table has two header rows, we will reduce two from table row length
 222  
 223      if(!FindDuplicate())
 224          return false;
 225  
 226      if(max_row_count == 0)
 227      {
 228          alert('No product is selected. Select at least one Product');
 229          return false;
 230      }
 231  
 232      for (var i=1;i<=max_row_count;i++) 
 233      {
 234          //if the row is deleted then avoid validate that row values
 235          if(document.getElementById("deleted"+i).value == 1)
 236              continue;
 237  
 238          if (!emptyCheck("productName"+i,"Product","text")) return false
 239          if (!emptyCheck("qty"+i,"Qty","text")) return false
 240          if (!numValidate("qty"+i,"Qty","any")) return false
 241          if (!numConstComp("qty"+i,"Qty","GE","1")) return false
 242          if (!emptyCheck("listPrice"+i,"List Price","text")) return false
 243          if (!numValidate("listPrice"+i,"List Price","any")) return false           
 244      }
 245  
 246      //Product - Discount validation - not allow negative values
 247      if(!validateProductDiscounts())
 248          return false;
 249  
 250      //Final Discount validation - not allow negative values
 251      discount_checks = document.getElementsByName("discount_final");
 252  
 253      //Percentage selected, so validate the percentage
 254      if(discount_checks[1].checked == true)
 255      {
 256          temp = /^(0|[1-9]{1}\d{0,})(\.(\d{1}\d{0,}))?$/.test(document.getElementById("discount_percentage_final").value);
 257          if(!temp)
 258          {
 259              alert("Enter valid Final Discount Percentage");
 260              return false;
 261          }
 262      }
 263      if(discount_checks[2].checked == true)
 264      {
 265          temp = /^(0|[1-9]{1}\d{0,})(\.(\d{1}\d{0,}))?$/.test(document.getElementById("discount_amount_final").value);
 266          if(!temp)
 267          {
 268              alert("Enter valid Final Discount Amount");
 269              return false;
 270          }
 271      }
 272  
 273      //Shipping & Handling validation - not allow negative values
 274      temp = /^(0|[1-9]{1}\d{0,})(\.(\d{1}\d{0,}))?$/.test(document.getElementById("shipping_handling_charge").value);
 275      if(!temp)
 276      {
 277          alert("Enter a valid Shipping & Handling charge");
 278          return false;
 279      }
 280  
 281      //Adjustment validation - allow negative values
 282      temp = /^-?(0|[1-9]{1}\d{0,})(\.(\d{1}\d{0,}))?$/.test(document.getElementById("adjustment").value)
 283      if(!temp)
 284      {
 285          alert("Enter a valid Adjustment");
 286          return false;
 287      }
 288  
 289      return true    
 290  }
 291  
 292  function FindDuplicate()
 293  {
 294      var max_row_count = document.getElementById('proTab').rows.length;
 295          max_row_count = eval(max_row_count)-2;//As the table has two header rows, we will reduce two from row length
 296  
 297      var product_id = new Array(max_row_count-1);
 298      var product_name = new Array(max_row_count-1);
 299      product_id[1] = getObj("hdnProductId"+1).value;
 300      product_name[1] = getObj("productName"+1).value;
 301      for (var i=1;i<=max_row_count;i++)
 302      {
 303          for(var j=i+1;j<=max_row_count;j++)
 304          {
 305              if(i == 1)
 306              {
 307                  product_id[j] = getObj("hdnProductId"+j).value;
 308              }
 309              if(product_id[i] == product_id[j] && product_id[i] != '')
 310              {
 311                  alert("You have selected < "+getObj("productName"+j).value+" > more than once in line items  "+i+" & "+j+".\n It is advisable to select the product just once but change the Qty. Thank You");
 312                  //return false;
 313              }
 314          }
 315      }
 316          return true;
 317  }
 318  
 319  function fnshow_Hide(Lay){
 320      var tagName = document.getElementById(Lay);
 321         if(tagName.style.display == 'none')
 322             tagName.style.display = 'block';
 323      else
 324          tagName.style.display = 'none';
 325  }
 326  
 327  function ValidateTax(txtObj)
 328  {
 329      temp= /^\d+(\.\d\d*)*$/.test(document.getElementById(txtObj).value);
 330      if(temp == false)
 331          alert("Please enter Valid TAX value");
 332  }
 333  
 334  function loadTaxes_Ajax(curr_row)
 335  {
 336      //Retrieve all the tax values for the currently selected product
 337      new Ajax.Request(
 338          'index.php',
 339          {queue: {position: 'end', scope: 'command'},
 340              method: 'post',
 341              postBody: 'module=Products&action=ProductsAjax&file=InventoryTaxAjax&productid='+document.getElementById("hdnProductId"+curr_row).value+'&curr_row='+curr_row+'&productTotal='+document.getElementById('totalAfterDiscount'+curr_row).innerHTML,
 342              onComplete: function(response)
 343                  {
 344                      $("tax_div"+curr_row).innerHTML=response.responseText;
 345                      document.getElementById("taxTotal"+curr_row).innerHTML = getObj('hdnTaxTotal'+curr_row).value;
 346                  }
 347          }
 348      );
 349  
 350  }
 351  
 352  
 353  function fnAddTaxConfigRow(sh){
 354  
 355      var table_id = 'add_tax';
 356      var td_id = 'td_add_tax';
 357      var label_name = 'addTaxLabel';
 358      var label_val = 'addTaxValue';
 359      var add_tax_flag = 'add_tax_type';
 360  
 361      if(sh != '' && sh == 'sh')
 362      {
 363          table_id = 'sh_add_tax';
 364          td_id = 'td_sh_add_tax';
 365          label_name = 'sh_addTaxLabel';
 366          label_val = 'sh_addTaxValue';
 367          add_tax_flag = 'sh_add_tax_type';
 368      }
 369      var tableName = document.getElementById(table_id);
 370      var prev = tableName.rows.length;
 371          var count = rowCnt;
 372  
 373          var row = tableName.insertRow(0);
 374  
 375      var colone = row.insertCell(0);
 376      var coltwo = row.insertCell(1);
 377  
 378      colone.className = "cellLabel small";
 379      coltwo.className = "cellText small";
 380  
 381      colone.innerHTML="<input type='text' id='"+label_name+"' name='"+label_name+"' value='Tax Name' class='txtBox' onclick=\"this.form."+label_name+".value=''\";/>";
 382      coltwo.innerHTML="<input type='text' id='"+label_val+"' name='"+label_val+"' value='Tax Value' class='txtBox' onclick=\"this.form."+label_val+".value=''\";/>";
 383  
 384      document.getElementById(td_id).innerHTML="<input type='submit' name='Save' value='Save' class='crmButton small save' onclick=\"this.form.action.value='TaxConfig'; this.form."+add_tax_flag+".value='true'; this.form.parenttab.value='Settings'; return validateNewTaxType('"+label_name+"','"+label_val+"');\">&nbsp;<input type='submit' name='Cancel' value='Cancel' class='crmButton small cancel' onclick=\"this.form.action.value='TaxConfig'; this.form.module.value='Settings'; this.form."+add_tax_flag+".value='false'; this.form.parenttab.value='Settings';\">";
 385  }
 386  
 387  function validateNewTaxType(fieldname, fieldvalue)
 388  {
 389      if(trim(document.getElementById(fieldname).value)== '')
 390      {
 391          alert("Enter valid Tax Name");
 392          return false;
 393      }
 394      if(trim(document.getElementById(fieldvalue).value)== '')
 395      {
 396          alert("Enter Correct Tax Value");
 397          return false;
 398      }
 399      else
 400      {
 401          var temp = /^(0|[1-9]{1}\d{0,})(\.(\d{1}\d{0,}))?$/.test(document.getElementById(fieldvalue).value);
 402          if(!temp)
 403          {
 404              alert("Please enter positive value");
 405              return false;
 406          }
 407      }
 408  
 409      return true;
 410  }
 411  
 412  function validateTaxes(countname)
 413  {
 414      taxcount = eval(document.getElementById(countname).value)+1;
 415  
 416      if(countname == 'tax_count')
 417      {
 418          taxprefix = 'tax';
 419          taxLabelPrefix = 'taxlabel_tax';
 420      }
 421      else
 422      {
 423          taxprefix = 'shtax';
 424          taxLabelPrefix = 'taxlabel_shtax';
 425      }
 426  
 427      for(var i=1;i<=taxcount;i++)
 428      {
 429          taxval = document.getElementById(taxprefix+i).value;
 430          taxLabelVal = document.getElementById(taxLabelPrefix+i).value;
 431          document.getElementById(taxLabelPrefix+i).value = taxLabelVal.replace(/^\s*|\s*$/g,'').replace(/\s+/g,'');
 432  
 433          if(document.getElementById(taxLabelPrefix+i).value.length == 0)
 434          {
 435              alert("The tax label name should not be empty");
 436              return false
 437          } 
 438  
 439          //Tax value - numeric validation    
 440          var temp = /^(0|[1-9]{1}\d{0,})(\.(\d{1}\d{0,}))?$/.test(taxval);
 441          if(!temp)
 442          {
 443              alert("'"+taxval+"' is not a valid entry. Please enter correct value");
 444              return false;
 445          }
 446      }
 447      return true;
 448  }
 449  
 450  
 451  
 452  //Function used to add a new product row in PO, SO, Quotes and Invoice
 453  function fnAddProductRow(module,image_path){
 454      rowCnt++;
 455  
 456      var tableName = document.getElementById('proTab');
 457      var prev = tableName.rows.length;
 458          var count = eval(prev)-1;//As the table has two headers, we should reduce the count
 459          var row = tableName.insertRow(prev);
 460          row.id = "row"+count;
 461          row.style.verticalAlign = "top";
 462  
 463      
 464      var colone = row.insertCell(0);
 465      var coltwo = row.insertCell(1);
 466      if(module == "PurchaseOrder"){
 467          var colfour = row.insertCell(2);
 468          var colfive = row.insertCell(3);
 469          var colsix = row.insertCell(4);
 470          var colseven = row.insertCell(5);
 471      }
 472      else{
 473          var colthree = row.insertCell(2);
 474          var colfour = row.insertCell(3);
 475          var colfive = row.insertCell(4);
 476          var colsix = row.insertCell(5);
 477          var colseven = row.insertCell(6);
 478      }
 479      
 480      //Delete link
 481      colone.className = "crmTableRow small";
 482      colone.innerHTML='<img src="'+image_path+'delete.gif" border="0" onclick="deleteRow(\''+module+'\','+count+')"><input id="deleted'+count+'" name="deleted'+count+'" type="hidden" value="0">';
 483  
 484      //Product Name with Popup image to select product
 485      coltwo.className = "crmTableRow small"
 486      coltwo.innerHTML= '<table border="0" cellpadding="1" cellspacing="0" width="100%"><tr><td class="small"><input id="productName'+count+'" name="productName'+count+'" class="small" style="width: 70%;" value="" readonly="readonly" type="text"><input id="hdnProductId'+count+'" name="hdnProductId'+count+'" value="" type="hidden"><img src="'+image_path+'search.gif" style="cursor: pointer;" onclick="productPickList(this,\''+module+'\','+count+')" align="absmiddle"></td></tr><tr><td class="small" id="setComment'+count+'"><textarea id="comment1" name="comment'+count+'" class=small style="width:70%;height:40px"></textarea><br>[<a href="javascript:;" onclick="getObj(\'comment'+count+'\').value=\'\'";>Clear Comment</a>]</td></tr></tbody></table>';    
 487      
 488      //Quantity In Stock - only for SO, Quotes and Invoice
 489      if(module != "PurchaseOrder"){
 490      colthree.className = "crmTableRow small"
 491      colthree.innerHTML='<span id="qtyInStock'+count+'">&nbsp;</span>';
 492      }
 493      
 494      //Quantiry
 495      colfour.className = "crmTableRow small"
 496      colfour.innerHTML='<input id="qty'+count+'" name="qty'+count+'" type="text" class="small " style="width:50px" onfocus="this.className=\'detailedViewTextBoxOn\'" onBlur="FindDuplicate(); settotalnoofrows(); calcTotal(); loadTaxes_Ajax('+count+');" value=""/>';
 497      
 498      //List Price with Discount, Total after Discount and Tax labels
 499      colfive.className = "crmTableRow small"
 500      colfive.innerHTML='<table width="100%" cellpadding="0" cellspacing="0"><tr><td align="right"><input id="listPrice'+count+'" name="listPrice'+count+'" value="0.00" type="text" class="small " style="width:70px" onBlur="calcTotal(); callTaxCalc('+count+');"/>&nbsp;<img src="'+image_path+'pricebook.gif" onclick="priceBookPickList(this,'+count+')"></td></tr><tr><td align="right" style="padding:5px;" nowrap>        (-)&nbsp;<b><a href="javascript:doNothing();" onClick="displayCoords(event,\'discount_div'+count+'\',\'discount\','+count+')" >Discount</a> : </b><div class=\"discountUI\" id=\"discount_div'+count+'"><input type="hidden" id="discount_type'+count+'" name="discount_type'+count+'" value=""><table width="100%" border="0" cellpadding="5" cellspacing="0" class="small"><tr><td id="discount_div_title'+count+'" nowrap align="left" ></td><td align="right"><img src="'+image_path+'close.gif" border="0" onClick="fnHidePopDiv(\'discount_div'+count+'\')" style="cursor:pointer;"></td></tr><tr><td align="left" class="lineOnTop"><input type="radio" name="discount'+count+'" checked onclick="setDiscount(this,'+count+'); callTaxCalc('+count+');">&nbsp; Zero Discount</td><td class="lineOnTop">&nbsp;</td></tr><tr><td align="left"><input type="radio" name="discount'+count+'" onclick="setDiscount(this,'+count+'); callTaxCalc('+count+');">&nbsp; % of Price </td><td align="right"><input type="text" class="small" size="2" id="discount_percentage'+count+'" name="discount_percentage'+count+'" value="0" style="visibility:hidden" onBlur="setDiscount(this,'+count+'); callTaxCalc('+count+');">&nbsp;%</td></tr><tr><td align="left" nowrap><input type="radio" name="discount'+count+'" onclick="setDiscount(this,'+count+'); callTaxCalc('+count+');">&nbsp; Direct Price Redunction</td><td align="right"><input type="text" id="discount_amount'+count+'" name="discount_amount'+count+'" size="5" value="0" style="visibility:hidden" onBlur="setDiscount(this,'+count+'); callTaxCalc('+count+');"></td></tr></table></div></td></tr><tr> <td align="right" style="padding:5px;" nowrap><b>Total After Discount :</b></td></tr><tr id="individual_tax_row'+count+'" class="TaxShow"><td align="right" style="padding:5px;" nowrap>(+)&nbsp;<b><a href="javascript:doNothing();" onClick="displayCoords(event,\'tax_div'+count+'\',\'tax\','+count+')" >Tax </a> : </b><div class="discountUI" id="tax_div'+count+'"></div></td></tr></table> ';
 501  
 502      //Total and Discount, Total after Discount and Tax details
 503      colsix.className = "crmTableRow small"
 504      colsix.innerHTML = '<table width="100%" cellpadding="5" cellspacing="0"><tr><td id="productTotal'+count+'" align="right">&nbsp;</td></tr><tr><td id="discountTotal'+count+'" align="right">0.00</td></tr><tr><td id="totalAfterDiscount'+count+'" align="right">&nbsp;</td></tr><tr><td id="taxTotal'+count+'" align="right">0.00</td></tr></table>';
 505  
 506      //Net Price
 507      colseven.className = "crmTableRow small";
 508      colseven.align = "right";
 509      colseven.style.verticalAlign = "bottom";
 510      colseven.innerHTML = '<span id="netPrice'+count+'"><b>&nbsp;</b></span>';
 511      
 512      //This is to show or hide the individual or group tax
 513      decideTaxDiv();
 514  
 515      calcTotal();
 516  }
 517  
 518  function decideTaxDiv()
 519  {
 520      var taxtype = document.getElementById("taxtype").value
 521  
 522      calcTotal();
 523  
 524      if(taxtype == 'group')
 525      {
 526          //if group tax selected then we have to hide the individual taxes and also calculate the group tax
 527          hideIndividualTaxes()
 528          calcGroupTax();
 529      }
 530      else if(taxtype == 'individual')
 531          hideGroupTax()
 532  
 533  }
 534  
 535  function hideIndividualTaxes()
 536  {
 537      var max_row_count = document.getElementById('proTab').rows.length;
 538      max_row_count = eval(max_row_count)-2;//Because the table has two header rows. so we will reduce two from row length
 539  
 540      for(var i=1;i<=max_row_count;i++)
 541      {
 542          document.getElementById("individual_tax_row"+i).className = 'TaxHide';
 543          document.getElementById("taxTotal"+i).style.display = 'none';
 544      }
 545      document.getElementById("group_tax_row").className = 'TaxShow';
 546  }
 547  
 548  function hideGroupTax()
 549  {
 550      var max_row_count = document.getElementById('proTab').rows.length;
 551      max_row_count = eval(max_row_count)-2;//Because the table has two header rows. so we will reduce two from table row length
 552  
 553      for(var i=1;i<=max_row_count;i++)
 554      {
 555          document.getElementById("individual_tax_row"+i).className = 'TaxShow';
 556          document.getElementById("taxTotal"+i).style.display = 'block';
 557      }
 558      document.getElementById("group_tax_row").className = 'TaxHide';
 559  }
 560  
 561  function setDiscount(currObj,curr_row)
 562  {
 563      var discount_checks = new Array();
 564  
 565      discount_checks = document.getElementsByName("discount"+curr_row);
 566  
 567      if(discount_checks[0].checked == true)
 568      {
 569          document.getElementById("discount_type"+curr_row).value = 'zero';
 570          document.getElementById("discount_percentage"+curr_row).style.visibility = 'hidden';
 571          document.getElementById("discount_amount"+curr_row).style.visibility = 'hidden';
 572          document.getElementById("discountTotal"+curr_row).innerHTML = 0.00;
 573      }
 574      if(discount_checks[1].checked == true)
 575      {
 576          document.getElementById("discount_type"+curr_row).value = 'percentage';
 577          document.getElementById("discount_percentage"+curr_row).style.visibility = 'visible';
 578          document.getElementById("discount_amount"+curr_row).style.visibility = 'hidden';
 579  
 580          var discount_amount = 0.00;
 581          //This is to calculate the final discount
 582          if(curr_row == '_final')
 583          {
 584              discount_amount = eval(document.getElementById("netTotal").innerHTML)*eval(document.getElementById("discount_percentage"+curr_row).value)/eval(100);
 585          }
 586          else//This is to calculate the product discount
 587          {
 588              discount_amount = eval(document.getElementById("productTotal"+curr_row).innerHTML)*eval(document.getElementById("discount_percentage"+curr_row).value)/eval(100);
 589          }
 590  
 591          document.getElementById("discountTotal"+curr_row).innerHTML = discount_amount;
 592      }
 593      if(discount_checks[2].checked == true)
 594      {
 595          document.getElementById("discount_type"+curr_row).value = 'amount';
 596          document.getElementById("discount_percentage"+curr_row).style.visibility = 'hidden';
 597          document.getElementById("discount_amount"+curr_row).style.visibility = 'visible';
 598          document.getElementById("discountTotal"+curr_row).innerHTML = document.getElementById("discount_amount"+curr_row).value;
 599      }
 600  
 601      calcTotal();
 602  }
 603  
 604  //This function is added to call the tax calculation function
 605  function callTaxCalc(curr_row)
 606  {
 607      //when we change discount or list price, we have to calculate the taxes again before calculate the total
 608      tax_count = eval(document.getElementById('tax_table'+curr_row).rows.length-1);//subtract the title tr length
 609  
 610      for(var i=0, j=i+1;i<tax_count;i++,j++)
 611      {
 612          var tax_hidden_name = "hidden_tax"+j+"_percentage"+curr_row;
 613          var tax_name = document.getElementById(tax_hidden_name).value;
 614          calcCurrentTax(tax_name,curr_row,i);
 615      }
 616  }
 617  
 618  function calcCurrentTax(tax_name, curr_row, tax_row)
 619  {
 620      //we should calculate the tax amount only for the total After Discount
 621      var product_total = getObj("totalAfterDiscount"+curr_row).innerHTML
 622      //var product_total = document.getElementById("productTotal"+curr_row).innerHTML
 623      var new_tax_percent = document.getElementById(tax_name).value;
 624  
 625      var new_amount_lbl = document.getElementsByName("popup_tax_row"+curr_row);
 626  
 627      //calculate the new tax amount
 628      new_tax_amount = eval(product_total)*eval(new_tax_percent)/eval(100);
 629  
 630      //assign the new tax amount in the corresponding text box
 631      new_amount_lbl[tax_row].value = new_tax_amount;
 632  
 633      var tax_total = 0.00;
 634      for(var i=0;i<new_amount_lbl.length;i++)
 635      {
 636          tax_total = tax_total + eval(new_amount_lbl[i].value);
 637      }
 638      document.getElementById("taxTotal"+curr_row).innerHTML = tax_total;
 639  
 640      calcTotal();
 641  }
 642  
 643  function calcGroupTax()
 644  {
 645      var group_tax_count = document.getElementById("group_tax_count").value;
 646      var net_total_after_discount = eval(document.getElementById("netTotal").innerHTML)-eval(document.getElementById("discountTotal_final").innerHTML);
 647      var group_tax_total = 0.00, tax_amount=0.00;
 648  
 649      for(var i=1;i<=group_tax_count;i++)
 650      {
 651          tax_amount = eval(net_total_after_discount)*eval(document.getElementById("group_tax_percentage"+i).value)/eval(100);
 652          document.getElementById("group_tax_amount"+i).value = tax_amount;
 653          group_tax_total = eval(group_tax_total) + eval(tax_amount);
 654      }
 655  
 656      document.getElementById("tax_final").innerHTML = group_tax_total;
 657  
 658      calcTotal();
 659  }
 660  
 661  function calcSHTax()
 662  {
 663      var sh_tax_count = document.getElementById("sh_tax_count").value;
 664      var sh_charge = document.getElementById("shipping_handling_charge").value;
 665      var sh_tax_total = 0.00, tax_amount=0.00;
 666  
 667      for(var i=1;i<=sh_tax_count;i++)
 668      {
 669          tax_amount = eval(sh_charge)*eval(document.getElementById("sh_tax_percentage"+i).value)/eval(100);
 670          document.getElementById("sh_tax_amount"+i).value = tax_amount;
 671          sh_tax_total = eval(sh_tax_total) + eval(tax_amount);
 672      }
 673  
 674      document.getElementById("shipping_handling_tax").innerHTML = sh_tax_total;
 675  
 676      calcTotal();
 677  }
 678  
 679  function validateProductDiscounts()
 680  {
 681      var max_row_count = document.getElementById('proTab').rows.length;
 682      max_row_count = eval(max_row_count)-2;//As the table has two header rows, we will reduce two from table row length
 683  
 684      for(var i=1;i<=max_row_count;i++)
 685      {
 686          //if the row is deleted then avoid validate that row values
 687          if(document.getElementById("deleted"+i).value == 1)
 688              continue;
 689  
 690          discount_checks = document.getElementsByName("discount"+i);
 691  
 692          //Percentage selected, so validate the percentage
 693          if(discount_checks[1].checked == true)
 694          {
 695              temp = /^(0|[1-9]{1}\d{0,})(\.(\d{1}\d{0,}))?$/.test(document.getElementById("discount_percentage"+i).value);
 696              if(!temp)
 697              {
 698                  alert("Enter a valid Discount percentage");
 699                  return false;
 700              }
 701          }
 702          if(discount_checks[2].checked == true)
 703          {
 704              temp = /^(0|[1-9]{1}\d{0,})(\.(\d{1}\d{0,}))?$/.test(document.getElementById("discount_amount"+i).value);
 705              if(!temp)
 706              {
 707                  alert("Enter a valid Discount Amount");
 708                  return false;
 709              }
 710          }
 711      }
 712      return true;
 713  }
 714  


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7