noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_acc_payment.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 mod_payment
24  */
25 require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
26 require_once NOALYSS_INCLUDE.'/lib/class_icard.php';
27 require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
28 require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
29 require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
30 require_once NOALYSS_INCLUDE.'/class/class_fiche_def.php';
31 require_once NOALYSS_INCLUDE.'/constant.php';
32 /*!\brief Handle the table mod_payment
33  *\note the private data member are accessed via
34  - mp_id ==> id ( Primary key )
35  - mp_lib ==> lib (label)
36  - mp_jrn_def_id ==> ledger (Number of the ledger where to save)
37  - mp_fd_id ==> fiche_def (fiche class to use)
38  - mp_qcode ==> qcode (quick_code of the card)
39  *
40  */
42 {
43 
44  private static $variable=array("id"=>"mp_id",
45  "lib"=>"mp_lib",
46  "qcode"=>"mp_qcode",
47  "ledger_target"=>"mp_jrn_def_id",
48  "ledger_source"=>"jrn_def_id",
49  "fiche_def"=>"mp_fd_id");
50 
51 
52  private $mp_lib;
53  private $mp_qcode;
54  private $mp_jrn_def_if;
55  private $jrn_def_id;
56  private $mp_fd_id;
57 
58  function __construct ($p_cn,$p_init=0)
59  {
60  $this->cn=$p_cn;
61  $this->mp_id=$p_init;
62  }
63  public function get_parameter($p_string)
64  {
65  if ( array_key_exists($p_string,self::$variable) )
66  {
67  $idx=self::$variable[$p_string];
68  return $this->$idx;
69  }
70  else
71  {
72  throw new Exception("Attribut inexistant $p_string");
73  }
74  }
75  public function set_parameter($p_string,$p_value)
76  {
77  if ( array_key_exists($p_string,self::$variable) )
78  {
79  $idx=self::$variable[$p_string];
80  $this->$idx=$p_value;
81  }
82  else
83  throw new Exception("Attribut inexistant $p_string");
84 
85 
86  }
87  public function get_info()
88  {
89  return var_export(self::$variable,true);
90  }
91  public function verify()
92  {
93  // Verify that the elt we want to add is correct
94  }
95  public function save()
96  {
97  /* please adapt */
98  if ( $this->get_parameter("id") == 0 )
99  $this->insert();
100  else
101  $this->update();
102  }
103 
104  public function insert()
105  {
106  if ( $this->verify() != 0 ) return;
107  $sql='INSERT INTO mod_payment(
108  mp_lib, mp_jrn_def_id, mp_fd_id, mp_qcode,jrn_def_id)
109  VALUES ($1, $2, $3, upper($4),$5) returning mp_id';
110  $this->mp_id=$this->cn->exec_sql($sql,array(
111  $this->mp_lib,
112  $this->mp_jrn_def_id,
113  $this->mp_fd_id,
114  $this->mp_qcode,
115  $this->jrn_def_id));
116  }
117 
118  public function update()
119  {
120  if ( $this->verify() != 0 ) return;
121 
122  $sql="update mod_payment set mp_lib=$1,mp_qcode=$2,mp_jrn_def_id=$3,mp_fd_id=$4,jrn_def_id=$5 ".
123  " where mp_id = $6";
124  $res=$this->cn->exec_sql(
125  $sql,
126  array($this->mp_lib,
127  $this->mp_qcode,
128  $this->mp_jrn_def_id,
129  $this->mp_fd_id,
130  $this->jrn_def_id,
131  $this->mp_id)
132  );
133  if ( strlen (trim($this->mp_jrn_def_id))==0)
134  $this->cn->exec_sql(
135  'update mod_payment '.
136  'set mp_jrn_def_id = null where mp_id=$1',
137  array($this->mp_id));
138  if ( strlen (trim($this->jrn_def_id))==0)
139  $this->cn->exec_sql(
140  'update mod_payment '.
141  'set mp_jrn_def_id = null where mp_id=$1',
142  array($this->mp_id));
143  if ( strlen (trim($this->mp_qcode))==0)
144  $this->cn->exec_sql(
145  'update mod_payment '.
146  'set mp_qcode = null where mp_id=$1',
147  array($this->mp_id));
148  if ( strlen (trim($this->mp_fd_id))==0)
149  $this->cn->exec_sql(
150  'update mod_payment '.
151  'set mp_fd_id = null where mp_id=$1',
152  array($this->mp_id));
153 
154  }
155 
156  public function load()
157  {
158  $sql='select mp_id,mp_lib,mp_fd_id,mp_jrn_def_id,mp_qcode,jrn_def_id from mod_payment '.
159  ' where mp_id = $1';
160  $res=$this->cn->exec_sql(
161  $sql,
162  array($this->mp_id)
163  );
164 
165  if ( Database::num_row($res) == 0 ) return;
167  foreach ($row as $idx=>$value)
168  {
169  $this->$idx=$value;
170  }
171 
172  }
173  /**
174  *@brief remove a middle of payment
175  */
176  public function delete()
177  {
178  $sql="delete from mod_payment where mp_id=$1";
179  $this->cn->exec_sql($sql,array($this->mp_id));
180  }
181  /*!\brief retrieve all the data for all ledgers
182  *\param non
183  *\return an array of row
184  */
185  public function get_all()
186  {
187  $sql='select mp_id,mp_lib '.
188  ' from mod_payment order by mp_lib';
189  $array=$this->cn->get_array($sql);
190  $ret=array();
191  if ( !empty($array) )
192  {
193  foreach ($array as $row)
194  {
195  $t=new Acc_Payment($this->cn,$row['mp_id']);
196  $t->load();
197  $ret[]=$t;
198  }
199  }
200  return $ret;
201  }
202  /*!\brief retrieve all the data for a ledger but filter on the
203  *valid record (jrn and fd not null
204  *\param non
205  *\return an array of row
206  */
207  public function get_valide()
208  {
209  $sql='select mp_id '.
210  ' from mod_payment '.
211  ' where jrn_def_id=$1 and mp_jrn_def_id is not null and '.
212  ' (mp_fd_id is not null or mp_qcode is not null)';
213  $array=$this->cn->get_array($sql,array($this->jrn_def_id));
214  $ret=array();
215  if ( !empty($array) )
216  {
217  foreach ($array as $row)
218  {
219  $t=new Acc_Payment($this->cn,$row['mp_id']);
220  $t->load();
221  $ret[]=$t;
222  }
223  }
224  return $ret;
225  }
226  /*!\brief return a string with a form (into a table)
227  *\param none
228  *\return a html string
229  */
230  public function form()
231  {
232  //label
233  $lib=new IText('mp_lib');
234  $lib->value=$this->mp_lib;
235  $f_lib=$lib->input();
236 
237 
238  $ledger_source=new ISelect('jrn_def_id');
239  $ledger_source->value=$this->cn->make_array("select jrn_def_id,jrn_Def_name from
240  jrn_def where jrn_def_type in ('ACH','VEN') order by jrn_def_name");
241  $ledger_source->selected=$this->jrn_def_id;
242  $f_source=$ledger_source->input();
243 
244  // type of card
245  $tcard=new ISelect('mp_fd_id');
246  $tcard->value=$this->cn->make_array('select fd_id,fd_label from fiche_def join fiche_def_ref '.
247  ' using (frd_id) where frd_id in (25,4) order by fd_label');
248  $tcard->selected=$this->mp_fd_id;
249 
250  $f_type_fiche=$tcard->input();
251  $ledger_record=new ISelect('mp_jrn_def_id');
252  $ledger_record->value=$this->cn->make_array("select jrn_def_id,jrn_Def_name from
253  jrn_def where jrn_def_type in ('ODS','FIN')");
254  $ledger_record->selected=$this->mp_jrn_def_id;
255  $f_ledger_record=$ledger_record->input();
256 
257  // the card
258  $qcode=new ICard();
259  $qcode->noadd=true;
260  $qcode->name='mp_qcode';
261  $list=$this->cn->make_list('select fd_id from fiche_def where frd_id in (25,4)');
262  $qcode->typecard=$list;
263  $qcode->dblclick='fill_ipopcard(this);';
264  $qcode->value=$this->mp_qcode;
265 
266  $f_qcode=$qcode->input();
267 
268  $msg="Modification de ".$this->mp_lib;
269  ob_start();
270  require_once NOALYSS_TEMPLATE.'/new_mod_payment.php';
271  $r=ob_get_contents();
272  ob_end_clean();
273  return $r;
274 
275  }
276  /*!\brief show several lines with radio button to select the payment
277  *method we want to use, the $_POST['e_mp'] will be set
278  *\param $p_selected if the id choose
279  *\return html string
280  */
281  public function select($p_select)
282  {
283  $r='';
284  $array=$this->get_valide();
285  $r.=HtmlInput::hidden('gDossier',dossier::id());
286 
287  if ( empty($array)==false ) {
288  $acompte=new INum('acompte');
289  $acompte->value=0;
290  $r.=_(" Acompte à déduire");
291  $r.=$acompte->input();
292  $r.='<p>';
293  $e_comm_paiement=new IText('e_comm_paiement');
294  $e_comm_paiement->table = 0;
295  $e_comm_paiement->setReadOnly(false);
296  $e_comm_paiement->size = 60;
297  $e_comm_paiement->tabindex = 3;
298  $r.=_(" Libellé du paiement");
299  $r.=$e_comm_paiement->input();
300  $r.='</p>';
301  }
302 
303  $r.='<ol>';
304  $r.='<li ><input type="radio" name="e_mp" value="0" checked>'._('Paiement encodé plus tard');
305  if ( empty($array ) == false )
306  {
307  foreach ($array as $row)
308  {
309  $f='';
310  /* if the qcode is null the propose a search button to select
311  the card */
312  if ( $row->mp_qcode==NULL)
313  {
314  $a=new ICard();
315  $a->jrn=$row->mp_jrn_def_id;
316  $a->set_attribute('typecard',$row->mp_fd_id);
317  $a->name='e_mp_qcode_'.$row->mp_id;
318  $a->set_dblclick("fill_ipopcard(this);");
319  $a->set_callback('filter_card');
320  $a->set_function('fill_data');
321  $a->set_attribute('ipopup','ipopcard');
322  $a->set_attribute('label',$a->name.'_label');
323  if ( $p_select == $row->mp_id ) {
324  $a->value=HtmlInput::default_value_request("e_mp_qcode_".$p_select, "");
325  }
326  $s=new ISpan();
327  $s->name=$a->name.'_label';
328  $f=_(" paiement par ").$a->input().$s->input();
329 
330  }
331  else
332  {
333  /* if the qcode is not null then add a hidden variable with
334  the qcode */
335 
336  $fiche=new Fiche($this->cn);
337  $fiche->get_by_qcode($row->mp_qcode);
338  $f=HtmlInput::hidden('e_mp_qcode_'.$row->mp_id,$row->mp_qcode);
339 
340  // $f.=$fiche->strAttribut(ATTR_DEF_NAME);
341  }
342  $check=( $p_select == $row->mp_id)?" checked " : "unchecked";
343  $r.='<li><input type="radio" name="e_mp" value="'.$row->mp_id.'" '.$check.'>';
344  $r.=$row->mp_lib.' '.$f;
345 
346  }
347  }
348  $r.='</ol>';
349  return $r;
350  }
351 
352  /*!\brief convert an array into an Acc_Payment object
353  *\param array to convert
354  */
355  public function from_array($p_array)
356  {
357  $idx=array('mp_id','mp_lib','mp_fd_id','mp_jrn_def_id','mp_qcode','jrn_def_id');
358  foreach ($idx as $l)
359  if (isset($p_array[$l])) $this->$l=$p_array[$l];
360  }
361  /**
362  *@brief return an html with a form to add a new middle of payment
363  */
364  public function blank()
365  {
366  //label
367  $lib=new IText('mp_lib');
368  $f_lib=$lib->input();
369 
370  $ledger_source=new ISelect('jrn_def_id');
371  $ledger_source->value=$this->cn->make_array("select jrn_def_id,jrn_Def_name from
372  jrn_def where jrn_def_type in ('ACH','VEN') order by jrn_def_name");
373  $f_source=$ledger_source->input();
374 
375  // type of card
376  $tcard=new ISelect('mp_fd_id');
377  $tcard->value=$this->cn->make_array('select fd_id,fd_label from fiche_def join fiche_def_ref '.
378  ' using (frd_id) where frd_id in (25,4) order by fd_label');
379  $f_type_fiche=$tcard->input();
380  $ledger_record=new ISelect('mp_jrn_def_id');
381  $ledger_record->value=$this->cn->make_array("select jrn_def_id,jrn_Def_name from
382  jrn_def where jrn_def_type in ('ODS','FIN')");
383  $f_ledger_record=$ledger_record->input();
384 
385  // the card
386  $qcode=new ICard();
387  $qcode->noadd=true;
388  $qcode->name='mp_qcode';
389  $list=$this->cn->make_list('select fd_id from fiche_def where frd_id in (25,4)');
390  $qcode->typecard=$list;
391  $qcode->dblclick='fill_ipopcard(this);';
392 
393  $f_qcode=$qcode->input();
394  $msg="Ajout d'un nouveau moyen de paiement";
395  ob_start();
396  require_once NOALYSS_TEMPLATE.'/new_mod_payment.php';
397  $r=ob_get_contents();
398  ob_end_clean();
399  return $r;
400  }
401  /*!\brief test function
402  */
403  static function test_me()
404  {
405 
406  }
407 
408 }
409 
410 
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_parameter($p_string)
static num_row($ret)
wrapper for the function pg_NumRows
from_array($p_array)
convert an array into an Acc_Payment object
$value
$idx
select($p_select)
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
switch($ss_action) $f
static fetch_array($ret, $p_indice=0)
wrapper for the function pg_fetch_array
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: class_fiche.php:44
get_valide()
retrieve all the data for a ledger but filter on the valid record (jrn and fd not null ...
form()
return a string with a form (into a table)
static test_me()
test function
function trim(s)
remove trailing and heading space
Definition: scripts.js:95
$input_from cn
Definition: balance.inc.php:71
if(!isset($_REQUEST['p_jrn'])) else $Ledger id
$check
Input HTML for the card show buttons, in the file, you have to add card.js How to use : ...
Handle the table mod_payment.
static hidden($p_name, $p_value, $p_id="")
static default_value_request($ind, $default)
return default if the value if the value doesn't exist in $_REQUEST
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: class_inum.php:40