mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Merge branch 'develop' of github.com:invoiceninja/invoiceninja into develop
This commit is contained in:
commit
762b06667c
@ -229,7 +229,7 @@ class SendReminders extends Command
|
|||||||
// send email as user
|
// send email as user
|
||||||
auth()->onceUsingId($user->id);
|
auth()->onceUsingId($user->id);
|
||||||
|
|
||||||
$report = dispatch_now(new RunReport($scheduledReport->user, $reportType, $config, true));
|
$report = dispatch_now(new RunReport($scheduledReport->user, $reportType, $config, $account, true));
|
||||||
$file = dispatch_now(new ExportReportResults($scheduledReport->user, $config['export_format'], $reportType, $report->exportParams));
|
$file = dispatch_now(new ExportReportResults($scheduledReport->user, $config['export_format'], $reportType, $report->exportParams));
|
||||||
|
|
||||||
if ($file) {
|
if ($file) {
|
||||||
|
@ -61,6 +61,8 @@ class ReportController extends BaseController
|
|||||||
$action = Input::get('action');
|
$action = Input::get('action');
|
||||||
$format = Input::get('format');
|
$format = Input::get('format');
|
||||||
|
|
||||||
|
$account = Auth::user()->account;
|
||||||
|
|
||||||
if (Input::get('report_type')) {
|
if (Input::get('report_type')) {
|
||||||
$reportType = Input::get('report_type');
|
$reportType = Input::get('report_type');
|
||||||
$dateField = Input::get('date_field');
|
$dateField = Input::get('date_field');
|
||||||
@ -96,10 +98,10 @@ class ReportController extends BaseController
|
|||||||
'reportTypes' => array_combine($reportTypes, Utils::trans($reportTypes)),
|
'reportTypes' => array_combine($reportTypes, Utils::trans($reportTypes)),
|
||||||
'reportType' => $reportType,
|
'reportType' => $reportType,
|
||||||
'title' => trans('texts.charts_and_reports'),
|
'title' => trans('texts.charts_and_reports'),
|
||||||
'account' => Auth::user()->account,
|
'account' => $account,
|
||||||
];
|
];
|
||||||
|
|
||||||
if (Auth::user()->account->hasFeature(FEATURE_REPORTS)) {
|
if ($account->hasFeature(FEATURE_REPORTS)) {
|
||||||
$isExport = $action == 'export';
|
$isExport = $action == 'export';
|
||||||
$config = [
|
$config = [
|
||||||
'date_field' => $dateField,
|
'date_field' => $dateField,
|
||||||
@ -112,7 +114,8 @@ class ReportController extends BaseController
|
|||||||
'start_date' => $params['startDate'],
|
'start_date' => $params['startDate'],
|
||||||
'end_date' => $params['endDate'],
|
'end_date' => $params['endDate'],
|
||||||
];
|
];
|
||||||
$report = dispatch_now(new RunReport(auth()->user(), $reportType, $config, $isExport));
|
|
||||||
|
$report = dispatch_now(new RunReport(auth()->user(), $reportType, $config, $account, $isExport));
|
||||||
$params = array_merge($params, $report->exportParams);
|
$params = array_merge($params, $report->exportParams);
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case 'export':
|
case 'export':
|
||||||
|
@ -65,7 +65,17 @@ class ExportReportResults extends Job
|
|||||||
foreach ($totals as $currencyId => $each) {
|
foreach ($totals as $currencyId => $each) {
|
||||||
foreach ($each as $dimension => $val) {
|
foreach ($each as $dimension => $val) {
|
||||||
$tmp = [];
|
$tmp = [];
|
||||||
$tmp[] = Utils::getFromCache($currencyId, 'currencies')->name . (($dimension) ? ' - ' . $dimension : '');
|
|
||||||
|
$currency = Utils::getFromCache($currencyId, 'currencies');
|
||||||
|
if (!$currency) {
|
||||||
|
$name = $currencyId;
|
||||||
|
$account = $this->user->account->first();
|
||||||
|
$currencyId = $account->currency_id;
|
||||||
|
} else {
|
||||||
|
$name = $currency->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tmp[] = $dimension ? $name . ' - ' . $dimension : $name;
|
||||||
foreach ($val as $field => $value) {
|
foreach ($val as $field => $value) {
|
||||||
if ($field == 'duration') {
|
if ($field == 'duration') {
|
||||||
$tmp[] = Utils::formatTime($value);
|
$tmp[] = Utils::formatTime($value);
|
||||||
|
@ -10,11 +10,12 @@ use App\Jobs\Job;
|
|||||||
|
|
||||||
class RunReport extends Job
|
class RunReport extends Job
|
||||||
{
|
{
|
||||||
public function __construct($user, $reportType, $config, $isExport = false)
|
public function __construct($user, $reportType, $config, $account, $isExport = false)
|
||||||
{
|
{
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->reportType = $reportType;
|
$this->reportType = $reportType;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
$this->account = $account;
|
||||||
$this->isExport = $isExport;
|
$this->isExport = $isExport;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +72,7 @@ class RunReport extends Job
|
|||||||
$endDate = $config['end_date'];
|
$endDate = $config['end_date'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$report = new $reportClass($startDate, $endDate, $isExport, $config);
|
$report = new $reportClass($startDate, $endDate, $isExport, $this->account, $config);
|
||||||
$report->run();
|
$report->run();
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Ninja\Reports;
|
namespace App\Ninja\Reports;
|
||||||
|
|
||||||
|
use App\Libraries\MoneyUtils;
|
||||||
|
use App\Models\Currency;
|
||||||
use Utils;
|
use Utils;
|
||||||
use Auth;
|
use Auth;
|
||||||
use Carbon;
|
use Carbon;
|
||||||
@ -15,17 +17,19 @@ class AbstractReport
|
|||||||
public $startDate;
|
public $startDate;
|
||||||
public $endDate;
|
public $endDate;
|
||||||
public $isExport;
|
public $isExport;
|
||||||
|
private $account;
|
||||||
public $options;
|
public $options;
|
||||||
|
|
||||||
public $totals = [];
|
public $totals = [];
|
||||||
public $data = [];
|
public $data = [];
|
||||||
public $chartData = [];
|
public $chartData = [];
|
||||||
|
|
||||||
public function __construct($startDate, $endDate, $isExport, $options = false)
|
public function __construct($startDate, $endDate, $isExport, $account, $options = false)
|
||||||
{
|
{
|
||||||
$this->startDate = $startDate;
|
$this->startDate = $startDate;
|
||||||
$this->endDate = $endDate;
|
$this->endDate = $endDate;
|
||||||
$this->isExport = $isExport;
|
$this->isExport = $isExport;
|
||||||
|
$this->account = $account;
|
||||||
$this->options = $options;
|
$this->options = $options;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,6 +45,8 @@ class AbstractReport
|
|||||||
|
|
||||||
public function results()
|
public function results()
|
||||||
{
|
{
|
||||||
|
asort($this->totals);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'columns' => $this->getColumns(),
|
'columns' => $this->getColumns(),
|
||||||
'displayData' => $this->data,
|
'displayData' => $this->data,
|
||||||
@ -53,14 +59,26 @@ class AbstractReport
|
|||||||
$currencyId = $currencyId ?: Auth::user()->account->getCurrencyId();
|
$currencyId = $currencyId ?: Auth::user()->account->getCurrencyId();
|
||||||
|
|
||||||
if (! isset($this->totals[$currencyId][$dimension])) {
|
if (! isset($this->totals[$currencyId][$dimension])) {
|
||||||
$this->totals[$currencyId][$dimension] = [];
|
$this->totals[$currencyId][$dimension] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isset($this->totals[$currencyId][$dimension][$field])) {
|
if (! isset($this->totals[$currencyId][$dimension][$field])) {
|
||||||
$this->totals[$currencyId][$dimension][$field] = 0;
|
$this->totals[$currencyId][$dimension][$field] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->totals[$currencyId][$dimension][$field] += $value;
|
$this->totals[$currencyId][$dimension][$field] += $value;
|
||||||
|
|
||||||
|
if($currencyId !== 'Total') $this->addTotalToTotals($currencyId, $field, $value, $dimension);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function addTotalToTotals($currencyId, $field, $value, $dimension = false)
|
||||||
|
{
|
||||||
|
if ($currencyId != $this->account->getCurrencyId()) {
|
||||||
|
$currency = Currency::where('id', $currencyId)->first();
|
||||||
|
$value = MoneyUtils::convert($value, $currency->code, $this->account->currency->code);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->addToTotals('Total', $field, $value, $dimension);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tableHeaderArray() {
|
public function tableHeaderArray() {
|
||||||
|
@ -146,6 +146,7 @@ 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);
|
||||||
|
$this->addToTotals($client->currency_id, 'tax', $invoice->getTaxTotal());
|
||||||
|
|
||||||
if ($subgroup == 'status') {
|
if ($subgroup == 'status') {
|
||||||
$dimension = $invoice->statusLabel();
|
$dimension = $invoice->statusLabel();
|
||||||
|
@ -286,7 +286,12 @@
|
|||||||
@foreach ($reportTotals as $currencyId => $each)
|
@foreach ($reportTotals as $currencyId => $each)
|
||||||
@foreach ($each as $dimension => $val)
|
@foreach ($each as $dimension => $val)
|
||||||
<tr>
|
<tr>
|
||||||
<td>{!! Utils::getFromCache($currencyId, 'currencies')->name !!}
|
<td>
|
||||||
|
@if ($currencyId == 'Total')
|
||||||
|
Total
|
||||||
|
@else
|
||||||
|
{!! Utils::getFromCache($currencyId, 'currencies')->name !!}
|
||||||
|
@endif
|
||||||
@if ($dimension)
|
@if ($dimension)
|
||||||
- {{ $dimension }}
|
- {{ $dimension }}
|
||||||
@endif
|
@endif
|
||||||
@ -295,8 +300,10 @@
|
|||||||
<td>
|
<td>
|
||||||
@if ($field == 'duration')
|
@if ($field == 'duration')
|
||||||
{{ Utils::formatTime($value) }}
|
{{ Utils::formatTime($value) }}
|
||||||
|
@elseif ($currencyId == 'Total')
|
||||||
|
{{ Utils::formatMoney($value, $account->getCurrencyId()) }}
|
||||||
@else
|
@else
|
||||||
{{ Utils::formatMoney($value, $currencyId) }}
|
{{ Utils::formatMoney($value, $currencyId) }}
|
||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
Loading…
x
Reference in New Issue
Block a user