noalyss Version-9
export_fiche_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
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!\file
23 * \brief Called by impress->category, export in CVS the history of a category
24 * of card
25 */
26if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
27
28
29// Security we check if user does exist and his privilege
30require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
31
32$allcard=(isset($_GET['allcard']))?1:0;
33$export=new Noalyss_Csv(_('fiche-balance'));
34
35/* balance */
36if ( $_GET['histo'] == 4 || $_GET['histo'] == 5)
37{
38 $fd=new Fiche_Def($cn,$_REQUEST['cat']);
39 if ( $allcard==1 && $fd->hasAttribute(ATTR_DEF_ACCOUNT) == false )
40 {
41 exit;
42 }
43 // all card
44 if ($allcard==1)
45 {
46 $afiche=$cn->get_array("select fd_id from vw_fiche_def where ad_id=".ATTR_DEF_ACCOUNT." order by fd_label asc");
47 }
48 else
49 {
50 $afiche[0]=array('fd_id'=>$_REQUEST['cat']);
51 }
52
53 $title=array("Quick code",_("Nom"),_("poste comptable"),_("debit"),_("credit"),_("solde"),"D/C");
54 $export->send_header();
55 $export->write_header($title);
56
57 for ($e = 0; $e < count($afiche); $e++)
58 {
59 $aCard = $cn->get_array("select f_id,ad_value from fiche join fiche_Detail using (f_id) where ad_id=1 and fd_id=$1 order by 2 ", array($afiche[$e]['fd_id']));
60
61 if (empty($aCard))
62 {
63 continue;
64 }
65
66 for ($i = 0; $i < count($aCard); $i++)
67 {
68 if (isDate($_REQUEST['start']) == null || isDate($_REQUEST['end']) == null)
69 exit;
70 $filter = " (j_date >= to_date('" . $_REQUEST['start'] . "','DD.MM.YYYY') " .
71 " and j_date <= to_date('" . $_REQUEST['end'] . "','DD.MM.YYYY')) ";
72 $oCard = new Fiche($cn, $aCard[$i]['f_id']);
73 $solde = $oCard->get_solde_detail($filter);
74 if ($solde['debit'] == 0 && $solde['credit'] == 0)
75 continue;
76 /* only not purged card */
77 if ($_GET['histo'] == 5 && $solde['solde'] == 0)
78 continue;
79 $side = '';
80 if (bcsub($solde['credit'], $solde['debit']) < 0)
81 $side = 'Deb.';
82 if (bcsub($solde['credit'], $solde['debit']) > 0)
83 $side = 'Cred.';
84
85 $export->add($oCard->strAttribut(ATTR_DEF_QUICKCODE));
86 $export->add($oCard->strAttribut(ATTR_DEF_NAME));
87 $export->add($oCard->strAttribut(ATTR_DEF_ACCOUNT));
88 $export->add($solde['debit'],"number");
89 $export->add($solde['credit'],"number");
90 $export->add(abs($solde['solde']),"number");
91 $export->add($side);
92 $export->write();
93 }
94 }
95}
96else
97{
98 // all card
99 if ($allcard == 1)
100 {
101 $afiche = $cn->get_array("select fd_id from vw_fiche_def where ad_id=" . ATTR_DEF_ACCOUNT . " order by fd_label asc");
102 }
103 else
104 {
105 $afiche[0] = array('fd_id' => $_REQUEST['cat']);
106 }
107 $export->send_header();
109 for ($e = 0; $e < count($afiche); $e++)
110 {
111 $array = Fiche::get_fiche_def($cn, $afiche[$e]['fd_id'], 'name_asc');
112
113 foreach ($array as $card)
114 {
115 $row = new Fiche($cn, $card['f_id']);
117 $letter->set_parameter('quick_code', $row->strAttribut(ATTR_DEF_QUICKCODE));
118 $letter->set_parameter('start', $_GET['start']);
119 $letter->set_parameter('end', $_GET['end']);
120 // all
121 if ($_GET['histo'] == 0)
122 {
123 $letter->get_all();
124 }
125
126 // lettered
127 if ($_GET['histo'] == 1)
128 {
129 $letter->get_letter();
130 }
131 // unlettered
132 if ($_GET['histo'] == 2)
133 {
134 $letter->get_unletter();
135 }
136 if ($_GET['histo'] == 6)
137 {
138 $letter->get_letter_diff();
139 }
140 /* skip if nothing to display */
141 if (count($letter->content) == 0)
142 continue;
143 $export->add($row->strAttribut(ATTR_DEF_QUICKCODE));
144 $export->add( $row->strAttribut(ATTR_DEF_NAME));
145 $export->add($row->strAttribut(ATTR_DEF_ACCOUNT));
146 $export->write();
147
148
149 $export->add(_('Date'));
150 $export->add(_('ref'));
151 $export->add(_('Interne'));
152 $export->add(_('Comm'));
153 $export->add(_('Débit'));
154 $export->add(_('Crébit'));
155 $export->add(_('Prog.'));
156 $export->add(_('D/C'));
157 $export->add(_('Let.'));
158 $export->add(_("Diff Let."));
159 $export->add(_("Code Devise"));
160 $export->add(_("Montant Devise"));
161 $export->add(_("Taux"));
162 $export->add(_("Taux de référence"));
163
164 $export->write();
165
166 $amount_deb = 0;
167 $amount_cred = 0;
168 $prog = 0;
169 bcscale(2);
170 for ($i = 0; $i < count($letter->content); $i++)
171 {
172 $row = $letter->content[$i];
173 $export->add($row['j_date_fmt']);
174 $export->add($row['jr_pj_number']);
175 $export->add($row['jr_internal']);
176 $export->add($row['jr_comment']);
177 if ($row['j_debit'] == 't')
178 {
179 $export->add($row['j_montant'],"number");
180 $export->add(0,"number");
181 $amount_deb=bcadd($amount_deb,$row['j_montant']);
182 $prog = bcadd($prog, $row['j_montant']);
183 }
184 else
185 {
186 $export->add(0,"number");
187 $export->add($row['j_montant'],"number");
188 $amount_cred=bcadd($amount_cred,$row['j_montant']);
189 $prog = bcsub($prog, $row['j_montant']);
190 }
191 $export->add(abs($prog),"number");
192 $export->add($fic->get_amount_side($prog));
193 if ($row['letter'] != -1)
194 {
195 $export->add(strtoupper(base_convert($row['letter'],10,36)));
196 $export->add($row['letter_diff'],"number");
197 }
198 else
199 {
200 $export->add("");
201 $export->add("");
202 }
203 $export->add($row['cr_code_iso']);
204 $export->add($row['currency_amount'],"number");
205 $export->add($row['currency_rate'],"number");
206 $export->add($row['currency_rate_ref'],"number");
207 $export->write();
208 }
209 if ($prog < 0 )
210 $msg="Solde Debit";
211 elseif ($prog>0)
212 $msg="Solde Credit";
213 else
214 $msg="soldé";
215 $export->add("");
216 $export->add("");
217 $export->add("");
218
219 $export->add($msg);
220 $export->add($amount_deb,"number");
221 $export->add($amount_cred,"number");
222 $export->add(abs($prog),"number");
223 $export->add($fic->get_amount_side($prog));
224
225 $export->write();
226 }
227 }
228}
230
231
isDate($p_date)
Definition: ac_common.php:236
$_REQUEST['ac']
$filter
$_GET['qcode']
define Class fiche and fiche def, those class are using class attribut
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: fiche.class.php:38
static get_fiche_def($p_cn, $pFd_id, $p_order='')
get all the card from a categorie
only for operation retrieved thanks a quick_code manage the accounting entries for a given card
Manage the CSV : manage files and write CSV record.
const ATTR_DEF_NAME
Definition: constant.php:216
const ATTR_DEF_QUICKCODE
Definition: constant.php:237
const ATTR_DEF_ACCOUNT
Definition: constant.php:215
if( $_GET['histo']==4|| $_GET['histo']==5) else
for($e=0; $e< count($afiche); $e++) exit
$afiche[0]
Definition: fiche.inc.php:482
$amount_cred
Definition: letter_all.php:6
$amount_deb
Definition: letter_all.php:6
if( $delta< 0) elseif( $delta==0)
$side