Commit 0bd6723e authored by okhin's avatar okhin 🚴

Merge branch '22-mise-a-jour-des-cumuls-de-dons-mensuels' into 'preprod'

Resolve "Mise à jour des cumuls de dons mensuels"

Closes #22

See merge request !19
parents e7c7ae18 b365c8ca
...@@ -7,6 +7,7 @@ use LQDN\Command\AdminChangePasswordCommand; ...@@ -7,6 +7,7 @@ use LQDN\Command\AdminChangePasswordCommand;
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\UserUpdateByAdminCommand; use LQDN\Command\UserUpdateByAdminCommand;
class Admin extends Controller class Admin extends Controller
...@@ -486,7 +487,7 @@ class Admin extends Controller ...@@ -486,7 +487,7 @@ class Admin extends Controller
WHEN 'hoodie' THEN 8 WHEN 'hoodie' THEN 8
END END
)=$quoi) )=$quoi)
"; ";
} }
if ($status) { if ($status) {
$query .= " AND c.status IN (".\Utils::asl($status).") "; $query .= " AND c.status IN (".\Utils::asl($status).") ";
...@@ -1243,7 +1244,7 @@ class Admin extends Controller ...@@ -1243,7 +1244,7 @@ class Admin extends Controller
if ($result->rowCount() == 0) { if ($result->rowCount() == 0) {
// Identifier does not exist, we must create it. We have either a pseudo or an email. // Identifier does not exist, we must create it. We have either a pseudo or an email.
$user_field = explode("_", $identifier)[1]; $user_field = explode("_", $identifier)[1];
$user = 'asfhjk'; $user = '';
if (strpos($user_field, '@')) { if (strpos($user_field, '@')) {
// identifier is an email // identifier is an email
...@@ -1271,18 +1272,36 @@ class Admin extends Controller ...@@ -1271,18 +1272,36 @@ class Admin extends Controller
} else { } else {
$emails[$email] = 1; $emails[$email] = 1;
} }
// On a besoin de l'utilisateur
$user = $f3->get('container')['user_finder']->findByEmail($email);
// Récupération de l'id du bon abonnement // Récupération de l'id du bon abonnement
$result = $db->query("SELECT d.id AS id $stmt = $db->query("SELECT d.id AS id
FROM dons d FROM dons d
JOIN users u ON u.id = d.user_id JOIN users u ON u.id = d.user_id
WHERE u.email='".$email. "' WHERE u.email='".$email."'
AND d.status=101 AND d.status=101
AND d.id='".$transaction."' "); AND d.id=".$transaction);
print_r($result); $result = $stmt->fetch(\PDO::FETCH_ASSOC);
if ($result->rowCount() > 0) { if (!$result) {
// don non trouvé en statut 101. On le crée (la banque à raison)
// statut = cumul
$f3->get('container')['command_handler']
->handle(new DonationCreateCommand(
$user['id'],
101,
$new_effect,
$amount,
0,
0
));
// Et on le récupère
$cumul = $db->lastInsertId();
$don = $f3->get('container')['donation_finder']->findById($cumul);
} else {
$cumul = $result->fetch(\PDO::FETCH_ASSOC); $cumul = $result->fetch(\PDO::FETCH_ASSOC);
$cumul = $result['id']; $cumul = $result['id'];
if ($cumul!='') { }
// On regarde si le don n'as pas déjà été ajouté (en vérifiant la datec)
$result = $db->query("SELECT COUNT(1) $result = $db->query("SELECT COUNT(1)
FROM dons d FROM dons d
JOIN users u ON u.id = d.user_id JOIN users u ON u.id = d.user_id
...@@ -1296,9 +1315,6 @@ class Admin extends Controller ...@@ -1296,9 +1315,6 @@ class Admin extends Controller
if ($combien[0]==0) { if ($combien[0]==0) {
$update ++; $update ++;
// Don récurrent non comptabilisé, on l'ajoute // Don récurrent non comptabilisé, on l'ajoute
$user_id = $db->query("SELECT id FROM users WHERE email='$email'");
$user_id = $user_id->fetch(\PDO::FETCH_ASSOC);
$user_id = $user_id['id'];
$query = "INSERT INTO dons (status, $query = "INSERT INTO dons (status,
datec, datec,
somme, somme,
...@@ -1309,7 +1325,7 @@ class Admin extends Controller ...@@ -1309,7 +1325,7 @@ class Admin extends Controller
102, 102,
'".$new_effect."', '".$new_effect."',
".$amount.", ".$amount.",
'".$user_id."', '".$user['id']."',
'".$cumul."', '".$cumul."',
'".$identifier."')"; '".$identifier."')";
if (!$testing) { if (!$testing) {
...@@ -1318,16 +1334,12 @@ class Admin extends Controller ...@@ -1318,16 +1334,12 @@ class Admin extends Controller
$result = $db->query("UPDATE users $result = $db->query("UPDATE users
SET cumul=cumul+".$amount.", SET cumul=cumul+".$amount.",
total=total+".$amount." total=total+".$amount."
WHERE id='".$user_id."'"); WHERE id='".$user['id']."'");
} }
} else { } else {
$comptabilise[] = $identifier; $comptabilise[] = $identifier;
} }
} }
} else {
$sans_cumul[] = $email;
}
}
} }
} }
fclose($handle); fclose($handle);
...@@ -1339,6 +1351,7 @@ class Admin extends Controller ...@@ -1339,6 +1351,7 @@ class Admin extends Controller
return $datas; return $datas;
} }
public function stats($f3, $args) public function stats($f3, $args)
{ {
$startingDay = new \DateTime('2014-11-12'); $startingDay = new \DateTime('2014-11-12');
......
...@@ -70,7 +70,7 @@ class DonationSeeder extends AbstractSeed ...@@ -70,7 +70,7 @@ class DonationSeeder extends AbstractSeed
array( array(
'id' => 3, 'id' => 3,
'status' => 100, 'status' => 100,
'datec' => '2016-06-10 12:34', 'datec' => '2016-06-11 12:34',
'somme' => 100, 'somme' => 100,
'lang' => 'fr_FR', 'lang' => 'fr_FR',
'cadeau' => 1, 'cadeau' => 1,
......
...@@ -32,6 +32,24 @@ class DonationFinder ...@@ -32,6 +32,24 @@ class DonationFinder
return $donations; return $donations;
} }
/**
* findById
*
* @param int $donationId
*
* @return []
*/
public function findById($donationId)
{
$donationId = (int) $donationId;
$donations = [];
$stmt = $this->connection->query("SELECT * FROM dons WHERE id='$donationId'");
while ($donation = $stmt->fetch()) {
$donations[$donationId] = $donation;
}
return $donations;
}
/** /**
* Return dons for admins. * Return dons for admins.
* *
...@@ -43,7 +61,7 @@ class DonationFinder ...@@ -43,7 +61,7 @@ class DonationFinder
* *
* @return array * @return array
*/ */
public function adminSearch($text, $sum, $public, $status, $limit = 50, $page = 1) public function adminSearch($text, $sum, $public, $status, $date1, $date2 = "2999-12-31 23:59:59", $limit = 50, $page = 1)
{ {
$query = <<<EOQ $query = <<<EOQ
SELECT d.id as id, SELECT d.id as id,
...@@ -61,7 +79,7 @@ SELECT d.id as id, ...@@ -61,7 +79,7 @@ SELECT d.id as id,
a.ville AS ville, a.ville AS ville,
a.pays AS pays a.pays AS pays
FROM dons d FROM dons d
JOIN users u ON u.id = d.user_id LEFT JOIN users u ON u.id = d.user_id
LEFT JOIN adresses a ON d.adresse_id = a.id LEFT JOIN adresses a ON d.adresse_id = a.id
WHERE 1=1 WHERE 1=1
EOQ; EOQ;
...@@ -87,6 +105,11 @@ EOQ; ...@@ -87,6 +105,11 @@ EOQ;
$params['status'] = $status; $params['status'] = $status;
} }
if ('' !== $date1) {
$query .= ' AND d.datec BETWEEN (:date1) AND (:date2) ';
$params['date1'] = $date1;
$params['date2'] = $date2;
}
$first = ($page - 1) * $limit; $first = ($page - 1) * $limit;
$last = ($page) * $limit; $last = ($page) * $limit;
$query .= " ORDER BY datec DESC LIMIT $first, $last"; $query .= " ORDER BY datec DESC LIMIT $first, $last";
......
...@@ -37,6 +37,18 @@ class UserFinder ...@@ -37,6 +37,18 @@ class UserFinder
return $this->connection->fetchAssoc("SELECT * FROM users WHERE email = :email", ['email' => $email]); return $this->connection->fetchAssoc("SELECT * FROM users WHERE email = :email", ['email' => $email]);
} }
/**
* findByPseudo
*
* @param mixed pseudo
*
* @return []
*/
public function findByPseudo($pseudo)
{
return $this->connection->fetchAssoc("SELECT * FROM users WHERE pseudo = :pseudo", ['pseudo' => $pseudo]);
}
/** /**
* The search from the admin. * The search from the admin.
* *
......
...@@ -43,10 +43,12 @@ class DonationFinderTest extends FunctionalTest ...@@ -43,10 +43,12 @@ class DonationFinderTest extends FunctionalTest
public function testAdminSearchDonations() public function testAdminSearchDonations()
{ {
$this->assertCount(1, $this->container['donation_finder']->adminSearch($text='alice@example.org', $sum='', $public='', $status='')); $this->assertCount(1, $this->container['donation_finder']->adminSearch($text='alice@example.org', $sum='', $public='', $status='', $date1=''));
$this->assertCount(2, $this->container['donation_finder']->adminSearch($text='', $sum='1000', $public='', $status='')); $this->assertCount(2, $this->container['donation_finder']->adminSearch($text='', $sum='1000', $public='', $status='', $date1=''));
$this->assertCount(2, $this->container['donation_finder']->adminSearch($text='', $sum='', $public='0', $status='')); $this->assertCount(2, $this->container['donation_finder']->adminSearch($text='', $sum='', $public='0', $status='', $date1=''));
$this->assertCount(2, $this->container['donation_finder']->adminSearch($text='', $sum='', $public='', $status='1')); $this->assertCount(2, $this->container['donation_finder']->adminSearch($text='', $sum='', $public='', $status='1', $date1=''));
$this->assertCount(2, $this->container['donation_finder']->adminSearch($text='', $sum='', $public='', $status='1', $date1=''));
$this->assertCount(1, $this->container['donation_finder']->adminSearch($text='', $sum='', $public='', $status='', $date1='2016-06-11 00:00:00'));
} }
} }
...@@ -42,6 +42,25 @@ class UserFinderTest extends FunctionalTest ...@@ -42,6 +42,25 @@ class UserFinderTest extends FunctionalTest
$this->assertEquals($expectedUser, $user); $this->assertEquals($expectedUser, $user);
} }
public function testFindByPseudo()
{
$user = $this->container['user_finder']->findByPseudo('Alice');
$expectedUser = [
'id' => '1',
'status' => '1',
'hash' => '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8',
'cumul' => '2000',
'email' => 'alice@example.org',
'total' => '5000',
'pseudo' => 'Alice',
'expiration' => null,
'commentaire' => 'RAS',
];
$this->assertEquals($expectedUser, $user);
}
public function testAdminSearch() public function testAdminSearch()
{ {
$this->assertCount(1, $this->container['user_finder']->adminSearch($text='alice@example.org', $status='')); $this->assertCount(1, $this->container['user_finder']->adminSearch($text='alice@example.org', $status=''));
......
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