noalyss Version-9
export_gl_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
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*! \file
23 * \brief create GL comptes as CSV.
24 * Argument $_GET
25 @code
26 * Array
27(
28 [gDossier] => 10104
29 [bt_csv] => Export CSV
30 [act] => CSV:glcompte
31 [type] => poste
32 [p_action] => impress
33 [from_periode] => 01.01.2016
34 [to_periode] => 31.12.2016
35 [from_poste] =>
36 [to_poste] =>
37)
38@encode
39 */
40
41if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
42include_once NOALYSS_INCLUDE.'/class/acc_account_ledger.class.php';
43include_once NOALYSS_INCLUDE.'/lib/ac_common.php';
44include_once NOALYSS_INCLUDE.'/lib/impress.class.php';
45$http=new HttpInput();
46$from_periode = $http->get("from_periode","date");
47$to_periode = $http->get("to_periode","date");
48$from_poste = $http->get("from_poste");
49$to_poste = $http->get("to_poste");
50
52/* Security */
54
55$export=new Noalyss_Csv(_('grandlivre'));
56$accounting_item_id=$http->get('poste_id',"string","");
57$export->send_header();
58
60
61if ( count($a_accounting) == 0 )
62{
63 echo _('Aucun résultat');
64 printf("\n");
65 exit;
66}
67
68// Header
69$header = array( _("Date"), _("Référence"), _("Libellé"), _("Pièce"),_("Lettrage"),_("Type"), _("Débit"), _("Crédit"), _("Solde") );
70
71$l=(isset($_GET['letter']))?2:0;
72$s=(isset($_REQUEST['solded']))?1:0;
73
74foreach ($a_accounting as $accounting_item)
75{
76
77
78 $acc_account_ledger=new Acc_Account_Ledger($cn,$accounting_item['pcm_val']);
79
80 $array1=$acc_account_ledger->get_row_date($from_periode,$to_periode,$l,$s);
81 // don't print empty account
82 if ( count($array1) == 0 )
83 {
84 continue;
85 }
86 $array=$array1[0];
87 $tot_deb=$array1[1];
88 $tot_cred=$array1[2];
89
90 // don't print empty account
91 if ( count($array) == 0 )
92 {
93 continue;
94 }
95
96 $export->add(sprintf("%s - %s ",$accounting_item['pcm_val'],$accounting_item['pcm_lib']));
97 $export->write();
98 $export->write_header($header);
99
100 $solde = 0.0;
101 $solde_d = 0.0;
102 $solde_c = 0.0;
103 bcscale(2);
105 foreach ($acc_account_ledger->row as $detail)
106 {
107
108 /*
109 [0] => 1 [jr_id] => 1
110 [1] => 01.02.2009 [j_date_fmt] => 01.02.2009
111 [2] => 2009-02-01 [j_date] => 2009-02-01
112 [3] => 0 [deb_montant] => 0
113 [4] => 12211.9100 [cred_montant] => 12211.9100
114 [5] => Ecriture douverture [description] => Ecriture douverture
115 [6] => Opération Diverses [jrn_name] => Opération Diverses
116 [7] => f [j_debit] => f
117 [8] => 17OD-01-1 [jr_internal] => 17OD-01-1
118 [9] => ODS1 [jr_pj_number] => ODS1 ) 1
119 */
120/*
121 * separation per exercice
122 */
123 if ( $current_exercice == "") $current_exercice=$detail['p_exercice'];
124
125 if ( $current_exercice != $detail['p_exercice']) {
126 $export->add("");
128 $export->add("");
129 $export->add("");
130 $export->add(_('Total')." ".$acc_account_ledger->id);
131 if ( $solde_d > 0 ) {
132 $export->add($solde_d,"number");
133 } else {
134 $export->add("");
135 }
136 if ( $solde_c > 0 ) {
137 $export->add($solde_c,"number");
138 } else {
139 $export->add("");
140 }
141
142 $export->add(abs($solde_c-$solde_d),"number");
143 $export->add(($solde_c > $solde_d ? 'C' : 'D'));
144 $export->write();
145 /*
146 * reset total and current_exercice
147 */
148 $current_exercice=$detail['p_exercice'];
149 $solde = 0.0;
150 $solde_d = 0.0;
151 $solde_c = 0.0;
152
153 }
154 if ($detail['cred_montant'] > 0)
155 {
156 $solde =bcsub($solde,$detail['cred_montant']);
157 $solde_c =bcadd($solde_c, $detail['cred_montant']);
158 }
159 if ($detail['deb_montant'] > 0)
160 {
161 $solde =bcadd($solde, $detail['deb_montant']);
162 $solde_d = bcadd($solde_d,$detail['deb_montant']);
163 }
164
165 $export->add($detail['j_date_fmt']);
166 $export->add($detail['jr_internal']);
167 $export->add($detail['description']);
168 $export->add($detail['jr_pj_number']);
169 if ($detail['letter'] == -1) { $export->add(""); }
170 else { $export->add($detail['letter']);}
171 $export->add($detail['jr_optype']);
172 if ($detail['deb_montant'] > 0 )
173 $export->add($detail['deb_montant'],"number");
174 else
175 $export->add("");
176
177 if ($detail['cred_montant'] > 0 )
178 $export->add($detail['cred_montant'],"number");
179 else
180 $export->add("");
181 $export->add(abs($solde),"number");
182 $export->add($acc_account_ledger->get_amount_side($solde),"text");
183 $export->write();
184
185 }
186
187
188 $export->add("");
190 $export->add("");
191 $export->add("");
192 $export->add(_('Total').$acc_account_ledger->id);
193 if ($solde_d > 0 ) $export->add($solde_d,"number"); else $export->add("");
194 if ($solde_c > 0 ) $export->add($solde_c,"number"); else $export->add("");
195 $export->add(abs($solde_c-$solde_d),"number");
196 $export->add(($solde_c > $solde_d ? 'C' : 'D'));
197 $export->write();
198}
199
200exit;
201
202?>
$_REQUEST['ac']
$input_from id
Definition: balance.inc.php:63
$from_poste
$to_poste
$_GET['qcode']
Manage the account from the table jrn, jrnx or tmp_pcmn.
static get_used_accounting($from_date, $to_date, $from_accounting, $to_accounting)
static connect()
manage the http input (get , post, request) and extract from an array
Manage the CSV : manage files and write CSV record.
for($e=0; $e< count($afiche); $e++) exit
$a_accounting
if(count($a_accounting)==0) $header