Commit dc15442f by Damien Moulard

Interface achat de monnaie en CB

parent b97c4831
......@@ -33,6 +33,8 @@ use Symfony\Component\Translation\TranslatorInterface;
* - PRESTATAIRES => ADHERENTS (Virement vers un adherent)
* - PRESTATAIRES => PRESTATAIRES (Virement entre prestataires)
* - ADHERENTS => PRESTATAIRES (Paiement numérique)
* - SIEGE => ADHERENTS (Achat de monnaie numérique par CB d'un adhérent)
* - SIEGE => PRESTATAIRES (Achat de monnaie numérique par CB d'un prestataire)
*
*/
class FluxController extends AbstractController
......
......@@ -7,11 +7,13 @@ use App\Entity\Cotisation;
use App\Entity\Geoloc;
use App\Entity\TransactionAdherentAdherent;
use App\Entity\TransactionAdherentPrestataire;
use App\Entity\AchatMonnaieAdherent;
use App\Entity\Usergroup;
use App\Form\Type\AdherentInfosFormType;
use App\Form\Type\AdhererFormType;
use App\Form\Type\TransactionAdherentAdherentFormType;
use App\Form\Type\TransactionAdherentPrestataireFormType;
use App\Form\Type\AchatMonnaieAdherentFormType;
use Doctrine\ORM\EntityManagerInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
......@@ -90,4 +92,30 @@ class UserAdherentController extends FluxController
$this->translator->trans('Transaction à un adhérent')
);
}
/**
* @Route("/adherent/achat-monnaie/", name="achatMonnaieAdherent")
* @IsGranted("ROLE_ADHERENT")
*/
public function achatMonnaieAdherentAction(Request $request)
{
if (empty($this->getUser()) || empty($this->getUser()->getAdherent())) {
return $this->redirectToRoute('index');
}
$entity = new AchatMonnaieAdherent();
$entity->setReference("Achat Monnaie en CB");
$form = $this->createForm(AchatMonnaieAdherentFormType::class, $entity);
//TODO custom form handling -> redirect to payzen or other mean of payment
return $this->redirectToRoute('index');
return $this->manageFluxForm(
$request,
$form,
$this->getUser()->getAdherent()->getCompte(),
$this->translator->trans('Achat de monnaie locale bien effectuée !'),
$this->translator->trans('Achat de monnaie locale')
);
}
}
......@@ -8,10 +8,12 @@ use App\Entity\Rubrique;
use App\Entity\TransactionPrestataireAdherent;
use App\Entity\TransfertPrestataireSiege;
use App\Entity\TypePrestataire;
use App\Entity\AchatMonnaiePrestataire;
use App\Form\Type\GroupePrestataireInscriptionFormType;
use App\Form\Type\PrestataireInfosFormType;
use App\Form\Type\TransactionPrestataireAdherentFormType;
use App\Form\Type\TransfertPrestataireSiegeFormType;
use App\Form\Type\AchatMonnaiePrestataireFormType;
use Doctrine\ORM\EntityManagerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sonata\Exporter\Handler;
......@@ -123,7 +125,31 @@ class UserPrestataireController extends FluxController
$this->translator->trans('Reconversion de monnaie au siège')
);
}
/**
* @Route("/prestataire/achat-monnaie/", name="achatMonnaiePrestataire")
* @IsGranted("ROLE_PRESTATAIRE")
*/
public function achatMonnaiePrestataireAction(Request $request)
{
if (empty($this->getUser()) || empty($this->session->get('_prestagere'))) {
return $this->redirectToRoute('index');
}
$entity = new AchatMonnaiePrestataire();
$form = $this->createForm(AchatMonnaiePrestataireFormType::class, $entity);
///TODO custom form handling -> redirect to payzen or other mean of payment
return $this->redirectToRoute('index');
return $this->manageFluxForm(
$request,
$form,
$this->session->get('_prestagere'),
$this->translator->trans('Achat de monnaie locale bien effectuée !'),
$this->translator->trans('Achat de monnaie locale')
);
}
/**
* Export all transferts / transactions for prestataire
*
......
<?php
namespace App\Entity;
use App\Entity\Siege;
use Doctrine\ORM\Mapping as ORM;
/**
* Achat de monnaie en CB par un Adhérent ou Prestataire
*
* @ORM\Entity
*/
class AchatMonnaie extends Flux
{
/**
* @ORM\ManyToOne(targetEntity="Siege")
* @ORM\JoinColumn(name="siege_id", referencedColumnName="id", nullable=true)
*/
protected $expediteur;
public function operate($em)
{
// Increment Ecompte of Siege
$this->getExpediteur()->addEcompte($this->getMontant());
$this->getDestinataire()->addEcompte($this->getMontant());
return [$this->getExpediteur(), $this->getDestinataire()];
}
public function getUsersToNotify()
{
return ['siege'];
}
/**
* @return string
*/
public function getParenttype(): string
{
return self::TYPE_ACHAT;
}
/**
* @return string
*/
public function getType(): string
{
return 'achat_monnaie';
}
}
<?php
namespace App\Entity;
use App\Entity\Adherent;
use Doctrine\ORM\Mapping as ORM;
/**
* TRANSACTION
* - Achat de monnaie en CB par un Adhérent
*
* @ORM\Entity
*/
class AchatMonnaieAdherent extends AchatMonnaie
{
/**
* @ORM\ManyToOne(targetEntity="Adherent")
* @ORM\JoinColumn(name="adherent_dest_id", referencedColumnName="id", nullable=true)
*/
protected $destinataire;
/**
* @return string
*/
public function getType(): string
{
return 'achat_monnaie_adherent';
}
}
<?php
namespace App\Entity;
use App\Entity\Prestataire;
use Doctrine\ORM\Mapping as ORM;
/**
* TRANSACTION
* - Achat de monnaie en CB par un Prestataire.
*
* @ORM\Entity
*/
class AchatMonnaiePrestataire extends AchatMonnaie
{
/**
* @ORM\ManyToOne(targetEntity="Prestataire")
* @ORM\JoinColumn(name="prestataire_dest_id", referencedColumnName="id", nullable=true)
*/
protected $destinataire;
/**
* @return string
*/
public function getType(): string
{
return 'achat_monnaie_prestataire';
}
}
......@@ -18,7 +18,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
* @ORM\HasLifecycleCallbacks()
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap({"cotisation" = "Cotisation", "cotisation_adherent" = "CotisationAdherent", "cotisation_prestataire" = "CotisationPrestataire", "tro_adh_pre" = "TransactionAdherentPrestataire", "tro_adh_adh" = "TransactionAdherentAdherent", "tro_pre_adh" = "TransactionPrestataireAdherent", "tro_pre_pre" = "TransactionPrestatairePrestataire", "tre_cpt_grp" = "TransfertComptoirGroupe", "tre_grp_cpt" = "TransfertGroupeComptoir", "tre_pre_cpt" = "TransfertPrestataireComptoir", "tre_pre_sie" = "TransfertPrestataireSiege", "tre_sie_grp" = "TransfertSiegeGroupe", "tre_grp_sie" = "TransfertGroupeSiege", "vte_cpt_pre" = "VenteComptoirPrestataire", "vte_cpt_adh" = "VenteComptoirAdherent", "ret_cpt_pre" = "RetraitComptoirPrestataire", "ret_cpt_adh" = "RetraitComptoirAdherent", "com_rec_pre" = "CommissionPrestataireMLC"})
* @ORM\DiscriminatorMap({"cotisation" = "Cotisation", "cotisation_adherent" = "CotisationAdherent", "cotisation_prestataire" = "CotisationPrestataire", "tro_adh_pre" = "TransactionAdherentPrestataire", "tro_adh_adh" = "TransactionAdherentAdherent", "tro_pre_adh" = "TransactionPrestataireAdherent", "tro_pre_pre" = "TransactionPrestatairePrestataire", "tre_cpt_grp" = "TransfertComptoirGroupe", "tre_grp_cpt" = "TransfertGroupeComptoir", "tre_pre_cpt" = "TransfertPrestataireComptoir", "tre_pre_sie" = "TransfertPrestataireSiege", "tre_sie_grp" = "TransfertSiegeGroupe", "tre_grp_sie" = "TransfertGroupeSiege", "vte_cpt_pre" = "VenteComptoirPrestataire", "vte_cpt_adh" = "VenteComptoirAdherent", "ret_cpt_pre" = "RetraitComptoirPrestataire", "ret_cpt_adh" = "RetraitComptoirAdherent", "com_rec_pre" = "CommissionPrestataireMLC", "achat_monnaie" = "AchatMonnaie", "achat_monnaie_prestataire" = "AchatMonnaiePrestataire", "achat_monnaie_adherent" = "AchatMonnaieAdherent"})
*/
abstract class Flux
{
......@@ -30,6 +30,7 @@ abstract class Flux
const TYPE_VENTE = 'vente';
const TYPE_RETRAIT = 'retrait';
const TYPE_COMMISSION = 'commission';
const TYPE_ACHAT = 'achat';
/**
* @var int
......@@ -136,13 +137,13 @@ abstract class Flux
* @return array Tableau des entité(s) à persister (siege, comptoir, groupe, presta, adherent...)
*/
abstract public function operate($em);
/**
* Obtenir la liste des utilisateurs à notifier
* @return array Tableau d'utilisateurs
*/
abstract public function getUsersToNotify();
public function __construct()
{
$this->parenttype = $this->getParenttype();
......@@ -298,7 +299,7 @@ abstract class Flux
{
return $this->hash;
}
/**
* Set hash
* @return $this
......@@ -335,7 +336,7 @@ abstract class Flux
{
return $this->tauxreconversion;
}
/**
* Set tauxreconversion
* @return $this
......
......@@ -3,6 +3,7 @@
namespace App\Entity;
use App\Entity\EntityTrait\HasCompteEntity;
use App\Entity\EntityTrait\HasEcompteEntity;
use App\Entity\EntityTrait\NameSlugContentEntityTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
......@@ -15,7 +16,8 @@ use Symfony\Component\Validator\Constraints as Assert;
class Siege
{
use NameSlugContentEntityTrait,
HasCompteEntity;
HasCompteEntity,
HasEcompteEntity;
/**
* @var int
......
......@@ -19,6 +19,8 @@ use App\Entity\RetraitComptoirAdherent;
use App\Entity\RetraitComptoirPrestataire;
use App\Entity\VenteComptoirAdherent;
use App\Entity\VenteComptoirPrestataire;
use App\Entity\AchatMonnaieAdherent;
use App\Entity\AchatMonnaiePrestataire;
use App\Entity\User;
use App\Enum\MoyenEnum;
use App\Form\Type\AdherentInfosFormType;
......@@ -41,6 +43,8 @@ use App\Form\Type\RetraitComptoirAdherentFormType;
use App\Form\Type\RetraitComptoirPrestataireFormType;
use App\Form\Type\VenteComptoirAdherentFormType;
use App\Form\Type\VenteComptoirPrestataireFormType;
use App\Form\Type\AchatMonnaieAdherentFormType;
use App\Form\Type\AchatMonnaiePrestataireFormType;
use App\Form\Type\UserInfosFormType;
use FOS\UserBundle\Form\Type\ChangePasswordFormType;
use Symfony\Component\Form\FormFactoryInterface as FormF;
......@@ -285,4 +289,29 @@ class FormFactory
return $form->createView();
}
public function getAchatMonnaieAdherentForm(User $user)
{
if (empty($user) || empty($user->getAdherent())) {
throw new \Exception("[FORM 16] Opération impossible !");
}
$entity = new AchatMonnaieAdherent();
$entity->setOperateur($user);
$form = $this->ff->create(AchatMonnaieAdherentFormType::class, $entity, array('action' => $this->router->generate('achatMonnaieAdherent')));
return $form->createView();
}
public function getAchatMonnaiePrestataireForm(User $user)
{
if (empty($user) || empty($this->session->get('_prestagere'))) {
throw new \Exception("[FORM 17] Opération impossible !");
}
$entity = new AchatMonnaiePrestataire();
$entity->setOperateur($user);
$form = $this->ff->create(AchatMonnaiePrestataireFormType::class, $entity, array('action' => $this->router->generate('achatMonnaiePrestataire')));
return $form->createView();
}
}
<?php
namespace App\Form\Type;
use App\Entity\Adherent;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class AchatMonnaieAdherentFormType extends AchatMonnaieFormType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (empty($this->security) || empty($this->security->getUser())) {
throw new \Exception("[FORM ACHAT MONNAIE ADHERENT] Opération impossible !");
}
$builder
-> add('destinataire', HiddenType::class, array(
'data' => $this->security->getUser()->getAdherent()->getId(),
'data_class' => null,
'entity_class' => Adherent::class,
'em' => $this->em
))
->add('reference', HiddenType::class, array(
'data' => 'Achat monnaie en CB'
))
->add('save', SubmitType::class, ['label' => "Payer en CB"])
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'class' => AchatMonnaieAdherent::class,
));
}
public function getParent()
{
return AchatMonnaieFormType::class;
}
public function getBlockPrefix()
{
return 'formAchatMonnaieAdherent';
}
}
<?php
namespace App\Form\Type;
use App\Entity\Siege;
use App\Enum\MoyenEnum;
use App\Form\Type\FluxFormType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
class AchatMonnaieFormType extends FluxFormType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('moyen', HiddenType::class, array(
'data' => MoyenEnum::MOYEN_CB
))
->add('expediteur', HiddenType::class, array(
'data' => 1,
'data_class' => null,
'entity_class' => Siege::class,
'em' => $this->em
))
;
}
public function getParent()
{
return FluxFormType::class;
}
public function getBlockPrefix()
{
return 'formAchatMonnaie';
}
}
<?php
namespace App\Form\Type;
use App\Entity\Prestataire;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class AchatMonnaiePrestataireFormType extends AchatMonnaieFormType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (empty($this->security) || empty($this->security->getUser())) {
throw new \Exception("[FORM ACHAT MONNAIE PRESTATAIRE] Opération impossible !");
}
$builder
-> add('destinataire', HiddenType::class, array(
'data' => $this->session->get('_prestagere')->getId(),
'data_class' => null,
'entity_class' => Prestataire::class,
'em' => $this->em
))
->add('reference', HiddenType::class, array(
'data' => 'Achat monnaie en CB'
))
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'class' => AchatMonnaiePrestataire::class,
));
}
public function getParent()
{
return AchatMonnaieFormType::class;
}
public function getBlockPrefix()
{
return 'formAchatMonnaiePrestataire';
}
}
<?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 Version20200619082406 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE siege ADD ecompte NUMERIC(12, 2) NOT NULL DEFAULT 0');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE siege DROP ecompte');
}
}
......@@ -42,6 +42,8 @@ class FormExtension extends AbstractExtension
new \Twig_SimpleFunction('getTransfertGroupeComptoirForm', array($this, 'getTransfertGroupeComptoirForm')),
new \Twig_SimpleFunction('getTransfertSiegeGroupeForm', array($this, 'getTransfertSiegeGroupeForm')),
new \Twig_SimpleFunction('getTransfertGroupeSiegeForm', array($this, 'getTransfertGroupeSiegeForm')),
new \Twig_SimpleFunction('getAchatMonnaieAdherentForm', array($this, 'getAchatMonnaieAdherentForm')),
new \Twig_SimpleFunction('getAchatMonnaiePrestataireForm', array($this, 'getAchatMonnaiePrestataireForm')),
];
}
......@@ -121,4 +123,12 @@ class FormExtension extends AbstractExtension
{
return $this->container->get('app.formfactory')->getTransfertGroupeSiegeForm($user);
}
public function getAchatMonnaieAdherentForm(User $user)
{
return $this->container->get('app.formfactory')->getAchatMonnaieAdherentForm($user);
}
public function getAchatMonnaiePrestataireForm(User $user)
{
return $this->container->get('app.formfactory')->getAchatMonnaiePrestataireForm($user);
}
}
{% extends 'block/block_collapse.html.twig' %}
{% block blocktitle %}
<i class="fa fa-shopping-basket mr-4"></i> {{'Achat de monnaie locale'|trans }}
{% endblock blocktitle %}
{% block blockcontent %}
{% set form = getAchatMonnaieAdherentForm(app.user) %}
{{form(form)}}
{% endblock blockcontent %}
......@@ -67,6 +67,7 @@
{% set compte = siege.getCompte() %}
{% set soldelabel = 'Solde du siège'|trans %}
{% include 'block/solde.html.twig' with {'compte': compte, 'soldelabel': soldelabel} %}
{% include 'block/solde.html.twig' with {'compte': siege.getECompte(), 'soldelabel': 'Solde de monnaie numérique distribuée'} %}
{% include 'block/solde.html.twig' with {'compte': siege.getCompteNantie(), 'soldelabel': 'Monnaie nantie'} %}
{% include 'block/userinfos.html.twig' %}
{% include 'block/userpassword.html.twig' %}
......@@ -153,6 +154,7 @@
{% include 'block/cotisations.html.twig' %}
{% include 'groupepresta/block/inscription.html.twig' %}
{% endif %}
{% include 'presta/block/achat_monnaie.html.twig' %}
{% include 'presta/block/transaction_presta.html.twig' %}
{% include 'presta/block/transaction_adherent.html.twig' %}
{% if getCurrentPrestataire().mlc == false and getCurrentPrestataire().ecompte > 0 %}
......@@ -167,13 +169,14 @@
{% include 'block/userpassword.html.twig' %}
{% include 'block/cotisations.html.twig' %}
{% include 'block/transactions.html.twig' %}
{% include 'adherent/block/achat_monnaie.html.twig' %}
{% include 'adherent/block/transaction_presta.html.twig' %}
{% include 'adherent/block/transaction_adherent.html.twig' %}
{% else %}
{% if KOH_USE_WORDPRESS is defined and KOH_USE_WORDPRESS == 'false' %}
{% include 'presta/block/carte.html.twig' with {'title': 'Situer les Prestataires'|trans}%}
{% endif %}
{% endif %}
{% endif %}
</div>
\ No newline at end of file
</div>
{% extends 'block/block_collapse.html.twig' %}
{% block blocktitle %}
<i class="fa fa-shopping-basket mr-4"></i> {{'Achat de monnaie locale'|trans }}
{% endblock blocktitle %}
{% block blockcontent %}
{% set form = getAchatMonnaiePrestataireForm(app.user) %}
{{form(form)}}
{% 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