noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_fiche.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 
00021 
00022 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00023 include_once("class_fiche_attr.php");
00024 require_once("class_ispan.php");
00025 require_once("class_itva_popup.php");
00026 require_once("class_itext.php");
00027 require_once("class_ihidden.php");
00028 require_once('class_fiche_def.php');
00029 require_once('class_iposte.php');
00030 
00031 /*! \file
00032  * \brief define Class fiche, this class are using
00033  *        class attribut
00034  */
00035 /*!
00036  * \brief define Class fiche and fiche def, those class are using
00037  *        class attribut. When adding or modifing new card in a IPOPUP
00038  *        the ipopup for the accounting item is ipop_account
00039  */
00040 
00041 //-----------------------------------------------------
00042 // class fiche
00043 //-----------------------------------------------------
00044 class Fiche
00045 {
00046     var $cn;           /*! < $cn database connection */
00047     var $id;           /*! < $id fiche.f_id */
00048     var $fiche_def;    /*! < $fiche_def fd_id */
00049     var $attribut;     /*! < $attribut array of attribut object */
00050     var $fiche_def_ref; /*!< $fiche_def_ref Type */
00051     var $row;           /*! < All the row from the ledgers */
00052     var $quick_code;            /*!< quick_code of the card */
00053     function __construct($p_cn,$p_id=0)
00054     {
00055         $this->cn=$p_cn;
00056         $this->id=$p_id;
00057         $this->quick_code='';
00058     }
00059     /**
00060      *@brief used with a usort function, to sort an array of Fiche on the name
00061      */
00062     static function cmp_name($o1,$o2)
00063     {
00064         return strcmp($o1->strAttribut(ATTR_DEF_NAME),$o2->strAttribut(ATTR_DEF_NAME));
00065     }
00066 
00067   /**
00068    *@brief get the available bank_account filtered by the security
00069    *@return array of card
00070    */
00071     function get_bk_account()
00072     {
00073         global $g_user;
00074       $sql_ledger=$g_user->get_ledger_sql('FIN',3);
00075       $avail=$this->cn->get_array("select jrn_def_id,jrn_def_name,"
00076               . "jrn_def_bank,jrn_def_description from jrn_def where jrn_def_type='FIN' and $sql_ledger
00077                             order by jrn_def_name");
00078 
00079       if ( count($avail) == 0 )
00080             return null;
00081 
00082       for ($i=0;$i<count($avail);$i++)
00083         {
00084             $t=new Fiche($this->cn,$avail[$i]['jrn_def_bank']);
00085             $t->ledger_name=$avail[$i]['jrn_def_name'];
00086             $t->ledger_description=$avail[$i]['jrn_def_description'];
00087             $t->getAttribut();
00088             $all[$i]=$t;
00089 
00090         }
00091         return $all;
00092     }
00093 
00094 
00095     /*!   get_by_qcode($p_qcode)
00096      * \brief Retrieve a card thx his quick_code
00097      *        complete the object,, set the id member of the object or set it
00098      *        to 0 if no card is found
00099      * \param $p_qcode quick_code (ad_id=23)
00100      * \param $p_all retrieve all the attribut of the card, possible value
00101      * are true or false. false retrieves only the f_id. By default true
00102      * \return 0 success 1 error not found
00103      */
00104     function get_by_qcode($p_qcode=null,$p_all=true)
00105     {
00106         if ( $p_qcode == null )
00107             $p_qcode=$this->quick_code;
00108         $p_qcode=trim($p_qcode);
00109         $sql="select f_id from fiche_detail
00110              where ad_id=23 and ad_value=upper($1)";
00111         $this->id=$this->cn->get_value($sql,array($p_qcode));
00112         if ( $this->cn->count()==0)
00113         {
00114             $this->id=0;
00115             return 1;
00116         }
00117 
00118 
00119         if ( $p_all )
00120             $this->getAttribut();
00121         return 0;
00122     }
00123     /**
00124      *@brief set an attribute by a value, if the attribut array is empty
00125      * a call to getAttribut is performed
00126      *@param the AD_ID
00127      *@param the value
00128      *@see constant.php table: attr_def
00129      */
00130     function setAttribut($p_ad_id,$p_value)
00131     {
00132         if ( sizeof($this->attribut)==0 ) $this->getAttribut();
00133         for ($e=0;$e <sizeof($this->attribut);$e++)
00134         {
00135             if ( $this->attribut[$e]->ad_id == $p_ad_id )
00136             {
00137                 $this->attribut[$e]->av_text=$p_value;
00138                 break;
00139             }
00140         }
00141     }
00142     /**
00143      *\brief  get all the attribute of a card, add missing ones
00144      *         and sort the array ($this->attribut) by ad_id
00145      */
00146     function getAttribut()
00147     {
00148         if ( $this->id == 0)
00149         {
00150             return;
00151         }
00152         $sql="select *
00153              from
00154                    fiche
00155              natural join fiche_detail
00156              join jnt_fic_attr on (jnt_fic_attr.fd_id=fiche.fd_id and fiche_detail.ad_id=jnt_fic_attr.ad_id)
00157              join attr_def on (attr_def.ad_id=fiche_detail.ad_id) where f_id=".$this->id.
00158              " order by jnt_order";
00159 
00160         $Ret=$this->cn->exec_sql($sql);
00161         if ( ($Max=Database::num_row($Ret)) == 0 )
00162             return ;
00163         for ($i=0;$i<$Max;$i++)
00164         {
00165             $row=Database::fetch_array($Ret,$i);
00166             $this->fiche_def=$row['fd_id'];
00167             $t=new Fiche_Attr ($this->cn);
00168             $t->ad_id=$row['ad_id'];
00169             $t->ad_text=$row['ad_text'];
00170             $t->av_text=$row['ad_value'];
00171             $t->ad_type=$row['ad_type'];
00172             $t->ad_size=$row['ad_size'];
00173             $t->ad_extra=$row['ad_extra'];
00174             $t->jnt_order=$row['jnt_order'];
00175             $this->attribut[$i]=$t;
00176         }
00177         $e=new Fiche_Def($this->cn,$this->fiche_def);
00178         $e->GetAttribut();
00179 
00180         if ( sizeof($this->attribut) != sizeof($e->attribut ) )
00181         {
00182 
00183             /*
00184                          * !! Missing attribute
00185                          */
00186             foreach ($e->attribut as $f )
00187             {
00188                 $flag=0;
00189                 foreach ($this->attribut as $g )
00190                 {
00191                     if ( $g->ad_id == $f->ad_id )
00192                         $flag=1;
00193                 }
00194                 if ( $flag == 0 )
00195                 {
00196                     // there's a missing one, we insert it
00197                     $t=new Fiche_Attr ($f->ad_id);
00198                     $t->av_text="";
00199                     $t->ad_text=$f->ad_text;
00200                     $t->jnt_order=$f->jnt_order;
00201                     $t->ad_type=$f->ad_type;
00202                     $t->ad_size=$f->ad_size;
00203                     $t->ad_id=$f->ad_id;
00204                     $t->ad_extra=$f->ad_extra;
00205                     $this->attribut[$Max]=$t;
00206                     $Max++;
00207                 } // if flag == 0
00208 
00209             }// foreach
00210 
00211 
00212         }//missing attribut
00213     }
00214     /**
00215      * @brief find the card with the p_attribut equal to p_value, it is not case sensitive
00216      * @param $p_attribut attribute to find see table attr_def
00217      * @param $p_value value in attr_value.av_text
00218      * @return return ARRAY OF jft_id,f_id,fd_id,ad_id,av_text
00219      */
00220     function seek($p_attribut,$p_value)
00221     {
00222         $sql="select jft_id,f_id,fd_id,ad_id,ad_value from fiche join fiche_detail using (f_id)
00223              where ad_id=$1 and upper(ad_value)=upper($2)";
00224         $res=$this->cn->get_array($sql,array($p_attribut,$p_value));
00225         return $res;
00226     }
00227 
00228     /*!
00229      * \brief give the size of a card object
00230      *
00231      * \return size
00232      */
00233     function size()
00234     {
00235         if ( isset ($this->ad_id))
00236             return sizeof($this->ad_id);
00237         else
00238             return 0;
00239     }
00240 
00241 
00242     /*!
00243      **************************************************
00244      * \brief  Return array of card from the frd family
00245      *
00246      * \param $p_frd_id the fiche_def_ref.frd_id
00247      * \param $p_search p_search is a filter on the name
00248      * \param $p_sql extra sql condition
00249      *
00250      * \return array of fiche object
00251      */
00252     function count_by_modele($p_frd_id,$p_search="",$p_sql="")
00253     {
00254         $sql="select *
00255              from
00256              fiche join fiche_Def using (fd_id)
00257              where frd_id=".$p_frd_id;
00258         if ( $p_search != "" )
00259         {
00260             $a=sql_string($p_search);
00261             $sql="select * from vw_fiche_attr where frd_id=".$p_frd_id.
00262                  " and vw_name ~* '$p_search'";
00263         }
00264 
00265         $Ret=$this->cn->exec_sql($sql.$p_sql);
00266 
00267         return Database::num_row($Ret) ;
00268     }
00269     /*!
00270      **************************************************
00271      * \brief  Return array of card from the frd family
00272      *
00273      *
00274      * \param  $p_frd_id the fiche_def_ref.frd_id
00275      * \param  $p_offset
00276      * \param  $p_search is an optional filter
00277      *\param $p_order : possible values are name, f_id
00278      * \return array of fiche object
00279      */
00280     function GetByDef($p_frd_id,$p_offset=-1,$p_search="",$p_order='')
00281     {
00282         switch($p_order)
00283         {
00284         case 'name' :
00285                 $order=' order by name';
00286             break;
00287         case 'f_id':
00288             $order='order by f_id';
00289             break;
00290         default:
00291             $order='';
00292         }
00293         if ( $p_offset == -1 )
00294         {
00295             $sql="select *
00296                  from
00297                  fiche join fiche_Def using (fd_id) join vw_fiche_name using(f_id)
00298                  where frd_id=".$p_frd_id." $p_search ".$order;
00299         }
00300         else
00301         {
00302             $limit=($_SESSION['g_pagesize']!=-1)?"limit ".$_SESSION['g_pagesize']:"";
00303             $sql="select *
00304                  from
00305                  fiche join fiche_Def using (fd_id) join vw_fiche_name using(f_id)
00306                  where frd_id=".$p_frd_id." $p_search $order  "
00307                  .$limit." offset ".$p_offset;
00308 
00309         }
00310 
00311         $Ret=$this->cn->exec_sql($sql);
00312         if ( ($Max=Database::num_row($Ret)) == 0 )
00313             return ;
00314         $all[0]=new Fiche($this->cn);
00315 
00316         for ($i=0;$i<$Max;$i++)
00317         {
00318             $row=Database::fetch_array($Ret,$i);
00319             $t=new Fiche($this->cn,$row['f_id']);
00320             $t->getAttribut();
00321             $all[$i]=clone $t;
00322 
00323         }
00324         return $all;
00325     }
00326     function ShowTable()
00327     {
00328         echo "<TR><TD> ".
00329         $this->id."</TD>".
00330         "<TR> <TD>".
00331         $this->attribut_value."</TD>".
00332         "<TR> <TD>".
00333         $this->attribut_def."</TD></TR>";
00334     }
00335     /*!
00336      **************************************************
00337      * \brief  return the string of the given attribute
00338      *        (attr_def.ad_id)
00339      * \param $p_ad_id the AD_ID from attr_def.ad_id
00340      * \see constant.php
00341      * \return string
00342      */
00343     function strAttribut($p_ad_id,$p_return=1)
00344     {
00345                 $return=($p_return==1)?NOTFOUND:"";
00346         if ( sizeof ($this->attribut) == 0 )
00347         {
00348 
00349             if ($this->id==0) {
00350                                         return $return;
00351                         }
00352             // object is not in memory we need to look into the database
00353             $sql="select ad_value from fiche_detail
00354                  where f_id= $1  and ad_id= $2 ";
00355             $Res=$this->cn->exec_sql($sql,array($this->id,$p_ad_id));
00356             $row=Database::fetch_all($Res);
00357             // if not found return error
00358             if ( $row == false )
00359                 return $return;
00360 
00361             return $row[0]['ad_value'];
00362         }
00363 
00364         foreach ($this->attribut as $e)
00365         {
00366             if ( $e->ad_id == $p_ad_id )
00367                 return $e->av_text;
00368         }
00369         return $return;
00370     }
00371     /**
00372      * @brief make an array of attributes of the category of card (FICHE_DEF.FD_ID)
00373      *The array can be used with the function insert, it will return a struct like this :
00374      * in the first key (av_textX),  X is the ATTR_DEF::AD_ID
00375     \verbatim
00376     Example
00377     Array
00378     (
00379       [av_text1] => Nom
00380       [av_text12] => Personne de contact
00381       [av_text5] => Poste Comptable
00382       [av_text13] => numéro de tva
00383       [av_text14] => Adresse
00384       [av_text15] => code postal
00385       [av_text24] => Ville
00386       [av_text16] => pays
00387       [av_text17] => téléphone
00388       [av_text18] => email
00389       [av_text23] => Quick Code
00390     )
00391 
00392     \endverbatim
00393      *\param $pfd_id FICHE_DEF::FD_ID
00394      *\return an array of attribute
00395      *\exception Exception if the cat of card doesn't exist, Exception.getCode()=1
00396      *\see fiche::insert()
00397      */
00398     function to_array($pfd_id)
00399     {
00400         $sql="select 'av_text'||to_char(ad_id,'9999') as key,".
00401              " ad_text ".
00402              " from fiche_def join jnt_fic_attr using (fd_id)".
00403              " join attr_def using (ad_id) ".
00404              " where fd_id=$1 order by jnt_order";
00405         $ret=$this->cn->get_array($sql,array($pfd_id));
00406         if ( empty($ret)) throw new Exception(_('Cette categorie de card n\'existe pas').' '.$pfd_id,1);
00407         $array=array();
00408         foreach($ret as $idx=>$val)
00409         {
00410             $a=str_replace(' ','',$val['key']);
00411             $array[$a]=$val['ad_text'];
00412         }
00413         return $array;
00414 
00415     }
00416     /*!
00417      * \brief  insert a new record
00418      *         show a blank card to be filled
00419      *
00420      * \param  $p_fiche_def is the fiche_def.fd_id
00421      *
00422      * \return HTML Code
00423      */
00424     function blank($p_fiche_def)
00425     {
00426         // array = array of attribute object sorted on ad_id
00427         $f=new Fiche_Def($this->cn,$p_fiche_def);
00428         $f->get();
00429         $array=$f->getAttribut();
00430         $r=h2('Catégorie '.$f->label,"");
00431         $r.='<table style="width:98%;margin:1%">';
00432         foreach ($array as $attr)
00433         {
00434             $table=0;
00435             $msg="";$bulle='';
00436             if ( $attr->ad_id == ATTR_DEF_ACCOUNT)
00437             {
00438                 $w=new IPoste("av_text".$attr->ad_id);
00439                 $w->set_attribute('ipopup','ipop_account');
00440                 $w->set_attribute('account',"av_text".$attr->ad_id);
00441                                 $w->dbl_click_history();
00442                 //  account created automatically
00443                 $sql="select account_auto($p_fiche_def)";
00444                 $ret_sql=$this->cn->exec_sql($sql);
00445                 $a=Database::fetch_array($ret_sql,0);
00446                 $label=new ISpan();
00447                 $label->name="av_text".$attr->ad_id."_label";
00448 
00449                 if ( $a['account_auto'] == 't' )
00450                     $msg.=$label->input()." <span style=\"color:red\">".
00451                                                 _("Rappel: Poste créé automatiquement à partir de ")
00452                                                 .$f->class_base." </span> ";
00453                 else
00454                 {
00455                     // if there is a class base in fiche_def_ref, this account will be the
00456                     // the default one
00457                     if ( strlen(trim($f->class_base)) != 0 )
00458                     {
00459                         $msg.="<TD>".$label->input()." <span style=\"color:red\">"._("Rappel: Poste par défaut sera ").
00460                               $f->class_base.
00461                               " !</span> ";
00462                         $w->value=$f->class_base;
00463                     }
00464 
00465                 }
00466                 $r.="<TR>".td("Poste Comptable",' class="input_text" ' ).td($w->input().$msg)."</TR>";
00467                 continue;
00468             }
00469             elseif ( $attr->ad_id == ATTR_DEF_TVA)
00470             {
00471                 $w=new ITva_Popup('popup_tva');
00472                 $w->table=1;
00473             }
00474 
00475             else
00476             {
00477               switch ($attr->ad_type)
00478                                 {
00479                                         case 'text':
00480                                                 $w = new IText();
00481                                                 $w->css_size = "100%";
00482                                                 break;
00483                                         case 'numeric':
00484                                                 $w = new INum();
00485                                                 $w->prec=($attr->ad_extra=="")?2:$attr->ad_extra;
00486                                                 $w->size = $attr->ad_size;
00487                                                 break;
00488                                         case 'date':
00489                                                 $w = new IDate();
00490                                                 break;
00491                                         case 'zone':
00492                                                 $w = new ITextArea();
00493                                                 $w->style=' class="itextarea" style="margin:0px;width:100%"';
00494                                                 break;
00495                                         case 'poste':
00496                                                 $w = new IPoste("av_text" . $attr->ad_id);
00497                                                 $w->set_attribute('ipopup', 'ipop_account');
00498                                                 $w->set_attribute('account', "av_text" . $attr->ad_id);
00499                                                 $w->table = 1;
00500                                                 $bulle = HtmlInput::infobulle(14);
00501                                                 break;
00502                                         case 'select':
00503                                                 $w = new ISelect("av_text" . $attr->ad_id);
00504                                                 $w->value = $this->cn->make_array($attr->ad_extra);
00505                                                 $w->style= 'style="width:100%"';
00506                                                 break;
00507                                         case 'card':
00508                                                 $w = new ICard("av_text" . $attr->ad_id);
00509                                                 // filter on frd_id
00510                                                 $w->extra = $attr->ad_extra;
00511                                                 $w->extra2 = 0;
00512                                                 $label = new ISpan();
00513                                                 $label->name = "av_text" . $attr->ad_id . "_label";
00514                                                 $w->set_attribute('ipopup', 'ipopcard');
00515                                                 $w->set_attribute('typecard', $attr->ad_extra);
00516                                                 $w->set_attribute('inp', "av_text" . $attr->ad_id);
00517                                                 $w->set_attribute('label', "av_text" . $attr->ad_id . "_label");
00518                                                 $msg = $w->search();
00519                                                 $msg.=$label->input();
00520                                                 break;
00521                                 }
00522                                 $w->table = 0;
00523                         }
00524                         $w->table = $table;
00525                         $w->label = $attr->ad_text;
00526                         $w->name = "av_text" . $attr->ad_id;
00527                         if ($attr->ad_id == 21 || $attr->ad_id==22||$attr->ad_id==20||$attr->ad_id==31)
00528                         {
00529                                 $bulle=HtmlInput::infobulle(21);
00530                         }
00531                         $r.="<TR>" . td($w->label." $bulle", ' class="input_text" ') . td($w->input()." $msg")." </TR>";
00532                 }
00533                 $r.= '</table>';
00534         return $r;
00535     }
00536 
00537 
00538     /*!
00539      * \brief  Display object instance, getAttribute
00540      *        sort the attribute and add missing ones
00541      * \param $p_readonly true= if can not modify, otherwise false
00542      *
00543      *
00544      * \return string to display or FNT string for fiche non trouvé
00545      */
00546     function Display($p_readonly)
00547     {
00548                 $this->GetAttribut();
00549                 $attr = $this->attribut;
00550                 /* show card type here */
00551                 $type_card = $this->cn->get_value('select fd_label from fiche_def join fiche using (fd_id) where f_id=$1', array($this->id));
00552                 $ret = "";
00553                 $ret.=h2( "Catégorie ".$type_card, 'style="display:inline"');
00554                 $ret.='<span style="font-weight:bolder;margin-right:5px;float:right"> id fiche:' . $this->id . "</span>";
00555                 $ret.="<table style=\"width:98%;margin:1%\">";
00556                 if (empty($attr))
00557                 {
00558                         return 'FNT';
00559                 }
00560 
00561                 /* for each attribute */
00562                 foreach ($attr as $r)
00563                 {
00564                         $msg = "";
00565                         $bulle = "";
00566                         if ($p_readonly)
00567                         {
00568                                 $w = new IText();
00569                                 $w->table = 1;
00570                                 $w->readOnly = true;
00571                                 $w->css_size = "100%";
00572                         }
00573                         if ($p_readonly == false)
00574                         {
00575 
00576                                 if ($r->ad_id == ATTR_DEF_ACCOUNT)
00577                                 {
00578                                         $w = new IPoste("av_text" . $r->ad_id);
00579                                         $w->set_attribute('ipopup', 'ipop_account');
00580                                         $w->set_attribute('account', "av_text" . $r->ad_id);
00581                                         $w->dbl_click_history();
00582                                         //  account created automatically
00583                                         $w->table = 0;
00584                                         $w->value = $r->av_text;
00585                                         //  account created automatically
00586                                         $sql = "select account_auto($this->fiche_def)";
00587                                         $ret_sql = $this->cn->exec_sql($sql);
00588                                         $a = Database::fetch_array($ret_sql, 0);
00589                                         $bulle = HtmlInput::infobulle(10);
00590 
00591                                         if ($a['account_auto'] == 't')
00592                                                 $bulle.=HtmlInput::warnbulle(11);
00593                                 }
00594                                 elseif ($r->ad_id == ATTR_DEF_TVA)
00595                                 {
00596                                         $w = new ITva_Popup('popup_tva');
00597                                         $w->table = 1;
00598                                         $w->value = $r->av_text;
00599                                 }
00600                                 else
00601                                 {
00602                                         switch ($r->ad_type)
00603                                         {
00604                                                 case 'text':
00605                                                         $w = new IText('av_text' . $r->ad_id);
00606                                                         $w->css_size = "100%";
00607                                                         $w->value = $r->av_text;
00608                                                         break;
00609                                                 case 'numeric':
00610                                                         $w = new INum('av_text' . $r->ad_id);
00611                                                         $w->size = $r->ad_size;
00612                                                         $w->prec=($r->ad_extra=="")?2:$r->ad_extra;
00613                                                         $w->value = $r->av_text;
00614                                                         break;
00615                                                 case 'date':
00616                                                         $w = new IDate('av_text' . $r->ad_id);
00617                                                         $w->value = $r->av_text;
00618                                                         break;
00619                                                 case 'zone':
00620                                                         $w = new ITextArea('av_text' . $r->ad_id);
00621                                                         $w->style=' class="itextarea" style="margin:0px;width:100%"';
00622                                                         $w->value = $r->av_text;
00623                                                         break;
00624                                                 case 'poste':
00625                                                         $w = new IPoste("av_text" . $r->ad_id);
00626                                                         $w->set_attribute('ipopup', 'ipop_account');
00627                                                         $w->set_attribute('account', "av_text" . $r->ad_id);
00628                                                         $w->dbl_click_history();
00629                                                         $w->width = $r->ad_size;
00630                                                         $w->table = 0;
00631                                                         $bulle = HtmlInput::infobulle(14);
00632                                                         $w->value = $r->av_text;
00633                                                         break;
00634                                                 case 'card':
00635                                                         $uniq=rand(0,1000);
00636                                                         $w = new ICard("av_text" . $r->ad_id);
00637                                                         $w->id="card_".$this->id.$uniq;
00638                                                         // filter on ad_extra
00639 
00640                                                         $filter = $r->ad_extra;
00641                                                         $w->width = $r->ad_size;
00642                                                         $w->extra = $filter;
00643                                                         $w->extra2 = 0;
00644                                                         $label = new ISpan();
00645                                                         $label->name = "av_text" .$uniq. $r->ad_id . "_label";
00646                                                         $fiche=new Fiche($this->cn);
00647                                                         $fiche->get_by_qcode($r->av_text);
00648                                                         if ($fiche->id == 0 )
00649                                                         {
00650                                                                 $label->value=(trim($r->av_text)=='')?"":" Fiche non trouvé ";
00651                                                                 $r->av_text="";
00652                                                         } else
00653                                                         {
00654                                                                 $label->value=$fiche->strAttribut(ATTR_DEF_NAME)." ".$fiche->strAttribut(ATTR_DEF_FIRST_NAME,0);
00655                                                         }
00656                                                         $w->set_attribute('ipopup', 'ipopcard');
00657                                                         $w->set_attribute('typecard', $filter);
00658                                                         $w->set_attribute('inp', "av_text" . $r->ad_id);
00659                                                         $w->set_attribute('label', $label->name);
00660                                                         $w->autocomplete=0;
00661                                                         $w->dblclick="fill_ipopcard(this);";
00662                                                         $msg = $w->search();
00663                                                         $msg.=$label->input();
00664                                                         $w->value = $r->av_text;
00665                                                         break;
00666                                                 case 'select':
00667                                                         $w = new ISelect();
00668                                                         $w->value = $this->cn->make_array($r->ad_extra);
00669                                                         $w->selected = $r->av_text;
00670                                                         $w->style = ' style="width:100%" ';
00671                                                         break;
00672                                                 default:
00673                                                         var_dump($r);
00674                                                         throw new Exception("Type invalide");
00675                                         }
00676                                         $w->table = 0;
00677                                 }
00678                         }
00679                         else
00680                         {
00681                                 switch ($r->ad_type)
00682                                 {
00683                                         case 'select':
00684                                                 $x = new ISelect();
00685                                                 $x->value = $this->cn->make_array($r->ad_extra);
00686                                                 $x->selected = $r->av_text;
00687                                                 $value = $x->display();
00688                                                 $w->value = $value;
00689                                                 break;
00690                                         default:
00691                                                 $w->value = $r->av_text;
00692                                 }
00693                         }
00694 
00695                         $w->name = "av_text" . $r->ad_id;
00696                         $w->readOnly = $p_readonly;
00697 
00698                         if ($r->ad_id == 21 || $r->ad_id==22||$r->ad_id==20||$r->ad_id==31)
00699                         {
00700                                 $bulle=HtmlInput::infobulle(21);
00701                         }
00702                         $ret.="<TR>" . td($r->ad_text . $bulle) . td($w->input()." ". $msg) . " </TR>";
00703                 }
00704 
00705                 $ret.="</table>";
00706 
00707                 return $ret;
00708         }
00709     /*!
00710      * \brief  Save a card, call insert or update
00711      *
00712      * \param p_fiche_def (default 0)
00713      */
00714     function Save($p_fiche_def=0)
00715     {
00716         // new card or only a update ?
00717         if ( $this->id == 0 )
00718             $this->insert($p_fiche_def);
00719         else
00720             $this->update();
00721     }
00722     /*!
00723      * \brief  insert a new record
00724      *
00725      * \param $p_fiche_def fiche_def.fd_id
00726      * \param $p_array is the array containing the data
00727      *\param $transation if we want to manage the transaction in this function
00728      * true for small insert and false for a larger loading, the BEGIN / COMMIT sql
00729      * must be done into the caller
00730      av_textX where X is the ad_id
00731      *\verb
00732     example
00733     av_text1=>'name'
00734     \endverb
00735      */
00736     function insert($p_fiche_def,$p_array=null,$transaction=true)
00737     {
00738         if ( $p_array == null)
00739             $p_array=$_POST;
00740 
00741         $fiche_id=$this->cn->get_next_seq('s_fiche');
00742         $this->id=$fiche_id;
00743         // first we create the card
00744         if ( $transaction)    $this->cn->start();
00745         /*
00746          * Sort the array for having the name AFTER the quickcode and the 
00747          * Accounting
00748          */
00749         ksort($p_array);
00750         
00751         try
00752         {
00753             $sql=sprintf("insert into fiche(f_id,fd_id)".
00754                          " values (%d,%d)",
00755                          $fiche_id,$p_fiche_def);
00756             $Ret=$this->cn->exec_sql($sql);
00757             // parse the $p_array array
00758             foreach ($p_array as $name=>$value )
00759             {
00760                 /* avoid the button for searching an accounting item */
00761               if ( preg_match('/^av_text[0-9]+$/',$name) == 0) continue;
00762 
00763               list ($id) = sscanf ($name,"av_text%d");
00764               if ( $id == null ) continue;
00765 
00766                 // Special traitement
00767                 // quickcode
00768                 if ( $id == ATTR_DEF_QUICKCODE)
00769                 {
00770                     $sql=sprintf("select insert_quick_code(%d,'%s')",
00771                                  $fiche_id,sql_string($value));
00772                     $this->cn->exec_sql($sql);
00773                     continue;
00774                 }
00775                 // name
00776                 if ( $id == ATTR_DEF_NAME )
00777                 {
00778                     if ( strlen(trim($value)) == 0 )
00779                         $value="pas de nom";
00780 
00781                 }
00782                 // account
00783                 if ( $id == ATTR_DEF_ACCOUNT )
00784                 {
00785                     $v=sql_string($value);
00786                     try
00787                     {
00788 
00789                         if ( strlen(trim($v)) != 0)
00790                         {
00791                                                         if( strpos($value,',')==0)
00792                                                         {
00793                                                                 $v=$this->cn->get_value("select format_account($1)",array($value));
00794                                                         } else {
00795                                                                 $ac_array = explode(",", $value);
00796                                                                 if (count($ac_array) <> 2)
00797                                                                         throw new Exception('Désolé, il y a trop de virgule dans le poste comptable ' . h($value));
00798                                                                 $part1 = $ac_array[0];
00799                                                                 $part2 = $ac_array[1];
00800                                                                 $part1 = $this->cn->get_value('select format_account($1)', array($part1));
00801                                                                 $part2 = $this->cn->get_value('select format_account($1)', array($part2));
00802                                                                 $v = $part1 . ',' . $part2;
00803                                                         }
00804                             $parameter=array($this->id,$v);
00805                         }
00806                         else
00807                         {
00808                             $parameter=array($this->id,null);
00809                         }
00810                         $v=$this->cn->get_value("select account_insert($1,$2)",$parameter);
00811                     }
00812                     catch (Exception $e)
00813                     {
00814                         throw new Exception ("Erreur : ce compte [$v] n'a pas de compte parent.".
00815                                              "L'opération est annulée",
00816                                              1);
00817                     }
00818                     continue;
00819                 }
00820                 // TVA
00821                 if ( $id == ATTR_DEF_TVA )
00822                 {
00823                     // Verify if the rate exists, if not then do not update
00824                     if ( strlen(trim($value)) != 0 )
00825                     {
00826                         if ( isNumber($value) == 0 ) continue;
00827                         if ( $this->cn->count_sql("select * from tva_rate where tva_id=".$value) == 0)
00828                         {
00829                             continue;
00830                         }
00831                     }
00832                 }
00833                 // Normal traitement
00834                 $value2=sql_string($value);
00835 
00836                 $sql=sprintf("select attribut_insert(%d,%d,'%s')",
00837                              $fiche_id,$id,  strip_tags(trim($value2)));
00838                 $this->cn->exec_sql($sql);
00839             }
00840         }
00841         catch (Exception $e)
00842         {
00843             $this->cn->rollback();
00844             throw ($e);
00845             return;
00846         }
00847         if ( $transaction)         $this->cn->commit();
00848         return;
00849     }
00850 
00851 
00852 
00853     /*!\brief update a card
00854      */
00855     function update($p_array=null)
00856     {
00857         global $g_user;
00858         if ( $p_array == null)
00859             $p_array=$_POST;
00860 
00861         try
00862         {
00863             $this->cn->start();
00864             // parse the $p_array array
00865             foreach ($p_array as $name=>$value )
00866             {
00867                 if ( preg_match('/^av_text[0-9]+$/',$name) == 0) continue;
00868 
00869                 list ($id) = sscanf ($name,"av_text%d");
00870 
00871                 if ( $id == null ) continue;
00872 
00873                 // retrieve jft_id to update table attr_value
00874                 $sql=" select jft_id from fiche_detail where ad_id=$id and f_id=$this->id";
00875                 $Ret=$this->cn->exec_sql($sql);
00876                 if ( Database::num_row($Ret) == 0 )
00877                 {
00878                     // we need to insert this new attribut
00879                     $jft_id=$this->cn->get_next_seq('s_jnt_fic_att_value');
00880 
00881                     $sql2="insert into fiche_detail(jft_id,ad_id,f_id,ad_value) values ($1,$2,$3,NULL)";
00882 
00883                     $ret2=$this->cn->exec_sql($sql2,array($jft_id,$id,$this->id));
00884 
00885                 }
00886                 else
00887                 {
00888                     $tmp=Database::fetch_array($Ret,0);
00889                     $jft_id=$tmp['jft_id'];
00890                 }
00891                 // Special traitement
00892                 // quickcode
00893                 if ( $id == ATTR_DEF_QUICKCODE)
00894                 {
00895                     $sql=sprintf("select update_quick_code(%d,'%s')",
00896                                  $jft_id,sql_string($value));
00897                     $this->cn->exec_sql($sql);
00898                     continue;
00899                 }
00900                 // name
00901                 if ( $id == ATTR_DEF_NAME )
00902                 {
00903                     if ( strlen(trim($value)) == 0 )
00904                         continue;
00905 
00906 
00907                 }
00908                 // account
00909                 if ($id == ATTR_DEF_ACCOUNT)
00910                                 {
00911                                         $v = sql_string($value);
00912                                         if (trim($v) != '')
00913                                         {
00914                                                 if (strpos($v, ',') != 0)
00915                                                 {
00916                                                         $ac_array = explode(",", $v);
00917                                                         if (count($ac_array) <> 2)
00918                                                                 throw new Exception('Désolé, il y a trop de virgule dans le poste comptable ' . h($v));
00919                                                         $part1 = $ac_array[0];
00920                                                         $part2 = $ac_array[1];
00921                                                         $part1 = $this->cn->get_value('select format_account($1)', array($part1));
00922                                                         $part2 = $this->cn->get_value('select format_account($1)', array($part2));
00923                                                         $v = $part1 . ',' . $part2;
00924                                                 }
00925                                                 else
00926                                                 {
00927                                                         $v=$this->cn->get_value('select format_account($1)',array($value));
00928                                                 }
00929                                                 $sql = sprintf("select account_update(%d,'%s')", $this->id, $v);
00930                                                 try
00931                                                 {
00932                                                         $this->cn->exec_sql($sql);
00933                                                 }
00934                                                 catch (Exception $e)
00935                                                 {
00936                                                         throw new Exception(__LINE__ . "Erreur : ce compte [$v] n'a pas de compte parent." .
00937                                                                         "L'op&eacute;ration est annul&eacute;e");
00938                                                 }
00939                                                 continue;
00940                                         }
00941                                         if (strlen(trim($v)) == 0)
00942                                         {
00943 
00944                                                 $sql = sprintf("select account_update(%d,null)", $this->id);
00945                                                 try
00946                                                 {
00947                                                         $Ret = $this->cn->exec_sql($sql);
00948                                                 }
00949                                                 catch (Exception $e)
00950                                                 {
00951                                                         throw new Exception(__LINE__ . "Erreur : ce compte [$v] n'a pas de compte parent." .
00952                                                                         "L'opération est annulée");
00953                                                 }
00954 
00955                                                 continue;
00956                                         }
00957                                 }
00958                 // TVA
00959                 if ( $id == ATTR_DEF_TVA )
00960                 {
00961                     // Verify if the rate exists, if not then do not update
00962                     if ( strlen(trim($value)) != 0 )
00963                     {
00964                         if ( $this->cn->count_sql("select * from tva_rate where tva_id=".$value) == 0)
00965                         {
00966                             continue;
00967                         }
00968                     }
00969                 }
00970                 // Normal traitement
00971                 $sql="update fiche_detail set ad_value=$1 where jft_id=$2";
00972                                 $this->cn->exec_sql($sql,array(strip_tags($value),$jft_id));
00973             }
00974         }
00975         catch (Exception $e )
00976         {
00977             echo '<span class="error">'.
00978             $e->getMessage().
00979             '</span>';
00980             $this->cn->rollback();
00981             return;
00982         }
00983         $this->cn->commit();
00984         return;
00985 
00986     }
00987     /*!\brief  remove a card
00988     */
00989     function remove($silent=false)
00990     {
00991         if ( $this->id==0 ) return;
00992         // verify if that card has not been used is a ledger
00993         // if the card has its own account in PCMN
00994         // Get the fiche_def.fd_id from fiche.f_id
00995         $this->Get();
00996         $fiche_def=new Fiche_Def($this->cn,$this->fiche_def);
00997         $fiche_def->get();
00998 
00999         // if the card is used do not removed it
01000         $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
01001 
01002         if ( $this->cn->count_sql("select * from jrnx where j_qcode='".Database::escape_string($qcode)."'") != 0)
01003         {
01004             if ( ! $silent ) {
01005                                         alert('Impossible cette fiche est utilisée dans un journal');
01006                         }
01007             return 1;
01008         }
01009 
01010         $this->delete();
01011                 return 0;
01012     }
01013 
01014 
01015     /*!\brief return the name of a card
01016      *
01017      */
01018     function getName()
01019     {
01020         $sql="select ad_value from fiche_detail
01021              where ad_id=1 and f_id=$1";
01022         $Res=$this->cn->exec_sql($sql,array($this->id));
01023         $r=Database::fetch_all($Res);
01024         if ( sizeof($r) == 0 )
01025             return 1;
01026         return $r[0]['ad_value'];
01027     }
01028 
01029     /*!\brief return the quick_code of a card
01030      * \return null if not quick_code is found
01031      */
01032     function get_quick_code()
01033     {
01034         $sql="select ad_value from fiche_detail where ad_id=23 and f_id=$1";
01035         $Res=$this->cn->exec_sql($sql,array($this->id));
01036         $r=Database::fetch_all($Res);
01037         if ( sizeof($r) == 0 )
01038             return null;
01039         return $r[0]['ad_value'];
01040     }
01041 
01042     /*!\brief Synonum of fiche::getAttribut
01043      */
01044     function Get()
01045     {
01046         $this->getAttribut();
01047     }
01048     /*!\brief get all the card thanks the fiche_def_ref
01049      * \param $p_offset (default =-1)
01050      * \param $p_search sql condition
01051      * \return array of fiche object
01052      */
01053     function get_by_category($p_offset=-1,$p_search="",$p_order='')
01054     {
01055         return fiche::GetByDef($this->fiche_def_ref,$p_offset,$p_search,$p_order);
01056     }
01057     /*!\brief retrieve the frd_id of the fiche it is the type of the
01058      *        card (bank, purchase...)
01059      *        (fiche_def_ref primary key)
01060      */
01061     function get_fiche_def_ref_id()
01062     {
01063         $result=$this->cn->get_array("select frd_id from fiche join fiche_Def using (fd_id) where f_id=".$this->id);
01064         if ( $result == null )
01065             return null;
01066 
01067         return $result[0]['frd_id'];
01068     }
01069     /**
01070      *@brief fetch and return and array
01071      *@see get_row get_row_date
01072      */
01073     private function get_row_result($res)
01074     {
01075         $array=array();
01076         $tot_cred=0.0;
01077         $tot_deb=0.0;
01078         $Max=Database::num_row($res);
01079         if ( $Max == 0 ) return null;
01080         for ($i=0;$i<$Max;$i++)
01081         {
01082             $array[]=Database::fetch_array($res,$i);
01083             if ($array[$i]['j_debit']=='t')
01084             {
01085                 $tot_deb+=$array[$i]['deb_montant'] ;
01086             }
01087             else
01088             {
01089                 $tot_cred+=$array[$i]['cred_montant'] ;
01090             }
01091         }
01092         $this->row=$array;
01093         return array($array,$tot_deb,$tot_cred);
01094     }
01095     /*!
01096      * \brief  Get data for poste
01097      *
01098      * \param  $p_from periode from
01099      * \param  $p_to   end periode
01100      *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered one
01101      * \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
01102      *         (tot_deb,tot_credit
01103      *
01104      */
01105     function get_row_date($p_from,$p_to,$op_let=0)
01106     {
01107         global $g_user;
01108         if ( $this->id == 0 )
01109         {
01110             echo_error("class_fiche",__LINE__,"id is 0");
01111             return;
01112         }
01113         $filter_sql=$g_user->get_ledger_sql('ALL',3);
01114         $sql_let='';
01115         switch ($op_let)
01116         {
01117         case 0:
01118             break;
01119         case 1:
01120             $sql_let=' and j_id in (select j_id from letter_cred union select j_id from letter_deb)';
01121             break;
01122         case '2':
01123             $sql_let=' and j_id not in (select j_id from letter_cred union select j_id from letter_deb) ';
01124             break;
01125         }
01126 
01127         $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
01128         $Res=$this->cn->exec_sql("select distinct substring(jr_pj_number,'[0-9]+$'),j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_qcode,".
01129                                  "case when j_debit='t' then j_montant else 0 end as deb_montant,".
01130                                  "case when j_debit='f' then j_montant else 0 end as cred_montant,".
01131                                  " jr_comment as description,jrn_def_name as jrn_name,".
01132                                  " jr_pj_number,".
01133                                  "j_debit, jr_internal,jr_id,coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter, ".
01134                                  " jr_tech_per,p_exercice,
01135                                                                   jrn_def_code".
01136                                  " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ".
01137                                  " left join jrn on jr_grpt_id=j_grpt".
01138                                  " left join parm_periode on (p_id=jr_tech_per) ".
01139                                  " where j_qcode=$1 and ".
01140                                  " ( to_date($2,'DD.MM.YYYY') <= j_date and ".
01141                                  "   to_date($3,'DD.MM.YYYY') >= j_date )".
01142                                  " and $filter_sql $sql_let ".
01143                                  " order by j_date,substring(jr_pj_number,'[0-9]+$')",array($qcode,$p_from,$p_to));
01144 
01145         return $this->get_row_result($Res);
01146     }
01147 
01148     /*!
01149      * \brief  Get data for poste
01150      *
01151      * \param  $p_from periode from
01152      * \param  $p_to   end periode
01153      * \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
01154      *         (tot_deb,tot_credit
01155      *
01156      */
01157     function get_row($p_from,$p_to)
01158     {
01159         if ( $this->id == 0 )
01160         {
01161             echo_error("class_fiche",__LINE__,"id is 0");
01162             return;
01163         }
01164         $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
01165         $periode=sql_filter_per($this->cn,$p_from,$p_to,'p_id','jr_tech_per');
01166 
01167         $Res=$this->cn->exec_sql("select j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_qcode,".
01168                                  "case when j_debit='t' then j_montant else 0 end as deb_montant,".
01169                                  "case when j_debit='f' then j_montant else 0 end as cred_montant,".
01170                                  " jr_comment as description,jrn_def_name as jrn_name,".
01171                                  "j_debit, jr_internal,jr_id ".
01172                                  " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ".
01173                                  " left join jrn on jr_grpt_id=j_grpt".
01174                                  " where j_qcode='".$qcode."' and ".$periode.
01175                                  " order by j_date::date");
01176         return $this->get_row_result($Res);
01177 
01178     }
01179     /*!
01180      * \brief HtmlTable, display a HTML of a card for the asked period
01181      *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered one
01182      * \return none
01183      */
01184     function HtmlTableDetail($p_array=null,$op_let=0)
01185     {
01186         if ( $p_array == null)
01187             $p_array=$_REQUEST;
01188 
01189         $name=$this->getName();
01190 
01191         list($array,$tot_deb,$tot_cred)=$this->get_row_date( $p_array['from_periode'],
01192                                         $p_array['to_periode'],
01193                                         $op_let
01194                                                            );
01195 
01196         if ( count($this->row ) == 0 )
01197             return;
01198         $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
01199 
01200         $rep="";
01201         $already_seen=array();
01202         echo '<h2 class="info">'.$this->id." ".$name.'</h2>';
01203         echo "<TABLE class=\"result\" style=\"width:100%;border-collapse:separate;border-spacing:5px\">";
01204         echo "<TR>".
01205         "<TH> n° de pièce / Code interne </TH>".
01206         "<TH> Date</TH>".
01207         "<TH> Description </TH>".
01208         "<TH> Montant  </TH>".
01209         "<TH> Débit/Crédit </TH>".
01210         "</TR>";
01211 
01212         foreach ( $this->row as $op )
01213         {
01214             if ( in_array($op['jr_internal'],$already_seen) )
01215                 continue;
01216             else
01217                 $already_seen[]=$op['jr_internal'];
01218             echo "<TR  style=\"text-align:center;background-color:lightgrey\">".
01219             "<td>".$op['jr_pj_number']." / ".$op['jr_internal']."</td>".
01220             "<td>".$op['j_date']."</td>".
01221             "<td>".h($op['description'])."</td>".
01222             "<td>"."</td>".
01223             "<td>"."</td>".
01224             "</TR>";
01225             $ac=new Acc_Operation($this->cn);
01226             $ac->jr_id=$op['jr_id'];
01227             $ac->qcode=$qcode;
01228             echo $ac->display_jrnx_detail(1);
01229 
01230         }
01231         $solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde créditeur";
01232         $diff=round(abs($tot_deb-$tot_cred),2);
01233         echo "<TR>".
01234         "<TD>$solde_type".
01235         "<TD>$diff</TD>".
01236         "<TD></TD>".
01237         "<TD>$tot_deb</TD>".
01238         "<TD>$tot_cred</TD>".
01239         "</TR>";
01240 
01241         echo "</table>";
01242 
01243         return;
01244     }
01245     /*!
01246      * \brief HtmlTable, display a HTML of a card for the asked period
01247      * \param $p_array default = null keys = from_periode, to_periode
01248      *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered one
01249      *\return -1 if nothing is found otherwise 0
01250      *\see get_row_date
01251      */
01252     function HtmlTable($p_array=null,$op_let=0,$from_div=1)
01253     {
01254         if ( $p_array == null)
01255             $p_array=$_REQUEST;
01256         $progress=0;
01257                 // if from_periode is greater than to periode then swap the values
01258                 if (cmpDate($p_array['from_periode'],$p_array['to_periode']) > 0)
01259                 {
01260                         $tmp=$p_array['from_periode'];
01261                         $p_array['from_periode']=$p_array['to_periode'];
01262                         $p_array['to_periode']=$tmp;
01263 
01264                 }
01265         list($array, $tot_deb, $tot_cred) = $this->get_row_date($p_array['from_periode'], $p_array['to_periode'], $op_let);
01266 
01267         if ( count($this->row ) == 0 )
01268             return -1;
01269 
01270         $rep="";
01271         if ( $from_div==1)
01272           {
01273             echo "<TABLE class=\"resultfooter\" style=\"margin:1%;width:98%;;border-collapse:separate;border-spacing:0px 5px\">";
01274           }
01275         else
01276           {
01277             echo "<TABLE id=\"tb" . $from_div . "\"class=\"result\" style=\"margin:1%;width:98%;border-collapse:separate;border-spacing:0px 2px\">";
01278                 }
01279         echo '<tbody>';
01280         echo "<TR>".
01281         "<TH style=\"text-align:left\">"._('Date')."</TH>".
01282         "<TH style=\"text-align:left\">"._('n° pièce')." </TH>".
01283         "<TH style=\"text-align:left\">"._('Code interne')." </TH>".
01284         "<TH style=\"text-align:left\">"._('Description')." </TH>".
01285         "<TH style=\"text-align:right\">"._('Débit')."  </TH>".
01286         "<TH style=\"text-align:right\">"._('Crédit')." </TH>".
01287         th('Prog.','style="text-align:right"').
01288         th('Let.','style="text-align:right"');
01289         "</TR>"
01290         ;
01291         $old_exercice="";$sum_deb=0;$sum_cred=0;
01292         bcscale(2);
01293         $idx=0;
01294         foreach ( $this->row as $op )
01295         {
01296             $vw_operation = sprintf('<A class="detail" style="text-decoration:underline;color:red" HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s</A>', $op['jr_id'], dossier::id(), $op['jr_internal']);
01297             $let = '';
01298                         $html_let = "";
01299                         if ($op['letter'] != -1)
01300                         {
01301                                 $let = strtoupper(base_convert($op['letter'], 10, 36));
01302                                 $html_let = HtmlInput::show_reconcile($from_div, $let);
01303                         }
01304                         $tmp_diff=bcsub($op['deb_montant'],$op['cred_montant']);
01305 
01306             /*
01307              * reset prog. balance to zero if we change of exercice
01308              */
01309             if ( $old_exercice != $op['p_exercice'])
01310               {
01311                 if ($old_exercice != '' )
01312                   {
01313                     $progress=bcsub($sum_deb,$sum_cred);
01314                         $side="&nbsp;".$this->get_amount_side($progress);
01315                     echo "<TR  style=\"font-weight:bold\">".
01316                       "<TD></TD>".
01317                       td('').
01318                       "<TD></TD>".
01319                       "<TD>Totaux</TD>".
01320                       "<TD style=\"text-align:right\">".nbm($sum_deb)."</TD>".
01321                       "<TD style=\"text-align:right\">".nbm($sum_cred)."</TD>".
01322                       td(nbm(abs($progress)).$side,'style="text-align:right"').
01323                       td('').
01324                       "</TR>";
01325                     $sum_cred=0;
01326                     $sum_deb=0;
01327                     $progress=0;
01328                   }
01329               }
01330             $progress=bcadd($progress,$tmp_diff);
01331                         $side="&nbsp;".$this->get_amount_side($progress);
01332             $sum_cred=bcadd($sum_cred,$op['cred_montant']);
01333             $sum_deb=bcadd($sum_deb,$op['deb_montant']);
01334                 if ($idx%2 == 0) $class='class="odd"'; else $class=' class="even"';
01335                 $idx++;
01336 
01337             echo "<TR $class name=\"tr_" . $let . "_" . $from_div . "\">" .
01338                         "<TD>".smaller_date(format_date($op['j_date_fmt']))."</TD>".
01339               td(h($op['jr_pj_number'])).
01340             "<TD>".$vw_operation."</TD>".
01341             "<TD>".h($op['description'])."</TD>".
01342             "<TD style=\"text-align:right\">".nbm($op['deb_montant'])."</TD>".
01343               "<TD style=\"text-align:right\">".nbm($op['cred_montant'])."</TD>".
01344               td(nbm(abs($progress)).$side,'style="text-align:right"').
01345             td($html_let, ' style="text-align:right"') .
01346                         "</TR>";
01347             $old_exercice=$op['p_exercice'];
01348 
01349         }
01350         $solde_type=($sum_deb>$sum_cred)?"solde débiteur":"solde créditeur";
01351         $diff=abs(bcsub($sum_deb,$sum_cred));
01352         echo '<tfoot>';
01353        echo "<TR style=\"font-weight:bold\">".
01354         "<TD>Totaux</TD>".
01355         "<TD ></TD>".
01356         "<TD ></TD>".
01357         "<TD></TD>".
01358          "<TD  style=\"text-align:right\">".nbm($sum_deb)."</TD>".
01359          "<TD  style=\"text-align:right\">".nbm($sum_cred)."</TD>".
01360           "<TD style=\"text-align:right\">".nbm($diff)."</TD>".
01361 
01362         "</TR>";
01363         echo "<TR style=\"font-weight:bold\">".
01364         "<TD>$solde_type</TD>".
01365           "<TD style=\"text-align:right\">".nbm($diff)."</TD>".
01366         "<TD></TD>".
01367         "</TR>";
01368         echo '</tfoot>';
01369         echo '</tbody>';
01370 
01371         echo "</table>";
01372 
01373         return 0;
01374     }
01375     /*!
01376      * \brief Display HTML Table Header (button)
01377      *
01378      * \return none
01379      */
01380     function HtmlTableHeader($p_array=null)
01381     {
01382         if ( $p_array == null)
01383             $p_array=$_REQUEST;
01384 
01385         $hid=new IHidden();
01386         echo '<div class="noprint">';
01387         echo "<table >";
01388         echo '<TR>';
01389 
01390         echo '<TD><form method="GET" ACTION="">'.
01391         HtmlInput::submit('bt_other',"Autre poste").
01392         dossier::hidden().
01393         $hid->input("type","poste").$hid->input('p_action','impress')."</form></TD>";
01394         $str_ople=(isset($_REQUEST['ople']))?HtmlInput::hidden('ople',$_REQUEST['ople']):'';
01395 
01396         echo '<TD><form method="GET" ACTION="export.php">'.
01397         HtmlInput::submit('bt_pdf',"Export PDF").
01398         dossier::hidden().$str_ople.
01399           HtmlInput::hidden('act','PDF:fichedetail').
01400         $hid->input("type","poste").
01401         $hid->input('p_action','impress').
01402         $hid->input("f_id",$this->id).
01403         dossier::hidden().
01404         $hid->input("from_periode",$p_array['from_periode']).
01405         $hid->input("to_periode",$p_array['to_periode']);
01406         if (isset($p_array['oper_detail']))
01407             echo $hid->input('oper_detail','on');
01408 
01409         echo "</form></TD>";
01410 
01411         echo '<TD><form method="GET" ACTION="export.php">'.
01412         HtmlInput::submit('bt_csv',"Export CSV").
01413           HtmlInput::hidden('act','CSV:fichedetail').
01414         dossier::hidden().$str_ople.
01415         $hid->input("type","poste").
01416         $hid->input('p_action','impress').
01417         $hid->input("f_id",$this->id).
01418         $hid->input("from_periode",$p_array['from_periode']).
01419         $hid->input("to_periode",$p_array['to_periode']);
01420         if (isset($p_array['oper_detail']))
01421             echo $hid->input('oper_detail','on');
01422 
01423         echo "</form></TD>";
01424                 echo "</form></TD>";
01425                 echo '<td style="vertical-align:top">';
01426                 echo HtmlInput::print_window();
01427                 echo '</td>';
01428         echo "</table>";
01429         echo '</div>';
01430 
01431     }
01432     /*!
01433      * \brief   give the balance of an card
01434      * \return
01435      *      balance of the card
01436      *
01437      */
01438     function get_solde_detail($p_cond="")
01439     {
01440         if ( $this->id == 0 ) return array('credit'=>0,'debit'=>0,'solde'=>0);
01441         $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
01442 
01443         if ( $p_cond != "") $p_cond=" and ".$p_cond;
01444         $Res=$this->cn->exec_sql("select sum(deb) as sum_deb, sum(cred) as sum_cred from
01445                                  ( select j_poste,
01446                                  case when j_debit='t' then j_montant else 0 end as deb,
01447                                  case when j_debit='f' then j_montant else 0 end as cred
01448                                  from jrnx
01449                                  where
01450                                  j_qcode = ('$qcode'::text)
01451                                  $p_cond
01452                                  ) as m  ");
01453         $Max=Database::num_row($Res);
01454         if ($Max==0) return 0;
01455         $r=Database::fetch_array($Res,0);
01456 
01457         return array('debit'=>$r['sum_deb'],
01458                      'credit'=>$r['sum_cred'],
01459                      'solde'=>abs($r['sum_deb']-$r['sum_cred']));
01460     }
01461     /**
01462      *get the bank balance with receipt or not
01463      *
01464      */
01465     function get_bk_balance($p_cond="")
01466     {
01467         if ( $this->id == 0 ) exit('fiche->id est nul');
01468         $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
01469 
01470         if ( $p_cond != "") $p_cond=" and ".$p_cond;
01471         $sql="select sum(deb) as sum_deb, sum(cred) as sum_cred from
01472                                  ( select j_poste,
01473                                  case when j_debit='t' then j_montant else 0 end as deb,
01474                                  case when j_debit='f' then j_montant else 0 end as cred
01475                                  from jrnx
01476                                  join jrn on (jr_grpt_id=j_grpt)
01477                                  where
01478                                  j_qcode = ('$qcode'::text)
01479                                  $p_cond
01480                                  ) as m  ";
01481 
01482         $Res=$this->cn->exec_sql($sql);
01483         $Max=Database::num_row($Res);
01484         if ($Max==0) return 0;
01485         $r=Database::fetch_array($Res,0);
01486 
01487         return array('debit'=>$r['sum_deb'],
01488                      'credit'=>$r['sum_cred'],
01489                      'solde'=>abs($r['sum_deb']-$r['sum_cred']));
01490 
01491     }
01492     /*!\brief check if an attribute is empty
01493      *\param $p_attr the id of the attribut to check (ad_id)
01494      *\return return true is the attribute is empty or missing
01495      */
01496     function empty_attribute($p_attr)
01497     {
01498         $sql="select ad_value
01499              from fiche_detail
01500              natural join fiche
01501              left join attr_def using (ad_id) where f_id=".$this->id.
01502              " and ad_id = ".$p_attr.
01503              " order by ad_id";
01504         $res=$this->cn->exec_sql($sql);
01505         if ( Database::num_row($res) == 0 ) return true;
01506         $text=Database::fetch_result($res,0,0);
01507         return (strlen(trim($text)) > 0)?false:true;
01508 
01509 
01510     }
01511     /*! Summary
01512      * \brief  show the default screen
01513      *
01514      * \param $p_search (filter)
01515      * \param $p_action show the action column
01516      * \param $p_sql SQL to filter the number of card must start with AND
01517      * \param $p_amount true : only cards with at least one operation default : false
01518      * \return: string to display
01519      */
01520     function Summary($p_search="",$p_action="",$p_sql="",$p_amount=false)
01521     {
01522         global $g_user;
01523         bcscale(4);
01524         $str_dossier=dossier::get();
01525         $p_search=sql_string($p_search);
01526         $script=$_SERVER['PHP_SELF'];
01527         // Creation of the nav bar
01528         // Get the max numberRow
01529         $filter_amount='';
01530         global $g_user;
01531 
01532         $filter_year="  j_tech_per in (select p_id from parm_periode ".
01533                      "where p_exercice='".$g_user->get_exercice()."')";
01534 
01535         if ( $p_amount) $filter_amount=' and f_id in (select f_id from jrnx where  '.$filter_year.')';
01536 
01537         $all_tiers=$this->count_by_modele($this->fiche_def_ref,"",$p_sql.$filter_amount);
01538         // Get offset and page variable
01539         $offset=( isset ($_REQUEST['offset'] )) ?$_REQUEST['offset']:0;
01540         $page=(isset($_REQUEST['page']))?$_REQUEST['page']:1;
01541         $bar=navigation_bar($offset,$all_tiers,$_SESSION['g_pagesize'],$page);
01542 
01543         // set a filter ?
01544         $search=$p_sql;
01545 
01546         $exercice=$g_user->get_exercice();
01547         $tPeriode=new Periode($this->cn);
01548         list($max,$min)=$tPeriode->get_limit($exercice);
01549 
01550 
01551         if ( trim($p_search) != "" )
01552         {
01553             $search.=" and f_id in
01554                      (select distinct f_id from fiche_detail
01555                      where
01556                      ad_id in (1,32,30,23,18,13) and ad_value ~* '$p_search')";
01557         }
01558         // Get The result Array
01559         $step_tiers=$this->get_by_category($offset,$search.$filter_amount,'name');
01560 
01561         if ( $all_tiers == 0 || count($step_tiers)==0 ) return "";
01562         $r="";
01563         $r.="Filtre rapide ".HtmlInput::filter_table("tiers_tb", '0,1', 1);
01564         $r.=$bar;
01565         
01566         $r.='<table  id="tiers_tb" class="sortable"  style="width:90%;margin-left:5%">
01567             <TR >
01568             <TH>'._('Quick Code').HtmlInput::infobulle(17).'</TH>
01569             <th  class="sorttable_sorted_reverse">'._('Nom').'<span id="sorttable_sortrevind">&nbsp;&blacktriangle;</span>'.'</th>
01570             <th>'._('Adresse').'</th>
01571             <th style="text-align:right">'._('Total débit').'</th>
01572             <th style="text-align:right">'._('Total crédit').'</th>
01573             <th style="text-align:right">'._('Solde').'</th>';
01574         $r.='</TR>';
01575         if ( sizeof ($step_tiers ) == 0 )
01576             return $r;
01577 
01578         $i=0;
01579                 $deb=0;$cred=0;
01580         foreach ($step_tiers as $tiers )
01581         {
01582             $i++;
01583             $odd="";
01584              $odd  = ($i % 2 == 0 ) ? 'class="odd"': ' class="even" ';
01585             /* Filter on the default year */
01586 
01587             $amount=$tiers->get_solde_detail($filter_year);
01588 
01589             /* skip the tiers without operation */
01590             if ( $p_amount && $amount['debit']==0 && $amount['credit'] == 0 && $amount['solde'] == 0 ) continue;
01591 
01592             $r.="<TR $odd>";
01593             $e=sprintf('<A HREF="%s?ac=%s&sb=detail&f_id=%d&%s&sc=sv" title="Détail" class="line"> ',
01594                        $script,$_REQUEST['ac'],$tiers->id,$str_dossier);
01595 
01596             $r.="<TD> $e".$tiers->strAttribut(ATTR_DEF_QUICKCODE)."</A></TD>";
01597             $r.="<TD>".h($tiers->strAttribut(ATTR_DEF_NAME))."</TD>";
01598             $r.="<TD>".h($tiers->strAttribut(ATTR_DEF_ADRESS).
01599                          " ".$tiers->strAttribut(ATTR_DEF_CP).
01600                          " ".$tiers->strAttribut(ATTR_DEF_PAYS)).
01601                 "</TD>";
01602             $str_deb=(($amount['debit']==0)?0:nbm($amount['debit']));
01603             $str_cred=(($amount['credit']==0)?0:nbm($amount['credit']));
01604             $str_solde=nbm($amount['solde']);
01605             $r.='<TD sorttable_customkey="'.$amount['debit'].'" align="right"> '.$str_deb.'</TD>';
01606             $r.='<TD sorttable_customkey="'.$amount['credit'].'" align="right"> '.$str_cred.'</TD>';
01607             $r.='<TD sorttable_customkey="'.$amount['solde'].'" align="right"> '.$str_solde."</TD>";
01608             $deb=bcadd($deb,$amount['debit']);
01609             $cred=bcadd($cred,$amount['credit']);
01610 
01611             $r.="</TR>";
01612 
01613         }
01614                 $r.="<tfoot>";
01615                 $solde=abs(bcsub($deb,$cred));
01616                 $side=($deb > $cred)?'Débit':'Crédit';
01617                 $r.=td("").td("").td("Totaux").td(nbm($deb),'class="num"').td(nbm($cred),'class="num"').td(" $side ".nbm($solde),'class="num"');
01618                 $r.="</tfoot>";
01619         $r.="</TABLE>";
01620         $r.=$bar;
01621         return $r;
01622     }
01623     /*!
01624      * \brief get the fd_id of the card : fd_id, it set the attribute fd_id
01625      */
01626     function get_categorie()
01627     {
01628         if ( $this->id == 0 ) exit('class_fiche : f_id = 0 ');
01629         $sql='select fd_id from fiche where f_id='.$this->id;
01630         $R=$this->cn->get_value($sql);
01631         if ( $R == "" )
01632             $this->fd_id=0;
01633         else
01634             $this->fd_id=$R;
01635     }
01636     /*!
01637      ***************************************************
01638      * \brief   Check if a fiche is used by a jrn
01639      *  return 1 if the  fiche is in the range otherwise 0, the quick_code
01640      *  or the id  must be set
01641      *
01642      *
01643      * \param   $p_jrn journal_id
01644      * \param   $p_type : deb or cred default empty
01645      *
01646      * \return 1 if the fiche is in the range otherwise < 1
01647      *        -1 the card doesn't exist
01648      *        -2 the ledger has no card to check
01649      *
01650      */
01651     function belong_ledger($p_jrn,$p_type="")
01652     {
01653         // check if we have a quick_code or a f_id
01654         if (($this->quick_code==null || $this->quick_code == "" )
01655                 && $this->id == 0 )
01656         {
01657             echo 'erreur ni quick_code ni f_id ne sont donnes';
01658             exit();
01659         }
01660 
01661         //retrieve the quick_code
01662         if ( $this->quick_code=="")
01663             $this->quick_code=$this->get_quick_code();
01664 
01665 
01666         if ( $this->quick_code==null)
01667             return -1;
01668 
01669         if ( $this->id == 0 )
01670             if ( $this->get_by_qcode(null,false) == 1)
01671                 return -1;
01672 
01673         $get="";
01674         if ( $p_type == 'deb' )
01675         {
01676             $get='jrn_def_fiche_deb';
01677         }
01678         if ( $p_type == 'cred' )
01679         {
01680             $get='jrn_def_fiche_cred';
01681         }
01682         if ( $get != "" )
01683         {
01684             $Res=$this->cn->exec_sql("select $get as fiche from jrn_def where jrn_def_id=$p_jrn");
01685         }
01686         else
01687         {
01688             // Get all the fiche type (deb and cred)
01689             $Res=$this->cn->exec_sql(" select jrn_def_fiche_cred as fiche
01690                                      from jrn_def where jrn_def_id=$p_jrn
01691                                      union
01692                                      select jrn_def_fiche_deb
01693                                      from jrn_def where jrn_def_id=$p_jrn"
01694                                     );
01695         }
01696         $Max=Database::num_row($Res);
01697         if ( $Max==0)
01698         {
01699             return -2;
01700         }
01701         /* convert the array to a string */
01702         $list=Database::fetch_all($Res);
01703         $str_list="";
01704         $comma='';
01705         foreach ($list as $row)
01706         {
01707             if ( $row['fiche'] != '' )
01708             {
01709                 $str_list.=$comma.$row['fiche'];
01710                 $comma=',';
01711             }
01712         }
01713         // Normally Max must be == 1
01714 
01715         if ( $str_list=="")
01716         {
01717             return -3;
01718         }
01719 
01720         $sql="select *
01721              from fiche
01722              where
01723              fd_id in (".$str_list.") and f_id= ".$this->id;
01724 
01725         $Res=$this->cn->exec_sql($sql);
01726         $Max=Database::num_row($Res);
01727         if ($Max==0 )
01728             return 0;
01729         else
01730             return 1;
01731     }
01732     /*!\brief  get all the card from a categorie
01733      *\param $p_cn database connx
01734      *\param $pFd_id is the category id
01735      *\param $p_order for the sort, possible values is name_asc,name_desc or nothing
01736      *\return an array of card, but only the fiche->id is set
01737      */
01738     static function get_fiche_def($p_cn,$pFd_id,$p_order='')
01739     {
01740         switch ($p_order)
01741         {
01742         case 'name_asc':
01743             $sql='select f_id,ad_value from fiche join fiche_detail using (f_id) where ad_id=1 and fd_id=$1 order by 2 asc';
01744             break;
01745         case 'name_desc':
01746             $sql='select f_id,ad_value from fiche join fiche_detail using (f_id) where ad_id=1 and fd_id=$1 order by 2 desc';
01747             break;
01748         default:
01749             $sql='select f_id from fiche  where fd_id=$1 ';
01750         }
01751         $array=$p_cn->get_array($sql,array($pFd_id));
01752 
01753         return $array;
01754     }
01755     /*!\brief check if a card is used
01756      *\return return true is a card is used otherwise false
01757      */
01758     function is_used()
01759     {
01760         /* retrieve first the quickcode */
01761         $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
01762         $sql='select count(*) as c from jrnx where j_qcode=$1';
01763         $count=$this->cn->get_value($sql,array($qcode));
01764         if ( $count == 0 ) return false;
01765         return true;
01766     }
01767     /*\brief remove a card without verification */
01768     function delete()
01769     {
01770         // Remove from attr_value
01771         $Res=$this->cn->exec_sql("delete from fiche_detail
01772                                  where
01773                                    f_id=".$this->id);
01774 
01775         // Remove from fiche
01776         $Res=$this->cn->exec_sql("delete from fiche where f_id=".$this->id);
01777 
01778     }
01779     /*!\brief create the sql statement for retrieving all
01780      * the card
01781      *\return string with sql statement
01782      *\param $array contains the condition
01783     \verbatim
01784        [jrn] => 2
01785        [typecard] => cred / deb / filter or list
01786        [query] => string
01787     \endverbatim
01788      *\note the typecard cred, deb or filter must be used with jrn, the value of list means a list of fd_id
01789      *\see ajax_card.php cards.js
01790      */
01791     function build_sql($array)
01792     {
01793         if ( ! empty($array) ) extract($array);
01794         $and='';
01795         $filter_fd_id='true';
01796         $filter_query='';
01797         if ( isset($typecard))
01798         {
01799                         if (strpos($typecard, "sql")==false)
01800                         {
01801                                 switch($typecard)
01802                                 {
01803                                 case 'cred':
01804                                         if ( ! isset($jrn)) throw ('Erreur pas de valeur pour jrn');
01805                                         $filter_jrn=$this->cn->make_list("select jrn_def_fiche_cred from jrn_Def where jrn_def_id=$1",array($jrn));
01806                                         $filter_fd_id=" fd_id in (".$filter_jrn.")";
01807                                         $and=" and ";
01808                                         break;
01809                                 case 'deb':
01810                                         if ( ! isset($jrn)) throw ('Erreur pas de valeur pour jrn');
01811                                         $filter_jrn=$this->cn->make_list("select jrn_def_fiche_deb from jrn_Def where jrn_def_id=$1",array($jrn));
01812                                         $filter_fd_id=" fd_id in (".$filter_jrn.")";
01813                                         $and=" and ";
01814                                         break;
01815                                 case 'filter':
01816                                         if ( ! isset($jrn)) throw ('Erreur pas de valeur pour jrn');
01817                                         $filter_jrn=$this->cn->make_list("select jrn_def_fiche_deb from jrn_Def where jrn_def_id=$1",array($jrn));
01818 
01819                                         if ( trim($filter_jrn) !='')
01820                                                 $fp1=" fd_id in (".$filter_jrn.")";
01821                                         else
01822                                                 $fp1="fd_id < 0";
01823 
01824                                         $filter_jrn=$this->cn->make_list("select jrn_def_fiche_cred from jrn_Def where jrn_def_id=$1",array($jrn));
01825 
01826                                         if ( trim($filter_jrn) !='')
01827                                                 $fp2=" fd_id in (".$filter_jrn.")";
01828                                         else
01829                                                 $fp2="fd_id < 0";
01830 
01831                                         $filter_fd_id='('.$fp1.' or '.$fp2.')';
01832 
01833                                         $and=" and ";
01834                                         break;
01835                                 case 'all':
01836                                         $filter_fd_id=' true';
01837                                         break;
01838                                 default:
01839                                         if ( trim($typecard) != '')
01840                                                 $filter_fd_id=' fd_id in ('.$typecard.')';
01841                                         else
01842                                                 $filter_fd_id=' fd_id < 0';
01843                                 }
01844                         }
01845                         else
01846                         {
01847                                 $filter_fd_id = str_replace('[sql]', '', $typecard);
01848                         }
01849                 }
01850 
01851         $and=" and ";
01852         if (isset($query))
01853         {
01854             $query=sql_string($query);
01855 
01856             if (strlen(trim($query)) > 1)
01857             {
01858                 $filter_query=$and."(vw_name ilike '%$query%' or quick_code ilike ('%$query%') or vw_description ilike '%$query%' or tva_num ilike '%$query%')";
01859             }
01860             else
01861             {
01862                 $filter_query='';
01863             }
01864         }
01865         $sql="select * from vw_fiche_attr where ".$filter_fd_id.$filter_query;
01866         return $sql;
01867 
01868     }
01869     /**
01870      *@brief move a card to another cat. The properties will changed
01871      * and be removed
01872      *@param $p_fdid the fd_id of destination
01873      */
01874     function move_to($p_fdid)
01875     {
01876         $this->cn->start();
01877         $this->cn->exec_sql('update fiche set fd_id=$1 where f_id=$2',array($p_fdid,$this->id));
01878         // add missing
01879         $this->cn->exec_sql('select fiche_attribut_synchro($1)',array($p_fdid));
01880         // add to the destination missing fields
01881         $this->cn->exec_sql("insert into jnt_fic_attr (fd_id,ad_id,jnt_order) select $1,ad_id,100 from fiche_detail where f_id=$2 and ad_id not in (select ad_id from jnt_fic_attr where fd_id=$3)",array($p_fdid,$this->id,$p_fdid));
01882         $this->cn->commit();
01883     }
01884         /**
01885          * return the letter C if amount is > 0, D if < 0 or =
01886          * @param type $p_amount
01887          * @return string
01888          */
01889         function get_amount_side($p_amount)
01890         {
01891                 if ($p_amount == 0)
01892                         return "=";
01893                 if ($p_amount < 0)
01894                         return "C";
01895                 if ($p_amount > 0)
01896                         return "D";
01897         }
01898     static function test_me()
01899     {
01900         $cn=new Database(dossier::id());
01901         $a=new Fiche($cn);
01902         $select_cat=new ISelect('fd_id');
01903         $select_cat->value=$cn->make_array('select fd_id,fd_label from fiche_def where frd_id='.
01904                                            FICHE_TYPE_CLIENT);
01905         echo '<FORM METHOD="GET"> ';
01906         echo dossier::hidden();
01907         echo HtmlInput::hidden('test_select',$_GET['test_select']);
01908         echo 'Choix de la catégorie';
01909         echo $select_cat->input();
01910         echo HtmlInput::submit('go_card','Afficher');
01911         echo '</form>';
01912         if ( isset ($_GET['go_card']))
01913         {
01914             $empty=$a->to_array($_GET['fd_id']);
01915             print_r($empty);
01916         }
01917     }
01918 
01919         function get_gestion_title()
01920         {
01921                 $r = "<h2>" . h($this->getName()) . " " . h($this->getAttribut(ATTR_DEF_FIRST_NAME)) . '[' . $this->get_quick_code() . ']</h2>';
01922                 return $r;
01923         }
01924         function get_all_account()
01925         {
01926 
01927         }
01928 }
01929 
01930 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations