Commit 67bf68ce authored by okhin's avatar okhin 🚴

Fixing the CSV imports

parent d7f61fc3
Pipeline #2254 failed with stages
in 1 minute and 24 seconds
......@@ -7,6 +7,7 @@ use LQDN\Command\AdminChangePasswordCommand;
use LQDN\Command\DonationValidateCommand;
use LQDN\Command\DonationInvalidateCommand;
use LQDN\Command\DonationResetPdfCommand;
use LQDN\Command\DonationCreateCommand;
use LQDN\Command\UserUpdateByAdminCommand;
class Admin extends Controller
......@@ -486,7 +487,7 @@ class Admin extends Controller
WHEN 'hoodie' THEN 8
END
)=$quoi)
";
";
}
if ($status) {
$query .= " AND c.status IN (".\Utils::asl($status).") ";
......@@ -1243,7 +1244,7 @@ class Admin extends Controller
if ($result->rowCount() == 0) {
// Identifier does not exist, we must create it. We have either a pseudo or an email.
$user_field = explode("_", $identifier)[1];
$user = 'asfhjk';
$user = '';
if (strpos($user_field, '@')) {
// identifier is an email
......@@ -1271,18 +1272,36 @@ class Admin extends Controller
} else {
$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
$result = $db->query("SELECT d.id AS id
$stmt = $db->query("SELECT d.id AS id
FROM dons d
JOIN users u ON u.id = d.user_id
WHERE u.email='".$email. "'
WHERE u.email='".$email."'
AND d.status=101
AND d.id='".$transaction."' ");
print_r($result);
if ($result->rowCount() > 0) {
AND d.id=".$transaction);
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
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['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)
FROM dons d
JOIN users u ON u.id = d.user_id
......@@ -1296,9 +1315,6 @@ class Admin extends Controller
if ($combien[0]==0) {
$update ++;
// 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,
datec,
somme,
......@@ -1309,7 +1325,7 @@ class Admin extends Controller
102,
'".$new_effect."',
".$amount.",
'".$user_id."',
'".$user['id']."',
'".$cumul."',
'".$identifier."')";
if (!$testing) {
......@@ -1318,16 +1334,12 @@ class Admin extends Controller
$result = $db->query("UPDATE users
SET cumul=cumul+".$amount.",
total=total+".$amount."
WHERE id='".$user_id."'");
WHERE id='".$user['id']."'");
}
} else {
$comptabilise[] = $identifier;
}
}
} else {
$sans_cumul[] = $email;
}
}
}
}
fclose($handle);
......@@ -1339,6 +1351,7 @@ class Admin extends Controller
return $datas;
}
public function stats($f3, $args)
{
$startingDay = new \DateTime('2014-11-12');
......
......@@ -32,6 +32,24 @@ class DonationFinder
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.
*
......
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