Skip to content

Commit

Permalink
Add checkbox to invoices export to select only B2B invoices
Browse files Browse the repository at this point in the history
- B2B invoice has filled in either buyer's company ID, VAT ID
or TAX ID.

remp/crm#2447
  • Loading branch information
Matefko committed May 26, 2022
1 parent ba2e06b commit dc197d1
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
14 changes: 12 additions & 2 deletions src/Hermes/ZipInvoicesHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,24 @@ public function handle(MessageInterface $message): bool
return true;
}

if (isset($payload['from_time']) && isset($payload['to_time'])) {
if (isset($payload['from_time']) && isset($payload['to_time']) && isset($payload['b2b_only'])) {
$from = DateTime::from(strtotime($payload['from_time']));
$to = DateTime::from(strtotime($payload['to_time']))->setTime(23, 59, 59, 999);

$payments = $this->paymentsRepository->all()->where([
'invoice.delivery_date >=' => $from,
'invoice.delivery_date <=' => $to,
])->order('created_at DESC')->fetchAll();
])->order('created_at DESC');

if ($payload['b2b_only']) {
$payments->whereOr([
'invoice.buyer_id NOT ? AND invoice.buyer_id != ?' => [null, ''],
'invoice.buyer_tax_id NOT ? AND invoice.buyer_tax_id != ?' => [null, ''],
'invoice.buyer_vat_id NOT ? AND invoice.buyer_vat_id != ?' => [null, ''],
]);
}

$payments = $payments->fetchAll();

if (count($payments) === 0) {
$this->logger->info("No invoices with delivery dates between [{$from}] and [{$to}] found.");
Expand Down
4 changes: 4 additions & 0 deletions src/Presenters/InvoicesAdminPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,14 @@ protected function createComponentExportForm()
->setHtmlAttribute('class', 'flatpickr');
$form->addText('to_time', 'invoices.admin.export_form.to_time')
->setHtmlAttribute('class', 'flatpickr');
$form->addCheckbox('b2b_only', 'invoices.admin.export_form.b2b_only')
->setHtmlAttribute('style', 'margin: 0 5px');
$form->addText('invoices', 'invoices.admin.export_form.invoices');
$form->addSubmit('submit', 'invoices.admin.export_form.generate');
$form->setDefaults([
'from_time' => DateTime::from('-1 month')->format(DATE_RFC3339),
'to_time' => DateTime::from('now')->format(DATE_RFC3339),
'b2b_only' => true,
]);
$form->onSuccess[] = function (Form $form, $values) {
if ($values->invoices) {
Expand All @@ -148,6 +151,7 @@ protected function createComponentExportForm()
$this->hermesEmitter->emit(new HermesMessage('invoice_zip', [
'from_time' => $values['from_time'],
'to_time' => $values['to_time'],
'b2b_only' => $values['b2b_only'],
]), HermesMessage::PRIORITY_LOW);

$this->flashMessage($this->translator->translate('invoices.admin.export_form.scheduled'));
Expand Down
2 changes: 2 additions & 0 deletions src/lang/invoices.cs_CZ.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ admin:
export_form:
from_time: Začátek
to_time: Konec
b2b_only: Zahrnout pouze B2B faktury
b2b_tooltip: Zahrne faktury s vyplněným IČO, DIČ nebo IČ DPH.
invoices: Faktury
generate: Vygeneruj
scheduled: "Generování faktur bylo naplánováno, chvíli počkejte."
Expand Down
2 changes: 2 additions & 0 deletions src/lang/invoices.en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ admin:
export_form:
from_time: From
to_time: To
b2b_only: Include only B2B invoices
b2b_tooltip: Includes invoices with filled buyer's company ID, VAT ID or TAX ID.
invoices: Invoices
generate: Generate
scheduled: "Batch generation was scheduled, please wait."
Expand Down
2 changes: 2 additions & 0 deletions src/lang/invoices.sk_SK.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ admin:
export_form:
from_time: Začiatok
to_time: Koniec
b2b_only: Zahrnúť iba B2B faktúry
b2b_tooltip: Zahrnie faktúry s vyplneným IČO, DIČ alebo IČ DPH.
invoices: Faktúry
generate: Vygeneruj
scheduled: "Generovanie faktúr bolo naplánované, chvíľu počkajte."
Expand Down
28 changes: 25 additions & 3 deletions src/templates/InvoicesAdmin/default.latte
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,32 @@
{_invoices.admin.default.export}
</h2>
</div>

<div class="col-md-12">
<hr>
{control exportForm}
<hr>
{form exportForm, class => 'form-inline'}
<div style="display: block; margin-bottom: 10px">
<div class="form-group">
{label from_time /}
{input from_time, class => 'form-control flatpickr'}
</div>
<div class="form-group">
{label to_time /}
{input to_time, class => 'form-control flatpickr'}
</div>
<div class="form-group">
{label b2b_only /}
{input b2b_only, class => 'form-control'}
<i class="fa fa-question-circle" data-toggle="tooltip" data-original-title="{_invoices.admin.export_form.b2b_tooltip}"></i>
</div>
</div>
<div style="display: block; margin-bottom: 10px">
<div class="form-group">
{label invoices /}
{input invoices, class => 'form-control'}
</div>
</div>
{input submit, class => 'btn btn-primary'}
{/form}
</div>
</div>

Expand Down

0 comments on commit dc197d1

Please sign in to comment.