noalyss  Version-6.7.2
Public Member Functions | Static Public Member Functions
Anc_Balance_Simple Class Reference

manage the simple balance for CA, inherit from balance_ca More...

Inheritance diagram for Anc_Balance_Simple:
Anc_Print

Public Member Functions

 display_csv ()
 Compute the csv export.
 display_form ($p_string="")
 Compute the form to display.
 display_html ()
 compute the html display
 display_pdf ()
 Display the result in pdf.
 load ()
 load the data from the database
 set_sql_filter ()
 Set the filter (account_date)
 show_button ($p_string="")
 Show the button to export in PDF or CSV.

Static Public Member Functions

static test_me ()
 for testing and debuggind the class it must never be called from production system, it is intended only for developpers

Detailed Description

manage the simple balance for CA, inherit from balance_ca

Definition at line 36 of file class_anc_balance_simple.php.


Member Function Documentation

Compute the csv export.

Returns:
string with the csv

Definition at line 208 of file class_anc_balance_simple.php.

References $array, $r, $row, $solde, load(), and nb().

    {
        $array=$this->load();
        if ( is_array($array) == false )
        {
            return $array;

        }
        $r="";
        foreach ( $array as $row)
        {
            // the name and po_id
            $solde=($row['sum_cred']>$row['sum_deb'])?'C':'D';
            $solde=($row['sum_cred']==$row['sum_deb'])?'':$solde;
            $r.=sprintf("'%s';",$row['po_id']);
            $r.=sprintf("'%s';",$row['po_name']);
            $r.=sprintf("%s;",nb($row['sum_deb']));
            $r.=sprintf("%s;",nb($row['sum_cred']));
            $r.=sprintf("%s;",nb($row['solde']));
            $r.=sprintf("'%s'",$row['debit']);
            $r.="\r\n";
        }
        return $r;

    }
Anc_Balance_Simple::display_form ( p_string = "")

Compute the form to display.

Parameters:
$p_hiddenhidden tag to be included (gDossier,...)
Returns:
string containing the data

Reimplemented from Anc_Print.

Definition at line 165 of file class_anc_balance_simple.php.

References $r, and HtmlInput\submit().

    {
        $r=parent::display_form($p_string);

        $r.= HtmlInput::submit('Affiche','Affiche');

        return $r;
    }

compute the html display

Returns:
string

Definition at line 121 of file class_anc_balance_simple.php.

References $array, $deb, $r, $row, h(), load(), nbm(), and td().

    {
        $r="<table class=\"result\">";
        $r.="<tr>";
        $r.="<th>Poste comptable Analytique</th>";
        $r.="<th>D&eacute;bit</th>";
        $r.="<th>Cr&eacute;dit</th>";
        $r.="<th>Solde</th>";
        $r.="<th>D/C</th>";
        $r.="</tr>";

        $array=$this->load();
        $odd=0;
        if ( is_array($array) == false )
        {
            return $array;

        }
        foreach ( $array as $row)
        {
            $odd++;

            $r.=($odd%2==0)?'<tr class="odd">':'<tr class="even">';
            // the name and po_id
            //    $r.=sprintf("<td>%s</td>",$row['po_id']);
            $r.=sprintf("<td align=\"left\">%s</td>",h($row['po_name']));
            $r.=td(nbm($row['sum_deb']),' class="num"');
            $r.=td(nbm($row['sum_cred']),' class="num"');
            $r.=td(nbm($row['solde']),' class="num"');
            $deb=($row['sum_deb'] > $row['sum_cred'])?"D":"C";
            $deb=($row['solde'] == 0 )?'':$deb;
            $r.=sprintf("<td>%s</td>",$deb);
            $r.="</tr>";
        }
        $r.="</table>";
        return $r;
    }

Display the result in pdf.

Returns:
none

Definition at line 179 of file class_anc_balance_simple.php.

References $array, $fDate, $pdf, $row, db, from, from_poste, load(), nbm(), to, and to_poste.

    {
        $array=$this->load();
        $pdf=new PDFBalance_Simple($this->db);
        $pdf->set_info($this->from_poste,$this->to_poste,$this->from,$this->to);
        $pdf->AliasNbPages();
        $pdf->AddPage();
        $pdf->setTitle("Balance analytique",true);

        $pdf->SetFont('DejaVu','',6);
        for ($i=0;$i<count($array);$i++)
        {
            $row=$array[$i];
            $pdf->Cell(20,6,$row['po_id'],0,0,'L');
            $pdf->Cell(90,6,$row['po_name'],0,0,'L');
            $pdf->Cell(20,6,sprintf('%s',nbm($row['sum_deb'])),0,0,'R');
            $pdf->Cell(20,6,sprintf('%s',nbm($row['sum_cred'])),0,0,'R');
            $pdf->Cell(20,6,sprintf('%s',nbm($row['solde'])),0,0,'R');
            $pdf->Cell(20,6,$row['debit'],0,0,'R');
            $pdf->Ln();
        }
        $fDate=date('dmy-Hi');
        $pdf->output('simple-balance-'.$fDate.'.pdf','D');

    }

load the data from the database

Returns:
array

Definition at line 44 of file class_anc_balance_simple.php.

References $a, $array, $count, $res, $row, $sql, db, Database\fetch_all(), Database\num_row(), and set_sql_filter().

Referenced by display_csv(), display_html(), and display_pdf().

    {
        $filter=$this->set_sql_filter();
        // sum debit

        $sql="select m.po_id,sum(deb) as sum_deb,sum(cred) as sum_cred,";
        $sql.=" po_name||'  '||coalesce(po_description,'') as po_name";
        $sql.=" from ";
        $sql.=" (select po_id,case when oa_debit='t' then oa_amount else 0 end as deb,";
        $sql.="case when oa_debit='f' then oa_amount else 0 end as cred ";
        $sql.=" from operation_analytique join poste_analytique using(po_id)";
        $sql.=(empty($filter) == false)?" where ".$filter:"";
        $sql.=" ) as m join poste_analytique using (po_id)";
        $sql.=" where pa_id=".$this->pa_id;
        $sql.=" group by po_id,po_name,po_description";
        $sql.=" order by po_id";
        $res=$this->db->exec_sql($sql);

        if ( Database::num_row($res) == 0 )
            return null;
        $a=array();
        $count=0;
        $array=Database::fetch_all($res);
        foreach ($array as $row)
        {
            $a[$count]['po_id']=$row['po_id'];
            $a[$count]['sum_deb']=$row['sum_deb'];
            $a[$count]['sum_cred']=$row['sum_cred'];
            $a[$count]['po_name']=$row['po_name'];
            $a[$count]['solde']=abs($row['sum_deb']-$row['sum_cred']);
            $a[$count]['debit']=($row['sum_deb']>$row['sum_cred'])?"debit":"credit";
            $count++;
        }
        return $a;


    }

Set the filter (account_date)

Returns:
return the string to add to load

Reimplemented from Anc_Print.

Definition at line 88 of file class_anc_balance_simple.php.

References $sql, from, from_poste, to, and to_poste.

Referenced by load().

    {
        $sql="";
        $and="";
        if ( $this->from != "" )
        {
            $sql.=" oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
            $and=" and ";
        }
        if ( $this->to != "" )
        {
            $sql.=" $and oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
            $and=" and ";
        }
        if ( $this->from_poste != "" )
        {
            $sql.=" $and upper(po_name)>= upper('".$this->from_poste."')";
            $and=" and ";
        }
        if ( $this->to_poste != "" )
        {
            $sql.=" $and upper(po_name)<= upper('".$this->to_poste."')";
            $and=" and ";
        }
        return $sql;

    }
Anc_Balance_Simple::show_button ( p_string = "")

Show the button to export in PDF or CSV.

Parameters:
$url_csvurl of the csv
$url_pdfurl of the pdf
$p_stringhidden data to include in the form
Returns:
string with the button

Definition at line 242 of file class_anc_balance_simple.php.

References $r, from, from_poste, HtmlInput\hidden(), HtmlInput\submit(), to, and to_poste.

    {
        $r="";
        $r.= '<form method="GET" action="export.php" style="display:inline">';
        $r.= $p_string;
        $r.= dossier::hidden();
        $r.= HtmlInput::hidden("to",$this->to);
        $r.= HtmlInput::hidden("act","PDF:AncBalSimple");

        $r.= HtmlInput::hidden("from",$this->from);
        $r.= HtmlInput::hidden("pa_id",$this->pa_id);
        $r.= HtmlInput::hidden("from_poste",$this->from_poste);
        $r.= HtmlInput::hidden("to_poste",$this->to_poste);
        $r.=HtmlInput::submit('bt_pdf',"Export en PDF");
        $r.= '</form>';

        $r.= '<form method="GET" action="export.php"  style="display:inline">';
        $r.= HtmlInput::hidden("act","CSV:AncBalSimple");
        $r.= HtmlInput::hidden("to",$this->to);
        $r.= HtmlInput::hidden("from",$this->from);
        $r.= HtmlInput::hidden("pa_id",$this->pa_id);
        $r.= HtmlInput::hidden("from_poste",$this->from_poste);
        $r.= HtmlInput::hidden("to_poste",$this->to_poste);
        $r.= $p_string;
        $r.= dossier::hidden();
        $r.=HtmlInput::submit('bt_csv',"Export en CSV");
        $r.= '</form>';
        return $r;
    }
static Anc_Balance_Simple::test_me ( ) [static]

for testing and debuggind the class it must never be called from production system, it is intended only for developpers

Parameters:
\param
Returns:
none

Definition at line 283 of file class_anc_balance_simple.php.

References $_GET, $a, $bal, echo, and id.

    {
        // call the page with ?gDossier=14
        $a=new Database(dossier::id());

        $bal=new Anc_Balance_Simple($a);
        $bal->get_request();

        echo '<form method="GET">';

        echo $bal->display_form();
        echo '</form>';
        if ( isset($_GET['result']))
        {
            echo $bal->show_button("","");
            echo "<h1>HTML</h1>";
            echo $bal->display_html();
            echo "<h1>CSV</h1>";
            echo $bal->display_csv();
            /*  echo "<h1>pdf</h1>"; */
            /*  echo $bal->display_pdf(); */

        }

    }

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