Subversion Repositories Applications.annuaire

Rev

Rev 328 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 328 Rev 336
1
<?php 
1
<?php 
2
 
2
 
3
class CotisationModele extends AnnuaireModele {
3
class CotisationModele extends AnnuaireModele {
4
	
4
	
5
	public function __construct() {
5
	public function __construct() {
6
		parent::__construct();
6
		parent::__construct();
7
	}
7
	}
8
	
8
	
9
	public function obtenirInformationsCotisationsPourInscrit($id_inscrit) {
9
	public function obtenirInformationsCotisationsPourInscrit($id_inscrit) {
10
		
10
		
11
		$requete_informations_cotisation = 'SELECT * FROM '.Config::get('cotisation_bdd').'.'.Config::get('cotisation_table').' '.
11
		$requete_informations_cotisation = 'SELECT * FROM '.Config::get('cotisation_bdd').'.'.Config::get('cotisation_table').' '.
12
    								'WHERE IC_ANNU_ID = '.$this->proteger($id_inscrit).' '.
12
    								'WHERE IC_ANNU_ID = '.$this->proteger($id_inscrit).' '.
13
    								'ORDER BY IC_DATE ';
13
    								'ORDER BY IC_DATE ';
14
 
14
 
15
    	$infos_cotisation_inscrit = $this->requeteTous($requete_informations_cotisation);
15
    	$infos_cotisation_inscrit = $this->requeteTous($requete_informations_cotisation);
16
    	
16
    	
17
    	return $infos_cotisation_inscrit;
17
    	return $infos_cotisation_inscrit;
18
	}
18
	}
19
	
19
	
20
	public function obtenirInformationsPourIdCotisation($id_cotisation, $id_inscrit) {
20
	public function obtenirInformationsPourIdCotisation($id_cotisation, $id_inscrit) {
21
		
21
		
22
		$requete_informations_cotisation = 'SELECT * FROM '.Config::get('cotisation_bdd').'.'.Config::get('cotisation_table').' '.
22
		$requete_informations_cotisation = 'SELECT * FROM '.Config::get('cotisation_bdd').'.'.Config::get('cotisation_table').' '.
23
    								'WHERE '.
23
    								'WHERE '.
24
    								'IC_ID = '.$this->proteger($id_cotisation).' '.
24
    								'IC_ID = '.$this->proteger($id_cotisation).' '.
25
									'AND IC_ANNU_ID = '.$this->proteger($id_inscrit);
25
									'AND IC_ANNU_ID = '.$this->proteger($id_inscrit);
26
		
26
		
27
    	$infos_cotisation = $this->requeteUn($requete_informations_cotisation);
27
    	$infos_cotisation = $this->requeteUn($requete_informations_cotisation);
28
    	
28
    	
29
    	return $infos_cotisation;
29
    	return $infos_cotisation;
30
	}
30
	}
31
	
31
	
32
	public function ajouterCotisation($params) {
32
	public function ajouterCotisation($params) {
33
	
33
	
34
		$requete_creation_cotisation = 'INSERT INTO '.Config::get('cotisation_bdd').'.annuaire_COTISATION '.
34
		$requete_creation_cotisation = 'INSERT INTO '.Config::get('cotisation_bdd').'.annuaire_COTISATION '.
35
						'(IC_MC_ID, IC_ANNU_ID, IC_DATE, IC_MONTANT) '.
35
						'(IC_MC_ID, IC_ANNU_ID, IC_DATE, IC_MONTANT) '.
36
						'VALUES ('.
36
						'VALUES ('.
37
	    						$this->proteger($params['mode_cotisation']).','.	
37
	    						$this->proteger($params['mode_cotisation']).','.	
38
								$this->proteger($params['id_cotisant']).','.
38
								$this->proteger($params['id_cotisant']).','.
39
								$this->proteger($params['date_cotisation']).','.
39
								$this->proteger($params['date_cotisation']).','.
40
								$this->proteger($params['montant_cotisation']).' '.
40
								$this->proteger($params['montant_cotisation']).' '.
41
						')';		
41
						')';		
42
												
42
												
43
		return $this->requete($requete_creation_cotisation);
43
		return $this->requete($requete_creation_cotisation);
44
	}
44
	}
45
	
45
	
46
	public function MettreAJourCotisation($id_cotisation, $params) {
46
	public function MettreAJourCotisation($id_cotisation, $params) {
47
		
47
		
48
		$requete_modification_cotisation = 'UPDATE '.Config::get('cotisation_bdd').'.annuaire_COTISATION '.
48
		$requete_modification_cotisation = 'UPDATE '.Config::get('cotisation_bdd').'.annuaire_COTISATION '.
49
			'SET '.
49
			'SET '.
50
			'IC_MC_ID ='.$this->proteger($params['mode_cotisation']).','.
50
			'IC_MC_ID ='.$this->proteger($params['mode_cotisation']).','.
51
			'IC_DATE ='.$this->proteger($params['date_cotisation']).','.
51
			'IC_DATE ='.$this->proteger($params['date_cotisation']).','.
52
			'IC_MONTANT ='.$this->proteger($params['montant_cotisation']).' '.
52
			'IC_MONTANT ='.$this->proteger($params['montant_cotisation']).' '.
53
			'WHERE IC_ID = '.$this->proteger($id_cotisation);
53
			'WHERE IC_ID = '.$this->proteger($id_cotisation);
54
							
54
							
55
		return $this->requete($requete_modification_cotisation);
55
		return $this->requete($requete_modification_cotisation);
56
	}
56
	}
57
	
57
	
58
	public function supprimerCotisation($id_cotisation) {
58
	public function supprimerCotisation($id_cotisation) {
59
		
59
		
60
		$requete_suppression_cotisation = 'DELETE FROM '.Config::get('cotisation_bdd').'.annuaire_COTISATION '.
60
		$requete_suppression_cotisation = 'DELETE FROM '.Config::get('cotisation_bdd').'.annuaire_COTISATION '.
61
    	'WHERE IC_ID = '.$this->proteger($id_cotisation);
61
    	'WHERE IC_ID = '.$this->proteger($id_cotisation);
62
    	
62
    	
63
    	return $this->requete($requete_suppression_cotisation);
63
    	return $this->requete($requete_suppression_cotisation);
64
	}
64
	}
65
	
65
	
66
    public function obtenirListeModesCotisation() {
66
    public function obtenirListeModesCotisation() {
67
    	
67
    	
68
    	    $modes_cotisation = array(0 => 'Chèque',
68
    	    $modes_cotisation = array(0 => 'Chèque',
69
							    	1 => 'Espèce',
69
							    	1 => 'Espèce',
70
							    	2 => 'Virement',
70
							    	2 => 'Virement',
71
							    	3 => 'Paypal',
71
							    	3 => 'Paypal',
72
							    	4 => 'Prélèvement'
72
							    	4 => 'Prélèvement'
73
    						);
73
    						);
74
			
74
			
75
    	//FIXME : en attendant de savoir si on déplace le contenu de la table mode_cotisation dans les triples					
75
    	//FIXME : en attendant de savoir si on déplace le contenu de la table mode_cotisation dans les triples					
76
    	return $modes_cotisation;
76
    	return $modes_cotisation;
77
    }
77
    }
78
	
78
	
79
    public function obtenirModeCotisationParId($id_mode) {
79
    public function obtenirModeCotisationParId($id_mode) {
80
    	
80
    	
81
    	$modes_cotisation = array(0 => 'Chèque',
81
    	$modes_cotisation = array(0 => 'Chèque',
82
							    	1 => 'Espèce',
82
							    	1 => 'Espèce',
83
							    	2 => 'Virement',
83
							    	2 => 'Virement',
84
							    	3 => 'Paypal',
84
							    	3 => 'Paypal',
85
							    	4 => 'Prélèvement'
85
							    	4 => 'Prélèvement'
86
    						);
86
    						);
87
 
87
 
88
    						
88
    						
89
    	//FIXME : en attendant de savoir si on déplace le contenu de la table mode_cotisation dans les triples					
89
    	//FIXME : en attendant de savoir si on déplace le contenu de la table mode_cotisation dans les triples					
90
    	return $modes_cotisation[$id_mode];
90
    	return $modes_cotisation[$id_mode];
91
    	
91
    	
92
    	$requete_infos_mode = 'SELECT MC_LABEL as mode_label FROM MODE_COTISATION WHERE MC_ID = '.$this->proteger($id_mode);
92
    	$requete_infos_mode = 'SELECT MC_LABEL as mode_label FROM MODE_COTISATION WHERE MC_ID = '.$this->proteger($id_mode);
93
    	
93
    	
94
    	$infos_mode = $this->requete($requete_infos_mode);
94
    	$infos_mode = $this->requete($requete_infos_mode);
95
    	
95
    	
96
    	if(!empty($infos_mode)) {
96
    	if(!empty($infos_mode)) {
97
    		$infos_mode = $infos_mode[0];
97
    		$infos_mode = $infos_mode[0];
98
    	}
98
    	}
99
    	
99
    	
100
    	return $infos_mode['mode_label'];
100
    	return $infos_mode['mode_label'];
101
    }
101
    }
102
    
102
    
103
    public function calculerNouvelOrdreRecuEtIncrementer() {
-
 
104
 
-
 
105
    	$requete_nouvel_ordre = 'select COMPTEUR from '.Config::get('cotisation_bdd').'.COMPTEUR_COTISATION';
-
 
106
    			
-
 
107
		$resultat_requete_nouvel_ordre = $this->requeteUn($requete_nouvel_ordre) ;
-
 
108
		
-
 
-
 
103
    public function calculerNouvelOrdreRecuEtIncrementer($annee) {
-
 
104
		
109
		$num_recu = $resultat_requete_nouvel_ordre['COMPTEUR'];
105
		$numero_recu = $this->numeroRecuExistePourAnnee($annee);
110
		
106
 
111
		if(!$num_recu) {
107
    	if($numero_recu == null) {
112
			return 0;
108
    		$numero_recu = $this->initialiserNumeroRecuPourAnnee($annee);
113
		}
109
    	}
-
 
110
		
-
 
111
		$requete_incrementation_ordre = 'UPDATE '.Config::get('cotisation_bdd').'.COMPTEUR_COTISATION '.
114
		
112
										'SET COMPTEUR = COMPTEUR + 1 '.
115
		$requete_incrementation_ordre = 'UPDATE '.Config::get('cotisation_bdd').'.COMPTEUR_COTISATION '.
113
										'WHERE ANNEE = "'.$annee.'"';
-
 
114
 
-
 
115
		$resultat_requete_incrementation_ordre = $this->requete($requete_incrementation_ordre) ;
-
 
116
		
-
 
117
		return $numero_recu;
-
 
118
    }
-
 
119
    
-
 
120
    private function numeroRecuExistePourAnnee($annee) {
-
 
121
    	
-
 
122
    	$requete_selection_num_recu_annee = 'SELECT COMPTEUR ' .
-
 
123
    										'FROM '.Config::get('cotisation_bdd').'.COMPTEUR_COTISATION ' .
-
 
124
    											'WHERE ANNEE = "'.$annee.'"';
-
 
125
    											
-
 
126
    	$resultat_selection_num_recu_annee = $this->requeteUn($requete_selection_num_recu_annee);
-
 
127
    	
-
 
128
    	$num_recu = null;
-
 
129
    	
-
 
130
    	if($resultat_selection_num_recu_annee) {
-
 
131
    		$num_recu = $resultat_selection_num_recu_annee['COMPTEUR'];
-
 
132
    	}  
-
 
133
    	
-
 
134
    	return $num_recu;   	
-
 
135
    }
-
 
136
    
-
 
137
    private function initialiserNumeroRecuPourAnnee($annee) {
-
 
138
    	
-
 
139
    	$requete_insertion_num_recu_annee = 'INSERT INTO '.Config::get('cotisation_bdd').'.COMPTEUR_COTISATION ' .
-
 
140
    										'(COMPTEUR, ANNEE) '.
-
 
141
											'VALUES ('.
-
 
142
										    	'1,'.									
-
 
143
						    					$this->proteger($annee).	
-
 
144
											')';
-
 
145
					
-
 
146
    	$resultat_insertion_num_recu_annee = $this->requete($requete_insertion_num_recu_annee);
-
 
147
    
-
 
148
    	$num_nouveau_recu = 1;  	
-
 
149
    	if(!$resultat_insertion_num_recu_annee) {
116
										'SET COMPTEUR = COMPTEUR + 1';
150
    		$num_nouveau_recu = null;
117
		$resultat_requete_incrementation_ordre = $this->requete($requete_incrementation_ordre) ;
151
    	}
118
		
152
    	
119
		return $num_recu;
153
    	return $num_nouveau_recu;
120
    }
154
    }
121
    
155
    
122
	public function mettreAJourNumeroRecu($id_cotisation, $id_recu) {
156
	public function mettreAJourNumeroRecu($id_cotisation, $id_recu) {
123
    	
157
    	
124
    	$requete_maj_num_recu_cotisation = 'UPDATE '.Config::get('cotisation_bdd').'.annuaire_COTISATION '.
158
    	$requete_maj_num_recu_cotisation = 'UPDATE '.Config::get('cotisation_bdd').'.annuaire_COTISATION '.
125
			'SET '.
159
			'SET '.
126
			'IC_RECU = '.$this->proteger($id_recu).' '.
160
			'IC_RECU = '.$this->proteger($id_recu).' '.
127
			'WHERE IC_ID = '.$this->proteger($id_cotisation);
161
			'WHERE IC_ID = '.$this->proteger($id_cotisation);
128
    	
162
    	
129
    	$resultat_maj_envoi_num_cotisation = $this->requete($requete_maj_num_recu_cotisation) ;
163
    	$resultat_maj_envoi_num_cotisation = $this->requete($requete_maj_num_recu_cotisation) ;
130
    	
164
    	
131
    	return $id_recu;
165
    	return $id_recu;
132
    }
166
    }
133
    
167
    
134
    public function mettreAJourDateEnvoiRecu($id_cotisation) {
168
    public function mettreAJourDateEnvoiRecu($id_cotisation) {
135
    	
169
    	
136
    	$requete_maj_envoi_recu_cotisation = 'UPDATE '.Config::get('cotisation_bdd').'.annuaire_COTISATION '.
170
    	$requete_maj_envoi_recu_cotisation = 'UPDATE '.Config::get('cotisation_bdd').'.annuaire_COTISATION '.
137
			'SET '.
171
			'SET '.
138
			'IC_DATE_ENVOIE_RECU = NOW() '.
172
			'IC_DATE_ENVOIE_RECU = NOW() '.
139
			'WHERE IC_ID = '.$this->proteger($id_cotisation);
173
			'WHERE IC_ID = '.$this->proteger($id_cotisation);
140
    	
174
    	
141
    	$resultat_maj_envoi_recu_cotisation = $this->requete($requete_maj_envoi_recu_cotisation) ;
175
    	$resultat_maj_envoi_recu_cotisation = $this->requete($requete_maj_envoi_recu_cotisation) ;
142
    	
176
    	
143
    	return $resultat_maj_envoi_recu_cotisation;
177
    	return $resultat_maj_envoi_recu_cotisation;
144
    }
178
    }
145
    
179
    
146
	protected function renvoyerDernierIdInsere() {
180
	protected function renvoyerDernierIdInsere() {
147
		//TODO: cela marche t'il partout ? 
181
		//TODO: cela marche t'il partout ? 
148
		// à faire: tester le type de driver pdo et faire une fonction portable 
182
		// à faire: tester le type de driver pdo et faire une fonction portable 
149
		return $this->connexion->lastInsertId();
183
		return $this->connexion->lastInsertId();
150
	}
184
	}
151
}
185
}
152
?>
186
?>