/
InvoiceSubscriber.php
42 lines (33 loc) · 1.38 KB
/
InvoiceSubscriber.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\EventSubscriber\Actions;
use App\Entity\Invoice;
use App\Event\PageActionsEvent;
class InvoiceSubscriber extends AbstractActionsSubscriber
{
public static function getActionName(): string
{
return 'invoice';
}
public function onActions(PageActionsEvent $event): void
{
$payload = $event->getPayload();
/** @var Invoice $invoice */
$invoice = $payload['invoice'];
if ($invoice->getId() === null) {
return;
}
if ($invoice->isNew() || $invoice->isPaid()) {
$event->addAction('invoice.pending', ['url' => $this->path('admin_invoice_status', ['id' => $invoice->getId(), 'status' => 'pending'])]);
} elseif ($invoice->isPending()) {
$event->addAction('invoice.paid', ['url' => $this->path('admin_invoice_status', ['id' => $invoice->getId(), 'status' => 'paid']), 'class' => 'modal-ajax-form']);
}
$event->addAction('download', ['url' => $this->path('admin_invoice_download', ['id' => $invoice->getId()]), 'target' => '_blank']);
$event->addDelete($this->path('admin_invoice_delete', ['id' => $invoice->getId(), 'token' => $payload['token']]), false);
}
}