noalyss Version-9
export_ledger_csv.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * NOALYSS is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * NOALYSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with NOALYSS; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21/*!
22 * \file
23 * \brief Send a ledger in CSV format , receives
24 * - jrn_id id of the ledger
25 * - p_simple L list , D detailled, A accounting, E extended
26 * - from periode
27 * - to periode
28 */
29if (!defined('ALLOWED'))
30 die('Appel direct ne sont pas permis');
31
32include_once NOALYSS_INCLUDE."/lib/ac_common.php";
33
34global $cn,$g_user;
35
36
39
40$export=new Noalyss_Csv(_('journal'));
41
42$export->send_header();
43
44
45/*
46 * Variable from $_GET
47 */
48try
49{
50 $get_jrn=$http->get('jrn_id', "number");
51 $get_option=$http->get('p_simple', "string");
52 $get_from_periode=$http->get('from_periode', 'number');
53 $get_to_periode=$http->get('to_periode', 'number');
54 $filter_operation=$http->get("operation_type");
55}
56catch (Exception $exc)
57{
58 echo $exc->getMessage();
59 error_log($exc->getTraceAsString());
60 throw $exc;
61}
62
63$g_user->Check();
64$g_user->check_dossier($gDossier);
65
66//----------------------------------------------------------------------------
67// $get_jrn == 0 when request for all ledger, in that case, we must filter
68// the legder with the security in Acc_Ledger::get_row
69//----------------------------------------------------------------------------
70if ($get_jrn!=0&&$g_user->check_jrn($get_jrn)=='X')
71{
72 NoAccess();
73 exit();
74}
75global $g_user;
76/**
77 * for all ledgers
78 */
79if ($get_jrn==0)
80{
81 // find out all the available ledgers for the current user
83 $Jrn=new Acc_Ledger($cn,0);
84}
85else
86{
87 $a_jrn=$get_jrn;
88 $Jrn=new Acc_Ledger($cn, $get_jrn);
89}
90
91$Jrn->get_name();
92$jrn_type=$Jrn->get_type();
93
94//
95// With Detail per item which is possible only for VEN or ACH
96// For Detailled VAT for ACH or VEN
97// ODS or all ledgers becomes A
98// Extended but no FIN becomes L
99//
100if ( $get_option=="E")
101{
102 if ($jrn_type=='FIN')
103 {
104 $get_option='A';
105 }
106 elseif ($jrn_type=='ODS'||$Jrn->id==0)
107 {
108 $get_option='A';
109 }
110 else
111 {
112 switch ($jrn_type)
113 {
114 case 'VEN':
115 $ledger=new Acc_Ledger_Sale($cn, $get_jrn);
116 $ret_detail=$ledger->get_detail_sale($get_from_periode,
119
120 break;
121 case 'ACH':
122 $ledger=new Acc_Ledger_Purchase($cn, $get_jrn);
123 $ret_detail=$ledger->get_detail_purchase($get_from_periode,
126 break;
127 default:
128 die(__FILE__.":".__LINE__.'Journal invalide');
129 break;
130 }
131 if ($ret_detail==null)
132 return;
133
134 $a_heading[]=_("Date paiement");
135 $a_heading[]=_("Montant paiement");
136 $a_heading[]=_("Methode paiement");
137 $a_heading[]=_("Libellé");
138 $a_heading[]=_("Opération paiement");
139
140 // Prepare the query for reconcile date
141 $prepared_query=new Prepared_Query($cn);
142 $prepared_query->prepare_reconcile_date();
143
144 $nb=Database::num_row($ret_detail);
145 $title=array();
146 foreach ($a_heading as $key=> $value)
147 {
148 $title[]=$value;
149 }
150 for ($i=0; $i<$nb; $i++)
151 {
152 $row=Database::fetch_array($ret_detail, $i);
153 if ($i==0)
154 {
155 $export->write_header($title);
156 }
157 $a_row=array();
158 $type="text";
159 $idx_col=0;
160 foreach ($row as $col)
161 {
162 if ($idx_col> 18 ) $type="number";
163 $export->add($col,$type);
164 $idx_col++;
165 }
166 //info payment
167 $ret_reconcile=$cn->execute('reconcile_date',array($row['jr_id']));
169 for ($e=0;$e<$max;$e++) {
171 $export->add($row['jr_date']);
172 $export->add($row['jr_montant'],"number");
173 $export->add($row['qcode_bank']);
174 $export->add($row['qcode_name']);
175 $export->add($row['jr_internal']);
176 }
177 $export->write();
178 }
179 }
180}
181//-----------------------------------------------------------------------------
182// Detailled printing
183// For miscellaneous legder or all ledgers
184//-----------------------------------------------------------------------------
185if ($get_option=='A')
186{
187 if ($get_jrn == 0 )
188 {
189 $acc_ledger_history=new Acc_Ledger_History_Generic($cn, $a_jrn,
191 } else {
192 $acc_ledger_history=new Acc_Ledger_History_Generic($cn, array($a_jrn),
194
195 }
196 $acc_ledger_history->set_filter_operation($filter_operation);
197 $acc_ledger_history->export_csv();
198 exit;
199}
200//-----------------------------------------------------------------------------
201// Mode list for ODS , FIN and GL
202//-----------------------------------------------------------------------------
203if ($get_option=="L" && ($jrn_type=='ODS'||$jrn_type=='FIN'||$jrn_type=='GL') )
204{
205 if ( $get_jrn==0) {
206 $Row=$Jrn->get_rowSimple($get_from_periode, $get_to_periode, $a_jrn);
207 }else {
208 $Row=$Jrn->get_rowSimple($get_from_periode, $get_to_periode);
209 }
210 // Prepare the query for reconcile date
211 $prepared_query=new Prepared_Query($cn);
212 $prepared_query->prepare_reconcile_date();
213
214 $title=array();
215 $title[]=_("operation");
216 $title[]=_("Date");
217 $title[]=_("N° Pièce");
218 $title[]=_("QuickCode");
219 $title[]=_("Tiers");
220 $title[]=_("commentaire");
221 $title[]=_("internal");
222 $title[]=_("montant");
223 $title[]=_("montant devise");
224 $title[]=_("devise");
225 $title[]=_("taux");
226 $title[]=_("taux réf");
227 $export->write_header($title);
228 foreach ($Row as $line)
229 {
230 $tiers_id=$Jrn->get_tiers_id($line['jrn_def_type'], $line['jr_id']);
231 $fiche_tiers=new Fiche($cn, $tiers_id);
232 $tiers=$fiche_tiers->strAttribut(ATTR_DEF_NAME, 0)." ".$fiche_tiers->strAttribut(ATTR_DEF_FIRST_NAME,
233 0);
234
235 $export->add($line['num']);
236 $export->add($line['date']);
237 $export->add($line['jr_pj_number']);
238 $export->add($fiche_tiers->get_quick_code());
239 $export->add($tiers);
240 $export->add($line['comment']);
241 $export->add($line['jr_internal']);
242 // echo "<TD>".$line['pj'].";";
243 // If the ledger is financial :
244 // the credit must be negative and written in red
245 // Get the jrn type
246 if ($line['jrn_def_type']=='FIN')
247 {
248 $positive=$cn->get_value("select qf_amount from quant_fin ".
249 " where jr_id=$1", array($line['jr_id']));
250
251 $export->add($positive, "number");
252 // for financial , all the rows are in the table operation_currency and then the
253 // amount is doubled
254 $export->add(bcdiv($line['sum_ocamount'],2,4),"number");
255 }
256 else
257 {
258 $export->add($line['montant'], "number");
259 $export->add(bcadd($line['sum_ocamount'],$line['sum_ocvat_amount']),"number");
260 }
261 //-- add currency
262 $export->add($line['cr_code_iso']);
263 $export->add($line['currency_rate']);
264 $export->add($line['currency_rate_ref']);
265
266 //------ Add reconcilied operation ---------------
267 $ret_reconcile=$cn->execute('reconcile_date',
268 array($line['jr_id']));
270 if ($max>0)
271 {
272 for ($e=0; $e<$max; $e++)
273 {
275 $export->add($row['qcode_bank']);
276 $export->add($row['qcode_name']);
277 $export->add($row['jr_date']);
278 $export->add($row['jr_internal']);
279 $export->add($row['jr_pj_number']);
280 $export->add($row['jr_montant'],"number");
281 }
282 }
283 $export->write();
284 }
285 return;
286}
287
288//-----------------------------------------------------------------------------
289// Detail printing for ACH or VEN : 1 row resume the situation with VAT, DNA
290// for Misc the amount
291// For Financial only the tiers and the sign of the amount
292//-----------------------------------------------------------------------------
293if ($get_option=="L" || $get_option == 'D')
294{
295
296//-----------------------------------------------------
297 if ($jrn_type=='ODS'||$jrn_type=='FIN'||$jrn_type=='GL')
298 {
299 if ($get_jrn == 0 )
300 {
301 $acc_ledger_history=new Acc_Ledger_History_Generic($cn, $a_jrn,
303 } else {
304 $acc_ledger_history=new Acc_Ledger_History_Generic($cn, array($a_jrn),
306
307 }
308 $acc_ledger_history->set_filter_operation($filter_operation);
309 $acc_ledger_history->export_csv();
310 return;
311 }
312//------------------------------------------------------------------------------
313// One line summary with tiers, amount VAT, DNA, tva code ....
314//
315//------------------------------------------------------------------------------
316 if ($jrn_type=="ACH")
317 {
318 $acc_ledger_history=new Acc_Ledger_History_Purchase($cn, [$Jrn->id],
320 $acc_ledger_history->set_filter_operation($filter_operation);
321 $acc_ledger_history->export_csv();
322 }
323 if ($jrn_type=="VEN")
324 {
325 $acc_ledger_history=new Acc_Ledger_History_Sale($cn, [$Jrn->id],
327 $acc_ledger_history->set_filter_operation($filter_operation);
328 $acc_ledger_history->export_csv();
329 }
330}
331?>
NoAccess($js=1)
Echo no access and stop.
Definition: ac_common.php:480
$input_from id
Definition: balance.inc.php:63
manage the list of operation when we need several ledger with a different type or from Misceleaneous ...
Display the operations for Purchase.
Acc_Ledger_History : Manage the list (history) of operations for display.
Handle the ledger of purchase,.
static heading_detail_purchase()
compute an array with the heading cells for the details, used for the export in CSV
Handle the ledger of sold,.
static heading_detail_sale()
compute an array with the heading cells for the details, used for the export in CSV
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: fiche.class.php:38
manage the http input (get , post, request) and extract from an array
Manage the CSV : manage files and write CSV record.
contains prepared query used in different classes of the application
static available_ledger($get_from_periode)
find all the active ledger for the exerice of the periode and readable by the current user @global ty...
const ATTR_DEF_NAME
Definition: constant.php:216
const ATTR_DEF_FIRST_NAME
Definition: constant.php:238
for($e=0; $e< count($afiche); $e++) exit
$get_from_periode
global $cn
$get_to_periode
$filter_operation
global $g_user
if( $delta< 0) elseif( $delta==0)