Differences From Artifact [a96dfe987a]:

To Artifact [d0fb4b8ed7]:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

		if (!$fp)
		{
			return false;
		}

		$db = DB::getInstance();
		$db->exec('BEGIN;');
		$comptes = new Comptes;
		$banques = new Comptes_Bancaires;
		$cats = new Categories;
		$journal = new Journal;

		$columns = array_flip($this->csv_header);
		$liste_comptes = $db->simpleStatementFetchAssoc('SELECT id, id FROM compta_comptes;');







|







78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

		if (!$fp)
		{
			return false;
		}

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

		$columns = array_flip($this->csv_header);
		$liste_comptes = $db->simpleStatementFetchAssoc('SELECT id, id FROM compta_comptes;');
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
				}
				
				continue;
			}
	
			if (count($row) != count($columns))
			{
				$db->exec('ROLLBACK;');
				throw new UserException('Erreur sur la ligne ' . $line . ' : le nombre de colonnes est incorrect.');
			}

			if (trim($row[0]) !== '' && !is_numeric($row[0]))
			{
				$db->exec('ROLLBACK;');
				throw new UserException('Erreur sur la ligne ' . $line . ' : la première colonne doit être vide ou contenir le numéro unique d\'opération.');
			}

			$id = $col('Numéro mouvement');
			$date = $col('Date');

			if (!preg_match('!^\d{2}/\d{2}/\d{4}$!', $date))
			{
				$db->exec('ROLLBACK;');
				throw new UserException('Erreur sur la ligne ' . $line . ' : la date n\'est pas au format jj/mm/aaaa.');
			}

			$date = explode('/', $date);
			$date = $date[2] . '-' . $date[1] . '-' . $date[0];

			// En dehors de l'exercice courant







|





|








|







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
				}
				
				continue;
			}
	
			if (count($row) != count($columns))
			{
				$db->rollback();
				throw new UserException('Erreur sur la ligne ' . $line . ' : le nombre de colonnes est incorrect.');
			}

			if (trim($row[0]) !== '' && !is_numeric($row[0]))
			{
				$db->rollback();
				throw new UserException('Erreur sur la ligne ' . $line . ' : la première colonne doit être vide ou contenir le numéro unique d\'opération.');
			}

			$id = $col('Numéro mouvement');
			$date = $col('Date');

			if (!preg_match('!^\d{2}/\d{2}/\d{4}$!', $date))
			{
				$db->rollback();
				throw new UserException('Erreur sur la ligne ' . $line . ' : la date n\'est pas au format jj/mm/aaaa.');
			}

			$date = explode('/', $date);
			$date = $date[2] . '-' . $date[1] . '-' . $date[0];

			// En dehors de l'exercice courant
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
			}
			else
			{
				$journal->edit($id, $data);
			}
		}

		$db->exec('END;');

		fclose($fp);
		return true;
	}

	public function fromCitizen($path)
	{
		if (!file_exists($path) || !is_readable($path))
		{
			throw new \RuntimeException('Fichier inconnu : '.$path);
		}

		$fp = fopen($path, 'r');

		if (!$fp)
		{
			return false;
		}

		$db = DB::getInstance();
		$db->exec('BEGIN;');
		$comptes = new Comptes;
		$banques = new Comptes_Bancaires;
		$cats = new Categories;
		$journal = new Journal;

		$columns = [];
		$liste_comptes = $db->simpleStatementFetchAssoc('SELECT id, id FROM compta_comptes;');







|




















|







207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
			}
			else
			{
				$journal->edit($id, $data);
			}
		}

		$db->commit();

		fclose($fp);
		return true;
	}

	public function fromCitizen($path)
	{
		if (!file_exists($path) || !is_readable($path))
		{
			throw new \RuntimeException('Fichier inconnu : '.$path);
		}

		$fp = fopen($path, 'r');

		if (!$fp)
		{
			return false;
		}

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

		$columns = [];
		$liste_comptes = $db->simpleStatementFetchAssoc('SELECT id, id FROM compta_comptes;');
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
				continue;
			}

			$date = $col('Date');

			if (!preg_match('!^\d{2}/\d{2}/\d{4}$!', $date))
			{
				$db->exec('ROLLBACK;');
				throw new UserException('Erreur sur la ligne ' . $line . ' : la date n\'est pas au format jj/mm/aaaa.');
			}

			$date = explode('/', $date);
			$date = $date[2] . '-' . $date[1] . '-' . $date[0];

			if ($db->simpleQuerySingle('SELECT 1 FROM compta_exercices







|







304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
				continue;
			}

			$date = $col('Date');

			if (!preg_match('!^\d{2}/\d{2}/\d{4}$!', $date))
			{
				$db->rollback();
				throw new UserException('Erreur sur la ligne ' . $line . ' : la date n\'est pas au format jj/mm/aaaa.');
			}

			$date = explode('/', $date);
			$date = $date[2] . '-' . $date[1] . '-' . $date[0];

			if ($db->simpleQuerySingle('SELECT 1 FROM compta_exercices
377
378
379
380
381
382
383
384
385
386
387
388
389
				$data['numero_cheque']	=	$col('Numéro de chèque');
				$data['id_categorie']	=	$liste_cats[$cat];
			}

			$journal->add($data);
		}

		$db->exec('END;');

		fclose($fp);
		return true;
	}
}







|





377
378
379
380
381
382
383
384
385
386
387
388
389
				$data['numero_cheque']	=	$col('Numéro de chèque');
				$data['id_categorie']	=	$liste_cats[$cat];
			}

			$journal->add($data);
		}

		$db->commit();

		fclose($fp);
		return true;
	}
}