[ Index ]
 

Code source de vtiger CRM 5.0.2

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

title

Body

[fermer]

/modules/Settings/ -> TaxConfig.php (source)

   1  <?php
   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  
  12  
  13  require_once ('Smarty_setup.php');
  14  global $mod_strings;
  15  global $app_strings;
  16  global $adb;
  17  global $log;
  18  
  19  $smarty = new vtigerCRM_Smarty;
  20  global $theme;
  21  $theme_path="themes/".$theme."/";
  22  $image_path=$theme_path."images/";
  23  require_once ($theme_path.'layout_utils.php');
  24  
  25  $tax_details = getAllTaxes();
  26  $sh_tax_details = getAllTaxes('all','sh');
  27  
  28  
  29  //To save the edited value
  30  if($_REQUEST['save_tax'] == 'true')
  31  {
  32      for($i=0;$i<count($tax_details);$i++)
  33      {
  34               $new_labels[$tax_details[$i]['taxid']] = $_REQUEST[$tax_details[$i]['taxlabel']];
  35          $new_percentages[$tax_details[$i]['taxid']] = $_REQUEST[$tax_details[$i]['taxname']];
  36      }
  37      updateTaxPercentages($new_percentages);
  38      updateTaxLabels($new_labels);
  39      $getlist = true;
  40  }
  41  elseif($_REQUEST['sh_save_tax'] == 'true')
  42  {
  43   
  44      for($i=0;$i<count($sh_tax_details);$i++)
  45      {
  46        $new_labels[$sh_tax_details[$i]['taxid']] = $_REQUEST[$sh_tax_details[$i]['taxlabel']];
  47          $new_percentages[$sh_tax_details[$i]['taxid']] = $_REQUEST[$sh_tax_details[$i]['taxname']];
  48      }
  49      
  50      updateTaxPercentages($new_percentages,'sh');
  51      updateTaxLabels($new_labels,'sh');
  52      $getlist = true;
  53  }
  54  
  55  //To edit
  56  if($_REQUEST['edit_tax'] == 'true')
  57  {
  58      $smarty->assign("EDIT_MODE", 'true');
  59  }
  60  elseif($_REQUEST['sh_edit_tax'] == 'true')
  61  {
  62      $smarty->assign("SH_EDIT_MODE", 'true');
  63  }
  64  
  65  //To add tax
  66  if($_REQUEST['add_tax_type'] == 'true')
  67  {
  68      //Add the given tax name and value as a new tax type
  69      echo addTaxType($_REQUEST['addTaxLabel'],$_REQUEST['addTaxValue']);
  70      $getlist = true;
  71  }
  72  elseif($_REQUEST['sh_add_tax_type'] == 'true')
  73  {
  74      echo addTaxType($_REQUEST['sh_addTaxLabel'],$_REQUEST['sh_addTaxValue'],'sh');
  75      $getlist = true;
  76  }
  77  
  78  //To Disable ie., delete or enable
  79  if(($_REQUEST['disable'] == 'true' || $_REQUEST['enable'] == 'true') && $_REQUEST['taxname'] != '')
  80  {
  81      if($_REQUEST['disable'] == 'true')
  82          changeDeleted($_REQUEST['taxname'],1);
  83      else
  84          changeDeleted($_REQUEST['taxname'],0);
  85      $getlist = true;
  86  }
  87  elseif(($_REQUEST['sh_disable'] == 'true' || $_REQUEST['sh_enable'] == 'true') && $_REQUEST['sh_taxname'] != '')
  88  {
  89      if($_REQUEST['sh_disable'] == 'true')
  90          changeDeleted($_REQUEST['sh_taxname'],1,'sh');
  91      else
  92          changeDeleted($_REQUEST['sh_taxname'],0,'sh');
  93      $getlist = true;
  94  }
  95  
  96  //after done save or enable/disable or added new tax the list will be retrieved again from db
  97  if($getlist)
  98  {
  99      $tax_details = getAllTaxes();
 100      $sh_tax_details = getAllTaxes('all','sh');
 101  }
 102  
 103  $smarty->assign("TAX_COUNT", count($tax_details));
 104  $smarty->assign("SH_TAX_COUNT", count($sh_tax_details));
 105  
 106  if(count($tax_details) == 0)
 107      $smarty->assign("TAX_COUNT", 0);
 108  if(count($sh_tax_details) == 0)
 109      $smarty->assign("SH_TAX_COUNT", 0);
 110  
 111  $smarty->assign("TAX_VALUES", $tax_details);
 112  
 113  $smarty->assign("SH_TAX_VALUES", $sh_tax_details);
 114  
 115  $smarty->assign("MOD", return_module_language($current_language,'Settings'));
 116  $smarty->assign("IMAGE_PATH",$image_path);
 117  $smarty->assign("APP", $app_strings);
 118  $smarty->assign("MOD", $mod_strings);
 119  $smarty->display("Settings/TaxConfig.tpl");
 120  
 121  
 122  /**    Function to update the list of Tax percentages for the passed tax types
 123   *    @param array $new_percentages - array of tax types and the values like [taxid]=new value ie., [1]=3.56, [2]=11.45
 124   *      @param string $sh - sh or empty, if sh passed then update will be done in shipping and handling related table
 125   *      @return void
 126   */
 127  function updateTaxPercentages($new_percentages, $sh='')
 128  {
 129      global $adb, $log;
 130      $log->debug("Entering into the function updateTaxPercentages");
 131  
 132      foreach($new_percentages as $taxid => $new_val)
 133      {
 134          if($new_val != '')
 135          {
 136              if($sh != '' && $sh == 'sh')
 137                  $query = "update vtiger_shippingtaxinfo set percentage=\"$new_val\" where taxid=\"$taxid\"";
 138              else
 139                  $query = "update vtiger_inventorytaxinfo set percentage = \"$new_val\" where taxid=\"$taxid\"";
 140              $adb->query($query);
 141          }
 142      }
 143  
 144      $log->debug("Exiting from the function updateTaxPercentages");
 145  }
 146  
 147  /**    Function to update the list of Tax Labels for the taxes
 148   *    @param array $new_labels - array of tax types and the values like [taxid]=new label ie., [1]=aa, [2]=bb
 149   *      @param string $sh - sh or empty, if sh passed then update will be done in shipping and handling related table
 150   *      @return void
 151   */
 152  function updateTaxLabels($new_labels, $sh='')
 153  {
 154      global $adb, $log;
 155      $log->debug("Entering into the function updateTaxPercentages");
 156  
 157      foreach($new_labels as $taxid => $new_val)
 158      {
 159          if($new_val != '')
 160          {
 161              if($sh != '' && $sh == 'sh')
 162                  $query = "update vtiger_shippingtaxinfo set taxlabel= \"$new_val\" where taxid=\"$taxid\"";
 163              else
 164                  $query = "update vtiger_inventorytaxinfo set taxlabel = \"$new_val\" where taxid=\"$taxid\"";
 165              $adb->query($query);
 166          }
 167      }
 168  
 169      $log->debug("Exiting from the function updateTaxPercentages");
 170  }
 171  /**    Function used to add the tax type which will do database alterations
 172   *    @param string $taxlabel - tax label name to be added
 173   *    @param string $taxvalue - tax value to be added
 174   *      @param string $sh - sh or empty , if sh passed then the tax will be added in shipping and handling related table
 175   *      @return void
 176   */
 177  function addTaxType($taxlabel, $taxvalue, $sh='')
 178  {
 179      global $adb, $log;
 180      $log->debug("Entering into function addTaxType($taxlabel, $taxvalue, $sh)");
 181  
 182      //First we will check whether the tax is already available or not
 183      if($sh != '' && $sh == 'sh')
 184          $check_query = "select taxlabel from vtiger_shippingtaxinfo where taxlabel='".addslashes($taxlabel)."'";
 185      else
 186          $check_query = "select taxlabel from vtiger_inventorytaxinfo where taxlabel='".addslashes($taxlabel)."'";
 187      $check_res = $adb->query($check_query);
 188  
 189      if($adb->num_rows($check_res) > 0)
 190          return "<font color='red'>This tax is already available</font>";
 191  
 192      //if the tax is not available then add this tax.
 193      //Add this tax as a column in related table    
 194      if($sh != '' && $sh == 'sh')
 195      {
 196          $taxid = $adb->getUniqueID("vtiger_shippingtaxinfo");
 197          $taxname = "shtax".$taxid;
 198          $query = "alter table vtiger_inventoryshippingrel add column $taxname decimal(7,3) default NULL";
 199      }
 200      else
 201      {
 202          $taxid = $adb->getUniqueID("vtiger_inventorytaxinfo");
 203          $taxname = "tax".$taxid;
 204          $query = "alter table vtiger_inventoryproductrel add column $taxname decimal(7,3) default NULL";
 205      }
 206      $res = $adb->query($query);
 207  
 208      //if the tax is added as a column then we should add this tax in the list of taxes
 209      if($res)
 210      {
 211          if($sh != '' && $sh == 'sh')
 212              $query1 = "insert into vtiger_shippingtaxinfo values($taxid,'".$taxname."','".$taxlabel."','".$taxvalue."',0)";
 213          else
 214              $query1 = "insert into vtiger_inventorytaxinfo values($taxid,'".$taxname."','".$taxlabel."','".$taxvalue."',0)";
 215  
 216          $res1 = $adb->query($query1);
 217      }
 218  
 219      $log->debug("Exit from function addTaxType($taxlabel, $taxvalue)");
 220      if($res1)
 221          return '';
 222      else
 223          return "There may be some problem in adding the Tax type. Please try again";
 224  }
 225  
 226  /**    Function used to Enable or Disable the tax type 
 227   *    @param string $taxname - taxname to enable or disble
 228   *    @param int $deleted - 0 or 1 where 0 to enable and 1 to disable
 229   *    @param string $sh - sh or empty, if sh passed then the enable/disable will be done in shipping and handling tax table ie.,vtiger_shippingtaxinfo  else this enable/disable will be done in Product tax table ie., in vtiger_inventorytaxinfo
 230   *    @return void
 231   */
 232  function changeDeleted($taxname, $deleted, $sh='')
 233  {
 234      global $log, $adb;
 235      $log->debug("Entering into function changeDeleted($taxname, $deleted, $sh)");
 236  
 237      if($sh == 'sh')
 238          $adb->query("update vtiger_shippingtaxinfo set deleted=$deleted where taxname=\"$taxname\"");
 239      else
 240          $adb->query("update vtiger_inventorytaxinfo set deleted=$deleted where taxname=\"$taxname\"");
 241      $log->debug("Exit from function changeDeleted($taxname, $deleted, $sh)");
 242  }
 243  
 244  ?>


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