diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index fed420c..0a964e8 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -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')); diff --git a/app/View/Composers/MonthGraph.php b/app/View/Composers/MonthGraph.php new file mode 100644 index 0000000..aa33c2a --- /dev/null +++ b/app/View/Composers/MonthGraph.php @@ -0,0 +1,41 @@ +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]); + } +} diff --git a/app/View/Composers/YearGraph.php b/app/View/Composers/YearGraph.php new file mode 100644 index 0000000..f8dd378 --- /dev/null +++ b/app/View/Composers/YearGraph.php @@ -0,0 +1,41 @@ +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]); + } +} diff --git a/package-lock.json b/package-lock.json index 70c027d..75840de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,13 @@ { - "name": "project", + "name": "html", "lockfileVersion": 3, "requires": true, "packages": { "": { "dependencies": { "@alpinejs/sort": "^3.14.7", - "alpine": "^0.2.1" + "alpine": "^0.2.1", + "chart.js": "^4.4.7" }, "devDependencies": { "@tailwindcss/forms": "^0.5.9", @@ -501,6 +502,12 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@kurkle/color": { + "version": "0.3.4", + "resolved": "https://registry.npmjs.org/@kurkle/color/-/color-0.3.4.tgz", + "integrity": "sha512-M5UknZPHRu3DEDWoipU6sE8PdkZ6Z/S+v4dD+Ke8IaNlpdSQah50lz1KtcFBa2vsdOnwbbnxJwVM4wty6udA5w==", + "license": "MIT" + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -1134,6 +1141,18 @@ "node": ">=8" } }, + "node_modules/chart.js": { + "version": "4.4.7", + "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-4.4.7.tgz", + "integrity": "sha512-pwkcKfdzTMAU/+jNosKhNL2bHtJc/sSmYgVbuGTEDhzkrhmyihmP7vUc/5ZK9WopidMDHNe3Wm7jOd/WhuHWuw==", + "license": "MIT", + "dependencies": { + "@kurkle/color": "^0.3.0" + }, + "engines": { + "pnpm": ">=8" + } + }, "node_modules/chokidar": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", diff --git a/package.json b/package.json index 4d4bc2a..a6d706e 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ }, "dependencies": { "@alpinejs/sort": "^3.14.7", - "alpine": "^0.2.1" + "alpine": "^0.2.1", + "chart.js": "^4.4.7" } } diff --git a/resources/js/app.js b/resources/js/app.js index 1345258..a785094 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -2,8 +2,10 @@ import './bootstrap'; import Alpine from 'alpinejs'; import sort from '@alpinejs/sort'; +import Chart from "chart.js/auto"; Alpine.plugin(sort); window.Alpine = Alpine; +window.Chart = Chart; Alpine.start(); diff --git a/resources/views/components/graph-month.blade.php b/resources/views/components/graph-month.blade.php new file mode 100644 index 0000000..b429f58 --- /dev/null +++ b/resources/views/components/graph-month.blade.php @@ -0,0 +1,27 @@ +