diff --git a/html/ajax_misc.php b/html/ajax_misc.php index efdf3ab08..c4d89c5e3 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -567,6 +567,8 @@ EOF; }else { $Res = $cn->exec_sql("select * from v_tva_rate + where + tva_purchase <> '#' and tva_sale <> '#' order by tva_rate desc"); } $Max = Database::num_row($Res); diff --git a/include/class/acc_tva.class.php b/include/class/acc_tva.class.php index 6868788cf..6ab1eb3e1 100644 --- a/include/class/acc_tva.class.php +++ b/include/class/acc_tva.class.php @@ -138,10 +138,11 @@ class Acc_Tva } /** - * @brief retrieve TVA rate thanks the code that could be the tva_id or tva_code + * @brief retrieve TVA rate thanks the code that could be the tva_id or tva_code. Check first if p_code is a + * TVA_CODE and if not, check if it is a TVA_ID * @param $db Database connection * @param $p_code either tva_id or tva_code - * @return Acc_Tva or null + * @return Acc_Tva or Acc_TVA with tva_id=-1 */ static function build($db,$p_code):Acc_Tva { if (empty($p_code)) return new Acc_Tva($db,-1); @@ -149,12 +150,12 @@ class Acc_Tva if ( $db->size() == 1) { return new Acc_Tva($db,$tva_id); } - + if (isNumber($p_code) == 0) return new Acc_Tva($db,-1); $exist = $db->get_value("select count(*) from public.tva_rate where tva_id=$1",[$p_code]); - if ( $db->size() == 1) { + if ( $exist == 1) { return new Acc_Tva($db,$p_code); } - new Acc_Tva($db,-1); + return new Acc_Tva($db,-1); } } diff --git a/include/class/card_property.class.php b/include/class/card_property.class.php index 60f90d5cc..91ceb5958 100644 --- a/include/class/card_property.class.php +++ b/include/class/card_property.class.php @@ -631,7 +631,8 @@ class Card_Property // Verify if the rate exists, if not then do not update if (noalyss_strlentrim($value->av_text)!=0) { - if ($p_fiche->cn->get_value("select count(*) from tva_rate where tva_id=$1",[$value->av_text])==0) + $acc_tva=Acc_Tva::build($p_fiche->cn,$value->av_text ); + if ($acc_tva->tva_id==-1) { continue; } diff --git a/include/lib/itva_popup.class.php b/include/lib/itva_popup.class.php index 2d67a9611..f23b05a4a 100644 --- a/include/lib/itva_popup.class.php +++ b/include/lib/itva_popup.class.php @@ -71,7 +71,43 @@ class ITva_Popup extends HtmlInput else $this->button = false; } + protected function make_datalist() + { + $cn=Dossier::connect(); + $r=""; + switch ($this->filter) { + case 'none': + $sql="select tva_code + from v_tva_rate + where + tva_purchase <> '#' and tva_sale <> '#' + order by tva_code "; + break; + case 'sale': + $sql="select tva_code + from v_tva_rate + where + tva_sale <> '#' + order by tva_code "; + break; + case 'purchase': + $sql="select tva_code + from v_tva_rate + where + tva_purchase <> '#' + order by tva_code "; + break; + } + $a_tva_code=$cn->get_array($sql); + if ( empty($a_tva_code)) return ""; + $r.=sprintf(''; + return $r; + } /*!\brief show the html input of the widget*/ public function input($p_name = null, $p_value = null) { @@ -101,8 +137,8 @@ class ITva_Popup extends HtmlInput $strAttribut = $this->get_node_attribute(); - $str = ''; - $r = sprintf($str, $this->name, $this->value, $this->id, _("C.TVA"),$this->js, $strAttribut); + $str = ''; + $r = sprintf($str, $this->name, $this->value, $this->id, _("C.TVA"),$this->js, $strAttribut,$this->id); $r.=$code; if ($this->in_table) $table = '