Include graph.js and build some dashboard tiles.
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\View\Composers\MonthGraph;
|
||||
use App\View\Composers\OptionLogo;
|
||||
use App\View\Composers\TaxDropdown;
|
||||
use App\View\Composers\YearGraph;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\Number;
|
||||
@@ -36,6 +38,8 @@ class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
View::composer('components.tax-dropdown', TaxDropdown::class);
|
||||
View::composer('components.company-logo', OptionLogo::class);
|
||||
View::composer('components.graph-year', YearGraph::class);
|
||||
View::composer('components.graph-month', MonthGraph::class);
|
||||
Number::useLocale(config('app.locale'));
|
||||
Number::useCurrency(config('app.currency'));
|
||||
|
||||
|
||||
41
app/View/Composers/MonthGraph.php
Normal file
41
app/View/Composers/MonthGraph.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Composers;
|
||||
|
||||
use App\Models\Incoming;
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class MonthGraph
|
||||
{
|
||||
public function compose(View $view): void
|
||||
{
|
||||
$monthly_invoices = Invoice::whereYear('created_at', '=', Carbon::now()->year)->get()
|
||||
->groupBy(function ($invoice) {
|
||||
return $invoice->created_at->format('n');
|
||||
})
|
||||
->map(function ($month) {
|
||||
return $month->sum('sum');
|
||||
});
|
||||
|
||||
$monthly_incoming = Incoming::whereYear('issue_date', '=', Carbon::now()->year)->get()
|
||||
->groupBy(function ($incoming) {
|
||||
return Carbon::parse($incoming->issue_date)->format('n');
|
||||
})
|
||||
->map(function ($month) {
|
||||
return $month->sum('net');
|
||||
});
|
||||
|
||||
$diff_invoices = $monthly_invoices->diffKeys($monthly_incoming);
|
||||
foreach ($diff_invoices as $year => $invoices) {
|
||||
$monthly_incoming[$year] = 0;
|
||||
}
|
||||
$diff_incoming = $monthly_incoming->diffKeys($monthly_invoices);
|
||||
foreach ($diff_incoming as $year => $invoices) {
|
||||
$monthly_invoices[$year] = 0;
|
||||
}
|
||||
|
||||
$view->with(['monthly_invoices' => $monthly_invoices, 'monthly_incoming' => $monthly_incoming]);
|
||||
}
|
||||
}
|
||||
41
app/View/Composers/YearGraph.php
Normal file
41
app/View/Composers/YearGraph.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Composers;
|
||||
|
||||
use App\Models\Incoming;
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class YearGraph
|
||||
{
|
||||
public function compose(View $view): void
|
||||
{
|
||||
$yearly_invoices = Invoice::all()
|
||||
->groupBy(function ($invoice) {
|
||||
return $invoice->created_at->format('Y');
|
||||
})
|
||||
->map(function ($year) {
|
||||
return $year->sum('sum');
|
||||
});
|
||||
|
||||
$yearly_incoming = Incoming::all()
|
||||
->groupBy(function ($incoming) {
|
||||
return Carbon::parse($incoming->pay_date)->format('Y');
|
||||
})
|
||||
->map(function ($year) {
|
||||
return $year->sum('net');
|
||||
});
|
||||
|
||||
$diff_invoices = $yearly_invoices->diffKeys($yearly_incoming);
|
||||
foreach ($diff_invoices as $year => $invoices) {
|
||||
$yearly_incoming[$year] = 0;
|
||||
}
|
||||
$diff_incoming = $yearly_incoming->diffKeys($yearly_invoices);
|
||||
foreach ($diff_incoming as $year => $invoices) {
|
||||
$yearly_invoices[$year] = 0;
|
||||
}
|
||||
|
||||
$view->with(['yearly_invoices' => $yearly_invoices, 'yearly_incoming' => $yearly_incoming]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user