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