Commit 0c5cf6c9 by Yvon Kerdoncuff

Merge branch '7923-presta-operation-export-by-caissier' into montpellier-preprod

parents 9c84fad2 d10d9f80
......@@ -4,6 +4,7 @@ namespace App\Admin;
use App\Entity\AccountPrestataire;
use App\Entity\Adherent;
use App\Entity\Caissier;
use App\Entity\ContactPrestataire;
use App\Entity\CotisationAdherent;
use App\Entity\CotisationPrestataire;
......@@ -179,6 +180,11 @@ class PrestataireAdmin extends AbstractAdmin
}
}
$existingCaissiers = $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(Caissier::class)->findBy(['prestataire' => $presta]);
$existingCaissiersUsers = array_map(function ($caissier) {
return $caissier->getUser();
}, $existingCaissiers);
$formMapper
->tab('Prestataire')
->with('Prestataire', ['class' => 'col-md-6'])
......@@ -333,11 +339,12 @@ class PrestataireAdmin extends AbstractAdmin
->end()
->with('Caissier(s)', ['class' => 'col-md-6'])
->add('caissiers', EntityType::class, [
// 'mapped' => false,
'class' => User::class,
'mapped' => false,
'class' => User::class, // instance of user so we can set existing users as choices
'multiple' => true,
'required' => false,
'label' => 'Associer à un(des) utilisateur(s) existant :',
'data' => $existingCaissiersUsers,
'choices' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(User::class)->findOrderByName(),
'choice_label' => function ($user) {
return $user->getLastname() . ' ' . $user->getFirstname() . ' (' . $user->getEmail() . ')';
......@@ -419,31 +426,58 @@ class PrestataireAdmin extends AbstractAdmin
// ))
$em = $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager();
$formMapper->getFormBuilder()->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
$formMapper->getFormBuilder()->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use ($existingCaissiers) {
$prestataire = $event->getData();
$users = null;
$em = $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager();
/*
Permet d'ajouter le nouvel utilisateur crée (newusers) aux gestionnaires du presta
Permet d'ajouter le nouvel utilisateur créé (newusers) aux gestionnaires du presta
(On crée un compte adhérent en même temps que le prestataire)
Ajoute et/ou supprime le(s) caissier(s)
*/
if (null != $event->getForm()->get('users')->getData()) {
$users = $event->getForm()->get('users')->getData();
$this->addUsersOrCaissers($users, $prestataire);
$this->addUsersOrCaissiers($users, $prestataire);
}
if (null != $event->getForm()->get('caissiers')->getData()) {
$caissiers = $event->getForm()->get('caissiers')->getData();
$this->addUsersOrCaissers($caissiers, $prestataire, 'ROLE_CAISSIER');
$caissiers = $event->getForm()->get('caissiers')->getData(); // instances of user here
$this->addUsersOrCaissiers($caissiers, $prestataire, 'ROLE_CAISSIER');
// Remove caissiers: get difference between existing caissier and caissiers set in field
$caissiersToRemove = [];
foreach ($existingCaissiers as $existingCaissier) {
$remove = true;
foreach ($caissiers as $caissierUser) {
if ($existingCaissier->getUser()->getId() === $caissierUser->getId()) {
$remove = false;
break;
}
}
if (true === $remove) {
// if user is only caissier for this prestataire and caissier is removed,
// remove role caissier for user
if (count($existingCaissier->getUser()->getCaissiers()) === 1) {
$groupeCaissier = $em->getRepository(Usergroup::class)->findOneByName('Caissier');
$existingCaissier->getUser()->removePossibleGroup($groupeCaissier);
}
// Remove caissier from prestataire
$prestataire->removeCaissier($existingCaissier);
}
}
}
if (null != $event->getForm()->get('newusers')->getData()) {
$newusers = $event->getForm()->get('newusers')->getData();
$return = $this->addUsersOrCaissers($newusers, $prestataire);
$return = $this->addUsersOrCaissiers($newusers, $prestataire);
if (false === $return) {
$event->getForm()->get('newusers')->addError(new FormError('Gestionnaires : Courriel(s) déjà utilisé : ' . implode(', ', $return) . '!'));
}
}
if (null != $event->getForm()->get('newcaissiers')->getData()) {
$newcaissiers = $event->getForm()->get('newcaissiers')->getData();
$return = $this->addUsersOrCaissers($newcaissiers, $prestataire, 'ROLE_CAISSIER');
$return = $this->addUsersOrCaissiers($newcaissiers, $prestataire, 'ROLE_CAISSIER');
if (count($return) > 0) {
$event->getForm()->get('newcaissiers')->addError(new FormError('Caissiers : Courriel(s) déjà utilisé : ' . implode(', ', $return) . '!'));
}
......@@ -452,7 +486,7 @@ class PrestataireAdmin extends AbstractAdmin
parent::configureFormFields($formMapper);
}
private function addUsersOrCaissers($users, Prestataire $prestataire, string $role = 'ROLE_PRESTATAIRE')
private function addUsersOrCaissiers($users, Prestataire $prestataire, string $role = 'ROLE_PRESTATAIRE')
{
$return = [];
$em = $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager();
......@@ -474,18 +508,27 @@ class PrestataireAdmin extends AbstractAdmin
}
if ('ROLE_PRESTATAIRE' == $role) {
$prestataire->addUser($user);
$groupePresta = $em->getRepository(Usergroup::class)->findOneByName('Prestataire');
if ($newUser) {
$this->eventDispatcher->dispatch(MLCEvents::REGISTRATION_PRESTATAIRE, new PrestataireEvent($user, $prestataire, $this->getRequest()));
}
$groupePresta = $em->getRepository(Usergroup::class)->findOneByName('Prestataire');
$user->addPossiblegroup($groupePresta);
} elseif ('ROLE_CAISSIER' == $role) {
$prestataire->addCaissier($user);
$groupePresta = $em->getRepository(Usergroup::class)->findOneByName('Caissier');
$caissier = $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(Caissier::class)->findOneBy(['prestataire' => $prestataire, 'user' => $user]);
if (null === $caissier) {
$caissier = new Caissier();
$caissier->setUser($user);
$caissier->setPrestataire($prestataire);
$em->persist($caissier);
}
$prestataire->addCaissier($caissier);
if ($newUser) {
$this->eventDispatcher->dispatch(MLCEvents::REGISTRATION_CAISSIER, new PrestataireEvent($user, $prestataire, $this->getRequest()));
}
$groupeCaissier = $em->getRepository(Usergroup::class)->findOneByName('Caissier');
$user->addPossiblegroup($groupeCaissier);
}
$user->addPossiblegroup($groupePresta);
$this->userManager->updateCanonicalFields($user);
$em->persist($user);
if ($newUser) {
......
......@@ -6,6 +6,7 @@ use App\Entity\AccountComptoir;
use App\Entity\AccountGroupe;
use App\Entity\AccountPrestataire;
use App\Entity\AccountSiege;
use App\Entity\Caissier;
use App\Entity\Comptoir;
use App\Entity\Geoloc;
use App\Entity\GeolocPrestataire;
......@@ -696,11 +697,12 @@ class IndexController extends AbstractController
public function prestaChoiceAction(Usergroup $group, Prestataire $prestataire, Request $request)
{
$this->em->refresh($this->getUser());
if (!(($this->getUser()->getPossiblegroups()->exists(function ($key, $value) {
return in_array('ROLE_PRESTATAIRE', $value->getRoles());
}) and $this->getUser()->getPrestataires()->contains($prestataire)) || (($this->getUser()->getPossiblegroups()->exists(function ($key, $value) {
return in_array('ROLE_CAISSIER', $value->getRoles());
}) and $this->getUser()->getCaissiers()->contains($prestataire))))
// prevent operation if user isn't a prestataire
if (
!($this->getUser()->getPossiblegroups()->exists(function ($key, $value) {
return in_array('ROLE_PRESTATAIRE', $value->getRoles());
}) and $this->getUser()->getPrestataires()->contains($prestataire))
) {
$this->addFlash(
'error',
......@@ -717,6 +719,39 @@ class IndexController extends AbstractController
return $this->redirectToRoute('index');
}
/**
* Choix du presta géré.
*
* @Route("/login/caissier/choice/{usergrpid}/{caissierid}", name="caissier_choice")
* @ParamConverter("group", class="App:Usergroup", options={"mapping": {"usergrpid": "id"}})
* @ParamConverter("caissier", class="App:Caissier", options={"mapping": {"caissierid": "id"}})
* @IsGranted("ROLE_USER")
*/
public function caissierChoiceAction(Usergroup $group, Caissier $caissier, Request $request)
{
$this->em->refresh($this->getUser());
// prevent operation if user isn't a caissier
if (
!($this->getUser()->getPossiblegroups()->exists(function ($key, $value) {
return in_array('ROLE_CAISSIER', $value->getRoles());
}) and $this->getUser()->getCaissiers()->contains($caissier))
) {
$this->addFlash(
'error',
'Accès impossible !'
);
return $this->redirectToRoute('index');
}
$this->removeOldSessionParams();
// On enregistre le presta choisit en session
$this->session->set('_prestagere', $caissier->getPrestataire());
$this->reloadUserTokenFromGroup($group, $request);
return $this->redirectToRoute('index');
}
/**
* @Route("/login/group/choice/{id}", name="usergroup_choice")
* @IsGranted("ROLE_USER")
......
......@@ -2,6 +2,7 @@
namespace App\Controller;
use App\Entity\Caissier;
use App\Entity\Groupe;
use App\Entity\Prestataire;
use App\Entity\Rubrique;
......@@ -16,18 +17,21 @@ use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Security;
class PrestatairesController extends FrontController
{
protected $em;
private $router;
private $session;
private $security;
public function __construct(EntityManagerInterface $em, RouterInterface $router, SessionInterface $session)
public function __construct(EntityManagerInterface $em, RouterInterface $router, SessionInterface $session, Security $security)
{
$this->em = $em;
$this->router = $router;
$this->session = $session;
$this->security = $security;
}
/**
......@@ -165,45 +169,53 @@ class PrestatairesController extends FrontController
}
/**
* Get the total transactions amount towards the Prestataire since the last time it was fetched.
* Exclude Reconversions from calculation.
* Get the total transactions amount towards the Prestataire operated by the connected Caissier,
* since the last time it was fetched.
*
* @Route("/prestataires/get_last_transactions", name="get_presta_last_transactions")
* @IsGranted({"ROLE_CAISSIER", "ROLE_PRESTATAIRE"})
* @Route("/prestataires/get_caissier_last_transactions", name="get_caissier_last_transactions")
* @IsGranted({"ROLE_CAISSIER"})
*/
public function getLastTransactionsAmount()
public function getLastCaissierTransactionsAmount()
{
if (!$this->session->has('_prestagere')) {
return null;
}
// Get last export datetime (presta creation if first export)
$user = $this->security->getUser();
$presta = $this->em->getRepository(Prestataire::class)->findOneById($this->session->get('_prestagere')->getId());
$caissier = $this->em->getRepository(Caissier::class)->findOneBy(['prestataire' => $presta, 'user' => $user]);
$datetime_last_export = $presta->getLastTransactionsExportDatetime();
// Get last caissier export datetime
$datetime_last_export = $caissier->getLastTransactionsExportDatetime();
if (null == $datetime_last_export) {
$datetime_last_export = $presta->getCreatedAt();
// for transition purposes from Prestataire level export towards Caissier level export,
// get prestataire last export if caissier export date is not yet set
$datetime_last_export = $caissier->getLastTransactionsExportDatetime();
if (null == $datetime_last_export) {
// prestaire creation if first export
$datetime_last_export = $presta->getCreatedAt();
}
}
// Get total amount
$flux = $this->em->getRepository(Flux::class)->getQueryByPrestataire(
$this->session->get('_prestagere'),
null,
null,
// Get total amount of transactions operated by connecteed Caissier for this Prestataire
$flux = $this->em->getRepository(Flux::class)->getQueryByCaissier(
$user,
$presta,
$datetime_last_export->format(("Y-m-d H:i:s"))
)->getResult();
$total_amount = 0;
foreach ($flux as $flux_item) {
// Exclude reconversions from calculation
// Exclude reconversions from calculation (extra security but probably unecessary, as reconversions don't have an operator)
if ($flux_item->getType() != "reconversion_prestataire") {
$total_amount += $flux_item->getMontant();
}
}
// Set now as this presta last export date
$presta->setLastTransactionsExportDatetime(new \Datetime('now'));
$this->em->persist($presta);
// Set now as this caissier last export datetime
$caissier->setLastTransactionsExportDatetime(new \Datetime('now'));
$this->em->persist($caissier);
$this->em->flush();
$str_datetime = $datetime_last_export->format('d/m/Y H\hi');
......
......@@ -4,6 +4,7 @@ namespace App\Controller;
use App\Entity\AchatMonnaieAConfirmerPrestataire;
use App\Entity\AchatMonnaiePrestataire;
use App\Entity\Caissier;
use App\Entity\GlobalParameter;
use App\Entity\Payment;
use App\Entity\Prestataire;
......@@ -75,12 +76,17 @@ class UserPrestataireController extends FluxController
$this->translator->trans($errorText)
);
} else {
// Remove caissier(s) if delete from the field
// Remove caissier(s) if deleted from the field
foreach ($originalCaissiers as $oldCaissier) {
if (!in_array($oldCaissier->getEmail(), $caissiers)) {
$groupePresta = $this->em->getRepository(Usergroup::class)->findOneByName('Caissier');
$oldCaissier->removePossibleGroup($groupePresta);
$this->em->persist($oldCaissier);
if (!in_array($oldCaissier->getUser()->getEmail(), $caissiers)) {
// if user is only caissier for this prestataire and caissier is removed,
// remove role caissier for user
if (count($oldCaissier->getUser()->getCaissiers()) === 1) {
$groupeCaissier = $this->em->getRepository(Usergroup::class)->findOneByName('Caissier');
$oldCaissier->getUser()->removePossibleGroup($groupeCaissier);
$this->em->persist($oldCaissier->getUser());
}
$form->getData()->getCaissiers()->removeElement($oldCaissier);
}
}
......@@ -134,12 +140,19 @@ class UserPrestataireController extends FluxController
$user->setEmail($email);
$user->setUsername($email);
}
$prestataire->addCaissier($user);
$groupePresta = $this->em->getRepository(Usergroup::class)->findOneByName('Caissier');
$caissier = $this->em->getRepository(Caissier::class)->findOneBy(['prestataire' => $prestataire, 'user' => $user]);
if (null === $caissier) {
$caissier = new Caissier();
$caissier->setUser($user);
$caissier->setPrestataire($prestataire);
$this->em->persist($caissier);
}
$prestataire->addCaissier($caissier);
$groupeCaissier = $this->em->getRepository(Usergroup::class)->findOneByName('Caissier');
if ($newUser) {
$this->eventDispatcher->dispatch(MLCEvents::REGISTRATION_CAISSIER, new PrestataireEvent($user, $prestataire, $request));
}
$user->addPossiblegroup($groupePresta);
$user->addPossiblegroup($groupeCaissier);
$this->userManager->updateCanonicalFields($user);
$this->em->persist($user);
if ($newUser) {
......
<?php
namespace App\Entity;
use App\Repository\CaissierRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=CaissierRepository::class)
*/
class Caissier
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="caissiers")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity=Prestataire::class, inversedBy="caissiers")
* @ORM\JoinColumn(nullable=false)
*/
private $prestataire;
/**
* Caissiers can export all the transactions since the last export.
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastTransactionsExportDatetime;
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getPrestataire(): ?Prestataire
{
return $this->prestataire;
}
public function setPrestataire(?Prestataire $prestataire): self
{
$this->prestataire = $prestataire;
return $this;
}
public function getLastTransactionsExportDatetime(): ?\DateTimeInterface
{
return $this->lastTransactionsExportDatetime;
}
public function setLastTransactionsExportDatetime(?\DateTimeInterface $lastTransactionsExportDatetime): self
{
$this->lastTransactionsExportDatetime = $lastTransactionsExportDatetime;
return $this;
}
public function __toString()
{
return $this->getUser()->__toString();
}
}
......@@ -291,16 +291,9 @@ class Prestataire extends AccountableObject implements AccountableInterface
protected $users;
/**
* @var ArrayCollection|User[]
*
* @ORM\ManyToMany(targetEntity="User", inversedBy="caissiers", cascade={"persist"})
* @ORM\JoinTable(name="user_caissier",
* joinColumns={@ORM\JoinColumn(name="prestataire_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}
* )
* @Groups({"read", "write"})
* @ORM\OneToMany(targetEntity=Caissier::class, mappedBy="prestataire", orphanRemoval=true)
*/
protected $caissiers;
private $caissiers;
/**
* @var Groupe
......@@ -359,7 +352,9 @@ class Prestataire extends AccountableObject implements AccountableInterface
private $comments;
/**
* Caissiers can export all the transactions since the last export.
* [UNUSED]
* This field has been moved to the Caissier entity.
* This field is kept for transitions purposes only and isn't updated anymore.
*
* @ORM\Column(type="datetime", nullable=true)
*/
......@@ -794,9 +789,9 @@ class Prestataire extends AccountableObject implements AccountableInterface
}
/**
* @return ArrayCollection[]|User
* @return Collection<int, Caissier>
*/
public function getCaissiers()
public function getCaissiers(): Collection
{
return $this->caissiers;
}
......@@ -872,31 +867,23 @@ class Prestataire extends AccountableObject implements AccountableInterface
return $this;
}
/**
* @param User $caissier
*
* @return $this
*/
public function addCaissier(User $caissier): self
public function addCaissier(Caissier $caissier): self
{
if (!$this->caissiers->contains($caissier)) {
$this->caissiers[] = $caissier;
$caissier->addCaissier($this);
$caissier->setPrestataire($this);
}
return $this;
}
/**
* @param User $caissier
*
* @return $this
*/
public function removeCaissier(User $caissier)
public function removeCaissier(Caissier $caissier): self
{
if ($this->caissiers->contains($caissier)) {
$this->caissiers->removeElement($caissier);
$caissier->removeCaissier($this);
if ($this->caissiers->removeElement($caissier)) {
// set the owning side to null (unless already changed)
if ($caissier->getPrestataire() === $this) {
$caissier->setPrestataire(null);
}
}
return $this;
......
......@@ -126,9 +126,9 @@ class User extends BaseUser
protected $prestataires;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Prestataire", mappedBy="caissiers", cascade={"persist"}, fetch="EAGER")
* @ORM\OneToMany(targetEntity=Caissier::class, mappedBy="user", orphanRemoval=true)
*/
protected $caissiers;
private $caissiers;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Groupe", mappedBy="gestionnaires", cascade={"persist"}, fetch="EAGER")
......@@ -418,48 +418,35 @@ class User extends BaseUser
}
/**
* Get caissiers.
*
* @return
* @return Collection<int, Caissier>
*/
public function getCaissiers()
public function getCaissiers(): Collection
{
return $this->caissiers;
}
/**
* @param Prestataire $caissier
*
* @return $this
*/
public function addCaissier(Prestataire $caissier): self
public function addCaissier(Caissier $caissier): self
{
if (!$this->caissiers->contains($caissier)) {
$this->caissiers[] = $caissier;
$caissier->setUser($this);
}
return $this;
}
/**
* @param Prestataire $caissier
*
* @return $this
*/
public function removeCaissier(Prestataire $caissier): self
public function removeCaissier(Caissier $caissier): self
{
if ($this->caissiers->contains($caissier)) {
$this->caissiers->removeElement($caissier);
if ($this->caissiers->removeElement($caissier)) {
// set the owning side to null (unless already changed)
if ($caissier->getUser() === $this) {
$caissier->setUser(null);
}
}
return $this;
}
/**
* Set caissier.
*
* @return $this
*/
public function setCaissiers($caissiers): self
{
$this->caissiers = $caissiers;
......
......@@ -38,7 +38,7 @@ class LoginListener
if (in_array('ROLE_PRESTATAIRE', $groupe->getRoles()) && count($user->getPrestataires()) >= 1) {
$this->session->set('_prestagere', $user->getPrestataires()[0]);
} elseif (in_array('ROLE_CAISSIER', $groupe->getRoles()) && count($user->getCaissiers()) >= 1) {
$this->session->set('_prestagere', $user->getCaissiers()[0]);
$this->session->set('_prestagere', $user->getCaissiers()[0]->getPrestataire());
} elseif (in_array('ROLE_COMPTOIR', $groupe->getRoles()) && count($user->getComptoirsGeres()) >= 1) {
$this->session->set('_comptoirgere', $user->getComptoirsGeres()[0]);
} elseif ((in_array('ROLE_TRESORIER', $groupe->getRoles()) || in_array('ROLE_CONTACT', $groupe->getRoles()) || in_array('ROLE_GESTION_GROUPE', $groupe->getRoles())) && count($user->getGroupesGeres()) >= 1) {
......
......@@ -103,7 +103,7 @@ class SwitchUserSubscriber implements EventSubscriberInterface
if (in_array('ROLE_PRESTATAIRE', $groupe->getRoles()) && count($user->getPrestataires()) >= 1) {
$this->session->set('_prestagere', $user->getPrestataires()[0]);
} elseif (in_array('ROLE_CAISSIER', $groupe->getRoles()) && count($user->getCaissiers()) >= 1) {
$this->session->set('_prestagere', $user->getCaissiers()[0]);
$this->session->set('_prestagere', $user->getCaissiers()[0]->getPrestataire());
} elseif (in_array('ROLE_COMPTOIR', $groupe->getRoles()) && count($user->getComptoirsGeres()) >= 1) {
$this->session->set('_comptoirgere', $user->getComptoirsGeres()[0]);
} elseif ((in_array('ROLE_TRESORIER', $groupe->getRoles()) || in_array('ROLE_CONTACT', $groupe->getRoles()) || in_array('ROLE_GESTION_GROUPE', $groupe->getRoles())) && count($user->getGroupesGeres()) >= 1) {
......
......@@ -45,7 +45,7 @@ class PrestataireInfosFormType extends AbstractType
if ('' !== $caissiers) {
$caissiers .= ';';
}
$caissiers .= $caissier->getEmail();
$caissiers .= $caissier->getUser()->getEmail();
}
}
$builder
......
......@@ -119,7 +119,7 @@ class AfterLoginRedirection implements AuthenticationSuccessHandlerInterface
if (in_array('ROLE_PRESTATAIRE', $groupe->getRoles()) && count($user->getPrestataires()) >= 1) {
$this->session->set('_prestagere', $user->getPrestataires()[0]);
} elseif (in_array('ROLE_CAISSIER', $groupe->getRoles()) && count($user->getCaissiers()) >= 1) {
$this->session->set('_prestagere', $user->getCaissiers()[0]);
$this->session->set('_prestagere', $user->getCaissiers()[0]->getPrestataire());
} elseif (in_array('ROLE_COMPTOIR', $groupe->getRoles()) && count($user->getComptoirsGeres()) >= 1) {
$this->session->set('_comptoirgere', $user->getComptoirsGeres()[0]);
} elseif ((in_array('ROLE_TRESORIER', $groupe->getRoles()) || in_array('ROLE_CONTACT', $groupe->getRoles()) || in_array('ROLE_GESTION_GROUPE', $groupe->getRoles())) && count($user->getGroupesGeres()) >= 1) {
......
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250422095126 extends AbstractMigration
{
public function getDescription() : string
{
return 'Operations related to changing ManyToMany relationship "caissiers" to explicit relation entity "Caissier"';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE user_caissier DROP FOREIGN KEY FK_FF8E6FC2A76ED395');
$this->addSql('ALTER TABLE user_caissier DROP FOREIGN KEY FK_FF8E6FC2BE3DB2B7');
$this->addSql('ALTER TABLE user_caissier ADD id INT AUTO_INCREMENT NOT NULL, ADD last_transactions_export_datetime DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', DROP PRIMARY KEY, ADD PRIMARY KEY (id)');
$this->addSql('ALTER TABLE user_caissier RENAME TO caissier');
$this->addSql('ALTER TABLE caissier ADD CONSTRAINT FK_1F038BC2A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE caissier ADD CONSTRAINT FK_1F038BC2BE3DB2B7 FOREIGN KEY (prestataire_id) REFERENCES prestataire (id)');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE caissier DROP FOREIGN KEY FK_1F038BC2A76ED395');
$this->addSql('ALTER TABLE caissier DROP FOREIGN KEY FK_1F038BC2BE3DB2B7');
$this->addSql('ALTER TABLE caissier DROP PRIMARY KEY, ADD PRIMARY KEY (prestataire_id, user_id), DROP COLUMN id, DROP COLUMN last_transactions_export_datetime');
$this->addSql('ALTER TABLE caissier RENAME TO user_caissier');
$this->addSql('ALTER TABLE user_caissier ADD CONSTRAINT FK_FF8E6FC2A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE user_caissier ADD CONSTRAINT FK_FF8E6FC2BE3DB2B7 FOREIGN KEY (prestataire_id) REFERENCES prestataire (id)');
}
}
<?php
namespace App\Repository;
use App\Entity\Caissier;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Caissier>
*
* @method Caissier|null find($id, $lockMode = null, $lockVersion = null)
* @method Caissier|null findOneBy(array $criteria, array $orderBy = null)
* @method Caissier[] findAll()
* @method Caissier[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class CaissierRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Caissier::class);
}
/**
* @throws ORMException
* @throws OptimisticLockException
*/
public function add(Caissier $entity, bool $flush = true): void
{
$this->_em->persist($entity);
if ($flush) {
$this->_em->flush();
}
}
/**
* @throws ORMException
* @throws OptimisticLockException
*/
public function remove(Caissier $entity, bool $flush = true): void
{
$this->_em->remove($entity);
if ($flush) {
$this->_em->flush();
}
}
// /**
// * @return Caissier[] Returns an array of Caissier objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('c')
->andWhere('c.exampleField = :val')
->setParameter('val', $value)
->orderBy('c.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?Caissier
{
return $this->createQueryBuilder('c')
->andWhere('c.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}
......@@ -177,19 +177,27 @@ class FluxRepository extends ServiceEntityRepository
}
/**
* @param Prestataire $presta
* @param bool $onlySameDay
* @param User $user operator of the flux
* @param Prestataire $presta
* @param string $from Date from which to fetch the flux
*
* @return Query Returns a query fo finding an array of Flux
*/
public function getQueryByCaissier(Prestataire $presta, $onlySameDay = true)
public function getQueryByCaissier(User $user, Prestataire $presta, $from = true)
{
$sqlQuery = "SELECT f.id FROM {$this->tableName} f WHERE ((f.type = 'adherent_prestataire' AND f.prestataire_id = :id) OR (f.type = 'prestataire_prestataire' AND f.prestataire_dest_id = :id))";
if ($onlySameDay) {
$sqlQuery .= ' AND DATE(f.created_at) = CURDATE()';
$sqlQuery = "SELECT f.id FROM {$this->tableName} f";
$sqlQuery .= " WHERE ((f.type = 'adherent_prestataire' AND f.prestataire_id = :pid) OR (f.type = 'prestataire_prestataire' AND f.prestataire_dest_id = :pid))";
$sqlQuery .= " AND f.user_id = :cid"; // set operateur
if ($from != null) {
$sqlQuery .= " AND f.created_at >= :from";
}
$statement = $this->connection->prepare($sqlQuery);
$statement->bindValue(':id', $presta->getId());
$statement->bindValue(':pid', $presta->getId());
$statement->bindValue(':cid', $user->getId());
if ($from != null) {
$statement->bindValue(':from', $from);
}
$statement->execute();
$results = $statement->fetchAll();
$qb = $this->createQueryBuilder('f');
......
......@@ -7,6 +7,7 @@ use App\Entity\AchatMonnaieAConfirmerPrestataire;
use App\Entity\AchatMonnaieAdherent;
use App\Entity\AchatMonnaiePrestataire;
use App\Entity\Adherent;
use App\Entity\Caissier;
use App\Entity\Comptoir;
use App\Entity\CotisationAdherent;
use App\Entity\CotisationPrestataire;
......@@ -106,7 +107,7 @@ class AppExtension extends AbstractExtension
new \Twig_SimpleFunction('getPaymentReceiptUrlFromFlux', [$this, 'getPaymentReceiptUrlFromFlux']),
new \Twig_SimpleFunction('getDonType', [$this, 'getDonType']),
new \Twig_SimpleFunction('getLastTavCotisationForAdherent', [$this, 'getLastTavCotisationForAdherent']),
new \Twig_SimpleFunction('getPrestaLastTransactionsExportDate', [$this, 'getPrestaLastTransactionsExportDate']),
new \Twig_SimpleFunction('getCaissierLastTransactionsExportDate', [$this, 'getCaissierLastTransactionsExportDate']),
new \Twig_SimpleFunction('checkExistingRecurringPayment', [$this, 'checkExistingRecurringPayment']),
new \Twig_SimpleFunction('parameter', function ($name) {
return $this->container->getParameter($name);
......@@ -478,7 +479,7 @@ class AppExtension extends AbstractExtension
if ($this->security->isGranted('ROLE_PRESTATAIRE')) {
$query = $this->em->getRepository(Flux::class)->getQueryByPrestataire($this->session->get('_prestagere'), $parenttype);
} elseif ($this->security->isGranted('ROLE_CAISSIER')) {
$query = $this->em->getRepository(Flux::class)->getQueryByCaissier($this->session->get('_prestagere'));
$query = $this->em->getRepository(Flux::class)->getQueryByCaissier($user, $this->session->get('_prestagere'));
}
} elseif (null != $user->getAdherent()) {
$query = $this->em->getRepository(Flux::class)->getQueryByAdherent($user->getAdherent(), $parenttype);
......@@ -549,15 +550,17 @@ class AppExtension extends AbstractExtension
return str_replace('@', '&#64;', $email);
}
public function getPrestaLastTransactionsExportDate(?Adherent $adherent = null)
public function getCaissierLastTransactionsExportDate(?Adherent $adherent = null)
{
if (!$this->session->has('_prestagere')) {
return null;
}
$presta = $this->em->getRepository(Prestataire::class)->findOneById($this->session->get('_prestagere')->getId());
$user = $this->security->getUser();
$caissier = $this->em->getRepository(Caissier::class)->findOneBy(['prestataire' => $presta, 'user' => $user]);
$datetime_last_export = $presta->getLastTransactionsExportDatetime();
$datetime_last_export = $caissier->getLastTransactionsExportDatetime();
$res = "";
if (null == $datetime_last_export) {
......
......@@ -17,9 +17,9 @@
</div>
{% endfor %}
{% elseif role == 'ROLE_CAISSIER' %}
{% for presta in app.user.caissiers %}
{% for caissier in app.user.caissiers %}
<div class='col-6 text-center p-2'>
<a role="button" class="btn btn-default btn-secondary" href='{{path('presta_choice', {'prestaid' : presta.id, 'usergrpid': group.id})}}'>{{ group.name|trans }} - {{presta}} </a>
<a role="button" class="btn btn-default btn-secondary" href='{{path('caissier_choice', {'caissierid' : caissier.id, 'usergrpid': group.id})}}'>{{ group.name|trans }} - {{caissier.prestataire}} </a>
</div>
{% endfor %}
{% elseif role == 'ROLE_COMPTOIR' %}
......
......@@ -4,10 +4,10 @@
<i class="fa fa-list-alt mr-4"></i> {{'Transactions'|trans }}
{% endblock blocktitle %}
{% block blockcontent %}
{% set datetime_last_export = getPrestaLastTransactionsExportDate() %}
{% set datetime_last_export = getCaissierLastTransactionsExportDate() %}
<p>Récupérer le montant total des transactions (hors reconversions) depuis le <b>{{ datetime_last_export }}</b></p>
<a class='btn btn-xs btn-primary mt-2' href='{{ path('get_presta_last_transactions') }}'>
<p>Récupérer le montant total des transactions opérées par ce compte Caissier (hors reconversions) depuis le <b>{{ datetime_last_export }}</b></p>
<a class='btn btn-xs btn-primary mt-2' href='{{ path('get_caissier_last_transactions') }}'>
{{ 'Exporter'|trans }}
</a>
{% endblock blockcontent %}
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