0002360: TVA : tva_code check that TVA_CODE is Unique , has maximum 5 characters , do not contain any else than letter or digit
This commit is contained in:
parent
f9ba2a7c6a
commit
20c5fe7031
2 changed files with 69 additions and 14 deletions
|
|
@ -204,7 +204,7 @@ class Tva_Rate_MTable extends Manage_Table_SQL
|
|||
*/
|
||||
function save()
|
||||
{
|
||||
if ( $this->previous_id == null ) {
|
||||
if ( $this->previous_id === null ) {
|
||||
throw new \Exception ("TVA184: no previous TVA id");
|
||||
}
|
||||
$cn=Dossier::connect();
|
||||
|
|
@ -257,11 +257,11 @@ class Tva_Rate_MTable extends Manage_Table_SQL
|
|||
function check()
|
||||
{
|
||||
$cn=Dossier::connect();
|
||||
if ( $this->previous_id == null ) {
|
||||
if ( $this->previous_id === null ) {
|
||||
throw new \Exception ("TVA184: no previous TVA id");
|
||||
}
|
||||
// both accounting can not be empty
|
||||
if (trim($this->table->tva_purchase)==""&&trim($this->table->tva_sale)=="")
|
||||
if (trim($this->table->tva_purchase??"")==""&&trim($this->table->tva_sale??"")=="")
|
||||
{
|
||||
$this->set_error("tva_purchase",
|
||||
_("Les 2 postes comptables ne peuvent être nuls"));
|
||||
|
|
@ -270,7 +270,7 @@ class Tva_Rate_MTable extends Manage_Table_SQL
|
|||
}
|
||||
|
||||
// Check the tva rate
|
||||
if (trim($this->table->tva_rate)==""||isNumber($this->table->tva_rate)==0||$this->table->tva_rate>1)
|
||||
if (trim($this->table->tva_rate??"")==""||isNumber($this->table->tva_rate)==0||$this->table->tva_rate>1)
|
||||
{
|
||||
$this->set_error("tva_rate", _("Taux de TVA invalide"));
|
||||
}
|
||||
|
|
@ -284,7 +284,7 @@ class Tva_Rate_MTable extends Manage_Table_SQL
|
|||
}
|
||||
|
||||
// Check accounting exists for purchase
|
||||
if (trim($this->table->tva_purchase)!=""&&$this->table->tva_purchase!="#")
|
||||
if (trim($this->table->tva_purchase??"")!=""&&$this->table->tva_purchase!="#")
|
||||
{
|
||||
$count=$cn->get_value("select count(*) from tmp_pcmn where pcm_val = $1",
|
||||
[$this->table->tva_purchase]);
|
||||
|
|
@ -294,7 +294,7 @@ class Tva_Rate_MTable extends Manage_Table_SQL
|
|||
}
|
||||
}
|
||||
// Check accounting exists for sale
|
||||
if (trim($this->table->tva_sale)!=""&&$this->table->tva_sale!="#")
|
||||
if (trim($this->table->tva_sale??"")!=""&&$this->table->tva_sale!="#")
|
||||
{
|
||||
$count=$cn->get_value("select count(*) from tmp_pcmn where pcm_val = $1",
|
||||
[$this->table->tva_sale]);
|
||||
|
|
@ -309,19 +309,27 @@ class Tva_Rate_MTable extends Manage_Table_SQL
|
|||
{
|
||||
$this->set_error("tva_both_side", _("Choix incorrect"));
|
||||
}
|
||||
$flag = true;
|
||||
if ( isNumber($this->table->tva_id) == 0 || $this->table->tva_id != round($this->table->tva_id) )
|
||||
{
|
||||
$this->set_error("tva_id",_("Valeur invalide"));
|
||||
$flag=false;
|
||||
}
|
||||
|
||||
// Check if old tva_id was not overwritting something
|
||||
if ( $flag && $this->previous_id != $this->table->tva_id && $cn->get_value("select count(*) from tva_rate where tva_id=$1",[$this->table->tva_id]) > 0)
|
||||
if ( $this->previous_id != $this->table->tva_id && $cn->get_value("select count(*) from tva_rate where tva_id=$1",[$this->table->tva_id]) > 0)
|
||||
{
|
||||
$this->set_error("tva_id",_("Code TVA déjà utilisé"));
|
||||
}
|
||||
// Check that tva_id is a integer not a float
|
||||
// Check that tva code is unique and remove not letter
|
||||
$this->table->tva_code=strtoupper(trim( $this->table->tva_code));
|
||||
$tva_code=$this->table->tva_code;
|
||||
|
||||
$tva_code=strtoupper($tva_code);
|
||||
$tva_code=preg_replace("/[A-Z]/", "", $tva_code);
|
||||
$tva_code=preg_replace("/[0-9]/", "", $tva_code);
|
||||
|
||||
if (strlen($tva_code)>0){
|
||||
$this->set_error("tva_code", _("code tva : Uniquement des chiffres et des lettres"));
|
||||
}
|
||||
|
||||
if (strlen($this->table->tva_code)>5){
|
||||
$this->set_error("tva_code", _("code tva : Maximum 5 caractères"));
|
||||
}
|
||||
if ($this->count_error()!=0)
|
||||
return false;
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -71,4 +71,51 @@ class Acc_TVATest extends TestCase
|
|||
$this->assertEquals(0.2100 , $tva->tva_rate,"Cannot get tva rate after set_parameter");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief display error from tva_rate_mtable
|
||||
* @param Tva_Rate_MTable $tva_rate_mtable
|
||||
* @return void
|
||||
*/
|
||||
function display_error(Tva_Rate_MTable $tva_rate_mtable) {
|
||||
$col=$tva_rate_mtable->get_order();
|
||||
foreach($col as $item) {
|
||||
$error = $tva_rate_mtable->get_error($item);
|
||||
if ( !empty ($error)) print "$error \n";
|
||||
}
|
||||
}
|
||||
|
||||
function dataCheck() {
|
||||
return array(
|
||||
['abc',true]
|
||||
,['13A',true]
|
||||
,['1',true]
|
||||
,['1-A',false]
|
||||
,['+a',false]
|
||||
,['abcdefg',false]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testDox check TVA_CODE value
|
||||
* @dataProvider dataCheck
|
||||
* @return void
|
||||
*/
|
||||
function testCheck($tva_code,$result)
|
||||
{
|
||||
$cn=\Dossier::connect();
|
||||
$vtva_rate=new V_Tva_rate_SQL($cn,-1);
|
||||
$vtva_rate->tva_code=$tva_code;
|
||||
$vtva_rate->tva_label="Test";
|
||||
$vtva_rate->tva_sale="451";
|
||||
$vtva_rate->tva_both_side="0";
|
||||
$vtva_rate->tva_rate=0.21;
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue