· 8 years ago · Apr 21, 2018, 08:24 PM
1#####################################
2### CRÉATION DE LA BASE DE DONNÉE ###
3#####################################
4
5-- MySQL Workbench Forward Engineering
6
7SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
8SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
9SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
10
11-- -----------------------------------------------------
12-- Schema TP3
13-- -----------------------------------------------------
14CREATE SCHEMA IF NOT EXISTS `TP3` DEFAULT CHARACTER SET utf8 ;
15USE `TP3` ;
16
17-- -----------------------------------------------------
18-- Table `TP3`.`tblVille`
19-- -----------------------------------------------------
20CREATE TABLE IF NOT EXISTS `TP3`.`tblVille` (
21 `idVille` INT NOT NULL AUTO_INCREMENT,
22 `nomVille` VARCHAR(50) NOT NULL,
23 PRIMARY KEY (`idVille`),
24 INDEX `idx_nomVille` (`nomVille` ASC))
25ENGINE = InnoDB;
26
27-- -----------------------------------------------------
28-- Table `TP3`.`tblAbonne`
29-- -----------------------------------------------------
30CREATE TABLE IF NOT EXISTS `TP3`.`tblAbonne` (
31 `idAbonne` INT NOT NULL AUTO_INCREMENT,
32 `nomAbonne` VARCHAR(50) NOT NULL,
33 `prenomAbonne` VARCHAR(25) NULL DEFAULT NULL,
34 `codePostal` VARCHAR(7) NOT NULL,
35 `telephone` VARCHAR(15) NOT NULL,
36 `courriel` VARCHAR(50) NOT NULL,
37 `typeAbonne` CHAR(1) NOT NULL,
38 `idVille` INT NOT NULL,
39 PRIMARY KEY (`idAbonne`),
40 INDEX `idx_nomAbonne` (`nomAbonne` ASC),
41 INDEX `FK_tblAbonne_idVille` (`idVille` ASC),
42 CONSTRAINT `FK_tblAbonne_idVille`
43 FOREIGN KEY (`idVille`)
44 REFERENCES `TP3`.`tblVille` (`idVille`))
45ENGINE = InnoDB;
46
47-- -----------------------------------------------------
48-- Table `TP3`.`tblVehicule`
49-- -----------------------------------------------------
50CREATE TABLE IF NOT EXISTS `TP3`.`tblVehicule` (
51 `idVehicule` VARCHAR(7) NOT NULL,
52 `marque` VARCHAR(25) NOT NULL,
53 `modele` VARCHAR(25) NOT NULL,
54 `couleur` VARCHAR(15) NOT NULL,
55 PRIMARY KEY (`idVehicule`))
56ENGINE = InnoDB;
57
58-- -----------------------------------------------------
59-- Table `TP3`.`tblMethodPaiement`
60-- -----------------------------------------------------
61CREATE TABLE IF NOT EXISTS `TP3`.`tblMethodPaiement` (
62 `idPaiement` INT NOT NULL AUTO_INCREMENT,
63 `typePaiement` CHAR(1) NOT NULL,
64 `descPaiement` VARCHAR(25) NOT NULL,
65 PRIMARY KEY (`idPaiement`))
66ENGINE = InnoDB;
67
68-- -----------------------------------------------------
69-- Table `TP3`.`tblOccasionnel`
70-- -----------------------------------------------------
71CREATE TABLE IF NOT EXISTS `TP3`.`tblOccasionnel` (
72 `idOccas` VARCHAR(12) NOT NULL,
73 `dateDebutOccas` DATETIME NOT NULL,
74 `dateFinOccas` DATETIME NULL,
75 `idTransaction` INT NULL,
76 PRIMARY KEY (`idOccas`),
77 INDEX `FK_tblOccasionnel_idTransaction` (`idTransaction` ASC),
78 CONSTRAINT `FK_tblOccasionnel_idTransaction`
79 FOREIGN KEY (`idTransaction`)
80 REFERENCES `TP3`.`tblTransaction` (`idTransaction`))
81ENGINE = InnoDB;
82
83-- -----------------------------------------------------
84-- Table `TP3`.`tblTransaction`
85-- -----------------------------------------------------
86CREATE TABLE IF NOT EXISTS `TP3`.`tblTransaction` (
87 `idTransaction` INT NOT NULL AUTO_INCREMENT,
88 `montant` DECIMAL(6,2) NULL,
89 `numPaiement` VARCHAR(16) NULL,
90 `idPaiement` INT NULL,
91 `idAbonnement` INT NULL,
92 `idOccas` VARCHAR(12) NULL,
93 PRIMARY KEY (`idTransaction`),
94 INDEX `FK_tblTransaction_idPaiement` (`idPaiement` ASC),
95 INDEX `FK_tblTransaction_idAbonnement` (`idAbonnement` ASC),
96 INDEX `FK_tblTransaction_idOccas` (`idOccas` ASC),
97 CONSTRAINT `FK_tblTransaction_idPaiement`
98 FOREIGN KEY (`idPaiement`)
99 REFERENCES `TP3`.`tblMethodPaiement` (`idPaiement`),
100 CONSTRAINT `FK_tblTransaction_idAbonne`
101 FOREIGN KEY (`idAbonnement`)
102 REFERENCES `TP3`.`tblAbonnement` (`idAbonnement`),
103 CONSTRAINT `FK_tblTransaction_idOccas`
104 FOREIGN KEY (`idOccas`)
105 REFERENCES `TP3`.`tblOccasionnel` (`idOccas`))
106ENGINE = InnoDB;
107
108-- -----------------------------------------------------
109-- Table `TP3`.`tblAbonnement`
110-- -----------------------------------------------------
111CREATE TABLE IF NOT EXISTS `TP3`.`tblAbonnement` (
112 `idAbonnement` INT NOT NULL AUTO_INCREMENT,
113 `dateDebutAbonne` DATE NOT NULL,
114 `dateFinAbonne` DATE NOT NULL,
115 `idAbonne` INT NOT NULL,
116 `idVehicule` VARCHAR(7) NOT NULL,
117 `idPlace` SMALLINT NOT NULL,
118 `idTransaction` INT NOT NULL,
119 PRIMARY KEY (`idAbonnement`),
120 INDEX `FK_tblAbonnement_idAbonne_tblAbonne` (`idAbonne` ASC),
121 INDEX `FK_tblAbonnement_idVehicule` (`idVehicule` ASC),
122 INDEX `FK_tblAbonnement_idPlace` (`idPlace` ASC),
123 INDEX `FK_tblAbonnement_idTransaction` (`idTransaction` ASC),
124 CONSTRAINT `FK_tblAbonnement_idAbonne_tblAbonne`
125 FOREIGN KEY (`idAbonne`)
126 REFERENCES `TP3`.`tblAbonne` (`idAbonne`),
127 CONSTRAINT `FK_tblAbonnement_idVehicule`
128 FOREIGN KEY (`idVehicule`)
129 REFERENCES `TP3`.`tblVehicule` (`idVehicule`),
130 CONSTRAINT `FK_tblAbonnement_idPlace`
131 FOREIGN KEY (`idPlace`)
132 REFERENCES `TP3`.`tblPlace` (`idPlace`),
133 CONSTRAINT `FK_tblAbonnement_idTransaction`
134 FOREIGN KEY (`idTransaction`)
135 REFERENCES `TP3`.`tblTransaction` (`idTransaction`))
136ENGINE = InnoDB;
137
138-- -----------------------------------------------------
139-- Table `TP3`.`tblPlace`
140-- -----------------------------------------------------
141CREATE TABLE IF NOT EXISTS `TP3`.`tblPlace` (
142 `idPlace` SMALLINT NOT NULL AUTO_INCREMENT,
143 `typePlace` VARCHAR(25) NOT NULL,
144 `idAbonne` INT NULL,
145 PRIMARY KEY (`idPlace`),
146 INDEX `FK_tblPlace_idAbonne` (`idAbonne` ASC),
147 CONSTRAINT `FK_tblPlace_idAbonne`
148 FOREIGN KEY (`idAbonne`)
149 REFERENCES `TP3`.`tblAbonnement` (`idAbonnement`))
150ENGINE = InnoDB;
151
152SET SQL_MODE=@OLD_SQL_MODE;
153SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
154SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
155
156###############################
157### FONCTIONS ET PROCÉDURES ###
158###############################
159
160-- -----------------------------------------------------
161-- Fonctions -------------------------------------------
162-- -----------------------------------------------------
163
164-- -------------------------------------------------------------------------------------------
165-- Fonction FnNbPlaceAbonne() qui retourne le nombre de place utilisé par un abonnement valide
166-- -------------------------------------------------------------------------------------------
167DELIMITER $$
168CREATE FUNCTION FnNbPlaceAbonne()
169RETURNS int
170BEGIN
171 DECLARE v_nb int;
172 SELECT count(*) as v_nb
173 FROM tblAbonnement as abon
174 WHERE abon.dateFinAbonne > now()
175 into v_nb;
176RETURN v_nb;
177END $$
178DELIMITER ;
179
180-- -----------------------------------------------------------------------------------------
181-- Fonction FnNbPlaceOccas() qui retourne le nombre de place utilisé par un occasionel actif
182-- -----------------------------------------------------------------------------------------
183DELIMITER $$
184CREATE FUNCTION FnNbPlaceOccas()
185RETURNS int
186BEGIN
187 DECLARE v_nb int;
188 SELECT count(*) as v_nv
189 FROM tblOccasionnel as ocas
190 WHERE ocas.dateFinOccas is null
191 into v_nb;
192RETURN v_nb;
193END $$
194DELIMITER ;
195
196-- -------------------------------------------------------------
197-- Fonction pour calculer le montant à payer pour un occasionnel
198-- -------------------------------------------------------------
199DELIMITER $$
200CREATE FUNCTION FnCalculerMontant(p_idOccas varchar(12))
201RETURNS DECIMAL(6, 2)
202BEGIN
203 DECLARE v_tHeure int DEFAULT 5;
204 DECLARE v_tJour int DEFAULT 20;
205 DECLARE v_mJour DECIMAL(6, 2);
206 DECLARE v_mHeure DECIMAL(6, 2);
207 DECLARE v_dateDebut DATETIME;
208 DECLARE v_dTemps TIME;
209 DECLARE v_nbJour INT;
210
211 SELECT dateDebutOccas INTO v_dateDebut FROM tblOccasionnel
212 WHERE idOccas = p_idOccas;
213 SET v_dTemps = TIMEDIFF(CURRENT_TIME(), TIME(v_dateDebut));
214
215 IF (TIME(v_dateDebut) > CURRENT_TIME()) THEN
216 SET v_dTemps = TIMEDIFF('23:59:59', v_dTemps);
217 END IF;
218
219 SET v_nbJour = DATEDIFF(NOW(), v_dateDebut);
220 SET v_mJour = v_nbJour * v_tJour;
221 SET v_mHeure = CEIL(time_to_sec(v_dtemps) / (60 * 60)) * v_tHeure;
222
223 IF (v_mHeure > v_tJour)
224 THEN SET v_mHeure = v_tJour;
225 END IF;
226 RETURN (v_mJour + v_mHeure);
227END $$
228DELIMITER ;
229
230-- ---------------------------------------------------------------------------------------
231-- Fonction FnCreditAbonne() qui retourne le nombre de paiement Abonnement fait par crédit
232-- ---------------------------------------------------------------------------------------
233DELIMITER $$
234CREATE FUNCTION FnCreditAbonne(p_dateTrans DATE)
235RETURNS DECIMAL(9,2)
236BEGIN
237 DECLARE v_Montant DECIMAL(9,2) default 0;
238 SELECT SUM(trans.montant)
239 FROM tblTransaction as trans
240 INNER JOIN tblMethodPaiement as methode
241 ON trans.idPaiement = methode.idPaiement
242 INNER JOIN tblAbonnement as abon
243 ON trans.idAbonnement = abon.idAbonnement
244 WHERE methode.typePaiement in ('V','M','X') AND idOccas is null AND abon.dateDebutAbonne = p_dateTrans
245 INTO v_Montant;
246 if (v_Montant is null) then
247 set v_Montant = 0;
248 end if;
249RETURN v_Montant;
250END $$
251DELIMITER ;
252
253-- ---------------------------------------------------------------------------------------
254-- Fonction FnComptantAbonne() qui retourne le nombre de paiement Abonnement fait comptant
255-- ---------------------------------------------------------------------------------------
256DELIMITER $$
257CREATE FUNCTION FnComptantAbonne(p_dateTrans DATE)
258RETURNS DECIMAL(9,2)
259BEGIN
260 DECLARE v_Montant DECIMAL(9,2);
261 SELECT SUM(trans.montant)
262 FROM tblTransaction as trans
263 INNER JOIN tblMethodPaiement as methode
264 ON trans.idPaiement = methode.idPaiement
265 INNER JOIN tblAbonnement as abon
266 ON trans.idAbonnement = abon.idAbonnement
267 WHERE methode.typePaiement in ('A','C') AND idOccas is null AND abon.dateDebutAbonne = p_dateTrans
268 INTO v_Montant;
269 if (v_Montant is null) then
270 set v_Montant = 0;
271 end if;
272RETURN v_Montant;
273END $$
274DELIMITER ;
275
276 -- ---------------------------------------------------------------------------------------
277-- Fonction FnCreditOcca() qui retourne le nombre de paiement Occasionnel fait par crédit
278-- ---------------------------------------------------------------------------------------
279DELIMITER $$
280CREATE FUNCTION FnCreditOcca(p_dateTrans DATE)
281RETURNS DECIMAL(9,2)
282BEGIN
283 DECLARE v_Montant DECIMAL(9,2);
284 SELECT SUM(trans.montant)
285 FROM tblTransaction as trans
286 INNER JOIN tblMethodPaiement as methode
287 ON trans.idPaiement = methode.idPaiement
288 INNER JOIN tblOccasionnel as occa
289 ON trans.idOccas = occa.idOccas
290 WHERE methode.typePaiement in ('V','M','X') AND idAbonnement is null AND cast(occa.dateFinOccas as date) = p_dateTrans
291 INTO v_Montant;
292 if (v_Montant is null) then
293 set v_Montant = 0;
294 end if;
295RETURN v_Montant;
296END $$
297DELIMITER ;
298
299-- ---------------------------------------------------------------------------------------
300-- Fonction FnComptantOcca() qui retourne le nombre de paiement Occasionnel fait comptant
301-- ---------------------------------------------------------------------------------------
302DELIMITER $$
303CREATE FUNCTION FnComptantOcca(p_dateTrans DATE)
304RETURNS DECIMAL(9,2)
305BEGIN
306 DECLARE v_Montant DECIMAL(9,2);
307 SELECT SUM(trans.montant)
308 FROM tblTransaction as trans
309 INNER JOIN tblMethodPaiement as methode
310 ON trans.idPaiement = methode.idPaiement
311 INNER JOIN tblOccasionnel as occa
312 ON trans.idOccas = occa.idOccas
313 WHERE methode.typePaiement in ('A','C') AND idAbonnement is null AND cast(occa.dateFinOccas as DATE) = p_dateTrans
314 INTO v_Montant;
315 if (v_Montant is null) then
316 set v_Montant = 0;
317 end if;
318RETURN v_Montant;
319END $$
320DELIMITER ;
321
322-- ------------------------------------------------------------
323-- Fonction pour générer des plaques de voiture
324-- ------------------------------------------------------------
325DELIMITER $$
326CREATE FUNCTION FnRandomPlaque()
327 RETURNS VARCHAR(6)
328BEGIN
329 DECLARE plaque VARCHAR(6) DEFAULT "";
330 SELECT concat(substring('ABCDEFGHIJKLMNOPQRSTUVWXYZ', rand()*25+1, 1),
331 substring('ABCDEFGHIJKLMNOPQRSTUVWXYZ', rand()*25+1, 1),
332 substring('ABCDEFGHIJKLMNOPQRSTUVWXYZ', rand()*25+1, 1),
333 substring('0123456789', rand()*9+1, 1),
334 substring('0123456789', rand()*9+1, 1),
335 substring('0123456789', rand()*9+1, 1))
336 into @idVehicule;
337
338 SET @rcount = -1;
339 SELECT COUNT(*) INTO @rcount FROM `tblVehicule` WHERE `idVehicule` = @idVehicule ;
340
341 IF @rcount = 0 THEN
342 SET plaque = @idVehicule ;
343 END IF ;
344
345 RETURN plaque ;
346END$$
347DELIMITER ;
348
349-- ------------------------------------------------------------
350-- Fonction pour retourner le NOMBRE ABONNEMENTS PERSONNE/SOCIETE
351-- ------------------------------------------------------------
352DELIMITER $$
353CREATE FUNCTION FnNbAbon(p_DateDebut Date, p_DateFin Date, p_TypeAbonne char)
354 RETURNS int
355BEGIN
356 DECLARE v_nb int;
357SELECT count(*) FROM tblTransaction as trans
358 INNER JOIN tblAbonnement as abonnem
359 ON trans.idTransaction = abonnem.idTransaction
360 INNER JOIN tblAbonne as abon
361 ON abonnem.idAbonne = abon.idAbonne
362 WHERE abon.typeAbonne = p_TypeAbonne AND abonnem.dateDebutAbonne <= p_DateFin AND abonnem.dateDebutAbonne > p_DateDebut
363 INTO v_nb;
364
365 IF (v_nb is null) THEN
366 SET v_nb = 0;
367 END IF ;
368
369 RETURN v_nb ;
370END$$
371DELIMITER ;
372
373 -- ------------------------------------------------------------
374-- Fonction pour connaitre SOMME ABONNEMENTS PERSONNE/SOCIETE
375-- ------------------------------------------------------------
376DELIMITER $$
377CREATE FUNCTION FnSommeAbon(p_DateDebut Date, p_DateFin Date, p_TypeAbonne char)
378 RETURNS int
379BEGIN
380 DECLARE v_somme int;
381SELECT sum(trans.montant) FROM tblTransaction as trans
382 INNER JOIN tblAbonnement as abonnem
383 ON trans.idTransaction = abonnem.idTransaction
384 INNER JOIN tblAbonne as abon
385 ON abonnem.idAbonne = abon.idAbonne
386 WHERE abon.typeAbonne = p_TypeAbonne AND abonnem.dateDebutAbonne <= p_DateFin AND abonnem.dateDebutAbonne > p_DateDebut
387 INTO v_somme;
388
389 IF (v_somme is null) THEN
390 SET v_somme = 0;
391 END IF ;
392
393 RETURN v_somme ;
394END$$
395DELIMITER ;
396
397-- --------------------------------------------
398-- Fonction pour connaitre NOMBRE OCCASIONNEL
399-- --------------------------------------------
400DELIMITER $$
401CREATE FUNCTION FnNbOcca(p_DateDebut Date, p_DateFin Date)
402 RETURNS int
403BEGIN
404 DECLARE v_nb int;
405SELECT count(*) FROM tblTransaction as trans
406 INNER JOIN tblAbonnement as abonnem
407 ON trans.idTransaction = abonnem.idTransaction
408 INNER JOIN tblOccasionnel as occa
409 ON trans.idOccas = occa.idOccas
410 WHERE occa.dateFinOccas >= p_DateFin AND occa.dateFinOccas < p_DateDebut
411 INTO v_nb;
412
413 IF (v_nb is null) THEN
414 SET v_nb = 0;
415 END IF ;
416
417 RETURN v_nb ;
418END$$
419DELIMITER ;
420
421-- --------------------------------------------
422-- Fonction pour connaitre SOMME OCCASIONNEL
423-- --------------------------------------------
424DELIMITER $$
425CREATE FUNCTION FnSommeOcca(p_DateDebut Date, p_DateFin Date)
426 RETURNS int
427BEGIN
428 DECLARE v_nb int;
429SELECT sum(trans.montant) FROM tblTransaction as trans
430 INNER JOIN tblAbonnement as abonnem
431 ON trans.idTransaction = abonnem.idTransaction
432 INNER JOIN tblOccasionnel as occa
433 ON trans.idOccas = occa.idOccas
434 WHERE trans.idAbonnement is null AND occa.dateFinOccas <= p_DateFin AND occa.dateFinOccas > p_DateDebut
435 INTO v_nb;
436
437 IF (v_nb is null) THEN
438 SET v_nb = 0;
439 END IF ;
440
441 RETURN v_nb ;
442END$$
443DELIMITER ;
444
445-- -----------------------------------------------------
446-- Procédures ------------------------------------------
447-- -----------------------------------------------------
448
449-- ------------------------------------------------------------------------------
450-- Procédure pour la création des places dans tblPlace selon le nombre et le type
451-- ------------------------------------------------------------------------------
452DELIMITER $$
453CREATE PROCEDURE `InsertPlaces`(in p_nb int, in p_type varchar(25))
454BEGIN
455 DECLARE v_i int DEFAULT 1;
456
457 WHILE v_i <= p_nb DO
458 INSERT INTO tblPlace (typePlace,idAbonne) VALUES(p_type, null);
459 SET v_i = v_i + 1;
460 END WHILE;
461END $$
462DELIMITER ;
463
464-- -------------------------------------------------------------------------
465-- Procédure CompterPlaceDispo(), va retourner le nombre de place disponible
466-- en tenant compte des places utilisés par les abonnés et occasionnels
467-- -------------------------------------------------------------------------
468DELIMITER $$
469CREATE PROCEDURE `CompterPlaceDispo`()
470BEGIN
471 DECLARE v_nbOccas int;
472 DECLARE v_nbAbon int;
473 DECLARE v_nbTotal int;
474
475 SET v_nbOccas = FnNbPlaceOccas();
476 SET v_nbAbon = FnNbPlaceAbonne();
477 SET v_nbTotal = 2500 - v_nbOccas -v_nbAbon;
478 SELECT v_nbTotal as 'Stationnement disponible';
479END$$
480DELIMITER ;
481
482#call CompterPlaceDispo();
483
484-- -----------------------------------------------------------------------------------
485-- Procédure SommesPercuesParType(), va calculer les montants percus par type d'usager
486-- en se basant sur des dates fournis
487-- -----------------------------------------------------------------------------------
488DELIMITER $$
489CREATE PROCEDURE `SommesPercuesParType`(IN p_dateDebut Date, IN p_dateFin Date)
490BEGIN
491 DECLARE v_type varchar(8);
492 DECLARE v_nbAbon int;
493 DECLARE v_nbOccas int;
494 DECLARE v_somme decimal(9,2);
495 DECLARE v_total int;
496
497 SELECT * FROM tblAbonne as ab
498 INNER JOIN tblAbonnement as abt
499 ON ab.idAbonne = abt.idAbonne
500 WHERE abt.dateDebutAbonne >= p_dateDebut and abt.dateFinAbonne <= p_dateFin;
501END$$
502DELIMITER ;
503
504#call SommesPercuesParType('2018-01-01', curdate());
505
506-- -----------------------------------------------------
507-- Procédure AjoutAbonne(), va faire l'ajout d'un abonné
508-- -----------------------------------------------------
509drop procedure if exists AjoutAbonne;
510
511DELIMITER $$
512CREATE PROCEDURE `AjoutAbonne`(in p_nomAbonne varchar(50), in p_prenomAbonne varchar(25), in p_codePostal varchar(7),
513 in p_telephone varchar(15), in p_courriel varchar(50), in p_typeAbonne char(1), in p_idVille int)
514BEGIN
515 SET @abCount = -1;
516 SELECT COUNT(*) INTO @abCount FROM `tblAbonne` WHERE `nomAbonne` = p_nomAbonne and `prenomAbonne` = p_prenomAbonne
517 or `nomAbonne` = p_nomAbonne and `prenomAbonne` is null;
518 SELECT COUNT(*) INTO @abCount FROM tblAbonne as abon WHERE abon.nomAbonne = p_nomAbonne and abon.prenomAbonne = p_prenomAbonne and abon.telephone = p_telephone
519 or abon.nomAbonne = p_nomAbonne and abon.prenomAbonne is null and abon.telephone = p_telephone;
520 IF @abCount = 0 THEN
521 INSERT INTO tblAbonne (nomAbonne,prenomAbonne,codePostal,telephone,courriel,typeAbonne,idVille)
522 VALUES(p_nomAbonne,p_prenomAbonne,p_codePostal,p_telephone,p_courriel,p_typeAbonne,p_idVille);
523 ELSE
524 SELECT 'Abonné déjà existant';
525 END IF ;
526END$$
527DELIMITER ;
528
529use TP3;
530
531#select * from tblAbonne order by nomAbonne desc;
532#call AjoutAbonne('Leblanc', 'Robby', 'Q4A2O7', '1-195-388-6491', 'nec@Nulla.co.uk', 'S', 3);
533
534-- -----------------------------------------------------------------------------------------------------------------------
535-- Procédure AjoutTransactionAbonne(), va ajouter la transaction pour l'action d'abonnement et retourner l'id de celle-ci
536-- -----------------------------------------------------------------------------------------------------------------------
537DELIMITER $$
538CREATE PROCEDURE `AjoutTransactionAbonne`(in p_duree int, in p_numPaiement varchar(16), in p_idPaiement int, out LIDTRANSACABON int)
539BEGIN
540 DECLARE v_tMois int DEFAULT 240;
541 DECLARE v_tAn int DEFAULT 2500;
542 DECLARE v_mTotal int;
543 DECLARE v_montant decimal(6,2);
544 IF (p_duree > 11) THEN
545 SET v_mTotal = CEIL(p_duree / 12) * v_tAn;
546 ELSE
547 SET v_mTotal = p_duree * v_tMois;
548 END IF;
549
550 SET v_montant = v_mTotal;
551
552 INSERT INTO tblTransaction (montant,numPaiement,idPaiement,idAbonnement,idOccas)
553 VALUES(v_montant,p_numPaiement,p_idPaiement,null,null);
554
555 SET LIDTRANSACABON = LAST_INSERT_ID();
556END$$
557DELIMITER ;
558
559-- --------------------------------------------------
560-- Procédure AjoutAbonnement(), va créer l'abonnement
561-- --------------------------------------------------
562DELIMITER $$
563CREATE PROCEDURE `AjoutAbonnement`(in p_dateDebut Date, in p_duree int, in p_idAbonne int, in p_idPaiement int, in p_numPaiement varchar(16)
564 , in p_idVehicule varchar(7), in p_idPlace smallint)
565BEGIN
566 DECLARE v_idTransac int;
567 DECLARE v_dateFin date;
568
569 SET @abtCount = -1;
570 SELECT COUNT(*) INTO @abtCount FROM tblAbonnement where idVehicule = p_idVehicule and dateFinAbonne >= p_dateDebut
571 or idPlace = p_idPlace and dateFinAbonne >= p_dateDebut;
572
573 IF (@abtCount = 0) THEN
574 SET v_dateFin = DATE_ADD(p_dateDebut, INTERVAL p_duree MONTH);
575 -- Appele la procedure pour générer la transaction de l'abonnement
576 call AjoutTransactionAbonne(p_duree, p_numPaiement, p_idPaiement, @LIDTRANSACABON);
577
578 INSERT INTO tblAbonnement (dateDebutAbonne,dateFinAbonne,idAbonne,idVehicule,idPlace,idTransaction)
579 VALUES(p_dateDebut,v_dateFin,p_idAbonne,p_idVehicule,p_idPlace,@LIDTRANSACABON);
580
581 UPDATE tblTransaction set idAbonnement = LAST_INSERT_ID() where idTransaction = @LIDTRANSACABON;
582 ELSE
583 SELECT 'Un abonnement avec la même plaque ou place est toujours actif!';
584 END IF;
585END$$
586DELIMITER ;
587
588#select 'ALLO';
589#SELECT COUNT(*) INTO @abtCount FROM tblAbonnement where idVehicule = 'XJA029' and dateFinAbonne >= '2018-10-20' or idPlace = 526 and dateFinAbonne >= '2018-10-20';
590#SELECT * FROM tblAbonnement where idVehicule = 'XJA028' and dateFinAbonne >= '2018-10-20';
591#SELECT @abtCount;
592#SELECT * from tblAbonnement where idVehicule = 'XJA028';
593#call AjoutAbonnement(curdate(), 10, 1, 4, null, 'XJA028', 414);
594#update tblAbonnement set dateFinAbonne = curdate()-1 where idAbonnement = 15;
595#SELECT * from tblAbonnement where idPlace = 1996;
596
597-- ----------------------------------------------------------------------------------------
598-- Procédure AjoutTransactionOcaas(), va ajouter la transaction pour l'action d'occasionnel
599-- ----------------------------------------------------------------------------------------
600DELIMITER $$
601CREATE PROCEDURE `AjoutTransactionOccas`(in p_idOccas varchar(12), in p_idPaiement int, in p_numPaiement varchar(16), out LIDTRANSACOCCAS int)
602BEGIN
603 DECLARE v_montantOccas decimal(6,2);
604 DECLARE v_dateDebut datetime;
605
606 SELECT dateDebutOccas FROM tblOccasionnel AS occas
607 INNER JOIN tblTransaction as trans
608 ON occas.idOccas = trans.idOccas
609 WHERE occas.idOccas = p_idOccas
610 INTO @v_dateDebut;
611
612 #SET v_montantOccas = FnCalculeMontant(@v_dateDebut, now());
613 SET v_montantOccas = FnCalculerMontant(p_idOccas);
614
615 INSERT INTO tblTransaction (montant,numPaiement,idPaiement,idAbonnement,idOccas)
616 VALUES(v_montantOccas,p_numPaiement,p_idPaiement,null,p_idOccas);
617
618 SET LIDTRANSACOCCAS = LAST_INSERT_ID();
619END$$
620DELIMITER ;
621
622-- ---------------------------------------------------------------
623-- Procédure AjoutOccasionnel(), va créer l'ajout d'un occasionnel
624-- ---------------------------------------------------------------
625DELIMITER $$
626CREATE PROCEDURE `AjoutOccasionnel`()
627BEGIN
628
629 DECLARE v_nbIdTotal int DEFAULT 0;
630 DECLARE v_nbIdAvant int DEFAULT 0;
631 DECLARE v_idOccas varchar(12);
632
633 SELECT count(*) into v_nbIdTotal
634 FROM tblOccasionnel;
635 SELECT count(*) into v_nbIdAvant
636 FROM tblOccasionnel WHERE TIMESTAMPDIFF(DAY, dateDebutOccas, now() != 0);
637
638 SET v_idOccas = concat(DATE_FORMAT(curdate(), '%Y%m%d'), v_nbIdTotal - v_nbIdAvant + 1);
639
640 INSERT INTO tblOccasionnel VALUES(v_idOccas,now(),null,null);
641
642END$$
643DELIMITER ;
644
645-- --------------------------------------------------------------------------------------
646-- Procédure SortieOccasionnel(), va mettre à jour l'occasionel lorsque la voiture quitte
647-- --------------------------------------------------------------------------------------
648drop procedure if exists SortieOccasionnel;
649
650DELIMITER $$
651CREATE PROCEDURE `SortieOccasionnel`(in p_idOccas varchar(12), in p_idPaiement int, in p_numPaiement varchar(16))
652BEGIN
653 SET @occasCount = -1;
654 SELECT COUNT(*) INTO @occasCount FROM tblOccasionnel where idOccas = p_idOccas and dateFinOccas is not null;
655 IF (@occasCount = 0) THEN
656 call AjoutTransactionOccas(p_idOccas, p_idPaiement, p_numPaiement, @LIDTRANSACOCCAS);
657
658 UPDATE tblOccasionnel set dateFinOccas = now(), idTransaction = @LIDTRANSACOCCAS WHERE idOccas = p_idOccas;
659 ELSE
660 SELECT 'Cet occasionel a déjà quitté';
661 END IF;
662END$$
663DELIMITER ;
664
665update tblOccasionnel set dateDebutOccas = '2018-04-21 15:00:00' where idOccas = '201804212';
666call SortieOccasionnel('201804216', 4, null);
667call SortieOccasionnel('201804212', 1, '4000000000000002');
668select * from tblTransaction where idTransaction = 67;
669select * from tblOccasionnel where idOccas = '201804216';
670select * from tblOccasionnel;
671
672-- -------------------------------------------------------------------------
673-- Procédure DepotQuotidien(), va retourner les achats par type de paiement et
674-- par type d'utilisateur
675-- -------------------------------------------------------------------------
676drop procedure if exists DepotQuotidien;
677DROP TEMPORARY TABLE if exists TMP_depot;
678
679DELIMITER $$
680CREATE PROCEDURE `DepotQuotidien`(p_DateVerif Date)
681BEGIN
682 DECLARE v_CrOcca int;
683 DECLARE v_CrAbon int;
684 DECLARE v_CoOcca int;
685 DECLARE v_CoAbon int;
686 set v_CrOcca = FnCreditOcca(p_DateVerif);
687 set v_CrAbon = FnCreditAbonne(p_DateVerif);
688 set v_CoOcca = FnComptantOcca(p_DateVerif);
689 set v_CoAbon = FnComptantAbonne(p_DateVerif);
690
691
692 CREATE TEMPORARY TABLE TMP_depot (
693 type_Depot varchar(25),
694 Abonnements DECIMAL(9,2),
695 Occasionnels DECIMAL(9,2));
696
697 INSERT INTO TMP_depot (type_Depot, Abonnements, Occasionnels)
698 VALUE ('Carte de crédit', v_CrAbon, v_CrOcca);
699 INSERT INTO TMP_depot (type_Depot, Abonnements, Occasionnels)
700 VALUE ('Argent comptant', v_CoAbon, v_CoOcca);
701 INSERT INTO TMP_depot (type_Depot, Abonnements, Occasionnels)
702 VALUE ('Total', (v_CoAbon + v_CrAbon), (v_CoOcca + v_CrOcca));
703
704 SELECT * From TMP_depot;
705
706 DROP TEMPORARY TABLE TMP_depot;
707
708END$$
709DELIMITER ;
710
711call DepotQuotidien(curdate());
712#SELECT SUM(FnCreditOcca(curdate()) + FnComptantOcca(curdate()));
713
714-- --------------------------------------------------------------------------------
715-- Procédure ventilation donne la ventilation dans un tableau des sommes
716-- perçues par type de personne (physique ou société), les véhicules occasionnels.
717-- --------------------------------------------------------------------------------
718drop procedure if exists ventilation;
719DROP TEMPORARY TABLE if exists TMP_ventilation;
720
721DELIMITER $$
722CREATE PROCEDURE `ventilation`(p_DateDebut Date, p_DateFin Date)
723BEGIN
724 DECLARE v_NnOcca int;
725 DECLARE v_NbAbonSoc int;
726 DECLARE v_NbAbonPers int;
727 DECLARE v_SommeOcca DEC(9,2);
728 DECLARE v_SommeAbonSoc DEC(9,2);
729 DECLARE v_SommeAbonPers DEC(9,2);
730
731 SET v_NnOcca = FnNbOcca(p_DateDebut, p_DateFin);
732 SET v_NbAbonSoc = FnNbAbon(p_DateDebut, p_DateFin, 's');
733 SET v_NbAbonPers = FnNbAbon(p_DateDebut, p_DateFin, 'p');
734 SET v_SommeOcca = FnSommeOcca(p_DateDebut, p_DateFin);
735 SET v_SommeAbonSoc = FnSommeAbon(p_DateDebut, p_DateFin, 's');
736 SET v_SommeAbonPers = FnSommeAbon(p_DateDebut, p_DateFin, 'p');
737
738 CREATE TEMPORARY TABLE TMP_ventilation (
739 TypeDeClient varchar(25),
740 NbAbonnements INT,
741 SommeAbonnements DECIMAL(9,2),
742 NbOccasionnels INT,
743 SommeOccasionnels DECIMAL(9,2));
744
745 INSERT INTO TMP_ventilation (TypeDeClient, NbAbonnements, SommeAbonnements, NbOccasionnels, SommeOccasionnels)
746 VALUE ('Personne', v_NbAbonPers, v_SommeAbonPers, v_NnOcca, v_SommeOcca);
747 INSERT INTO TMP_ventilation (TypeDeClient, NbAbonnements, SommeAbonnements, NbOccasionnels, SommeOccasionnels)
748 VALUE ('Société', v_NbAbonSoc, v_SommeAbonSoc, null, null);
749 INSERT INTO TMP_ventilation (TypeDeClient, NbAbonnements, SommeAbonnements, NbOccasionnels, SommeOccasionnels)
750 VALUE ('Total', (v_NbAbonPers+v_NbAbonSoc), (v_SommeAbonPers+v_SommeAbonSoc), v_NnOcca, v_SommeOcca);
751
752 SELECT TypeDeClient as '', NbAbonnements, SommeAbonnements, NbOccasionnels, SommeOccasionnels From TMP_ventilation;
753
754 DROP TEMPORARY TABLE TMP_ventilation;
755
756END$$
757DELIMITER ;
758
759call ventilation(curdate()-1, curdate()+1);
760
761###############################
762### INSERTIONS DES DONNÉÉES ###
763###############################
764
765SET FOREIGN_KEY_CHECKS = 1;
766
767use TP3;
768
769-- appele de la procédure pour faire l'insertion des places
770call InsertPlaces(500, 'plein air');
771call InsertPlaces(2000, 'couvert');
772
773-- insertion manuelle, car pas besoin de beaucoup de ville
774INSERT INTO tblVille (nomville) VALUES("Québec"),("Montréal"),("Laval"),("Shannon"),("St-Gabriel-de-Valcartier"),("Val-Bélair"),("Loretteville"),("Charlesbourg"),("Beauport");
775
776-- insertion manuelle avec des données produite par generatedata
777INSERT INTO tblAbonne (`nomAbonne`,`prenomAbonne`,`codePostal`,`telephone`,`courriel`,`typeAbonne`,`idVille`)
778 VALUES ("Harveys",NULL,"Q4A2O7","1-195-388-6491","nec@Nulla.co.uk","S","3"),("Valentine","Cooper","K6A6V3","1-398-119-9628","habitant.morbi@diamluctuslobortis.com","P","3"),("Hedley","Harrell","B9D5S6","1-630-751-9399","leo@cursusaenim.ca","P","8"),("Gary","Roberts","Q2R2V3","1-965-296-3762","Morbi.accumsan.laoreet@fermentum.co.uk","P","7"),("Francis","Austin","P8O0F3","1-892-685-0409","tempor.diam@sociis.org","P","1"),("Edward","Mosley","S8J5W1","1-385-850-5982","et@urnaet.ca","P","3"),("Benedict","Bell","U0K6N4","1-570-196-4909","nunc.sit.amet@penatibusetmagnis.co.uk","P","8"),("Stewart","Soto","B1A4D5","1-893-189-9061","nec.metus.facilisis@enimcondimentumeget.ca","P","1"),("Neville","Marquez","O1J0H8","1-868-749-2997","ipsum.ac@diamnunc.edu","P","3"),("Zachery","Zimmerman","Y6T5A4","1-765-696-4719","et.tristique.pellentesque@dignissimtemporarcu.edu","P","5");
779INSERT INTO tblAbonne (`nomAbonne`,`prenomAbonne`,`codePostal`,`telephone`,`courriel`,`typeAbonne`,`idVille`)
780 VALUES ("Simons",NULL,"Q9R5F5","1-878-506-6536","dictum.eu@a.edu","S","1"),("Steven","Hampton","T0V9T4","1-736-971-6586","Lorem.ipsum@ante.com","P","9"),("Jamal","Ramirez","V3F5Y9","1-826-233-8755","Donec.consectetuer@fringilla.net","P","2"),("Norman","Fields","M9C8J1","1-411-164-1888","a.feugiat@erosnectellus.net","P","2"),("Wyatt","Christensen","J8E3J3","1-746-245-0521","feugiat.Lorem.ipsum@nullaInteger.ca","P","1"),("Bert","Frazier","O0S9T6","1-781-873-6623","Aliquam.fringilla@Quisquelibero.com","P","7"),("Louis","House","I8M6E3","1-974-211-5774","ultrices.mauris@Integervitae.net","P","9"),("Alden","Cote","F3J7B6","1-893-631-0078","tristique.ac@quisturpis.net","P","5"),("Dolan","Fischer","L9Z4M5","1-141-234-6710","risus.Quisque@odiosagittissemper.co.uk","P","4"),("Zane","Manning","L6Y8S3","1-595-890-4447","imperdiet@placerataugueSed.com","P","4");
781INSERT INTO tblAbonne (`nomAbonne`,`prenomAbonne`,`codePostal`,`telephone`,`courriel`,`typeAbonne`,`idVille`)
782 VALUES ("Sears",NULL,"Q7J7T4","1-337-614-9853","lacinia.vitae@malesuada.co.uk","S","6"),("Channing","Chapman","I9D6T3","1-530-608-2930","velit.Quisque@lectus.edu","P","7"),("Declan","Gamble","F4T1A0","1-431-958-2193","Fusce@lectusantedictum.co.uk","P","1"),("Zeph","Grant","U6Q2T3","1-662-303-3018","elit.Aliquam@nibh.ca","P","6"),("Reuben","Crane","Q2M9Z2","1-108-887-7001","dui.semper.et@felisDonec.co.uk","P","1"),("Cairo","Hensley","Z6V4Q0","1-193-858-1665","erat@nonluctussit.org","P","1"),("Acton","Garza","S5P7Q3","1-410-750-3337","neque@Quisque.net","P","1"),("Victor","Beach","B6V2T6","1-361-585-6601","at.risus@nonquamPellentesque.net","P","9"),("Brett","Doyle","O9P4R4","1-929-469-2034","aliquam@semmolestie.edu","P","9"),("Quentin","Haynes","X1D1L4","1-489-636-2755","nisl.Nulla.eu@vitaedolorDonec.edu","P","1");
783INSERT INTO tblAbonne (`nomAbonne`,`prenomAbonne`,`codePostal`,`telephone`,`courriel`,`typeAbonne`,`idVille`)
784 VALUES ("Canac",NULL,"Y1C5C7","1-321-806-6027","In.ornare@adipiscingMaurismolestie.co.uk","S","6"),("Amery","Fletcher","A7V3H7","1-922-766-4167","ut.sem@sitametconsectetuer.edu","P","8"),("Lawrence","Conley","N2J8S1","1-309-234-5089","nec@luctuslobortisClass.net","P","9"),("Herman","Clarke","C4Q6N4","1-594-470-9280","Morbi.metus@dolor.net","P","9"),("Alvin","Garrison","I9N0E9","1-807-832-5544","augue.malesuada.malesuada@Nuncsedorci.co.uk","P","7"),("Jesse","Meyers","G0O1X7","1-593-459-8094","adipiscing.ligula@semper.edu","P","6"),("Martin","Montgomery","L8Z8W1","1-951-412-8004","molestie@Donecconsectetuer.net","P","9"),("Yuli","Wiley","T8I8E4","1-397-165-4584","diam.luctus@nec.org","P","8"),("Kareem","Singleton","Z3H8Q9","1-199-250-4773","et.libero.Proin@leo.edu","P","4"),("Ezekiel","Hardin","N3A6B8","1-425-440-1465","euismod@placerat.co.uk","P","4");
785INSERT INTO tblAbonne (`nomAbonne`,`prenomAbonne`,`codePostal`,`telephone`,`courriel`,`typeAbonne`,`idVille`)
786 VALUES ("Ardenne",NULL,"A0G8T1","1-520-529-5925","Sed.nunc.est@antebibendumullamcorper.com","S","4"),("Donovan","Boyle","V9U4T5","1-116-449-6440","iaculis.odio.Nam@ipsumdolor.ca","P","5"),("Zachary","Wagner","I5I8I3","1-768-867-8790","Integer.aliquam@auguescelerisque.co.uk","P","4"),("Josiah","Pickett","W5L4F1","1-859-110-2038","enim.Suspendisse@leo.ca","P","7"),("Demetrius","Reed","K6E8S2","1-979-137-2222","Sed.nunc.est@laciniaatiaculis.org","P","6"),("Ezra","Strong","H7C2N6","1-403-362-0716","laoreet@metusAliquam.org","P","4"),("Slade","Mann","P7C1V8","1-812-124-1004","venenatis@laciniavitae.org","P","8"),("Emmanuel","George","U2R8C6","1-477-621-3758","feugiat.nec.diam@non.net","P","8"),("John","Warner","P8D4H6","1-276-604-5994","mi@feugiat.co.uk","P","3"),("Lucius","Rocha","U2D1F6","1-191-164-7881","erat.volutpat@posuerevulputatelacus.com","P","7");
787
788INSERT INTO `tblVehicule` VALUES (FnRandomPlaque(),"Lexus","Multi-Segment","violet"),(FnRandomPlaque(),"Fiat","Pickup","grey"),(FnRandomPlaque(),"Lexus","Utilitaire","black"),(FnRandomPlaque(),"Ford","VUS","yellow"),(FnRandomPlaque(),"BMW","Utilitaire","blue"),(FnRandomPlaque(),"Acura","Utilitaire","blue"),(FnRandomPlaque(),"Lexus","Berline","red"),(FnRandomPlaque(),"Dacia","Multi-Segment","violet"),(FnRandomPlaque(),"Peugeot","Multi-Segment","violet"),(FnRandomPlaque(),"General Motors","Berline","blue");
789INSERT INTO `tblVehicule` VALUES (FnRandomPlaque(),"Kia Motors","Hatchback","red"),(FnRandomPlaque(),"Mahindra and Mahindra","Hatchback","yellow"),(FnRandomPlaque(),"Audi","Berline","green"),(FnRandomPlaque(),"Dacia","Hatchback","black"),(FnRandomPlaque(),"Seat","Pickup","indigo"),(FnRandomPlaque(),"Audi","Sport","orange"),(FnRandomPlaque(),"Mitsubishi Motors","Sport","orange"),(FnRandomPlaque(),"Kia Motors","Hatchback","blue"),(FnRandomPlaque(),"Subaru","Hatchback","grey"),(FnRandomPlaque(),"Mahindra and Mahindra","Berline","indigo");
790INSERT INTO `tblVehicule` VALUES (FnRandomPlaque(),"Daihatsu","Utilitaire","indigo"),(FnRandomPlaque(),"Mercedes-Benz","Hatchback","grey"),(FnRandomPlaque(),"Infiniti","Pickup","blue"),(FnRandomPlaque(),"BMW","Pickup","indigo"),(FnRandomPlaque(),"Chrysler","Pickup","blue"),(FnRandomPlaque(),"Lincoln","Utilitaire","grey"),(FnRandomPlaque(),"Suzuki","Berline","red"),(FnRandomPlaque(),"Mahindra and Mahindra","Hatchback","blue"),(FnRandomPlaque(),"BMW","Multi-Segment","blue"),(FnRandomPlaque(),"Dongfeng Motor","Pickup","orange");
791INSERT INTO `tblVehicule` VALUES (FnRandomPlaque(),"Nissan","VUS","violet"),(FnRandomPlaque(),"Subaru","Berline","yellow"),(FnRandomPlaque(),"Daimler","Berline","indigo"),(FnRandomPlaque(),"Daihatsu","Pickup","red"),(FnRandomPlaque(),"Honda","Multi-Segment","violet"),(FnRandomPlaque(),"BMW","Hatchback","yellow"),(FnRandomPlaque(),"Mazda","Pickup","violet"),(FnRandomPlaque(),"Kia Motors","Sport","green"),(FnRandomPlaque(),"Skoda","Sport","violet"),(FnRandomPlaque(),"Skoda","VUS","orange");
792INSERT INTO `tblVehicule` VALUES (FnRandomPlaque(),"Daimler","Berline","blue"),(FnRandomPlaque(),"Toyota","Utilitaire","grey"),(FnRandomPlaque(),"Renault","Multi-Segment","blue"),(FnRandomPlaque(),"Cadillac","Hatchback","red"),(FnRandomPlaque(),"Dodge","Pickup","red"),(FnRandomPlaque(),"Lexus","Berline","red"),(FnRandomPlaque(),"RAM Trucks","Multi-Segment","yellow"),(FnRandomPlaque(),"Daimler","Berline","orange"),(FnRandomPlaque(),"Chevrolet","Berline","green"),(FnRandomPlaque(),"Subaru","Sport","violet");
793INSERT INTO `tblVehicule` VALUES (FnRandomPlaque(),"Renault","Berline","blue"),(FnRandomPlaque(),"Mazda","Hatchback","indigo"),(FnRandomPlaque(),"Fiat","Utilitaire","indigo"),(FnRandomPlaque(),"Chrysler","Sport","blue"),(FnRandomPlaque(),"Mitsubishi Motors","VUS","violet"),(FnRandomPlaque(),"Lexus","Hatchback","grey"),(FnRandomPlaque(),"Chevrolet","VUS","indigo"),(FnRandomPlaque(),"Skoda","Hatchback","red"),(FnRandomPlaque(),"GMC","Utilitaire","orange"),(FnRandomPlaque(),"Subaru","VUS","yellow");
794INSERT INTO `tblVehicule` VALUES (FnRandomPlaque(),"Vauxhall","Sport","grey"),(FnRandomPlaque(),"Jeep","Pickup","yellow"),(FnRandomPlaque(),"Kenworth","VUS","grey"),(FnRandomPlaque(),"Chevrolet","Pickup","black"),(FnRandomPlaque(),"Isuzu","VUS","blue"),(FnRandomPlaque(),"JLR","Multi-Segment","violet"),(FnRandomPlaque(),"Dacia","VUS","indigo"),(FnRandomPlaque(),"Smart","Sport","blue"),(FnRandomPlaque(),"Lexus","Pickup","yellow"),(FnRandomPlaque(),"Mitsubishi Motors","Utilitaire","red");
795INSERT INTO `tblVehicule` VALUES (FnRandomPlaque(),"GMC","Hatchback","red"),(FnRandomPlaque(),"Cadillac","Multi-Segment","green"),(FnRandomPlaque(),"Kia Motors","Pickup","red"),(FnRandomPlaque(),"Mahindra and Mahindra","Pickup","blue"),(FnRandomPlaque(),"Citroën","VUS","indigo"),(FnRandomPlaque(),"Vauxhall","Hatchback","green"),(FnRandomPlaque(),"Fiat","Pickup","violet"),(FnRandomPlaque(),"Ferrari","Berline","black"),(FnRandomPlaque(),"Smart","Multi-Segment","indigo"),(FnRandomPlaque(),"Volkswagen","Utilitaire","grey");
796INSERT INTO `tblVehicule` VALUES (FnRandomPlaque(),"Volvo","Multi-Segment","orange"),(FnRandomPlaque(),"Hyundai Motors","Berline","black"),(FnRandomPlaque(),"Hyundai Motors","Multi-Segment","green"),(FnRandomPlaque(),"GMC","Utilitaire","orange"),(FnRandomPlaque(),"General Motors","Utilitaire","yellow"),(FnRandomPlaque(),"BMW","Sport","grey"),(FnRandomPlaque(),"Peugeot","Sport","black"),(FnRandomPlaque(),"Seat","Multi-Segment","red"),(FnRandomPlaque(),"Mahindra and Mahindra","Berline","red"),(FnRandomPlaque(),"Lincoln","Pickup","black");
797INSERT INTO `tblVehicule` VALUES (FnRandomPlaque(),"Toyota","Pickup","grey"),(FnRandomPlaque(),"Lincoln","Berline","orange"),(FnRandomPlaque(),"Seat","Utilitaire","yellow"),(FnRandomPlaque(),"Lexus","Multi-Segment","red"),(FnRandomPlaque(),"Mahindra and Mahindra","VUS","grey"),(FnRandomPlaque(),"Subaru","Berline","blue"),(FnRandomPlaque(),"Daimler","Hatchback","indigo"),(FnRandomPlaque(),"MINI","Sport","yellow"),(FnRandomPlaque(),"Peugeot","Berline","yellow"),(FnRandomPlaque(),"Smart","Berline","yellow");
798
799select count(*) from tblVehicule;
800
801-- insertion manuelle, car pas assé de donnée à générer
802INSERT INTO tblMethodPaiement (typePaiement,descPaiement) VALUES("V","Visa"),("M","MasterCard"),("X","Amex"),("A","Comptant"),("C","Chèque");
803
804-- -------------------------------------------------------------------
805-- Procédure pour ajouter des occasionnels en lot selon une qte donnée
806-- -------------------------------------------------------------------
807DELIMITER $$
808CREATE PROCEDURE `AjoutOccasEnLot`(in p_nb int)
809BEGIN
810 DECLARE v_i int DEFAULT 1;
811 WHILE v_i <= p_nb DO
812 call AjoutOccasionnel();
813 SET v_i = v_i + 1;
814 END WHILE;
815END $$
816DELIMITER ;
817
818call AjoutOccasEnLot(150);
819
820#select count(*) from tblOccasionnel;
821
822-- -----------------------------------------------------------------
823-- Procédure pour ajouter des Abonnement en lot selon une qte donnée
824-- -----------------------------------------------------------------
825DELIMITER $$
826CREATE PROCEDURE `AjoutAbonEnLot`(in p_nb int)
827BEGIN
828 DECLARE v_i int DEFAULT 1;
829 DECLARE v_idAbon int;
830 DECLARE v_nbDuree int;
831 DECLARE v_idPaiement int;
832 DECLARE v_idVehicule varchar(6);
833 DECLARE v_idPlace int;
834 WHILE v_i <= p_nb DO
835 SET v_idAbon = FLOOR(RAND()*(50-1+1))+1;
836 SET v_nbDuree = FLOOR(RAND()*(12-1+1))+1;
837 SET v_idPaiement = FLOOR(RAND()*(5-1+1))+1;
838 SET v_idVehicule = (SELECT idVehicule FROM tblVehicule ORDER BY RAND() LIMIT 1);
839 SET v_idPlace = FLOOR(RAND()*(2500-1+1))+1;
840 IF (v_idPaiement = 4) THEN
841 call AjoutAbonnement(curdate(),v_nbDuree,v_idAbon,v_idPaiement,null,v_idVehicule,v_idPlace);
842 ELSE
843 call AjoutAbonnement(curdate(),v_nbDuree,v_idAbon,v_idPaiement,'4000000000000002',v_idVehicule,v_idPlace);
844 END IF;
845 SET v_i = v_i + 1;
846 END WHILE;
847END $$
848DELIMITER ;
849
850call AjoutAbonEnLot(100);
851
852select COUNT(*) from tblAbonnement;
853############################
854########## TESTS ###########
855############################
856
857#select * from tblAbonne where nomAbonne = 'Harveys';
858#insert into tblAbonne (nomAbonne,prenomAbonne,codePostal,telephone,courriel,typeAbonne,idVille) values('Harveys', null, 'Q4A2O7', '1-195-388-6491', 'nec@Nulla.co.uk', 'S', 3, @UnErreur);