TVA_CODE : suggest tva_code + unittest

This commit is contained in:
sparkyx 2024-06-18 11:56:15 +02:00
parent 8af7eb1047
commit 2e9b11932d
5 changed files with 74 additions and 9 deletions

View file

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

View file

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

View file

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

View file

@ -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('<datalist id="dl_tva_%s">',$this->id);
foreach ($a_tva_code as $item) {
$r.=sprintf('<option value="%s"></option>',$item['tva_code']);
}
$r.='</datalist>';
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 = '<input type="TEXT" class="input_text" name="%s" value="%s" id="%s" placeholder="%s" size="3" %s %s>';
$r = sprintf($str, $this->name, $this->value, $this->id, _("C.TVA"),$this->js, $strAttribut);
$str = '<input type="TEXT" class="input_text" name="%s" value="%s" id="%s" placeholder="%s" size="3" %s %s list="dl_tva_%s">';
$r = sprintf($str, $this->name, $this->value, $this->id, _("C.TVA"),$this->js, $strAttribut,$this->id);
$r.=$code;
if ($this->in_table)
$table = '<table>' . '<tr>' . td($r);
@ -114,6 +150,7 @@ class ITva_Popup extends HtmlInput
$r = $table . td($this->dbutton()) . '</tr></table>';
if ($this->table == 1) $r = td($r);
$r.=$this->make_datalist();
return $r;
}

View file

@ -96,7 +96,7 @@ class Acc_TVATest extends TestCase
}
/**
* @testDox check TVA_CODE value
* @testdox check TVA_CODE value
* @dataProvider dataCheck
* @return void
*/
@ -117,5 +117,29 @@ class Acc_TVATest extends TestCase
$this->assertTrue($result==$check," erreur pour $tva_code ");
$this->display_error($tva_rate_mtable);
}
function dataBuild() {
return array(
['0A',4]
,['0B',6]
,[6,6]
,['NONE',-1]
,[14,-1]
,[" ",-1]
,[null,-1]
);
}
/**
* @testdox check Acc_TVA::Build
* @dataProvider dataBuild
* @return void
*/
function testBuild($tva_code,$result)
{
$cn=\Dossier::connect();
$tva=Acc_Tva::build($cn, $tva_code);
$tva->load();
$this->assertTrue($result==$tva->tva_id," erreur pour tva_code [$tva_code] tva_id {$tva->tva_id}");
}
}