noalyss Version-9
acc_account.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19// Copyright Author Dany De Bontridder danydb@aevalys.eu
20/*! \file
21 * \brief Manage the account
22 */
23/*!
24 * \brief Manage the account from the table tmp_pcmn
25 */
26require_once NOALYSS_INCLUDE.'/database/tmp_pcmn_sql.class.php';
27
29{
30 var $db; /*!< $db database connection */
31 private $data_sql ;//< Tmp_Pcmn_SQL
32 static public $type=array(
33 array('label'=>'Actif','value'=>'ACT'),
34 array('label'=>'Passif','value'=>'PAS'),
35 array('label'=>'Actif c. inverse','value'=>'ACTINV'),
36 array('label'=>'Passif c.inverse','value'=>'PASINV'),
37 array('label'=>'Produit','value'=>'PRO'),
38 array('label'=>'Produit Inverse','value'=>'PROINV'),
39 array('label'=>'Charge','value'=>'CHA'),
40 array('label'=>'Charge Inverse','value'=>'CHAINV'),
41 array('label'=>'Contexte','value'=>'CON')
42 );
43 /**
44 *
45 * @param type $p_cn Database connection
46 * @param type $pcm_val Accounting tmp_pcmn.pcm_val
47 */
48 function __construct (Database $p_cn,$pcm_val="")
49 {
50 $this->db=$p_cn;
51 $id=-1;
52 if ( trim($pcm_val) != "" ) {
53 $pcm_val=mb_strtoupper($pcm_val);
54 $pcm_val=$this->db->get_value("select format_account($1)",
55 array($pcm_val));
56 $id=$p_cn->get_value("select id from tmp_pcmn where pcm_val=$1",[$pcm_val]);
57 }
58 if ( $id == "") { $id=-1;}
59 $this->data_sql=new Tmp_Pcmn_SQL($p_cn, $id);
60 $this->data_sql->pcm_val=$pcm_val;
61
62 }
63 public function get_parameter($p_string)
64 {
65 return $this->data_sql->getp($p_string);
66 }
67
68 function set_parameter($p_string,$p_value)
69 {
70 return $this->data_sql->setp($p_string,$p_value);
71
72 }
73 /*!\brief Return the name of a account
74 * it doesn't change any data member
75 * \return string with the pcm_lib
76 */
77 function get_lib()
78 {
79 $ret=$this->data_sql->getp('pcm_lib');
80 if ( $ret !="")
81 {
82 return $ret;
83 }
84 else
85 {
86 return _("Poste inconnu");
87 }
88 }
89 function searchValue($p_value) {
90
91
92 }
93 /*!\brief Get all the value for this object from the database
94 * the data member are set
95 * \return false if this account doesn't exist otherwise true
96 */
97 function load():bool
98 {
99 return $this->data_sql->load();
100 }
101
102 function count($p_value)
103 {
104 $sql="select count(*) from tmp_pcmn where pcm_val=$1";
105 return $this->db->get_value($sql,array($p_value));
106 }
107 /**
108 * Find the parent of an account
109 * @return string (pcm_val)
110 */
111 function find_parent() {
112 $name=$this->data_sql->pcm_val;
113 $length_name=strlen($name);
114 $parent="";
115 for ($i = 1;$i <$length_name;$i++) {
116 $parent=mb_substr($name, 0, $length_name-$i);
117 $exist=$this->db->get_value("select count(*) from tmp_pcmn where pcm_val=$1",[$parent]);
118 if ( $exist == 1) return $parent;
119 }
120
121 return $parent;
122 }
123 /**
124 * Check before inserting or updating
125 */
126 function verify() {
127 // check for Duplicate key, parent ... see Acc_Plan_MTable
128 $count=$this->data_sql->count(" where pcm_val =$1 and id <> $2",
129 [mb_strtoupper($this->data_sql->pcm_val),$this->data_sql->id]);
130 if ( $count > 0)
131 throw new Exception (_("Poste en double"),EXC_DUPLICATE);
132
133 if (noalyss_trim($this->data_sql->pcm_lib)=="")
134 throw new Exception (_("Libellé vide"),EXC_PARAM_VALUE);
135
136 // can not depend of itself
137 if ( $this->data_sql->pcm_val_parent == $this->data_sql->pcm_val)
138 throw new Exception (_("Poste parent incorrect"),EXC_PARAM_VALUE);
139
140 if ( $this->data_sql->pcm_val_parent == "") {
141 $account=$this->find_parent();
142 $this->data_sql->pcm_val_parent=$account;
143 if ($account == "")
144 throw new Exception (_("Poste Parent n'existe pas"),EXC_PARAM_VALUE);
145 }
146
147 // purpose not clear
148 if ( $this->data_sql->count(" where pcm_val = $1 and pcm_val <> $2",
149 [$this->data_sql->pcm_val_parent,$this->data_sql->pcm_val]) == 0)
150 throw new Exception (_("Poste Parent n'existe pas"),EXC_PARAM_VALUE);
151
152
153 if ( $this->data_sql->pcm_direct_use != 'N' && $this->data_sql->pcm_direct_use != 'Y')
154 throw new Exception (_("Paramètre incorrect"),EXC_PARAM_VALUE);
155
156 if ( trim($this->data_sql->pcm_val)==""||trim($this->data_sql->pcm_val_parent)=="")
157 throw new Exception (_("Paramètre incorrect"),EXC_PARAM_VALUE);
158
159 if ( strlen($this->data_sql->pcm_val)>40) {
160 throw new Exception (_("Poste comptable doit être de 40 caractères maximum"),EXC_PARAM_VALUE);
161 }
162
163 }
164 function update() {
165 // check for Duplicate key, parent ... see Acc_Plan_MTable
166 $this->verify();
167 $this->data_sql->update();
168 }
169 function insert() {
170 // check for Duplicate key, parent ... see Acc_Plan_MTable
171 $this->verify();
172 $this->data_sql->insert();
173 }
174 function delete() {
175 // if already use cannot be deleted
176 if ( $this->data_sql->count("where pcm_val in (select j_poste from jrnx where j_poste=$1) or pcm_val_parent=$1",
177 [$this->data_sql->pcm_val]) > 0)
178 {
179 throw new Exception(_("Poste utilisé : effacement interdit"),EXC_PARAM_VALUE);
180 }
181 $this->data_sql->delete();
182
183 }
184 function find_by_value($p_pcm_val)
185 {
186 $id=$this->db->get_value("select id from tmp_pcmn where pcm_val=$1",[$p_pcm_val]);
187 $this->data_sql->setp("id",$id);
188 $this->data_sql->load();
189 }
190 function save() {
191 try {
192 $this->verify();
193 $this->data_sql->save();
194 } catch (Exception $e) {
195 throw $e;
196 }
197 }
198 }
noalyss_trim($p_string)
Definition: ac_common.php:1545
Manage the account from the table tmp_pcmn.
set_parameter($p_string, $p_value)
__construct(Database $p_cn, $pcm_val="")
searchValue($p_value)
get_parameter($p_string)
load()
Get all the value for this object from the database the data member are set.
get_lib()
Return the name of a account it doesn't change any data member.
find_by_value($p_pcm_val)
verify()
Check before inserting or updating.
find_parent()
Find the parent of an account.
get_value($p_sql, $p_array=null)
return the value of the sql, the sql will return only one value with the value
contains the class for connecting to Noalyss
ORM abstract of the table public.tmp_pcmn.
const EXC_DUPLICATE
Definition: constant.php:345
const EXC_PARAM_VALUE
Definition: constant.php:343
$count
$SecUser db