Merge branch 'master' of https://github.com/brkcvn/akaunting into code-clean
This commit is contained in:
@ -199,6 +199,8 @@ abstract class Report
|
||||
|
||||
$chart->setType('bar')
|
||||
->setOptions($options)
|
||||
->setDefaultLocale($this->getDefaultLocaleOfChart())
|
||||
->setLocales($this->getLocaleTranslationOfChart())
|
||||
->setLabels(array_values($this->dates))
|
||||
->setDataset($this->tables[$table_key], 'column', array_values($this->footer_totals[$table_key]));
|
||||
|
||||
@ -246,6 +248,8 @@ abstract class Report
|
||||
|
||||
$chart->setType('donut')
|
||||
->setOptions($options)
|
||||
->setDefaultLocale($this->getDefaultLocaleOfChart())
|
||||
->setLocales($this->getLocaleTranslationOfChart())
|
||||
->setLabels(array_values($labels))
|
||||
->setColors(array_values($colors))
|
||||
->setDataset($this->tables[$table_key], 'donut', array_values($values));
|
||||
@ -300,8 +304,8 @@ abstract class Report
|
||||
|
||||
public function setChartLabelFormatter()
|
||||
{
|
||||
$this->chart['bar']['yaxis']['labels']['formatter'] = $this->getFormatLabel();
|
||||
$this->chart['donut']['yaxis']['labels']['formatter'] = $this->getFormatLabel('percent');
|
||||
$this->chart['bar']['yaxis']['labels']['formatter'] = $this->getChartLabelFormatter();
|
||||
$this->chart['donut']['yaxis']['labels']['formatter'] = $this->getChartLabelFormatter('percent');
|
||||
}
|
||||
|
||||
public function setYear()
|
||||
|
@ -68,7 +68,7 @@ class CreateBankingDocumentTransaction extends Job implements ShouldCreate
|
||||
|
||||
$this->request['company_id'] = $this->model->company_id;
|
||||
$this->request['currency_code'] = isset($this->request['currency_code']) ? $this->request['currency_code'] : $this->model->currency_code;
|
||||
$this->request['paid_at'] = isset($this->request['paid_at']) ? $this->request['paid_at'] : Date::now()->format('Y-m-d');
|
||||
$this->request['paid_at'] = isset($this->request['paid_at']) ? $this->request['paid_at'] : Date::now()->toDateTimeString();
|
||||
$this->request['currency_rate'] = config('money.' . $currency_code . '.rate');
|
||||
$this->request['account_id'] = isset($this->request['account_id']) ? $this->request['account_id'] : setting('default.account');
|
||||
$this->request['document_id'] = isset($this->request['document_id']) ? $this->request['document_id'] : $this->model->id;
|
||||
|
@ -67,7 +67,7 @@ class UpdateBankingDocumentTransaction extends Job implements ShouldUpdate
|
||||
|
||||
$this->request['company_id'] = $this->model->company_id;
|
||||
$this->request['currency_code'] = isset($this->request['currency_code']) ? $this->request['currency_code'] : $this->model->currency_code;
|
||||
$this->request['paid_at'] = isset($this->request['paid_at']) ? $this->request['paid_at'] : Date::now()->format('Y-m-d');
|
||||
$this->request['paid_at'] = isset($this->request['paid_at']) ? $this->request['paid_at'] : Date::now()->toDateTimeString();
|
||||
$this->request['currency_rate'] = config('money.' . $currency_code . '.rate');
|
||||
$this->request['account_id'] = isset($this->request['account_id']) ? $this->request['account_id'] : setting('default.account');
|
||||
$this->request['document_id'] = isset($this->request['document_id']) ? $this->request['document_id'] : $this->model->id;
|
||||
|
@ -19,14 +19,14 @@ trait Charts
|
||||
'values' => [],
|
||||
];
|
||||
|
||||
public function addToDonut($color, $label, $value)
|
||||
public function addToDonutChart($color, $label, $value)
|
||||
{
|
||||
$this->donut['colors'][] = $color;
|
||||
$this->donut['labels'][] = $label;
|
||||
$this->donut['values'][] = (int) $value;
|
||||
}
|
||||
|
||||
public function addMoneyToDonut($color, $amount, $description = '')
|
||||
public function addMoneyToDonutChart($color, $amount, $description = '')
|
||||
{
|
||||
$label = money($amount, setting('default.currency'), true)->formatForHumans();
|
||||
|
||||
@ -34,7 +34,7 @@ trait Charts
|
||||
$label .= ' - ' . $description;
|
||||
}
|
||||
|
||||
$this->addToDonut($color, $label, $amount);
|
||||
$this->addToDonutChart($color, $label, $amount);
|
||||
}
|
||||
|
||||
public function getDonutChart($name, $width = '100%', $height = 300, $limit = 10)
|
||||
@ -60,6 +60,8 @@ trait Charts
|
||||
$chart->setType('donut')
|
||||
->setWidth($width)
|
||||
->setHeight($height)
|
||||
->setDefaultLocale($this->getDefaultLocaleOfChart())
|
||||
->setLocales($this->getLocaleTranslationOfChart())
|
||||
->setLabels(array_values($labels))
|
||||
->setColors(array_values($colors))
|
||||
->setDataset($name, 'donut', array_values($values));
|
||||
@ -67,7 +69,7 @@ trait Charts
|
||||
return $chart;
|
||||
}
|
||||
|
||||
public function addToBar($color, $label, $value)
|
||||
public function addToBarChart($color, $label, $value)
|
||||
{
|
||||
$this->bar['colors'][] = $color;
|
||||
$this->bar['labels'][] = $label;
|
||||
@ -81,6 +83,8 @@ trait Charts
|
||||
$chart->setType('bar')
|
||||
->setWidth($width)
|
||||
->setHeight($height)
|
||||
->setDefaultLocale($this->getDefaultLocaleOfChart())
|
||||
->setLocales($this->getLocaleTranslationOfChart())
|
||||
->setLabels(array_values($this->bar['labels']))
|
||||
->setColors($this->bar['colors']);
|
||||
|
||||
@ -91,7 +95,7 @@ trait Charts
|
||||
return $chart;
|
||||
}
|
||||
|
||||
public function getFormatLabel($type = 'money', $position = null)
|
||||
public function getChartLabelFormatter($type = 'money', $position = null)
|
||||
{
|
||||
$label = '';
|
||||
$decimal_mark = str_replace("'", "\\'", config('money.' . setting('default.currency') . '.decimal_mark'));
|
||||
@ -165,4 +169,62 @@ trait Charts
|
||||
|
||||
return $label;
|
||||
}
|
||||
|
||||
public function getDefaultLocaleOfChart(): string
|
||||
{
|
||||
$default = 'en';
|
||||
|
||||
$short = language()->getShortCode();
|
||||
$long = language()->getLongCode();
|
||||
|
||||
$short_path = public_path('vendor/apexcharts/locales/' . $short . '.json');
|
||||
$long_path = public_path('vendor/apexcharts/locales/' . $long . '.json');
|
||||
|
||||
if (is_file($short_path)) {
|
||||
return $short;
|
||||
}
|
||||
|
||||
if (is_file($long_path)) {
|
||||
return $long;
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
public function getLocaleTranslationOfChart(?string $locale = null): array
|
||||
{
|
||||
$translations = [];
|
||||
|
||||
$user_locale = $locale ?: $this->getDefaultLocaleOfChart();
|
||||
|
||||
$locales = ($user_locale == 'en') ? [$user_locale] : [$user_locale, 'en'];
|
||||
|
||||
foreach ($locales as $loc) {
|
||||
$translations[] = json_decode(
|
||||
file_get_contents(
|
||||
public_path('vendor/apexcharts/locales/' . $loc . '.json')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $translations;
|
||||
}
|
||||
|
||||
// @deprecated version 3.0.0
|
||||
public function addToDonut($color, $label, $value)
|
||||
{
|
||||
$this->addToDonutChart($color, $label, $value);
|
||||
}
|
||||
|
||||
// @deprecated version 3.0.0
|
||||
public function addMoneyToDonut($color, $amount, $description = '')
|
||||
{
|
||||
$this->addMoneyToDonutChart($color, $amount, $description);
|
||||
}
|
||||
|
||||
// @deprecated version 3.0.0
|
||||
public function addToBar($color, $label, $value)
|
||||
{
|
||||
$this->addToBarChart($color, $label, $value);
|
||||
}
|
||||
}
|
||||
|
@ -34,39 +34,21 @@ class CashFlow extends Widget
|
||||
{
|
||||
$this->setFilter();
|
||||
|
||||
$labels = $this->getLabels();
|
||||
|
||||
$income = array_values($this->calculateTotals('income'));
|
||||
$expense = array_values($this->calculateTotals('expense'));
|
||||
$profit = array_values($this->calculateProfit($income, $expense));
|
||||
|
||||
$colors = $this->getColors();
|
||||
|
||||
$options = [
|
||||
'chart' => [
|
||||
'stacked' => true,
|
||||
],
|
||||
'plotOptions' => [
|
||||
'bar' => [
|
||||
'columnWidth' => '40%',
|
||||
],
|
||||
],
|
||||
'legend' => [
|
||||
'position' => 'top',
|
||||
],
|
||||
'yaxis' => [
|
||||
'labels' => [
|
||||
'formatter' => $this->getFormatLabel(),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$chart = new Chart();
|
||||
|
||||
$chart->setType('line')
|
||||
->setOptions($options)
|
||||
->setLabels(array_values($labels))
|
||||
->setColors($colors)
|
||||
->setDefaultLocale($this->getDefaultLocaleOfChart())
|
||||
->setLocales($this->getLocaleTranslationOfChart())
|
||||
->setStacked(true)
|
||||
->setBar(['columnWidth' => '40%'])
|
||||
->setLegendPosition('top')
|
||||
->setYaxisLabels(['formatter' => $this->getChartLabelFormatter()])
|
||||
->setLabels(array_values($this->getLabels()))
|
||||
->setColors($this->getColors())
|
||||
->setDataset(trans('general.incoming'), 'column', $income)
|
||||
->setDataset(trans('general.outgoing'), 'column', $expense)
|
||||
->setDataset(trans_choice('general.profits', 1), 'line', $profit);
|
||||
|
@ -22,7 +22,7 @@ class ExpensesByCategory extends Widget
|
||||
$amount += $transaction->getAmountConvertedToDefault();
|
||||
});
|
||||
|
||||
$this->addMoneyToDonut($category->colorHexCode, $amount, $category->name);
|
||||
$this->addMoneyToDonutChart($category->colorHexCode, $amount, $category->name);
|
||||
});
|
||||
|
||||
$chart = $this->getDonutChart(trans_choice('general.expenses', 2), '100%', 300, 6);
|
||||
|
@ -31,37 +31,18 @@ class ProfitLoss extends Widget
|
||||
{
|
||||
$this->setFilter();
|
||||
|
||||
$labels = $this->getLabels();
|
||||
|
||||
$income = $this->getIncome();
|
||||
|
||||
$expense = $this->getExpense();
|
||||
|
||||
$colors = $this->getColors();
|
||||
|
||||
$chart = new Chart();
|
||||
|
||||
$options = [
|
||||
'legend' => [
|
||||
'position' => 'top',
|
||||
'markers' => [
|
||||
'radius' => '12',
|
||||
],
|
||||
],
|
||||
|
||||
'yaxis' => [
|
||||
'labels' => [
|
||||
'formatter' => $this->getFormatLabel(),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$chart->setType('bar')
|
||||
->setOptions($options)
|
||||
->setLabels(array_values($labels))
|
||||
->setColors($colors)
|
||||
->setDataset(trans_choice('general.incomes', 1), 'column', array_values($income))
|
||||
->setDataset(trans_choice('general.expenses', 1), 'column', array_values($expense));
|
||||
->setDefaultLocale($this->getDefaultLocaleOfChart())
|
||||
->setLocales($this->getLocaleTranslationOfChart())
|
||||
->setLegendPosition('top')
|
||||
->setLegendMarkers(['radius' => '12'])
|
||||
->setYaxisLabels(['formatter' => $this->getChartLabelFormatter()])
|
||||
->setLabels(array_values($this->getLabels()))
|
||||
->setColors($this->getColors())
|
||||
->setDataset(trans_choice('general.incomes', 1), 'column', array_values($this->getIncome()))
|
||||
->setDataset(trans_choice('general.expenses', 1), 'column', array_values($this->getExpense()));
|
||||
|
||||
return $this->view('widgets.bar_chart', [
|
||||
'chart' => $chart,
|
||||
|
Reference in New Issue
Block a user