00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 require_once("class_iselect.php");
00026 require_once("class_icard.php");
00027 require_once("class_ispan.php");
00028 require_once('class_acc_ledger.php');
00029 require_once('class_fiche.php');
00030 require_once('class_fiche_def.php');
00031 require_once('constant.php');
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 class Acc_Payment
00042 {
00043
00044 private static $variable=array("id"=>"mp_id",
00045 "lib"=>"mp_lib",
00046 "qcode"=>"mp_qcode",
00047 "ledger_target"=>"mp_jrn_def_id",
00048 "ledger_source"=>"jrn_def_id",
00049 "fiche_def"=>"mp_fd_id");
00050
00051
00052 private $mp_lib;
00053 private $mp_qcode;
00054 private $mp_jrn_def_if;
00055 private $jrn_def_id;
00056 private $mp_fd_id;
00057
00058 function __construct ($p_cn,$p_init=0)
00059 {
00060 $this->cn=$p_cn;
00061 $this->mp_id=$p_init;
00062 }
00063 public function get_parameter($p_string)
00064 {
00065 if ( array_key_exists($p_string,self::$variable) )
00066 {
00067 $idx=self::$variable[$p_string];
00068 return $this->$idx;
00069 }
00070 else
00071 {
00072 throw new Exception("Attribut inexistant $p_string");
00073 exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
00074 }
00075 }
00076 public function set_parameter($p_string,$p_value)
00077 {
00078 if ( array_key_exists($p_string,self::$variable) )
00079 {
00080 $idx=self::$variable[$p_string];
00081 $this->$idx=$p_value;
00082 }
00083 else
00084 exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
00085
00086
00087 }
00088 public function get_info()
00089 {
00090 return var_export(self::$variable,true);
00091 }
00092 public function verify()
00093 {
00094
00095 }
00096 public function save()
00097 {
00098
00099 if ( $this->get_parameter("id") == 0 )
00100 $this->insert();
00101 else
00102 $this->update();
00103 }
00104
00105 public function insert()
00106 {
00107 if ( $this->verify() != 0 ) return;
00108 $sql='INSERT INTO mod_payment(
00109 mp_lib, mp_jrn_def_id, mp_fd_id, mp_qcode,jrn_def_id)
00110 VALUES ($1, $2, $3, upper($4),$5) returning mp_id';
00111 $this->mp_id=$this->cn->exec_sql($sql,array(
00112 $this->mp_lib,
00113 $this->mp_jrn_def_id,
00114 $this->mp_fd_id,
00115 $this->mp_qcode,
00116 $this->jrn_def_id));
00117 }
00118
00119 public function update()
00120 {
00121 if ( $this->verify() != 0 ) return;
00122
00123 $sql="update mod_payment set mp_lib=$1,mp_qcode=$2,mp_jrn_def_id=$3,mp_fd_id=$4,jrn_def_id=$5 ".
00124 " where mp_id = $6";
00125 $res=$this->cn->exec_sql(
00126 $sql,
00127 array($this->mp_lib,
00128 $this->mp_qcode,
00129 $this->mp_jrn_def_id,
00130 $this->mp_fd_id,
00131 $this->jrn_def_id,
00132 $this->mp_id)
00133 );
00134 if ( strlen (trim($this->mp_jrn_def_id))==0)
00135 $this->cn->exec_sql(
00136 'update mod_payment '.
00137 'set mp_jrn_def_id = null where mp_id=$1',
00138 array($this->mp_id));
00139 if ( strlen (trim($this->jrn_def_id))==0)
00140 $this->cn->exec_sql(
00141 'update mod_payment '.
00142 'set mp_jrn_def_id = null where mp_id=$1',
00143 array($this->mp_id));
00144 if ( strlen (trim($this->mp_qcode))==0)
00145 $this->cn->exec_sql(
00146 'update mod_payment '.
00147 'set mp_qcode = null where mp_id=$1',
00148 array($this->mp_id));
00149 if ( strlen (trim($this->mp_fd_id))==0)
00150 $this->cn->exec_sql(
00151 'update mod_payment '.
00152 'set mp_fd_id = null where mp_id=$1',
00153 array($this->mp_id));
00154
00155 }
00156
00157 public function load()
00158 {
00159 $sql='select mp_id,mp_lib,mp_fd_id,mp_jrn_def_id,mp_qcode,jrn_def_id from mod_payment '.
00160 ' where mp_id = $1';
00161 $res=$this->cn->exec_sql(
00162 $sql,
00163 array($this->mp_id)
00164 );
00165
00166 if ( Database::num_row($res) == 0 ) return;
00167 $row=Database::fetch_array($res,0);
00168 foreach ($row as $idx=>$value)
00169 {
00170 $this->$idx=$value;
00171 }
00172
00173 }
00174
00175
00176
00177 public function delete()
00178 {
00179 $sql="delete from mod_payment where mp_id=$1";
00180 $this->cn->exec_sql($sql,array($this->mp_id));
00181 }
00182
00183
00184
00185
00186 public function get_all()
00187 {
00188 $sql='select mp_id,mp_lib '.
00189 ' from mod_payment order by mp_lib';
00190 $array=$this->cn->get_array($sql);
00191 $ret=array();
00192 if ( !empty($array) )
00193 {
00194 foreach ($array as $row)
00195 {
00196 $t=new Acc_Payment($this->cn,$row['mp_id']);
00197 $t->load();
00198 $ret[]=$t;
00199 }
00200 }
00201 return $ret;
00202 }
00203
00204
00205
00206
00207
00208 public function get_valide()
00209 {
00210 $sql='select mp_id '.
00211 ' from mod_payment '.
00212 ' where jrn_def_id=$1 and mp_jrn_def_id is not null and '.
00213 ' (mp_fd_id is not null or mp_qcode is not null)';
00214 $array=$this->cn->get_array($sql,array($this->jrn_def_id));
00215 $ret=array();
00216 if ( !empty($array) )
00217 {
00218 foreach ($array as $row)
00219 {
00220 $t=new Acc_Payment($this->cn,$row['mp_id']);
00221 $t->load();
00222 $ret[]=$t;
00223 }
00224 }
00225 return $ret;
00226 }
00227
00228
00229
00230
00231 public function form()
00232 {
00233
00234 $lib=new IText('mp_lib');
00235 $lib->value=$this->mp_lib;
00236 $f_lib=$lib->input();
00237
00238
00239 $ledger_source=new ISelect('jrn_def_id');
00240 $ledger_source->value=$this->cn->make_array("select jrn_def_id,jrn_Def_name from
00241 jrn_def where jrn_def_type in ('ACH','VEN') order by jrn_def_name");
00242 $ledger_source->selected=$this->jrn_def_id;
00243 $f_source=$ledger_source->input();
00244
00245
00246 $tcard=new ISelect('mp_fd_id');
00247 $tcard->value=$this->cn->make_array('select fd_id,fd_label from fiche_def join fiche_def_ref '.
00248 ' using (frd_id) where frd_id in (25,4) order by fd_label');
00249 $tcard->selected=$this->mp_fd_id;
00250
00251 $f_type_fiche=$tcard->input();
00252 $ledger_record=new ISelect('mp_jrn_def_id');
00253 $ledger_record->value=$this->cn->make_array("select jrn_def_id,jrn_Def_name from
00254 jrn_def where jrn_def_type in ('ODS','FIN')");
00255 $ledger_record->selected=$this->mp_jrn_def_id;
00256 $f_ledger_record=$ledger_record->input();
00257
00258
00259 $qcode=new ICard();
00260 $qcode->noadd=true;
00261 $qcode->name='mp_qcode';
00262 $list=$this->cn->make_list('select fd_id from fiche_def where frd_id in (25,4)');
00263 $qcode->typecard=$list;
00264 $qcode->dblclick='fill_ipopcard(this);';
00265 $qcode->value=$this->mp_qcode;
00266
00267 $f_qcode=$qcode->input();
00268
00269 $msg="Modification de ".$this->mp_lib;
00270 ob_start();
00271 require_once('template/new_mod_payment.php');
00272 $r=ob_get_contents();
00273 ob_end_clean();
00274 return $r;
00275
00276 }
00277
00278
00279
00280
00281
00282 public function select()
00283 {
00284 $r='';
00285 $array=$this->get_valide();
00286 $r.=HtmlInput::hidden('gDossier',dossier::id());
00287
00288 if ( empty($array)==false ) {
00289 $acompte=new INum('acompte');
00290 $acompte->value=0;
00291 $r.=_(" Acompte à déduire");
00292 $r.=$acompte->input();
00293 $r.='<p>';
00294 $e_comm_paiement=new IText('e_comm_paiement');
00295 $e_comm_paiement->table = 0;
00296 $e_comm_paiement->setReadOnly(false);
00297 $e_comm_paiement->size = 60;
00298 $e_comm_paiement->tabindex = 3;
00299 $r.=_(" Libellé du paiement");
00300 $r.=$e_comm_paiement->input();
00301 $r.='</p>';
00302 }
00303
00304 $r.='<ol>';
00305 $r.='<li ><input type="radio" name="e_mp" value="0" checked>'._('Paiement encodé plus tard');
00306 if ( empty($array ) == false )
00307 {
00308 foreach ($array as $row)
00309 {
00310 $f='';
00311
00312
00313 if ( $row->mp_qcode==NULL)
00314 {
00315 $a=new ICard();
00316 $a->jrn=$row->mp_jrn_def_id;
00317 $a->set_attribute('typecard',$row->mp_fd_id);
00318 $a->name='e_mp_qcode_'.$row->mp_id;
00319 $a->set_dblclick("fill_ipopcard(this);");
00320 $a->set_callback('filter_card');
00321 $a->set_function('fill_data');
00322 $a->set_attribute('ipopup','ipopcard');
00323 $a->set_attribute('label',$a->name.'_label');
00324
00325 $s=new ISpan();
00326 $s->name=$a->name.'_label';
00327 $f=_(" paiement par ").$a->input().$s->input();
00328 }
00329 else
00330 {
00331
00332
00333
00334 $fiche=new Fiche($this->cn);
00335 $fiche->get_by_qcode($row->mp_qcode);
00336 $f=HtmlInput::hidden('e_mp_qcode_'.$row->mp_id,$row->mp_qcode);
00337
00338
00339 }
00340 $r.='<li><input type="radio" name="e_mp" value="'.$row->mp_id.'">';
00341 $r.=$row->mp_lib.' '.$f;
00342
00343 }
00344 }
00345 $r.='</ol>';
00346 return $r;
00347 }
00348
00349
00350
00351
00352 public function from_array($p_array)
00353 {
00354 $idx=array('mp_id','mp_lib','mp_fd_id','mp_jrn_def_id','mp_qcode','jrn_def_id');
00355 foreach ($idx as $l)
00356 if (isset($p_array[$l])) $this->$l=$p_array[$l];
00357 }
00358
00359
00360
00361 public function blank()
00362 {
00363
00364 $lib=new IText('mp_lib');
00365 $f_lib=$lib->input();
00366
00367 $ledger_source=new ISelect('jrn_def_id');
00368 $ledger_source->value=$this->cn->make_array("select jrn_def_id,jrn_Def_name from
00369 jrn_def where jrn_def_type in ('ACH','VEN') order by jrn_def_name");
00370 $f_source=$ledger_source->input();
00371
00372
00373 $tcard=new ISelect('mp_fd_id');
00374 $tcard->value=$this->cn->make_array('select fd_id,fd_label from fiche_def join fiche_def_ref '.
00375 ' using (frd_id) where frd_id in (25,4) order by fd_label');
00376 $f_type_fiche=$tcard->input();
00377 $ledger_record=new ISelect('mp_jrn_def_id');
00378 $ledger_record->value=$this->cn->make_array("select jrn_def_id,jrn_Def_name from
00379 jrn_def where jrn_def_type in ('ODS','FIN')");
00380 $f_ledger_record=$ledger_record->input();
00381
00382
00383 $qcode=new ICard();
00384 $qcode->noadd=true;
00385 $qcode->name='mp_qcode';
00386 $list=$this->cn->make_list('select fd_id from fiche_def where frd_id in (25,4)');
00387 $qcode->typecard=$list;
00388 $qcode->dblclick='fill_ipopcard(this);';
00389
00390 $f_qcode=$qcode->input();
00391 $msg="Ajout d'un nouveau moyen de paiement";
00392 ob_start();
00393 require_once('template/new_mod_payment.php');
00394 $r=ob_get_contents();
00395 ob_end_clean();
00396 return $r;
00397 }
00398
00399
00400 static function test_me()
00401 {
00402
00403 }
00404
00405 }
00406
00407