Task #1476 : add an new column to TMP_PCMN
Adapt the add and update for CFGPCMN Code cleaning : rewrite of Acc_Account + PhpUnit test
This commit is contained in:
parent
b61fd0bc97
commit
19633eb0bf
6 changed files with 242 additions and 157 deletions
|
|
@ -26,18 +26,12 @@
|
|||
require_once NOALYSS_INCLUDE.'/lib/iselect.class.php';
|
||||
require_once NOALYSS_INCLUDE.'/lib/database.class.php';
|
||||
require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
|
||||
require_once NOALYSS_INCLUDE.'/database/tmp_pcmn_sql.class.php';
|
||||
|
||||
class Acc_Account
|
||||
{
|
||||
var $db; /*!< $db database connection */
|
||||
static private $variable = array("value"=>'pcm_val',
|
||||
'type'=>'pcm_type',
|
||||
'parent'=>'pcm_val_parent',
|
||||
'libelle'=>'pcm_lib');
|
||||
private $pcm_val;
|
||||
private $pcm_type;
|
||||
private $pcm_parent;
|
||||
private $pcm_lib;
|
||||
private $data_sql ;//< Tmp_Pcmn_SQL
|
||||
static public $type=array(
|
||||
array('label'=>'Actif','value'=>'ACT'),
|
||||
array('label'=>'Passif','value'=>'PAS'),
|
||||
|
|
@ -47,35 +41,32 @@ class Acc_Account
|
|||
array('label'=>'Produit Inverse','value'=>'PROINV'),
|
||||
array('label'=>'Charge','value'=>'CHA'),
|
||||
array('label'=>'Charge Inverse','value'=>'CHAINV'),
|
||||
array('label'=>'Non defini','value'=>'CON')
|
||||
array('label'=>'Contexte','value'=>'CON')
|
||||
);
|
||||
|
||||
function __construct ($p_cn,$p_id=0)
|
||||
/**
|
||||
*
|
||||
* @param type $p_cn Database connection
|
||||
* @param type $pcm_val Accounting tmp_pcmn.pcm_val
|
||||
*/
|
||||
function __construct (Database $p_cn,$pcm_val="")
|
||||
{
|
||||
$this->db=$p_cn;
|
||||
$this->pcm_val=$p_id;
|
||||
$id=-1;
|
||||
if ( trim($pcm_val) != "" ) {
|
||||
$id=$p_cn->get_value("select id from tmp_pcmn where pcm_val=$1",[$pcm_val]);
|
||||
}
|
||||
if ( $id == "") { $id=-1;}
|
||||
$this->data_sql=new Tmp_Pcmn_SQL($p_cn, $id);
|
||||
$this->data_sql->pcm_val=$pcm_val;
|
||||
}
|
||||
public function get_parameter($p_string)
|
||||
{
|
||||
if ( array_key_exists($p_string,self::$variable) )
|
||||
{
|
||||
$idx=self::$variable[$p_string];
|
||||
return $this->$idx;
|
||||
}
|
||||
else
|
||||
throw new Exception (__FILE__.":".__LINE__._('Erreur attribut inexistant'));
|
||||
return $this->data_sql->getp($p_string);
|
||||
}
|
||||
|
||||
function set_parameter($p_string,$p_value)
|
||||
{
|
||||
if ( array_key_exists($p_string,self::$variable) )
|
||||
{
|
||||
$idx=self::$variable[$p_string];
|
||||
if ($this->check($idx,$p_value) == true ) $this->$idx=$p_value;
|
||||
}
|
||||
else
|
||||
throw new Exception (__FILE__.":".__LINE__._('Erreur attribut inexistant'));
|
||||
|
||||
return $this->data_sql->setp($p_string,$p_value);
|
||||
|
||||
}
|
||||
/*!\brief Return the name of a account
|
||||
|
|
@ -84,60 +75,19 @@ class Acc_Account
|
|||
*/
|
||||
function get_lib()
|
||||
{
|
||||
$ret=$this->db->exec_sql(
|
||||
"select pcm_lib from tmp_pcmn where
|
||||
pcm_val=$1",array($this->pcm_val));
|
||||
if ( Database::num_row($ret) != 0)
|
||||
$ret=$this->data_sql->getp('pcm_lib');
|
||||
if ( $ret !="")
|
||||
{
|
||||
$r=Database::fetch_array($ret);
|
||||
$this->pcm_lib=$r['pcm_lib'];
|
||||
return $ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->pcm_lib=_("Poste inconnu");
|
||||
return _("Poste inconnu");
|
||||
}
|
||||
return $this->pcm_lib;
|
||||
}
|
||||
/*!\brief Check that the value are valid
|
||||
*\return true if all value are valid otherwise false
|
||||
*/
|
||||
function check ($p_member='',$p_value='')
|
||||
{
|
||||
// if there is no argument we check all the member
|
||||
if ($p_member == '' && $p_value== '' )
|
||||
{
|
||||
foreach (self::$variable as $l=>$k)
|
||||
{
|
||||
$this->check($k,$this->$k);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// otherwise we check only the value
|
||||
if ( strcmp ($p_member,'pcm_val') == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( strcmp ($p_member,'pcm_val_parent') == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( strcmp ($p_member,'pcm_lib') == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( strcmp ($p_member,'pcm_type') == 0 )
|
||||
{
|
||||
foreach (self::$type as $l=>$k)
|
||||
{
|
||||
if ( strcmp ($k['value'],$p_value) == 0 ) return true;
|
||||
|
||||
}
|
||||
throw new Exception(_('type de compte incorrect ').$p_value);
|
||||
}
|
||||
throw new Exception (_('Donnee member inconnue ').$p_member);
|
||||
}
|
||||
|
||||
function searchValue($p_value) {
|
||||
|
||||
|
||||
}
|
||||
/*!\brief Get all the value for this object from the database
|
||||
* the data member are set
|
||||
|
|
@ -145,88 +95,56 @@ class Acc_Account
|
|||
*/
|
||||
function load()
|
||||
{
|
||||
$ret=$this->db->exec_sql("select pcm_lib,pcm_val_parent,pcm_type from
|
||||
tmp_pcmn where pcm_val=$1",array($this->pcm_val));
|
||||
$r=Database::fetch_all($ret);
|
||||
|
||||
if ( ! $r ) return false;
|
||||
$this->pcm_lib=$r[0]['pcm_lib'];
|
||||
$this->pcm_val_parent=$r[0]['pcm_val_parent'];
|
||||
$this->pcm_type=$r[0]['pcm_type'];
|
||||
return true;
|
||||
|
||||
}
|
||||
function form($p_table=true)
|
||||
{
|
||||
$wType=new ISelect();
|
||||
$wType->name='p_type';
|
||||
$wType->value=self::$type;
|
||||
|
||||
if ( ! $p_table )
|
||||
{
|
||||
$ret=' <TR>
|
||||
<TD>
|
||||
<INPUT TYPE="TEXT" NAME="p_val" SIZE=7>
|
||||
</TD>
|
||||
<TD>
|
||||
<INPUT TYPE="TEXT" NAME="p_lib" size=50>
|
||||
</TD>
|
||||
<TD>
|
||||
<INPUT TYPE="TEXT" NAME="p_parent" size=5>
|
||||
</TD>
|
||||
<TD>';
|
||||
|
||||
$ret.=$wType->input().'</TD>';
|
||||
return $ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret='<TABLE><TR>';
|
||||
$ret.=sprintf ('<TD>'._('Numéro de classe').' </TD><TD><INPUT TYPE="TEXT" name="p_val" value="%s"></TD>',$this->pcm_val);
|
||||
$ret.="</TR><TR>";
|
||||
$ret.=sprintf('<TD>'._('Libellé').' </TD><TD><INPUT TYPE="TEXT" size="70" NAME="p_lib" value="%s"></TD>',h($this->pcm_lib));
|
||||
$ret.= "</TR><TR>";
|
||||
$ret.=sprintf ('<TD>'._('Classe Parent').'</TD><TD><INPUT TYPE="TEXT" name="p_parent" value="%s"></TD>',$this->pcm_val_parent);
|
||||
$ret.='</tr><tr>';
|
||||
$wType->selected=$this->pcm_type;
|
||||
$ret.="<td> Type de poste </td>";
|
||||
$ret.= '<td>'.$wType->input().'</td>';
|
||||
$ret.="</TR> </TABLE>";
|
||||
$ret.=dossier::hidden();
|
||||
|
||||
return $ret;
|
||||
}
|
||||
$this->data_sql->load();
|
||||
}
|
||||
|
||||
function count($p_value)
|
||||
{
|
||||
$sql="select count(*) from tmp_pcmn where pcm_val=$1";
|
||||
return $this->db->get_value($sql,array($p_value));
|
||||
}
|
||||
/*!\brief for developper only during test */
|
||||
static function test_me()
|
||||
{
|
||||
/**
|
||||
* Check before inserting or updating
|
||||
*/
|
||||
function verify() {
|
||||
// check for Duplicate key, parent ... see Acc_Plan_MTable
|
||||
$count=$this->data_sql->count(" where pcm_val =$1 and id <> $2",
|
||||
[$this->data_sql->pcm_val,$this->data_sql->id]);
|
||||
if ( $count > 0)
|
||||
throw new Exception (_("Poste en double"),EXC_DUPLICATE);
|
||||
if (trim($this->data_sql->pcm_lib)=="")
|
||||
throw new Exception (_("Libellé vide"),EXC_PARAM_VALUE);
|
||||
if ( $this->data_sql->count(" where pcm_val = $1 and pcm_val <> $2",
|
||||
[$this->data_sql->pcm_val_parent,$this->data_sql->pcm_val]) == 0)
|
||||
throw new Exception (_("Parent n'existe pas"),EXC_PARAM_VALUE);
|
||||
if ( $this->data_sql->pcm_direct_use != 'N' && $this->data_sql->pcm_direct_use != 'Y')
|
||||
throw new Exception (_("Paramètre incorrect"),EXC_PARAM_VALUE);
|
||||
if ( trim($this->data_sql->pcm_val)==""||trim($this->data_sql->pcm_val_parent)=="")
|
||||
throw new Exception (_("Paramètre incorrect"),EXC_PARAM_VALUE);
|
||||
|
||||
}
|
||||
function update() {
|
||||
// check for Duplicate key, parent ... see Acc_Plan_MTable
|
||||
$this->verify();
|
||||
$this->data_sql->update();
|
||||
}
|
||||
function insert() {
|
||||
// check for Duplicate key, parent ... see Acc_Plan_MTable
|
||||
$this->verify();
|
||||
$this->data_sql->insert();
|
||||
}
|
||||
function delete() {
|
||||
// if already use cannot be deleted
|
||||
if ( $this->data_sql->count("where pcm_val in (select j_poste from jrnx where j_poste=$1) or pcm_val_parent=$1",
|
||||
[$this->data_sql->pcm_val]) > 0)
|
||||
{
|
||||
throw new Exception(_("Poste utilisé : effacement interdit"),EXC_PARAM_VALUE);
|
||||
}
|
||||
$this->data_sql->delete();
|
||||
|
||||
}
|
||||
/**
|
||||
*@brief update an accounting, but you can update pcm_val only if
|
||||
* this accounting has never been used before */
|
||||
function update($p_old)
|
||||
{
|
||||
if (strcmp(trim($p_old), trim($this->pcm_val)) !=0 )
|
||||
{
|
||||
$count=$this->db->get_value('select count(*) from jrnx where j_poste=$1',
|
||||
array($p_old)
|
||||
);
|
||||
if ($count != 0)
|
||||
throw new Exception(_('Impossible de changer la valeur: poste déjà utilisé'));
|
||||
}
|
||||
$this->pcm_lib=mb_substr($this->pcm_lib,0,150);
|
||||
$this->check();
|
||||
$sql="update tmp_pcmn set pcm_val=$1, pcm_lib=$2,pcm_val_parent=$3,pcm_type=$4 where pcm_val=$5";
|
||||
$Ret=$this->db->exec_sql($sql,array($this->pcm_val,
|
||||
$this->pcm_lib,
|
||||
$this->pcm_val_parent,
|
||||
$this->pcm_type,
|
||||
$p_old));
|
||||
function save() {
|
||||
$this->verify();
|
||||
$this->data_sql->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ class Acc_Plan_MTable extends Manage_Table_SQL
|
|||
$this->set_col_label("pcm_lib", _("Libellé"));
|
||||
$this->set_col_label("parent_accounting", _("Dépend"));
|
||||
$this->set_col_label("fiche_qcode", _("Fiche"));
|
||||
$this->set_col_label("pcm_direct_use", _("Utilisation directe"));
|
||||
//--------------------------------------------------------------
|
||||
$this->set_property_visible("id", FALSE);
|
||||
$this->set_property_updatable("fiche_qcode", FALSE);
|
||||
|
|
@ -55,7 +56,8 @@ class Acc_Plan_MTable extends Manage_Table_SQL
|
|||
["label"=>_("Produit inversé"),"value"=>"PROINV"],
|
||||
["label"=>_("Contexte"),"value"=>"CON"]
|
||||
]);
|
||||
$this->a_order=["pcm_val","pcm_lib","parent_accounting","pcm_type","fiche_qcode"];
|
||||
$this->set_col_type("pcm_direct_use", "select",array(["label"=>_("Oui"),"value"=>"Y"],["label"=>"Non","value"=>"N"]));
|
||||
$this->a_order=["pcm_val","pcm_lib","parent_accounting","pcm_direct_use","pcm_type","fiche_qcode"];
|
||||
$this->set_icon_mod("first");
|
||||
}
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ class Acc_Plan_SQL extends Data_SQL
|
|||
"parent_accounting"=>"parent_accounting",
|
||||
"pcm_lib"=>"pcm_lib",
|
||||
"pcm_type"=>"pcm_type",
|
||||
"fiche_qcode"=>"fiche_qcode"
|
||||
"fiche_qcode"=>"fiche_qcode",
|
||||
"pcm_direct_use"=>"pcm_direct_use"
|
||||
);
|
||||
|
||||
$this->type = array(
|
||||
|
|
@ -51,7 +52,8 @@ class Acc_Plan_SQL extends Data_SQL
|
|||
"parent_accounting" => "text",
|
||||
"pcm_lib" => "text",
|
||||
"pcm_type" => "text",
|
||||
"fiche_qcode"=>"string"
|
||||
"fiche_qcode"=>"string",
|
||||
"pcm_direct_use"=>"text"
|
||||
);
|
||||
|
||||
$this->default = array(
|
||||
|
|
@ -64,6 +66,7 @@ class Acc_Plan_SQL extends Data_SQL
|
|||
pcm_val_parent as parent_accounting,
|
||||
pcm_type,
|
||||
id,
|
||||
pcm_direct_use,
|
||||
(select string_agg(m.fiche_qcode,' , ')
|
||||
from (select a.ad_value as fiche_qcode
|
||||
from fiche_detail as a
|
||||
|
|
@ -108,6 +111,7 @@ class Acc_Plan_SQL extends Data_SQL
|
|||
$obj->set("pcm_lib",$this->pcm_lib);
|
||||
$obj->set("pcm_type",$this->pcm_type);
|
||||
$obj->set("pcm_val_parent",$this->parent_accounting);
|
||||
$obj->set("pcm_direct_use",$this->pcm_direct_use);
|
||||
$obj->insert();
|
||||
$this->id=$obj->id;
|
||||
}
|
||||
|
|
@ -158,6 +162,8 @@ class Acc_Plan_SQL extends Data_SQL
|
|||
$obj->set("pcm_lib",$this->pcm_lib);
|
||||
$obj->set("pcm_type",$this->pcm_type);
|
||||
$obj->set("pcm_val_parent",$this->parent_accounting);
|
||||
$obj->set("pcm_direct_use",$this->pcm_direct_use);
|
||||
|
||||
$obj->update();
|
||||
}
|
||||
public function get_limit_fiche_qcode()
|
||||
|
|
@ -169,5 +175,6 @@ class Acc_Plan_SQL extends Data_SQL
|
|||
{
|
||||
$this->limit_fiche_qcode=$limit_fiche_qcode;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ class Tmp_Pcmn_SQL extends Noalyss_SQL
|
|||
/**
|
||||
* @brief manage table key_distribution_detail
|
||||
*/
|
||||
function __construct(&$p_cn, $p_id=-1)
|
||||
function __construct($p_cn, $p_id=-1)
|
||||
{
|
||||
|
||||
$this->table="public.tmp_pcmn";
|
||||
|
|
@ -42,7 +42,8 @@ class Tmp_Pcmn_SQL extends Noalyss_SQL
|
|||
"pcm_val"=>"pcm_val",
|
||||
"pcm_type"=>"pcm_type",
|
||||
"pcm_val_parent"=>"pcm_val_parent",
|
||||
"pcm_lib"=>"pcm_lib"
|
||||
"pcm_lib"=>"pcm_lib",
|
||||
"pcm_direct_use"=>"pcm_direct_use"
|
||||
);
|
||||
|
||||
$this->type=array(
|
||||
|
|
@ -50,7 +51,8 @@ class Tmp_Pcmn_SQL extends Noalyss_SQL
|
|||
"pcm_val"=>"text",
|
||||
"pcm_type"=>"text",
|
||||
"pcm_val_parent"=>"text",
|
||||
"pcm_lib"=>"text"
|
||||
"pcm_lib"=>"text",
|
||||
"pcm_direct_use"=>"text"
|
||||
);
|
||||
|
||||
$this->default=array(
|
||||
|
|
|
|||
|
|
@ -10,6 +10,14 @@ ALTER TABLE tmp_pcmn ALTER COLUMN id SET DEFAULT nextval('tmp_pcmn_id_seq'::regc
|
|||
ALTER TABLE tmp_pcmn ADD CONSTRAINT id_ux UNIQUE(id);
|
||||
COMMENT ON COLUMN tmp_pcmn.id IS 'allow to identify the row, it is unique and not null (pseudo pk)';
|
||||
|
||||
-- set search_path to public,comptaproc;
|
||||
alter table tmp_pcmn add column pcm_direct_use varchar(1);
|
||||
COMMENT ON COLUMN tmp_pcmn.pcm_direct_use IS 'Value are N or Y , N cannot be used directly , not even through a card';
|
||||
ALTER TABLE tmp_pcmn ALTER COLUMN pcm_direct_use SET DEFAULT 'Y';
|
||||
update tmp_pcmn set pcm_direct_use='Y';
|
||||
update tmp_pcmn set pcm_direct_use='N' where length(pcm_val) < 3 and not exists (select j_poste from jrnx where j_poste=pcm_val);
|
||||
ALTER TABLE tmp_pcmn ALTER COLUMN pcm_direct_use SET NOT NULL;
|
||||
alter table tmp_pcmn add constraint pcm_direct_use_ck check (pcm_direct_use in ('Y','N'));
|
||||
|
||||
insert into bilan (b_name,b_file_template,b_file_form,b_type) values ('ASBL','document/fr_be/bnb-asbl.rtf','document/fr_be/bnb-asbl.form','RTF');
|
||||
|
||||
|
|
|
|||
148
unit-test/include/class/acc_account.classTest.php
Normal file
148
unit-test/include/class/acc_account.classTest.php
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator on 2017-11-26 at 11:24:04.
|
||||
*/
|
||||
class Acc_AccountTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Acc_Account
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
global $g_connection, $g_parameter, $g_user;
|
||||
$_REQUEST['gDossier']=DOSSIER;
|
||||
$g_connection=new Database(DOSSIER);
|
||||
$g_parameter=new Own($g_connection);
|
||||
$g_user=new User($g_connection);
|
||||
$cn=Dossier::connect();
|
||||
$this->object=new Acc_Account($cn, '400');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Acc_Account::get_parameter
|
||||
*/
|
||||
public function testGet_parameter()
|
||||
{
|
||||
|
||||
$this->assertEquals($this->object->get_parameter("pcm_lib"), 'Clients');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Acc_Account::set_parameter
|
||||
*/
|
||||
public function testSet_parameter()
|
||||
{
|
||||
$this->object->set_parameter("pcm_direct_use", "N");
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Acc_Account::get_lib
|
||||
*/
|
||||
public function testGet_lib()
|
||||
{
|
||||
$this->assertEquals($this->object->get_lib(), 'Clients');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Acc_Account::load
|
||||
*/
|
||||
public function testLoad()
|
||||
{
|
||||
$this->object->load();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Acc_Account::count
|
||||
*/
|
||||
public function testCount()
|
||||
{
|
||||
|
||||
$this->assertEquals($this->object->count("400"), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Acc_Account::verify
|
||||
*/
|
||||
public function testVerify()
|
||||
{
|
||||
$this->object->verify();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Acc_Account::update
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
$this->object->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Acc_Account::insert
|
||||
*/
|
||||
public function testInsert()
|
||||
{
|
||||
$cn=Dossier::connect();
|
||||
$new=new Acc_Account($cn);
|
||||
$new->set_parameter("pcm_val", '400A');
|
||||
$new->set_parameter("pcm_val_parent", "400");
|
||||
$new->set_parameter("pcm_direct_use", "Y");
|
||||
// expect libelle vide
|
||||
try
|
||||
{
|
||||
// exception must be thrown from insert
|
||||
$new->insert();
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->assertEquals($e->getCode(), EXC_PARAM_VALUE);
|
||||
}
|
||||
|
||||
$new->set_parameter("pcm_lib", "Insertion test");
|
||||
$new->insert();
|
||||
$new->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Acc_Account::delete
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->object->delete();
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getTraceAsString();
|
||||
$this->assertEquals($e->getCode(), EXC_PARAM_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Acc_Account::save
|
||||
*/
|
||||
public function testSave()
|
||||
{
|
||||
$this->object->save();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue