Skip to content

Commit a330134

Browse files
committed
generating new invoices
1 parent 6193a90 commit a330134

File tree

3 files changed

+82
-3
lines changed

3 files changed

+82
-3
lines changed

module/Application/config/module.config.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use CleanPhp\Invoicer\Domain\Factory\InvoiceFactory;
4+
use CleanPhp\Invoicer\Domain\Service\InvoicingService;
35
use CleanPhp\Invoicer\Service\InputFilter\CustomerInputFilter;
46
use CleanPhp\Invoicer\Service\InputFilter\OrderInputFilter;
57
use Zend\Stdlib\Hydrator\ClassMethods;
@@ -110,7 +112,11 @@
110112
'Application\Controller\Invoices' => function ($sm) {
111113
return new \Application\Controller\InvoicesController(
112114
$sm->getServiceLocator()->get('InvoiceTable'),
113-
$sm->getServiceLocator()->get('OrderTable')
115+
$sm->getServiceLocator()->get('OrderTable'),
116+
new InvoicingService(
117+
$sm->getServiceLocator()->get('OrderTable'),
118+
new InvoiceFactory()
119+
)
114120
);
115121
},
116122
'Application\Controller\Orders' => function ($sm) {

module/Application/src/Application/Controller/InvoicesController.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use CleanPhp\Invoicer\Domain\Repository\InvoiceRepositoryInterface;
66
use CleanPhp\Invoicer\Domain\Repository\OrderRepositoryInterface;
7+
use CleanPhp\Invoicer\Domain\Service\InvoicingService;
78
use Zend\Mvc\Controller\AbstractActionController;
89

910
/**
@@ -22,14 +23,24 @@ class InvoicesController extends AbstractActionController
2223
*/
2324
protected $orderRepository;
2425

26+
/**
27+
* @var InvoicingService
28+
*/
29+
protected $invoicing;
30+
2531
/**
2632
* @param InvoiceRepositoryInterface $invoices
2733
* @param OrderRepositoryInterface $orders
34+
* @param InvoicingService $invoicing
2835
*/
29-
public function __construct(InvoiceRepositoryInterface $invoices, OrderRepositoryInterface $orders)
30-
{
36+
public function __construct(
37+
InvoiceRepositoryInterface $invoices,
38+
OrderRepositoryInterface $orders,
39+
InvoicingService $invoicing
40+
) {
3141
$this->invoiceRepository = $invoices;
3242
$this->orderRepository = $orders;
43+
$this->invoicing = $invoicing;
3344
}
3445

3546
/**
@@ -53,4 +64,24 @@ public function newAction()
5364
'orders' => $this->orderRepository->getUninvoicedOrders()
5465
];
5566
}
67+
68+
/**
69+
* @return array
70+
*/
71+
public function generateAction()
72+
{
73+
$invoices = $this->invoicing->generateInvoices();
74+
75+
$this->invoiceRepository->begin();
76+
77+
foreach ($invoices as $invoice) {
78+
$this->invoiceRepository->persist($invoice);
79+
}
80+
81+
$this->invoiceRepository->commit();
82+
83+
return [
84+
'invoices' => $invoices
85+
];
86+
}
5687
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<div class="page-header">
2+
<h2>Generated Invoices</h2>
3+
</div>
4+
5+
<?php if (empty($this->invoices)): ?>
6+
<p class="text-center">
7+
<em>No invoices were generated.</em>
8+
</p>
9+
<?php else: ?>
10+
<table class="table table-striped clearfix">
11+
<thead>
12+
<tr>
13+
<th>#</th>
14+
<th>Order Number</th>
15+
<th>Invoice Date</th>
16+
<th>Customer</th>
17+
<th>Description</th>
18+
<th class="text-right">Total</th>
19+
</tr>
20+
</thead>
21+
<?php foreach ($this->invoices as $invoice): ?>
22+
<tr>
23+
<td>
24+
<a href="/invoices/view/<?= $this->escapeHtmlAttr($invoice->getId()) ?>">
25+
<?= $this->escapeHtml($invoice->getId()) ?></a>
26+
</td>
27+
<td>
28+
<?= $invoice->getInvoiceDate()->format('m/d/Y') ?>
29+
</td>
30+
<td><?= $this->escapeHtml($invoice->getOrder()->getOrderNumber()) ?></td>
31+
<td>
32+
<a href="/customers/edit/<?= $this->escapeHtmlAttr($invoice->getOrder()->getCustomer()->getId()) ?>">
33+
<?= $this->escapeHtml($invoice->getOrder()->getCustomer()->getName()) ?></a>
34+
</td>
35+
<td><?= $this->escapeHtml($invoice->getOrder()->getDescription()) ?></td>
36+
<td class="text-right">
37+
$ <?= number_format($invoice->getTotal(), 2) ?>
38+
</td>
39+
</tr>
40+
<?php endforeach; ?>
41+
</table>
42+
<?php endif; ?>

0 commit comments

Comments
 (0)