diff --git a/html/ajax_misc.php b/html/ajax_misc.php
index 46a8ed8e4..b926f4ccb 100644
--- a/html/ajax_misc.php
+++ b/html/ajax_misc.php
@@ -598,7 +598,7 @@ EOF;
$Res = $cn->exec_sql("select * from v_tva_rate
where
- tva_purchase <> '#' and tva_sale <> '#'
+ tva_purchase <> '#' or tva_sale <> '#'
order by tva_id asc");
}
$Max = Database::num_row($Res);
diff --git a/html/js/noalyss_script.js b/html/js/noalyss_script.js
index a5f6c5400..8bd090620 100644
--- a/html/js/noalyss_script.js
+++ b/html/js/noalyss_script.js
@@ -609,14 +609,19 @@ function popup_select_tva(obj, p_function_callback) {
if (document.getElementById('tva_select')) {
removeDiv('tva_select');
}
+ var gDossier=(obj.gDossier)?obj.gDossier:obj.getAttribute("gdossier");
+ var ctl=(obj.ctl)?obj.ctl:obj.getAttribute("ctl");
+
+ var queryString = "gDossier=" + gDossier + "&op=dsp_tva" + "&ctl=" + ctl + '&popup=' + 'tva_select';
- var queryString = "gDossier=" + obj.getAttribute("gdossier") + "&op=dsp_tva" + "&ctl=" + obj.getAttribute("ctl") + '&popup=' + 'tva_select';
- if (obj.jcode)
- queryString += '&code=' + obj.jcode;
- if (obj.compute)
- queryString += '&compute=' + obj.compute;
- if (obj.filter)
- queryString += '&filter=' + obj.filter;
+ var jcode=(obj.jcode)?obj.jcode:obj.getAttribute("jcode");
+ if (jcode)
+ queryString += '&code=' + jcode;
+ var compute=(obj.compute)?obj.compute:obj.getAttribute("compute");
+ if (compute) queryString += '&compute=' + compute;
+ var filter=(obj.filter)?obj.filter:obj.getAttribute("filter");
+
+ if (filter) queryString += '&filter=' + filter;
var action = new Ajax.Request(
"ajax_misc.php",
diff --git a/include/class/tva_rate_mtable.class.php b/include/class/tva_rate_mtable.class.php
index d576dbfd4..c2be0fe7b 100644
--- a/include/class/tva_rate_mtable.class.php
+++ b/include/class/tva_rate_mtable.class.php
@@ -452,17 +452,17 @@ class Tva_Rate_MTable extends Manage_Table_SQL
}
// if vatex is set then code invoice must be different from S and Z
- if ( trim($this->table->vx_code) != "" && in_array($this->table->tva_peppol_code,['S','Z'] ))
+ if ( trim($this->table->vx_code??"") != "" && in_array($this->table->tva_peppol_code,['S','Z'] ))
{
$this->set_error("vx_code",_("Le code d'exemption TVA ne peut être utilisé avec ce code Facture électronique UBL "));
}
// if vatex is set then code invoice must be different from S and Z
- if ( trim($this->table->vx_code) != "" && $this->table->tva_peppol_code=="")
+ if ( trim($this->table->vx_code??"") != "" && $this->table->tva_peppol_code=="")
{
$this->set_error("vx_code",_("Le code d'exemption TVA n' pas de sens sans code Facture électronique"));
}
// if tva_peppol_code is not S or Z then a VATEX code must be supplied
- if ( ! in_array($this->table->tva_peppol_code,["Z","S"]) && trim($this->table->vx_code ) =="")
+ if ( ! in_array($this->table->tva_peppol_code??"",["Z","S"]) && trim($this->table->vx_code??"" ) =="")
{
$this->set_error("vx_code",_("Un code d'exemption de TVA doit être fourni, voyez le manuel"));
diff --git a/unit-test/include/class/Acc_TVATest.php b/unit-test/include/class/Acc_TVATest.php
index 878e4bfe0..5d22ce835 100644
--- a/unit-test/include/class/Acc_TVATest.php
+++ b/unit-test/include/class/Acc_TVATest.php
@@ -110,14 +110,60 @@ class Acc_TVATest extends TestCase
$vtva_rate->tva_sale="451";
$vtva_rate->tva_both_side="0";
$vtva_rate->tva_rate=0.21;
-
+ $vtva_rate->tva_peppol_code='S';
$tva_rate_mtable=new Tva_Rate_MTable($vtva_rate);
$tva_rate_mtable->setPreviousId(0);
$check = $tva_rate_mtable->check();
+
$this->assertTrue($result==$check," erreur pour $tva_code ");
- $this->display_error($tva_rate_mtable);
+ if ( $result != $check)
+ {
+ print "Error for $peppopl_code\n";
+ print_r($tva_rate_mtable->aerror);
+ $this->display_error($tva_rate_mtable);
+ }
}
+ static function dataCheckVatex() {
+ return array(
+ ['S',true,null]
+ ,['Z',true,null]
+ ,['A',false,""]
+ ,['A',true,"XX"]
+ );
+ }
+ /**
+ * @brief VATEX Mandatory of tva_peppol_code not in S or Z
+ * @testdox VATEX Mandatory if tva_peppol_code not S or Z
+ * @param type $tva_code
+ * @param type $result
+ */
+ #[DataProvider('dataCheckVatex')]
+ function testCheckVatex($peppopl_code,$result,$vatex_code)
+ {
+ $cn=\Dossier::connect();
+ $vtva_rate=new V_Tva_rate_SQL($cn,1);
+
+ $vtva_rate->tva_label="Test";
+ $vtva_rate->tva_sale="451";
+ $vtva_rate->tva_both_side="0";
+ $vtva_rate->tva_rate=0.21;
+ $vtva_rate->tva_peppol_code=$peppopl_code;
+ $vtva_rate->vx_code=$vatex_code;
+ $tva_rate_mtable=new Tva_Rate_MTable($vtva_rate);
+ $tva_rate_mtable->setPreviousId(1);
+
+ $check = $tva_rate_mtable->check();
+
+ $this->assertTrue($result==$check," erreur pour $peppopl_code ");
+ if ( $result != $check)
+ {
+ print "Error for $peppopl_code\n";
+ print_r($tva_rate_mtable->aerror);
+ $this->display_error($tva_rate_mtable);
+ }
+ }
+
static function dataBuild() {
return array(
['0A',4]