1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Working on charts

This commit is contained in:
Hillel Coren 2018-02-28 16:57:10 +02:00
parent dd6fc10d98
commit b3047fb202
11 changed files with 88 additions and 6 deletions

View File

@ -246,7 +246,7 @@ class AbstractReport
$record->lineTension = 0; $record->lineTension = 0;
$record->borderWidth = 3; $record->borderWidth = 3;
$record->borderColor = "rgba({$color}, 1)"; $record->borderColor = "rgba({$color}, 1)";
$record->backgroundColor = "rgba({$color}, 0.1)"; $record->backgroundColor = "rgba(255,255,255,0)";
} }
$data = new stdClass(); $data = new stdClass();

View File

@ -57,7 +57,11 @@ class ClientReport extends AbstractReport
$amount += $invoice->amount; $amount += $invoice->amount;
$paid += $invoice->getAmountPaid(); $paid += $invoice->getAmountPaid();
if ($subgroup == 'country') {
$dimension = $client->present()->country;
} else {
$dimension = $this->getDimension($client); $dimension = $this->getDimension($client);
}
$this->addChartData($dimension, $invoice->invoice_date, $invoice->amount); $this->addChartData($dimension, $invoice->invoice_date, $invoice->amount);
} }

View File

@ -89,6 +89,16 @@ class ExpenseReport extends AbstractReport
$this->addToTotals($expense->expense_currency_id, 'amount', $amount); $this->addToTotals($expense->expense_currency_id, 'amount', $amount);
$this->addToTotals($expense->invoice_currency_id, 'amount', 0); $this->addToTotals($expense->invoice_currency_id, 'amount', 0);
if ($subgroup == 'category') {
$dimension = $expense->present()->category;
} elseif ($subgroup == 'vendor') {
$dimension = $expense->vendor ? $expense->vendor->name : trans('texts.unset');
} else {
$dimension = $this->getDimension($expense);
}
$this->addChartData($dimension, $expense->expense_date, $amount);
} }
} }
} }

View File

@ -46,6 +46,7 @@ class InvoiceReport extends AbstractReport
$account = Auth::user()->account; $account = Auth::user()->account;
$statusIds = $this->options['status_ids']; $statusIds = $this->options['status_ids'];
$exportFormat = $this->options['export_format']; $exportFormat = $this->options['export_format'];
$subgroup = $this->options['subgroup'];
$hasTaxRates = TaxRate::scope()->count(); $hasTaxRates = TaxRate::scope()->count();
$clients = Client::scope() $clients = Client::scope()
@ -122,6 +123,14 @@ class InvoiceReport extends AbstractReport
$this->addToTotals($client->currency_id, 'amount', $invoice->amount); $this->addToTotals($client->currency_id, 'amount', $invoice->amount);
$this->addToTotals($client->currency_id, 'balance', $invoice->balance); $this->addToTotals($client->currency_id, 'balance', $invoice->balance);
if ($subgroup == 'status') {
$dimension = $invoice->statusLabel();
} else {
$dimension = $this->getDimension($client);
}
$this->addChartData($dimension, $invoice->invoice_date, $invoice->amount);
} }
} }
} }

View File

@ -28,6 +28,7 @@ class PaymentReport extends AbstractReport
$account = Auth::user()->account; $account = Auth::user()->account;
$currencyType = $this->options['currency_type']; $currencyType = $this->options['currency_type'];
$invoiceMap = []; $invoiceMap = [];
$subgroup = $this->options['subgroup'];
$payments = Payment::scope() $payments = Payment::scope()
->orderBy('payment_date', 'desc') ->orderBy('payment_date', 'desc')
@ -80,6 +81,15 @@ class PaymentReport extends AbstractReport
} }
} }
if ($subgroup == 'method') {
$dimension = $payment->present()->method;
} else {
$dimension = $this->getDimension($payment);
}
$convertedAmount = $currencyType == 'converted' ? ($invoice->amount * $payment->exchange_rate) : $invoice->amount;
$this->addChartData($dimension, $payment->payment_date, $convertedAmount);
$lastInvoiceId = $invoice->id; $lastInvoiceId = $invoice->id;
} }
} }

View File

@ -46,11 +46,12 @@ class ProductReport extends AbstractReport
{ {
$account = Auth::user()->account; $account = Auth::user()->account;
$statusIds = $this->options['status_ids']; $statusIds = $this->options['status_ids'];
$subgroup = $this->options['subgroup'];
$clients = Client::scope() $clients = Client::scope()
->orderBy('name') ->orderBy('name')
->withArchived() ->withArchived()
->with('contacts') ->with('contacts', 'user')
->with(['invoices' => function ($query) use ($statusIds) { ->with(['invoices' => function ($query) use ($statusIds) {
$query->invoices() $query->invoices()
->withArchived() ->withArchived()
@ -90,6 +91,13 @@ class ProductReport extends AbstractReport
$this->data[] = $row; $this->data[] = $row;
if ($subgroup == 'product') {
$dimension = $item->product_key;
} else {
$dimension = $this->getDimension($client);
}
$this->addChartData($dimension, $invoice->invoice_date, $invoice->amount);
} }
//$this->addToTotals($client->currency_id, 'paid', $payment ? $payment->getCompletedAmount() : 0); //$this->addToTotals($client->currency_id, 'paid', $payment ? $payment->getCompletedAmount() : 0);

View File

@ -22,10 +22,11 @@ class ProfitAndLossReport extends AbstractReport
public function run() public function run()
{ {
$account = Auth::user()->account; $account = Auth::user()->account;
$subgroup = $this->options['subgroup'];
$payments = Payment::scope() $payments = Payment::scope()
->orderBy('payment_date', 'desc') ->orderBy('payment_date', 'desc')
->with('client.contacts', 'invoice') ->with('client.contacts', 'invoice', 'user')
->withArchived() ->withArchived()
->excludeFailed() ->excludeFailed()
->where('payment_date', '>=', $this->startDate) ->where('payment_date', '>=', $this->startDate)
@ -48,6 +49,13 @@ class ProfitAndLossReport extends AbstractReport
$this->addToTotals($client->currency_id, 'revenue', $payment->getCompletedAmount(), $payment->present()->month); $this->addToTotals($client->currency_id, 'revenue', $payment->getCompletedAmount(), $payment->present()->month);
$this->addToTotals($client->currency_id, 'expenses', 0, $payment->present()->month); $this->addToTotals($client->currency_id, 'expenses', 0, $payment->present()->month);
$this->addToTotals($client->currency_id, 'profit', $payment->getCompletedAmount(), $payment->present()->month); $this->addToTotals($client->currency_id, 'profit', $payment->getCompletedAmount(), $payment->present()->month);
if ($subgroup == 'type') {
$dimension = trans('texts.payment');
} else {
$dimension = $this->getDimension($payment);
}
$this->addChartData($dimension, $payment->payment_date, $payment->getCompletedAmount());
} }
$expenses = Expense::scope() $expenses = Expense::scope()
@ -70,6 +78,13 @@ class ProfitAndLossReport extends AbstractReport
$this->addToTotals($expense->expense_currency_id, 'revenue', 0, $expense->present()->month); $this->addToTotals($expense->expense_currency_id, 'revenue', 0, $expense->present()->month);
$this->addToTotals($expense->expense_currency_id, 'expenses', $expense->amountWithTax(), $expense->present()->month); $this->addToTotals($expense->expense_currency_id, 'expenses', $expense->amountWithTax(), $expense->present()->month);
$this->addToTotals($expense->expense_currency_id, 'profit', $expense->amountWithTax() * -1, $expense->present()->month); $this->addToTotals($expense->expense_currency_id, 'profit', $expense->amountWithTax() * -1, $expense->present()->month);
if ($subgroup == 'type') {
$dimension = trans('texts.expense');
} else {
$dimension = $this->getDimension($payment);
}
$this->addChartData($dimension, $payment->expense_date, $expense->amountWithTax());
} }
//$this->addToTotals($client->currency_id, 'paid', $payment ? $payment->getCompletedAmount() : 0); //$this->addToTotals($client->currency_id, 'paid', $payment ? $payment->getCompletedAmount() : 0);

View File

@ -43,6 +43,7 @@ class QuoteReport extends AbstractReport
$statusIds = $this->options['status_ids']; $statusIds = $this->options['status_ids'];
$exportFormat = $this->options['export_format']; $exportFormat = $this->options['export_format'];
$hasTaxRates = TaxRate::scope()->count(); $hasTaxRates = TaxRate::scope()->count();
$subgroup = $this->options['subgroup'];
$clients = Client::scope() $clients = Client::scope()
->orderBy('name') ->orderBy('name')
@ -102,6 +103,14 @@ class QuoteReport extends AbstractReport
$this->data[] = $row; $this->data[] = $row;
$this->addToTotals($client->currency_id, 'amount', $invoice->amount); $this->addToTotals($client->currency_id, 'amount', $invoice->amount);
if ($subgroup == 'status') {
$dimension = $invoice->statusLabel();
} else {
$dimension = $this->getDimension($client);
}
$this->addChartData($dimension, $invoice->invoice_date, $invoice->amount);
} }
} }
} }

View File

@ -24,6 +24,7 @@ class TaskReport extends AbstractReport
{ {
$startDate = date_create($this->startDate); $startDate = date_create($this->startDate);
$endDate = date_create($this->endDate); $endDate = date_create($this->endDate);
$subgroup = $this->options['subgroup'];
$tasks = Task::scope() $tasks = Task::scope()
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
@ -52,6 +53,13 @@ class TaskReport extends AbstractReport
$this->addToTotals($currencyId, 'duration', $duration); $this->addToTotals($currencyId, 'duration', $duration);
$this->addToTotals($currencyId, 'amount', $amount); $this->addToTotals($currencyId, 'amount', $amount);
if ($subgroup == 'project') {
$dimension = $task->present()->project;
} else {
$dimension = $this->getDimension($task);
}
$this->addChartData($dimension, $task->created_at, round($duration / 60 / 60, 2));
} }
} }
} }

View File

@ -24,11 +24,12 @@ class TaxRateReport extends AbstractReport
public function run() public function run()
{ {
$account = Auth::user()->account; $account = Auth::user()->account;
$subgroup = $this->options['subgroup'];
$clients = Client::scope() $clients = Client::scope()
->orderBy('name') ->orderBy('name')
->withArchived() ->withArchived()
->with('contacts') ->with('contacts', 'user')
->with(['invoices' => function ($query) { ->with(['invoices' => function ($query) {
$query->with('invoice_items') $query->with('invoice_items')
->withArchived() ->withArchived()
@ -85,6 +86,9 @@ class TaxRateReport extends AbstractReport
$this->addToTotals($client->currency_id, 'amount', $tax['amount']); $this->addToTotals($client->currency_id, 'amount', $tax['amount']);
$this->addToTotals($client->currency_id, 'paid', $tax['paid']); $this->addToTotals($client->currency_id, 'paid', $tax['paid']);
$dimension = $this->getDimension($client);
$this->addChartData($dimension, $invoice->invoice_date, $tax['amount']);
} }
} }
} }

View File

@ -468,7 +468,6 @@
if (['client'].indexOf(reportType) == -1) { if (['client'].indexOf(reportType) == -1) {
$subgroup.append(new Option("{{ trans('texts.client') }}", 'client')); $subgroup.append(new Option("{{ trans('texts.client') }}", 'client'));
} }
$subgroup.append(new Option("{{ trans('texts.user') }}", 'user')); $subgroup.append(new Option("{{ trans('texts.user') }}", 'user'));
if (reportType == 'activity') { if (reportType == 'activity') {
@ -484,6 +483,12 @@
$subgroup.append(new Option("{{ trans('texts.type') }}", 'type')); $subgroup.append(new Option("{{ trans('texts.type') }}", 'type'));
} else if (reportType == 'task') { } else if (reportType == 'task') {
$subgroup.append(new Option("{{ trans('texts.project') }}", 'project')); $subgroup.append(new Option("{{ trans('texts.project') }}", 'project'));
} else if (reportType == 'client') {
$subgroup.append(new Option("{{ trans('texts.country') }}", 'country'));
} else if (reportType == 'invoice' || reportType == 'quote') {
$subgroup.append(new Option("{{ trans('texts.status') }}", 'status'));
} else if (reportType == 'product') {
$subgroup.append(new Option("{{ trans('texts.product') }}", 'product'));
} }
if (isStorageSupported()) { if (isStorageSupported()) {