create multiple invoices at once (#2465)

This commit is contained in:
Kevin Papst
2021-03-27 20:47:53 +01:00
committed by GitHub
parent 87d07ffaaf
commit f8a5ff7315
34 changed files with 754 additions and 378 deletions

View File

@@ -18,7 +18,6 @@ use App\Invoice\ServiceInvoice;
use App\Repository\CustomerRepository;
use App\Repository\InvoiceTemplateRepository;
use App\Repository\ProjectRepository;
use App\Repository\TimesheetRepository;
use App\Repository\UserRepository;
use App\Tests\DataFixtures\CustomerFixtures;
use App\Tests\DataFixtures\InvoiceTemplateFixtures;
@@ -69,7 +68,6 @@ class InvoiceCreateCommandTest extends KernelTestCase
$this->application->add(new InvoiceCreateCommand(
$container->get(ServiceInvoice::class),
$container->get(TimesheetRepository::class),
$container->get(CustomerRepository::class),
$container->get(ProjectRepository::class),
$container->get(InvoiceTemplateRepository::class),

View File

@@ -208,7 +208,7 @@ abstract class ControllerBaseTest extends WebTestCase
*/
protected function assertDataTableRowCount(HttpKernelBrowser $client, string $id, int $count)
{
$node = $client->getCrawler()->filter('section.content div#' . $id . ' table.table-striped tbody tr:not(.summary)');
$node = $client->getCrawler()->filter('section.content div.' . $id . ' table.table-striped tbody tr:not(.summary)');
self::assertEquals($count, $node->count());
}
@@ -346,7 +346,7 @@ abstract class ControllerBaseTest extends WebTestCase
* @param HttpKernelBrowser $client
* @param string $url
*/
protected function assertIsRedirect(HttpKernelBrowser $client, $url = null)
protected function assertIsRedirect(HttpKernelBrowser $client, $url = null, $endsWith = true)
{
self::assertTrue($client->getResponse()->isRedirect(), 'Response is not a redirect');
if (null === $url) {
@@ -354,7 +354,19 @@ abstract class ControllerBaseTest extends WebTestCase
}
self::assertTrue($client->getResponse()->headers->has('Location'), 'Could not find "Location" header');
self::assertStringEndsWith($url, $client->getResponse()->headers->get('Location'), 'Redirect URL does not match');
if ($endsWith) {
self::assertStringEndsWith(
$url,
$client->getResponse()->headers->get('Location'),
'Redirect URL does not match'
);
} else {
self::assertStringContainsString(
$url,
$client->getResponse()->headers->get('Location'),
'Redirect URL does not match'
);
}
}
protected function assertExcelExportResponse(HttpKernelBrowser $client, string $prefix)

View File

@@ -73,7 +73,7 @@ class InvoiceControllerTest extends ControllerBaseTest
$templates = $this->importFixture($fixture);
$id = $templates[0]->getId();
$this->request($client, '/invoice/?customer=1&template=' . $id . '&preview=');
$this->request($client, '/invoice/?customers[]=1&template=' . $id);
$this->assertTrue($client->getResponse()->isSuccessful());
$this->assertHasNoEntriesWithFilter($client);
@@ -168,12 +168,12 @@ class InvoiceControllerTest extends ControllerBaseTest
$form = $client->getCrawler()->filter('#invoice-print-form')->form();
$node = $form->getFormNode();
$node->setAttribute('action', $this->createUrl('/invoice/?preview='));
$node->setAttribute('action', $this->createUrl('/invoice/'));
$node->setAttribute('method', 'GET');
$client->submit($form, [
'template' => $template->getId(),
'daterange' => $dateRange,
'customer' => 1,
'customers' => [1],
]);
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -181,25 +181,20 @@ class InvoiceControllerTest extends ControllerBaseTest
// no warning should be displayed
$node = $client->getCrawler()->filter('div.callout.callout-warning.lead');
$this->assertEquals(0, $node->count());
// but the datatable with all timesheets + 1 row for the total
$this->assertDataTableRowCount($client, 'datatable_invoice', 21);
// but the datatable with all timesheets
$this->assertDataTableRowCount($client, 'datatable_invoice', 20);
$form = $client->getCrawler()->filter('#invoice-print-form')->form();
$node = $form->getFormNode();
$node->setAttribute('action', $this->createUrl('/invoice/?create='));
$node->setAttribute('method', 'GET');
$client->submit($form, [
'template' => $template->getId(),
$urlParams = [
'daterange' => $dateRange,
'customer' => 1,
'projects' => [1],
'projects[]' => 1,
'markAsExported' => 1,
]);
];
$this->assertTrue($client->getResponse()->isSuccessful());
$node = $client->getCrawler()->filter('body');
$this->assertEquals(1, $node->count());
$this->assertEquals('invoice_print', $node->getIterator()[0]->getAttribute('class'));
$action = '/invoice/save-invoice/1/' . $template->getId() . '?' . http_build_query($urlParams);
$this->request($client, $action);
$this->assertIsRedirect($client, '/invoice/show?id=', false);
$client->followRedirect();
$this->assertDataTableRowCount($client, 'datatable_invoices', 1);
$em = $this->getEntityManager();
$em->clear();
@@ -234,35 +229,13 @@ class InvoiceControllerTest extends ControllerBaseTest
$dateRange = $begin->format('Y-m-d') . DateRangeType::DATE_SPACER . $end->format('Y-m-d');
$form = $client->getCrawler()->filter('#invoice-print-form')->form();
$node = $form->getFormNode();
$node->setAttribute('action', $this->createUrl('/invoice/?preview='));
$node->setAttribute('method', 'GET');
$client->submit($form, [
'template' => $id,
$params = [
'daterange' => $dateRange,
'customer' => 1,
]);
$this->assertTrue($client->getResponse()->isSuccessful());
// no warning should be displayed
$node = $client->getCrawler()->filter('div.callout.callout-warning.lead');
$this->assertEquals(0, $node->count());
// but the datatable with all timesheets + 1 row for the total
$this->assertDataTableRowCount($client, 'datatable_invoice', 21);
$form = $client->getCrawler()->filter('#invoice-print-form')->form();
$node = $form->getFormNode();
$node->setAttribute('action', $this->createUrl('/invoice/?print='));
$node->setAttribute('method', 'GET');
$client->submit($form, [
'template' => $id,
'daterange' => $dateRange,
'customer' => 1,
'projects' => [1],
]);
];
$action = '/invoice/preview/1/' . $id . '?' . http_build_query($params);
$this->request($client, $action);
$this->assertTrue($client->getResponse()->isSuccessful());
$node = $client->getCrawler()->filter('body');
$this->assertEquals(1, $node->count());
@@ -299,7 +272,7 @@ class InvoiceControllerTest extends ControllerBaseTest
$client->submit($form, [
'template' => $template->getId(),
'daterange' => $dateRange,
'customer' => 1,
'customers' => [1],
]);
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -307,17 +280,17 @@ class InvoiceControllerTest extends ControllerBaseTest
// no warning should be displayed
$node = $client->getCrawler()->filter('div.callout.callout-warning.lead');
$this->assertEquals(0, $node->count());
// but the datatable with all timesheets + 1 row for the total
$this->assertDataTableRowCount($client, 'datatable_invoice', 21);
// but the datatable with all timesheets
$this->assertDataTableRowCount($client, 'datatable_invoice', 20);
$form = $client->getCrawler()->filter('#invoice-print-form')->form();
$node = $form->getFormNode();
$node->setAttribute('action', $this->createUrl('/invoice/?create='));
$node->setAttribute('action', $this->createUrl('/invoice/?createInvoice=true'));
$node->setAttribute('method', 'GET');
$client->submit($form, [
'template' => $template->getId(),
'daterange' => $dateRange,
'customer' => 1,
'customers' => [1],
'projects' => [1],
'markAsExported' => 1,
]);

View File

@@ -35,7 +35,7 @@ class PermissionControllerTest extends ControllerBaseTest
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
$this->assertAccessIsGranted($client, '/admin/permissions');
$this->assertHasDataTable($client);
$this->assertDataTableRowCount($client, 'datatable_user_admin_permissions', 119);
$this->assertDataTableRowCount($client, 'datatable_user_admin_permissions', 118);
$this->assertPageActions($client, [
//'back' => $this->createUrl('/admin/user/'),
'create modal-ajax-form' => $this->createUrl('/admin/permissions/roles/create'),

View File

@@ -54,7 +54,7 @@ class ProjectViewControllerTest extends ControllerBaseTest
$this->assertAccessIsGranted($client, '/reporting/project_view');
self::assertStringContainsString('<div class="box-body project-view-reporting-box', $client->getResponse()->getContent());
$rows = $client->getCrawler()->filterXPath("//table[@id='dt_project_view_reporting']/tbody/tr");
$rows = $client->getCrawler()->filterXPath("//table[contains(@class, 'dataTable')]/tbody/tr[not(@class='summary')]");
self::assertGreaterThan(0, $rows->count());
}
}

View File

@@ -82,7 +82,7 @@ class TimesheetControllerTest extends ControllerBaseTest
$this->assertDataTableRowCount($client, 'datatable_timesheet', 7);
// make sure the recording css class exist on tr for targeting running record rows
$node = $client->getCrawler()->filter('section.content div#datatable_timesheet table.table-striped tbody tr.recording');
$node = $client->getCrawler()->filter('section.content div.datatable_timesheet table.table-striped tbody tr.recording');
self::assertEquals(2, $node->count());
}

View File

@@ -87,7 +87,7 @@ class TimesheetTeamControllerTest extends ControllerBaseTest
$this->assertDataTableRowCount($client, 'datatable_timesheet_admin', 13);
// make sure the recording css class exist on tr for targeting running record rows
$node = $client->getCrawler()->filter('section.content div#datatable_timesheet_admin table.table-striped tbody tr.recording');
$node = $client->getCrawler()->filter('section.content div.datatable_timesheet_admin table.table-striped tbody tr.recording');
self::assertEquals(3, $node->count());
}

View File

@@ -10,10 +10,14 @@
namespace App\Tests\Invoice;
use App\Configuration\LanguageFormattings;
use App\Entity\Customer;
use App\Entity\Invoice;
use App\Entity\InvoiceDocument;
use App\Entity\InvoiceTemplate;
use App\Entity\Project;
use App\Entity\Timesheet;
use App\Invoice\Calculator\DefaultCalculator;
use App\Invoice\InvoiceItemRepositoryInterface;
use App\Invoice\NumberGenerator\DateNumberGenerator;
use App\Invoice\Renderer\TwigRenderer;
use App\Invoice\ServiceInvoice;
@@ -93,11 +97,8 @@ class ServiceInvoiceTest extends TestCase
$sut->addCalculator(new DefaultCalculator());
$sut->addNumberGenerator($this->getNumberGeneratorSut());
$sut->addRenderer(
new TwigRenderer(
$this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock()
)
);
$twig = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock();
$sut->addRenderer(new TwigRenderer($twig));
$this->assertEquals(1, \count($sut->getCalculator()));
$this->assertInstanceOf(DefaultCalculator::class, $sut->getCalculatorByName('default'));
@@ -113,8 +114,11 @@ class ServiceInvoiceTest extends TestCase
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Cannot create invoice model without template');
$query = new InvoiceQuery();
$query->setCustomers([new Customer()]);
$sut = $this->getSut([]);
$sut->createModel(new InvoiceQuery());
$sut->createModel($query);
}
/**
@@ -124,10 +128,10 @@ class ServiceInvoiceTest extends TestCase
{
$template = new InvoiceTemplate();
$template->setNumberGenerator('date');
self::assertNull($template->getLanguage());
$query = new InvoiceQuery();
$query->setCustomers([new Customer()]);
$query->setTemplate($template);
$sut = $this->getSut([]);
@@ -139,6 +143,30 @@ class ServiceInvoiceTest extends TestCase
self::assertEquals('en', $model->getTemplate()->getLanguage());
}
/**
* @group legacy
*/
public function testFindInvoiceItemsWithoutCustomer()
{
$sut = $this->getSut([]);
$query = new InvoiceQuery();
$items = $sut->findInvoiceItems($query);
self::assertEquals([], $items);
}
public function testFindInvoiceItemsWithCustomer()
{
$sut = $this->getSut([]);
$query = new InvoiceQuery();
$query->setCustomers([new Customer(), new Customer()]);
$items = $sut->findInvoiceItems($query);
self::assertEquals([], $items);
}
public function testCreateModelUsesTemplateLanguage()
{
$template = new InvoiceTemplate();
@@ -148,6 +176,7 @@ class ServiceInvoiceTest extends TestCase
self::assertEquals('de', $template->getLanguage());
$query = new InvoiceQuery();
$query->setCustomers([new Customer()]);
$query->setTemplate($template);
$sut = $this->getSut([]);
@@ -159,6 +188,74 @@ class ServiceInvoiceTest extends TestCase
self::assertEquals('de', $model->getTemplate()->getLanguage());
}
public function testBeginAndEndDateFallback()
{
$timezone = new \DateTimeZone('Europe/Vienna');
$customer = new Customer();
$project = new Project();
$project->setCustomer($customer);
$timesheet1 = new Timesheet();
$timesheet1->setProject($project);
$timesheet1->setBegin(new \DateTime('2011-01-27 12:12:12', $timezone));
$timesheet1->setEnd(new \DateTime('2020-01-27 12:12:12', $timezone));
$timesheet2 = new Timesheet();
$timesheet2->setProject($project);
$timesheet2->setBegin(new \DateTime('2010-01-27 08:24:33', $timezone));
$timesheet2->setEnd(new \DateTime('2019-01-27 12:12:12', $timezone));
$timesheet3 = new Timesheet();
$timesheet3->setProject($project);
$timesheet3->setBegin(new \DateTime('2019-01-27 12:12:12', $timezone));
$timesheet3->setEnd(new \DateTime('2020-01-07 12:12:12', $timezone));
$timesheet4 = new Timesheet();
$timesheet4->setProject($project);
$timesheet4->setBegin(new \DateTime('2020-01-27 10:12:12', $timezone));
$timesheet4->setEnd(new \DateTime('2020-11-27 11:12:12', $timezone));
$timesheet5 = new Timesheet();
$timesheet5->setProject($project);
$timesheet5->setBegin(new \DateTime('2012-01-27 12:12:12', $timezone));
$timesheet5->setEnd(new \DateTime('2018-01-27 12:12:12', $timezone));
$repo = $this->createMock(InvoiceItemRepositoryInterface::class);
$repo->method('getInvoiceItemsForQuery')->willReturn([
$timesheet1,
$timesheet2,
$timesheet3,
$timesheet4,
$timesheet5,
]);
$template = new InvoiceTemplate();
$template->setNumberGenerator('date');
$template->setLanguage('de');
self::assertEquals('de', $template->getLanguage());
$query = new InvoiceQuery();
$query->setCustomers([new Customer(), $customer]);
$query->setTemplate($template);
self::assertNull($query->getBegin());
self::assertNull($query->getEnd());
$sut = $this->getSut([]);
$sut->addCalculator(new DefaultCalculator());
$sut->addNumberGenerator($this->getNumberGeneratorSut());
$sut->addInvoiceItemRepository($repo);
$sut->createModels($query);
self::assertNotNull($query->getBegin());
self::assertNotNull($query->getEnd());
self::assertEquals('2010-01-27T00:00:00+0100', $query->getBegin()->format(DATE_ISO8601));
self::assertEquals('2020-11-27T23:59:59+0100', $query->getEnd()->format(DATE_ISO8601));
}
private function getNumberGeneratorSut()
{
$repository = $this->createMock(InvoiceRepository::class);