From 13322382cabe483339cd6d52dfb58b3f9bd8cf42 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 12 Nov 2017 20:48:59 +0800 Subject: [PATCH] Update monthly report page --- app/Entities/Reports/ReportsRepository.php | 15 +++- app/helpers.php | 18 ++++- resources/views/layouts/partials/sidebar.blade.php | 2 +- resources/views/reports/payments/monthly.blade.php | 85 ++++++++++++---------- 4 files changed, 78 insertions(+), 42 deletions(-) diff --git a/app/Entities/Reports/ReportsRepository.php b/app/Entities/Reports/ReportsRepository.php index e07d769..8ab63a0 100755 --- a/app/Entities/Reports/ReportsRepository.php +++ b/app/Entities/Reports/ReportsRepository.php @@ -31,12 +31,25 @@ class ReportsRepository extends BaseRepository public function getMonthlyReports($year, $month) { - return Payment::select(DB::raw("date, count(`id`) as count, sum(if(in_out = 1, amount, 0)) AS cashin, sum(if(in_out = 0, amount, 0)) AS cashout, in_out")) + $rawQuery = "date, count(`id`) as count"; + $rawQuery .= ", sum(if(in_out = 1, amount, 0)) AS cashin"; + $rawQuery .= ", sum(if(in_out = 0, amount, 0)) AS cashout"; + + $reportsData = DB::table('payments')->select(DB::raw($rawQuery)) ->where(DB::raw('YEAR(date)'), $year) ->where(DB::raw('MONTH(date)'), $month) ->groupBy('date') ->orderBy('date', 'asc') ->get(); + + $reports = []; + foreach ($reportsData as $report) { + $key = substr($report->date, -2); + $reports[$key] = $report; + $reports[$key]->profit = $report->cashin - $report->cashout; + } + + return collect($reports); } public function getYearlyReports($year) diff --git a/app/helpers.php b/app/helpers.php index 113569d..51a3f2b 100755 --- a/app/helpers.php +++ b/app/helpers.php @@ -237,6 +237,22 @@ function paymentTypes($paymentTypeId = null) function appLogoImage() { $logoString = ''; + $logoString .= 'src="'.appLogoPath().'">'; return $logoString; } + +function appLogoPath() +{ + return asset('assets/imgs/'.Option::get('agency_logo_path', 'default-logo.png')); +} + +function monthDateArray($year, $month) +{ + $dateCount = Carbon::parse($year.'-'.$month)->format('t'); + $dates = []; + foreach (range(1, $dateCount) as $dateNumber) { + $dates[] = str_pad($dateNumber, 2, '0', STR_PAD_LEFT); + } + + return $dates; +} diff --git a/resources/views/layouts/partials/sidebar.blade.php b/resources/views/layouts/partials/sidebar.blade.php index ec573bd..c602d26 100755 --- a/resources/views/layouts/partials/sidebar.blade.php +++ b/resources/views/layouts/partials/sidebar.blade.php @@ -10,7 +10,7 @@