Task #0001536: Achat - Vente : n'utilisez que les codes TVA disponibles

This commit is contained in:
Dany De Bontridder 2018-02-10 14:44:23 +01:00
parent dc34dbb066
commit 90ee4d4f47
5 changed files with 44 additions and 3 deletions

View file

@ -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");

View file

@ -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",

View file

@ -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");

View file

@ -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;

View file

@ -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;