compteae.php 11.3 KB
Newer Older
Ayolo's avatar
Ayolo committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/* Copyright 2006
 * - Julien Etelain < julien at pmad dot net >
 *
 * Ce fichier fait partie du site de l'Association des Étudiants de
 * l'UTBM, http://ae.utbm.fr.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */
$topdir="../";
require_once($topdir."include/site.inc.php");
require_once($topdir."include/cts/sqltable.inc.php");
require_once($topdir."comptoir/include/defines.inc.php");
$site = new site();

$site->allow_only_logged_users("matmatronch");

	
if ( isset($_REQUEST['id_utilisateur']) )
{
	$user = new utilisateur($site->db,$site->dbrw);
	$user->load_by_id($_REQUEST["id_utilisateur"]);	
	
	if ( !$user->is_valid() )
		$site->error_not_found("matmatronch");
		
	if ( !($user->id==$site->user->id || $site->user->is_in_group("gestion_ae")) )
		$site->error_forbidden("matmatronch","private");
}
else
	$user = &$site->user;

if ( ($_REQUEST["action"] == "delete") && $site->user->is_in_group("gestion_ae") && ( $site->user->is_in_group("root") || $site->user->id != $user->id ) )
{
	if ( isset($_REQUEST["id_facture"]))
	{
		require_once("../comptoir/include/facture.inc.php");
		$fact = new debitfacture ($site->db,$site->dbrw);
		$fact->load_by_id($_REQUEST["id_facture"]);
		if ( $fact->id > 0 )
			$fact->annule_facture();
	}
	else	if ( isset($_REQUEST["id_rechargement"]))
	{
		$user->annuler_credit($_REQUEST["id_rechargement"]);
	}
}

if ( $_REQUEST["page"] == "AE" || $_REQUEST["page"] == "SG" )
{
	$mode = $_REQUEST["page"];
	
	$req = new requete($site->db, "SELECT " .
			"`cpt_debitfacture`.`id_facture`, " .
			"`cpt_debitfacture`.`date_facture`, " .
			"`asso`.`id_asso`, " .
			"`asso`.`nom_asso`, " .
			"CONCAT(`utilisateurs`.`prenom_utl`,' ',`utilisateurs`.`nom_utl`) as `nom_utilisateur`, " .
			"`utilisateurs`.`id_utilisateur`, " .
			"`cpt_vendu`.`quantite`, " .
			"`cpt_vendu`.`prix_unit`/100 AS `prix_unit`, " .
			"`cpt_vendu`.`prix_unit`*`cpt_vendu`.`quantite`/100 AS `total`," .
			"`cpt_comptoir`.`id_comptoir`, " .
			"`cpt_comptoir`.`nom_cpt`," .
			"`cpt_produits`.`nom_prod` " .
			"FROM `cpt_vendu` " .
Feu's avatar
Feu committed
80
			"LEFT JOIN `asso` ON `asso`.`id_asso` =`cpt_vendu`.`id_assocpt` " .
Ayolo's avatar
Ayolo committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
			"INNER JOIN `cpt_produits` ON `cpt_produits`.`id_produit` =`cpt_vendu`.`id_produit` " .
			"INNER JOIN `cpt_debitfacture` ON `cpt_debitfacture`.`id_facture` =`cpt_vendu`.`id_facture` " .
			"INNER JOIN `utilisateurs` ON `cpt_debitfacture`.`id_utilisateur` =`utilisateurs`.`id_utilisateur` " .
			"INNER JOIN `cpt_comptoir` ON `cpt_debitfacture`.`id_comptoir` =`cpt_comptoir`.`id_comptoir` " .
			"WHERE `id_utilisateur_client`='".$user->id."' AND mode_paiement='$mode' " .
			"AND EXTRACT(YEAR_MONTH FROM `date_facture`)='".mysql_real_escape_string($_REQUEST["month"])."' " .
			"ORDER BY `cpt_debitfacture`.`date_facture` DESC");

	$mois = substr($_REQUEST["month"],4);
	$annee = substr($_REQUEST["month"],0,4);
		
	$site->start_page("matmatronch", $user->prenom . " " . $user->nom );
  $cts = new contents( $user->prenom . " " . $user->nom );
  $cts->add(new tabshead($user->get_tabs($site->user),"compte"));
	
	$cts->add(new sqltable(
		"listresp", 
		"Depenses", $req, "compteae.php?id_utilisateur=".$user->id, 
		"id_facture", 
		array(
			"id_facture"=>"Facture",
			"date_facture"=>"Date",
			"nom_prod"=>"Produit",
			"nom_cpt"=>"Lieu",
			"nom_utilisateur"=>"Vendeur",
			"nom_asso"=>"Association",
			"quantite"=>"Quantité",
			"prix_unit"=>"Prix unitaire",
			"total"=>"Total"), 
		($mode == "AE") && ($site->user->is_in_group("gestion_ae") &&
                                    ($site->user->is_in_group("root") || $site->user->id != $user->id)) ? array("delete"=>"Annuler la facture"):array(),
		array(),
		array( )
		));

	$site->add_contents($cts);
	$site->end_page();
	exit();
}
elseif ( $_REQUEST["page"] == "rech" )
{
	$mois = substr($_REQUEST["month"],4);
	$annee = substr($_REQUEST["month"],0,4);	
	
	$req = new requete($site->db, "SELECT " .
			"`cpt_rechargements`.`id_rechargement`, " .
			"`cpt_rechargements`.`date_rech`, " .
			"`cpt_rechargements`.`type_paiement_rech`, " .
			"`cpt_rechargements`.`montant_rech`/100 AS `montant_rech`, " .
			"`asso`.`id_asso`, " .
			"`asso`.`nom_asso`, " .
			"CONCAT(`utilisateurs`.`prenom_utl`,' ',`utilisateurs`.`nom_utl`) as `nom_utilisateur`, " .
			"`utilisateurs`.`id_utilisateur`, " .
			"`cpt_comptoir`.`id_comptoir`, " .
			"`cpt_comptoir`.`nom_cpt` " .
			"FROM `cpt_rechargements` " .
Feu's avatar
Feu committed
137
			"LEFT JOIN `asso` ON `asso`.`id_asso` =`cpt_rechargements`.`id_assocpt` " .
Ayolo's avatar
Ayolo committed
138
139
140
141
142
143
144
145
146
147
148
149
			"INNER JOIN `utilisateurs` ON `cpt_rechargements`.`id_utilisateur_operateur` =`utilisateurs`.`id_utilisateur` " .
			"INNER JOIN `cpt_comptoir` ON `cpt_rechargements`.`id_comptoir` =`cpt_comptoir`.`id_comptoir` " .
			"WHERE `cpt_rechargements`.`id_utilisateur`='".$user->id."' " .
			"AND EXTRACT(YEAR_MONTH FROM `date_rech`)='".mysql_real_escape_string($_REQUEST["month"])."' " .
			"ORDER BY `cpt_rechargements`.`date_rech` DESC");
				
	$site->start_page("matmatronch", $user->prenom . " " . $user->nom );
  $cts = new contents( $user->prenom . " " . $user->nom );
  $cts->add(new tabshead($user->get_tabs($site->user),"compte"));
	
	$cts->add(new sqltable(
		"listresp", 
Feu's avatar
wip    
Feu committed
150
		$user->type=="srv"?"Paiements":"Rechargements", $req, "compteae.php?id_utilisateur=".$user->id,
Ayolo's avatar
Ayolo committed
151
152
		"id_rechargement", 
		array(
Feu's avatar
wip    
Feu committed
153
			"id_rechargement"=>$user->type=="srv"?"Paiement":"Rechargement",
Ayolo's avatar
Ayolo committed
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
			"date_rech"=>"Date",
			"montant_rech"=>"Montant",
			"type_paiement_rech"=>"Type",
			"nom_cpt"=>"Lieu",
			"nom_utilisateur"=>"Opérateur",
			"nom_asso"=>"Association"), 
		($site->user->is_in_group("gestion_ae") && ( $site->user->is_in_group("root") || $site->user->id != $user->id ))?array("delete"=>"Annuler la facture"):array(), 
		array(),
		array("type_paiement_rech"=> $TypesPaiementsFull)
		));
	
	
	$site->add_contents($cts);		
	$site->end_page();
	exit();
	
}


$site->start_page("matmatronch", $user->prenom . " " . $user->nom );
$cts = new contents( $user->prenom . " " . $user->nom );
$cts->add(new tabshead($user->get_tabs($site->user),"compte"));

Feu's avatar
wip    
Feu committed
177
if ( $user->type!="srv" )
Ayolo's avatar
Ayolo committed
178
{
Feu's avatar
Feu committed
179
180
181
182
183
184
185
186
187
188
189
190
191
192
  $cts->puts("<a href=\"".$topdir."e-boutic/?cat=11\"><img src=\"".$topdir."images/comptoir/eboutic/pub-eb-rech.png\" border=\"0\" alt=\"Recharger par carte bleue\" class=\"imgright\" /></a>");
  
  $cts->add_title(2,"Carte AE");
  
  if ( !$user->ae )
  {
  	$cts->add_paragraph("Remarque: Cotisation AE non renouvelée, ce compte n'est plus utilisable.");
  	
  	if ( $user->montant_compte >= 500 )
  		$cts->add_paragraph("Vous pouvez demander le remboursement des ".($user->montant_compte/100)." Euros restant sur le compte.");
  	elseif ( $user->montant_compte > 0 )
  		$cts->add_paragraph("Le solde restant est insuffisant pour pouvoir obtenir un remboursement. Conformément au réglement intérieur de l'AE.");
  	
  }
Ayolo's avatar
Ayolo committed
193
}
Feu's avatar
Feu committed
194
195
else
  $cts->add_title(2,"Factures");
Ayolo's avatar
Ayolo committed
196
197


Feu's avatar
Feu committed
198
199
200
$cts->add_paragraph("Solde actuel : ".($user->montant_compte/100)." Euros");

$months = array();
Ayolo's avatar
Ayolo committed
201
202
203
204
205
206
207
208

$req = new requete($site->db, "SELECT SUM(`montant_facture`), " .
		"EXTRACT(YEAR_MONTH FROM `date_facture`) as `month` " .
		"FROM `cpt_debitfacture` " .
		"WHERE `id_utilisateur_client`='".$user->id."' AND mode_paiement='AE' " .
		"GROUP BY `month` " .
		"ORDER BY `month` DESC");
		
Feu's avatar
Feu committed
209
210
while ( list($sum,$month) = $req->get_row() )
{
Ayolo's avatar
Ayolo committed
211
	$report[$month]["depense"] = $sum;
Feu's avatar
fix    
Feu committed
212
	$months[$month]=$month;
Feu's avatar
Feu committed
213
}
Ayolo's avatar
Ayolo committed
214
215
216
217
218
219
220
221
$req = new requete($site->db, "SELECT SUM(`montant_rech`), " .
		"EXTRACT(YEAR_MONTH FROM `date_rech`) as `month` " .
		"FROM `cpt_rechargements` " .
		"WHERE `id_utilisateur`='".$user->id."' " .
		"GROUP BY `month` " .
		"ORDER BY `month` DESC");
		
while ( list($sum,$month) = $req->get_row() ) 
Feu's avatar
Feu committed
222
{
Ayolo's avatar
Ayolo committed
223
	$report[$month]["recharge"] = $sum;
Feu's avatar
fix    
Feu committed
224
	$months[$month]=$month;
Feu's avatar
Feu committed
225
}
Ayolo's avatar
Ayolo committed
226
227
228

if(!empty($report))
{
Feu's avatar
fixes    
Feu committed
229
  rsort($months);
Feu's avatar
Feu committed
230
231
232
  
  $cts->add_title(3,"Bilan mensuel");
  
Ayolo's avatar
Ayolo committed
233
  $tbl = new table(false,"sqltable");
Feu's avatar
wip    
Feu committed
234
  $tbl->add_row(array("Mois","Depenses",$user->type=="srv"?"Paiements":"Rechargements"),"head");
Ayolo's avatar
Ayolo committed
235
  $t=0;
Feu's avatar
Feu committed
236
  foreach( $months as $month )
Ayolo's avatar
Ayolo committed
237
  {
Feu's avatar
Feu committed
238
    $data = $report[$month];
Ayolo's avatar
Ayolo committed
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
	  $t = $t^1;
  	$mois = substr($month,4);
	  $annee = substr($month,0,4);	
  	$tbl->add_row(array("$mois / $annee",
		  "<a href=\"compteae.php?page=AE&amp;month=$month&amp;id_utilisateur=".$user->id."\">".($data["depense"]/100)."</a>",
	  	"<a href=\"compteae.php?page=rech&amp;month=$month&amp;id_utilisateur=".$user->id."\">".($data["recharge"]/100)."</a>"),"ln$t");	
  }
  
  $cts->add($tbl);  
}

$req1 = new requete($site->db,
        "SELECT " .
        "`cpt_debitfacture`.`id_facture`, " .
        "`cpt_debitfacture`.`date_facture`, " .
Feu's avatar
Feu committed
254
        "`cpt_vendu`.`prix_unit`*`cpt_vendu`.`quantite`/100 AS `total` " .
Ayolo's avatar
Ayolo committed
255
256
257
258
259
260
        "FROM `cpt_vendu` " .
        "INNER JOIN `cpt_produits` ON ".
        "`cpt_produits`.`id_produit` =`cpt_vendu`.`id_produit` " .
        "INNER JOIN `cpt_debitfacture` ON ".
        "`cpt_debitfacture`.`id_facture` =`cpt_vendu`.`id_facture` " .
        "WHERE mode_paiement = 'SG' " .
Feu's avatar
Feu committed
261
        "AND `cpt_debitfacture`.`id_comptoir` = '3' ".
Feu's avatar
Feu committed
262
        "AND `utilisateurs`.`id_utilisateur` = '".mysql_real_escape_string($user->id) ."' ".
Ayolo's avatar
Ayolo committed
263
264
265
266
267
268
269
        "GROUP BY `cpt_debitfacture`.`id_facture` ".
        "ORDER BY `cpt_debitfacture`.`date_facture` DESC");

$req2 = new requete($site->db,
        "SELECT " .
        "`cpt_debitfacture`.`id_facture`, " .
        "`cpt_debitfacture`.`date_facture`, " .
Feu's avatar
Feu committed
270
        "`cpt_vendu`.`prix_unit`*`cpt_vendu`.`quantite`/100 AS `total` " .
Ayolo's avatar
Ayolo committed
271
272
273
274
275
276
        "FROM `cpt_vendu` " .
        "INNER JOIN `cpt_produits` ON ".
        "`cpt_produits`.`id_produit` =`cpt_vendu`.`id_produit` " .
        "INNER JOIN `cpt_debitfacture` ON ".
        "`cpt_debitfacture`.`id_facture` =`cpt_vendu`.`id_facture` " .
        "WHERE mode_paiement = 'AE' " .
Feu's avatar
Feu committed
277
278
        "AND `cpt_debitfacture`.`id_comptoir` = '3' ".
        "AND `cpt_debitfacture`.`id_utilisateur_client` = '".mysql_real_escape_string($user->id) ."' ".
Ayolo's avatar
Ayolo committed
279
280
281
        "GROUP BY `cpt_debitfacture`.`id_facture` ".
        "ORDER BY `cpt_debitfacture`.`date_facture` DESC");

Feu's avatar
Feu committed
282
283
284
285
286
if ( $req1->lines > 0 )
{      
  $cts->add_title(3,"E-boutic : commandes payées par carte bleue");
  $cts->add(new sqltable("eblstcb",
         null,
Ayolo's avatar
Ayolo committed
287
288
289
         $req1,
         "moncompte.php",
         "id_facture",
Feu's avatar
Feu committed
290
291
292
          array("id_facture"=>"Numéro de facture",
          "total"=>"Montant",
                "date_facture"=>"Date"),
Ayolo's avatar
Ayolo committed
293
294
         array(),
         array(),
Feu's avatar
Feu committed
295
296
         array()));
}
Ayolo's avatar
Ayolo committed
297

Feu's avatar
Feu committed
298
299
300
301
302
303
304
305
306
307
308
if ( $req2->lines > 0 )
{
  $cts->add_title(3,$user->type == "srv"
                         ? "E-boutic : commandes sur facturation"
                         : "E-boutic : commandes payées par carte AE");
                         
  $cts->add(new sqltable("eblstae",
          null,
          $req2,
          "moncompte.php",
          "id_facture",
Feu's avatar
Feu committed
309
310
311
          array("id_facture"=>"Numéro de facture",
          "total"=>"Montant",
                "date_facture"=>"Date"),
Feu's avatar
Feu committed
312
313
314
315
          array(),
          array(),
          array()));
}
Ayolo's avatar
Ayolo committed
316
317
318



319
$site->add_contents($cts);
Ayolo's avatar
Ayolo committed
320
321
322

$site->end_page();
?>