added copy invoice template action (#331)
This commit is contained in:
@@ -76,7 +76,7 @@ class InvoiceController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/", name="invoice", methods={"GET"})
|
||||
* @Route(path="/", name="invoice", methods={"GET", "POST"})
|
||||
* @Security("is_granted('view', 'invoice')")
|
||||
*
|
||||
* @param Request $request
|
||||
@@ -110,7 +110,7 @@ class InvoiceController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/print", name="invoice_print", methods={"GET"})
|
||||
* @Route(path="/print", name="invoice_print", methods={"GET", "POST"})
|
||||
* @Security("is_granted('create', 'invoice')")
|
||||
*
|
||||
* @param Request $request
|
||||
@@ -242,19 +242,37 @@ class InvoiceController extends AbstractController
|
||||
|
||||
/**
|
||||
* @Route(path="/template/create", name="admin_invoice_template_create", methods={"GET", "POST"})
|
||||
* @Route(path="/template/create/{id}", name="admin_invoice_template_copy", methods={"GET", "POST"})
|
||||
* @Security("is_granted('create', 'invoice_template')")
|
||||
*
|
||||
* @param Request $request
|
||||
* @param InvoiceTemplate|null $template
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createTemplateAction(Request $request)
|
||||
public function createTemplateAction(Request $request, ?InvoiceTemplate $copyFrom)
|
||||
{
|
||||
if (!$this->invoiceRepository->hasTemplate()) {
|
||||
$this->flashWarning('invoice.first_template');
|
||||
}
|
||||
|
||||
return $this->renderTemplateForm(new InvoiceTemplate(), $request);
|
||||
$template = new InvoiceTemplate();
|
||||
if (null !== $copyFrom) {
|
||||
$template
|
||||
->setName('Copy of ' . $copyFrom->getName())
|
||||
->setTitle($copyFrom->getTitle())
|
||||
->setDueDays($copyFrom->getDueDays())
|
||||
->setCalculator($copyFrom->getCalculator())
|
||||
->setVat($copyFrom->getVat())
|
||||
->setRenderer($copyFrom->getRenderer())
|
||||
->setCompany($copyFrom->getCompany())
|
||||
->setPaymentTerms($copyFrom->getPaymentTerms())
|
||||
->setAddress($copyFrom->getAddress())
|
||||
->setNumberGenerator($copyFrom->getNumberGenerator())
|
||||
;
|
||||
}
|
||||
|
||||
return $this->renderTemplateForm($template, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -315,7 +333,7 @@ class InvoiceController extends AbstractController
|
||||
{
|
||||
return $this->createForm(InvoiceToolbarForm::class, $query, [
|
||||
'action' => $this->generateUrl('invoice', []),
|
||||
'method' => 'GET',
|
||||
'method' => 'POST',
|
||||
'attr' => [
|
||||
'id' => 'invoice-print-form'
|
||||
]
|
||||
|
||||
@@ -59,6 +59,7 @@ class Extensions extends \Twig_Extension
|
||||
'admin' => 'fas fa-wrench',
|
||||
'calendar' => 'far fa-calendar-alt',
|
||||
'customer' => 'fas fa-users',
|
||||
'copy' => 'far fa-copy',
|
||||
'create' => 'far fa-plus-square',
|
||||
'dashboard' => 'fas fa-tachometer-alt',
|
||||
'delete' => 'far fa-trash-alt',
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
<td class="hidden-xs hidden-sm">{{ entry.vat }}</td>
|
||||
<td>
|
||||
{% set actionButtons = {'edit': path('admin_invoice_template_edit', {'id' : entry.id, 'page': page})} %}
|
||||
{% set actionButtons = actionButtons|merge({'copy': path('admin_invoice_template_copy', {'id' : entry.id, 'page': page})}) %}
|
||||
{% set actionButtons = actionButtons|merge({'trash': path('admin_invoice_template_delete', {'id' : entry.id, 'page': page})}) %}
|
||||
{{ widgets.button_group(actionButtons) }}
|
||||
</td>
|
||||
|
||||
@@ -88,6 +88,34 @@ class InvoiceControllerTest extends ControllerBaseTest
|
||||
$this->assertHasFlashSuccess($client);
|
||||
}
|
||||
|
||||
public function testCopyTemplateAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
$fixture = new InvoiceFixtures();
|
||||
$this->importFixture($em, $fixture);
|
||||
|
||||
/** @var InvoiceTemplate $template */
|
||||
$template = $em->getRepository(InvoiceTemplate::class)->find(1);
|
||||
|
||||
$this->request($client, '/invoice/template/create/1');
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$form = $client->getCrawler()->filter('form[name=invoice_template_form]')->form();
|
||||
$values = $form->getPhpValues()['invoice_template_form'];
|
||||
$this->assertEquals('Copy of ' . $template->getName(), $values['name']);
|
||||
$this->assertEquals($template->getTitle(), $values['title']);
|
||||
$this->assertEquals($template->getDueDays(), $values['dueDays']);
|
||||
$this->assertEquals($template->getCalculator(), $values['calculator']);
|
||||
$this->assertEquals($template->getVat(), $values['vat']);
|
||||
$this->assertEquals($template->getRenderer(), $values['renderer']);
|
||||
$this->assertEquals($template->getCompany(), $values['company']);
|
||||
$this->assertEquals($template->getAddress(), $values['address']);
|
||||
$this->assertEquals($template->getPaymentTerms(), $values['paymentTerms']);
|
||||
$this->assertEquals($template->getNumberGenerator(), $values['numberGenerator']);
|
||||
}
|
||||
|
||||
public function testPrintAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
|
||||
@@ -180,7 +180,7 @@ class ExtensionsTest extends TestCase
|
||||
$icons = [
|
||||
'user', 'customer', 'project', 'activity', 'admin', 'invoice', 'timesheet', 'dashboard', 'logout', 'trash',
|
||||
'delete', 'repeat', 'edit', 'manual', 'help', 'start', 'start-small', 'stop', 'stop-small', 'filter',
|
||||
'create', 'list', 'print', 'visibility', 'calendar', 'money', 'duration', 'download'
|
||||
'create', 'list', 'print', 'visibility', 'calendar', 'money', 'duration', 'download', 'copy'
|
||||
];
|
||||
|
||||
// test pre-defined icons
|
||||
|
||||
Reference in New Issue
Block a user