noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
acc_payment.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
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!\file
23 * \brief Handle the table payment_method
24 */
25require_once NOALYSS_INCLUDE.'/constant.php';
26
27/*!\brief Handle the table payment_method
28 *\note the private data member are accessed via
29 - mp_id ==> id ( Primary key )
30 - mp_lib ==> lib (label)
31 - mp_jrn_def_id ==> ledger (Number of the ledger where to save)
32 - mp_fd_id ==> fiche_def (fiche class to use)
33 - mp_qcode ==> qcode (quick_code of the card)
34 *
35 */
36
37#[AllowDynamicProperties]
39{
40 private static $variable=array("id"=>"mp_id",
41 "lib"=>"mp_lib",
42 "qcode"=>"mp_qcode",
43 "ledger_target"=>"mp_jrn_def_id",
44 "ledger_source"=>"jrn_def_id",
45 "fiche_def"=>"mp_fd_id");
46
47 private $mp_id;
48 private $mp_lib;
49 private $mp_qcode;
51 private $jrn_def_id;
52 private $mp_fd_id;
53 private $cn; //!< Database connection
54 function __construct ($p_cn,$p_init=0)
55 {
56 $this->cn=$p_cn;
57 $this->mp_id=$p_init;
58 }
59 public function get_parameter($p_string)
60 {
61 if ( array_key_exists($p_string,self::$variable) )
62 {
63 $idx=self::$variable[$p_string];
64 return $this->$idx;
65 }
66 else
67 {
68 throw new Exception("Attribut inexistant $p_string");
69 }
70 }
71 public function set_parameter($p_string,$p_value)
72 {
73 if ( array_key_exists($p_string,self::$variable) )
74 {
75 $idx=self::$variable[$p_string];
76 $this->$idx=$p_value;
77 }
78 else
79 throw new Exception("Attribut inexistant $p_string");
80
81
82 }
83 public function get_info()
84 {
85 return var_export(self::$variable,true);
86 }
87
88 public function load():bool
89 {
90 $sql='select mp_id,mp_lib,mp_fd_id,mp_jrn_def_id,mp_qcode,jrn_def_id from payment_method '.
91 ' where mp_id = $1';
92 $res=$this->cn->exec_sql(
93 $sql,
94 array($this->mp_id)
95 );
96
97 if ( Database::num_row($res) == 0 ) return false;
98
100 $a_index=array_values(self::$variable);
101 foreach ($a_index as $idx)
102 {
103 $this->$idx=$row[$idx];
104 }
105 return true;
106 }
107
108 /*!\brief retrieve all the data for all ledgers
109 *\param non
110 *\return an array of row
111 */
112 public function get_all()
113 {
114 $sql='select mp_id,mp_lib '.
115 ' from payment_method order by mp_lib';
116 $array=$this->cn->get_array($sql);
117 $ret=array();
118 if ( !empty($array) )
119 {
120 foreach ($array as $row)
121 {
122 $t=new Acc_Payment($this->cn,$row['mp_id']);
123 $t->load();
124 $ret[]=$t;
125 }
126 }
127 return $ret;
128 }
129 /*!\brief retrieve all the data for a ledger but filter on the
130 *valid record (jrn and fd not null
131 *\param non
132 *\return an array of row
133 */
134 public function get_valide()
135 {
136 $sql='select mp_id '.
137 ' from payment_method '.
138 ' where jrn_def_id=$1 and mp_jrn_def_id is not null and '.
139 ' (mp_fd_id is not null or mp_qcode is not null)';
140 $array=$this->cn->get_array($sql,array($this->jrn_def_id));
141 $ret=array();
142 if ( !empty($array) )
143 {
144 foreach ($array as $row)
145 {
146 $t=new Acc_Payment($this->cn,$row['mp_id']);
147 $t->load();
148 $ret[]=$t;
149 }
150 }
151 return $ret;
152 }
153 /*!\brief return a string with a form (into a table)
154 *\param none
155 *\return a html string
156 */
157 public function form()
158 {
159 //label
160 $lib=new IText('mp_lib');
161 $lib->value=$this->mp_lib;
162 $f_lib=$lib->input();
163
164
165 $ledger_source=new ISelect('jrn_def_id');
166 $ledger_source->value=$this->cn->make_array("select jrn_def_id,jrn_Def_name from
167 jrn_def where jrn_def_type in ('ACH','VEN') order by jrn_def_name");
168 $ledger_source->selected=$this->jrn_def_id;
169 $f_source=$ledger_source->input();
170
171 // type of card
172 $tcard=new ISelect('mp_fd_id');
173 $tcard->value=$this->cn->make_array('select fd_id,fd_label from fiche_def join fiche_def_ref '.
174 ' using (frd_id) where frd_id in (25,4) order by fd_label');
175 $tcard->selected=$this->mp_fd_id;
176
177 $f_type_fiche=$tcard->input();
178 $ledger_record=new ISelect('mp_jrn_def_id');
179 $ledger_record->value=$this->cn->make_array("select jrn_def_id,jrn_Def_name from
180 jrn_def where jrn_def_type in ('ODS','FIN')");
181 $ledger_record->selected=$this->mp_jrn_def_id;
182 $f_ledger_record=$ledger_record->input();
183
184 // the card
185 $qcode=new ICard();
186 $qcode->noadd=true;
187 $qcode->name='mp_qcode';
188 $list=$this->cn->make_list('select fd_id from fiche_def where frd_id in (25,4)');
189 $qcode->typecard=$list;
190 $qcode->dblclick='fill_ipopcard(this);';
191 $qcode->value=$this->mp_qcode;
192
193 $f_qcode=$qcode->input();
194
195 $msg="Modification de ".$this->mp_lib;
196 ob_start();
197 require_once NOALYSS_TEMPLATE.'/new_mod_payment.php';
198 $r=ob_get_contents();
199 ob_end_clean();
200 return $r;
201
202 }
203 /*!\brief show several lines with radio button to select the payment
204 *method we want to use, the $_POST['e_mp'] will be set
205 * \todo this class is used only for storage of the defined payment method, not the payment itself,
206 * it must be moved to another class 'Operation_Payment'
207 *\param $p_selected if the id choose
208 *\param $p_date date of payment
209 *\param $p_amount amount already paid
210 *\param $p_comm label of payment
211 *\return html string
212 */
213 public function select($p_select,$p_amount,$p_date,$p_comm)
214 {
215 $r='';
216 $array=$this->get_valide();
217 $r.=HtmlInput::hidden('gDossier',dossier::id());
218
219 if ( empty($array)==false ) {
220 $date_pay=new IDate('mp_date');
221 $date_pay->value=$p_date;
222 $r.=sprintf(_("Date %s"),
223 $date_pay->input());
224 $acompte=new INum('acompte');
225 $acompte->value=$p_amount;
226 $r.=_(" Acompte à déduire");
227 $r.=$acompte->input();
228 $r.='<p>';
229 $e_comm_paiement=new IText('e_comm_paiement');
230 $e_comm_paiement->value=$p_comm;
231 $e_comm_paiement->table = 0;
232 $e_comm_paiement->setReadOnly(false);
233 $e_comm_paiement->size = 60;
234 $e_comm_paiement->tabindex = 3;
235 $r.=_(" Libellé du paiement");
236 $r.=$e_comm_paiement->input();
237 $r.='</p>';
238 }
239
240 $r.='<ol>';
241 $r.='<li ><input type="radio" name="e_mp" value="0" checked>'._('Paiement encodé plus tard');
242 $http=new HttpInput();
243 if ( empty($array ) == false )
244 {
245 foreach ($array as $row)
246 {
247 $f='';
248 /* if the qcode is null the propose a search button to select
249 the card */
250 if ( $row->mp_qcode==NULL)
251 {
252 $a=new ICard();
253 $a->jrn=$row->mp_jrn_def_id;
254 $a->set_attribute('typecard',$row->mp_fd_id);
255 $a->name='e_mp_qcode_'.$row->mp_id;
256 $a->set_dblclick("fill_ipopcard(this);");
257 $a->set_callback('filter_card');
258 $a->set_function('fill_data');
259 $a->set_attribute('ipopup','ipopcard');
260 $a->set_attribute('label',$a->name.'_label');
261 if ( $p_select == $row->mp_id ) {
262 $a->value=$http->request("e_mp_qcode_".$p_select, "string","");
263 }
264 $s=new ISpan();
265 $s->name=$a->name.'_label';
266 $f=_(" paiement par ").$a->input().$s->input().$a->search();
267
268 }
269 else
270 {
271 /* if the qcode is not null then add a hidden variable with
272 the qcode */
273
274 $fiche=new Fiche($this->cn);
275 $fiche->get_by_qcode($row->mp_qcode);
276 $f=HtmlInput::hidden('e_mp_qcode_'.$row->mp_id,$row->mp_qcode);
277
278 // $f.=$fiche->strAttribut(ATTR_DEF_NAME);
279 }
280 $check=( $p_select == $row->mp_id)?" checked " : "unchecked";
281 $r.='<li><input type="radio" name="e_mp" value="'.$row->mp_id.'" '.$check.'>';
282 $r.=$row->mp_lib.' '.$f;
283
284 }
285 }
286 $r.='</ol>';
287 return $r;
288 }
289
290 /*!\brief convert an array into an Acc_Payment object
291 *\param array to convert
292 */
293 public function from_array($p_array)
294 {
295 $a_index=array_values(self::$variable);
296 // $idx=array('mp_id','mp_lib','mp_fd_id','mp_jrn_def_id','mp_qcode','jrn_def_id');
297 foreach ($a_index as $l) {
298 if (isset($p_array[$l])) $this->$l=$p_array[$l];
299 }
300 }
301 /**
302 *@brief return an html with a form to add a new middle of payment
303 */
304 public function blank()
305 {
306 //label
307 $lib=new IText('mp_lib');
308 $f_lib=$lib->input();
309
310 $ledger_source=new ISelect('jrn_def_id');
311 $ledger_source->value=$this->cn->make_array("select jrn_def_id,jrn_Def_name from
312 jrn_def where jrn_def_type in ('ACH','VEN') order by jrn_def_name");
313 $f_source=$ledger_source->input();
314
315 // type of card
316 $tcard=new ISelect('mp_fd_id');
317 $tcard->value=$this->cn->make_array('select fd_id,fd_label from fiche_def join fiche_def_ref '.
318 ' using (frd_id) where frd_id in (25,4) order by fd_label');
319 $f_type_fiche=$tcard->input();
320 $ledger_record=new ISelect('mp_jrn_def_id');
321 $ledger_record->value=$this->cn->make_array("select jrn_def_id,jrn_Def_name from
322 jrn_def where jrn_def_type in ('ODS','FIN')");
323 $f_ledger_record=$ledger_record->input();
324
325 // the card
326 $qcode=new ICard();
327 $qcode->noadd=true;
328 $qcode->name='mp_qcode';
329 $list=$this->cn->make_list('select fd_id from fiche_def where frd_id in (25,4)');
330 $qcode->typecard=$list;
331 $qcode->dblclick='fill_ipopcard(this);';
332
333 $f_qcode=$qcode->input();
334 $msg="Ajout d'un nouveau moyen de paiement";
335 ob_start();
336 require_once NOALYSS_TEMPLATE.'/new_mod_payment.php';
337 $r=ob_get_contents();
338 ob_end_clean();
339 return $r;
340 }
341}
342
343
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
margin jrn_def_id
$input_from cn
_("actif, passif,charge,...")
Handle the table payment_method.
from_array($p_array)
convert an array into an Acc_Payment object
form()
return a string with a form (into a table)
$cn
Database connection.
set_parameter($p_string, $p_value)
blank()
return an html with a form to add a new middle of payment
__construct($p_cn, $p_init=0)
get_valide()
retrieve all the data for a ledger but filter on the valid record (jrn and fd not null
select($p_select, $p_amount, $p_date, $p_comm)
show several lines with radio button to select the payment method we want to use, the $_POST['e_mp'] ...
get_all()
retrieve all the data for all ledgers
get_parameter($p_string)
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
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
manage the http input (get , post, request) and extract from an array
Input HTML for the card show buttons, in the file, you have to add card.js How to use :
Html Input : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
This class handles only the numeric input, the input will call a javascript to change comma to period...
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Html Input.
Html Input.
$t
Definition compute.php:46
$check