phpcompta-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpcompta-dev] r4377 - in phpcompta/trunk: html include sql


From: phpcompta-dev
Subject: [Phpcompta-dev] r4377 - in phpcompta/trunk: html include sql
Date: Thu, 17 Nov 2011 15:20:16 +0100 (CET)

Author: danydb
Date: 2011-11-17 15:20:15 +0100 (Thu, 17 Nov 2011)
New Revision: 4377

Added:
   phpcompta/trunk/include/export_anc_grandlivre_csv.php
   phpcompta/trunk/sql/anc-grandlivre.sql
Modified:
   phpcompta/trunk/html/export.php
   phpcompta/trunk/include/class_anc_grandlivre.php
   phpcompta/trunk/include/class_database.php
   phpcompta/trunk/include/class_impress.php
Log:
add export CSV to ANC grand livre

Modified: phpcompta/trunk/html/export.php
===================================================================
--- phpcompta/trunk/html/export.php     2011-11-17 13:38:12 UTC (rev 4376)
+++ phpcompta/trunk/html/export.php     2011-11-17 14:20:15 UTC (rev 4377)
@@ -39,7 +39,7 @@
 if ( $act=='X' || ! isset($_GET['act']) || $user->check_print($_GET['act'])==0 
)
   {
     echo alert('Accès interdit');
-       redirect("do.php?".dossier::get());
+    redirect("do.php?".dossier::get());
     exit();
   }
 
@@ -156,6 +156,9 @@
       require_once 'export_bilan_oth.php';
       exit();
       break;
+  case 'CSV:AncGrandLivre':
+      require_once 'export_anc_grandlivre_csv.php';
+      break;
    default:
     alert('Action inconnue '.$_GET['act']);
     exit();

Modified: phpcompta/trunk/include/class_anc_grandlivre.php
===================================================================
--- phpcompta/trunk/include/class_anc_grandlivre.php    2011-11-17 13:38:12 UTC 
(rev 4376)
+++ phpcompta/trunk/include/class_anc_grandlivre.php    2011-11-17 14:20:15 UTC 
(rev 4377)
@@ -24,6 +24,7 @@
  * \brief show the Grand Livre for analytic
  */
 require_once('class_anc_print.php');
+require_once 'class_impress.php';
 
 class Anc_GrandLivre extends Anc_Print
 {
@@ -63,7 +64,7 @@
        left join jrn on  (j_grpt=jr_grpt_id)
              where $pa_id_cond oa_amount <> 0.0  $cond_poste
        order by po_name,oa_date ,qcode,j_poste");
-
+        
        
         return $array;
     }
@@ -149,4 +150,71 @@
         $r.= '</table>';
         return $r;
     }
+      /*!
+     * \brief Show the button to export in PDF or CSV
+     * \param $url_csv url of the csv
+     * \param $url_pdf url of the pdf
+     * \param $p_string hidden data to include in the form
+     *
+     *
+     * \return string with the button
+     */
+    function show_button($p_string="")
+    {
+        $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:AncGrandLivre");
+
+        $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:AncGrandLivre");
+        $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;
+    }
+    function display_csv()
+    {
+        $r="";
+        //---Html
+        $array=$this->load();
+        if ( is_array($array) == false )
+        {
+            return $array;
+
+        }
+
+        if ( empty($array) )
+        {
+            $r.= _("aucune donnée");
+            return $r;
+        }
+
+        $ix=0;$prev='xx';
+       $tot_deb=$tot_cred=0;
+        $aheader=array();
+        $aheader=array("title"=>'Date','type'=>'string');
+        $aheader=array("title"=>'Poste','type'=>'string');
+        $aheader=array("title"=>'Quick_Code','type'=>'string');
+        $aheader=array("title"=>'libelle','type'=>'string');
+        $aheader=array("title"=>'Num.interne','type'=>'string');
+        $aheader=array("title"=>'Debit','type'=>'num');
+        $aheader=array("title"=>'Credit','type'=>'num');
+        Impress::array_to_csv($array, $aheader);
+    }
 }
\ No newline at end of file

Modified: phpcompta/trunk/include/class_database.php
===================================================================
--- phpcompta/trunk/include/class_database.php  2011-11-17 13:38:12 UTC (rev 
4376)
+++ phpcompta/trunk/include/class_database.php  2011-11-17 14:20:15 UTC (rev 
4377)
@@ -846,6 +846,45 @@
     {
       return pg_transaction_status($this->db);
     }
+    /**
+     * with the handle of a successull query, echo each row into CSV and
+     * send it directly
+     * @param type $ret handle to a query
+     * @param type $aheader  double array, each item of the array contains 
+     * a key type (num) and a key title
+     */
+    function query_to_csv($ret,$aheader)
+    {
+        $seq="";
+        for ($i=0;$i<count($i);$i++)
+        {
+            echo '"'.$aheader[$i]['title'].'"';
+            $seq=";";
+        }
+        printf("\n\r");
+        
+        $seq="";
+        // fetch all the rows
+        for ($i=0;$i<count(Database::num_row($ret));$i++)
+        {
+            $row=Database::fetch_array($ret, $i);
+            $sep2="";
+            // for each rows, for each value
+            for ($e=0;$e<count($row);$e++)
+            {
+                switch ($aheader[$e]['type'])
+                {
+                    case 'num':
+                        echo nb($row[$e]).$sep2;
+                        break;
+                    default:
+                        echo '"'.$row[$e].'"'.$sep2;
+                }
+                $sep2=";";
+            }
+            printf("\n\r");
+        }
+    }
 }
 
 /* test::test_me(); */

Modified: phpcompta/trunk/include/class_impress.php
===================================================================
--- phpcompta/trunk/include/class_impress.php   2011-11-17 13:38:12 UTC (rev 
4376)
+++ phpcompta/trunk/include/class_impress.php   2011-11-17 14:20:15 UTC (rev 
4377)
@@ -229,4 +229,43 @@
             return true;
         }
     }
+     /**
+     * with the handle of a successull query, echo each row into CSV and
+     * send it directly
+     * @param type $array of data
+     * @param type $aheader  double array, each item of the array contains 
+     * a key type (num) and a key title
+     */
+    static function array_to_csv($array,$aheader)
+    {
+        $seq="";
+        for ($i=0;$i<count($i);$i++)
+        {
+            echo '"'.$aheader[$i]['title'].'"';
+            $seq=";";
+        }
+        printf("\n\r");
+        
+        $seq="";
+        // fetch all the rows
+        for ($i=0;$i<count($array);$i++)
+        {
+            $row=$array[$i];
+            $sep2="";
+            // for each rows, for each value
+            for ($e=0;$e<count($row);$e++)
+            {
+                switch ($aheader[$e]['type'])
+                {
+                    case 'num':
+                        echo nb($row[$e]).$sep2;
+                        break;
+                    default:
+                        echo '"'.$row[$e].'"'.$sep2;
+                }
+                $sep2=";";
+            }
+            printf("\n\r");
+        }
+    }
 }
\ No newline at end of file

Added: phpcompta/trunk/include/export_anc_grandlivre_csv.php
===================================================================
--- phpcompta/trunk/include/export_anc_grandlivre_csv.php                       
        (rev 0)
+++ phpcompta/trunk/include/export_anc_grandlivre_csv.php       2011-11-17 
14:20:15 UTC (rev 4377)
@@ -0,0 +1,17 @@
+<?php
+header('Pragma: public');
+header('Content-type: application/csv');
+header('Content-Disposition: attachment;filename="anc-grand-livre.csv"',FALSE);
+
+require_once 'class_anc_grandlivre.php';
+
+$cn=Dossier::connect();
+
+$gl=new Anc_GrandLivre($cn);
+$gl->get_request();
+echo $gl->display_csv();
+
+
+
+
+?>

Added: phpcompta/trunk/sql/anc-grandlivre.sql
===================================================================
--- phpcompta/trunk/sql/anc-grandlivre.sql                              (rev 0)
+++ phpcompta/trunk/sql/anc-grandlivre.sql      2011-11-17 14:20:15 UTC (rev 
4377)
@@ -0,0 +1,15 @@
+insert into menu_ref(me_code,me_menu,me_file,me_description,me_type) 
+values ('CSV:AncGrandLivre','Impression Grand-Livre',null,null,'PR');
+CREATE TABLE profile_menu (
+    pm_id integer NOT NULL,
+    me_code text,
+    me_code_dep text,
+    p_id integer,
+    p_order integer,
+    p_type_display text NOT NULL,
+    pm_default integer
+);
+
+insert into profile_menu(me_code,me_code_dep,p_id,pm_default)
+values ( 'CSV:AncGrandLivre', NULL, 1 , 'P', 0);
+




reply via email to

[Prev in Thread] Current Thread [Next in Thread]