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                 }
00074     }
00075     public function set_parameter($p_string,$p_value)
00076     {
00077         if ( array_key_exists($p_string,self::$variable) )
00078         {
00079             $idx=self::$variable[$p_string];
00080             $this->$idx=$p_value;
00081         }
00082         else
00083             throw new Exception("Attribut inexistant $p_string");
00084 
00085 
00086     }
00087     public function get_info()
00088     {
00089         return var_export(self::$variable,true);
00090     }
00091     public function verify()
00092     {
00093         // Verify that the elt we want to add is correct
00094     }
00095     public function save()
00096     {
00097         /* please adapt */
00098         if (  $this->get_parameter("id") == 0 )
00099             $this->insert();
00100         else
00101             $this->update();
00102     }
00103 
00104     public function insert()
00105     {
00106         if ( $this->verify() != 0 ) return;
00107         $sql='INSERT INTO mod_payment(
00108              mp_lib, mp_jrn_def_id, mp_fd_id, mp_qcode,jrn_def_id)
00109              VALUES ($1, $2, $3, upper($4),$5) returning mp_id';
00110         $this->mp_id=$this->cn->exec_sql($sql,array(
00111                                              $this->mp_lib,
00112                                              $this->mp_jrn_def_id,
00113                                              $this->mp_fd_id,
00114                                              $this->mp_qcode,
00115                                              $this->jrn_def_id));
00116     }
00117 
00118     public function update()
00119     {
00120         if ( $this->verify() != 0 ) return;
00121 
00122         $sql="update mod_payment set mp_lib=$1,mp_qcode=$2,mp_jrn_def_id=$3,mp_fd_id=$4,jrn_def_id=$5 ".
00123              " where mp_id = $6";
00124         $res=$this->cn->exec_sql(
00125                  $sql,
00126                  array($this->mp_lib,
00127                        $this->mp_qcode,
00128                        $this->mp_jrn_def_id,
00129                        $this->mp_fd_id,
00130                        $this->jrn_def_id,
00131                        $this->mp_id)
00132              );
00133         if ( strlen (trim($this->mp_jrn_def_id))==0)
00134             $this->cn->exec_sql(
00135                 'update mod_payment '.
00136                 'set mp_jrn_def_id = null where mp_id=$1',
00137                 array($this->mp_id));
00138         if ( strlen (trim($this->jrn_def_id))==0)
00139             $this->cn->exec_sql(
00140                 'update mod_payment '.
00141                 'set mp_jrn_def_id = null where mp_id=$1',
00142                 array($this->mp_id));
00143         if ( strlen (trim($this->mp_qcode))==0)
00144             $this->cn->exec_sql(
00145                 'update mod_payment '.
00146                 'set mp_qcode = null where mp_id=$1',
00147                 array($this->mp_id));
00148         if ( strlen (trim($this->mp_fd_id))==0)
00149             $this->cn->exec_sql(
00150                 'update mod_payment '.
00151                 'set mp_fd_id = null where mp_id=$1',
00152                 array($this->mp_id));
00153 
00154     }
00155 
00156     public function load()
00157     {
00158         $sql='select mp_id,mp_lib,mp_fd_id,mp_jrn_def_id,mp_qcode,jrn_def_id from mod_payment '.
00159              ' where mp_id = $1';
00160         $res=$this->cn->exec_sql(
00161                  $sql,
00162                  array($this->mp_id)
00163              );
00164 
00165         if ( Database::num_row($res) == 0 ) return;
00166         $row=Database::fetch_array($res,0);
00167         foreach ($row as $idx=>$value)
00168         {
00169             $this->$idx=$value;
00170         }
00171 
00172     }
00173     /**
00174      *@brief remove a middle of payment
00175      */
00176     public function delete()
00177     {
00178         $sql="delete from mod_payment where mp_id=$1";
00179         $this->cn->exec_sql($sql,array($this->mp_id));
00180     }
00181     /*!\brief retrieve all the data for all ledgers
00182      *\param non
00183      *\return an array of row
00184      */
00185     public function get_all()
00186     {
00187         $sql='select mp_id,mp_lib '.
00188              ' from mod_payment order by mp_lib';
00189         $array=$this->cn->get_array($sql);
00190         $ret=array();
00191         if ( !empty($array) )
00192         {
00193             foreach ($array as $row)
00194             {
00195                 $t=new Acc_Payment($this->cn,$row['mp_id']);
00196                 $t->load();
00197                 $ret[]=$t;
00198             }
00199         }
00200         return $ret;
00201     }
00202     /*!\brief retrieve all the data for a ledger but filter on the
00203      *valid record (jrn and fd not null
00204      *\param non
00205      *\return an array of row
00206      */
00207     public function get_valide()
00208     {
00209         $sql='select mp_id '.
00210              ' from mod_payment '.
00211              ' where jrn_def_id=$1 and mp_jrn_def_id is not null and '.
00212              ' (mp_fd_id is not null or mp_qcode is not null)';
00213         $array=$this->cn->get_array($sql,array($this->jrn_def_id));
00214         $ret=array();
00215         if ( !empty($array) )
00216         {
00217             foreach ($array as $row)
00218             {
00219                 $t=new Acc_Payment($this->cn,$row['mp_id']);
00220                 $t->load();
00221                 $ret[]=$t;
00222             }
00223         }
00224         return $ret;
00225     }
00226     /*!\brief return a string with a form (into a table)
00227      *\param none
00228      *\return a html string
00229      */
00230     public function form()
00231     {
00232         //label
00233         $lib=new IText('mp_lib');
00234         $lib->value=$this->mp_lib;
00235                 $f_lib=$lib->input();
00236 
00237 
00238         $ledger_source=new ISelect('jrn_def_id');
00239         $ledger_source->value=$this->cn->make_array("select jrn_def_id,jrn_Def_name from
00240                               jrn_def where jrn_def_type  in ('ACH','VEN') order by jrn_def_name");
00241                 $ledger_source->selected=$this->jrn_def_id;
00242         $f_source=$ledger_source->input();
00243 
00244         // type of card
00245         $tcard=new ISelect('mp_fd_id');
00246         $tcard->value=$this->cn->make_array('select fd_id,fd_label from fiche_def join fiche_def_ref '.
00247                                             ' using (frd_id) where frd_id in (25,4) order by fd_label');
00248                 $tcard->selected=$this->mp_fd_id;
00249 
00250         $f_type_fiche=$tcard->input();
00251         $ledger_record=new ISelect('mp_jrn_def_id');
00252         $ledger_record->value=$this->cn->make_array("select jrn_def_id,jrn_Def_name from
00253                               jrn_def where jrn_def_type  in ('ODS','FIN')");
00254                 $ledger_record->selected=$this->mp_jrn_def_id;
00255         $f_ledger_record=$ledger_record->input();
00256 
00257         // the card
00258         $qcode=new ICard();
00259         $qcode->noadd=true;
00260         $qcode->name='mp_qcode';
00261         $list=$this->cn->make_list('select fd_id from fiche_def where frd_id in (25,4)');
00262         $qcode->typecard=$list;
00263                 $qcode->dblclick='fill_ipopcard(this);';
00264                 $qcode->value=$this->mp_qcode;
00265 
00266         $f_qcode=$qcode->input();
00267 
00268                 $msg="Modification de ".$this->mp_lib;
00269         ob_start();
00270         require_once('template/new_mod_payment.php');
00271         $r=ob_get_contents();
00272         ob_end_clean();
00273         return $r;
00274 
00275     }
00276     /*!\brief show several lines with radio button to select the payment
00277      *method we want to use, the $_POST['e_mp'] will be set
00278      *\param none
00279      *\return html string
00280      */
00281     public function select()
00282     {
00283         $r='';
00284         $array=$this->get_valide();
00285         $r.=HtmlInput::hidden('gDossier',dossier::id());
00286 
00287         if ( empty($array)==false ) {
00288             $acompte=new INum('acompte');
00289             $acompte->value=0;
00290             $r.=_(" Acompte à déduire");
00291             $r.=$acompte->input();
00292                         $r.='<p>';
00293                         $e_comm_paiement=new IText('e_comm_paiement');
00294                         $e_comm_paiement->table = 0;
00295                         $e_comm_paiement->setReadOnly(false);
00296                         $e_comm_paiement->size = 60;
00297                         $e_comm_paiement->tabindex = 3;
00298                         $r.=_(" Libellé du paiement");
00299                         $r.=$e_comm_paiement->input();
00300                         $r.='</p>';
00301                 }
00302 
00303         $r.='<ol>';
00304         $r.='<li ><input type="radio" name="e_mp" value="0" checked>'._('Paiement encodé plus tard');
00305         if ( empty($array ) == false )
00306         {
00307             foreach ($array as $row)
00308             {
00309                 $f='';
00310                 /* if the qcode is  null the propose a search button to select
00311                    the card */
00312                 if ( $row->mp_qcode==NULL)
00313                 {
00314                     $a=new ICard();
00315                     $a->jrn=$row->mp_jrn_def_id;
00316                                         $a->set_attribute('typecard',$row->mp_fd_id);
00317                     $a->name='e_mp_qcode_'.$row->mp_id;
00318                     $a->set_dblclick("fill_ipopcard(this);");
00319                     $a->set_callback('filter_card');
00320                     $a->set_function('fill_data');
00321                     $a->set_attribute('ipopup','ipopcard');
00322                     $a->set_attribute('label',$a->name.'_label');
00323 
00324                     $s=new ISpan();
00325                     $s->name=$a->name.'_label';
00326                     $f=_(" paiement par ").$a->input().$s->input();
00327                 }
00328                 else
00329                 {
00330                     /* if the qcode is not null then add a hidden variable with
00331                        the qcode */
00332 
00333                     $fiche=new Fiche($this->cn);
00334                     $fiche->get_by_qcode($row->mp_qcode);
00335                     $f=HtmlInput::hidden('e_mp_qcode_'.$row->mp_id,$row->mp_qcode);
00336 
00337                     //    $f.=$fiche->strAttribut(ATTR_DEF_NAME);
00338                 }
00339                 $r.='<li><input type="radio" name="e_mp" value="'.$row->mp_id.'">';
00340                 $r.=$row->mp_lib.'  '.$f;
00341 
00342             }
00343         }
00344         $r.='</ol>';
00345         return $r;
00346     }
00347 
00348     /*!\brief convert an array into an Acc_Payment object
00349      *\param array to convert
00350      */
00351     public function from_array($p_array)
00352     {
00353         $idx=array('mp_id','mp_lib','mp_fd_id','mp_jrn_def_id','mp_qcode','jrn_def_id');
00354         foreach ($idx as $l)
00355         if (isset($p_array[$l])) $this->$l=$p_array[$l];
00356     }
00357     /**
00358      *@brief return an html with a form to add a new middle of payment
00359      */
00360     public function blank()
00361     {
00362         //label
00363         $lib=new IText('mp_lib');
00364         $f_lib=$lib->input();
00365 
00366         $ledger_source=new ISelect('jrn_def_id');
00367         $ledger_source->value=$this->cn->make_array("select jrn_def_id,jrn_Def_name from
00368                               jrn_def where jrn_def_type  in ('ACH','VEN') order by jrn_def_name");
00369         $f_source=$ledger_source->input();
00370 
00371         // type of card
00372         $tcard=new ISelect('mp_fd_id');
00373         $tcard->value=$this->cn->make_array('select fd_id,fd_label from fiche_def join fiche_def_ref '.
00374                                             ' using (frd_id) where frd_id in (25,4) order by fd_label');
00375         $f_type_fiche=$tcard->input();
00376         $ledger_record=new ISelect('mp_jrn_def_id');
00377         $ledger_record->value=$this->cn->make_array("select jrn_def_id,jrn_Def_name from
00378                               jrn_def where jrn_def_type  in ('ODS','FIN')");
00379         $f_ledger_record=$ledger_record->input();
00380 
00381         // the card
00382         $qcode=new ICard();
00383         $qcode->noadd=true;
00384         $qcode->name='mp_qcode';
00385         $list=$this->cn->make_list('select fd_id from fiche_def where frd_id in (25,4)');
00386         $qcode->typecard=$list;
00387                 $qcode->dblclick='fill_ipopcard(this);';
00388 
00389         $f_qcode=$qcode->input();
00390                 $msg="Ajout d'un nouveau moyen de paiement";
00391         ob_start();
00392         require_once('template/new_mod_payment.php');
00393         $r=ob_get_contents();
00394         ob_end_clean();
00395         return $r;
00396     }
00397     /*!\brief test function
00398      */
00399     static function test_me()
00400     {
00401 
00402     }
00403 
00404 }
00405 
00406 
 All Data Structures Namespaces Files Functions Variables Enumerations