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/Http/Controllers/Admins/RekeningCoa/RekeningCoaController.php b/app/Http/Controllers/Admins/RekeningCoa/RekeningCoaController.php new file mode 100644 index 0000000..f08decf --- /dev/null +++ b/app/Http/Controllers/Admins/RekeningCoa/RekeningCoaController.php @@ -0,0 +1,76 @@ +get(); + $nomor = 1; + + return datatables() + ->of($rekeningCoa) + ->addColumn('nomor', function($rekeningCoa) use (&$nomor){ + return $nomor++; + }) + ->rawColumns(['nomor']) + ->addColumn('ubah', function($rekeningCoa) { + if($rekeningCoa->status <> 0){ + return ' + + '; + } + }) + ->rawColumns(['ubah']) + ->make(true); + } + + public function simpan(Request $request){ + try { + if($request->detail_coa <> null){ + $status = 1; + $coa = $request->kode_coa.".".$request->sub_kode_coa.".".$request->detail_coa; + }else{ + $status = 0; + $coa = $request->kode_coa.".".$request->sub_kode_coa; + } + RekeningCoa::create([ + 'kode_coa' => $request->kode_coa, + 'sub_kode_coa' => $request->sub_kode_coa, + 'detail_coa' => $request->detail_coa, + 'coa' => $coa, + 'keterangan_coa' => $request->keterangan_coa, + 'status' => $status + ]); + + return redirect()->route('coa.index')->with(['success' => 'Data berhasil ditambahkan']); + + } catch (\Throwable $th) { + return back()->withError($th->getMessage())->withInput(); + } + } + + public function ubah(Request $request){ + try { + $rekeningCoa = RekeningCoa::where('id', $request->id_rekening_coa); + $rekeningCoa->update([ + 'detail_coa' => $request->detail_coa, + 'keterangan_coa' => $request->keterangan_coa, + ]); + + return redirect()->route('coa.index')->with(['success' => 'Data berhasil diubah']); + + } catch (\Throwable $th) { + return back()->withError($th->getMessage())->withInput(); + } + } +} \ No newline at end of file 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/app/Models/Pengeluaran.php b/app/Models/Pengeluaran.php index 8d31211..5a70c8d 100644 --- a/app/Models/Pengeluaran.php +++ b/app/Models/Pengeluaran.php @@ -15,4 +15,8 @@ class Pengeluaran extends Model public function user(){ return $this->belongsTo(User::class, 'user_id'); } + + public function jenis_kelamin(){ + return $this->belongsTo(User::class, 'user_id'); + } } diff --git a/database/seeders/RekeningCoaSeeder.php b/database/seeders/RekeningCoaSeeder.php index 70999e9..9b9c196 100644 --- a/database/seeders/RekeningCoaSeeder.php +++ b/database/seeders/RekeningCoaSeeder.php @@ -5,6 +5,7 @@ namespace Database\Seeders; use App\Models\RekeningCoa; use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; +use Illuminate\Support\Facades\DB; class RekeningCoaSeeder extends Seeder { @@ -13,7 +14,13 @@ class RekeningCoaSeeder extends Seeder */ public function run(): void { - // RekeningCoa::truncate(); + // Disable foreign key checks + DB::statement('SET FOREIGN_KEY_CHECKS=0;'); + + RekeningCoa::truncate(); + + // Enable foreign key checks + DB::statement('SET FOREIGN_KEY_CHECKS=1;'); $csvFile = fopen(base_path("database/seeders/data_csv/rekening_coa.csv"), "r"); $firstline = true; diff --git a/database/seeders/data_csv/rekening_coa.csv b/database/seeders/data_csv/rekening_coa.csv index 1eac876..1dc38f6 100644 --- a/database/seeders/data_csv/rekening_coa.csv +++ b/database/seeders/data_csv/rekening_coa.csv @@ -1,56 +1,56 @@ kode_coa,sub_kode_coa,detail_coa,coa,keterangan_coa,status 1,100,,1.100,Kas,0 -1,100,1,1.100.01,Kas Kasir,1 -1,100,1,1.100.02,Kas BCA1,1 -1,100,1,1.100.03,Kas BCA2,1 -1,100,1,1.100.04,Kas Mandiri1,1 -1,100,1,1.100.05,Kas Mandiri2,1 -1,100,1,1.100.06,Kas BRI1,1 -1,100,1,1.100.07,Kas BRI2,1 -1,100,1,1.100.08,Kas BNI1,1 -1,100,1,1.100.09,Kas BNI2,1 -1,100,1,1.100.10,Kas BSI1,1 -1,100,1,1.100.11,Kas BSI2,1 +1,100,01,1.100.01,Kas Kasir,1 +1,100,02,1.100.02,Kas BCA1,1 +1,100,03,1.100.03,Kas BCA2,1 +1,100,04,1.100.04,Kas Mandiri1,1 +1,100,05,1.100.05,Kas Mandiri2,1 +1,100,06,1.100.06,Kas BRI1,1 +1,100,07,1.100.07,Kas BRI2,1 +1,100,08,1.100.08,Kas BNI1,1 +1,100,09,1.100.09,Kas BNI2,1 +1,100,10,1.100.10,Kas BSI1,1 +1,100,11,1.100.11,Kas BSI2,1 1,200,,1.200,Antar Bank Aktiva,0 -1,200,1,1.200.01,Tab ABA Bank Mandiri1,1 -1,200,2,1.200.02,Tab ABA Bank Mandiri2,1 -1,200,3,1.200.03,Tab ABA Bank BNI1,1 -1,200,4,1.200.04,Tab ABA Bank BNI2,1 -1,200,5,1.200.05,Tab ABA Bank BCA1,1 -1,200,5,1.200.06,Tab ABA Bank BCA2,1 -1,200,5,1.200.07,Tab ABA Bank BRI1,1 -1,200,5,1.200.08,Tab ABA Bank BRI2,1 -1,200,5,1.200.09,Tab ABA Bank BSI1,1 -1,200,5,1.200.10,Tab ABA Bank BSI2,1 +1,200,01,1.200.01,Tab ABA Bank Mandiri1,1 +1,200,02,1.200.02,Tab ABA Bank Mandiri2,1 +1,200,03,1.200.03,Tab ABA Bank BNI1,1 +1,200,04,1.200.04,Tab ABA Bank BNI2,1 +1,200,05,1.200.05,Tab ABA Bank BCA1,1 +1,200,06,1.200.06,Tab ABA Bank BCA2,1 +1,200,07,1.200.07,Tab ABA Bank BRI1,1 +1,200,08,1.200.08,Tab ABA Bank BRI2,1 +1,200,09,1.200.09,Tab ABA Bank BSI1,1 +1,200,10,1.200.10,Tab ABA Bank BSI2,1 1,300,,1.300,Piutang,0 -1,300,1,1.300.01,Piutang Konsumen,1 +1,300,01,1.300.01,Piutang Konsumen,1 2,100,,2.100,Hutang,0 -2,100,1,2.100.01,Hutang Usaha,1 -2,100,2,2.100.02,Hutang Bank,1 +2,100,01,2.100.01,Hutang Usaha,1 +2,100,02,2.100.02,Hutang Bank,1 2,200,,2.200,Pajak,0 -2,200,1,2.200.01,Pajak PPh21,1 -2,200,2,2.200.02,Pajak PPh22,1 +2,200,01,2.200.01,Pajak PPh21,1 +2,200,02,2.200.02,Pajak PPh22,1 3,100,,3.100,Modal,0 -3,100,1,3.100.01,Modal Awal,1 +3,100,01,3.100.01,Modal Awal,1 4,100,,4.100,Pendapatan,0 -4,100,1,4.100.01,Pendapatan Penjualan,1 +4,100,01,4.100.01,Pendapatan Penjualan,1 5,100,,5.100,Beban Umum & Administrasi,0 -5,100,1,5.100.01,Gaji & Upah,1 -5,100,2,5.100.02,Lembur,1 -5,100,3,5.100.03,Alat Tulis & Kantor,1 -5,100,4,5.100.04,Perjalanan Dinas / Transport,1 -5,100,5,5.100.05,Perawatan Kendaraan,1 +5,100,01,5.100.01,Gaji & Upah,1 +5,100,02,5.100.02,Lembur,1 +5,100,03,5.100.03,Alat Tulis & Kantor,1 +5,100,04,5.100.04,Perjalanan Dinas / Transport,1 +5,100,05,5.100.05,Perawatan Kendaraan,1 5,200,,5.200,Beban Organisasi,0 -5,200,1,5.200.01,Biaya Rapat,1 -5,200,2,5.200.02,Biaya Lainnya,1 +5,200,01,5.200.01,Biaya Rapat,1 +5,200,02,5.200.02,Biaya Lainnya,1 5,300,,5.300,Beban Operasional Lainnya,0 -5,300,1,5.300.01,Sewa Kantor,1 -5,300,2,5.300.02,Biaya Telepon / Pulsa,1 -5,300,3,5.300.03,Biaya Listrik,1 -5,300,4,5.300.04,Biaya Air,1 -5,300,5,5.300.05,Biaya Wifi,1 -5,300,6,5.300.06,Biaya BBM,1 -5,300,7,5.300.07,Biaya Penyisihan THR,1 +5,300,01,5.300.01,Sewa Kantor,1 +5,300,02,5.300.02,Biaya Telepon / Pulsa,1 +5,300,03,5.300.03,Biaya Listrik,1 +5,300,04,5.300.04,Biaya Air,1 +5,300,05,5.300.05,Biaya Wifi,1 +5,300,06,5.300.06,Biaya BBM,1 +5,300,07,5.300.07,Biaya Penyisihan THR,1 5,400,,5.400,Pembelian,0 -5,400,1,5.400.01,Pembelian Barang,1 -5,400,2,5.400.02,Pembelian Sarpras,1 +5,400,01,5.400.01,Pembelian Barang,1 +5,400,02,5.400.02,Pembelian Sarpras,1 diff --git a/resources/views/components/navbar.blade.php b/resources/views/components/navbar.blade.php index 992e280..f1376e3 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/resources/views/pages/admin/rekening_coa/index.blade.php b/resources/views/pages/admin/rekening_coa/index.blade.php new file mode 100644 index 0000000..b794432 --- /dev/null +++ b/resources/views/pages/admin/rekening_coa/index.blade.php @@ -0,0 +1,104 @@ +@extends('layouts.base') + +@section('content-header') +
+
+
+
+

Rekening Coa

+
+
+ +
+
+
+
+@endsection + +@section('content') +
+
+
+
+
+
+
+
+
+ @csrf +
+
+
Form Input Data
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+
+
+
+
+
+ + + + + + + + + + + + +
NoKode COASub Kode COADetail COACOAKeterangan COA
+
+
+
+
+
+
+
+@include('pages.admin.rekening_coa.modal') +@endsection + +@include('pages.admin.rekening_coa.style') +@include('pages.admin.rekening_coa.js') diff --git a/resources/views/pages/admin/rekening_coa/js.blade.php b/resources/views/pages/admin/rekening_coa/js.blade.php new file mode 100644 index 0000000..891b6f6 --- /dev/null +++ b/resources/views/pages/admin/rekening_coa/js.blade.php @@ -0,0 +1,51 @@ +@push('scripts') + + + + + +@endpush \ No newline at end of file diff --git a/resources/views/pages/admin/rekening_coa/modal.blade.php b/resources/views/pages/admin/rekening_coa/modal.blade.php new file mode 100644 index 0000000..b4604d7 --- /dev/null +++ b/resources/views/pages/admin/rekening_coa/modal.blade.php @@ -0,0 +1,39 @@ + \ No newline at end of file diff --git a/resources/views/pages/admin/rekening_coa/style.blade.php b/resources/views/pages/admin/rekening_coa/style.blade.php new file mode 100644 index 0000000..63bfc92 --- /dev/null +++ b/resources/views/pages/admin/rekening_coa/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 a8ecb5f..1b1ad10 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,7 +1,11 @@ ['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"); }); @@ -104,4 +112,12 @@ Route::group(['middleware' => ['auth', 'permission']], function () { Route::post('/laporan', [PengeluaranController::class, 'laporan'])->name('pengeluaran.laporan')->comment('Halaman Laporan'); Route::get('/getDatapengeluaran', [PengeluaranController::class, 'getDatapengeluaran'])->name('pengeluaran.getDataPengeluaran')->comment("Ambil data Riwayat Transaksi"); }); + + // Rekening Coa + Route::group(['prefix' => 'coa'], function () { + Route::get('/', [RekeningCoaController::class, 'index'])->name('coa.index')->comment('Halaman Rekening Coa'); + Route::get('/getData', [RekeningCoaController::class, 'getData'])->name('coa.getData')->comment('Halaman Get Data Coa'); + Route::post('/simpan', [RekeningCoaController::class, 'simpan'])->name('coa.simpan')->comment('Halaman Simpan Rekening Coa'); + Route::post('/ubah/{id}', [RekeningCoaController::class, 'ubah'])->name('coa.ubah')->comment('Halaman Ubah Rekening Coa'); + }); });