noalyss Version-9
export_balance_csv.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19// Copyright Author Dany De Bontridder danydb@aevalys.eu
20/*! \file
21 * \brief Return the balance in CSV format
22 */
23if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
24
25include_once ("lib/ac_common.php");
26include_once("class/acc_balance.class.php");
27
30
32bcscale(2);
33
34$http=new HttpInput();
35$export=new Noalyss_Csv('balance');
37$bal->jrn=null;
38$p_filter=$http->get("p_filter");
39switch( $p_filter)
40{
41case 0:
42 $bal->jrn=null;
43 break;
44case 1:
45 if ( isset($_GET['r_jrn']))
46 {
47 $selected=$http->get('r_jrn');
48 $array_ledger=$g_user->get_ledger('ALL',3);
50 for ($e=0;$e<count($selected);$e++)
51 {
52 if (isset ($selected[$e]) && in_array ($selected[$e],$array) )
53 $bal->jrn[]=$selected[$e];
54 }
55 }
56 break;
57case 2:
58 if ( isset($_GET['r_cat'])) $bal->filter_cat($http->get('r_cat'));
59 break;
60}
61
62$bal->from_poste=$http->get('from_poste');
63$bal->to_poste=$http->get('to_poste');
64
65if (isset($_GET['unsold'])) $bal->unsold=true;
66$prev = (isset($_GET['previous_exc'])) ? 1: 0;
67
68$row=$bal->get_row($http->get('from_periode','number'),
69 $http->get('to_periode','number'),
70 $prev);
71$prev = ( isset ($row[0]['sum_cred_previous'])) ?1:0;
72$title=array('poste','libelle');
73if ($prev == 1 ) $title=array_merge($title,array('deb n-1','cred n-1','solde n-1','d/c;'));
74$title=array_merge($title,array(_('Débit'),_('Crédit'),_("Solde débiteur"),_("Solde créditeur")));
75
76$export->send_header();
77$pstart = new Periode($cn,$http->get("from_periode"));
78$pend= new Periode($cn,$http->get("to_periode"));
79
80$export->add(sprintf (_("balance du %s au %s"),$pstart->first_day(),$pend->last_day()));
81$export->write();
82$export->write_header($title);
83
84foreach ($row as $r)
85{
86 $export->add($r['poste']);
87 $export->add($r['label']);
88
89 if ( $prev == 1 )
90 {
91 $delta=bcsub($r['solde_deb_previous'],$r['solde_cred_previous']);
92 $sign=($delta<0)?'C':'D';
93 $sign=($delta == 0)?'=':$sign;
94 $export->add($r['sum_deb_previous'],"number");
95 $export->add($r['sum_cred_previous'],"number");
96 $export->add(abs($delta),"number");
97 $export->add($sign);
98
99 }
100 $delta=bcsub($r['solde_deb'],$r['solde_cred']);
101 $export->add($r['sum_deb'],"number");
102 $export->add($r['sum_cred'],"number");
103
104 if ( $delta < 0){
105 $export->add("0","number");
106 $export->add($r['solde_cred'],"number");
107 }elseif ( $delta > 0 ) {
108 $export->add($r['solde_deb'],"number");
109 $export->add("0","number");
110 }elseif ($delta==0 && $r['poste']!="")
111 {
112 $export->add("0","number");
113 $export->add("0","number");
114 }elseif ( $delta == 0 && $r['poste'] =="" ) {
115 $export->add($r['solde_deb'],"number");
116 $export->add($r['solde_cred'],"number");
117 } else {
118 throw new \Exception(__FILE__.":".__LINE__);
119 }
120 $export->write();
121}
122
123
124?>
get_array_column($p_array, $key)
Definition: ac_common.php:1278
global $g_user
if no group available , then stop
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$array_ledger
$selected
$input_from id
Definition: balance.inc.php:63
$_GET['qcode']
Class for manipulating data to print the balance of account.
static connect()
manage the http input (get , post, request) and extract from an array
Manage the CSV : manage files and write CSV record.
For the periode tables parm_periode and jrn_periode.
if( $delta< 0) elseif( $delta==0)