瀏覽代碼

Système de credit

packProduct
Fab 3 年之前
父節點
當前提交
425bb3fc6b
共有 8 個檔案被更改,包括 433 行新增6 行删除
  1. +158
    -0
      Controller/Credit/CreditHistoryAdminController.php
  2. +110
    -1
      Controller/User/UserMerchantAdminController.php
  3. +72
    -0
      Form/Credit/CreditHistoryFormType.php
  4. +13
    -0
      Model/Credit/CreditHistoryModel.php
  5. +10
    -5
      Repository/Credit/CreditHistoryRepository.php
  6. +20
    -0
      Resources/translations/admin.fr.yaml
  7. +6
    -0
      Resources/views/admin/credit/credit_history_index.html.twig
  8. +44
    -0
      Resources/views/admin/credit/modal_addcredithistory.html.twig

+ 158
- 0
Controller/Credit/CreditHistoryAdminController.php 查看文件

@@ -0,0 +1,158 @@
<?php

namespace Lc\CaracoleBundle\Controller\Credit;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
use EasyCorp\Bundle\EasyAdminBundle\Collection\ActionCollection;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\MoneyField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryModel;
use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Translation\TranslatorAdmin;

abstract class CreditHistoryAdminController extends AbstractAdminController
{
use AdminControllerTrait;

protected $em;
protected $translatorAdmin;
public function __construct(EntityManagerInterface $entityManager, TranslatorAdmin $translatorAdmin){
$this->em = $entityManager;
$this->translatorAdmin = $translatorAdmin;
}

public function overrideGlobalActions(?ActionCollection $actions)
{
parent::overrideGlobalActions($actions);
if ($actions) {
$adminUrlGenerator = $this->get(AdminUrlGenerator::class);

$creditControllerFqcn = $this->getControllerFqcnByInterface(CreditHistoryInterface::class);

foreach ($actions as $action) {
$url = $adminUrlGenerator
->setController($creditControllerFqcn)
->setAction(Action::NEW)
->set('userMerchantId', $this->getUserMerchant()->getId())
->generateUrl();
$action->setLinkUrl($url);
}
}
}

public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void
{
$entityInstance->setUserMerchant($this->getUserMerchant());

parent::persistEntity($entityManager, $entityInstance); // TODO: Change the autogenerated stub
}

protected function getUserMerchant(): UserMerchantInterface
{
$request = $this->get(AdminContextProvider::class)->getContext()->getRequest();
$userMerchant = $this->get('em')->getRepository(UserMerchantInterface::class)->find(
$request->get('userMerchantId')
);

return $userMerchant;
}

public function configureActions(Actions $actions): Actions
{
$actions->disable(Action::DELETE, Action::EDIT);

return parent::configureActions($actions); // TODO: Change the autogenerated stub
}

public function configureCrud(Crud $crud): Crud
{
$crud->overrideTemplate('crud/index', '@LcCaracole/admin/credit/credit_history_index.html.twig');

return $crud ;
}

public function configureFields(string $pageName): iterable
{
yield IdField::new('id')->hideOnForm();
yield ChoiceField::new('type')->setChoices(
array(
$this->translatorAdmin->transField(
'typeOptions.'.CreditHistoryModel::TYPE_CREDIT,
'CreditHistory'
) => CreditHistoryModel::TYPE_CREDIT,

$this->translatorAdmin->transField(
'typeOptions.'.CreditHistoryModel::TYPE_DEBIT,
'CreditHistory'
) => CreditHistoryModel::TYPE_DEBIT,
)
);
yield MoneyField::new('amount')->setCurrency('EUR');
yield DateField::new('paidAt');
yield ChoiceField::new('meanPayment')->setChoices(
array(
$this->translatorAdmin->transField(
'meanPaymentOptions.'.CreditHistoryModel::MEAN_PAYMENT_CASH,
'CreditHistory'
) => CreditHistoryModel::MEAN_PAYMENT_CASH,

$this->translatorAdmin->transField(
'meanPaymentOptions.'.CreditHistoryModel::MEAN_PAYMENT_CHEQUE,
'CreditHistory'
) => CreditHistoryModel::MEAN_PAYMENT_CHEQUE,

$this->translatorAdmin->transField(
'meanPaymentOptions.'.CreditHistoryModel::MEAN_PAYMENT_CREDIT,
'CreditHistory'
) => CreditHistoryModel::MEAN_PAYMENT_CREDIT,

$this->translatorAdmin->transField(
'meanPaymentOptions.'.CreditHistoryModel::MEAN_PAYMENT_CREDIT_CARD,
'CreditHistory'
) => CreditHistoryModel::MEAN_PAYMENT_CREDIT_CARD,

$this->translatorAdmin->transField(
'meanPaymentOptions.'.CreditHistoryModel::MEAN_PAYMENT_TRANSFER,
'CreditHistory'
) => CreditHistoryModel::MEAN_PAYMENT_TRANSFER
)
);;
yield TextField::new('reference');
yield TextField::new('comment');
}

public function createIndexQueryBuilder(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): QueryBuilder {
$queryBuilder = parent::createIndexQueryBuilder(
$searchDto,
$entityDto,
$fields,
$filters
);

$queryBuilder->andWhere('entity.userMerchant = :userMerchant');
$queryBuilder->setParameter('userMerchant', $searchDto->getRequest()->get('userMerchantId'));

return $queryBuilder;
}
}

+ 110
- 1
Controller/User/UserMerchantAdminController.php 查看文件

@@ -2,21 +2,85 @@

namespace Lc\CaracoleBundle\Controller\User;

use Doctrine\ORM\EntityManagerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Collection\EntityCollection;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use EasyCorp\Bundle\EasyAdminBundle\Event\AfterCrudActionEvent;
use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeCrudActionEvent;
use EasyCorp\Bundle\EasyAdminBundle\Exception\ForbiddenActionException;
use EasyCorp\Bundle\EasyAdminBundle\Exception\InsufficientEntityPermissionException;
use EasyCorp\Bundle\EasyAdminBundle\Factory\EntityFactory;
use EasyCorp\Bundle\EasyAdminBundle\Field\ArrayField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Form\Credit\CreditHistoryFormType;
use Lc\CaracoleBundle\Form\User\UserMerchantFormType;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Field\BooleanField;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\HttpFoundation\Response;

abstract class UserMerchantAdminController extends AbstractAdminController
{
use AdminControllerTrait;
protected $em;
protected $translatorAdmin;

public function __construct(EntityManagerInterface $entityManager, TranslatorAdmin $translatorAdmin){
$this->em = $entityManager;
$this->translatorAdmin = $translatorAdmin;
}

public function overrideEntitiesActions(?EntityCollection $entities){
$context = $this->get(AdminContextProvider::class)->getContext();
$adminUrlGenerator = $this->get(AdminUrlGenerator::class);

$creditControllerFqcn = $context->getCrudControllers()->findCrudFqcnByEntityFqcn(
$this->em->getEntityName(CreditHistoryInterface::class)
);

if($entities) {
foreach ($entities as $entity) {
foreach ($entity->getActions() as $action) {
if ($action->getName('credit_history')) {
$url = $adminUrlGenerator
->setController($creditControllerFqcn)
->set('userMerchantId', $entity->getInstance()->getId())
->generateUrl();
$action->setLinkUrl($url);
}
}
}
}
}

public function configureActions(Actions $actions): Actions
{
$actions = parent::configureActions($actions);

$creditAction = Action::new('credit_history', false, 'fa fa-cash-register')
->linkToCrudAction('credit_history')
->setHtmlAttributes(
array(
'data-toggle' => 'tooltip',
'title' => $this->translatorAdmin->transAction('credit'),
)
)
->setCssClass('btn btn-sm btn-success');
$actions->add(Crud::PAGE_INDEX, $creditAction);

return $actions;
}

public function configureFields(string $pageName): iterable
{
@@ -25,7 +89,9 @@ abstract class UserMerchantAdminController extends AbstractAdminController
yield TextField::new('user.firstname');
yield BooleanField::new('active');
yield BooleanField::new('creditActive');
if($this->isGranted('ROLE_SUPER_ADMIN'))yield ArrayField::new('roles');
if ($this->isGranted('ROLE_SUPER_ADMIN')) {
yield ArrayField::new('roles');
}
}

public function new(AdminContext $context): Response
@@ -128,4 +194,47 @@ abstract class UserMerchantAdminController extends AbstractAdminController
);
}

public function credit(AdminContext $context, AdminUrlGenerator $adminUrlGenerator): Response
{
$event = new BeforeCrudActionEvent($context);
$this->get('event_dispatcher')->dispatch($event);
if ($event->isPropagationStopped()) {
return $event->getResponse();
}

if (!$this->isGranted(
Permission::EA_EXECUTE_ACTION,
['action' => Action::DETAIL, 'entity' => $context->getEntity()]
)) {
throw new ForbiddenActionException($context);
}
if (!$context->getEntity()->isAccessible()) {
throw new InsufficientEntityPermissionException($context);
}
dump($context->getCrud()->getControllerFqcn());


$options['action'] = $adminUrlGenerator
->setController($context->getCrud()->getControllerFqcn())
->setAction('add_credit')
->setEntityId($context->getEntity()->getInstance()->getId())
->set('userMerchant', 'niche')
->generateUrl();
$addCreditHistoryForm = $this->createForm(CreditHistoryFormType::class, null, $options)->createView();


return $this->render(
'@LcCaracole/admin/credit/credit_detail.html.twig',
[
'pageName' => Crud::PAGE_DETAIL,
'entity' => $context->getEntity(),
'batch_actions' => array(),
'entities' => array(),
'filters' => array(),
'paginator' => array(),
'add_credit_history_form' => $addCreditHistoryForm,
]
);
}

}

+ 72
- 0
Form/Credit/CreditHistoryFormType.php 查看文件

@@ -0,0 +1,72 @@
<?php

namespace Lc\CaracoleBundle\Form\Credit;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryModel;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class CreditHistoryFormType extends AbstractType
{
protected $em;


public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('type', ChoiceType::class, array(
'choices' => array(
'field.CreditHistory.typeOptions.'.CreditHistoryModel::TYPE_CREDIT => CreditHistoryModel::TYPE_CREDIT,
'field.CreditHistory.typeOptions.'.CreditHistoryModel::TYPE_DEBIT => CreditHistoryModel::TYPE_DEBIT
),
'required' => true
))
->add('amount', MoneyType::class)
/*->add('meanPayment', ChoiceType::class, array(
'choices' => array(
'field.default.meanPaymentOptions.'.Utils::MEAN_PAYMENT_CASH => Utils::MEAN_PAYMENT_CASH,
'field.default.meanPaymentOptions.'.Utils::MEAN_PAYMENT_CHEQUE => Utils::MEAN_PAYMENT_CHEQUE,
'field.default.meanPaymentOptions.'.Utils::MEAN_PAYMENT_CREDIT => Utils::MEAN_PAYMENT_CREDIT,
'field.default.meanPaymentOptions.'.Utils::MEAN_PAYMENT_CREDIT_CARD => Utils::MEAN_PAYMENT_CREDIT_CARD,
'field.default.meanPaymentOptions.'.Utils::MEAN_PAYMENT_TRANSFER => Utils::MEAN_PAYMENT_TRANSFER
),
'required' => true
))*/
->add('paidAt', DateType::class, array(
'widget' => 'single_text',
'required' => true
))
->add('reference', TextType::class, array(
'required'=>false
))

->add('comment', TextareaType::class, array(
'required'=>false
))
->add('add', SubmitType::class, array(
'label' => 'action.add'
));


}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => $this->em->getClassMetadata(CreditHistoryInterface::class)->getName()
]);
}
}

+ 13
- 0
Model/Credit/CreditHistoryModel.php 查看文件

@@ -21,6 +21,14 @@ abstract class CreditHistoryModel extends AbstractLightEntity implements PayoffI
const TYPE_CREDIT = 'credit';
const TYPE_DEBIT = 'debit';


const MEAN_PAYMENT_CREDIT_CARD = 'cb';
const MEAN_PAYMENT_CHEQUE = 'cheque';
const MEAN_PAYMENT_CREDIT = 'credit';
const MEAN_PAYMENT_TRANSFER = 'transfer';
const MEAN_PAYMENT_CASH = 'cash';


/**
* @ORM\Column(type="float", nullable=true)
*/
@@ -61,6 +69,11 @@ abstract class CreditHistoryModel extends AbstractLightEntity implements PayoffI
*/
protected $updatedBy;

public function __toString(){
//Todo a écrire
return $this->getType();
}

public function getAmount(): ?float
{
return $this->amount;

+ 10
- 5
Repository/Credit/CreditHistoryRepository.php 查看文件

@@ -2,9 +2,10 @@

namespace Lc\CaracoleBundle\Repository\Credit;

use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Lc\CaracoleBundle\Model\Config\TaxRateInterface;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
use Lc\CaracoleBundle\Repository\RepositoryTrait;
use Lc\SovBundle\Repository\AbstractRepository;

/**
* @method CreditHistoryInterface|null find($id, $lockMode = null, $lockVersion = null)
@@ -12,10 +13,14 @@ use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
* @method CreditHistoryInterface[] findAll()
* @method CreditHistoryInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class CreditHistoryRepository extends ServiceEntityRepository
class CreditHistoryRepository extends AbstractRepository
{
public function __construct(ManagerRegistry $registry)
use RepositoryTrait;

public function getInterfaceClass()
{
parent::__construct($registry, CreditHistoryInterface::class);
return CreditHistoryInterface::class;
}


}

+ 20
- 0
Resources/translations/admin.fr.yaml 查看文件

@@ -76,6 +76,26 @@ entity:
lastname: Nom
firstname: Prénom
creditActive: Crédit activer
CreditHistory:
label: Historique de compte prépayé
label_plurial: Historiques de compte prépayé
fields:
type: Type
typeOptions:
credit: Crédit
debit: Débit
amount: Montant
meanPayment: Moyen de paiement
meanPaymentOptions:
cheque: Chèque
cb: Carte bancaire
cash: Espèces
transfer: Virement
credit: Compte prépayé
paidAt: Date de transaction
reference: Référence
comment: Commentaire

GroupUser:
label: Groupe d'utilisateur
label_plurial: Groupes d'utilisateurs

+ 6
- 0
Resources/views/admin/credit/credit_history_index.html.twig 查看文件

@@ -0,0 +1,6 @@
{% extends '@LcSov/adminlte/crud/index.html.twig' %}

{% block content_title %}
{{ 'index'|lc_trans_admin_title(ea.getEntity().getFqcn()) }}
Info de Fab
{% endblock %}

+ 44
- 0
Resources/views/admin/credit/modal_addcredithistory.html.twig 查看文件

@@ -0,0 +1,44 @@
{% trans_default_domain 'adin' %}

<div class="modal fade show" id="modal-add-credit-history">
{{ form_start(add_credit_history_form, {'attr': { 'id' : 'addCreditHistory'}}) }}
{% form_theme add_credit_history_form '@LcSov/adminlte/crud/form_theme.html.twig' %}
<div class="modal-dialog">

<div class="modal-content">
<div class="modal-header">
<h4>{{ "action.credit.add"|trans }}</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="col">
{{ form_row(add_credit_history_form.type) }}
</div>
<div class="col">
{{ form_row(add_credit_history_form.amount) }}
</div>

<div class="col">
{# {{ form_row(add_credit_history_form.meanPayment) }}#}
</div>
<div class="col">
{{ form_row(add_credit_history_form.paidAt) }}
</div>
<div class="col">
{{ form_row(add_credit_history_form.reference) }}
</div>
<div class="col">
{{ form_row(add_credit_history_form.comment) }}
</div>
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
{{ form_row(add_credit_history_form.add, {"attr": {'class' : 'btn btn-primary'}}) }}
</div>
</div>
<!-- /.modal-content -->
</div>
{{ form_end(add_credit_history_form) }}
</div>

Loading…
取消
儲存