noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_acc_payment.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   NOALYSS is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /*!\file
00023  * \brief Handle the table mod_payment
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 /*!\brief Handle the table mod_payment
00033  *\note the private data member are accessed via
00034   - mp_id  ==> id ( Primary key )
00035   - mp_lib ==> lib (label)
00036   - mp_jrn_def_id ==> ledger (Number of the ledger where to save)
00037   - mp_fd_id ==> fiche_def (fiche class to use)
00038   - mp_qcode ==> qcode (quick_code of the card)
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         // Verify that the elt we want to add is correct
00095     }
00096     public function save()
00097     {
00098         /* please adapt */
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      *@brief remove a middle of payment
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     /*!\brief retrieve all the data for all ledgers
00183      *\param non
00184      *\return an array of row
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     /*!\brief retrieve all the data for a ledger but filter on the
00204      *valid record (jrn and fd not null
00205      *\param non
00206      *\return an array of row
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     /*!\brief return a string with a form (into a table)
00228      *\param none
00229      *\return a html string
00230      */
00231     public function form()
00232     {
00233         //label
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         // type of card
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         // the card
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     /*!\brief show several lines with radio button to select the payment
00278      *method we want to use, the $_POST['e_mp'] will be set
00279      *\param none
00280      *\return html string
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                 /* if the qcode is  null the propose a search button to select
00312                    the card */
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                     /* if the qcode is not null then add a hidden variable with
00332                        the qcode */
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                     //    $f.=$fiche->strAttribut(ATTR_DEF_NAME);
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     /*!\brief convert an array into an Acc_Payment object
00350      *\param array to convert
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      *@brief return an html with a form to add a new middle of payment
00360      */
00361     public function blank()
00362     {
00363         //label
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         // type of card
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         // the card
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     /*!\brief test function
00399      */
00400     static function test_me()
00401     {
00402 
00403     }
00404 
00405 }
00406 
00407 
 All Data Structures Namespaces Files Functions Variables Enumerations