ventes.php 14 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
<?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. "include/entities/asso.inc.php");

Feu's avatar
FIX    
Feu committed
28
29
30
31
32
33
require_once($topdir. "comptoir/include/typeproduit.inc.php");
require_once($topdir. "comptoir/include/produit.inc.php");
require_once($topdir. "comptoir/include/comptoir.inc.php");



Ayolo's avatar
Ayolo committed
34
35
36
37
38
39
40
41
$site = new site ();
$asso = new asso($site->db,$site->dbrw);

$site->allow_only_logged_users("presentation");

$asso->load_by_id($_REQUEST["id_asso"]);
if ( $asso->id < 1 )
{
42
  $site->error_not_found();
Ayolo's avatar
Ayolo committed
43
44
45
46
  exit();
}

if ( !$site->user->is_in_group("gestion_ae") && !$asso->is_member_role($site->user->id,ROLEASSO_MEMBREBUREAU) )
47
  $site->error_forbidden();
Ayolo's avatar
Ayolo committed
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
80
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

if (isset($_REQUEST['action']) && $_REQUEST['action']=="pdf")
{
  require_once ($topdir . "include/pdf/facture_pdf.inc.php");
  define('FPDF_FONTPATH', $topdir.'./font/');
  $pdf=new FPDF();
  $pdf->AliasNbPages();
  $pdf->SetAutoPageBreak(false);
  $pdf->AddPage();
  $pdf->SetFont('Arial','B',14);

  $pdf->Image($topdir."./images/Ae-blanc.jpg", 10, 10, 75);
  $pdf->SetFont('Times','BI',22);
  $pdf->Cell(0, 18, date("d/m/Y"),'','','R');
  $pdf->Ln();

  $pdf->SetFont('Arial','B',14);
  $pdf->Cell('', 20, "Liste",'','','C');
  $pdf->Ln();

  $pdf->SetFont('Arial','B',11);

  //Header
  $w=array(40,40,60,20,15,15);

  //Data
  $fill=0;
  $skip=57;
  $height=0;
  $page=1;
  $breakpage = false;

  $conds = array();
  foreach($_POST[conds] as $value)
  {
    $conds[] = $value;
  }

  $req_= new requete($site->db, "SELECT " .
                                "`cpt_debitfacture`.`id_facture`, " .
                                "`cpt_debitfacture`.`date_facture`, " .
                                "`asso`.`id_asso`, " .
                                "`asso`.`nom_asso`, " .
                                "`client`.`prenom_utl` as `nom_client`, " .
                                "`client`.`id_utilisateur` AS `id_utilisateur_client`, " .
                                "`client`.`nom_utl` as `prenom_client`, " .
                                "`vendeur`.`id_utilisateur` AS `id_utilisateur_vendeur`, " .
                                "`cpt_vendu`.`quantite`, " .
                                "`cpt_vendu`.`prix_unit`/100 AS `prix_unit`, " .
                                "`cpt_vendu`.`prix_unit`*`cpt_vendu`.`quantite`/100 AS `total`," .
                                "`cpt_produits`.`prix_achat_prod`*`cpt_vendu`.`quantite`/100 AS `total_coutant`," .
                                "`cpt_comptoir`.`id_comptoir`, " .
                                "`cpt_comptoir`.`nom_cpt`," .
                                "`cpt_produits`.`nom_prod`, " .
                                "`cpt_produits`.`id_produit`, " .
                                "`cpt_type_produit`.`id_typeprod`, " .
                                "`cpt_type_produit`.`nom_typeprod`, " .
                                "`cpt_produits`.`nom_prod` AS `produit`" .
                                "FROM `cpt_vendu` " .
                                "INNER JOIN `asso` ON `asso`.`id_asso` =`cpt_vendu`.`id_assocpt` " .
                                "INNER JOIN `cpt_produits` ON `cpt_produits`.`id_produit` =`cpt_vendu`.`id_produit` " .
                                "INNER JOIN `cpt_type_produit` ON `cpt_produits`.`id_typeprod` =`cpt_type_produit`.`id_typeprod` " .
                                "INNER JOIN `cpt_debitfacture` ON `cpt_debitfacture`.`id_facture` =`cpt_vendu`.`id_facture` " .
                                "INNER JOIN `utilisateurs` AS `vendeur` ON `cpt_debitfacture`.`id_utilisateur` =`vendeur`.`id_utilisateur` " .
                                "INNER JOIN `utilisateurs` AS `client` ON `cpt_debitfacture`.`id_utilisateur_client` =`client`.`id_utilisateur` " .
                                "INNER JOIN `cpt_comptoir` ON `cpt_debitfacture`.`id_comptoir` =`cpt_comptoir`.`id_comptoir` " .
                                "WHERE " .implode(" AND ",$conds).
115
                                "ORDER BY `client`.`nom_utl`, `client`.`prenom_utl`");
116

Ayolo's avatar
Ayolo committed
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
  while ($res = $req_->get_row())
  {
    if(($skip + $height) > 255)
    {
      $breakpage = true;
      $border = 'LRB';
    }
    else if($height == 0)
    {
      //Colors, line width and bold font
      $pdf->SetFillColor(0,0,0);
      $pdf->SetTextColor(255);
      $pdf->SetDrawColor(128,128,128);
      $pdf->SetLineWidth(.3);
      $pdf->SetFont('','B');

      $pdf->Cell($w[0],7,"Nom", 1, 0, 'C', 1);
      $pdf->Cell($w[1],7,"Prenom", 1, 0, 'C', 1);
      $pdf->Cell($w[2],7,"Produit", 1, 0, 'C', 1);
      $pdf->Cell($w[3],7,"Quantite", 1, 0, 'C', 1);
      $pdf->Cell($w[4],7,"Prix", 1, 0, 'C', 1);
      $pdf->Cell($w[5],7,"Total", 1, 0, 'C', 1);

      $pdf->Ln();

      //Color and font restoration
      $pdf->SetFillColor(200,200,200);
      $pdf->SetTextColor(0);
      $pdf->SetFont('');

      $height += 7;

      $border = 'LR';
    }
    else
    {
      $border = 'LR';

      $height += 6;
    }

    $pdf->Cell($w[0],6,utf8_decode($res['nom_client']),$border,0,'L',$fill);
    $pdf->Cell($w[1],6,utf8_decode($res['prenom_client']),$border,0,'L',$fill);
    $pdf->Cell($w[2],6,utf8_decode($res['produit']),$border,0,'L',$fill);
    $pdf->Cell($w[3],6,utf8_decode($res['quantite']),$border,0,'L',$fill);
    $pdf->Cell($w[4],6,utf8_decode($res['prix_unit']),$border,0,'L',$fill);
    $pdf->Cell($w[5],6,utf8_decode($res['total']),$border,0,'L',$fill);

    $pdf->Ln();

    if($breakpage == true)
    {
      $skip = 0;
      $height = 0;
      $pdf->Cell(0, 10, "Page " . $page ,0,0,'C');
      $pdf->AddPage();
      $page++;
      $breakpage = false;
    }

    $fill=!$fill;
  }

  $pdf->Cell(array_sum($w),0,'','T');
  $pdf->Output('liste_compta_'.date("d-m-Y").'.pdf',D);
}

$site->start_page("presentation",$asso->nom);

$cts = new contents($asso->get_html_path());
187

Ayolo's avatar
Ayolo committed
188
189
190
191
192
193
194
195
196
197
198
199
$cts->add(new tabshead($asso->get_tabs($site->user),"slds"));

$cts->add_title(1,"Ventes cartes AE + e-boutic");

$frm = new form ("cptacpt","ventes.php",true,"POST","Critères de selection");
$frm->add_hidden("action","view");
$frm->add_hidden("id_asso",$asso->id);
$frm->add_datetime_field("debut","Date et heure de début");
$frm->add_datetime_field("fin","Date et heure de fin");
$frm->add_entity_select("id_typeprod", "Type", $site->db, "typeproduit",$_REQUEST["id_typeprod"],true);
$frm->add_entity_select("id_comptoir","Lieu", $site->db, "comptoir",$_REQUEST["id_comptoir"],true);
$frm->add_entity_select("id_produit", "Produit", $site->db, "produit",$_REQUEST["id_produit"],true);
200
$frm->add_select_field("a_retirer_produit", "A retirer", array(null => "", 1 => "Non retiré", 0 => "Retiré"));
Ayolo's avatar
Ayolo committed
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
$frm->add_submit("valid","Voir");
$cts->add($frm,true);


$conds = array("cpt_vendu.id_assocpt='".$asso->id."'");
$comptoir = false;

if ( $_REQUEST["debut"] )
  $conds[] = "cpt_debitfacture.date_facture >= '".date("Y-m-d H:i:s",$_REQUEST["debut"])."'";

if ( $_REQUEST["fin"] )
  $conds[] = "cpt_debitfacture.date_facture <= '".date("Y-m-d H:i:s",$_REQUEST["fin"])."'";

if ( $_REQUEST["id_comptoir"] )
{
  $conds[] = "cpt_debitfacture.id_comptoir='".intval($_REQUEST["id_comptoir"])."'";
  $comptoir=true;
}
219

Ayolo's avatar
Ayolo committed
220
221
if ( $_REQUEST["id_typeprod"] )
  $conds[] = "cpt_produits.id_typeprod='".intval($_REQUEST["id_typeprod"])."'";
222

Ayolo's avatar
Ayolo committed
223
224
225
if ( $_REQUEST["id_produit"] )
  $conds[] = "cpt_vendu.id_produit='".intval($_REQUEST["id_produit"])."'";

226
227
228
if ( $_REQUEST["a_retirer_produit"] )
  $conds[] = "cpt_vendu.a_retirer_produit='".intval($_REQUEST["a_retirer_produit"])."'";

Ayolo's avatar
Ayolo committed
229
230
if ( count($conds) >= 1 )
{
231

Ayolo's avatar
Ayolo committed
232
  $req = new requete($site->db, "SELECT " .
233
                                "COUNT(`cpt_vendu`.`id_produit`), " .
Ayolo's avatar
Ayolo committed
234
235
236
237
238
239
240
241
                                "SUM(`cpt_vendu`.`quantite`), " .
                                "SUM(`cpt_vendu`.`prix_unit`*`cpt_vendu`.`quantite`) AS `total`," .
                                "SUM(`cpt_produits`.`prix_achat_prod`*`cpt_vendu`.`quantite`) AS `total_coutant`" .
                                "FROM `cpt_vendu` " .
                                "INNER JOIN `asso` ON `asso`.`id_asso` =`cpt_vendu`.`id_assocpt` " .
                                "INNER JOIN `cpt_produits` ON `cpt_produits`.`id_produit` =`cpt_vendu`.`id_produit` " .
                                "INNER JOIN `cpt_type_produit` ON `cpt_produits`.`id_typeprod` =`cpt_type_produit`.`id_typeprod` " .
                                "INNER JOIN `cpt_debitfacture` ON `cpt_debitfacture`.`id_facture` =`cpt_vendu`.`id_facture` " .
242
                                "INNER JOIN `utilisateurs` AS `vendeur` ON `cpt_debitfacture`.`id_utilisateur` =`vendeur`.`id_utilisateur` " .
Ayolo's avatar
Ayolo committed
243
244
245
                                "INNER JOIN `utilisateurs` AS `client` ON `cpt_debitfacture`.`id_utilisateur_client` =`client`.`id_utilisateur` " .
                                "INNER JOIN `cpt_comptoir` ON `cpt_debitfacture`.`id_comptoir` =`cpt_comptoir`.`id_comptoir` " .
                                "WHERE " .implode(" AND ",$conds).
246
247
                                "ORDER BY `cpt_debitfacture`.`date_facture` DESC");

Ayolo's avatar
Ayolo committed
248
  list($ln,$qte,$sum,$sumcoutant) = $req->get_row();
249
250


Ayolo's avatar
Ayolo committed
251
252
253
254
255
  $cts->add_title(2,"Sommes");
  $cts->add_paragraph("Quantitée : $qte unités<br/>" .
                      "Chiffre d'affaire: ".($sum/100)." Euros<br/>" .
                      "Prix countant total estimé* : ".($sumcoutant/100)." Euros");

Feu's avatar
fix    
Feu committed
256
  $frm = new form ("cptacptpdf","ventes.php?id_asso=".$asso->id,true,"POST","PDF");
Ayolo's avatar
Ayolo committed
257
  $frm->add_hidden("action","pdf");
258
  $i=0;
Ayolo's avatar
Ayolo committed
259
  foreach($conds as $value)
260
261
262
263
  {
    $frm->add_hidden("conds[".$i."]",$value);
    $i++;
  }
Ayolo's avatar
Ayolo committed
264
265
266
267
268
269
  $frm->add_submit("valid","Générer le PDF");
  $cts->add($frm,true);


  if ( $ln < 1000 )
  {
270

Ayolo's avatar
Ayolo committed
271
272
273
274
275
276
277
278
    $req = new requete($site->db, "SELECT " .
                                  "`cpt_debitfacture`.`id_facture`, " .
                                  "`cpt_debitfacture`.`date_facture`, " .
                                  "`asso`.`id_asso`, " .
                                  "`asso`.`nom_asso`, " .
                                  "CONCAT(`client`.`prenom_utl`,' ',`client`.`nom_utl`) as `nom_utilisateur_client`, " .
                                  "`client`.`id_utilisateur` AS `id_utilisateur_client`, " .
                                  "CONCAT(`vendeur`.`prenom_utl`,' ',`vendeur`.`nom_utl`) as `nom_utilisateur_vendeur`, " .
279
                                  "`vendeur`.`id_utilisateur` AS `id_utilisateur_vendeur`, " .
Ayolo's avatar
Ayolo committed
280
281
282
283
284
285
286
287
288
                                  "`cpt_vendu`.`quantite`, " .
                                  "`cpt_vendu`.`prix_unit`/100 AS `prix_unit`, " .
                                  "`cpt_vendu`.`prix_unit`*`cpt_vendu`.`quantite`/100 AS `total`," .
                                  "`cpt_produits`.`prix_achat_prod`*`cpt_vendu`.`quantite`/100 AS `total_coutant`," .
                                  "`cpt_comptoir`.`id_comptoir`, " .
                                  "`cpt_comptoir`.`nom_cpt`," .
                                  "`cpt_produits`.`nom_prod`, " .
                                  "`cpt_produits`.`id_produit`, " .
                                  "`cpt_type_produit`.`id_typeprod`, " .
289
                                  "`cpt_type_produit`.`nom_typeprod`" .
Ayolo's avatar
Ayolo committed
290
291
292
293
294
                                  "FROM `cpt_vendu` " .
                                  "INNER JOIN `asso` ON `asso`.`id_asso` =`cpt_vendu`.`id_assocpt` " .
                                  "INNER JOIN `cpt_produits` ON `cpt_produits`.`id_produit` =`cpt_vendu`.`id_produit` " .
                                  "INNER JOIN `cpt_type_produit` ON `cpt_produits`.`id_typeprod` =`cpt_type_produit`.`id_typeprod` " .
                                  "INNER JOIN `cpt_debitfacture` ON `cpt_debitfacture`.`id_facture` =`cpt_vendu`.`id_facture` " .
295
                                  "INNER JOIN `utilisateurs` AS `vendeur` ON `cpt_debitfacture`.`id_utilisateur` =`vendeur`.`id_utilisateur` " .
Ayolo's avatar
Ayolo committed
296
297
298
299
                                  "INNER JOIN `utilisateurs` AS `client` ON `cpt_debitfacture`.`id_utilisateur_client` =`client`.`id_utilisateur` " .
                                  "INNER JOIN `cpt_comptoir` ON `cpt_debitfacture`.`id_comptoir` =`cpt_comptoir`.`id_comptoir` " .
                                  "WHERE " .implode(" AND ",$conds).
                                  "ORDER BY `cpt_debitfacture`.`date_facture` DESC");
300
301
302
303
304


    $cts->add(new sqltable( "listresp",
                            "Listing", $req, "ventes.php",
                            "id_facture",
Ayolo's avatar
Ayolo committed
305
306
307
308
309
310
311
312
313
314
315
                            array( "id_facture"=>"Facture",
                                   "date_facture"=>"Date",
                                   "nom_typeprod"=>"Type",
                                   "nom_prod"=>"Produit",
                                   "nom_cpt"=>"Lieu",
                                   "nom_utilisateur_vendeur"=>"Vendeur",
                                   "nom_utilisateur_client"=>"Client",
                                   "nom_asso"=>"Asso.",
                                   "quantite"=>"Qte",
                                   "total"=>"Som.",
                                   "total_coutant"=>"Coutant*"),
316
                            array(),
Ayolo's avatar
Ayolo committed
317
318
319
320
321
322
323
324
325
                            array(),
                            array( )
                          ),true);
  }
  $cts->add_paragraph("* ATTENTION: Prix coutant basé sur le prix actuel.");
}


$site->add_contents($cts);
326

Ayolo's avatar
Ayolo committed
327
328
$site->end_page();
?>