Skip to content

Commit fff3959

Browse files
committed
Added possibility to export payment orders as CSV files
1 parent 1a4f677 commit fff3959

File tree

8 files changed

+233
-13
lines changed

8 files changed

+233
-13
lines changed

src/Controller/Admin/PaymentOrderCrudController.php

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use App\Helpers\ZIPBinaryFileResponseFacade;
3434
use App\Message\PaymentOrder\PaymentOrderDeletedNotification;
3535
use App\Services\EmailConfirmation\ConfirmationEmailSender;
36+
use App\Services\PaymentOrder\CSVExporter;
3637
use App\Services\PaymentOrderMailLinkGenerator;
3738
use App\Services\PaymentReferenceGenerator;
3839
use Doctrine\ORM\EntityManagerInterface;
@@ -65,6 +66,8 @@
6566
use EasyCorp\Bundle\EasyAdminBundle\Registry\DashboardControllerRegistry;
6667
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
6768
use RuntimeException;
69+
use Symfony\Component\HttpFoundation\BinaryFileResponse;
70+
use Symfony\Component\HttpFoundation\HeaderUtils;
6871
use Symfony\Component\HttpFoundation\Response;
6972
use Symfony\Component\Messenger\MessageBusInterface;
7073

@@ -74,11 +77,12 @@ final class PaymentOrderCrudController extends AbstractCrudController
7477
{
7578
public function __construct(
7679
private readonly PaymentOrderMailLinkGenerator $mailToGenerator,
77-
private EntityManagerInterface $entityManager,
80+
private readonly EntityManagerInterface $entityManager,
7881
private readonly ConfirmationEmailSender $confirmationEmailSender,
7982
private readonly AdminUrlGenerator $adminURLGenerator,
8083
private readonly MessageBusInterface $messageBus,
8184
private readonly PaymentReferenceGenerator $paymentReferenceGenerator,
85+
private readonly CSVExporter $CSVExporter,
8286
)
8387
{
8488
}
@@ -88,6 +92,24 @@ public static function getEntityFqcn(): string
8892
return PaymentOrder::class;
8993
}
9094

95+
#[AdminAction(routePath: '/action-csv-export', routeName: 'admin_action_payment_order_csv_export', methods: ['POST'])]
96+
public function csvExport(BatchActionDto $batchActionDto): Response
97+
{
98+
$this->denyAccessUnlessGranted('ROLE_SHOW_PAYMENT_ORDERS');
99+
100+
$entities = $this->entityManager->getRepository(PaymentOrder::class)->findBy(['id' => $batchActionDto->getEntityIds()]);
101+
102+
$csv = $this->CSVExporter->export($entities);
103+
$response = new Response($csv);
104+
$response->headers->set('Content-type', 'text/csv');
105+
$response->headers->set('Content-length', (string) strlen($csv));
106+
$response->headers->set('Cache-Control', 'private');
107+
$disposition = HeaderUtils::makeDisposition("attachment", "payment_orders.csv", "payment_orders.csv");
108+
$response->headers->set('Content-Disposition', $disposition);
109+
110+
return $response;
111+
}
112+
91113
#[AdminAction(routePath: '/action-sepa-xml-export', routeName: 'admin_action_payment_order_sepa_xml_export', methods: ['POST'])]
92114
public function sepaXMLExport(BatchActionDto $batchActionDto): Response
93115
{
@@ -165,9 +187,9 @@ public function configureCrud(Crud $crud): Crud
165187
return $crud
166188

167189
//Set validation groups for new and edit forms
168-
->setFormOptions([
169-
'validation_groups' => ['Default', 'backend'],
170-
])
190+
->setFormOptions([
191+
'validation_groups' => ['Default', 'backend'],
192+
])
171193

172194
->setEntityLabelInSingular('payment_order.label')
173195
->setEntityLabelInPlural('payment_order.labelp')
@@ -250,17 +272,30 @@ public function configureActions(Actions $actions): Actions
250272
}
251273

252274
//if ($this->isGranted('ROLE_EXPORT_PAYMENT_ORDERS_REFERENCES')) {
253-
$actions->addBatchAction(Action::new('referencesExport', 'payment.order.action.export.export_references')
254-
->linkToCrudAction('referencesExport')
255-
->addCssClass('btn btn-primary')
256-
//Together with some backend.js logic, this attribute will prevent the modal from showing
257-
->setHtmlAttributes([
258-
'data-action-batch-no-confirm' => 'true',
259-
])
260-
->setIcon('fas fa-file-invoice')
261-
);
275+
$actions->addBatchAction(Action::new('referencesExport', 'payment.order.action.export.export_references')
276+
->linkToCrudAction('referencesExport')
277+
->addCssClass('btn btn-primary')
278+
//Together with some backend.js logic, this attribute will prevent the modal from showing
279+
->setHtmlAttributes([
280+
'data-action-batch-no-confirm' => 'true',
281+
])
282+
->setIcon('fas fa-file-invoice')
283+
);
262284
//}
263285

286+
if ($this->isGranted('ROLE_EXPORT_PAYMENT_ORDERS')) {
287+
$actions->addBatchAction(Action::new('csvExport', 'CSV Export')
288+
->linkToCrudAction('csvExport')
289+
->addCssClass('btn btn-secondary')
290+
//Together with some backend.js logic, this attribute will prevent the modal from showing
291+
->setHtmlAttributes([
292+
'data-action-batch-no-confirm' => 'true',
293+
])
294+
->setIcon('fas fa-file-csv')
295+
);
296+
}
297+
298+
264299
$actions->setPermissions([
265300
Action::INDEX => 'ROLE_SHOW_PAYMENT_ORDERS',
266301
Action::DETAIL => 'ROLE_SHOW_PAYMENT_ORDERS',

src/Entity/Department.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
use Doctrine\DBAL\Types\Types;
2828
use Doctrine\ORM\Mapping as ORM;
2929
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
30+
use Symfony\Component\Serializer\Attribute\Groups;
31+
use Symfony\Component\Serializer\Attribute\SerializedName;
3032
use Symfony\Component\Validator\Constraints as Assert;
3133

3234
/**
@@ -50,6 +52,8 @@ class Department implements DBElementInterface, NamedElementInterface, Timestamp
5052

5153

5254
#[ORM\Column(type: Types::STRING)]
55+
#[Groups('csv_export')]
56+
#[SerializedName("Name")]
5357
private string $name = '';
5458

5559

src/Entity/Embeddable/Check.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,50 @@
77

88
use Doctrine\DBAL\Types\Types;
99
use Doctrine\ORM\Mapping as ORM;
10+
use Symfony\Component\Serializer\Attribute\Groups;
11+
use Symfony\Component\Serializer\Attribute\SerializedName;
1012

1113
/**
1214
* This embeddable contains all information about a check (the checks done by the StuRa Finance members).
1315
*/
1416
#[ORM\Embeddable]
1517
class Check
1618
{
19+
#[Groups('csv_export')]
20+
#[SerializedName("Geprüft?")]
1721
#[ORM\Column(type: Types::BOOLEAN)]
1822
private bool $checked = false;
1923

2024
/**
2125
* @var \DateTime|null The timestamp of the confirmation. Null if not confirmed, or if legacy data.
2226
*/
2327
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
28+
#[Groups('csv_export')]
29+
#[SerializedName("Prüfzeitpunkt")]
2430
private ?\DateTime $timestamp = null;
2531

2632
/**
2733
* @var string|null The name of the person who confirmed the confirmation. Null if not confirmed
2834
*/
2935
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
36+
#[Groups('csv_export')]
37+
#[SerializedName("Prüfer")]
3038
private ?string $confirmerName = null;
3139

3240
/**
3341
* @var int|null The ID of the user who confirmed this check. Null if not confirmed (or if legacy data)
3442
*/
3543
#[ORM\Column(type: Types::INTEGER, nullable: true)]
44+
#[Groups('csv_export')]
45+
#[SerializedName("Benutzer ID")]
3646
private ?int $confirmerID = null;
3747

3848
/**
3949
* @var string|null An optional remark about the confirmation
4050
*/
4151
#[ORM\Column(type: Types::TEXT, nullable: true)]
52+
#[Groups('csv_export')]
53+
#[SerializedName("Anmerkung")]
4254
private ?string $remark = null;
4355

4456
public function isChecked(): bool

src/Entity/Embeddable/Confirmation.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use App\Entity\ConfirmationToken;
88
use Doctrine\DBAL\Types\Types;
99
use Doctrine\ORM\Mapping as ORM;
10+
use Symfony\Component\Serializer\Attribute\Groups;
11+
use Symfony\Component\Serializer\Attribute\SerializedName;
1012

1113
/**
1214
* This embeddable contains all information about a confirmation
@@ -18,13 +20,17 @@ class Confirmation
1820
/**
1921
* @var \DateTime|null The timestamp of the confirmation. Null if not confirmed.
2022
*/
23+
#[Groups('csv_export')]
24+
#[SerializedName("Bestätigungszeitpunkt")]
2125
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
2226
private ?\DateTime $timestamp = null;
2327

2428
/**
2529
* @var string|null The name of the person who confirmed the confirmation. Null if not confirmed
2630
*/
2731
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
32+
#[Groups('csv_export')]
33+
#[SerializedName("Bestätiger")]
2834
private ?string $confirmerName = null;
2935

3036
/**
@@ -34,18 +40,24 @@ class Confirmation
3440
private ?int $confirmationTokenID = null;
3541

3642
#[ORM\Column(type: Types::INTEGER, nullable: true)]
43+
#[Groups('csv_export')]
44+
#[SerializedName("Bestätiger ID")]
3745
private ?int $confirmerID = null;
3846

3947
/**
4048
* @var bool Whether the confirmation was overridden by an StuRa Finance member
4149
*/
4250
#[ORM\Column(type: Types::BOOLEAN)]
51+
#[Groups('csv_export')]
52+
#[SerializedName("Überschrieben?")]
4353
private bool $confirmationOverriden = false;
4454

4555
/**
4656
* @var string|null An optional remark about the confirmation
4757
*/
4858
#[ORM\Column(type: Types::TEXT, nullable: true)]
59+
#[Groups('csv_export')]
60+
#[SerializedName("Anmerkung")]
4961
private ?string $remark = null;
5062

5163
public function isConfirmed(): bool

src/Entity/Embeddable/PayeeInfo.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
use Doctrine\DBAL\Types\Types;
2222
use Doctrine\ORM\Mapping as ORM;
23+
use Symfony\Component\Serializer\Attribute\Groups;
24+
use Symfony\Component\Serializer\Attribute\SerializedName;
2325
use Symfony\Component\Validator\Constraints as Assert;
2426

2527
/**
@@ -33,35 +35,51 @@ class PayeeInfo
3335

3436
#[Assert\NotBlank]
3537
#[ORM\Column(type: Types::STRING)]
38+
#[Groups('csv_export')]
39+
#[SerializedName("Name")]
3640
private string $account_owner = '';
3741

3842
#[Assert\NotBlank]
3943
#[ORM\Column(type: Types::STRING)]
44+
#[Groups('csv_export')]
45+
#[SerializedName("Straße")]
4046
private string $street = '';
4147

4248
#[Assert\NotBlank]
4349
#[ORM\Column(type: Types::STRING)]
50+
#[Groups('csv_export')]
51+
#[SerializedName("PLZ")]
4452
private string $zip_code = '';
4553

4654
#[Assert\NotBlank]
4755
#[ORM\Column(type: Types::STRING)]
56+
#[Groups('csv_export')]
57+
#[SerializedName("Stadt")]
4858
private string $city = '';
4959

5060
#[ORM\Column(type: Types::STRING)]
5161
#[Assert\NotBlank()]
5262
#[Assert\Iban]
63+
#[Groups('csv_export')]
64+
#[SerializedName("IBAN")]
5365
private string $iban = '';
5466

5567
#[ORM\Column(type: Types::STRING)]
5668
#[Assert\Bic(ibanPropertyPath: 'iban')]
69+
#[Groups('csv_export')]
70+
#[SerializedName("BIC")]
5771
private string $bic = '';
5872

5973
#[Assert\NotBlank]
6074
#[ORM\Column(type: Types::STRING)]
75+
#[Groups('csv_export')]
76+
#[SerializedName("Bankname")]
6177
private string $bank_name = '';
6278

6379
#[ORM\Column(type: Types::STRING)]
6480
#[Assert\Length(max: 140)]
81+
#[Groups('csv_export')]
82+
#[SerializedName("Verwendungszweck")]
6583
private ?string $reference = '';
6684

6785
public function __construct()

0 commit comments

Comments
 (0)