Commit 375b289b authored by Okhin's avatar Okhin

Ajout du fichier de m pour les contreparties

parent ee7e45c1
...@@ -4,12 +4,14 @@ namespace Controller; ...@@ -4,12 +4,14 @@ namespace Controller;
use LQDN\Command\AdminCreateCommand; use LQDN\Command\AdminCreateCommand;
use LQDN\Command\AdminDeleteCommand; use LQDN\Command\AdminDeleteCommand;
use LQDN\Command\AdminChangePasswordCommand; use LQDN\Command\AdminChangePasswordCommand;
use LQDN\Command\CounterpartCreateCommand;
use LQDN\Command\DonationValidateCommand; use LQDN\Command\DonationValidateCommand;
use LQDN\Command\DonationInvalidateCommand; use LQDN\Command\DonationInvalidateCommand;
use LQDN\Command\DonationResetPdfCommand; use LQDN\Command\DonationResetPdfCommand;
use LQDN\Command\DonationCreateCommand; use LQDN\Command\DonationCreateCommand;
use LQDN\Command\UserUpdateByAdminCommand; use LQDN\Command\UserUpdateByAdminCommand;
use LQDN\Command\UserCreateCommand; use LQDN\Command\UserCreateCommand;
use LQDN\Command\UserUpdateCumulCommand;
use LQDN\Command\AdminUpdateTotalUsersCommand; use LQDN\Command\AdminUpdateTotalUsersCommand;
class Admin extends Controller class Admin extends Controller
...@@ -49,6 +51,7 @@ class Admin extends Controller ...@@ -49,6 +51,7 @@ class Admin extends Controller
)); ));
$f3->set('TAILLES', array( $f3->set('TAILLES', array(
0 => _('PlaceHolder -- ne pas utiliser') . ' S',
1 => _('Coupe Homme, Taille') . ' S', 1 => _('Coupe Homme, Taille') . ' S',
2 => _('Coupe Homme, Taille') . ' M', 2 => _('Coupe Homme, Taille') . ' M',
3 => _('Coupe Homme, Taille') . ' L', 3 => _('Coupe Homme, Taille') . ' L',
...@@ -378,6 +381,78 @@ class Admin extends Controller ...@@ -378,6 +381,78 @@ class Admin extends Controller
public function counterparts_dashboard($f3, $args) public function counterparts_dashboard($f3, $args)
{ {
$db = $f3->get('DB'); $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 // On définit des valeurs par défaut
$query = "SELECT DISTINCT quoi FROM contreparties;"; $query = "SELECT DISTINCT quoi FROM contreparties;";
$result = $db->query($query); $result = $db->query($query);
......
...@@ -29,7 +29,7 @@ GET @edit_support:/admin/support/edit/@id=Controller\Admin->support ...@@ -29,7 +29,7 @@ GET @edit_support:/admin/support/edit/@id=Controller\Admin->support
POST @modify_support:/admin/support/edit=Controller\Admin->support POST @modify_support:/admin/support/edit=Controller\Admin->support
GET @invalidate_support:/admin/support/invalidate/@id=Controller\Admin->invalidate GET @invalidate_support:/admin/support/invalidate/@id=Controller\Admin->invalidate
GET @validate_support:/admin/support/validate/@id=Controller\Admin->validate 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 GET|POST @admin_accounts:/admin/accounts=Controller\Admin->accounts
...@@ -47,7 +47,7 @@ POST @modify_user:/admin/users/@id=Controller\Admin->user ...@@ -47,7 +47,7 @@ POST @modify_user:/admin/users/@id=Controller\Admin->user
POST @adresse:/admin/adresses=Controller\Admin->adresse 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 GET|POST @banque:/admin/banque=Controller\Admin->banque
......
<section> <section>
<h2>Import des contreparties depuis un fichier csv</h2>
<p>Veuillez préparer un fichier csv du format : Mail;quoi;</p>
<form enctype="multipart/form-data" method=POST action="{{ 'counterparts_dashboard' | alias}}">
<input type="hidden" id="csrf" name="csrf" value="{{ @CSRF }}" />
<input type="file" id="file" name="file">
<br />
<input type="submit" value="Pousser le fichier">
</form>
{{ var_dump(@counterparts_import) }}
<message messages="{{@SESSION.error}}" class="alert alert-danger" />
</form>
</section>
<h2>Tableau de bord des contreparties</h2> <h2>Tableau de bord des contreparties</h2>
<table cellspacing="0" cellpadding="0"> <table cellspacing="0" cellpadding="0">
<theader> <theader>
...@@ -19,8 +31,8 @@ ...@@ -19,8 +31,8 @@
</tr> </tr>
<tr> <tr>
<td>Hoodies</td> <td>Hoodies</td>
<td style="text-align:right;"><b>{{ @hoodie_s1 }}</b></td> <td style="text-align:right;"><b>{{ @hoopie_s1 }}</b></td>
<td style="text-align:right;">{{ @hoodie_s2 }}</td> <td style="text-align:right;">{{ @hoopie_s2 }}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
......
...@@ -33,6 +33,24 @@ class CounterpartSeeder extends AbstractSeed ...@@ -33,6 +33,24 @@ class CounterpartSeeder extends AbstractSeed
'status' => 2, 'status' => 2,
'adresse_id' => null, 'adresse_id' => null,
), ),
array(
'id' => 3,
'datec' => '2016-06-22 12:34',
'user_id' => 2,
'quoi' => 'pibag', // [piplome|pibag|pishirt|hoodie]
'taille' => 2,
'status' => 2,
'adresse_id' => null,
),
array(
'id' => 4,
'datec' => '2016-06-22 12:34',
'user_id' => 2,
'quoi' => 'hoopie', // [piplome|pibag|pishirt|hoodie]
'taille' => 2,
'status' => 2,
'adresse_id' => null,
),
); );
$this->table('contreparties')->insert($data)->save(); $this->table('contreparties')->insert($data)->save();
......
...@@ -9,7 +9,7 @@ class CounterpartFinderTest extends FunctionalTest ...@@ -9,7 +9,7 @@ class CounterpartFinderTest extends FunctionalTest
public function testFindByUserId() public function testFindByUserId()
{ {
$counterparts = $this->container['counterpart_finder']->findByUserId(2); $counterparts = $this->container['counterpart_finder']->findByUserId(2);
$this->assertCount(1, $counterparts); $this->assertCount(3, $counterparts);
$firstCounterpart = reset($counterparts); $firstCounterpart = reset($counterparts);
......
...@@ -19,7 +19,7 @@ class CounterpartHandlerTest extends FunctionalTest ...@@ -19,7 +19,7 @@ class CounterpartHandlerTest extends FunctionalTest
public function testCounterpartCreate() public function testCounterpartCreate()
{ {
$this->assertFalse($this->counterpartExists(3)); $this->assertFalse($this->counterpartExists(5));
$this->container['command_handler']->handle(new CounterpartCreateCommand(1, 1, 'pishirt', 4, 1, date("Y-m-d H:i:s"), '')); $this->container['command_handler']->handle(new CounterpartCreateCommand(1, 1, 'pishirt', 4, 1, date("Y-m-d H:i:s"), ''));
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment