noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
noalyss_parameter_folder.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 Class to manage the company parameter (address, name...)
22 */
23/*!
24 * \brief Class to manage the company parameter (address, name...)
25 */
26#[AllowDynamicProperties]
28{
29 var $db;
53 var $MY_REPORT; //!< In Belgium , we need a report on the beginning of the exercice , not in France,
54 var $MY_INVOICE_FORMAT; //!< Default invoice format : BASIC, UBL21BEL, FACTURXFR
55
56
57 const VALID_INVOICE_FORMAT=['BASIC','UBL21BEL','FACTURXFR'];
58 // constructor
59 function __construct($p_cn)
60 {
61 $this->db=$p_cn;
62 $Res=$p_cn->exec_sql("select * from parameter where pr_id like 'MY_%'");
63 for ($i = 0;$i < Database::num_row($Res);$i++)
64 {
66 $key=$row['pr_id'];
67 $elt=$row['pr_value'];
68 // store value here
69 $this->{"$key"}=$elt;
70 }
71
72 }
73
74 public function __toString(): string
75 {
76 $r = <<<EOF
77MY_TVA = [ {$this->MY_TVA }]
78MY_STREET = [ {$this->MY_STREET }]
79MY_NUMBER= [ {$this->MY_NUMBER }]
80MY_POSTCODE= [ {$this->MY_POSTCODE }]
81MY_PHONE= [ {$this->MY_PHONE }]
82MY_COUNTRY= [ {$this->MY_COUNTRY }]
83MY_COUNTRY_CODE= [ {$this->MY_COUNTRY_CODE }]
84MY_CITY= [ {$this->MY_CITY }]
85MY_FAX= [ {$this->MY_FAX }]
86MY_ANALYTIC= [ {$this->MY_ANALYTIC }]
87MY_STRICT= [ {$this->MY_STRICT }]
88MY_TVA_USE= [ {$this->MY_TVA_USE }]
89MY_PJ_SUGGEST= [ {$this->MY_PJ_SUGGEST }]
90MY_CHECK_PERIODE= [ {$this->MY_CHECK_PERIODE }]
91MY_DATE_SUGGEST= [ {$this->MY_DATE_SUGGEST }]
92MY_ALPHANUM= [ {$this->MY_ALPHANUM }]
93MY_UPDLAB= [ {$this->MY_UPDLAB }]
94MY_STOCK= [ {$this->MY_STOCK }]
95MY_DEFAULT_ROUND_ERROR_DEB= [ {$this->MY_DEFAULT_ROUND_ERROR_DEB }]
96MY_DEFAULT_ROUND_ERROR_CRED= [ {$this->MY_DEFAULT_ROUND_ERROR_CRED }]
97MY_ANC_FILTER= [ {$this->MY_ANC_FILTER }]
98MY_REPORT = [ {$this->MY_REPORT } ]
99MY_INVOICE_FORMAT = [ {$this->MY_INVOICE_FORMAT} ]
100EOF;
101 return $r;
102 }
103 /**
104 * @brief check that the filter for ANC operation is valid
105 * @param $p_value (string) list of digit for accounting separated by comma
106 * @return void
107 * @throws if value contains a no-digit value
108 */
109 function check_anc_filter($p_value):void
110 {
111 $tmp_value=$p_value;
112 $tmp_value=preg_replace("/[0-9]|,/", '', $p_value);
113 if ( $tmp_value != "") {
114 throw new Exception (sprintf(_("Valeur invalide %s"),$tmp_value),1000);
115 }
116 if (trim($p_value) == "") {
117 throw new Exception (sprintf(_("Erreur Filtre analytique %s"),$tmp_value),1001);
118
119 }
120
121 }
122 function check($p_attr, $p_value)
123 {
124 $ret_value=$p_value;
125 switch ($p_attr)
126 {
127 case 'MY_STRICT':
128
129 if (empty($p_value) ||($p_value!='Y'&&$p_value!='N'))
130 {
131 $ret_value='N';
132 }
133
134 break;
135 case 'MY_ANC_FILTER':
136 try
137 {
138 $p_value=noalyss_str_replace(" ", "", $p_value);
139 $this->check_anc_filter($p_value);
140 $ret_value=$p_value;
141 }
142 catch (Exception $exc)
143 {
144 throw $exc;
145 }
146
147 break;
148 case 'MY_INVOICE_FORMAT':
149 if ( !in_array($this->MY_INVOICE_FORMAT, Noalyss_Parameter_Folder::VALID_INVOICE_FORMAT))
150 {
151 throw new \Exception ('Format facture invalide');
152 }
153 default :
154 $ret_value= strip_tags($p_value);
155 }
156 return $ret_value;
157 }
158
159 /*!
160 **************************************************
161 * \brief save the parameter into the database by inserting or updating
162 *
163 *
164 * \param $p_attr give the attribut name
165 *
166 */
167 function save($p_attr)
168 {
169 try {
170 $value=$this->check($p_attr,$this->$p_attr);
171
172 // check if the parameter does exist
173 if ( $this->db->get_value('select count(*) from parameter where pr_id=$1',array($p_attr)) != 0 )
174 {
175 $Res=$this->db->exec_sql("update parameter set pr_value=$1 where pr_id=$2",
176 array($value,$p_attr));
177 }
178 else
179 {
180
181 $Res=$this->db->exec_sql("insert into parameter (pr_id,pr_value) values( $1,$2)",
182 array($p_attr,$value));
183
184 }
185 } catch (Exception $e) {
186 throw $e;
187 }
188
189 }
190
191 /*!
192 **************************************************
193 * \brief save data
194 *
195 *
196 */
197 function update()
198 {
199
200 $this->save('MY_NAME');
201 $this->save('MY_TVA');
202 $this->save('MY_STREET');
203 $this->save('MY_NUMBER');
204 $this->save('MY_POSTCODE');
205 $this->save('MY_PHONE');
206 $this->save('MY_COUNTRY');
207 $this->save('MY_COUNTRY_CODE');
208 $this->save('MY_CITY');
209 $this->save('MY_FAX');
210 $this->save('MY_ANALYTIC');
211 $this->save('MY_STRICT');
212 $this->save('MY_TVA_USE');
213 $this->save('MY_PJ_SUGGEST');
214 $this->save('MY_CHECK_PERIODE');
215 $this->save('MY_DATE_SUGGEST');
216 $this->save('MY_ALPHANUM');
217 $this->save('MY_UPDLAB');
218 $this->save('MY_STOCK');
219 $this->save('MY_DEFAULT_ROUND_ERROR_DEB');
220 $this->save('MY_DEFAULT_ROUND_ERROR_CRED');
221 $this->save("MY_ANC_FILTER");
222 $this->save("MY_REPORT");
223 $this->save("MY_INVOICE_FORMAT");
224
225 }
226 /**
227 * Check if an accounting match the anc_filter
228 * @param string $p_accounting
229 * @return boolean FALSE does not match , TRUE matches
230 */
231 function match_analytic($p_accounting)
232 {
233 $a_filter=explode(",",$this->MY_ANC_FILTER??"");
234 if (empty($a_filter)) return false;
235 foreach ($a_filter as $filter ) {
236 $string="/^".$filter.".*/";
237
238 if ( preg_match($string,$p_accounting) != 0 ) return TRUE;
239 }
240 return FALSE;
241 }
242 /**
243 * @brief build a SELECT html input
244 * @return \ISelect
245 */
247 $select_format_invoice=new \ISelect('invoice_format');
248 $a_label=[_("Basic"),_("UBL21 Belgique"),_("FacturX France")];
252 }
253}
noalyss_str_replace($search, $replace, $string)
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
_("actif, passif,charge,...")
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows
Class to manage the company parameter (address, name...)
save($p_attr)
save the parameter into the database by inserting or updating
$MY_INVOICE_FORMAT
Default invoice format : BASIC, UBL21BEL, FACTURXFR.
check_anc_filter($p_value)
check that the filter for ANC operation is valid
match_analytic($p_accounting)
Check if an accounting match the anc_filter.
input_select_format()
build a SELECT html input
$MY_REPORT
In Belgium , we need a report on the beginning of the exercice , not in France,.
$select_format_invoice
$SecUser db