From 4750362961d8538f3d3a89a5e49bc641192d5c79 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 21 Jan 2018 15:53:43 +0200 Subject: [PATCH] Working on reports --- app/Ninja/Reports/AbstractReport.php | 16 ++++++++--- app/Ninja/Reports/ActivityReport.php | 15 ++++++---- app/Ninja/Reports/AgingReport.php | 22 +++++++++------ app/Ninja/Reports/ClientReport.php | 34 +++++++++++++++++++++-- app/Ninja/Reports/DocumentReport.php | 16 +++++++---- app/Ninja/Reports/ExpenseReport.php | 21 +++++++++----- app/Ninja/Reports/InvoiceReport.php | 25 ++++++++++------- app/Ninja/Reports/PaymentReport.php | 23 +++++++++------ app/Ninja/Reports/ProductReport.php | 25 +++++++++-------- app/Ninja/Reports/ProfitAndLossReport.php | 17 +++++++----- app/Ninja/Reports/QuoteReport.php | 19 ++++++++----- app/Ninja/Reports/TaskReport.php | 19 +++++++------ app/Ninja/Reports/TaxRateReport.php | 19 +++++++------ 13 files changed, 176 insertions(+), 95 deletions(-) diff --git a/app/Ninja/Reports/AbstractReport.php b/app/Ninja/Reports/AbstractReport.php index 83fa60f83a3b..a96f0e4ca010 100644 --- a/app/Ninja/Reports/AbstractReport.php +++ b/app/Ninja/Reports/AbstractReport.php @@ -12,7 +12,6 @@ class AbstractReport public $options; public $totals = []; - public $columns = []; public $data = []; public function __construct($startDate, $endDate, $isExport, $options = false) @@ -28,10 +27,15 @@ class AbstractReport } + public function getColumns() + { + return []; + } + public function results() { return [ - 'columns' => $this->columns, + 'columns' => $this->getColumns(), 'displayData' => $this->data, 'reportTotals' => $this->totals, ]; @@ -55,7 +59,7 @@ class AbstractReport public function tableHeaderArray() { $columns_labeled = []; - foreach ($this->columns as $key => $val) { + foreach ($this->getColumns() as $key => $val) { if (is_array($val)) { $field = $key; $class = $val; @@ -74,8 +78,12 @@ class AbstractReport $class[] = 'group-number-30'; } + if (! in_array('custom', $class)) { + $label = trans("texts.{$field}"); + } else { + $label = $field; + } $class = count($class) ? implode(' ', $class) : 'group-false'; - $label = trans("texts.{$field}"); $columns_labeled[] = [ 'label' => $label, diff --git a/app/Ninja/Reports/ActivityReport.php b/app/Ninja/Reports/ActivityReport.php index 2aaac5188af9..3ad95f292545 100644 --- a/app/Ninja/Reports/ActivityReport.php +++ b/app/Ninja/Reports/ActivityReport.php @@ -7,12 +7,15 @@ use Auth; class ActivityReport extends AbstractReport { - public $columns = [ - 'date', - 'client', - 'user', - 'activity', - ]; + public function getColumns() + { + return [ + 'date', + 'client', + 'user', + 'activity', + ]; + } public function run() { diff --git a/app/Ninja/Reports/AgingReport.php b/app/Ninja/Reports/AgingReport.php index b34ca6326f1a..1b82cceaaf31 100644 --- a/app/Ninja/Reports/AgingReport.php +++ b/app/Ninja/Reports/AgingReport.php @@ -7,15 +7,19 @@ use Auth; class AgingReport extends AbstractReport { - public $columns = [ - 'client', - 'invoice_number', - 'invoice_date', - 'due_date', - 'age', - 'amount', - 'balance', - ]; + public function getColumns() + { + return [ + 'client', + 'invoice_number', + 'invoice_date', + 'due_date', + 'age', + 'amount', + 'balance', + ]; + } + public function run() { diff --git a/app/Ninja/Reports/ClientReport.php b/app/Ninja/Reports/ClientReport.php index befde9b3bc67..f3e5b9be07f0 100644 --- a/app/Ninja/Reports/ClientReport.php +++ b/app/Ninja/Reports/ClientReport.php @@ -7,12 +7,29 @@ use Auth; class ClientReport extends AbstractReport { - public $columns = [ + public function getColumns() + { + $columns = [ 'client', 'amount', 'paid', 'balance', - ]; + 'public_notes' => ['columnSelector-false'], + 'private_notes' => ['columnSelector-false'], + ]; + + $user = auth()->user(); + $account = $user->account; + + if ($account->custom_client_label1) { + $columns[$account->custom_client_label1] = ['columnSelector-false', 'custom']; + } + if ($account->custom_client_label2) { + $columns[$account->custom_client_label2] = ['columnSelector-false', 'custom']; + } + + return $columns; + } public function run() { @@ -39,13 +56,24 @@ class ClientReport extends AbstractReport $paid += $invoice->getAmountPaid(); } - $this->data[] = [ + $row = [ $this->isExport ? $client->getDisplayName() : $client->present()->link, $account->formatMoney($amount, $client), $account->formatMoney($paid, $client), $account->formatMoney($amount - $paid, $client), + $client->public_notes, + $client->private_notes, ]; + if ($account->custom_client_label1) { + $row[] = $client->custom_value1; + } + if ($account->custom_client_label2) { + $row[] = $client->custom_value2; + } + + $this->data[] = $row; + $this->addToTotals($client->currency_id, 'amount', $amount); $this->addToTotals($client->currency_id, 'paid', $paid); $this->addToTotals($client->currency_id, 'balance', $amount - $paid); diff --git a/app/Ninja/Reports/DocumentReport.php b/app/Ninja/Reports/DocumentReport.php index c87408731923..c131ae73f8ab 100644 --- a/app/Ninja/Reports/DocumentReport.php +++ b/app/Ninja/Reports/DocumentReport.php @@ -8,12 +8,16 @@ use Barracuda\ArchiveStream\Archive; class DocumentReport extends AbstractReport { - public $columns = [ - 'document', - 'client', - 'invoice_or_expense', - 'date', - ]; + public function getColumns() + { + return [ + 'document', + 'client', + 'invoice_or_expense', + 'date', + ]; + } + public function run() { diff --git a/app/Ninja/Reports/ExpenseReport.php b/app/Ninja/Reports/ExpenseReport.php index 788b33908ee8..30888c64019b 100644 --- a/app/Ninja/Reports/ExpenseReport.php +++ b/app/Ninja/Reports/ExpenseReport.php @@ -9,13 +9,18 @@ use Utils; class ExpenseReport extends AbstractReport { - public $columns = [ - 'vendor', - 'client', - 'date', - 'category', - 'amount', - ]; + public function getColumns() + { + return [ + 'vendor', + 'client', + 'date', + 'category', + 'amount', + 'public_notes' => ['columnSelector-false'], + 'private_notes' => ['columnSelector-false'], + ]; + } public function run() { @@ -57,6 +62,8 @@ class ExpenseReport extends AbstractReport $this->isExport ? $expense->present()->expense_date : link_to($expense->present()->url, $expense->present()->expense_date), $expense->present()->category, Utils::formatMoney($amount, $expense->currency_id), + $expense->public_notes, + $expense->private_notes, ]; $this->addToTotals($expense->expense_currency_id, 'amount', $amount); diff --git a/app/Ninja/Reports/InvoiceReport.php b/app/Ninja/Reports/InvoiceReport.php index 8b353230ab08..74b418b9129f 100644 --- a/app/Ninja/Reports/InvoiceReport.php +++ b/app/Ninja/Reports/InvoiceReport.php @@ -8,16 +8,20 @@ use Barracuda\ArchiveStream\Archive; class InvoiceReport extends AbstractReport { - public $columns = [ - 'client', - 'invoice_number', - 'invoice_date', - 'amount', - 'status', - 'payment_date', - 'paid', - 'method', - ]; + public function getColumns() + { + return [ + 'client', + 'invoice_number', + 'invoice_date', + 'amount', + 'status', + 'payment_date', + 'paid', + 'method', + 'private_notes' => ['columnSelector-false'], + ]; + } public function run() { @@ -70,6 +74,7 @@ class InvoiceReport extends AbstractReport $payment ? $payment->present()->payment_date : '', $payment ? $account->formatMoney($payment->getCompletedAmount(), $client) : '', $payment ? $payment->present()->method : '', + $invoice->private_notes, ]; $this->addToTotals($client->currency_id, 'paid', $payment ? $payment->getCompletedAmount() : 0); diff --git a/app/Ninja/Reports/PaymentReport.php b/app/Ninja/Reports/PaymentReport.php index 53d201f1880f..dab9f779d094 100644 --- a/app/Ninja/Reports/PaymentReport.php +++ b/app/Ninja/Reports/PaymentReport.php @@ -8,15 +8,19 @@ use Utils; class PaymentReport extends AbstractReport { - public $columns = [ - 'client', - 'invoice_number', - 'invoice_date', - 'amount', - 'payment_date', - 'paid', - 'method', - ]; + public function getColumns() + { + return [ + 'client', + 'invoice_number', + 'invoice_date', + 'amount', + 'payment_date', + 'paid', + 'method', + 'private_notes' => ['columnSelector-false'], + ]; + } public function run() { @@ -60,6 +64,7 @@ class PaymentReport extends AbstractReport $payment->present()->payment_date, $amount, $payment->present()->method, + $payment->private_notes, ]; if (! isset($invoiceMap[$invoice->id])) { diff --git a/app/Ninja/Reports/ProductReport.php b/app/Ninja/Reports/ProductReport.php index d0a9c7c96a7e..cddc9a80c032 100644 --- a/app/Ninja/Reports/ProductReport.php +++ b/app/Ninja/Reports/ProductReport.php @@ -8,17 +8,20 @@ use Utils; class ProductReport extends AbstractReport { - public $columns = [ - 'client', - 'invoice_number', - 'invoice_date', - 'product', - 'description', - 'qty', - 'cost', - //'tax_rate1', - //'tax_rate2', - ]; + public function getColumns() + { + return [ + 'client', + 'invoice_number', + 'invoice_date', + 'product', + 'description', + 'qty', + 'cost', + //'tax_rate1', + //'tax_rate2', + ]; + } public function run() { diff --git a/app/Ninja/Reports/ProfitAndLossReport.php b/app/Ninja/Reports/ProfitAndLossReport.php index cd16ed49b0c9..14f1b97b2721 100644 --- a/app/Ninja/Reports/ProfitAndLossReport.php +++ b/app/Ninja/Reports/ProfitAndLossReport.php @@ -8,13 +8,16 @@ use Auth; class ProfitAndLossReport extends AbstractReport { - public $columns = [ - 'type', - 'client', - 'amount', - 'date', - 'notes', - ]; + public function getColumns() + { + return [ + 'type', + 'client', + 'amount', + 'date', + 'notes', + ]; + } public function run() { diff --git a/app/Ninja/Reports/QuoteReport.php b/app/Ninja/Reports/QuoteReport.php index 704bc4820bd7..167d2831af05 100644 --- a/app/Ninja/Reports/QuoteReport.php +++ b/app/Ninja/Reports/QuoteReport.php @@ -8,13 +8,17 @@ use Barracuda\ArchiveStream\Archive; class QuoteReport extends AbstractReport { - public $columns = [ - 'client', - 'quote_number', - 'quote_date', - 'amount', - 'status', - ]; + public function getColumns() + { + return [ + 'client', + 'quote_number', + 'quote_date', + 'amount', + 'status', + 'private_notes' => ['columnSelector-false'], + ]; + } public function run() { @@ -58,6 +62,7 @@ class QuoteReport extends AbstractReport $invoice->present()->invoice_date, $account->formatMoney($invoice->amount, $client), $invoice->present()->status(), + $invoice->private_notes, ]; $this->addToTotals($client->currency_id, 'amount', $invoice->amount); diff --git a/app/Ninja/Reports/TaskReport.php b/app/Ninja/Reports/TaskReport.php index b19e871c8639..4c5e2faf142b 100644 --- a/app/Ninja/Reports/TaskReport.php +++ b/app/Ninja/Reports/TaskReport.php @@ -7,14 +7,17 @@ use Utils; class TaskReport extends AbstractReport { - public $columns = [ - 'client', - 'date', - 'project', - 'description', - 'duration', - 'amount', - ]; + public function getColumns() + { + return [ + 'client', + 'date', + 'project', + 'description', + 'duration', + 'amount', + ]; + } public function run() { diff --git a/app/Ninja/Reports/TaxRateReport.php b/app/Ninja/Reports/TaxRateReport.php index 7fad4c6e1c31..91b39b7bc43f 100644 --- a/app/Ninja/Reports/TaxRateReport.php +++ b/app/Ninja/Reports/TaxRateReport.php @@ -7,14 +7,17 @@ use Auth; class TaxRateReport extends AbstractReport { - public $columns = [ - 'client', - 'invoice', - 'tax_name', - 'tax_rate', - 'amount', - 'paid', - ]; + public function getColumns() + { + return [ + 'client', + 'invoice', + 'tax_name', + 'tax_rate', + 'amount', + 'paid', + ]; + } public function run() {