From 256dc0570fbf4f46f24cee8a8c663c4f9e99f388 Mon Sep 17 00:00:00 2001 From: Adam Daley Date: Sat, 21 Mar 2026 19:13:49 +0000 Subject: [PATCH] Remove client-side invoice deletion and add unpaid invoice button (#3356) * Remove client-side invoice delete feature - Remove delete() method from Invoice Client API - Remove deleteInvoiceByClient() from Invoice Service - Remove client delete button from admin invoice template - Remove related test methods * Add Delete button for unpaid invoices --- src/modules/Invoice/Api/Client.php | 19 ------ src/modules/Invoice/Service.php | 18 ----- .../admin/mod_invoice_invoice.html.twig | 10 +-- .../modules/Invoice/Api/ClientTest.php | 31 --------- tests-legacy/modules/Invoice/ServiceTest.php | 65 ------------------- 5 files changed, 5 insertions(+), 138 deletions(-) diff --git a/src/modules/Invoice/Api/Client.php b/src/modules/Invoice/Api/Client.php index 2465b1b2b..31fa774e2 100644 --- a/src/modules/Invoice/Api/Client.php +++ b/src/modules/Invoice/Api/Client.php @@ -133,25 +133,6 @@ class Client extends \Api_Abstract return $invoice->hash; } - /** - * Client removes unpaid invoice. - * - * @return bool - * - * @throws \FOSSBilling\Exception - */ - #[RequiredParams(['hash' => 'Invoice hash was not passed'])] - public function delete($data) - { - $identity = $this->getIdentity(); - $model = $this->di['db']->findOne('Invoice', 'hash = :hash AND client_id = :client_id', ['hash' => $data['hash'], 'client_id' => $identity->id]); - if (!$model) { - throw new \FOSSBilling\Exception('Invoice was not found'); - } - - return $this->getService()->deleteInvoiceByClient($model); - } - /** * Get paginated list of transactions. * diff --git a/src/modules/Invoice/Service.php b/src/modules/Invoice/Service.php index 04670e3e6..6ede6b5da 100644 --- a/src/modules/Invoice/Service.php +++ b/src/modules/Invoice/Service.php @@ -964,24 +964,6 @@ class Service implements InjectionAwareInterface return true; } - public function deleteInvoiceByClient(\Model_Invoice $model): bool - { - $this->di['events_manager']->fire(['event' => 'onBeforeClientInvoiceDelete', 'params' => ['id' => $model->id]]); - - // check if invoice is associated with order - $invoiceItem = $this->di['db']->find('InvoiceItem', 'invoice_id = ?', [$model->id]); - foreach ($invoiceItem as $item) { - if ($item->type == \Model_InvoiceItem::TYPE_ORDER) { - throw new InformationException('Invoice is related to order #:id. Please cancel order first.', [':id' => $item->rel_id]); - } - } - - $this->rmInvoice($model); - $this->di['logger']->info("Removed invoice #{$model->id}."); - - return true; - } - public function renewInvoice(\Model_ClientOrder $model, array $data) { $this->di['events_manager']->fire(['event' => 'onBeforeAdminGenerateRenewalInvoice', 'params' => ['order_id' => $model->id]]); diff --git a/src/modules/Invoice/templates/admin/mod_invoice_invoice.html.twig b/src/modules/Invoice/templates/admin/mod_invoice_invoice.html.twig index 453f3d402..b88451b9e 100644 --- a/src/modules/Invoice/templates/admin/mod_invoice_invoice.html.twig +++ b/src/modules/Invoice/templates/admin/mod_invoice_invoice.html.twig @@ -700,11 +700,11 @@
- {% if invoice.status == 'unpaid' %} - - {{ 'Delete'|trans }} - {% endif %} + {% if invoice.status == 'unpaid' %} + + {{ 'Delete'|trans }} + {% endif %}
{% endblock %} diff --git a/tests-legacy/modules/Invoice/Api/ClientTest.php b/tests-legacy/modules/Invoice/Api/ClientTest.php index 2d999e05d..9f7738646 100644 --- a/tests-legacy/modules/Invoice/Api/ClientTest.php +++ b/tests-legacy/modules/Invoice/Api/ClientTest.php @@ -265,37 +265,6 @@ final class ClientTest extends \BBTestCase $this->assertEquals($generatedHash, $result); } - public function testDelete(): void - { - $serviceMock = $this->createMock(\Box\Mod\Invoice\Service::class); - $serviceMock->expects($this->atLeastOnce()) - ->method('deleteInvoiceByClient') - ->willReturn(true); - - $dbMock = $this->createMock('\Box_Database'); - $model = new \Model_Invoice(); - $model->loadBean(new \DummyBean()); - - $dbMock->expects($this->atLeastOnce()) - ->method('findOne') - ->willReturn($model); - - $di = $this->getDi(); - $di['db'] = $dbMock; - $di['logger'] = new \Box_Log(); - - $this->api->setDi($di); - $this->api->setService($serviceMock); - $identity = new \Model_Client(); - $identity->loadBean(new \DummyBean()); - $this->api->setIdentity($identity); - - $data['hash'] = md5('1'); - $result = $this->api->delete($data); - $this->assertIsBool($result); - $this->assertTrue($result); - } - public function testTransactionGetList(): void { $transactionService = $this->createMock(\Box\Mod\Invoice\ServiceTransaction::class); diff --git a/tests-legacy/modules/Invoice/ServiceTest.php b/tests-legacy/modules/Invoice/ServiceTest.php index 1326b710a..ccd666864 100644 --- a/tests-legacy/modules/Invoice/ServiceTest.php +++ b/tests-legacy/modules/Invoice/ServiceTest.php @@ -957,71 +957,6 @@ final class ServiceTest extends \BBTestCase $this->assertTrue($result); } - public function testDeleteInvoiceByClient(): void - { - $invoiceItemModel = new \Model_InvoiceItem(); - $invoiceItemModel->loadBean(new \DummyBean()); - - $serviceMock = $this->getMockBuilder(Service::class) - ->onlyMethods(['rmInvoice']) - ->getMock(); - $serviceMock->expects($this->once()) - ->method('rmInvoice'); - - $invoiceModel = new \Model_Invoice(); - $invoiceModel->loadBean(new \DummyBean()); - - $eventManagerMock = $this->createMock('\Box_EventManager'); - $eventManagerMock->expects($this->atLeastOnce()) - ->method('fire'); - - $dbMock = $this->createMock('\Box_Database'); - $dbMock->expects($this->atLeastOnce()) - ->method('find') - ->willReturn([$invoiceItemModel]); - - $di = $this->getDi(); - $di['db'] = $dbMock; - $di['events_manager'] = $eventManagerMock; - $di['logger'] = new \Box_Log(); - - $serviceMock->setDi($di); - - $result = $serviceMock->deleteInvoiceByClient($invoiceModel); - $this->assertTrue($result); - } - - public function testDeleteInvoiceByClientInvoiceIsRelatedToOrder(): void - { - $invoiceItemModel = new \Model_InvoiceItem(); - $invoiceItemModel->loadBean(new \DummyBean()); - $invoiceItemModel->type = \Model_InvoiceItem::TYPE_ORDER; - $rel_id = 1; - $invoiceItemModel->rel_id = $rel_id; - - $invoiceModel = new \Model_Invoice(); - $invoiceModel->loadBean(new \DummyBean()); - - $eventManagerMock = $this->createMock('\Box_EventManager'); - $eventManagerMock->expects($this->atLeastOnce()) - ->method('fire'); - - $dbMock = $this->createMock('\Box_Database'); - $dbMock->expects($this->atLeastOnce()) - ->method('find') - ->willReturn([$invoiceItemModel]); - - $di = $this->getDi(); - $di['db'] = $dbMock; - $di['events_manager'] = $eventManagerMock; - - $this->service->setDi($di); - - $this->expectException(\FOSSBilling\Exception::class); - $this->expectExceptionMessage(sprintf('Invoice is related to order #%d. Please cancel order first.', $rel_id)); - $this->service->deleteInvoiceByClient($invoiceModel); - } - public function testRenewInvoice(): void { $newId = 2;