Skip to content

Commit

Permalink
Merge branch 'check_types' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jbtronics committed Nov 10, 2024
2 parents 9e65970 + bcce025 commit b9c66d0
Show file tree
Hide file tree
Showing 18 changed files with 609 additions and 119 deletions.
3 changes: 3 additions & 0 deletions config/routes/easyadmin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
easyadmin:
resource: .
type: easyadmin.routes
49 changes: 49 additions & 0 deletions migrations/Version20241109231434.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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 Version20241109231434 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add new datastructures to store details about the checks done by the StuRa finance members';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE bank_accounts_audit CHANGE diffs diffs JSON DEFAULT NULL');
$this->addSql('ALTER TABLE confirmation_token_audit CHANGE diffs diffs JSON DEFAULT NULL');
$this->addSql('ALTER TABLE confirmer_audit CHANGE diffs diffs JSON DEFAULT NULL');
$this->addSql('ALTER TABLE departments_audit CHANGE diffs diffs JSON DEFAULT NULL');
$this->addSql('ALTER TABLE payment_orders ADD mathematically_correct_checked TINYINT(1) NOT NULL, ADD mathematically_correct_timestamp DATETIME DEFAULT NULL, ADD mathematically_correct_confirmer_name VARCHAR(255) DEFAULT NULL, ADD mathematically_correct_confirmer_id INT DEFAULT NULL, ADD mathematically_correct_remark LONGTEXT DEFAULT NULL, ADD factually_correct_checked TINYINT(1) NOT NULL, ADD factually_correct_timestamp DATETIME DEFAULT NULL, ADD factually_correct_confirmer_name VARCHAR(255) DEFAULT NULL, ADD factually_correct_confirmer_id INT DEFAULT NULL, ADD factually_correct_remark LONGTEXT DEFAULT NULL');

//Move the old data from mathematically_correct and factually_correct to the new fields
$this->addSql('UPDATE payment_orders SET mathematically_correct_checked = mathematically_correct, factually_correct_checked = factually_correct');

//Drop the old columns
$this->addSql('ALTER TABLE payment_orders DROP mathematically_correct, DROP factually_correct');
$this->addSql('ALTER TABLE payment_orders_audit CHANGE diffs diffs JSON DEFAULT NULL');
$this->addSql('ALTER TABLE user_audit CHANGE diffs diffs JSON DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE bank_accounts_audit CHANGE diffs diffs LONGTEXT DEFAULT NULL');
$this->addSql('ALTER TABLE confirmation_token_audit CHANGE diffs diffs LONGTEXT DEFAULT NULL');
$this->addSql('ALTER TABLE confirmer_audit CHANGE diffs diffs LONGTEXT DEFAULT NULL');
$this->addSql('ALTER TABLE departments_audit CHANGE diffs diffs LONGTEXT DEFAULT NULL');
$this->addSql('ALTER TABLE payment_orders ADD mathematically_correct TINYINT(1) NOT NULL, ADD factually_correct TINYINT(1) NOT NULL, DROP mathematically_correct_checked, DROP mathematically_correct_timestamp, DROP mathematically_correct_confirmer_name, DROP mathematically_correct_confirmer_id, DROP mathematically_correct_remark, DROP factually_correct_checked, DROP factually_correct_timestamp, DROP factually_correct_confirmer_name, DROP factually_correct_confirmer_id, DROP factually_correct_remark');
$this->addSql('ALTER TABLE payment_orders_audit CHANGE diffs diffs LONGTEXT DEFAULT NULL');
$this->addSql('ALTER TABLE user_audit CHANGE diffs diffs LONGTEXT DEFAULT NULL');
}
}
23 changes: 23 additions & 0 deletions src/Admin/Field/CheckField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);


namespace App\Admin\Field;

use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait;

class CheckField implements FieldInterface
{
use FieldTrait;

public static function new(string $propertyName, ?string $label = null): self
{
return (new self())
->setProperty($propertyName)
->setLabel($label)
->setTemplatePath('admin/field/check.html.twig')
->setTextAlign('center');
}
}
38 changes: 38 additions & 0 deletions src/Admin/Filter/CheckFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);


namespace App\Admin\Filter;

use Doctrine\ORM\QueryBuilder;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Filter\FilterInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FilterDataDto;
use EasyCorp\Bundle\EasyAdminBundle\Filter\FilterTrait;
use EasyCorp\Bundle\EasyAdminBundle\Form\Filter\Type\BooleanFilterType;

class CheckFilter implements FilterInterface
{
use FilterTrait;

public static function new(string $propertyName, $label = null): self
{
return (new self())
->setFilterFqcn(__CLASS__)
->setProperty($propertyName)
->setLabel($label)
->setFormType(BooleanFilterType::class)
->setFormTypeOption('translation_domain', 'EasyAdminBundle');
}

public function apply(QueryBuilder $queryBuilder, FilterDataDto $filterDataDto, ?FieldDto $fieldDto, EntityDto $entityDto): void
{
$property = $filterDataDto->getProperty() . '.checked';

$queryBuilder
->andWhere(sprintf('%s.%s %s :%s', $filterDataDto->getEntityAlias(), $property, $filterDataDto->getComparison(), $filterDataDto->getParameterName()))
->setParameter($filterDataDto->getParameterName(), $filterDataDto->getValue());
}
}
2 changes: 1 addition & 1 deletion src/Controller/Admin/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function configureDashboard(): Dashboard
->setTitle('StuRa Finanzen');
}

#[Route(path: '/admin', name: 'admin_dashboard')]
#[Route(path: '/admin', name: 'admin')]
public function index(): Response
{
return $this->render('admin/dashboard.html.twig');
Expand Down
85 changes: 27 additions & 58 deletions src/Controller/Admin/PaymentOrderCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@

namespace App\Controller\Admin;

use App\Admin\Field\CheckField;
use App\Admin\Field\ConfirmationField;
use App\Admin\Field\FieldChangesField;
use App\Admin\Field\VichyFileField;
use App\Admin\Filter\CheckFilter;
use App\Admin\Filter\ConfirmedFilter;
use App\Admin\Filter\DepartmentTypeFilter;
use App\Admin\Filter\MoneyAmountFilter;
use App\Entity\Embeddable\Check;
use App\Entity\FieldChanges;
use App\Entity\PaymentOrder;
use App\Entity\User;
Expand Down Expand Up @@ -64,7 +67,13 @@

final class PaymentOrderCrudController extends AbstractCrudController
{
public function __construct(private readonly PaymentOrderMailLinkGenerator $mailToGenerator, private readonly DashboardControllerRegistry $dashboardControllerRegistry, private EntityManagerInterface $entityManager, private readonly ConfirmationEmailSender $confirmationEmailSender, private readonly AdminUrlGenerator $adminURLGenerator, private readonly MessageBusInterface $messageBus)
public function __construct(
private readonly PaymentOrderMailLinkGenerator $mailToGenerator,
private EntityManagerInterface $entityManager,
private readonly ConfirmationEmailSender $confirmationEmailSender,
private readonly AdminUrlGenerator $adminURLGenerator,
private readonly MessageBusInterface $messageBus
)
{
}

Expand Down Expand Up @@ -163,9 +172,9 @@ public function configureFilters(Filters $filters): Filters
->add(EntityFilter::new('department', 'payment_order.department.label'))
->add(DepartmentTypeFilter::new('department_type', 'payment_order.department_type.label'))
->add(MoneyAmountFilter::new('amount', 'payment_order.amount.label'))
->add(BooleanFilter::new('factually_correct', 'payment_order.factually_correct.label'))
->add(CheckFilter::new('factually_correct', 'payment_order.factually_correct.label'))
->add(CheckFilter::new('mathematically_correct', 'payment_order.mathematically_correct.label'))
->add(BooleanFilter::new('exported', 'payment_order.exported.label'))
->add(BooleanFilter::new('mathematically_correct', 'payment_order.mathematically_correct.label'))
->add(ConfirmedFilter::new('confirmed', 'payment_order.confirmed.label'))
->add(TextFilter::new('funding_id', 'payment_order.funding_id.label'))
->add(DateTimeFilter::new('creation_date', 'creation_date'))
Expand All @@ -191,40 +200,6 @@ public function resendConfirmationEmail(AdminContext $context): Response
return $this->redirect($context->getReferrer() ?? '/admin');
}

/**
* Handler for action if user click "check mathematically" button in admin page.
*/
public function checkMathematicallyCorrect(AdminContext $context): Response
{
$this->denyAccessUnlessGranted('ROLE_PO_MATHEMATICALLY');

/** @var PaymentOrder $payment_order */
$payment_order = $context->getEntity()
->getInstance();
$payment_order->setMathematicallyCorrect(true);
$this->entityManager->flush();
$this->addFlash('success', 'payment_order.action.mathematically_correct.success');

return $this->redirect($context->getReferrer() ?? '/admin');
}

/**
* Handler for action if user click "check factually" button in admin page.
*/
public function checkFactuallyCorrect(AdminContext $context): Response
{
$this->denyAccessUnlessGranted('ROLE_PO_FACTUALLY');

/** @var PaymentOrder $payment_order */
$payment_order = $context->getEntity()
->getInstance();
$payment_order->setFactuallyCorrect(true);
$this->entityManager->flush();
$this->addFlash('success', 'payment_order.action.factually_correct.success');

return $this->redirect($context->getReferrer() ?? '/admin');
}

public function configureAssets(Assets $assets): Assets
{
return $assets
Expand Down Expand Up @@ -321,28 +296,24 @@ public function configureActions(Actions $actions): Actions
//Hide action if no contact emails are associated with department
$emailAction->displayIf(fn(PaymentOrder $paymentOrder): bool => null !== $this->mailToGenerator->generateContactMailLink($paymentOrder));

$hhv_action = Action::new('contactHHV', 'payment_order.action.contact_hhv', 'fas fa-comment-dots')
->linkToUrl(fn(PaymentOrder $paymentOrder): string => $this->mailToGenerator->getHHVMailLink($paymentOrder))
->setCssClass('btn btn-secondary text-dark');

$resend_confirmation_action = Action::new('resendConfirmation', 'payment_order.action.resend_confirmation', 'fas fa-redo')
->linkToCrudAction('resendConfirmationEmail')
->displayIf(fn(PaymentOrder $paymentOrder): bool => $this->isGranted('ROLE_EDIT_PAYMENT_ORDERS') && !$paymentOrder->isConfirmed())
->setCssClass('btn btn-secondary text-dark');

$mathematically_correct_action = Action::new('mathematicallyCorrect', 'payment_order.action.mathematically_correct', 'fas fa-check')
->linkToCrudAction('checkMathematicallyCorrect')
->linkToRoute('payment_order_check', fn (PaymentOrder $paymentOrder) => ['type' => 'mathematically_correct', 'id' => $paymentOrder->getId()])
->displayIf(fn(PaymentOrder $paymentOrder): bool => $this->isGranted('ROLE_PO_MATHEMATICALLY')
&& $paymentOrder->isConfirmed()
&& !$paymentOrder->isMathematicallyCorrect())
&& !$paymentOrder->isMathematicallyCorrectChecked())
->setCssClass('btn btn-success');

$factually_correct_action = Action::new('factuallyCorrect', 'payment_order.action.factually_correct', 'fas fa-check')
->linkToCrudAction('checkFactuallyCorrect')
->linkToRoute('payment_order_check', fn (PaymentOrder $paymentOrder) => ['type' => 'factually_correct', 'id' => $paymentOrder->getId()])
->displayIf(fn(PaymentOrder $paymentOrder): bool => $this->isGranted('ROLE_PO_FACTUALLY')
&& $paymentOrder->isConfirmed()
&& !$paymentOrder->isFactuallyCorrect()
&& $paymentOrder->isMathematicallyCorrect())
&& !$paymentOrder->isFactuallyCorrectChecked()
&& $paymentOrder->isMathematicallyCorrectChecked())
->setCssClass('btn btn-success');

$manual_confirmation = Action::new('manual_confirmation', 'payment_order.action.manual_confirmation', 'fas fa-exclamation-triangle')
Expand All @@ -356,8 +327,6 @@ public function configureActions(Actions $actions): Actions
$actions->add(Crud::PAGE_EDIT, $emailAction);
$actions->add(Crud::PAGE_DETAIL, $emailAction);

$actions->add(Crud::PAGE_EDIT, $hhv_action);
$actions->add(Crud::PAGE_DETAIL, $hhv_action);

$actions->disable(Crud::PAGE_NEW);

Expand Down Expand Up @@ -430,16 +399,16 @@ public function configureFields(string $pageName): iterable
//$creationDate = TextField::new('creation_date', 'creation_date');

//Status informations
$statusPanel = FormField::addPanel('payment_order.group.status');
$mathematicallyCorrect = BooleanField::new('mathematically_correct', 'payment_order.mathematically_correct.label')
$statusPanel = FormField::addFieldset('payment_order.group.status');
$mathematicallyCorrect = BooleanField::new('mathematically_correct.checked', 'payment_order.mathematically_correct.label')
->setHelp('payment_order.mathematically_correct.help')
//Disable fields (and show coloumns as read only tags) if user does not have proper permissions to change
//factually and mathematically correct status
->setFormTypeOption('disabled', !$this->isGranted('ROLE_PO_MATHEMATICALLY'))
->renderAsSwitch($this->isGranted('ROLE_PO_MATHEMATICALLY'));
$exported = BooleanField::new('exported', 'payment_order.exported.label')
->setHelp('payment_order.exported.help');
$factuallyCorrect = BooleanField::new('factually_correct', 'payment_order.factually_correct.label')
$factuallyCorrect = BooleanField::new('factually_correct.checked', 'payment_order.factually_correct.label')
->setHelp('payment_order.factually_correct.help')
->setFormTypeOption('disabled', !$this->isGranted('ROLE_PO_FACTUALLY'))
->renderAsSwitch($this->isGranted('ROLE_PO_FACTUALLY'));
Expand All @@ -452,14 +421,14 @@ public function configureFields(string $pageName): iterable
$references_exported = BooleanField::new('references_exported', 'payment_order.references_exported.label');

//Payee informations
$payeePanel = FormField::addPanel('payment_order.group.receiver');
$payeePanel = FormField::addFieldset('payment_order.group.receiver');
$bankInfoAccountOwner = TextField::new('bank_info.account_owner', 'bank_info.account_owner.label');
$bankInfoStreet = TextField::new('bank_info.street', 'bank_info.street.label');
$bankInfoZipCode = TextField::new('bank_info.zip_code', 'bank_info.zip_code.label');
$bankInfoCity = TextField::new('bank_info.city', 'bank_info.city.label');

//Payee bank account infos
$bankInfoPanel = FormField::addPanel('payment_order.group.bank_info');
$bankInfoPanel = FormField::addFieldset('payment_order.group.bank_info');
$bankInfoIban = TextField::new('bank_info.iban', 'bank_info.iban.label');
$bankInfoBic = TextField::new('bank_info.bic', 'bank_info.bic.label')
->setRequired(false)
Expand Down Expand Up @@ -515,21 +484,21 @@ public function configureFields(string $pageName): iterable
FormField::addTab('payment_order.tab.status', 'fas fa-list-check'),
//Status infos
FormField::addColumn(),
FormField::addPanel('payment_order.section.status.confirmation'),
FormField::addFieldset('payment_order.section.status.confirmation'),
BooleanField::new('confirmed', 'payment_order.confirmed.label'),
$requiredConfirmations,
$confirmation1,
$confirmation2,

FormField::addColumn(),
FormField::addPanel('payment_order.section.status.review'),
$mathematicallyCorrect,
FormField::addFieldset('payment_order.section.status.review'),
CheckField::new('mathematically_correct', 'payment_order.mathematically_correct.label'),
CheckField::new('factually_correct', 'payment_order.factually_correct.label'),
$exported,
$factuallyCorrect,
$booking_date,
$references_exported,

FormField::addPanel('payment_order.section.edited_fields'),
FormField::addFieldset('payment_order.section.edited_fields'),
FieldChangesField::new('field_changes', ""),

];
Expand Down
Loading

0 comments on commit b9c66d0

Please sign in to comment.