mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-12-06 15:14:20 +09:00
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
This commit is contained in:
1 parent
f3e32ec43a
commit
256dc0570f
5 files changed
+5
-138
No files matched your search
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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]]);
|
||||
|
||||
@@ -700,11 +700,11 @@
|
||||
<div class="block">
|
||||
<button class="btn btn-primary" type="button" onclick="window.print()">
|
||||
<span class="dark-icon i-print"></span> {{ 'Print'|trans }}</button>
|
||||
{% if invoice.status == 'unpaid' %}
|
||||
<a class="btn btn-primary" href="{{ 'api/client/invoice/delete'|link({ 'hash': invoice.hash }) }}"
|
||||
{{ fb_api_link({modal: {type: 'confirm', title: 'Are you sure?'|trans}, redirect: 'invoice'|alink}) }}>
|
||||
<span class="dark-icon i-bin"></span> {{ 'Delete'|trans }}</a>
|
||||
{% endif %}
|
||||
{% if invoice.status == 'unpaid' %}
|
||||
<a class="btn btn-primary" href="{{ 'api/admin/invoice/delete'|link({ 'id': id.hash }) }}"
|
||||
{{ fb_api_link({modal: {type: 'confirm', title: 'Are you sure?'|trans}, redirect: 'invoice'|alink}) }}>
|
||||
<span class="dark-icon i-bin"></span> {{ 'Delete'|trans }}</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user