diff --git a/app/controller/admin.php b/app/controller/admin.php
index 1eb7be1e94ecc484a5b05b51d28f359f65cc230a..d79b7a8c43875670fe15de2faa7e2ee4f901089c 100644
--- a/app/controller/admin.php
+++ b/app/controller/admin.php
@@ -4,12 +4,14 @@ namespace Controller;
use LQDN\Command\AdminCreateCommand;
use LQDN\Command\AdminDeleteCommand;
use LQDN\Command\AdminChangePasswordCommand;
+use LQDN\Command\CounterpartCreateCommand;
use LQDN\Command\DonationValidateCommand;
use LQDN\Command\DonationInvalidateCommand;
use LQDN\Command\DonationResetPdfCommand;
use LQDN\Command\DonationCreateCommand;
use LQDN\Command\UserUpdateByAdminCommand;
use LQDN\Command\UserCreateCommand;
+use LQDN\Command\UserUpdateCumulCommand;
use LQDN\Command\AdminUpdateTotalUsersCommand;
class Admin extends Controller
@@ -49,6 +51,7 @@ class Admin extends Controller
));
$f3->set('TAILLES', array(
+ 0 => _('PlaceHolder -- ne pas utiliser') . ' S',
1 => _('Coupe Homme, Taille') . ' S',
2 => _('Coupe Homme, Taille') . ' M',
3 => _('Coupe Homme, Taille') . ' L',
@@ -378,6 +381,78 @@ class Admin extends Controller
public function counterparts_dashboard($f3, $args)
{
$db = $f3->get('DB');
+ $f3->set('counterparts_import', '');
+ $total = array("hoopie" => 0, "pishirt" => 0, "pibag" => 0, "piplome" => 0);
+
+
+ if ($f3->get('VERB') == 'POST') {
+ $separator = ';';
+ // Si on a un POST sur cette page, c'est que l'on a un csv à parser
+ if ($_FILES['file']['tmp_name'] == '') {
+ $f3->push('SESSION.error', 'Veuillez uploader un fichier au format csv');
+ } else {
+ // Lecture du fichier
+ if (($handle = fopen($_FILES['file']['tmp_name'], "r")) !== false) {
+ // D'abord le header : email / quoi
+ $fields = fgetcsv($handle, 1000, $separator);
+ $mail_idx = -1;
+ $quoi_idx = -1;
+ foreach ($fields as $key => $value) {
+ if ($value == "Quoi") {
+ $quoi_idx = $key;
+ }
+ if ($value == "Mail") {
+ $mail_idx = $key;
+ }
+ }
+
+ // On tourne sur le fichier maintenant
+ while (($data = fgetcsv($handle, 1000, $separator)) !== false) {
+ // Récupération des données
+ $mail = $data[$mail_idx];
+ $quoi = $data[$quoi_idx];
+
+ // On cherche l'utilisateur
+ $user = $f3->get('container')['user_finder']->findByEmail($mail);
+ // Et son addresse
+ $adresse = $f3->get('container')['address_finder']->findByUserId($user['id']);
+
+ if (count($user) >= 1 and is_array($user)) {
+ // On a un utilisateur, cool
+ // On crée une contrepartie, si son cumul est suffisant
+ switch ($quoi) {
+ case 'hoodie':
+ $needed = 250;
+ break;
+ case 'pishirt':
+ $needed = 100;
+ break;
+ case 'pibag':
+ $needed = 50;
+ break;
+ case 'piplome':
+ $needed = 30;
+ break;
+ }
+ if ($user['cumul'] >= $needed) {
+ // Assez de point, on crée
+ $f3->get('container')['command_handler']->handle(new CounterpartCreateCommand($adresse['id'], $user['id'], $quoi, 1, 2, date("Y-m-d H:i:s"), 'Imported from a file'));
+ // On mets à jour le cumul de l'utilisateur
+ $f3->get('container')['command_handler']->handle(new UserUpdateCumulCommand($user['id'], $user['cumul'] - $needed));
+ $total[$quoi] +=1;
+ } else {
+ $f3->push('SESSION.error', 'Pas assez de cumul pour un '.$quoi.' avec l\'email'.$mail);
+ }
+ } else {
+ $f3->push('SESSION.error', 'Pas d\'utilisateur avec l\'adresse '.$mail);
+ }
+ }
+ fclose($handle);
+ }
+ } // Fin de l'import CSV
+ $f3->set('counterparts_import', $total);
+ }
+
// On définit des valeurs par défaut
$query = "SELECT DISTINCT quoi FROM contreparties;";
$result = $db->query($query);
diff --git a/app/routes.ini b/app/routes.ini
index 7c235112e4f5ab58ac2353165089793ad7ae96d0..b774eb111176d64e2aab63a8e8c13a423e2228d0 100644
--- a/app/routes.ini
+++ b/app/routes.ini
@@ -29,7 +29,7 @@ GET @edit_support:/admin/support/edit/@id=Controller\Admin->support
POST @modify_support:/admin/support/edit=Controller\Admin->support
GET @invalidate_support:/admin/support/invalidate/@id=Controller\Admin->invalidate
GET @validate_support:/admin/support/validate/@id=Controller\Admin->validate
-GET @recompute:/admin/recompute=Controlle\Admin->recompute
+GET @recompute:/admin/recompute=Controller\Admin->recompute
GET|POST @admin_accounts:/admin/accounts=Controller\Admin->accounts
@@ -47,7 +47,7 @@ POST @modify_user:/admin/users/@id=Controller\Admin->user
POST @adresse:/admin/adresses=Controller\Admin->adresse
-GET @counterparts_dashboard:/admin/counterparts_dashboard=Controller\Admin->counterparts_dashboard
+GET|POST @counterparts_dashboard:/admin/counterparts_dashboard=Controller\Admin->counterparts_dashboard
GET|POST @banque:/admin/banque=Controller\Admin->banque
diff --git a/app/view/backend/contreparties_tableau.html b/app/view/backend/contreparties_tableau.html
index 80e624bfdc62e8ea05f683718e74eb96bc168d06..8f71355a1fd90dfba7e78e35a02007ed37ea1cbf 100644
--- a/app/view/backend/contreparties_tableau.html
+++ b/app/view/backend/contreparties_tableau.html
@@ -1,4 +1,16 @@
Veuillez préparer un fichier csv du format : Mail;quoi;Import des contreparties depuis un fichier csv
+
Hoodies | -{{ @hoodie_s1 }} | -{{ @hoodie_s2 }} | +{{ @hoopie_s1 }} | +{{ @hoopie_s2 }} |