Penjualan
- View Report -- - Penjualan Keseluruhan -
-- - 33.1% - - dari bulan lalu -
-diff --git a/app/Http/Controllers/Admins/DashboardController.php b/app/Http/Controllers/Admins/Dashboard/CalculationController.php similarity index 58% rename from app/Http/Controllers/Admins/DashboardController.php rename to app/Http/Controllers/Admins/Dashboard/CalculationController.php index 48e924e..493b77f 100644 --- a/app/Http/Controllers/Admins/DashboardController.php +++ b/app/Http/Controllers/Admins/Dashboard/CalculationController.php @@ -1,52 +1,24 @@ get(); - - return DataTables::of($data) - ->addIndexColumn() - ->make(true); - } public function getCalculationPendapatan() { $pendapatanBulan = $this->calculatePendapatanBulan(); + $pendapatanMinggu = $this->calculatePendapatanMinggu(); $pendapatanHari = $this->calculatePendapatanHari(); - $pengeluaranBulan = $this->calculatePengeluaranBulan(); - $pengeluaranHari = $this->calculatePengeluaranHari(); - - return ResponseFormatter::success(['pendapatanBulan' => $pendapatanBulan, 'pendapatanHari' => $pendapatanHari, 'pengeluaranBulan' => $pengeluaranBulan, 'pengeluaranHari' => $pengeluaranHari]); + // dd($pendapatanMinggu); + return ResponseFormatter::success(['pendapatanBulan' => $pendapatanBulan, 'pendapatanMinggu' => $pendapatanMinggu, 'pendapatanHari' => $pendapatanHari]); } private function calculatePendapatanBulan() @@ -95,6 +67,52 @@ class DashboardController extends Controller ]; } + private function calculatePendapatanMinggu() + { + // tanggal minggu ini + $first_day_of_the_current_week = Carbon::today()->startOfWeek(); + $last_day_of_the_current_week = $first_day_of_the_current_week->copy()->endOfWeek(); + // dd($last_day_of_the_current_week); + // tanggal minggu lalu + $first_day_of_the_previous_week = $first_day_of_the_current_week->copy()->subWeek()->startOfWeek(); + $last_day_of_the_previous_week = $first_day_of_the_current_week->copy()->subWeek()->endOfWeek(); + + // get data jumlah penjualan keseluruhan dalam satu minggu + $penjualanSatuMinggu = Pesanan::whereBetween('tanggal_pesanan', [$first_day_of_the_current_week, $last_day_of_the_current_week])->sum('grand_total'); + $penjualanMingguLalu = Pesanan::whereBetween('tanggal_pesanan', [$first_day_of_the_previous_week, $last_day_of_the_previous_week])->sum('grand_total'); + + /** + * @Author: xelz + * @Date: 2024-01-30 15:52:41 + * @Desc: constant status + * 1 netral + * 2 plus + * 3 minus + */ + $statusCalculation = 1; + + // calculate percentage of sales growth in the last week and this week + if ($penjualanMingguLalu != 0) { + $statusCalculation = 2; + $percentageOfSalesGrowth = ($penjualanSatuMinggu - $penjualanMingguLalu) / $penjualanMingguLalu * 100; + // minus or not + if ($percentageOfSalesGrowth < 0) { + $statusCalculation = 3; + $percentageOfSalesGrowth = $percentageOfSalesGrowth * -1; + } + } else { + $statusCalculation = 1; + $percentageOfSalesGrowth = 0; + } + + return [ + 'penjualanSatuMinggu' => $penjualanSatuMinggu, + 'penjualanMingguLalu' => $penjualanMingguLalu, + 'statusCalculation' => $statusCalculation, + 'percentageOfSalesGrowth' => $percentageOfSalesGrowth + ]; + } + private function calculatePendapatanHari() { // tanggal hari ini @@ -152,9 +170,9 @@ class DashboardController extends Controller $first_day_of_the_previous_month = $first_day_of_the_current_month->copy()->subMonth()->startOfMonth(); $last_day_of_the_previous_month = $first_day_of_the_current_month->copy()->subMonth()->endOfMonth(); - // get data jumlah penjualan keseluruhan dalam satu bulan - $penjualanSatuBulan = pengeluaran::whereBetween('tanggal', [$first_day_of_the_current_month, $last_day_of_the_current_month])->sum('nominal'); - $penjualanBulanLalu = pengeluaran::whereBetween('tanggal', [$first_day_of_the_previous_month, $last_day_of_the_previous_month])->sum('nominal'); + // get data jumlah pengeluaran keseluruhan dalam satu bulan + $pengeluaranSatuBulan = pengeluaran::whereBetween('tanggal', [$first_day_of_the_current_month, $last_day_of_the_current_month])->sum('nominal'); + $pengeluaranBulanLalu = pengeluaran::whereBetween('tanggal', [$first_day_of_the_previous_month, $last_day_of_the_previous_month])->sum('nominal'); /** * @Author: xelz @@ -167,9 +185,9 @@ class DashboardController extends Controller $statusCalculation = 1; // calculate percentage of sales growth in the last month and this month - if ($penjualanBulanLalu != 0) { + if ($pengeluaranBulanLalu != 0) { $statusCalculation = 2; - $percentageOfSalesGrowth = ($penjualanSatuBulan - $penjualanBulanLalu) / $penjualanBulanLalu * 100; + $percentageOfSalesGrowth = ($pengeluaranSatuBulan - $pengeluaranBulanLalu) / $pengeluaranBulanLalu * 100; // minus or not if ($percentageOfSalesGrowth < 0) { $statusCalculation = 3; @@ -181,8 +199,8 @@ class DashboardController extends Controller } return [ - 'penjualanSatuBulan' => $penjualanSatuBulan, - 'penjualanBulanLalu' => $penjualanBulanLalu, + 'pengeluaranSatuBulan' => $pengeluaranSatuBulan, + 'pengeluaranBulanLalu' => $pengeluaranBulanLalu, 'statusCalculation' => $statusCalculation, 'percentageOfSalesGrowth' => $percentageOfSalesGrowth ]; @@ -199,9 +217,9 @@ class DashboardController extends Controller $first_day_of_the_previous_day = $first_day_of_the_current_day->copy()->subDay()->startOfDay(); $last_day_of_the_previous_day = $first_day_of_the_current_day->copy()->subDay()->endOfDay(); - // get data jumlah penjualan keseluruhan dalam satu bulan - $penjualanHariIni = Pengeluaran::whereBetween('tanggal', [$first_day_of_the_current_day, $last_day_of_the_current_day])->sum('nominal'); - $penjualanKemarin = pengeluaran::whereBetween('tanggal', [$first_day_of_the_previous_day, $last_day_of_the_previous_day])->sum('nominal'); + // get data jumlah pengeluaran keseluruhan dalam satu bulan + $pengeluaranHariIni = Pengeluaran::whereBetween('tanggal', [$first_day_of_the_current_day, $last_day_of_the_current_day])->sum('nominal'); + $pengeluaranKemarin = pengeluaran::whereBetween('tanggal', [$first_day_of_the_previous_day, $last_day_of_the_previous_day])->sum('nominal'); /** * @Author: xelz @@ -214,9 +232,9 @@ class DashboardController extends Controller $statusCalculation = 1; // calculate percentage of sales growth in the last month and this month - if ($penjualanKemarin != 0) { + if ($pengeluaranKemarin != 0) { $statusCalculation = 2; - $percentageOfSalesGrowth = ($penjualanHariIni - $penjualanKemarin) / $penjualanKemarin * 100; + $percentageOfSalesGrowth = ($pengeluaranHariIni - $pengeluaranKemarin) / $pengeluaranKemarin * 100; // minus or not if ($percentageOfSalesGrowth < 0) { @@ -229,95 +247,10 @@ class DashboardController extends Controller } return [ - 'penjualanHariIni' => $penjualanHariIni, - 'penjualanKemarin' => $penjualanKemarin, + 'pengeluaranHariIni' => $pengeluaranHariIni, + 'pengeluaranKemarin' => $pengeluaranKemarin, 'statusCalculation' => $statusCalculation, 'percentageOfSalesGrowth' => $percentageOfSalesGrowth ]; } - - public function getChart() - { - $allPenjualan = Pesanan::sum('grand_total'); - - $weekThisMonth = $this->getDataEachWeekThisMonth(); - $weekLastMonth = $this->getDataEachWeekLastMonth(); - - return ResponseFormatter::success(['allPenjualan' => $allPenjualan, 'weekThisMonth' => $weekThisMonth, 'weekLastMonth' => $weekLastMonth]); - } - - private function getDataEachWeekThisMonth() - { - //format string - $f = 'Y-m-d'; - - //if you want to record time as well, then replace today() with now() - //and remove startOfDay() - $today = Carbon::today(); - $date = $today->copy()->firstOfMonth()->startOfDay(); - $eom = $today->copy()->endOfMonth()->startOfDay(); - - $dates = []; - - for ($i = 1; $date->lte($eom); $i++) { - - //record start date - $startDate = $date->copy(); - - //loop to end of the week while not crossing the last date of month - while ($date->dayOfWeek != Carbon::SUNDAY && $date->lte($eom)) { - $date->addDay(); - } - - $dates['Minggu ke ' . $i] = $startDate->format($f) . ' 00:00:00 |' . $date->format($f) . ' 23:59:59'; - $date->addDay(); - } - - $datapenjualan = []; - - foreach ($dates as $key => $value) { - $dataPenjualan = Pesanan::whereBetween('tanggal_pesanan', explode('|', $value))->sum('grand_total'); - - - $datapenjualan[$key] = $dataPenjualan; - } - - return $datapenjualan; - } - - private function getDataEachWeekLastMonth() - { - //format string - $f = 'Y-m-d'; - - //if you want to record time as well, then replace today() with now() - //and remove startOfDay() - $today = Carbon::today()->subMonth(); - $date = $today->copy()->firstOfMonth()->startOfDay(); - $eom = $today->copy()->endOfMonth()->startOfDay(); - - $dates = []; - - for ($i = 1; $date->lte($eom); $i++) { - - //record start date - $startDate = $date->copy(); - - //loop to end of the week while not crossing the last date of month - while ($date->dayOfWeek != Carbon::SUNDAY && $date->lte($eom)) { - $date->addDay(); - } - - $dates['Minggu ke ' . $i] = $startDate->format($f) . ' 00:00:00 |' . $date->format($f) . ' 23:59:59'; - $date->addDay(); - } - - $datapenjualan = []; - foreach ($dates as $key => $value) { - $dataPenjualan = Pesanan::whereBetween('tanggal_pesanan', explode('|', $value))->sum('grand_total'); - $datapenjualan[$key] = $dataPenjualan; - } - - return $datapenjualan; - } } diff --git a/app/Http/Controllers/Admins/Dashboard/ChartPengeluaranController.php b/app/Http/Controllers/Admins/Dashboard/ChartPengeluaranController.php new file mode 100644 index 0000000..4c8df25 --- /dev/null +++ b/app/Http/Controllers/Admins/Dashboard/ChartPengeluaranController.php @@ -0,0 +1,96 @@ +getDataEachWeekThisMonthPengeluaran(); + $weekLastMonth = $this->getDataEachWeekLastMonthPengeluaran(); + + return ResponseFormatter::success(['allPengeluaran' => $allPengeluaran, 'weekThisMonth' => $weekThisMonth, 'weekLastMonth' => $weekLastMonth]); + } + + private function getDataEachWeekThisMonthPengeluaran() + { + //format string + $f = 'Y-m-d'; + + //if you want to record time as well, then replace today() with now() + //and remove startOfDay() + $today = Carbon::today(); + $date = $today->copy()->firstOfMonth()->startOfDay(); + $eom = $today->copy()->endOfMonth()->startOfDay(); + + $dates = []; + + for ($i = 1; $date->lte($eom); $i++) { + + //record start date + $startDate = $date->copy(); + + //loop to end of the week while not crossing the last date of month + while ($date->dayOfWeek != Carbon::SUNDAY && $date->lte($eom)) { + $date->addDay(); + } + + $dates['Minggu ke ' . $i] = $startDate->format($f) . ' 00:00:00 |' . $date->format($f) . ' 23:59:59'; + $date->addDay(); + } + + $datapengeluaran = []; + + foreach ($dates as $key => $value) { + $dataPengeluaran = Pengeluaran::whereBetween('tanggal', explode('|', $value))->sum('nominal'); + $datapengeluaran[$key] = $dataPengeluaran; + } + + return $datapengeluaran; + } + + private function getDataEachWeekLastMonthPengeluaran() + { + //format string + $f = 'Y-m-d'; + + //if you want to record time as well, then replace today() with now() + //and remove startOfDay() + $today = Carbon::today()->subMonth(); + $date = $today->copy()->firstOfMonth()->startOfDay(); + $eom = $today->copy()->endOfMonth()->startOfDay(); + + $dates = []; + + for ($i = 1; $date->lte($eom); $i++) { + + //record start date + $startDate = $date->copy(); + + //loop to end of the week while not crossing the last date of month + while ($date->dayOfWeek != Carbon::SUNDAY && $date->lte($eom)) { + $date->addDay(); + } + + $dates['Minggu ke ' . $i] = $startDate->format($f) . ' 00:00:00 |' . $date->format($f) . ' 23:59:59'; + $date->addDay(); + } + + $datapengeluaran = []; + foreach ($dates as $key => $value) { + $dataPengeluaran = Pengeluaran::whereBetween('tanggal', explode('|', $value))->sum('nominal'); + $datapengeluaran[$key] = $dataPengeluaran; + } + + return $datapengeluaran; + } +} diff --git a/app/Http/Controllers/Admins/Dashboard/ChartPenjualanController.php b/app/Http/Controllers/Admins/Dashboard/ChartPenjualanController.php new file mode 100644 index 0000000..0d65d7f --- /dev/null +++ b/app/Http/Controllers/Admins/Dashboard/ChartPenjualanController.php @@ -0,0 +1,268 @@ +startOfWeek()->format('Y-m-d') . ' 00:00:00', Carbon::today()->endOfWeek()->format('Y-m-d') . ' 23:59:59'])->sum('grand_total'); + + // get data grand_total last week from first day until last day of week from 00:00:00 until 23:59:59 + $grandTotalLastWeek = Pesanan::whereBetween('tanggal_pesanan', [Carbon::today()->subWeek()->startOfWeek()->format('Y-m-d') . ' 00:00:00', Carbon::today()->subWeek()->endOfWeek()->format('Y-m-d') . ' 23:59:59'])->sum('grand_total'); + + /** + * @Author: xelz + * @Date: 2024-01-30 15:52:41 + * @Desc: constant status + * 1 netral + * 2 plus + * 3 minus + */ + $statusCalculation = 1; + + // calculate percentage of sales growth in the last week and this week + if ($grandTotalLastWeek != 0) { + $statusCalculation = 2; + $percentageOfSalesGrowth = ($grandTotalThisWeek - $grandTotalLastWeek) / $grandTotalLastWeek * 100; + // minus or not + if ($percentageOfSalesGrowth < 0) { + $statusCalculation = 3; + $percentageOfSalesGrowth = $percentageOfSalesGrowth * -1; + } + } else { + $statusCalculation = 1; + $percentageOfSalesGrowth = 0; + } + + $thisWeek = $this->getDataEachDayThisWeek(); + // $lastWeek = $this->getDataEachDayLastWeek(); + + return ResponseFormatter::success(['thisWeek' => $thisWeek, 'grandTotalThisWeek' => $grandTotalThisWeek, 'grandTotalLastWeek' => $grandTotalLastWeek, 'percentageOfSalesGrowth' => $percentageOfSalesGrowth, 'statusCalculation' => $statusCalculation]); + } + + private function getDataEachDayThisWeek() + { + // get data grand_total per day this week from 00:00:00 until 23:59:59 + $datapenjualan = []; + + $today = Carbon::today(); + $date = $today->copy()->startOfWeek()->startOfDay(); + $eow = $today->copy()->endOfWeek()->startOfDay(); + + for ($i = 1; $date->lte($eow); $i++) { + $dataPenjualan = Pesanan::whereBetween('tanggal_pesanan', [$date->format('Y-m-d') . ' 00:00:00', $date->format('Y-m-d') . ' 23:59:59'])->sum('grand_total'); + $datapenjualan[tanggal_indonesia($date->format('Y-m-d'))] = $dataPenjualan; + $date->addDay(); + } + + return $datapenjualan; + } + + private function getDataEachDayLastWeek() + { + // get data grand_total per day last week from 00:00:00 until 23:59:59 + $datapenjualan = []; + + $today = Carbon::today()->subWeek(); + $date = $today->copy()->startOfWeek()->startOfDay(); + $eow = $today->copy()->endOfWeek()->startOfDay(); + + for ($i = 1; $date->lte($eow); $i++) { + $dataPenjualan = Pesanan::whereBetween('tanggal_pesanan', [$date->format('Y-m-d') . ' 00:00:00', $date->format('Y-m-d') . ' 23:59:59'])->sum('grand_total'); + $datapenjualan[tanggal_indonesia($date->format('Y-m-d'))] = $dataPenjualan; + $date->addDay(); + } + + return $datapenjualan; + } + + public function getChartMonth() + { + // get data grand_total this month from first day until last day of month from 00:00:00 until 23:59:59 + $grandTotalThisMonth = Pesanan::whereBetween('tanggal_pesanan', [Carbon::today()->startOfMonth()->format('Y-m-d') . ' 00:00:00', Carbon::today()->endOfMonth()->format('Y-m-d') . ' 23:59:59'])->sum('grand_total'); + + // get data grand_total last month from first day until last day of month from 00:00:00 until 23:59:59 + $grandTotalLastMonth = Pesanan::whereBetween('tanggal_pesanan', [Carbon::today()->subMonth()->startOfMonth()->format('Y-m-d') . ' 00:00:00', Carbon::today()->subMonth()->endOfMonth()->format('Y-m-d') . ' 23:59:59'])->sum('grand_total'); + + + /** + * @Author: xelz + * @Date: 2024-01-30 15:52:41 + * @Desc: constant status + * 1 netral + * 2 plus + * 3 minus + */ + $statusCalculation = 1; + + // calculate percentage of sales growth in the last week and this week + if ($grandTotalLastMonth != 0) { + $statusCalculation = 2; + $percentageOfSalesGrowth = ($grandTotalThisMonth - $grandTotalLastMonth) / $grandTotalLastMonth * 100; + // minus or not + if ($percentageOfSalesGrowth < 0) { + $statusCalculation = 3; + $percentageOfSalesGrowth = $percentageOfSalesGrowth * -1; + } + } else { + $statusCalculation = 1; + $percentageOfSalesGrowth = 0; + } + + $weekThisMonth = $this->getDataEachWeekThisMonth(); + // $weekLastMonth = $this->getDataEachWeekLastMonth(); + + return ResponseFormatter::success(['weekThisMonth' => $weekThisMonth, 'grandTotalThisMonth' => $grandTotalThisMonth, 'grandTotalLastMonth' => $grandTotalLastMonth, 'percentageOfSalesGrowth' => $percentageOfSalesGrowth, 'statusCalculation' => $statusCalculation]); + } + + private function getDataEachWeekThisMonth() + { + // get data grand_total per week this month from 00:00:00 until 23:59:59 each day of week (Sunday) + $datapenjualan = []; + $today = Carbon::today(); + $date = $today->copy()->startOfMonth()->startOfDay(); + $eom = $today->copy()->endOfMonth()->startOfDay(); + + for ($i = 1; $date->lte($eom); $i++) { + + //record start date + $startDate = $date->copy(); + + //loop to end of the week while not crossing the last date of month + while ($date->dayOfWeek != Carbon::SUNDAY && $date->lte($eom)) { + $date->addDay(); + } + + $dataPenjualan = Pesanan::whereBetween('tanggal_pesanan', [$startDate->format('Y-m-d') . ' 00:00:00', $date->format('Y-m-d') . ' 23:59:59'])->sum('grand_total'); + $datapenjualan['Minggu ke ' . $i] = $dataPenjualan; + $date->addDay(); + } + + return $datapenjualan; + } + + private function getDataEachWeekLastMonth() + { + // get data grand_total per week this month from 00:00:00 until 23:59:59 each day of week (Sunday) last month + $datapenjualan = []; + $today = Carbon::today()->subMonth(); + $date = $today->copy()->startOfMonth()->startOfDay(); + $eom = $today->copy()->endOfMonth()->startOfDay(); + + for ($i = 1; $date->lte($eom); $i++) { + + //record start date + $startDate = $date->copy(); + + //loop to end of the week while not crossing the last date of month + while ($date->dayOfWeek != Carbon::SUNDAY && $date->lte($eom)) { + $date->addDay(); + } + + $dataPenjualan = Pesanan::whereBetween('tanggal_pesanan', [$startDate->format('Y-m-d') . ' 00:00:00', $date->format('Y-m-d') . ' 23:59:59'])->sum('grand_total'); + $datapenjualan['Minggu ke ' . $i] = $dataPenjualan; + $date->addDay(); + } + + return $datapenjualan; + } + + public function getChartYear() + { + // get data grand_total this year from first day until last day of year from 00:00:00 until 23:59:59 + $grandTotalThisYear = Pesanan::whereBetween('tanggal_pesanan', [Carbon::today()->startOfYear()->format('Y-m-d') . ' 00:00:00', Carbon::today()->endOfYear()->format('Y-m-d') . ' 23:59:59'])->sum('grand_total'); + + // get data grand_total last year from first day until last day of year from 00:00:00 until 23:59:59 + $grandTotalLastYear = Pesanan::whereBetween('tanggal_pesanan', [Carbon::today()->subYear()->startOfYear()->format('Y-m-d') . ' 00:00:00', Carbon::today()->subYear()->endOfYear()->format('Y-m-d') . ' 23:59:59'])->sum('grand_total'); + + /** + * @Author: xelz + * @Date: 2024-01-30 15:52:41 + * @Desc: constant status + * 1 netral + * 2 plus + * 3 minus + */ + $statusCalculation = 1; + + // calculate percentage of sales growth in the last week and this week + if ($grandTotalLastYear != 0) { + $statusCalculation = 2; + $percentageOfSalesGrowth = ($grandTotalThisYear - $grandTotalLastYear) / $grandTotalLastYear * 100; + // minus or not + if ($percentageOfSalesGrowth < 0) { + $statusCalculation = 3; + $percentageOfSalesGrowth = $percentageOfSalesGrowth * -1; + } + } else { + $statusCalculation = 1; + $percentageOfSalesGrowth = 0; + } + + $monthThisYear = $this->getDataEachMonthThisYear(); + // $monthLastYear = $this->getDataEachMonthLastYear(); + + return ResponseFormatter::success(['monthThisYear' => $monthThisYear, 'grandTotalThisYear' => $grandTotalThisYear, 'grandTotalLastYear' => $grandTotalLastYear, 'percentageOfSalesGrowth' => $percentageOfSalesGrowth, 'statusCalculation' => $statusCalculation]); + } + + private function getDataEachMonthThisYear() + { + // get data grand_total per month this year from 00:00:00 until 23:59:59 each day of month (last day of month) + $datapenjualan = []; + $today = Carbon::today(); + $date = $today->copy()->startOfYear()->startOfDay(); + $eoy = $today->copy()->endOfYear()->startOfDay(); + + for ($i = 1; $date->lte($eoy); $i++) { + + //record start date + $startDate = $date->copy(); + + //loop to end of the week while not crossing the last date of month + while ($date->day != $date->daysInMonth && $date->lte($eoy)) { + $date->addDay(); + } + + $dataPenjualan = Pesanan::whereBetween('tanggal_pesanan', [$startDate->format('Y-m-d') . ' 00:00:00', $date->format('Y-m-d') . ' 23:59:59'])->sum('grand_total'); + $datapenjualan[$date->format('F')] = $dataPenjualan; + $date->addDay(); + } + + return $datapenjualan; + } + + private function getDataEachMonthLastYear() + { + // get data grand_total per month this year from 00:00:00 until 23:59:59 each day of month (last day of month) last year + $datapenjualan = []; + $today = Carbon::today()->subYear(); + $date = $today->copy()->startOfYear()->startOfDay(); + $eoy = $today->copy()->endOfYear()->startOfDay(); + + for ($i = 1; $date->lte($eoy); $i++) { + + //record start date + $startDate = $date->copy(); + + //loop to end of the week while not crossing the last date of month + while ($date->day != $date->daysInMonth && $date->lte($eoy)) { + $date->addDay(); + } + + $dataPenjualan = Pesanan::whereBetween('tanggal_pesanan', [$startDate->format('Y-m-d') . ' 00:00:00', $date->format('Y-m-d') . ' 23:59:59'])->sum('grand_total'); + $datapenjualan['Bulan ke ' . $i] = $dataPenjualan; + $date->addDay(); + } + + return $datapenjualan; + } +} diff --git a/app/Http/Controllers/Admins/Dashboard/DashboardController.php b/app/Http/Controllers/Admins/Dashboard/DashboardController.php new file mode 100644 index 0000000..4bf3a43 --- /dev/null +++ b/app/Http/Controllers/Admins/Dashboard/DashboardController.php @@ -0,0 +1,57 @@ +get(); + + // $KelompokKategori = KelompokKategori::with('kelompokKategoriPivot.produkTerlaris')->get(); + // dd($KelompokKategori->kelompokKategoriPivot->first()->produkTerlaris); + + return DataTables::of($data) + ->addIndexColumn() + ->make(true); + } + + public function minumanTerlaris() + { + $data = MenuTerlarisView::where([['kategori_produk_id', '=', 1], ['tgl_start_promo', '=', null]])->get(); + + // $KelompokKategori = KelompokKategori::with('kelompokKategoriPivot.produkTerlaris')->get(); + // dd($KelompokKategori->kelompokKategoriPivot->first()->produkTerlaris); + + return DataTables::of($data) + ->addIndexColumn() + ->make(true); + } +} diff --git a/app/Models/KategoriProduk.php b/app/Models/KategoriProduk.php index 6f7756d..bbca472 100644 --- a/app/Models/KategoriProduk.php +++ b/app/Models/KategoriProduk.php @@ -23,6 +23,12 @@ class KategoriProduk extends Model return $this->hasMany(Produk::class, 'kategori_produk_id'); } + + public function produkTerlaris() + { + return $this->belongsTo(MenuTerlarisView::class, 'produk_id'); + } + // kelompok kategori public function kelompokKategori() { diff --git a/app/Models/KelompokKategoriPivot.php b/app/Models/KelompokKategoriPivot.php index 2a33d8b..8240a14 100644 --- a/app/Models/KelompokKategoriPivot.php +++ b/app/Models/KelompokKategoriPivot.php @@ -27,4 +27,9 @@ class KelompokKategoriPivot extends Model { return $this->belongsTo(Produk::class, 'produk_id'); } + + public function produkTerlaris() + { + return $this->belongsTo(MenuTerlarisView::class, 'produk_id'); + } } diff --git a/app/Models/MenuTerlarisView.php b/app/Models/MenuTerlarisView.php index 9cb238e..4a1b0f8 100644 --- a/app/Models/MenuTerlarisView.php +++ b/app/Models/MenuTerlarisView.php @@ -10,4 +10,25 @@ class MenuTerlarisView extends Model use HasFactory; protected $table = 'menu_terlaris_view'; + + // full path to reach image from storage folder and check if image exists or not + public function getGambarProdukAttribute($value) + { + $storage = storage_path('app/public/produk/' . $this->kategori_produk_id . '/' . $value); + if (file_exists($storage)) { + return asset('storage/produk/' . $this->kategori_produk_id . '/' . $value); + } else { + return asset('assets/images/menu_image.jpeg'); + } + } + + public function kategori_produk() + { + return $this->belongsTo(KategoriProduk::class, 'kategori_produk_id'); + } + + public function kelompokKategori() + { + return $this->belongsToMany(KelompokKategori::class, KelompokKategoriPivot::class, 'produk_id', 'kelompok_kategori_id'); + } } diff --git a/resources/views/components/navbar.blade.php b/resources/views/components/navbar.blade.php index 992e280..7497c3c 100644 --- a/resources/views/components/navbar.blade.php +++ b/resources/views/components/navbar.blade.php @@ -6,6 +6,11 @@ Keriting + +
- @endsection @include('pages.admin.pengeluaran.js') +@include('pages.admin.pengeluaran.style') diff --git a/resources/views/pages/admin/pengeluaran/js.blade.php b/resources/views/pages/admin/pengeluaran/js.blade.php index 2c54cce..5b28f5c 100644 --- a/resources/views/pages/admin/pengeluaran/js.blade.php +++ b/resources/views/pages/admin/pengeluaran/js.blade.php @@ -11,7 +11,6 @@ ], processing: true, serverSide: true, - ajax: { url: '{{ route('pengeluaran.getDataPengeluaran') }}', data: function(d) { diff --git a/resources/views/pages/admin/pengeluaran/style.blade.php b/resources/views/pages/admin/pengeluaran/style.blade.php new file mode 100644 index 0000000..63bfc92 --- /dev/null +++ b/resources/views/pages/admin/pengeluaran/style.blade.php @@ -0,0 +1,18 @@ +@push('styles') + + + + +@endpush \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 841d2fd..416b699 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,9 @@ ['auth', 'permission']], function () { Route::group(['prefix' => 'dashboard'], function () { Route::get('/', [DashboardController::class, 'index'])->name('dashboard.index')->comment('Halaman Dashboard'); Route::get('/menuTerlaris', [DashboardController::class, 'menuTerlaris'])->name('dashboard.menuTerlaris')->comment("Ambil data Menu Terlaris"); - Route::get('/getCalculationPendapatan', [DashboardController::class, 'getCalculationPendapatan'])->name('dashboard.getCalculationPendapatan')->comment("Ambil data Total Penjualan"); - Route::get('/getChart', [DashboardController::class, 'getChart'])->name('dashboard.getChart')->comment("Ambil data Total Penjualan"); + Route::get('/minumanTerlaris', [DashboardController::class, 'minumanTerlaris'])->name('dashboard.minumanTerlaris')->comment("Ambil data Minuman Terlaris"); + Route::get('/getCalculationPendapatan', [CalculationController::class, 'getCalculationPendapatan'])->name('dashboard.getCalculationPendapatan')->comment("Ambil data Total Penjualan"); + Route::get('/getChartWeek', [ChartPenjualanController::class, 'getChartWeek'])->name('dashboard.getChartWeek')->comment("Ambil data Total Penjualan per Minggu"); + Route::get('/getChartMonth', [ChartPenjualanController::class, 'getChartMonth'])->name('dashboard.getChartMonth')->comment("Ambil data Total Penjualan per Bulan"); + Route::get('/getChartYear', [ChartPenjualanController::class, 'getChartYear'])->name('dashboard.getChartYear')->comment("Ambil data Total Penjualan per Tahun"); + Route::get('/getChartPengeluaran', [ChartPengeluaranController::class, 'getChartPengeluaran'])->name('dashboard.getChartPengeluaran')->comment("Ambil data Total Pengeluaran"); });