diff --git a/html/ajax_misc.php b/html/ajax_misc.php
index 13e11d4a7..70f4f9387 100644
--- a/html/ajax_misc.php
+++ b/html/ajax_misc.php
@@ -419,7 +419,29 @@ EOF;
break;
case 'dsp_tva':
$cn = Dossier::connect();
- $Res = $cn->exec_sql("select * from tva_rate order by tva_rate desc");
+ // Filter the VAT
+ $filter=$http->get("filter","string","none");
+ if ( $filter == 'sale') {
+ $Res = $cn->exec_sql("select *
+ from v_tva_rate
+ where
+ tva_sale <> '#'
+ order by tva_rate desc");
+
+ } elseif ($filter == "purchase") {
+
+ $Res = $cn->exec_sql("select *
+ from
+ v_tva_rate
+ where
+ tva_purchase <> '#'
+ order by tva_rate desc");
+ }else {
+
+ $Res = $cn->exec_sql("select * from v_tva_rate
+ where
+ order by tva_rate desc");
+ }
$Max = Database::num_row($Res);
$r = "";
$r.=HtmlInput::title_box(_('Choisissez la TVA'),'tva_select',"close","","y");
diff --git a/html/js/scripts.js b/html/js/scripts.js
index 6c8d1d334..46ddea91e 100644
--- a/html/js/scripts.js
+++ b/html/js/scripts.js
@@ -496,6 +496,8 @@ function popup_select_tva(obj)
queryString += '&code=' + obj.jcode;
if (obj.compute)
queryString += '&compute=' + obj.compute;
+ if (obj.filter)
+ queryString += '&filter=' + obj.filter;
var action = new Ajax.Request(
"ajax_misc.php",
diff --git a/include/class/acc_ledger_purchase.class.php b/include/class/acc_ledger_purchase.class.php
index c931a09da..7dfc93803 100644
--- a/include/class/acc_ledger_purchase.class.php
+++ b/include/class/acc_ledger_purchase.class.php
@@ -1262,6 +1262,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
$Tva->js="onblur=\"format_number(this);onChange=clean_tva($i);compute_ledger($i)\"";
$Tva->in_table=true;
$Tva->set_attribute('compute',$i);
+ $Tva->set_filter("purchase");
$Tva->value=$march_tva_id;
$array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
diff --git a/include/class/acc_ledger_sold.class.php b/include/class/acc_ledger_sold.class.php
index 6dbf6b105..b7e8d53df 100644
--- a/include/class/acc_ledger_sold.class.php
+++ b/include/class/acc_ledger_sold.class.php
@@ -1291,6 +1291,7 @@ EOF;
$Tva = new ITva_Popup($this->db);
$Tva->in_table = true;
$Tva->set_attribute('compute', $i);
+ $Tva->set_filter("sale");
$Tva->js = 'onblur="format_number(this);clean_tva(' . $i . ');compute_ledger(' . $i . ')"';
$Tva->value = $march_tva_id;
diff --git a/include/lib/itva_popup.class.php b/include/lib/itva_popup.class.php
index f4731a311..948dddacc 100644
--- a/include/lib/itva_popup.class.php
+++ b/include/lib/itva_popup.class.php
@@ -54,13 +54,15 @@ class ITva_Popup extends HtmlInput
* to have its own javascript for the button you can use this->but_javascript)
* by default it is 'popup_select_tva(this)';
*/
+ private $filter; //!< filter the VAT by ledger PURCHASE or SALE or NO FILTER, default=NO
public function __construct($p_name=null,$p_value="",$p_id="")
{
$this->name=$p_name;
$this->button=true;
$this->in_table=false;
- $this->value=$p_value;
- $this->id=$p_id;
+ $this->value=$p_value;
+ $this->id=$p_id;
+ $this->filter='none';
}
function with_button($p)
{
@@ -113,6 +115,18 @@ class ITva_Popup extends HtmlInput
return $r;
}
+ /**
+ * Set a filter to limit the choice of VAT ;
+ * possible values are :
+ * - sale if there is an accounting for sale
+ * - purchase if there is an accounting for purchase
+ * - none : show VAT
+ *
+ */
+ function set_filter($p_filter)
+ {
+ $this->filter=$p_filter;
+ }
/**
*@brief show a button, if it is pushed show a popup to select the need vat
*@note
@@ -136,6 +150,7 @@ class ITva_Popup extends HtmlInput
$bt->set_attribute('jcode',$this->code->name);
if ( isset($this->compute))
$bt->set_attribute('compute',$this->compute);
+ $bt->set_attribute("filter", $this->filter);
$bt->javascript=(isset($this->but_javascript))?$this->but_javascript:'popup_select_tva(this)';
$r=$bt->input();
return $r;