1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00

Merge branch 'develop' of github.com:invoiceninja/invoiceninja into develop

This commit is contained in:
Hillel Coren 2020-03-31 13:01:02 +03:00
commit 762b06667c
7 changed files with 52 additions and 12 deletions

View File

@ -229,7 +229,7 @@ class SendReminders extends Command
// send email as user
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));
if ($file) {

View File

@ -61,6 +61,8 @@ class ReportController extends BaseController
$action = Input::get('action');
$format = Input::get('format');
$account = Auth::user()->account;
if (Input::get('report_type')) {
$reportType = Input::get('report_type');
$dateField = Input::get('date_field');
@ -96,10 +98,10 @@ class ReportController extends BaseController
'reportTypes' => array_combine($reportTypes, Utils::trans($reportTypes)),
'reportType' => $reportType,
'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';
$config = [
'date_field' => $dateField,
@ -112,7 +114,8 @@ class ReportController extends BaseController
'start_date' => $params['startDate'],
'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);
switch ($action) {
case 'export':

View File

@ -65,7 +65,17 @@ class ExportReportResults extends Job
foreach ($totals as $currencyId => $each) {
foreach ($each as $dimension => $val) {
$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) {
if ($field == 'duration') {
$tmp[] = Utils::formatTime($value);

View File

@ -10,11 +10,12 @@ use App\Jobs\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->reportType = $reportType;
$this->config = $config;
$this->account = $account;
$this->isExport = $isExport;
}
@ -71,7 +72,7 @@ class RunReport extends Job
$endDate = $config['end_date'];
}
$report = new $reportClass($startDate, $endDate, $isExport, $config);
$report = new $reportClass($startDate, $endDate, $isExport, $this->account, $config);
$report->run();
$params = [

View File

@ -2,6 +2,8 @@
namespace App\Ninja\Reports;
use App\Libraries\MoneyUtils;
use App\Models\Currency;
use Utils;
use Auth;
use Carbon;
@ -15,17 +17,19 @@ class AbstractReport
public $startDate;
public $endDate;
public $isExport;
private $account;
public $options;
public $totals = [];
public $data = [];
public $chartData = [];
public function __construct($startDate, $endDate, $isExport, $options = false)
public function __construct($startDate, $endDate, $isExport, $account, $options = false)
{
$this->startDate = $startDate;
$this->endDate = $endDate;
$this->isExport = $isExport;
$this->account = $account;
$this->options = $options;
}
@ -41,6 +45,8 @@ class AbstractReport
public function results()
{
asort($this->totals);
return [
'columns' => $this->getColumns(),
'displayData' => $this->data,
@ -53,14 +59,26 @@ class AbstractReport
$currencyId = $currencyId ?: Auth::user()->account->getCurrencyId();
if (! isset($this->totals[$currencyId][$dimension])) {
$this->totals[$currencyId][$dimension] = [];
}
$this->totals[$currencyId][$dimension] = [];
}
if (! isset($this->totals[$currencyId][$dimension][$field])) {
$this->totals[$currencyId][$dimension][$field] = 0;
}
$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() {

View File

@ -146,6 +146,7 @@ class InvoiceReport extends AbstractReport
$this->addToTotals($client->currency_id, 'amount', $invoice->amount);
$this->addToTotals($client->currency_id, 'balance', $invoice->balance);
$this->addToTotals($client->currency_id, 'tax', $invoice->getTaxTotal());
if ($subgroup == 'status') {
$dimension = $invoice->statusLabel();

View File

@ -286,7 +286,12 @@
@foreach ($reportTotals as $currencyId => $each)
@foreach ($each as $dimension => $val)
<tr>
<td>{!! Utils::getFromCache($currencyId, 'currencies')->name !!}
<td>
@if ($currencyId == 'Total')
Total
@else
{!! Utils::getFromCache($currencyId, 'currencies')->name !!}
@endif
@if ($dimension)
- {{ $dimension }}
@endif
@ -295,8 +300,10 @@
<td>
@if ($field == 'duration')
{{ Utils::formatTime($value) }}
@elseif ($currencyId == 'Total')
{{ Utils::formatMoney($value, $account->getCurrencyId()) }}
@else
{{ Utils::formatMoney($value, $currencyId) }}
{{ Utils::formatMoney($value, $currencyId) }}
@endif
</td>
@endforeach