phpcompta-dev
[Top][All Lists]
Advanced

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

[Phpcompta-dev] r5495 - phpcompta/trunk/include


From: phpcompta-dev
Subject: [Phpcompta-dev] r5495 - phpcompta/trunk/include
Date: Mon, 14 Oct 2013 23:15:36 +0200 (CEST)

Author: danydb
Date: 2013-10-14 23:15:36 +0200 (Mon, 14 Oct 2013)
New Revision: 5495

Modified:
   phpcompta/trunk/include/class_acc_reconciliation.php
   phpcompta/trunk/include/impress_rec.inc.php
Log:
Export CSV Reconciliation 

Modified: phpcompta/trunk/include/class_acc_reconciliation.php
===================================================================
--- phpcompta/trunk/include/class_acc_reconciliation.php        2013-10-14 
18:37:39 UTC (rev 5494)
+++ phpcompta/trunk/include/class_acc_reconciliation.php        2013-10-14 
21:15:36 UTC (rev 5495)
@@ -349,13 +349,14 @@
     {
         $array=$this->get_reconciled();
         $ret=array();
+        bcscale(2);
         for ($i=0;$i<count($array);$i++)
         {
             $first_amount=$array[$i]['first']['jr_montant'];
             $second_amount=0;
             for ($e=0;$e<count($array[$i]['depend']);$e++)
             {
-                $second_amount+=$array[$i]['depend'][$e]['jr_montant'];
+                
$second_amount=bcadd($second_amount,$array[$i]['depend'][$e]['jr_montant']);
             }
             if ( $p_equal &&  $first_amount==$second_amount)
             {
@@ -404,25 +405,110 @@
             echo '</tr>';
         }
     }
+    /**
+     * Export to CSV
+     * @param type $p_choice 
+     * 
+     * @note must be set before calling
+     *    - $this->a_jrn       array of ledger
+     *    - $this->start_day start date
+     *    - $this->end_day end date
+     * @see Acc_Reconciliation::get_data
+     */
+    function export_csv($p_choice)
+    {
+        $array = $this->get_data($p_choice);
+        for ($i = 0; $i < count($array); $i++)
+        {
+            // ---------------------------------------
+            // first index has 2 arrays : first & depend[]
+            // ---------------------------------------
+
+            $first = $array[$i]['first'];
+            $a_depend = array();
+            if (isset($array[$i]['depend']))
+            {
+                $a_depend = $array[$i]['depend'];
+                //----- HEADER ----
+                if ($i == 0)
+                {
+                    printf('"n°";"Date";"internal";"libellé";"n° pièce";"nom 
journal";"type journal";"montant"');
+                    printf(';"<->";"Date";"internal";"libellé";"n° pièce";"nom 
journal";"type journal";"montant"' . "\n\r");
+                }
+            }
+            else
+            {
+                //----- HEADER ----
+                if ($i == 0)
+                {
+                    printf('"n°";"Date";"internal";"libellé";"n° pièce";"nom 
journal";"type journal";"montant"' . "\n\r");
+                }
+            }
+            // --------------------------
+            // Print First
+            // --------------------------
+            printf('%d;"%s";"%s";"%s";"%s";"%s";"%s";%f',$i, 
$first['jr_date'], $first['jr_internal'], $first['jr_comment'], 
$first['jr_pj_number'], $first['jrn_def_name'], $first['jrn_def_type'], 
$first['jr_montant']);
+            if (count($a_depend) > 0)
+            {
+                // --------------------------------------
+                // Print first depending operation
+                // --------------------------------------
+                $depend = $a_depend[0];
+                printf(';"<->";"%s";"%s";"%s";"%s";"%s";"%s";%f' . "\n\r", 
$depend['jr_date'], $depend['jr_internal'], $depend['jr_comment'], 
$depend['jr_pj_number'], $depend['jrn_def_name'], $depend['jrn_def_type'], 
$depend['jr_montant']);
+
+                // --------------------------------------
+                // print other depending operation if any
+                // --------------------------------------
+                for ($e = 1; $e < count($a_depend); $e++)
+                {
+                    $depend = $a_depend[$e];
+                    printf(';;;;;;;"<->";');
+                    printf('"%s";"%s";"%s";"%s";"%s";"%s";%f' . "\n\r", 
$depend['jr_date'], $depend['jr_internal'], $depend['jr_comment'], 
$depend['jr_pj_number'], $depend['jrn_def_name'], $depend['jrn_def_type'], 
$depend['jr_montant']);
+                }
+            }
+            else
+            {
+                printf("\n\r");
+            }
+        }
+    }
+
+    /**
+     * 
+     * @param type $p_choice
+     *       - 0 : operation reconcilied
+     *       - 1 : reconcilied with different amount
+     *       - 2 : reconcilied with same amount
+     *       - 3 : not reconcilied 
+     * @return $array
+     */
+    function get_data($p_choice)
+    {
+        switch ($p_choice)
+        {
+            case 0:
+                $array = $this->get_reconciled();
+                break;
+            case 1:
+                $array = $this->get_reconciled_amount(false);
+                break;
+            case 2:
+                $array = $this->get_reconciled_amount(true);
+                break;
+            case 3:
+                $array = $this->get_not_reconciled();
+                break;
+            default:
+                echo "Choix invalid";
+                exit();
+        }
+        return $array;
+    }
+
     static function test_me()
     {
         $cn=new Database(dossier::id());
         $rap=new Acc_Reconciliation($cn);
-        /*    $rap->set_jr_id(38);
-        $a=$rap->get();
-        print_r($a);
-        $rap->remove(4);
-        $rap->insert("4,5,6");
-        $a=$rap->get();
-        print_r($a);
-        echo Acc_Reconciliation::$javascript;
-        $w=$rap->widget();
-        $w->name="jr_concerned";
-
-        $w->extra2="";
-        echo $w->input();
-        */
-        //var_dump($rap->get_reconciled(''));
         var_dump($rap->get_reconciled_amount('',false));
     }
 

Modified: phpcompta/trunk/include/impress_rec.inc.php
===================================================================
--- phpcompta/trunk/include/impress_rec.inc.php 2013-10-14 18:37:39 UTC (rev 
5494)
+++ phpcompta/trunk/include/impress_rec.inc.php 2013-10-14 21:15:36 UTC (rev 
5495)
@@ -83,29 +83,21 @@
 echo '</div>';
 echo '<div class="content">';
 if ( ! isset($_GET['vis'])) exit();
-$a=new Acc_Reconciliation($cn);
-$a->a_jrn=$r_jrn;
-$a->start_day=$dstart->value;
-$a->end_day=$dend->value;
+$acc_reconciliation=new Acc_Reconciliation($cn);
+$acc_reconciliation->a_jrn=$r_jrn;
+$acc_reconciliation->start_day=$dstart->value;
+$acc_reconciliation->end_day=$dend->value;
 
-switch ($choice)
-{
-case 0:
-    $array=$a->get_reconciled();
-    break;
-case 1:
-    $array=$a->get_reconciled_amount(false);
-    break;
-case 2:
-    $array=$a->get_reconciled_amount(true);
-    break;
-case 3:
-    $array=$a->get_not_reconciled();
-    break;
-default:
-    echo "Choix invalid";
-    exit();
-}
+$array=$acc_reconciliation->get_data($choice);
+
 $gDossier=Dossier::id();
+?>
+<form method="get" action="export.php">
+    <?php echo 
HtmlInput::get_to_hidden(array('ac','gDossier','p_end','p_start','choice','r_jrn'));
+    echo HtmlInput::hidden('act','CSV:Reconciliation');
+    echo HtmlInput::submit("csv_bt", "Export CSV");
+    ?>
+</form>
+<?php
 require_once('template/impress_reconciliation.php');
 exit();
\ No newline at end of file



---
PhpCompta est un logiciel de comptabilité libre en ligne (full web)
Projet opensource http://www.phpcompta.eu



reply via email to

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