Overview
Comment:Import dans la bonne catégorie recette/dépense s'il y a une catégorie qui a le même nom dans l'autre type
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable
Files: files | file ages | folders
SHA1: 34f324b0a2091c5966540b1f1be34a2f5dd5f972
User & Date: bohwaz on 2020-04-07 00:50:19
Other Links: manifest | tags
Context
2020-04-22
02:05
Fonctions dépréciées dans PHP 7.3 check-in: 2d91e51455 user: bohwaz tags: trunk, stable
2020-04-07
00:50
Import dans la bonne catégorie recette/dépense s'il y a une catégorie qui a le même nom dans l'autre type check-in: 34f324b0a2 user: bohwaz tags: trunk, stable
00:41
Suppression de la possibilité d'importer depuis Citizen check-in: 620df5a2e5 user: bohwaz tags: trunk, stable
Changes

Modified src/include/lib/Garradin/Compta/Import.php from [99fd308df7] to [f437eb905d].

86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100







-
+







		}

		$db = DB::getInstance();
		$db->begin();
		$cats = new Categories;
		$journal = new Journal;

		$liste_cats = $db->getAssoc('SELECT intitule, id FROM compta_categories;');
		$liste_cats = $db->getAssoc('SELECT type || intitule, id FROM compta_categories;');
		// Liste des moyens sous la forme nom -> code
		$liste_moyens = array_flip($cats->listMoyensPaiement(true));
		$liste_moyens = array_change_key_case($liste_moyens, \CASE_LOWER);

		// Liste associative des projets
		$liste_projets = $db->getAssoc('SELECT libelle, id FROM compta_projets;');

166
167
168
169
170
171
172











173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

194



195
196
197
198
199
200
201
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203

204

205
206
207
208
209
210
211
212
213
214







+
+
+
+
+
+
+
+
+
+
+




















-
+
-
+
+
+







			}

			$debit = $col('Compte de débit - numéro');
			$credit = $col('Compte de crédit - numéro');

			$cat = $col('Catégorie');
			$moyen = strtolower($col('Moyen de paiement'));
			$type = $col('Type de mouvement');

			if ('Recette' === $type) {
				$type = 1;
			}
			elseif ('Dépense' === $type) {
				$type = -1;
			}
			else {
				$type = 0;
			}

			// Association du moyen de paiement par nom
			if ($moyen && array_key_exists($moyen, $liste_moyens))
			{
				$moyen = $liste_moyens[$moyen];
			}
			// Sinon on estime que c'est juste le code qui est fourni
			else
			{
				$moyen = substr(strtoupper($moyen), 0, 2);
			}

			// Vérification de l'existence du moyen de paiement
			// s'il n'est pas valide, on ne peut pas avoir de catégorie non plus
			if (!trim($moyen) || !in_array($moyen, $liste_moyens, true))
			{
				$moyen = false;
				$cat = false;
			}

			if ($cat && !array_key_exists($cat, $liste_cats))
			if ($cat && array_key_exists($type . $cat, $liste_cats)) {
			{
				$cat = $liste_cats[$type . $cat];
			}
			else {
				$cat = $moyen = false;
			}

			$id_projet = null;

			if (!empty($col('Projet'))) {
				if (!array_key_exists($col('Projet'), $liste_projets)) {
216
217
218
219
220
221
222
223

224
225
226
227
228
229
230
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243







-
+







				'id_projet'     =>  $id_projet,
			];

			if ($cat)
			{
				$data['moyen_paiement']	=	$moyen;
				$data['numero_cheque']	=	$col('Numéro de chèque');
				$data['id_categorie']	=	$liste_cats[$cat];
				$data['id_categorie']	=	$cat;
			}

			try {
				if (empty($id))
				{
					$journal->add($data);
				}