added new invoice status: canceled (#2922)
This commit is contained in:
@@ -144,6 +144,7 @@ class ExportController extends AbstractController
|
||||
/**
|
||||
* @param ExportQuery $query
|
||||
* @return ExportItemInterface[]
|
||||
* @throws TooManyItemsExportException
|
||||
*/
|
||||
protected function getEntries(ExportQuery $query): array
|
||||
{
|
||||
|
||||
@@ -37,6 +37,7 @@ class Invoice
|
||||
{
|
||||
public const STATUS_PENDING = 'pending';
|
||||
public const STATUS_PAID = 'paid';
|
||||
public const STATUS_CANCELED = 'canceled';
|
||||
public const STATUS_NEW = 'new';
|
||||
|
||||
/**
|
||||
@@ -306,6 +307,16 @@ class Invoice
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isCanceled(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_CANCELED;
|
||||
}
|
||||
|
||||
public function setIsCanceled(): void
|
||||
{
|
||||
$this->status = self::STATUS_CANCELED;
|
||||
}
|
||||
|
||||
public function getDueDays(): int
|
||||
{
|
||||
return $this->dueDays;
|
||||
|
||||
@@ -30,12 +30,18 @@ class InvoiceSubscriber extends AbstractActionsSubscriber
|
||||
return;
|
||||
}
|
||||
|
||||
if ($invoice->isNew() || $invoice->isPaid()) {
|
||||
if (!$invoice->isPending()) {
|
||||
$event->addAction('invoice.pending', ['url' => $this->path('admin_invoice_status', ['id' => $invoice->getId(), 'status' => 'pending'])]);
|
||||
} elseif ($invoice->isPending()) {
|
||||
} else {
|
||||
$event->addAction('invoice.paid', ['url' => $this->path('admin_invoice_status', ['id' => $invoice->getId(), 'status' => 'paid']), 'class' => 'modal-ajax-form']);
|
||||
}
|
||||
|
||||
if (!$invoice->isCanceled()) {
|
||||
$event->addAction('invoice.cancel', ['url' => $this->path('admin_invoice_status', ['id' => $invoice->getId(), 'status' => 'canceled'])]);
|
||||
}
|
||||
|
||||
$event->addDivider();
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -239,10 +239,6 @@ final class ServiceInvoice
|
||||
|
||||
public function changeInvoiceStatus(Invoice $invoice, string $status)
|
||||
{
|
||||
if (!\in_array($status, [Invoice::STATUS_NEW, Invoice::STATUS_PENDING, Invoice::STATUS_PAID])) {
|
||||
throw new \InvalidArgumentException('Unknown invoice status');
|
||||
}
|
||||
|
||||
switch ($status) {
|
||||
case Invoice::STATUS_NEW:
|
||||
$invoice->setIsNew();
|
||||
@@ -255,6 +251,13 @@ final class ServiceInvoice
|
||||
case Invoice::STATUS_PAID:
|
||||
$invoice->setIsPaid();
|
||||
break;
|
||||
|
||||
case Invoice::STATUS_CANCELED:
|
||||
$invoice->setIsCanceled();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \InvalidArgumentException('Unknown invoice status');
|
||||
}
|
||||
|
||||
$this->invoiceRepository->saveInvoice($invoice);
|
||||
|
||||
Reference in New Issue
Block a user