From 7130110f8e44c0f7bf274641b28b60769fb0d785 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 24 Jan 2018 20:19:53 +0200 Subject: [PATCH] Working on reports --- app/Models/Invoice.php | 11 +++++++++++ app/Ninja/Reports/InvoiceReport.php | 13 ++++++++++++- app/Ninja/Reports/PaymentReport.php | 5 ++++- app/Ninja/Reports/QuoteReport.php | 9 +++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index a2ff6898b75b..90d58f749b53 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -1424,6 +1424,17 @@ class Invoice extends EntityModel implements BalanceAffecting return $taxes; } + public function getTaxTotal() + { + $total = 0; + + foreach ($this->getTaxes() as $tax) { + $total += $tax['amount']; + } + + return $total; + } + public function taxAmount($taxable, $rate) { $account = $this->account; diff --git a/app/Ninja/Reports/InvoiceReport.php b/app/Ninja/Reports/InvoiceReport.php index fbc0ae7d522e..3ac9e212a2d0 100644 --- a/app/Ninja/Reports/InvoiceReport.php +++ b/app/Ninja/Reports/InvoiceReport.php @@ -5,6 +5,7 @@ namespace App\Ninja\Reports; use App\Models\Client; use Auth; use Barracuda\ArchiveStream\Archive; +use App\Models\TaxRate; class InvoiceReport extends AbstractReport { @@ -22,6 +23,10 @@ class InvoiceReport extends AbstractReport 'private_notes' => ['columnSelector-false'], ]; + if (TaxRate::scope()->count()) { + $columns['tax'] = ['columnSelector-false']; + } + $account = auth()->user()->account; if ($account->custom_invoice_text_label1) { @@ -74,13 +79,14 @@ class InvoiceReport extends AbstractReport foreach ($clients->get() as $client) { foreach ($client->invoices as $invoice) { + $isFirst = true; $payments = $invoice->payments->count() ? $invoice->payments : [false]; foreach ($payments as $payment) { $row = [ $this->isExport ? $client->getDisplayName() : $client->present()->link, $this->isExport ? $invoice->invoice_number : $invoice->present()->link, $invoice->present()->invoice_date, - $account->formatMoney($invoice->amount, $client), + $isFirst ? $account->formatMoney($invoice->amount, $client) : '', $invoice->statusLabel(), $payment ? $payment->present()->payment_date : '', $payment ? $account->formatMoney($payment->getCompletedAmount(), $client) : '', @@ -88,6 +94,10 @@ class InvoiceReport extends AbstractReport $invoice->private_notes, ]; + if (TaxRate::scope()->count()) { + $row[] = $invoice->getTaxTotal(); + } + if ($account->custom_invoice_text_label1) { $row[] = $invoice->custom_text_value1; } @@ -98,6 +108,7 @@ class InvoiceReport extends AbstractReport $this->data[] = $row; $this->addToTotals($client->currency_id, 'paid', $payment ? $payment->getCompletedAmount() : 0); + $isFirst = false; } $this->addToTotals($client->currency_id, 'amount', $invoice->amount); diff --git a/app/Ninja/Reports/PaymentReport.php b/app/Ninja/Reports/PaymentReport.php index 19eb19072f02..b38b7a7d7f40 100644 --- a/app/Ninja/Reports/PaymentReport.php +++ b/app/Ninja/Reports/PaymentReport.php @@ -42,6 +42,7 @@ class PaymentReport extends AbstractReport ->where('payment_date', '>=', $this->startDate) ->where('payment_date', '<=', $this->endDate); + $lastInvoiceId = 0; foreach ($payments->get() as $payment) { $invoice = $payment->invoice; $client = $payment->client; @@ -60,7 +61,7 @@ class PaymentReport extends AbstractReport $this->isExport ? $client->getDisplayName() : $client->present()->link, $this->isExport ? $invoice->invoice_number : $invoice->present()->link, $invoice->present()->invoice_date, - $account->formatMoney($invoice->amount, $client), + $lastInvoiceId == $invoice->id ? '' : $account->formatMoney($invoice->amount, $client), $payment->present()->payment_date, $amount, $payment->present()->method, @@ -76,6 +77,8 @@ class PaymentReport extends AbstractReport $this->addToTotals($client->currency_id, 'amount', $invoice->amount); } } + + $lastInvoiceId = $invoice->id; } } } diff --git a/app/Ninja/Reports/QuoteReport.php b/app/Ninja/Reports/QuoteReport.php index b19479c46f56..28f1399feb39 100644 --- a/app/Ninja/Reports/QuoteReport.php +++ b/app/Ninja/Reports/QuoteReport.php @@ -5,6 +5,7 @@ namespace App\Ninja\Reports; use App\Models\Client; use Auth; use Barracuda\ArchiveStream\Archive; +use App\Models\TaxRate; class QuoteReport extends AbstractReport { @@ -19,6 +20,10 @@ class QuoteReport extends AbstractReport 'private_notes' => ['columnSelector-false'], ]; + if (TaxRate::scope()->count()) { + $columns['tax'] = ['columnSelector-false']; + } + $account = auth()->user()->account; if ($account->custom_invoice_text_label1) { @@ -76,6 +81,10 @@ class QuoteReport extends AbstractReport $invoice->private_notes, ]; + if (TaxRate::scope()->count()) { + $row[] = $invoice->getTaxTotal(); + } + if ($account->custom_invoice_text_label1) { $row[] = $invoice->custom_text_value1; }