noalyss  Version-6.7.2
Public Member Functions | Static Public Member Functions | Data Fields | Private Member Functions
Fiche Class Reference

define Class fiche and fiche def, those class are using class attribut. When adding or modifing new card in a IPOPUP the ipopup for the accounting item is ipop_account More...

Inheritance diagram for Fiche:
Admin Bank contact Customer Manager Supplier

Public Member Functions

 __construct ($p_cn, $p_id=0)
 belong_ledger ($p_jrn, $p_type="")
 Check if a fiche is used by a jrn return 1 if the fiche is in the range otherwise 0, the quick_code or the id must be set.
 blank ($p_fiche_def)
 insert a new record show a blank card to be filled
 build_sql ($array)
 create the sql statement for retrieving all the card
 count_by_modele ($p_frd_id, $p_search="", $p_sql="")
 Return array of card from the frd family.
 delete ()
 Display ($p_readonly)
 Display object instance, getAttribute sort the attribute and add missing ones.
 empty_attribute ($p_attr)
 check if an attribute is empty
 Get ()
 Synonum of fiche::getAttribut.
 get_all_account ()
 get_amount_side ($p_amount)
 return the letter C if amount is > 0, D if < 0 or =
 get_bk_account ()
 get the available bank_account filtered by the security
 get_bk_balance ($p_cond="")
 get the bank balance with receipt or not
 get_by_category ($p_offset=-1, $p_search="", $p_order='')
 get all the card thanks the fiche_def_ref
 get_by_qcode ($p_qcode=null, $p_all=true)
 Retrieve a card thx his quick_code complete the object,, set the id member of the object or set it to 0 if no card is found.
 get_categorie ()
 get the fd_id of the card : fd_id, it set the attribute fd_id
 get_fiche_def_ref_id ()
 retrieve the frd_id of the fiche it is the type of the card (bank, purchase...) (fiche_def_ref primary key)
 get_gestion_title ()
 get_quick_code ()
 return the quick_code of a card
 get_row ($p_from, $p_to)
 Get data for poste.
 get_row_date ($p_from, $p_to, $op_let=0)
 Get data for poste.
 get_solde_detail ($p_cond="")
 give the balance of an card
 getAttribut ()
 get all the attribute of a card, add missing ones and sort the array ($this->attribut) by ad_id
 GetByDef ($p_frd_id, $p_offset=-1, $p_search="", $p_order='')
 Return array of card from the frd family.
 getName ()
 return the name of a card
 HtmlTable ($p_array=null, $op_let=0, $from_div=1)
 HtmlTable, display a HTML of a card for the asked period.
 HtmlTableDetail ($p_array=null, $op_let=0)
 HtmlTable, display a HTML of a card for the asked period.
 HtmlTableHeader ($p_array=null)
 Display HTML Table Header (button)
 insert ($p_fiche_def, $p_array=null, $transaction=true)
 insert a new record
 is_used ()
 check if a card is used
 move_to ($p_fdid)
 move a card to another cat.
 remove ($silent=false)
 remove a card
 Save ($p_fiche_def=0)
 Save a card, call insert or update.
 seek ($p_attribut, $p_value)
 find the card with the p_attribut equal to p_value, it is not case sensitive
 setAttribut ($p_ad_id, $p_value)
 set an attribute by a value, if the attribut array is empty a call to getAttribut is performed
 ShowTable ()
 size ()
 give the size of a card object
 strAttribut ($p_ad_id, $p_return=1)
 return the string of the given attribute (attr_def.ad_id)
 Summary ($p_search="", $p_action="", $p_sql="", $p_amount=false)
 show the default screen
 to_array ($pfd_id)
 make an array of attributes of the category of card (FICHE_DEF.FD_ID) The array can be used with the function insert, it will return a struct like this : in the first key (av_textX), X is the ATTR_DEF::AD_ID
 update ($p_array=null)
 update a card

Static Public Member Functions

static cmp_name ($o1, $o2)
 used with a usort function, to sort an array of Fiche on the name
static get_fiche_def ($p_cn, $pFd_id, $p_order='')
 get all the card from a categorie
static test_me ()

Data Fields

 $attribut
 $cn
 $fiche_def
 $fiche_def_ref
 $id
 $quick_code
 $row

Private Member Functions

 get_row_result ($res)
 fetch and return and array

Detailed Description

define Class fiche and fiche def, those class are using class attribut. When adding or modifing new card in a IPOPUP the ipopup for the accounting item is ipop_account

Definition at line 44 of file class_fiche.php.


Constructor & Destructor Documentation

Fiche::__construct ( p_cn,
p_id = 0 
)

Reimplemented in Manager, Bank, Customer, and Supplier.

Definition at line 53 of file class_fiche.php.

References cn.

Referenced by Admin\Admin(), and contact\contact().

    {
        $this->cn=$p_cn;
        $this->id=$p_id;
        $this->quick_code='';
    }

Member Function Documentation

Fiche::belong_ledger ( p_jrn,
p_type = "" 
)

Check if a fiche is used by a jrn return 1 if the fiche is in the range otherwise 0, the quick_code or the id must be set.

Parameters:
$p_jrnjournal_id
$p_type: deb or cred default empty
Returns:
1 if the fiche is in the range otherwise < 1 -1 the card doesn't exist -2 the ledger has no card to check

Definition at line 1651 of file class_fiche.php.

References $list, $Max, $Res, $row, $sql, cn, echo, exit, Database\fetch_all(), get_by_qcode(), get_quick_code(), id, and Database\num_row().

    {
        // check if we have a quick_code or a f_id
        if (($this->quick_code==null || $this->quick_code == "" )
                && $this->id == 0 )
        {
            echo 'erreur ni quick_code ni f_id ne sont donnes';
            exit();
        }

        //retrieve the quick_code
        if ( $this->quick_code=="")
            $this->quick_code=$this->get_quick_code();


        if ( $this->quick_code==null)
            return -1;

        if ( $this->id == 0 )
            if ( $this->get_by_qcode(null,false) == 1)
                return -1;

        $get="";
        if ( $p_type == 'deb' )
        {
            $get='jrn_def_fiche_deb';
        }
        if ( $p_type == 'cred' )
        {
            $get='jrn_def_fiche_cred';
        }
        if ( $get != "" )
        {
            $Res=$this->cn->exec_sql("select $get as fiche from jrn_def where jrn_def_id=$p_jrn");
        }
        else
        {
            // Get all the fiche type (deb and cred)
            $Res=$this->cn->exec_sql(" select jrn_def_fiche_cred as fiche
                                     from jrn_def where jrn_def_id=$p_jrn
                                     union
                                     select jrn_def_fiche_deb
                                     from jrn_def where jrn_def_id=$p_jrn"
                                    );
        }
        $Max=Database::num_row($Res);
        if ( $Max==0)
        {
            return -2;
        }
        /* convert the array to a string */
        $list=Database::fetch_all($Res);
        $str_list="";
        $comma='';
        foreach ($list as $row)
        {
            if ( $row['fiche'] != '' )
            {
                $str_list.=$comma.$row['fiche'];
                $comma=',';
            }
        }
        // Normally Max must be == 1

        if ( $str_list=="")
        {
            return -3;
        }

        $sql="select *
             from fiche
             where
             fd_id in (".$str_list.") and f_id= ".$this->id;

        $Res=$this->cn->exec_sql($sql);
        $Max=Database::num_row($Res);
        if ($Max==0 )
            return 0;
        else
            return 1;
    }
Fiche::blank ( p_fiche_def)

insert a new record show a blank card to be filled

Parameters:
$p_fiche_defis the fiche_def.fd_id
Returns:
HTML Code

Definition at line 424 of file class_fiche.php.

References $a, $array, $f, $label, $msg, $r, $sql, $table, $w, cn, Database\fetch_array(), h2(), HtmlInput\infobulle(), td(), and trim().

    {
        // array = array of attribute object sorted on ad_id
        $f=new Fiche_Def($this->cn,$p_fiche_def);
        $f->get();
        $array=$f->getAttribut();
        $r=h2('Catégorie '.$f->label,"");
        $r.='<table style="width:98%;margin:1%">';
        foreach ($array as $attr)
        {
            $table=0;
            $msg="";$bulle='';
            if ( $attr->ad_id == ATTR_DEF_ACCOUNT)
            {
                $w=new IPoste("av_text".$attr->ad_id);
                $w->set_attribute('ipopup','ipop_account');
                $w->set_attribute('account',"av_text".$attr->ad_id);
                                $w->dbl_click_history();
                //  account created automatically
                $sql="select account_auto($p_fiche_def)";
                $ret_sql=$this->cn->exec_sql($sql);
                $a=Database::fetch_array($ret_sql,0);
                $label=new ISpan();
                $label->name="av_text".$attr->ad_id."_label";

                if ( $a['account_auto'] == 't' )
                    $msg.=$label->input()." <span style=\"color:red\">".
                                                _("Rappel: Poste créé automatiquement à partir de ")
                                                .$f->class_base." </span> ";
                else
                {
                    // if there is a class base in fiche_def_ref, this account will be the
                    // the default one
                    if ( strlen(trim($f->class_base)) != 0 )
                    {
                        $msg.="<TD>".$label->input()." <span style=\"color:red\">"._("Rappel: Poste par défaut sera ").
                              $f->class_base.
                              " !</span> ";
                        $w->value=$f->class_base;
                    }

                }
                $r.="<TR>".td("Poste Comptable",' class="input_text" ' ).td($w->input().$msg)."</TR>";
                continue;
            }
            elseif ( $attr->ad_id == ATTR_DEF_TVA)
            {
                $w=new ITva_Popup('popup_tva');
                $w->table=1;
            }

            else
            {
              switch ($attr->ad_type)
                                {
                                        case 'text':
                                                $w = new IText();
                                                $w->css_size = "100%";
                                                break;
                                        case 'numeric':
                                                $w = new INum();
                                                $w->prec=($attr->ad_extra=="")?2:$attr->ad_extra;
                                                $w->size = $attr->ad_size;
                                                break;
                                        case 'date':
                                                $w = new IDate();
                                                break;
                                        case 'zone':
                                                $w = new ITextArea();
                                                $w->style=' class="itextarea" style="margin:0px;width:100%"';
                                                break;
                                        case 'poste':
                                                $w = new IPoste("av_text" . $attr->ad_id);
                                                $w->set_attribute('ipopup', 'ipop_account');
                                                $w->set_attribute('account', "av_text" . $attr->ad_id);
                                                $w->table = 1;
                                                $bulle = HtmlInput::infobulle(14);
                                                break;
                                        case 'select':
                                                $w = new ISelect("av_text" . $attr->ad_id);
                                                $w->value = $this->cn->make_array($attr->ad_extra);
                                                $w->style= 'style="width:100%"';
                                                break;
                                        case 'card':
                                                $w = new ICard("av_text" . $attr->ad_id);
                                                // filter on frd_id
                                                $w->extra = $attr->ad_extra;
                                                $w->extra2 = 0;
                                                $label = new ISpan();
                                                $label->name = "av_text" . $attr->ad_id . "_label";
                                                $w->set_attribute('ipopup', 'ipopcard');
                                                $w->set_attribute('typecard', $attr->ad_extra);
                                                $w->set_attribute('inp', "av_text" . $attr->ad_id);
                                                $w->set_attribute('label', "av_text" . $attr->ad_id . "_label");
                                                $msg = $w->search();
                                                $msg.=$label->input();
                                                break;
                                }
                                $w->table = 0;
                        }
                        $w->table = $table;
                        $w->label = $attr->ad_text;
                        $w->name = "av_text" . $attr->ad_id;
                        if ($attr->ad_id == 21 || $attr->ad_id==22||$attr->ad_id==20||$attr->ad_id==31)
                        {
                                $bulle=HtmlInput::infobulle(21);
                        }
                        $r.="<TR>" . td($w->label." $bulle", ' class="input_text" ') . td($w->input()." $msg")." </TR>";
                }
                $r.= '</table>';
        return $r;
    }
Fiche::build_sql ( array)

create the sql statement for retrieving all the card

Returns:
string with sql statement
Parameters:
$arraycontains the condition
       [jrn] => 2
       [typecard] => cred / deb / filter or list
       [query] => string
    
Note:
the typecard cred, deb or filter must be used with jrn, the value of list means a list of fd_id
See also:
ajax_card.php cards.js

Definition at line 1791 of file class_fiche.php.

References $array, $jrn, $sql, cn, sql_string(), and trim().

    {
        if ( ! empty($array) ) extract($array);
        $and='';
        $filter_fd_id='true';
        $filter_query='';
        if ( isset($typecard))
        {
                        if (strpos($typecard, "sql")==false)
                        {
                                switch($typecard)
                                {
                                case 'cred':
                                        if ( ! isset($jrn)) throw ('Erreur pas de valeur pour jrn');
                                        $filter_jrn=$this->cn->make_list("select jrn_def_fiche_cred from jrn_Def where jrn_def_id=$1",array($jrn));
                                        $filter_fd_id=" fd_id in (".$filter_jrn.")";
                                        $and=" and ";
                                        break;
                                case 'deb':
                                        if ( ! isset($jrn)) throw ('Erreur pas de valeur pour jrn');
                                        $filter_jrn=$this->cn->make_list("select jrn_def_fiche_deb from jrn_Def where jrn_def_id=$1",array($jrn));
                                        $filter_fd_id=" fd_id in (".$filter_jrn.")";
                                        $and=" and ";
                                        break;
                                case 'filter':
                                        if ( ! isset($jrn)) throw ('Erreur pas de valeur pour jrn');
                                        $filter_jrn=$this->cn->make_list("select jrn_def_fiche_deb from jrn_Def where jrn_def_id=$1",array($jrn));

                                        if ( trim($filter_jrn) !='')
                                                $fp1=" fd_id in (".$filter_jrn.")";
                                        else
                                                $fp1="fd_id < 0";

                                        $filter_jrn=$this->cn->make_list("select jrn_def_fiche_cred from jrn_Def where jrn_def_id=$1",array($jrn));

                                        if ( trim($filter_jrn) !='')
                                                $fp2=" fd_id in (".$filter_jrn.")";
                                        else
                                                $fp2="fd_id < 0";

                                        $filter_fd_id='('.$fp1.' or '.$fp2.')';

                                        $and=" and ";
                                        break;
                                case 'all':
                                        $filter_fd_id=' true';
                                        break;
                                default:
                                        if ( trim($typecard) != '')
                                                $filter_fd_id=' fd_id in ('.$typecard.')';
                                        else
                                                $filter_fd_id=' fd_id < 0';
                                }
                        }
                        else
                        {
                                $filter_fd_id = str_replace('[sql]', '', $typecard);
                        }
                }

        $and=" and ";
        if (isset($query))
        {
            $query=sql_string($query);

            if (strlen(trim($query)) > 1)
            {
                $filter_query=$and."(vw_name ilike '%$query%' or quick_code ilike ('%$query%') or vw_description ilike '%$query%' or tva_num ilike '%$query%')";
            }
            else
            {
                $filter_query='';
            }
        }
        $sql="select * from vw_fiche_attr where ".$filter_fd_id.$filter_query;
        return $sql;

    }
static Fiche::cmp_name ( o1,
o2 
) [static]

used with a usort function, to sort an array of Fiche on the name

Definition at line 62 of file class_fiche.php.

    {
        return strcmp($o1->strAttribut(ATTR_DEF_NAME),$o2->strAttribut(ATTR_DEF_NAME));
    }
Fiche::count_by_modele ( p_frd_id,
p_search = "",
p_sql = "" 
)

Return array of card from the frd family.

Parameters:
$p_frd_idthe fiche_def_ref.frd_id
$p_searchp_search is a filter on the name
$p_sqlextra sql condition
Returns:
array of fiche object

Definition at line 252 of file class_fiche.php.

References $a, $Ret, $sql, cn, Database\num_row(), and sql_string().

Referenced by contact\Summary(), and Summary().

    {
        $sql="select *
             from
             fiche join fiche_Def using (fd_id)
             where frd_id=".$p_frd_id;
        if ( $p_search != "" )
        {
            $a=sql_string($p_search);
            $sql="select * from vw_fiche_attr where frd_id=".$p_frd_id.
                 " and vw_name ~* '$p_search'";
        }

        $Ret=$this->cn->exec_sql($sql.$p_sql);

        return Database::num_row($Ret) ;
    }

Definition at line 1768 of file class_fiche.php.

References $Res, and cn.

    {
        // Remove from attr_value
        $Res=$this->cn->exec_sql("delete from fiche_detail
                                 where
                                   f_id=".$this->id);

        // Remove from fiche
        $Res=$this->cn->exec_sql("delete from fiche where f_id=".$this->id);

    }
Fiche::Display ( p_readonly)

Display object instance, getAttribute sort the attribute and add missing ones.

Parameters:
$p_readonlytrue= if can not modify, otherwise false
Returns:
string to display or FNT string for fiche non trouvé

Definition at line 546 of file class_fiche.php.

References $a, $fiche, $label, $msg, $p_readonly, $r, $ret, $sql, $value, $w, cn, Database\fetch_array(), h2(), HtmlInput\infobulle(), td(), trim(), and HtmlInput\warnbulle().

    {
                $this->GetAttribut();
                $attr = $this->attribut;
                /* show card type here */
                $type_card = $this->cn->get_value('select fd_label from fiche_def join fiche using (fd_id) where f_id=$1', array($this->id));
                $ret = "";
                $ret.=h2( "Catégorie ".$type_card, 'style="display:inline"');
                $ret.='<span style="font-weight:bolder;margin-right:5px;float:right"> id fiche:' . $this->id . "</span>";
                $ret.="<table style=\"width:98%;margin:1%\">";
                if (empty($attr))
                {
                        return 'FNT';
                }

                /* for each attribute */
                foreach ($attr as $r)
                {
                        $msg = "";
                        $bulle = "";
                        if ($p_readonly)
                        {
                                $w = new IText();
                                $w->table = 1;
                                $w->readOnly = true;
                                $w->css_size = "100%";
                        }
                        if ($p_readonly == false)
                        {

                                if ($r->ad_id == ATTR_DEF_ACCOUNT)
                                {
                                        $w = new IPoste("av_text" . $r->ad_id);
                                        $w->set_attribute('ipopup', 'ipop_account');
                                        $w->set_attribute('account', "av_text" . $r->ad_id);
                                        $w->dbl_click_history();
                                        //  account created automatically
                                        $w->table = 0;
                                        $w->value = $r->av_text;
                                        //  account created automatically
                                        $sql = "select account_auto($this->fiche_def)";
                                        $ret_sql = $this->cn->exec_sql($sql);
                                        $a = Database::fetch_array($ret_sql, 0);
                                        $bulle = HtmlInput::infobulle(10);

                                        if ($a['account_auto'] == 't')
                                                $bulle.=HtmlInput::warnbulle(11);
                                }
                                elseif ($r->ad_id == ATTR_DEF_TVA)
                                {
                                        $w = new ITva_Popup('popup_tva');
                                        $w->table = 1;
                                        $w->value = $r->av_text;
                                }
                                else
                                {
                                        switch ($r->ad_type)
                                        {
                                                case 'text':
                                                        $w = new IText('av_text' . $r->ad_id);
                                                        $w->css_size = "100%";
                                                        $w->value = $r->av_text;
                                                        break;
                                                case 'numeric':
                                                        $w = new INum('av_text' . $r->ad_id);
                                                        $w->size = $r->ad_size;
                                                        $w->prec=($r->ad_extra=="")?2:$r->ad_extra;
                                                        $w->value = $r->av_text;
                                                        break;
                                                case 'date':
                                                        $w = new IDate('av_text' . $r->ad_id);
                                                        $w->value = $r->av_text;
                                                        break;
                                                case 'zone':
                                                        $w = new ITextArea('av_text' . $r->ad_id);
                                                        $w->style=' class="itextarea" style="margin:0px;width:100%"';
                                                        $w->value = $r->av_text;
                                                        break;
                                                case 'poste':
                                                        $w = new IPoste("av_text" . $r->ad_id);
                                                        $w->set_attribute('ipopup', 'ipop_account');
                                                        $w->set_attribute('account', "av_text" . $r->ad_id);
                                                        $w->dbl_click_history();
                                                        $w->width = $r->ad_size;
                                                        $w->table = 0;
                                                        $bulle = HtmlInput::infobulle(14);
                                                        $w->value = $r->av_text;
                                                        break;
                                                case 'card':
                                                        $uniq=rand(0,1000);
                                                        $w = new ICard("av_text" . $r->ad_id);
                                                        $w->id="card_".$this->id.$uniq;
                                                        // filter on ad_extra

                                                        $filter = $r->ad_extra;
                                                        $w->width = $r->ad_size;
                                                        $w->extra = $filter;
                                                        $w->extra2 = 0;
                                                        $label = new ISpan();
                                                        $label->name = "av_text" .$uniq. $r->ad_id . "_label";
                                                        $fiche=new Fiche($this->cn);
                                                        $fiche->get_by_qcode($r->av_text);
                                                        if ($fiche->id == 0 )
                                                        {
                                                                $label->value=(trim($r->av_text)=='')?"":" Fiche non trouvé ";
                                                                $r->av_text="";
                                                        } else
                                                        {
                                                                $label->value=$fiche->strAttribut(ATTR_DEF_NAME)." ".$fiche->strAttribut(ATTR_DEF_FIRST_NAME,0);
                                                        }
                                                        $w->set_attribute('ipopup', 'ipopcard');
                                                        $w->set_attribute('typecard', $filter);
                                                        $w->set_attribute('inp', "av_text" . $r->ad_id);
                                                        $w->set_attribute('label', $label->name);
                                                        $w->autocomplete=0;
                                                        $w->dblclick="fill_ipopcard(this);";
                                                        $msg = $w->search();
                                                        $msg.=$label->input();
                                                        $w->value = $r->av_text;
                                                        break;
                                                case 'select':
                                                        $w = new ISelect();
                                                        $w->value = $this->cn->make_array($r->ad_extra);
                                                        $w->selected = $r->av_text;
                                                        $w->style = ' style="width:100%" ';
                                                        break;
                                                default:
                                                        var_dump($r);
                                                        throw new Exception("Type invalide");
                                        }
                                        $w->table = 0;
                                }
                        }
                        else
                        {
                                switch ($r->ad_type)
                                {
                                        case 'select':
                                                $x = new ISelect();
                                                $x->value = $this->cn->make_array($r->ad_extra);
                                                $x->selected = $r->av_text;
                                                $value = $x->display();
                                                $w->value = $value;
                                                break;
                                        default:
                                                $w->value = $r->av_text;
                                }
                        }

                        $w->name = "av_text" . $r->ad_id;
                        $w->readOnly = $p_readonly;

                        if ($r->ad_id == 21 || $r->ad_id==22||$r->ad_id==20||$r->ad_id==31)
                        {
                                $bulle=HtmlInput::infobulle(21);
                        }
                        $ret.="<TR>" . td($r->ad_text . $bulle) . td($w->input()." ". $msg) . " </TR>";
                }

                $ret.="</table>";

                return $ret;
        }
Fiche::empty_attribute ( p_attr)

check if an attribute is empty

Parameters:
$p_attrthe id of the attribut to check (ad_id)
Returns:
return true is the attribute is empty or missing

Definition at line 1496 of file class_fiche.php.

References $res, $sql, cn, Database\fetch_result(), Database\num_row(), and trim().

Referenced by Acc_Ledger_Purchase\compute_no_deductible(), and Acc_Ledger_Purchase\insert_no_deductible().

    {
        $sql="select ad_value
             from fiche_detail
             natural join fiche
             left join attr_def using (ad_id) where f_id=".$this->id.
             " and ad_id = ".$p_attr.
             " order by ad_id";
        $res=$this->cn->exec_sql($sql);
        if ( Database::num_row($res) == 0 ) return true;
        $text=Database::fetch_result($res,0,0);
        return (strlen(trim($text)) > 0)?false:true;


    }

Synonum of fiche::getAttribut.

Definition at line 1044 of file class_fiche.php.

References getAttribut().

Referenced by remove().

    {
        $this->getAttribut();
    }

Definition at line 1924 of file class_fiche.php.

        {

        }
Fiche::get_amount_side ( p_amount)

return the letter C if amount is > 0, D if < 0 or =

Parameters:
type$p_amount
Returns:
string

Definition at line 1889 of file class_fiche.php.

        {
                if ($p_amount == 0)
                        return "=";
                if ($p_amount < 0)
                        return "C";
                if ($p_amount > 0)
                        return "D";
        }

get the available bank_account filtered by the security

Returns:
array of card

Definition at line 71 of file class_fiche.php.

References $all, $g_user, and cn.

    {
        global $g_user;
      $sql_ledger=$g_user->get_ledger_sql('FIN',3);
      $avail=$this->cn->get_array("select jrn_def_id,jrn_def_name,"
              . "jrn_def_bank,jrn_def_description from jrn_def where jrn_def_type='FIN' and $sql_ledger
                            order by jrn_def_name");

      if ( count($avail) == 0 )
            return null;

      for ($i=0;$i<count($avail);$i++)
        {
            $t=new Fiche($this->cn,$avail[$i]['jrn_def_bank']);
            $t->ledger_name=$avail[$i]['jrn_def_name'];
            $t->ledger_description=$avail[$i]['jrn_def_description'];
            $t->getAttribut();
            $all[$i]=$t;

        }
        return $all;
    }
Fiche::get_bk_balance ( p_cond = "")

get the bank balance with receipt or not

Definition at line 1465 of file class_fiche.php.

References $Max, $qcode, $r, $Res, $sql, cn, exit, Database\fetch_array(), Database\num_row(), and strAttribut().

    {
        if ( $this->id == 0 ) exit('fiche->id est nul');
        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);

        if ( $p_cond != "") $p_cond=" and ".$p_cond;
        $sql="select sum(deb) as sum_deb, sum(cred) as sum_cred from
                                 ( select j_poste,
                                 case when j_debit='t' then j_montant else 0 end as deb,
                                 case when j_debit='f' then j_montant else 0 end as cred
                                 from jrnx
                                 join jrn on (jr_grpt_id=j_grpt)
                                 where
                                 j_qcode = ('$qcode'::text)
                                 $p_cond
                                 ) as m  ";

        $Res=$this->cn->exec_sql($sql);
        $Max=Database::num_row($Res);
        if ($Max==0) return 0;
        $r=Database::fetch_array($Res,0);

        return array('debit'=>$r['sum_deb'],
                     'credit'=>$r['sum_cred'],
                     'solde'=>abs($r['sum_deb']-$r['sum_cred']));

    }
Fiche::get_by_category ( p_offset = -1,
p_search = "",
p_order = '' 
)

get all the card thanks the fiche_def_ref

Parameters:
$p_offset(default =-1)
$p_searchsql condition
Returns:
array of fiche object

Definition at line 1053 of file class_fiche.php.

References $p_order, and GetByDef().

Referenced by contact\Summary(), and Summary().

    {
        return fiche::GetByDef($this->fiche_def_ref,$p_offset,$p_search,$p_order);
    }
Fiche::get_by_qcode ( p_qcode = null,
p_all = true 
)

Retrieve a card thx his quick_code complete the object,, set the id member of the object or set it to 0 if no card is found.

get_by_qcode($p_qcode)

Parameters:
$p_qcodequick_code (ad_id=23)
$p_allretrieve all the attribut of the card, possible value are true or false. false retrieves only the f_id. By default true
Returns:
0 success 1 error not found

Definition at line 104 of file class_fiche.php.

References $sql, cn, getAttribut(), and trim().

Referenced by belong_ledger().

    {
        if ( $p_qcode == null )
            $p_qcode=$this->quick_code;
        $p_qcode=trim($p_qcode);
        $sql="select f_id from fiche_detail
             where ad_id=23 and ad_value=upper($1)";
        $this->id=$this->cn->get_value($sql,array($p_qcode));
        if ( $this->cn->count()==0)
        {
            $this->id=0;
            return 1;
        }


        if ( $p_all )
            $this->getAttribut();
        return 0;
    }

get the fd_id of the card : fd_id, it set the attribute fd_id

Definition at line 1626 of file class_fiche.php.

References $sql, cn, and exit.

    {
        if ( $this->id == 0 ) exit('class_fiche : f_id = 0 ');
        $sql='select fd_id from fiche where f_id='.$this->id;
        $R=$this->cn->get_value($sql);
        if ( $R == "" )
            $this->fd_id=0;
        else
            $this->fd_id=$R;
    }
static Fiche::get_fiche_def ( p_cn,
pFd_id,
p_order = '' 
) [static]

get all the card from a categorie

Parameters:
$p_cndatabase connx
$pFd_idis the category id
$p_orderfor the sort, possible values is name_asc,name_desc or nothing
Returns:
an array of card, but only the fiche->id is set

Definition at line 1738 of file class_fiche.php.

References $array, $p_order, and $sql.

    {
        switch ($p_order)
        {
        case 'name_asc':
            $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';
            break;
        case 'name_desc':
            $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';
            break;
        default:
            $sql='select f_id from fiche  where fd_id=$1 ';
        }
        $array=$p_cn->get_array($sql,array($pFd_id));

        return $array;
    }

retrieve the frd_id of the fiche it is the type of the card (bank, purchase...) (fiche_def_ref primary key)

Definition at line 1061 of file class_fiche.php.

References $result, and cn.

    {
        $result=$this->cn->get_array("select frd_id from fiche join fiche_Def using (fd_id) where f_id=".$this->id);
        if ( $result == null )
            return null;

        return $result[0]['frd_id'];
    }

Definition at line 1919 of file class_fiche.php.

References $r, get_quick_code(), getAttribut(), getName(), and h().

        {
                $r = "<h2>" . h($this->getName()) . " " . h($this->getAttribut(ATTR_DEF_FIRST_NAME)) . '[' . $this->get_quick_code() . ']</h2>';
                return $r;
        }

return the quick_code of a card

Returns:
null if not quick_code is found

Definition at line 1032 of file class_fiche.php.

References $r, $Res, $sql, cn, and Database\fetch_all().

Referenced by belong_ledger(), and get_gestion_title().

    {
        $sql="select ad_value from fiche_detail where ad_id=23 and f_id=$1";
        $Res=$this->cn->exec_sql($sql,array($this->id));
        $r=Database::fetch_all($Res);
        if ( sizeof($r) == 0 )
            return null;
        return $r[0]['ad_value'];
    }
Fiche::get_row ( p_from,
p_to 
)

Get data for poste.

Parameters:
$p_fromperiode from
$p_toend periode
Returns:
double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal) (tot_deb,tot_credit

Definition at line 1157 of file class_fiche.php.

References $periode, $qcode, $Res, cn, echo_error(), get_row_result(), sql_filter_per(), and strAttribut().

    {
        if ( $this->id == 0 )
        {
            echo_error("class_fiche",__LINE__,"id is 0");
            return;
        }
        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
        $periode=sql_filter_per($this->cn,$p_from,$p_to,'p_id','jr_tech_per');

        $Res=$this->cn->exec_sql("select j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_qcode,".
                                 "case when j_debit='t' then j_montant else 0 end as deb_montant,".
                                 "case when j_debit='f' then j_montant else 0 end as cred_montant,".
                                 " jr_comment as description,jrn_def_name as jrn_name,".
                                 "j_debit, jr_internal,jr_id ".
                                 " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ".
                                 " left join jrn on jr_grpt_id=j_grpt".
                                 " where j_qcode='".$qcode."' and ".$periode.
                                 " order by j_date::date");
        return $this->get_row_result($Res);

    }
Fiche::get_row_date ( p_from,
p_to,
op_let = 0 
)

Get data for poste.

Parameters:
$p_fromperiode from
$p_toend periode
$op_let0 all operation, 1 only lettered one, 2 only unlettered one
Returns:
double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal) (tot_deb,tot_credit

Definition at line 1105 of file class_fiche.php.

References $g_user, $qcode, $Res, cn, echo_error(), get_row_result(), and strAttribut().

Referenced by HtmlTable(), and HtmlTableDetail().

    {
        global $g_user;
        if ( $this->id == 0 )
        {
            echo_error("class_fiche",__LINE__,"id is 0");
            return;
        }
        $filter_sql=$g_user->get_ledger_sql('ALL',3);
        $sql_let='';
        switch ($op_let)
        {
        case 0:
            break;
        case 1:
            $sql_let=' and j_id in (select j_id from letter_cred union select j_id from letter_deb)';
            break;
        case '2':
            $sql_let=' and j_id not in (select j_id from letter_cred union select j_id from letter_deb) ';
            break;
        }

        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
        $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,".
                                 "case when j_debit='t' then j_montant else 0 end as deb_montant,".
                                 "case when j_debit='f' then j_montant else 0 end as cred_montant,".
                                 " jr_comment as description,jrn_def_name as jrn_name,".
                                 " jr_pj_number,".
                                 "j_debit, jr_internal,jr_id,coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter, ".
                                 " jr_tech_per,p_exercice,
                                                                  jrn_def_code".
                                 " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ".
                                 " left join jrn on jr_grpt_id=j_grpt".
                                 " left join parm_periode on (p_id=jr_tech_per) ".
                                 " where j_qcode=$1 and ".
                                 " ( to_date($2,'DD.MM.YYYY') <= j_date and ".
                                 "   to_date($3,'DD.MM.YYYY') >= j_date )".
                                 " and $filter_sql $sql_let ".
                                 " order by j_date,substring(jr_pj_number,'[0-9]+$')",array($qcode,$p_from,$p_to));

        return $this->get_row_result($Res);
    }
Fiche::get_row_result ( res) [private]

fetch and return and array

See also:
get_row get_row_date

Definition at line 1073 of file class_fiche.php.

References $array, $Max, $res, $tot_cred, $tot_deb, Database\fetch_array(), and Database\num_row().

Referenced by get_row(), and get_row_date().

    {
        $array=array();
        $tot_cred=0.0;
        $tot_deb=0.0;
        $Max=Database::num_row($res);
        if ( $Max == 0 ) return null;
        for ($i=0;$i<$Max;$i++)
        {
            $array[]=Database::fetch_array($res,$i);
            if ($array[$i]['j_debit']=='t')
            {
                $tot_deb+=$array[$i]['deb_montant'] ;
            }
            else
            {
                $tot_cred+=$array[$i]['cred_montant'] ;
            }
        }
        $this->row=$array;
        return array($array,$tot_deb,$tot_cred);
    }
Fiche::get_solde_detail ( p_cond = "")

give the balance of an card

Returns:
balance of the card

Definition at line 1438 of file class_fiche.php.

References $Max, $qcode, $r, $Res, cn, Database\fetch_array(), Database\num_row(), and strAttribut().

    {
        if ( $this->id == 0 ) return array('credit'=>0,'debit'=>0,'solde'=>0);
        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);

        if ( $p_cond != "") $p_cond=" and ".$p_cond;
        $Res=$this->cn->exec_sql("select sum(deb) as sum_deb, sum(cred) as sum_cred from
                                 ( select j_poste,
                                 case when j_debit='t' then j_montant else 0 end as deb,
                                 case when j_debit='f' then j_montant else 0 end as cred
                                 from jrnx
                                 where
                                 j_qcode = ('$qcode'::text)
                                 $p_cond
                                 ) as m  ");
        $Max=Database::num_row($Res);
        if ($Max==0) return 0;
        $r=Database::fetch_array($Res,0);

        return array('debit'=>$r['sum_deb'],
                     'credit'=>$r['sum_cred'],
                     'solde'=>abs($r['sum_deb']-$r['sum_cred']));
    }

get all the attribute of a card, add missing ones and sort the array ($this->attribut) by ad_id

Definition at line 146 of file class_fiche.php.

References $e, $f, $Max, $Ret, $row, $sql, cn, Database\fetch_array(), and Database\num_row().

Referenced by Get(), get_by_qcode(), get_gestion_title(), and setAttribut().

    {
        if ( $this->id == 0)
        {
            return;
        }
        $sql="select *
             from
                   fiche
             natural join fiche_detail
             join jnt_fic_attr on (jnt_fic_attr.fd_id=fiche.fd_id and fiche_detail.ad_id=jnt_fic_attr.ad_id)
             join attr_def on (attr_def.ad_id=fiche_detail.ad_id) where f_id=".$this->id.
             " order by jnt_order";

        $Ret=$this->cn->exec_sql($sql);
        if ( ($Max=Database::num_row($Ret)) == 0 )
            return ;
        for ($i=0;$i<$Max;$i++)
        {
            $row=Database::fetch_array($Ret,$i);
            $this->fiche_def=$row['fd_id'];
            $t=new Fiche_Attr ($this->cn);
            $t->ad_id=$row['ad_id'];
            $t->ad_text=$row['ad_text'];
            $t->av_text=$row['ad_value'];
            $t->ad_type=$row['ad_type'];
            $t->ad_size=$row['ad_size'];
            $t->ad_extra=$row['ad_extra'];
            $t->jnt_order=$row['jnt_order'];
            $this->attribut[$i]=$t;
        }
        $e=new Fiche_Def($this->cn,$this->fiche_def);
        $e->GetAttribut();

        if ( sizeof($this->attribut) != sizeof($e->attribut ) )
        {

            /*
                         * !! Missing attribute
                         */
            foreach ($e->attribut as $f )
            {
                $flag=0;
                foreach ($this->attribut as $g )
                {
                    if ( $g->ad_id == $f->ad_id )
                        $flag=1;
                }
                if ( $flag == 0 )
                {
                    // there's a missing one, we insert it
                    $t=new Fiche_Attr ($f->ad_id);
                    $t->av_text="";
                    $t->ad_text=$f->ad_text;
                    $t->jnt_order=$f->jnt_order;
                    $t->ad_type=$f->ad_type;
                    $t->ad_size=$f->ad_size;
                    $t->ad_id=$f->ad_id;
                    $t->ad_extra=$f->ad_extra;
                    $this->attribut[$Max]=$t;
                    $Max++;
                } // if flag == 0

            }// foreach


        }//missing attribut
    }
Fiche::GetByDef ( p_frd_id,
p_offset = -1,
p_search = "",
p_order = '' 
)

Return array of card from the frd family.

Parameters:
$p_frd_idthe fiche_def_ref.frd_id
$p_offset
$p_searchis an optional filter
$p_order: possible values are name, f_id
Returns:
array of fiche object

Definition at line 280 of file class_fiche.php.

References $all, $Max, $order, $p_order, $Ret, $row, $sql, cn, Database\fetch_array(), and Database\num_row().

Referenced by get_by_category().

    {
        switch($p_order)
        {
        case 'name' :
                $order=' order by name';
            break;
        case 'f_id':
            $order='order by f_id';
            break;
        default:
            $order='';
        }
        if ( $p_offset == -1 )
        {
            $sql="select *
                 from
                 fiche join fiche_Def using (fd_id) join vw_fiche_name using(f_id)
                 where frd_id=".$p_frd_id." $p_search ".$order;
        }
        else
        {
            $limit=($_SESSION['g_pagesize']!=-1)?"limit ".$_SESSION['g_pagesize']:"";
            $sql="select *
                 from
                 fiche join fiche_Def using (fd_id) join vw_fiche_name using(f_id)
                 where frd_id=".$p_frd_id." $p_search $order  "
                 .$limit." offset ".$p_offset;

        }

        $Ret=$this->cn->exec_sql($sql);
        if ( ($Max=Database::num_row($Ret)) == 0 )
            return ;
        $all[0]=new Fiche($this->cn);

        for ($i=0;$i<$Max;$i++)
        {
            $row=Database::fetch_array($Ret,$i);
            $t=new Fiche($this->cn,$row['f_id']);
            $t->getAttribut();
            $all[$i]=clone $t;

        }
        return $all;
    }

return the name of a card

Definition at line 1018 of file class_fiche.php.

References $r, $Res, $sql, cn, and Database\fetch_all().

Referenced by get_gestion_title(), and HtmlTableDetail().

    {
        $sql="select ad_value from fiche_detail
             where ad_id=1 and f_id=$1";
        $Res=$this->cn->exec_sql($sql,array($this->id));
        $r=Database::fetch_all($Res);
        if ( sizeof($r) == 0 )
            return 1;
        return $r[0]['ad_value'];
    }
Fiche::HtmlTable ( p_array = null,
op_let = 0,
from_div = 1 
)

HtmlTable, display a HTML of a card for the asked period.

Parameters:
$p_arraydefault = null keys = from_periode, to_periode
$op_let0 all operation, 1 only lettered one, 2 only unlettered one
Returns:
-1 if nothing is found otherwise 0
See also:
get_row_date

Definition at line 1252 of file class_fiche.php.

References $_REQUEST, $array, $class, $diff, $from_div, $idx, $op, $p_array, $progress, $rep, $side, $tmp, $tot_cred, $tot_deb, cmpDate(), echo, format_date(), get_row_date(), h(), id, nbm(), show_reconcile(), td(), and th().

    {
        if ( $p_array == null)
            $p_array=$_REQUEST;
        $progress=0;
                // if from_periode is greater than to periode then swap the values
                if (cmpDate($p_array['from_periode'],$p_array['to_periode']) > 0)
                {
                        $tmp=$p_array['from_periode'];
                        $p_array['from_periode']=$p_array['to_periode'];
                        $p_array['to_periode']=$tmp;

                }
        list($array, $tot_deb, $tot_cred) = $this->get_row_date($p_array['from_periode'], $p_array['to_periode'], $op_let);

        if ( count($this->row ) == 0 )
            return -1;

        $rep="";
        if ( $from_div==1)
          {
            echo "<TABLE class=\"resultfooter\" style=\"margin:1%;width:98%;;border-collapse:separate;border-spacing:0px 5px\">";
          }
        else
          {
            echo "<TABLE id=\"tb" . $from_div . "\"class=\"result\" style=\"margin:1%;width:98%;border-collapse:separate;border-spacing:0px 2px\">";
                }
        echo '<tbody>';
        echo "<TR>".
        "<TH style=\"text-align:left\">"._('Date')."</TH>".
        "<TH style=\"text-align:left\">"._('n° pièce')." </TH>".
        "<TH style=\"text-align:left\">"._('Code interne')." </TH>".
        "<TH style=\"text-align:left\">"._('Description')." </TH>".
        "<TH style=\"text-align:right\">"._('Débit')."  </TH>".
        "<TH style=\"text-align:right\">"._('Crédit')." </TH>".
        th('Prog.','style="text-align:right"').
        th('Let.','style="text-align:right"');
        "</TR>"
        ;
        $old_exercice="";$sum_deb=0;$sum_cred=0;
        bcscale(2);
        $idx=0;
        foreach ( $this->row as $op )
        {
            $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']);
            $let = '';
                        $html_let = "";
                        if ($op['letter'] != -1)
                        {
                                $let = strtoupper(base_convert($op['letter'], 10, 36));
                                $html_let = HtmlInput::show_reconcile($from_div, $let);
                        }
                        $tmp_diff=bcsub($op['deb_montant'],$op['cred_montant']);

            /*
             * reset prog. balance to zero if we change of exercice
             */
            if ( $old_exercice != $op['p_exercice'])
              {
                if ($old_exercice != '' )
                  {
                    $progress=bcsub($sum_deb,$sum_cred);
                        $side="&nbsp;".$this->get_amount_side($progress);
                    echo "<TR  style=\"font-weight:bold\">".
                      "<TD></TD>".
                      td('').
                      "<TD></TD>".
                      "<TD>Totaux</TD>".
                      "<TD style=\"text-align:right\">".nbm($sum_deb)."</TD>".
                      "<TD style=\"text-align:right\">".nbm($sum_cred)."</TD>".
                      td(nbm(abs($progress)).$side,'style="text-align:right"').
                      td('').
                      "</TR>";
                    $sum_cred=0;
                    $sum_deb=0;
                    $progress=0;
                  }
              }
            $progress=bcadd($progress,$tmp_diff);
                        $side="&nbsp;".$this->get_amount_side($progress);
            $sum_cred=bcadd($sum_cred,$op['cred_montant']);
            $sum_deb=bcadd($sum_deb,$op['deb_montant']);
                if ($idx%2 == 0) $class='class="odd"'; else $class=' class="even"';
                $idx++;

            echo "<TR $class name=\"tr_" . $let . "_" . $from_div . "\">" .
                        "<TD>".smaller_date(format_date($op['j_date_fmt']))."</TD>".
              td(h($op['jr_pj_number'])).
            "<TD>".$vw_operation."</TD>".
            "<TD>".h($op['description'])."</TD>".
            "<TD style=\"text-align:right\">".nbm($op['deb_montant'])."</TD>".
              "<TD style=\"text-align:right\">".nbm($op['cred_montant'])."</TD>".
              td(nbm(abs($progress)).$side,'style="text-align:right"').
            td($html_let, ' style="text-align:right"') .
                        "</TR>";
            $old_exercice=$op['p_exercice'];

        }
        $solde_type=($sum_deb>$sum_cred)?"solde débiteur":"solde créditeur";
        $diff=abs(bcsub($sum_deb,$sum_cred));
        echo '<tfoot>';
       echo "<TR style=\"font-weight:bold\">".
        "<TD>Totaux</TD>".
        "<TD ></TD>".
        "<TD ></TD>".
        "<TD></TD>".
         "<TD  style=\"text-align:right\">".nbm($sum_deb)."</TD>".
         "<TD  style=\"text-align:right\">".nbm($sum_cred)."</TD>".
          "<TD style=\"text-align:right\">".nbm($diff)."</TD>".

        "</TR>";
        echo "<TR style=\"font-weight:bold\">".
        "<TD>$solde_type</TD>".
          "<TD style=\"text-align:right\">".nbm($diff)."</TD>".
        "<TD></TD>".
        "</TR>";
        echo '</tfoot>';
        echo '</tbody>';

        echo "</table>";

        return 0;
    }
Fiche::HtmlTableDetail ( p_array = null,
op_let = 0 
)

HtmlTable, display a HTML of a card for the asked period.

Parameters:
$op_let0 all operation, 1 only lettered one, 2 only unlettered one
Returns:
none

Definition at line 1184 of file class_fiche.php.

References $_REQUEST, $ac, $array, $diff, $name, $op, $p_array, $qcode, $rep, $tot_cred, $tot_deb, cn, echo, get_row_date(), getName(), and strAttribut().

    {
        if ( $p_array == null)
            $p_array=$_REQUEST;

        $name=$this->getName();

        list($array,$tot_deb,$tot_cred)=$this->get_row_date( $p_array['from_periode'],
                                        $p_array['to_periode'],
                                        $op_let
                                                           );

        if ( count($this->row ) == 0 )
            return;
        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);

        $rep="";
        $already_seen=array();
        echo '<h2 class="info">'.$this->id." ".$name.'</h2>';
        echo "<TABLE class=\"result\" style=\"width:100%;border-collapse:separate;border-spacing:5px\">";
        echo "<TR>".
        "<TH> n° de pièce / Code interne </TH>".
        "<TH> Date</TH>".
        "<TH> Description </TH>".
        "<TH> Montant  </TH>".
        "<TH> Débit/Crédit </TH>".
        "</TR>";

        foreach ( $this->row as $op )
        {
            if ( in_array($op['jr_internal'],$already_seen) )
                continue;
            else
                $already_seen[]=$op['jr_internal'];
            echo "<TR  style=\"text-align:center;background-color:lightgrey\">".
            "<td>".$op['jr_pj_number']." / ".$op['jr_internal']."</td>".
            "<td>".$op['j_date']."</td>".
            "<td>".h($op['description'])."</td>".
            "<td>"."</td>".
            "<td>"."</td>".
            "</TR>";
            $ac=new Acc_Operation($this->cn);
            $ac->jr_id=$op['jr_id'];
            $ac->qcode=$qcode;
            echo $ac->display_jrnx_detail(1);

        }
        $solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde créditeur";
        $diff=round(abs($tot_deb-$tot_cred),2);
        echo "<TR>".
        "<TD>$solde_type".
        "<TD>$diff</TD>".
        "<TD></TD>".
        "<TD>$tot_deb</TD>".
        "<TD>$tot_cred</TD>".
        "</TR>";

        echo "</table>";

        return;
    }
Fiche::HtmlTableHeader ( p_array = null)

Display HTML Table Header (button)

Returns:
none

Definition at line 1380 of file class_fiche.php.

References $_REQUEST, $hid, $p_array, echo, HtmlInput\hidden(), HtmlInput\print_window(), and HtmlInput\submit().

    {
        if ( $p_array == null)
            $p_array=$_REQUEST;

        $hid=new IHidden();
        echo '<div class="noprint">';
        echo "<table >";
        echo '<TR>';

        echo '<TD><form method="GET" ACTION="">'.
        HtmlInput::submit('bt_other',"Autre poste").
        dossier::hidden().
        $hid->input("type","poste").$hid->input('p_action','impress')."</form></TD>";
        $str_ople=(isset($_REQUEST['ople']))?HtmlInput::hidden('ople',$_REQUEST['ople']):'';

        echo '<TD><form method="GET" ACTION="export.php">'.
        HtmlInput::submit('bt_pdf',"Export PDF").
        dossier::hidden().$str_ople.
          HtmlInput::hidden('act','PDF:fichedetail').
        $hid->input("type","poste").
        $hid->input('p_action','impress').
        $hid->input("f_id",$this->id).
        dossier::hidden().
        $hid->input("from_periode",$p_array['from_periode']).
        $hid->input("to_periode",$p_array['to_periode']);
        if (isset($p_array['oper_detail']))
            echo $hid->input('oper_detail','on');

        echo "</form></TD>";

        echo '<TD><form method="GET" ACTION="export.php">'.
        HtmlInput::submit('bt_csv',"Export CSV").
          HtmlInput::hidden('act','CSV:fichedetail').
        dossier::hidden().$str_ople.
        $hid->input("type","poste").
        $hid->input('p_action','impress').
        $hid->input("f_id",$this->id).
        $hid->input("from_periode",$p_array['from_periode']).
        $hid->input("to_periode",$p_array['to_periode']);
        if (isset($p_array['oper_detail']))
            echo $hid->input('oper_detail','on');

        echo "</form></TD>";
                echo "</form></TD>";
                echo '<td style="vertical-align:top">';
                echo HtmlInput::print_window();
                echo '</td>';
        echo "</table>";
        echo '</div>';

    }
Fiche::insert ( p_fiche_def,
p_array = null,
transaction = true 
)

insert a new record

Parameters:
$p_fiche_deffiche_def.fd_id
$p_arrayis the array containing the data
$transationif we want to manage the transaction in this function true for small insert and false for a larger loading, the BEGIN / COMMIT sql must be done into the caller av_textX where X is the ad_id example av_text1=>'name'

Definition at line 736 of file class_fiche.php.

References $e, $id, $name, $p_array, $Ret, $sql, $value, cn, h(), isNumber(), sql_string(), and trim().

Referenced by Save().

    {
        if ( $p_array == null)
            $p_array=$_POST;

        $fiche_id=$this->cn->get_next_seq('s_fiche');
        $this->id=$fiche_id;
        // first we create the card
        if ( $transaction)    $this->cn->start();
        /*
         * Sort the array for having the name AFTER the quickcode and the 
         * Accounting
         */
        ksort($p_array);
        
        try
        {
            $sql=sprintf("insert into fiche(f_id,fd_id)".
                         " values (%d,%d)",
                         $fiche_id,$p_fiche_def);
            $Ret=$this->cn->exec_sql($sql);
            // parse the $p_array array
            foreach ($p_array as $name=>$value )
            {
                /* avoid the button for searching an accounting item */
              if ( preg_match('/^av_text[0-9]+$/',$name) == 0) continue;

              list ($id) = sscanf ($name,"av_text%d");
              if ( $id == null ) continue;

                // Special traitement
                // quickcode
                if ( $id == ATTR_DEF_QUICKCODE)
                {
                    $sql=sprintf("select insert_quick_code(%d,'%s')",
                                 $fiche_id,sql_string($value));
                    $this->cn->exec_sql($sql);
                    continue;
                }
                // name
                if ( $id == ATTR_DEF_NAME )
                {
                    if ( strlen(trim($value)) == 0 )
                        $value="pas de nom";

                }
                // account
                if ( $id == ATTR_DEF_ACCOUNT )
                {
                    $v=sql_string($value);
                    try
                    {

                        if ( strlen(trim($v)) != 0)
                        {
                                                        if( strpos($value,',')==0)
                                                        {
                                                                $v=$this->cn->get_value("select format_account($1)",array($value));
                                                        } else {
                                                                $ac_array = explode(",", $value);
                                                                if (count($ac_array) <> 2)
                                                                        throw new Exception('Désolé, il y a trop de virgule dans le poste comptable ' . h($value));
                                                                $part1 = $ac_array[0];
                                                                $part2 = $ac_array[1];
                                                                $part1 = $this->cn->get_value('select format_account($1)', array($part1));
                                                                $part2 = $this->cn->get_value('select format_account($1)', array($part2));
                                                                $v = $part1 . ',' . $part2;
                                                        }
                            $parameter=array($this->id,$v);
                        }
                        else
                        {
                            $parameter=array($this->id,null);
                        }
                        $v=$this->cn->get_value("select account_insert($1,$2)",$parameter);
                    }
                    catch (Exception $e)
                    {
                        throw new Exception ("Erreur : ce compte [$v] n'a pas de compte parent.".
                                             "L'opération est annulée",
                                             1);
                    }
                    continue;
                }
                // TVA
                if ( $id == ATTR_DEF_TVA )
                {
                    // Verify if the rate exists, if not then do not update
                    if ( strlen(trim($value)) != 0 )
                    {
                        if ( isNumber($value) == 0 ) continue;
                        if ( $this->cn->count_sql("select * from tva_rate where tva_id=".$value) == 0)
                        {
                            continue;
                        }
                    }
                }
                // Normal traitement
                $value2=sql_string($value);

                $sql=sprintf("select attribut_insert(%d,%d,'%s')",
                             $fiche_id,$id,  strip_tags(trim($value2)));
                $this->cn->exec_sql($sql);
            }
        }
        catch (Exception $e)
        {
            $this->cn->rollback();
            throw ($e);
            return;
        }
        if ( $transaction)         $this->cn->commit();
        return;
    }

check if a card is used

Returns:
return true is a card is used otherwise false

Definition at line 1758 of file class_fiche.php.

References $count, $qcode, $sql, cn, and strAttribut().

    {
        /* retrieve first the quickcode */
        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
        $sql='select count(*) as c from jrnx where j_qcode=$1';
        $count=$this->cn->get_value($sql,array($qcode));
        if ( $count == 0 ) return false;
        return true;
    }
Fiche::move_to ( p_fdid)

move a card to another cat.

The properties will changed and be removed

Parameters:
$p_fdidthe fd_id of destination

Definition at line 1874 of file class_fiche.php.

References cn.

    {
        $this->cn->start();
        $this->cn->exec_sql('update fiche set fd_id=$1 where f_id=$2',array($p_fdid,$this->id));
        // add missing
        $this->cn->exec_sql('select fiche_attribut_synchro($1)',array($p_fdid));
        // add to the destination missing fields
        $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));
        $this->cn->commit();
    }
Fiche::remove ( silent = false)

remove a card

Definition at line 989 of file class_fiche.php.

References $fiche_def, $qcode, alert(), cn, Get(), and strAttribut().

    {
        if ( $this->id==0 ) return;
        // verify if that card has not been used is a ledger
        // if the card has its own account in PCMN
        // Get the fiche_def.fd_id from fiche.f_id
        $this->Get();
        $fiche_def=new Fiche_Def($this->cn,$this->fiche_def);
        $fiche_def->get();

        // if the card is used do not removed it
        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);

        if ( $this->cn->count_sql("select * from jrnx where j_qcode='".Database::escape_string($qcode)."'") != 0)
        {
            if ( ! $silent ) {
                                        alert('Impossible cette fiche est utilisée dans un journal');
                        }
            return 1;
        }

        $this->delete();
                return 0;
    }
Fiche::Save ( p_fiche_def = 0)

Save a card, call insert or update.

Parameters:
p_fiche_def(default 0)

Definition at line 714 of file class_fiche.php.

References insert(), and update().

    {
        // new card or only a update ?
        if ( $this->id == 0 )
            $this->insert($p_fiche_def);
        else
            $this->update();
    }
Fiche::seek ( p_attribut,
p_value 
)

find the card with the p_attribut equal to p_value, it is not case sensitive

Parameters:
$p_attributattribute to find see table attr_def
$p_valuevalue in attr_value.av_text
Returns:
return ARRAY OF jft_id,f_id,fd_id,ad_id,av_text

Definition at line 220 of file class_fiche.php.

References $res, $sql, and cn.

    {
        $sql="select jft_id,f_id,fd_id,ad_id,ad_value from fiche join fiche_detail using (f_id)
             where ad_id=$1 and upper(ad_value)=upper($2)";
        $res=$this->cn->get_array($sql,array($p_attribut,$p_value));
        return $res;
    }
Fiche::setAttribut ( p_ad_id,
p_value 
)

set an attribute by a value, if the attribut array is empty a call to getAttribut is performed

Parameters:
theAD_ID
thevalue
See also:
constant.php table: attr_def

Definition at line 130 of file class_fiche.php.

References $e, and getAttribut().

    {
        if ( sizeof($this->attribut)==0 ) $this->getAttribut();
        for ($e=0;$e <sizeof($this->attribut);$e++)
        {
            if ( $this->attribut[$e]->ad_id == $p_ad_id )
            {
                $this->attribut[$e]->av_text=$p_value;
                break;
            }
        }
    }

Definition at line 326 of file class_fiche.php.

References echo.

    {
        echo "<TR><TD> ".
        $this->id."</TD>".
        "<TR> <TD>".
        $this->attribut_value."</TD>".
        "<TR> <TD>".
        $this->attribut_def."</TD></TR>";
    }

give the size of a card object

Returns:
size

Definition at line 233 of file class_fiche.php.

    {
        if ( isset ($this->ad_id))
            return sizeof($this->ad_id);
        else
            return 0;
    }
Fiche::strAttribut ( p_ad_id,
p_return = 1 
)

return the string of the given attribute (attr_def.ad_id)

Parameters:
$p_ad_idthe AD_ID from attr_def.ad_id
See also:
constant.php
Returns:
string

Definition at line 343 of file class_fiche.php.

References $e, $Res, $row, $sql, cn, and Database\fetch_all().

Referenced by Acc_Ledger_Purchase\compute_no_deductible(), get_bk_balance(), get_row(), get_row_date(), get_solde_detail(), HtmlTableDetail(), Acc_Ledger_Purchase\insert_no_deductible(), is_used(), and remove().

    {
                $return=($p_return==1)?NOTFOUND:"";
        if ( sizeof ($this->attribut) == 0 )
        {

            if ($this->id==0) {
                                        return $return;
                        }
            // object is not in memory we need to look into the database
            $sql="select ad_value from fiche_detail
                 where f_id= $1  and ad_id= $2 ";
            $Res=$this->cn->exec_sql($sql,array($this->id,$p_ad_id));
            $row=Database::fetch_all($Res);
            // if not found return error
            if ( $row == false )
                return $return;

            return $row[0]['ad_value'];
        }

        foreach ($this->attribut as $e)
        {
            if ( $e->ad_id == $p_ad_id )
                return $e->av_text;
        }
        return $return;
    }
Fiche::Summary ( p_search = "",
p_action = "",
p_sql = "",
p_amount = false 
)

show the default screen

Summary

Parameters:
$p_search(filter)
$p_actionshow the action column
$p_sqlSQL to filter the number of card must start with AND
$p_amounttrue : only cards with at least one operation default : false
Returns:
: string to display

Reimplemented in contact.

Definition at line 1520 of file class_fiche.php.

References $_REQUEST, $amount, $bar, $cred, $deb, $e, $exercice, $filter_year, $g_user, $max, $offset, $page, $r, $script, $side, $solde, $str_dossier, cn, count_by_modele(), get_by_category(), navigation_bar(), nbm(), sql_string(), td(), and trim().

    {
        global $g_user;
        bcscale(4);
        $str_dossier=dossier::get();
        $p_search=sql_string($p_search);
        $script=$_SERVER['PHP_SELF'];
        // Creation of the nav bar
        // Get the max numberRow
        $filter_amount='';
        global $g_user;

        $filter_year="  j_tech_per in (select p_id from parm_periode ".
                     "where p_exercice='".$g_user->get_exercice()."')";

        if ( $p_amount) $filter_amount=' and f_id in (select f_id from jrnx where  '.$filter_year.')';

        $all_tiers=$this->count_by_modele($this->fiche_def_ref,"",$p_sql.$filter_amount);
        // Get offset and page variable
        $offset=( isset ($_REQUEST['offset'] )) ?$_REQUEST['offset']:0;
        $page=(isset($_REQUEST['page']))?$_REQUEST['page']:1;
        $bar=navigation_bar($offset,$all_tiers,$_SESSION['g_pagesize'],$page);

        // set a filter ?
        $search=$p_sql;

        $exercice=$g_user->get_exercice();
        $tPeriode=new Periode($this->cn);
        list($max,$min)=$tPeriode->get_limit($exercice);


        if ( trim($p_search) != "" )
        {
            $search.=" and f_id in
                     (select distinct f_id from fiche_detail
                     where
                     ad_id in (1,32,30,23,18,13) and ad_value ~* '$p_search')";
        }
        // Get The result Array
        $step_tiers=$this->get_by_category($offset,$search.$filter_amount,'name');

        if ( $all_tiers == 0 || count($step_tiers)==0 ) return "";
        $r="";
        $r.="Filtre rapide ".HtmlInput::filter_table("tiers_tb", '0,1', 1);
        $r.=$bar;
        
        $r.='<table  id="tiers_tb" class="sortable"  style="width:90%;margin-left:5%">
            <TR >
            <TH>'._('Quick Code').HtmlInput::infobulle(17).'</TH>
            <th  class="sorttable_sorted_reverse">'._('Nom').'<span id="sorttable_sortrevind">&nbsp;&blacktriangle;</span>'.'</th>
            <th>'._('Adresse').'</th>
            <th style="text-align:right">'._('Total débit').'</th>
            <th style="text-align:right">'._('Total crédit').'</th>
            <th style="text-align:right">'._('Solde').'</th>';
        $r.='</TR>';
        if ( sizeof ($step_tiers ) == 0 )
            return $r;

        $i=0;
                $deb=0;$cred=0;
        foreach ($step_tiers as $tiers )
        {
            $i++;
            $odd="";
             $odd  = ($i % 2 == 0 ) ? 'class="odd"': ' class="even" ';
            /* Filter on the default year */

            $amount=$tiers->get_solde_detail($filter_year);

            /* skip the tiers without operation */
            if ( $p_amount && $amount['debit']==0 && $amount['credit'] == 0 && $amount['solde'] == 0 ) continue;

            $r.="<TR $odd>";
            $e=sprintf('<A HREF="%s?ac=%s&sb=detail&f_id=%d&%s&sc=sv" title="Détail" class="line"> ',
                       $script,$_REQUEST['ac'],$tiers->id,$str_dossier);

            $r.="<TD> $e".$tiers->strAttribut(ATTR_DEF_QUICKCODE)."</A></TD>";
            $r.="<TD>".h($tiers->strAttribut(ATTR_DEF_NAME))."</TD>";
            $r.="<TD>".h($tiers->strAttribut(ATTR_DEF_ADRESS).
                         " ".$tiers->strAttribut(ATTR_DEF_CP).
                         " ".$tiers->strAttribut(ATTR_DEF_PAYS)).
                "</TD>";
            $str_deb=(($amount['debit']==0)?0:nbm($amount['debit']));
            $str_cred=(($amount['credit']==0)?0:nbm($amount['credit']));
            $str_solde=nbm($amount['solde']);
            $r.='<TD sorttable_customkey="'.$amount['debit'].'" align="right"> '.$str_deb.'</TD>';
            $r.='<TD sorttable_customkey="'.$amount['credit'].'" align="right"> '.$str_cred.'</TD>';
            $r.='<TD sorttable_customkey="'.$amount['solde'].'" align="right"> '.$str_solde."</TD>";
            $deb=bcadd($deb,$amount['debit']);
            $cred=bcadd($cred,$amount['credit']);

            $r.="</TR>";

        }
                $r.="<tfoot>";
                $solde=abs(bcsub($deb,$cred));
                $side=($deb > $cred)?'Débit':'Crédit';
                $r.=td("").td("").td("Totaux").td(nbm($deb),'class="num"').td(nbm($cred),'class="num"').td(" $side ".nbm($solde),'class="num"');
                $r.="</tfoot>";
        $r.="</TABLE>";
        $r.=$bar;
        return $r;
    }
static Fiche::test_me ( ) [static]

Definition at line 1898 of file class_fiche.php.

References $_GET, $a, $cn, $select_cat, echo, HtmlInput\hidden(), id, and HtmlInput\submit().

    {
        $cn=new Database(dossier::id());
        $a=new Fiche($cn);
        $select_cat=new ISelect('fd_id');
        $select_cat->value=$cn->make_array('select fd_id,fd_label from fiche_def where frd_id='.
                                           FICHE_TYPE_CLIENT);
        echo '<FORM METHOD="GET"> ';
        echo dossier::hidden();
        echo HtmlInput::hidden('test_select',$_GET['test_select']);
        echo 'Choix de la catégorie';
        echo $select_cat->input();
        echo HtmlInput::submit('go_card','Afficher');
        echo '</form>';
        if ( isset ($_GET['go_card']))
        {
            $empty=$a->to_array($_GET['fd_id']);
            print_r($empty);
        }
    }
Fiche::to_array ( pfd_id)

make an array of attributes of the category of card (FICHE_DEF.FD_ID) The array can be used with the function insert, it will return a struct like this : in the first key (av_textX), X is the ATTR_DEF::AD_ID

    Example
    Array
    (
      [av_text1] => Nom
      [av_text12] => Personne de contact
      [av_text5] => Poste Comptable
      [av_text13] => numéro de tva
      [av_text14] => Adresse
      [av_text15] => code postal
      [av_text24] => Ville
      [av_text16] => pays
      [av_text17] => téléphone
      [av_text18] => email
      [av_text23] => Quick Code
    )

    
Parameters:
$pfd_idFICHE_DEF::FD_ID
Returns:
an array of attribute
Exceptions:
Exceptionif the cat of card doesn't exist, Exception.getCode()=1
See also:
fiche::insert()

Definition at line 398 of file class_fiche.php.

References $a, $array, $idx, $ret, $sql, $val, and cn.

    {
        $sql="select 'av_text'||to_char(ad_id,'9999') as key,".
             " ad_text ".
             " from fiche_def join jnt_fic_attr using (fd_id)".
             " join attr_def using (ad_id) ".
             " where fd_id=$1 order by jnt_order";
        $ret=$this->cn->get_array($sql,array($pfd_id));
        if ( empty($ret)) throw new Exception(_('Cette categorie de card n\'existe pas').' '.$pfd_id,1);
        $array=array();
        foreach($ret as $idx=>$val)
        {
            $a=str_replace(' ','',$val['key']);
            $array[$a]=$val['ad_text'];
        }
        return $array;

    }
Fiche::update ( p_array = null)

update a card

Definition at line 855 of file class_fiche.php.

References $e, $g_user, $id, $name, $p_array, $Ret, $sql, $tmp, $value, cn, echo, Database\fetch_array(), h(), Database\num_row(), sql_string(), and trim().

Referenced by Save().

    {
        global $g_user;
        if ( $p_array == null)
            $p_array=$_POST;

        try
        {
            $this->cn->start();
            // parse the $p_array array
            foreach ($p_array as $name=>$value )
            {
                if ( preg_match('/^av_text[0-9]+$/',$name) == 0) continue;

                list ($id) = sscanf ($name,"av_text%d");

                if ( $id == null ) continue;

                // retrieve jft_id to update table attr_value
                $sql=" select jft_id from fiche_detail where ad_id=$id and f_id=$this->id";
                $Ret=$this->cn->exec_sql($sql);
                if ( Database::num_row($Ret) == 0 )
                {
                    // we need to insert this new attribut
                    $jft_id=$this->cn->get_next_seq('s_jnt_fic_att_value');

                    $sql2="insert into fiche_detail(jft_id,ad_id,f_id,ad_value) values ($1,$2,$3,NULL)";

                    $ret2=$this->cn->exec_sql($sql2,array($jft_id,$id,$this->id));

                }
                else
                {
                    $tmp=Database::fetch_array($Ret,0);
                    $jft_id=$tmp['jft_id'];
                }
                // Special traitement
                // quickcode
                if ( $id == ATTR_DEF_QUICKCODE)
                {
                    $sql=sprintf("select update_quick_code(%d,'%s')",
                                 $jft_id,sql_string($value));
                    $this->cn->exec_sql($sql);
                    continue;
                }
                // name
                if ( $id == ATTR_DEF_NAME )
                {
                    if ( strlen(trim($value)) == 0 )
                        continue;


                }
                // account
                if ($id == ATTR_DEF_ACCOUNT)
                                {
                                        $v = sql_string($value);
                                        if (trim($v) != '')
                                        {
                                                if (strpos($v, ',') != 0)
                                                {
                                                        $ac_array = explode(",", $v);
                                                        if (count($ac_array) <> 2)
                                                                throw new Exception('Désolé, il y a trop de virgule dans le poste comptable ' . h($v));
                                                        $part1 = $ac_array[0];
                                                        $part2 = $ac_array[1];
                                                        $part1 = $this->cn->get_value('select format_account($1)', array($part1));
                                                        $part2 = $this->cn->get_value('select format_account($1)', array($part2));
                                                        $v = $part1 . ',' . $part2;
                                                }
                                                else
                                                {
                                                        $v=$this->cn->get_value('select format_account($1)',array($value));
                                                }
                                                $sql = sprintf("select account_update(%d,'%s')", $this->id, $v);
                                                try
                                                {
                                                        $this->cn->exec_sql($sql);
                                                }
                                                catch (Exception $e)
                                                {
                                                        throw new Exception(__LINE__ . "Erreur : ce compte [$v] n'a pas de compte parent." .
                                                                        "L'op&eacute;ration est annul&eacute;e");
                                                }
                                                continue;
                                        }
                                        if (strlen(trim($v)) == 0)
                                        {

                                                $sql = sprintf("select account_update(%d,null)", $this->id);
                                                try
                                                {
                                                        $Ret = $this->cn->exec_sql($sql);
                                                }
                                                catch (Exception $e)
                                                {
                                                        throw new Exception(__LINE__ . "Erreur : ce compte [$v] n'a pas de compte parent." .
                                                                        "L'opération est annulée");
                                                }

                                                continue;
                                        }
                                }
                // TVA
                if ( $id == ATTR_DEF_TVA )
                {
                    // Verify if the rate exists, if not then do not update
                    if ( strlen(trim($value)) != 0 )
                    {
                        if ( $this->cn->count_sql("select * from tva_rate where tva_id=".$value) == 0)
                        {
                            continue;
                        }
                    }
                }
                // Normal traitement
                $sql="update fiche_detail set ad_value=$1 where jft_id=$2";
                                $this->cn->exec_sql($sql,array(strip_tags($value),$jft_id));
            }
        }
        catch (Exception $e )
        {
            echo '<span class="error">'.
            $e->getMessage().
            '</span>';
            $this->cn->rollback();
            return;
        }
        $this->cn->commit();
        return;

    }

Field Documentation

Fiche::$attribut

< $fiche_def fd_id

Definition at line 49 of file class_fiche.php.

Fiche::$cn

Definition at line 46 of file class_fiche.php.

Referenced by test_me().

Fiche::$fiche_def

< $id fiche.f_id

Definition at line 48 of file class_fiche.php.

Referenced by remove().

Fiche::$fiche_def_ref

< $attribut array of attribut object $fiche_def_ref Type

Definition at line 50 of file class_fiche.php.

Fiche::$id

< $cn database connection

Definition at line 47 of file class_fiche.php.

Referenced by insert(), and update().

Fiche::$quick_code

< All the row from the ledgers quick_code of the card

Definition at line 52 of file class_fiche.php.

Fiche::$row

The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations