altocompta/include/class_jrn_def_sql.php
Dany De Bontridder 9b60c79f54 Merged revisions 5560-5575 via svnmerge from
svn+ssh://danydb@ns352270.ovh.net/svn/phpcompta/tags/rel670

........
  r5560 | danydb | 2013-12-05 01:30:40 +0100 (jeu., 05 déc. 2013) | 1 line
  
  fix small bug utf-8 instead of utf8 for javascript
........
  r5561 | danydb | 2013-12-05 02:13:57 +0100 (jeu., 05 déc. 2013) | 1 line
  
  typo
........
  r5562 | danydb | 2013-12-05 02:14:55 +0100 (jeu., 05 déc. 2013) | 2 lines
  
  Task #929 - Ajout d'une description pour les journaux
........
  r5563 | danydb | 2013-12-05 06:37:23 +0100 (jeu., 05 déc. 2013) | 2 lines
  
  task #928 : ajax pour remplacer les journaux
  Task #928 - Fenêtre Journaux dans fenêtre recherche est clippé
........
  r5564 | danydb | 2013-12-05 07:23:14 +0100 (jeu., 05 déc. 2013) | 4 lines
  
  Task #929 : Ajout d'une description pour les journaux
  
  Description pour les journaux visibles dans lors encodages 
  Task #929 - Ajout d'une description pour les journaux
........
  r5565 | danydb | 2013-12-05 07:51:08 +0100 (jeu., 05 déc. 2013) | 3 lines
  
  Task #929 : Ajout d'une description pour les journaux
  
  nettoyage code
........
  r5566 | danydb | 2013-12-05 07:55:11 +0100 (jeu., 05 déc. 2013) | 3 lines
  
  Task #929 : Ajout d'une description pour les journaux
  
  ajout fichier
........
  r5567 | danydb | 2013-12-06 11:38:07 +0100 (ven., 06 déc. 2013) | 3 lines
  
  Task #941 Tag non disponible pour nouveau suivi
  Si nouveau document, on ne peut plus ajouter de tag
  Task #914 - Tag non disponible pour nouveau suivi
........
  r5568 | danydb | 2013-12-06 11:41:15 +0100 (ven., 06 déc. 2013) | 2 lines
  
  Task #924 FSALDO : les lignes paires et impaires n'ont pas la même taille de police
  Task #924 - FSALDO : les lignes paires et impaires n'ont pas la même taille de police
........
  r5569 | danydb | 2013-12-06 12:07:16 +0100 (ven., 06 déc. 2013) | 1 line
  
  FREC : tri incorrect
........
  r5570 | danydb | 2013-12-06 12:07:37 +0100 (ven., 06 déc. 2013) | 1 line
  
  ajout d'un 3ième paramètre pour TH : raw
........
  r5571 | danydb | 2013-12-06 12:20:37 +0100 (ven., 06 déc. 2013) | 2 lines
  
  task #925 - FSALDO  : ajouter les totaux
  Task #925 - FSALDO  : ajouter les totaux
........
  r5572 | danydb | 2013-12-06 12:32:43 +0100 (ven., 06 déc. 2013) | 2 lines
  
  task #930 - Quantité négative et impact sur les stocks
  Task #930 - Quantité négative et impact sur les stocks
........
  r5573 | danydb | 2013-12-06 13:01:05 +0100 (ven., 06 déc. 2013) | 2 lines
  
  task #926 : CARD : balance et balance non soldée
  Task #926 - CARD : balance et balance non soldée
........
  r5574 | danydb | 2013-12-06 14:38:08 +0100 (ven., 06 déc. 2013) | 2 lines
  
  task #0000919: FOLLOW : description des fichiers joints
  Task #919 - FOLLOW : description des fichiers joints
........
  r5575 | danydb | 2013-12-06 14:40:41 +0100 (ven., 06 déc. 2013) | 1 line
  
  Release
........
2013-12-06 14:41:27 +00:00

390 lines
8.9 KiB
PHP

<?php
/**
* @file
* @brief Manage the table public.jrn_def
*
*
Example
@code
@endcode
*/
require_once('class_database.php');
require_once('ac_common.php');
/**
* @brief Manage the table public.jrn_def
*/
class Jrn_Def_sql
{
/* example private $variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0); */
protected $variable = array(
"jrn_def_id" => "jrn_def_id",
"jrn_def_name" => "jrn_def_name"
, "jrn_def_class_deb" => "jrn_def_class_deb"
, "jrn_def_class_cred" => "jrn_def_class_cred"
, "jrn_def_fiche_deb" => "jrn_def_fiche_deb"
, "jrn_def_fiche_cred" => "jrn_def_fiche_cred"
, "jrn_deb_max_line" => "jrn_deb_max_line"
, "jrn_cred_max_line" => "jrn_cred_max_line"
, "jrn_def_ech" => "jrn_def_ech"
, "jrn_def_ech_lib" => "jrn_def_ech_lib"
, "jrn_def_type" => "jrn_def_type"
, "jrn_def_code" => "jrn_def_code"
, "jrn_def_pj_pref" => "jrn_def_pj_pref"
, "jrn_def_bank" => "jrn_def_bank"
, "jrn_def_num_op" => "jrn_def_num_op"
, "jrn_def_description" => "jrn_def_description"
);
function __construct(& $p_cn, $p_id=-1)
{
$this->db = $p_cn;
$this->jrn_def_id = $p_id;
if ($p_id == -1)
{
/* Initialize an empty object */
foreach ($this->variable as $key => $value)
$this->$value = null;
$this->jrn_def_id = $p_id;
}
else
{
/* load it */
$this->load();
}
}
public function get_parameter($p_string)
{
if (array_key_exists($p_string, $this->variable))
{
$idx = $this->variable[$p_string];
return $this->$idx;
}
else
throw new Exception(__FILE__ . ":" . __LINE__ . $p_string . 'Erreur attribut inexistant');
}
public function set_parameter($p_string, $p_value)
{
if (array_key_exists($p_string, $this->variable))
{
$idx = $this->variable[$p_string];
$this->$idx = $p_value;
}
else
throw new Exception(__FILE__ . ":" . __LINE__ . $p_string . 'Erreur attribut inexistant');
}
public function get_info()
{
return var_export($this, true);
}
public function verify_sql()
{
// Verify that the elt we want to add is correct
/* verify only the datatype */
if (trim($this->jrn_def_name) == '')
$this->jrn_def_name = null;
if (trim($this->jrn_def_class_deb) == '')
$this->jrn_def_class_deb = null;
if (trim($this->jrn_def_class_cred) == '')
$this->jrn_def_class_cred = null;
if (trim($this->jrn_def_fiche_deb) == '')
$this->jrn_def_fiche_deb = null;
if (trim($this->jrn_def_fiche_cred) == '')
$this->jrn_def_fiche_cred = null;
if (trim($this->jrn_deb_max_line) == '')
$this->jrn_deb_max_line = null;
if ($this->jrn_deb_max_line !== null && settype($this->jrn_deb_max_line, 'float') == false)
throw new Exception('DATATYPE jrn_deb_max_line $this->jrn_deb_max_line non numerique');
if (trim($this->jrn_cred_max_line) == '')
$this->jrn_cred_max_line = null;
if ($this->jrn_cred_max_line !== null && settype($this->jrn_cred_max_line, 'float') == false)
throw new Exception('DATATYPE jrn_cred_max_line $this->jrn_cred_max_line non numerique');
if (trim($this->jrn_def_ech) == '')
$this->jrn_def_ech = null;
if (trim($this->jrn_def_ech_lib) == '')
$this->jrn_def_ech_lib = null;
if (trim($this->jrn_def_type) == '')
$this->jrn_def_type = null;
if (trim($this->jrn_def_code) == '')
$this->jrn_def_code = null;
if (trim($this->jrn_def_pj_pref) == '')
$this->jrn_def_pj_pref = null;
if (trim($this->jrn_def_bank) == '')
$this->jrn_def_bank = null;
if ($this->jrn_def_bank !== null && settype($this->jrn_def_bank, 'float') == false)
throw new Exception('DATATYPE jrn_def_bank $this->jrn_def_bank non numerique');
if (trim($this->jrn_def_num_op) == '')
$this->jrn_def_num_op = null;
if ($this->jrn_def_num_op !== null && settype($this->jrn_def_num_op, 'float') == false)
throw new Exception('DATATYPE jrn_def_num_op $this->jrn_def_num_op non numerique');
}
public function save($p_string='')
{
/* please adapt */
if ($this->jrn_def_id == -1)
$this->insert();
else
$this->update();
}
/**
* @brief retrieve array of object thanks a condition
* @param $cond condition (where clause) (optional by default all the rows are fetched)
* you can use this parameter for the order or subselect
* @param $p_array array for the SQL stmt
* @see Database::exec_sql get_object Database::num_row
* @return the return value of exec_sql
*/
public function seek($cond='', $p_array=null)
{
$sql = "select * from public.jrn_def $cond";
$aobj = array();
$ret = $this->db->exec_sql($sql, $p_array);
return $ret;
}
/**
* get_seek return the next object, the return of the query must have all the column
* of the object
* @param $p_ret is the return value of an exec_sql
* @param $idx is the index
* @see seek
* @return object
*/
public function get_object($p_ret, $idx)
{
// map each row in a object
$oobj = new Jrn_Def_sql($this->db);
$array = Database::fetch_array($p_ret, $idx);
foreach ($array as $idx => $value)
{
$oobj->$idx = $value;
}
return $oobj;
}
public function insert($p_array=null)
{
if ($this->verify_sql() != 0)
return;
if ($this->jrn_def_id == -1)
{
/* please adapt */
$sql = "insert into public.jrn_def(jrn_def_name
,jrn_def_class_deb
,jrn_def_class_cred
,jrn_def_fiche_deb
,jrn_def_fiche_cred
,jrn_deb_max_line
,jrn_cred_max_line
,jrn_def_ech
,jrn_def_ech_lib
,jrn_def_type
,jrn_def_code
,jrn_def_pj_pref
,jrn_def_bank
,jrn_def_num_op
,jrn_def_description
) values ($1
,$2
,$3
,$4
,$5
,$6
,$7
,$8
,$9
,$10
,$11
,$12
,$13
,$14
,$15
) returning jrn_def_id";
$this->jrn_def_id = $this->db->get_value(
$sql, array($this->jrn_def_name
, $this->jrn_def_class_deb
, $this->jrn_def_class_cred
, $this->jrn_def_fiche_deb
, $this->jrn_def_fiche_cred
, $this->jrn_deb_max_line
, $this->jrn_cred_max_line
, $this->jrn_def_ech
, $this->jrn_def_ech_lib
, $this->jrn_def_type
, $this->jrn_def_code
, $this->jrn_def_pj_pref
, $this->jrn_def_bank
, $this->jrn_def_num_op
, strip_tags($this->jrn_def_description)
)
);
}
else
{
$sql = "insert into public.jrn_def(jrn_def_name
,jrn_def_class_deb
,jrn_def_class_cred
,jrn_def_fiche_deb
,jrn_def_fiche_cred
,jrn_deb_max_line
,jrn_cred_max_line
,jrn_def_ech
,jrn_def_ech_lib
,jrn_def_type
,jrn_def_code
,jrn_def_pj_pref
,jrn_def_bank
,jrn_def_num_op
,jrn_def_id
,jrn_def_description) values ($1
,$2
,$3
,$4
,$5
,$6
,$7
,$8
,$9
,$10
,$11
,$12
,$13
,$14
,$15
,$16
) returning jrn_def_id";
$this->jrn_def_id = $this->db->get_value(
$sql, array($this->jrn_def_name
, $this->jrn_def_class_deb
, $this->jrn_def_class_cred
, $this->jrn_def_fiche_deb
, $this->jrn_def_fiche_cred
, $this->jrn_deb_max_line
, $this->jrn_cred_max_line
, $this->jrn_def_ech
, $this->jrn_def_ech_lib
, $this->jrn_def_type
, $this->jrn_def_code
, $this->jrn_def_pj_pref
, $this->jrn_def_bank
, $this->jrn_def_num_op
, $this->jrn_def_id
, strip_tags($this->jrn_def_description))
);
}
}
public function update($p_string='')
{
if ($this->verify_sql() != 0)
return;
/* please adapt */
$sql = " update public.jrn_def set jrn_def_name = $1
,jrn_def_class_deb = $2
,jrn_def_class_cred = $3
,jrn_def_fiche_deb = $4
,jrn_def_fiche_cred = $5
,jrn_deb_max_line = $6
,jrn_cred_max_line = $7
,jrn_def_ech = $8
,jrn_def_ech_lib = $9
,jrn_def_type = $10
,jrn_def_code = $11
,jrn_def_pj_pref = $12
,jrn_def_bank = $13
,jrn_def_num_op = $14
,jrn_def_description = $15
where jrn_def_id= $16";
$res = $this->db->exec_sql(
$sql, array($this->jrn_def_name
, $this->jrn_def_class_deb
, $this->jrn_def_class_cred
, $this->jrn_def_fiche_deb
, $this->jrn_def_fiche_cred
, $this->jrn_deb_max_line
, $this->jrn_cred_max_line
, $this->jrn_def_ech
, $this->jrn_def_ech_lib
, $this->jrn_def_type
, $this->jrn_def_code
, $this->jrn_def_pj_pref
, $this->jrn_def_bank
, $this->jrn_def_num_op
, strip_tags($this->jrn_def_description)
, $this->jrn_def_id)
);
}
/**
* @brief load a object
* @return 0 on success -1 the object is not found
*/
public function load()
{
$sql = "select jrn_def_name
,jrn_def_class_deb
,jrn_def_class_cred
,jrn_def_fiche_deb
,jrn_def_fiche_cred
,jrn_deb_max_line
,jrn_cred_max_line
,jrn_def_ech
,jrn_def_ech_lib
,jrn_def_type
,jrn_def_code
,jrn_def_pj_pref
,jrn_def_bank
,jrn_def_num_op
,jrn_def_description
from public.jrn_def where jrn_def_id=$1";
/* please adapt */
$res = $this->db->get_array(
$sql, array($this->jrn_def_id)
);
if (count($res) == 0)
{
/* Initialize an empty object */
foreach ($this->variable as $key => $value)
$this->$key = '';
return -1;
}
foreach ($res[0] as $idx => $value)
{
$this->$idx = $value;
}
return 0;
}
public function delete()
{
$sql = "delete from public.jrn_def where jrn_def_id=$1";
$res = $this->db->exec_sql($sql, array($this->jrn_def_id));
}
/**
* Unit test for the class
*/
static function test_me()
{
}
}
// Jrn_Def_sql::test_me();
?>