refactored widgets

This commit is contained in:
denisdulici
2019-12-29 03:01:19 +03:00
parent e41b56a5b0
commit 6052506fd0
23 changed files with 445 additions and 935 deletions

View File

@ -4,14 +4,15 @@ namespace App\Abstracts;
use App\Exports\Common\Reports as Export;
use App\Models\Common\Report as Model;
use App\Utilities\Chartjs;
use App\Traits\Charts;
use App\Traits\DateTime;
use App\Utilities\Chartjs;
use Date;
use Illuminate\Support\Str;
abstract class Report
{
use DateTime;
use Charts, DateTime;
public $report;
@ -125,56 +126,7 @@ abstract class Report
$config = $this->chart[$this->report->chart];
$default_options = [
'tooltips' => [
'backgroundColor' => '#f5f5f5',
'titleFontColor' => '#333',
'bodyFontColor' => '#666',
'bodySpacing' => 4,
'YrPadding' => 12,
'mode' => 'nearest',
'intersect' => 0,
'position' => 'nearest'
],
'responsive' => true,
'scales' => [
'yAxes' => [
[
'barPercentage' => '1.6',
'gridLines' => [
'drawBorder' => false,
'color' => 'rgba(29,140,248,0.1)',
'zeroLineColor' => 'transparent',
'borderDash' => [2],
'borderDashOffset' => [2],
],
'ticks' => [
'padding' => 10,
'fontColor' => '#9e9e9e'
]
]
],
'xAxes' => [
[
'barPercentage' => '1.6',
'gridLines' => [
'drawBorder' => false,
'color' => 'rgba(29,140,248,0.0)',
'zeroLineColor' => 'transparent'
],
'ticks' => [
'suggestedMin' => 60,
'suggestedMax' => 125,
'padding' => 20,
'fontColor' => '#9e9e9e'
]
]
]
]
];
$default_options = $this->getLineChartOptions();
$options = array_merge($default_options, (array) $config['options']);

63
app/Abstracts/Widget.php Normal file
View File

@ -0,0 +1,63 @@
<?php
namespace App\Abstracts;
use Arrilot\Widgets\AbstractWidget;
use App\Models\Income\Invoice;
use App\Traits\Charts;
use Date;
abstract class Widget extends AbstractWidget
{
use Charts;
/**
* The configuration array.
*
* @var array
*/
protected $config = [
'width' => 'col-md-4',
];
/**
* Treat this method as a controller action.
* Return view() or other content to display.
*/
public function run()
{
return $this->show();
}
public function calculateDocumentTotals($model)
{
$open = $overdue = 0;
$today = Date::today()->toDateString();
$type = ($model instanceof Invoice) ? 'invoice' : 'bill';
$status_field = $type . '_status_code';
if ($model->$status_field == 'paid') {
return [$open, $overdue];
}
$payments = 0;
if ($model->$status_field == 'partial') {
foreach ($model->transactions as $transaction) {
$payments += $transaction->getAmountConvertedToDefault();
}
}
// Check if the invoice/bill is open or overdue
if ($model->due_at > $today) {
$open += $model->getAmountConvertedToDefault() - $payments;
} else {
$overdue += $model->getAmountConvertedToDefault() - $payments;
}
return [$open, $overdue];
}
}