From b66a9b2a33409ffa1a3242741b04f5d3a7cfe218 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 25 Feb 2018 23:03:29 +0200 Subject: [PATCH] Fix for UBL invoices --- app/Jobs/ConvertInvoiceToUbl.php | 42 +++++++------------ app/Ninja/Mailers/Mailer.php | 4 +- resources/views/calendar.blade.php | 2 +- .../partials/navigation_option.blade.php | 2 +- .../views/reports/report_builder.blade.php | 2 +- routes/web.php | 4 +- 6 files changed, 23 insertions(+), 33 deletions(-) diff --git a/app/Jobs/ConvertInvoiceToUbl.php b/app/Jobs/ConvertInvoiceToUbl.php index c19abc5111..f50b534069 100644 --- a/app/Jobs/ConvertInvoiceToUbl.php +++ b/app/Jobs/ConvertInvoiceToUbl.php @@ -57,22 +57,17 @@ class ConvertInvoiceToUbl extends Job $ublInvoice->setInvoiceLines($invoiceLines); - if ($invoice->hasTaxes()) { - $taxtotal = new TaxTotal(); - $taxAmount1 = $taxAmount2 = 0; + $taxtotal = new TaxTotal(); + $taxAmount1 = $taxAmount2 = 0; - if ($invoice->tax_name1 || floatval($invoice->tax_rate1)) { - $taxAmount1 = $this->createTaxRate($taxtotal, $taxable, $invoice->tax_rate1, $invoice->tax_name1); - } - - if ($invoice->tax_name2 || floatval($invoice->tax_rate2)) { - $taxAmount2 = $this->createTaxRate($taxtotal, $taxable, $invoice->tax_rate2, $invoice->tax_name2); - } - - $taxtotal->setTaxAmount($taxAmount1 + $taxAmount2); - $ublInvoice->setTaxTotal($taxtotal); + $taxAmount1 = $this->createTaxRate($taxtotal, $taxable, $invoice->tax_rate1, $invoice->tax_name1); + if ($invoice->tax_name2 || floatval($invoice->tax_rate2)) { + $taxAmount2 = $this->createTaxRate($taxtotal, $taxable, $invoice->tax_rate2, $invoice->tax_name2); } + $taxtotal->setTaxAmount($taxAmount1 + $taxAmount2); + $ublInvoice->setTaxTotal($taxtotal); + $ublInvoice->setLegalMonetaryTotal((new LegalMonetaryTotal()) //->setLineExtensionAmount() ->setTaxExclusiveAmount($taxable) @@ -118,22 +113,17 @@ class ConvertInvoiceToUbl extends Job ->setDescription($item->description)); //->setSellersItemIdentification("1ABCD")); - if ($item->hasTaxes()) { - $taxtotal = new TaxTotal(); - $itemTaxAmount1 = $itemTaxAmount2 = 0; + $taxtotal = new TaxTotal(); + $itemTaxAmount1 = $itemTaxAmount2 = 0; - if ($item->tax_name1 || floatval($item->tax_rate1)) { - $itemTaxAmount1 = $this->createTaxRate($taxtotal, $taxable, $item->tax_rate1, $item->tax_name1); - } - - if ($item->tax_name2 || floatval($item->tax_rate2)) { - $itemTaxAmount2 = $this->createTaxRate($taxtotal, $taxable, $item->tax_rate2, $item->tax_name2); - } - - $taxtotal->setTaxAmount($itemTaxAmount1 + $itemTaxAmount2); - $invoiceLine->setTaxTotal($taxtotal); + $itemTaxAmount1 = $this->createTaxRate($taxtotal, $taxable, $item->tax_rate1, $item->tax_name1); + if ($item->tax_name2 || floatval($item->tax_rate2)) { + $itemTaxAmount2 = $this->createTaxRate($taxtotal, $taxable, $item->tax_rate2, $item->tax_name2); } + $taxtotal->setTaxAmount($itemTaxAmount1 + $itemTaxAmount2); + $invoiceLine->setTaxTotal($taxtotal); + return $invoiceLine; } diff --git a/app/Ninja/Mailers/Mailer.php b/app/Ninja/Mailers/Mailer.php index 329827cc06..6277acb368 100644 --- a/app/Ninja/Mailers/Mailer.php +++ b/app/Ninja/Mailers/Mailer.php @@ -127,10 +127,10 @@ class Mailer // Handle invoice attachments if (! empty($data['pdfString']) && ! empty($data['pdfFileName'])) { - $attachments[] = PostmarkAttachment::fromRawData($document['pdfString'], $document['pdfFileName']); + $attachments[] = PostmarkAttachment::fromRawData($data['pdfString'], $data['pdfFileName']); } if (! empty($data['ublString']) && ! empty($data['ublFileName'])) { - $attachments[] = PostmarkAttachment::fromRawData($document['ublString'], $document['ublFileName']); + $attachments[] = PostmarkAttachment::fromRawData($data['ublString'], $data['ublFileName']); } if (! empty($data['documents'])) { foreach ($data['documents'] as $document) { diff --git a/resources/views/calendar.blade.php b/resources/views/calendar.blade.php index 95489a097a..b51f535175 100644 --- a/resources/views/calendar.blade.php +++ b/resources/views/calendar.blade.php @@ -86,7 +86,7 @@ defaultDate: '{{ date('Y-m-d') }}', eventLimit: true, events: { - url: '{{ url('/calendar_events') }}', + url: '{{ url('/reports/calendar_events') }}', type: 'GET', data: function() { return { diff --git a/resources/views/partials/navigation_option.blade.php b/resources/views/partials/navigation_option.blade.php index 9584d6afc6..ca1d13d6ae 100644 --- a/resources/views/partials/navigation_option.blade.php +++ b/resources/views/partials/navigation_option.blade.php @@ -7,7 +7,7 @@ @elseif ($option == 'reports') + href="{{ url('/reports/calendar') }}"> @elseif (Auth::user()->can('create', $option) || Auth::user()->can('create', substr($option, 0, -1))) diff --git a/resources/views/reports/report_builder.blade.php b/resources/views/reports/report_builder.blade.php index 93d2820f97..b3ce9d8c9c 100644 --- a/resources/views/reports/report_builder.blade.php +++ b/resources/views/reports/report_builder.blade.php @@ -43,7 +43,7 @@ ->appendIcon(Icon::create('envelope')) !!} @endif {!! Button::normal(trans('texts.calendar')) - ->asLinkTo(url('/calendar')) + ->asLinkTo(url('/reports/calendar')) ->appendIcon(Icon::create('calendar')) !!} @stop diff --git a/routes/web.php b/routes/web.php index b7889ca32f..ec010944fc 100644 --- a/routes/web.php +++ b/routes/web.php @@ -283,8 +283,8 @@ Route::group(['middleware' => ['lookup:user', 'auth:user']], function () { Route::get('reports', 'ReportController@showReports'); Route::post('reports', 'ReportController@showReports'); - Route::get('calendar', 'CalendarController@showCalendar'); - Route::get('calendar_events', 'CalendarController@loadEvents'); + Route::get('reports/calendar', 'CalendarController@showCalendar'); + Route::get('reports/calendar_events', 'CalendarController@loadEvents'); Route::get('reports/emails', 'ReportController@showEmailReport'); Route::get('reports/emails_report/{start_date}/{end_date}', 'ReportController@loadEmailReport'); });