noalyss Version-9
balance_age.class.php
Go to the documentation of this file.
1<?php
2
3/*
4 * Copyright (C) 2015 Dany De Bontridder <dany@alchimerys.be>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program 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 this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21/**
22 * @file
23 * @brief compute the ageing balance, currently this code is not used
24 *
25 */
26
27/**
28 * @class Balance_Age
29 * @brief compute the ageing balance, currently this code is not used
30 *
31 */
32
34{
35
36 private $cn;
37
38 function __construct($p_cn)
39 {
40 $this->cn=$p_cn;
41 $this->afiche=null;
42 }
43
44 function get_array_card($p_type, $p_extra="")
45 {
46 switch ($p_type)
47 {
48 case 'X':
49 $this->afiche=$this->cn->get_array("
50 with m as (select distinct qp_supplier as f_id from quant_purchase union select qs_client from quant_sold)
51 select distinct fiche.f_id as f_id ,f1.ad_value as name, f3.ad_value as first_name,f2.ad_value as quick_code
52 from fiche
53 join m on (fiche.f_id=m.f_id)
54 join fiche_detail as f1 on (fiche.f_id=f1.f_id and f1.ad_id=1)
55 join fiche_detail as f2 on (fiche.f_id=f2.f_id and f2.ad_id=23)
56 left join fiche_detail as f3 on (fiche.f_id=f3.f_id and f3.ad_id=32)
57 where
58 fiche.fd_id=$1
59 order by f1.ad_value
60 ", array($p_extra));
61 break;
62 case 'U':
63 $fiche=new Fiche($this->cn, $p_extra);
64 $this->afiche[0]['f_id']=$fiche->id;
65 $this->afiche[0]['quick_code']=$fiche->get_quick_code();
66 $this->afiche[0]['name']=$fiche->strAttribut(ATTR_DEF_NAME, 0);
67 $this->afiche[0]['first_name']=$fiche->strAttribut(ATTR_DEF_FIRST_NAME, 0);
68 break;
69 case 'F':
70 $this->afiche=$this->cn->get_array("
71 select distinct qp_supplier as f_id ,f1.ad_value as name, f3.ad_value as first_name,f2.ad_value as quick_code
72 from quant_purchase join
73 fiche_detail as f1 on (qp_supplier=f1.f_id and f1.ad_id=1)
74 join fiche_detail as f2 on (qp_supplier=f2.f_id and f2.ad_id=23)
75 left join fiche_detail as f3 on (qp_supplier=f3.f_id and f3.ad_id=32)
76 order by f1.ad_value
77 ");
78 break;
79 case 'C':
80 $this->afiche=$this->cn->get_array("
81 select distinct qs_client as f_id ,f1.ad_value as name, f3.ad_value as first_name,f2.ad_value as quick_code
82 from quant_sold join
83 fiche_detail as f1 on (qs_client=f1.f_id and f1.ad_id=1)
84 join fiche_detail as f2 on (qs_client=f2.f_id and f2.ad_id=23)
85 left join fiche_detail as f3 on (qs_client=f3.f_id and f3.ad_id=32)
86 order by f1.ad_value
87 ");
88 break;
89 default:
90 throw new Exception('Type invalide');
91 }
92 }
93
94 function display_card($p_date_start, $p_fiche, $p_let)
95 {
96 $this->get_array_card('U', $p_fiche);
97 $a_fiche=$this->afiche;
98 $nb_fiche=count($a_fiche);
99 require NOALYSS_TEMPLATE.'/balance_aged_result.php';
100 }
101
102 function display_category($p_date_start, $p_cat, $p_let)
103 {
104 // Get all fiche from Purchase
105
106 $this->get_array_card('X', $p_cat);
107 $a_fiche=$this->afiche;
108 $nb_fiche=count($a_fiche);
109 require NOALYSS_TEMPLATE.'/balance_aged_result.php';
110 }
111
112 /**
113 * Display all the operation for the customer
114 * @param type $p_date_start min date of the operatin
115 * @param type $p_let 'unlet' only unlettered or 'let' for all
116 */
117 function display_purchase($p_date_start, $p_let)
118 {
119 // Get all fiche from Purchase
120 $this->get_array_card('F');
121 $a_fiche=$this->afiche;
122 $nb_fiche=count($a_fiche);
123 require NOALYSS_TEMPLATE.'/balance_aged_result.php';
124 }
125
126 /**
127 * Display all the operation for the supplier
128 * @param type $p_date_start min date of the operatin
129 * @param type $p_let 'unlet' only unlettered or 'let' for all
130 */
131 function display_sale($p_date_start, $p_let)
132 {
133 // Get all fiche from Purchase
134 $this->get_array_card('C');
135 $a_fiche=$this->afiche;
136 $nb_fiche=count($a_fiche);
137 require NOALYSS_TEMPLATE.'/balance_aged_result.php';
138 }
139 /**
140 * Export Aged Balance to CSV
141 * @param $p_date_start date DD.MM.YYYY
142 * @param type $p_let unlet for unlettered operations
143 */
144 function export_csv($p_date_start, $p_let)
145 {
146 bcscale(2);
147 $export=new Noalyss_Csv('aged_balance');
148 $header = array(_('QuickCode') ,
149 _('Nom'),
150 _('Prénom'),
151 _('Date'),
152 _('N° pièce'),
153 _('Interne'),
154 _('Fin'),
155 _('<30 jours'),
156 _('entre 30 et 60 jours'),
157 _('entre 60 et 90 jours'),
158 _('> 90 jours') );
159 $export->send_header();
160 $export->write_header($header);
161
162
163 $nb_fiche=count($this->afiche);
164
165 for ($i=0; $i<$nb_fiche; $i++)
166 {
167 $card=new Lettering_Card($this->cn, $this->afiche[$i]['quick_code']);
168 $card->set_parameter('start', $p_date_start);
169 $card->get_balance_ageing($p_let);
170 if (empty($card->content))
171 continue;
172 $nb_row=count($card->content);
173 $sum_lt_30=0;
176 $sum_gt_90=0;
177 $sum_fin=0;
178 for ($j=0; $j<$nb_row; $j++)
179 {
180 $show=true;
181 $export->add($this->afiche[$i]['quick_code']);
182 $export->add($this->afiche[$i]['name']);
183 $export->add($this->afiche[$i]['first_name']);
184 $export->add($card->content[$j]['j_date_fmt']);
185 $export->add($card->content[$j]['jr_pj_number']);
186 $export->add($card->content[$j]['jr_internal']);
187 if ($card->content[$j]['jrn_def_type']=='FIN'||$card->content[$j]['jrn_def_type']=='ODS')
188 {
189 $export->add($card->content[$j]['j_montant'],"number");
190 $sum_fin=bcadd($sum_fin, $card->content[$j]['j_montant']);
191 $show=false;
192 }
193 else
194 {
195 $export->add(0,'number');
196 }
197 if ($show&&$card->content[$j]['day_paid']<=30)
198 {
199 $export->add($card->content[$j]['j_montant'],"number");
200 $sum_lt_30=bcadd($sum_lt_30, $card->content[$j]['j_montant']);
201 $show=false;
202 }
203 else
204 {
205 $export->add(0,'number');
206 }
207
208 if ($show&&$card->content[$j]['day_paid']>30&&$card->content[$j]['day_paid']<=60)
209 {
210 $export->add($card->content[$j]['j_montant'],"number");
211 $sum_gt_30_lt_60=bcadd($sum_gt_30_lt_60, $card->content[$j]['j_montant']);
212 }
213 else
214 {
215 $export->add(0,'number');
216 }
217
218 if ($show&&$card->content[$j]['day_paid']>60&&$card->content[$j]['day_paid']<=90)
219 {
220 $export->add($card->content[$j]['j_montant'],"number");
221 $sum_gt_60_lt_90=bcadd($sum_gt_60_lt_90, $card->content[$j]['j_montant']);
222 }
223 else
224 {
225 $export->add(0,'number');
226 }
227 if ($show&&$card->content[$j]['day_paid']>90)
228 {
229 $export->add($card->content[$j]['j_montant'],"number");
230 $sum_gt_90=bcadd($sum_gt_90, $card->content[$j]['j_montant']);
231 }
232 else
233 {
234 $export->add(0,'number');
235 }
236 $export->write();
237 }
238 $export->add(_('Totaux'));
239 $export->add("");
240 $export->add("");
241 $export->add("");
242 $export->add("");
243 $export->add("");
244 $export->add($sum_fin,"number");
245 $export->add($sum_lt_30,"number");
246 $export->add($sum_gt_30_lt_60,"number");
247 $export->add($sum_gt_60_lt_90,"number");
248 $export->add($sum_gt_90,"number");
249 $export->write();
250
251
252 }
253 }
254
255}
$input_from cn
Definition: balance.inc.php:66
$sum_gt_30_lt_60
for($j=0;$j< $nb_row;$j++)($j%2==0)? 'even' $show
$sum_gt_60_lt_90
compute the ageing balance, currently this code is not used
display_sale($p_date_start, $p_let)
Display all the operation for the supplier.
get_array_card($p_type, $p_extra="")
display_category($p_date_start, $p_cat, $p_let)
display_card($p_date_start, $p_fiche, $p_let)
export_csv($p_date_start, $p_let)
Export Aged Balance to CSV.
display_purchase($p_date_start, $p_let)
Display all the operation for the customer.
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: fiche.class.php:38
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_FIRST_NAME
Definition: constant.php:238
if(count($a_accounting)==0) $header
$afiche[0]
Definition: fiche.inc.php:482