noalyss Version-9
anc_grandlivre.class.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/*!
23 *\file
24 * \brief report the Grand Livre for analytic
25 */
26
27/*!\class Anc_GrandLivre
28 * \brief report he Grand Livre for analytic
29 */
31{
32
33 function set_sql_filter()
34 {
35 $sql="";
36 $and=" and ";
37 if ( $this->from != "" )
38 {
39 $sql.="$and oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
40 }
41 if ( $this->to != "" )
42 {
43 $sql.=" $and oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
44 }
45
46 return $sql;
47
48 }
49 /*!
50 * \brief load the data from the database
51 *
52 * \return array
53 */
54 function load()
55 {
56 $filter_date=$this->set_sql_filter();
57 $cond_poste='';
58 if ($this->from_poste != "" )
59 $cond_poste=" and upper(po_name) >= upper('".$this->from_poste."')";
60 if ($this->to_poste != "" )
61 $cond_poste.=" and upper(po_name) <= upper('".$this->to_poste."')";
62 $pa_id_cond="";
63 if ( isset ( $this->pa_id) && $this->pa_id !='')
64 $pa_id_cond= "pa_id=".$this->pa_id." and";
65 $array=$this->db->get_array(" select oa_id,
66 po_name,
67 oa_description,
68 po_description,
69 oa_debit,
70 to_char(oa_date,'DD.MM.YYYY') as oa_date,
71 oa_amount,
72 oa_group,
73 j_id ,
74 jr_internal,
75 jr_id,
76 coalesce(jr_comment,b.oa_description) as jr_comment,
77 case when j_poste is null and b.f_id is not null then
78 (select ad_value from fiche_detail where fiche_detail.f_id=b.f_id and ad_id=23)
79 when j_poste is not null then
80 j_poste
81 end as j_poste,
82 coalesce(jrnx.f_id,b.f_id) as f_id,
83 case when jrnx.f_id is not null then
84 (select ad_value from fiche_Detail where f_id=jrnx.f_id and ad_id=23)
85 when b.f_id is not null then
86 (select ad_value from fiche_Detail where f_id=b.f_id and ad_id=23)
87 end
88 as qcode,
89 jr_pj_number,
90 jr_tech_per,
91 ftiers.cardid,
92 (select ad_value from fiche_detail where f_id=ftiers.cardid and ad_id=23) as qcode_tiers
93 from operation_analytique as B join poste_analytique using(po_id)
94 left join jrnx using (j_id)
95 left join jrn on (j_grpt=jr_grpt_id)
96 left join ( select distinct qp_supplier as cardid,j_id from quant_purchase qp
97 union
98 select distinct qs_client,j_id from quant_sold qs
99 union
100 select distinct qf_bank,j_id from quant_fin qf ) as ftiers using (j_id)
101 where $pa_id_cond oa_amount <> 0.0 $cond_poste $filter_date
102 order by po_name,oa_date::date,qcode,j_poste");
103 $this->has_data=count($array);
104 return $array;
105 }
106
107 function load_csv()
108 {
109 $filter_date=$this->set_sql_filter();
110 $cond_poste='';
111 if ($this->from_poste != "" )
112 $cond_poste=" and upper(po_name) >= upper('".$this->from_poste."')";
113 if ($this->to_poste != "" )
114 $cond_poste.=" and upper(po_name) <= upper('".$this->to_poste."')";
115 $pa_id_cond="";
116 if ( isset ( $this->pa_id) && $this->pa_id !='')
117 $pa_id_cond= "pa_id=".$this->pa_id." and";
118 $array=$this->db->get_array(" select
119 po_name,
120 to_char(oa_date,'DD.MM.YYYY') as oa_date,
121 to_char(jr_date_paid,'DD.MM.YY') as strdate_paid,
122 case when j_poste is null and b.f_id is not null then
123 (select ad_value from fiche_detail where fiche_detail.f_id=b.f_id and ad_id=5)
124 when j_poste is not null then
125 j_poste
126 end as j_poste
127 ,
128 case when jrnx.f_id is not null then
129 (select ad_value from fiche_Detail where f_id=jrnx.f_id and ad_id=23)
130 when b.f_id is not null then
131 (select ad_value from fiche_Detail where f_id=b.f_id and ad_id=23)
132 end
133 as qcode,
134 coalesce(jr_comment,b.oa_description) as jr_comment,
135 (select ad_value from fiche_detail where f_id=ftiers.cardid and ad_id=23) as qcode_tiers,
136 coalesce (jr_pj_number,'') as jr_pj_number,
137 coalesce(jr_internal,'') as jr_internal,
138 coalesce(oa_group,0) as oa_group,
139 case when oa_debit='t' then oa_amount else 0 end as amount_deb,
140 case when oa_debit='f' then oa_amount else 0 end as amount_cred,
141 case when oa_debit='f' then 'C' else 'D' end as deb_cred,
142 ac.str_action ,
143 ag.str_action_ref ,
144 (
145 select string_agg( j10.jr_pj_number::text,'-')
146 from jrn j10
147 left join (select jr10.jr_id , jr10.jra_concerned from jrn_rapt jr10 ) as opr_cnc1 on (j10.jr_id=opr_cnc1.jr_id or j10.jr_id=opr_cnc1.jra_concerned)
148 where
149 opr_cnc1.jr_id=jrn.jr_id
150 or opr_cnc1.jra_concerned=jrn.jr_id) as agg_jr_pj_number,
151 (
152 select string_agg( j11.jr_internal::text,'-')
153 from jrn j11
154 left join (select jr11.jr_id , jr11.jra_concerned from jrn_rapt jr11 ) as opr_cnc2 on (j11.jr_id=opr_cnc2.jr_id or j11.jr_id=opr_cnc2.jra_concerned)
155 where
156 opr_cnc2.jr_id=jrn.jr_id
157 or opr_cnc2.jra_concerned=jrn.jr_id) as agg_jr_internal
158 from operation_analytique as B join poste_analytique using(po_id)
159 left join jrnx using (j_id)
160 left join jrn on (j_grpt=jr_grpt_id)
161 left join ( select distinct qp_supplier as cardid,j_id from quant_purchase qp
162 union
163 select distinct qs_client,j_id from quant_sold qs
164 union
165 select distinct qf_bank,j_id from quant_fin qf ) as ftiers using (j_id)
166 left join (select j.jr_id,string_agg( ag_id::text,'-') as str_action
167 from jrn j left
168 join action_gestion_operation ago on (j.jr_id=ago.jr_id )
169 group by j.jr_id) as ac on (ac.jr_id=jrn.jr_id)
170 left join (select j9.jr_id,string_agg( ag9.ag_ref::text,'-') as str_action_ref
171 from jrn j9 left
172 join action_gestion_operation ago9 on (j9.jr_id=ago9.jr_id )
173 join action_gestion ag9 on (ag9.ag_id =ago9.ag_id )
174 group by j9.jr_id) as ag on (ag.jr_id=jrn.jr_id)
175 where
176 $pa_id_cond oa_amount <> 0.0 $cond_poste $filter_date
177 order by po_name,oa_date::date,qcode,j_poste
178
179");
180
181
182 return $array;
183 }
184 /*!
185 * \brief Show the button to export in PDF all the receipt
186 *
187 * \param $p_string extra hidden value
188 * \return string with the button
189 */
190
191 function button_export_pdf($p_string = "")
192 {
193 if (CONVERT_GIF_PDF <> 'NOT' && PDFTK <> 'NOT')
194 {
195 $r="";
196 $r.= HtmlInput::hidden("to", $this->to);
197 $r.= HtmlInput::hidden("from", $this->from);
198 $r.= HtmlInput::hidden("pa_id", $this->pa_id);
199 $r.= HtmlInput::hidden("from_poste", $this->from_poste);
200 $r.= HtmlInput::hidden("to_poste", $this->to_poste);
201 $r.= HtmlInput::hidden("act","PDF:AncReceipt");
202
203 $r.= $p_string;
204 $r.= dossier::hidden();
205 $r.=HtmlInput::submit('bt_receipt_anal_pdf', _("Export des pièces en PDF"));
206 }
207 else
208 {
209
210 $r = "";
211 $msg = _("Les extensions CONVERT_GIF_PDF et PDFTK pour convertir en pdf ne sont pas installées ");
212 $r = HtmlInput::button("bt_receipt_anal",
213 _('Export des pièces en PDF'),
214 sprintf('onclick="smoke.alert(\'%s\')"',$msg));
215 }
216 return $r;
217 }
218 /*!
219 * \brief compute the html display
220 *
221 *
222 * \return string
223 */
224
225 function display_html($p_with_ck=1)
226 {
227 $r = "";
228 //---Html
229 $array = $this->load();
230 if (is_array($array) == false || empty($array))
231 {
232 return 0;
233 }
234 $r.= '<table class="result" style="width:100%;border-color:transparent">';
235 $ix = 0;
236 $prev = 'xx';
237 $idx = 0;
238 $tot_deb = $tot_cred = 0;
239
240 bcscale(2);
241 foreach ($array as $row)
242 {
243 if ($prev != $row['po_name'])
244 {
245 if ($ix > 0)
246 {
247 $r.='<tr class="highlight">';
248 $tot_solde = bcsub($tot_cred, $tot_deb);
249 $sign = " ".(($tot_solde > 0) ? 'C' : 'D');
250 $r.=td('') . td('') . td('');
251 $r.=td('') . td('') . td('') . td('') . td('') . td(nbm($tot_deb), ' class="num"') . td(nbm($tot_cred), ' class="num"') . td(nbm($tot_solde) . $sign, ' class="num"');
252 }
253 $r.='<tr>' . '<td colspan="12" style="width:auto">' . '<h2>' . h($row['po_name'] . ' ' . $row['po_description']) . '</td></tr>';
254 $r.= '<tr>' .
255 '<th>' . '</th>' .
256 '<th>' . _('Date') . '</th>' .
257 '<th>' . _('Poste') . '</th>' .
258 '<th>' . _('Quick_code') . '</th>' .
259 '<th>' . _('Libellé') . '</th>' .
260 th(_("Tiers")).
261 '<th>' . '</th>' .
262 '<th>' . _('Pièce') . '</th>' .
263 '<th>' . _('Interne') . '</th>' .
264 '<th style="text-align:right">' . _('Débit') . '</th>' .
265 '<th style="text-align:right">' . _('Crédit') . '</th>' .
266 '<th style="text-align:right">' . _('Prog.') . '</th>' .
267 '</tr>';
268
269 $tot_deb = $tot_cred = 0;
270 $prev = $row['po_name'];
271 $ix++;
272 }
273 $class = ($idx % 2 == 0) ? 'even' : 'odd';
274 $idx++;
275 // find out exercice
276 $exercice="";
277 if ( $row['jr_tech_per'] != null )
278 {
279 $periode=new Periode($this->db,$row['jr_tech_per']);
280 $exercice=$periode->get_exercice();
281 }
282 $r.='<tr class="' . $class . '">';
283 $detail = ($row['jr_id'] != null) ? HtmlInput::detail_op($row['jr_id'], $row['jr_internal']) : '';
284 $post_detail = ($row['j_poste'] != null) ? HtmlInput::history_account($row['j_poste'], $row['j_poste'],"",$exercice) : '';
285 $card_detail = ($row['f_id'] != null) ? HtmlInput::history_card($row['f_id'], $row['qcode'],"",$exercice) : '';
286 $amount_deb = ($row['oa_debit'] == 't') ? $row['oa_amount'] : 0;
287 $amount_cred = ($row['oa_debit'] == 'f') ? $row['oa_amount'] : 0;
288 $tot_deb = bcadd($tot_deb, $amount_deb);
290 $tot_solde=bcsub($tot_cred,$tot_deb);
291
292 /*
293 * Checked button
294 */
295 $str_ck = "";
296 $str_document = "";
297 if ($row['jr_id'] != null && $p_with_ck==1)
298 {
299 /*
300 * Get receipt info
301 */
302 $str_document = HtmlInput::show_receipt_document($row['jr_id']);
303 if ($str_document != "")
304 {
305 $ck = new ICheckBox('ck[]', $row['jr_id']);
306 $ck->set_range("document_export_ck");
307 $str_ck = $ck->input();
308 }
309 }
310
311 $r.=
312 '<td>' . $str_ck . '</td>' .
313 '<td>' . $row['oa_date'] . '</td>' .
314 td($post_detail) .
315 td($card_detail) .
316 td($row['jr_comment']) .
317 td($row["qcode_tiers"]).
318 '<td>' . $str_document . '</td>' .
319 td($row['jr_pj_number']) .
320 '<td>' . $detail . '</td>' .
321 '<td class="num">' . nbm($amount_deb) . '</td>' .
322 '<td class="num">' . nbm($amount_cred). '</td>'.
323 '<td class="num">' . nbm($tot_solde). '</td>';
324 $r.= '</tr>';
325 }
326 $r.='<tr class="highlight">';
327 $tot_solde = bcsub($tot_cred, $tot_deb);
328 $sign = ($tot_solde > 0) ? 'C' : 'D';
329 $r.=td('') . td('') . td('');
330 $r.=td('') . td('') . td('') . td('') . td('') . td(nbm($tot_deb), ' class="num"') . td(nbm($tot_cred), ' class="num"') . td(nbm($tot_solde) . $sign, ' class="num"');
331
332 $r.= '</table>';
333 $r.=ICheckBox::javascript_set_range("document_export_ck");
334 return $r;
335 }
336 /*!
337 * \brief Show the button to export CSV
338 * \return string with the button
339 */
340 function button_export_csv($p_string="")
341 {
342 $r="";
343 $r.= '<form method="GET" action="export.php" style="display:inline">';
344 $r.= HtmlInput::hidden("act","CSV:AncGrandLivre");
345 $r.= HtmlInput::hidden("to",$this->to);
346 $r.= HtmlInput::hidden("from",$this->from);
347 $r.= HtmlInput::hidden("pa_id",$this->pa_id);
348 $r.= HtmlInput::hidden("from_poste",$this->from_poste);
349 $r.= HtmlInput::hidden("to_poste",$this->to_poste);
350 $r.= $p_string;
351 $r.= dossier::hidden();
352 $r.=HtmlInput::submit('bt_csv',_("Export en CSV"));
353 $r.= '</form>';
354 return $r;
355 }
356 function display_csv()
357 {
358 $r="";
359 //---Html
360 $array=$this->load_csv();
361 if ( is_array($array) == false )
362 {
363 return $array;
364
365 }
366
367 $ix=0;$prev='xx';
369 $aheader=array();
370 $aheader[]=array("title"=>'Imp. Analytique','type'=>'string');
371 $aheader[]=array("title"=>'Date','type'=>'string');
372 $aheader[]=array("title"=>'Date Pay','type'=>'string');
373 $aheader[]=array("title"=>'Poste','type'=>'string');
374 $aheader[]=array("title"=>'Quick_Code','type'=>'string');
375 $aheader[]=array("title"=>'libelle','type'=>'string');
376 $aheader[]=array("title"=>'tiers','type'=>'string');
377 $aheader[]=array("title"=>'Pièce','type'=>'string');
378 $aheader[]=array("title"=>'Num.interne','type'=>'string');
379 $aheader[]=array("title"=>'row','type'=>'string');
380 $aheader[]=array("title"=>'Debit','type'=>'num');
381 $aheader[]=array("title"=>'Credit','type'=>'num');
382 $aheader[]=array("title"=>'D/C','type'=>'string');
383 $aheader[]=array("title"=>'Action','type'=>'string');
384 $aheader[]=array("title"=>'Suivi','type'=>'string');
385 $aheader[]=array("title"=>'Rapprochement pièce','type'=>'string');
386 $aheader[]=array("title"=>'Rapprochement n° interne','type'=>'string');
387 Impress::array_to_csv($array, $aheader,"export-anc-grandlivre");
388 }
389}
th($p_string, $p_extra='', $raw='')
Definition: ac_common.php:58
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
nbm($p_number, $p_dec=2)
format the number with a sep.
Definition: ac_common.php:137
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$anc pa_id
h( $row[ 'oa_description'])
$idx
catch(Exception $e) $exercice
$anc_grandlivre from_poste
$anc_grandlivre to
$anc_grandlivre to_poste
$anc_grandlivre from
$class
report he Grand Livre for analytic
button_export_csv($p_string="")
Show the button to export CSV.
set_sql_filter()
Set the filter (account_date)
button_export_pdf($p_string="")
Show the button to export in PDF all the receipt.
load()
load the data from the database
display_html($p_with_ck=1)
compute the html display
this class is the mother class for the CA printing
static history_account($p_account, $p_mesg, $p_style="", $p_exercice="")
display a div with the history of the account
static detail_op($p_jr_id, $p_mesg)
return a string containing the html code for calling the modifyOperation
static button($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
static show_receipt_document($p_jr_id, $p_name="")
Returns HTML code for displaying a icon with a link to a receipt document from the ledger.
static hidden($p_name, $p_value, $p_id="")
static history_card($f_id, $p_mesg, $p_style="", $p_exercice="")
display a div with the history of the card
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
Html Input.
static javascript_set_range($p_name)
Before calling this function , you must set a range with the function set_range.
static array_to_csv($array, $aheader, $p_filename)
with the handle of a successull query, echo each row into CSV and send it directly
For the periode tables parm_periode and jrn_periode.
$ix
Definition: dashboard.php:68
$SecUser db
$amount_cred
Definition: letter_all.php:6
$amount_deb
Definition: letter_all.php:6