VAT : fix bug when VAT not usable for ledger or purchase

This commit is contained in:
sparkyx 2025-11-22 10:27:16 +01:00
parent c236776db7
commit 1b2101c557
4 changed files with 64 additions and 13 deletions

View file

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

View file

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

View file

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

View file

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