diff --git a/app/Entities/Reports/ReportsRepository.php b/app/Entities/Reports/ReportsRepository.php new file mode 100755 index 0000000..1cd2101 --- /dev/null +++ b/app/Entities/Reports/ReportsRepository.php @@ -0,0 +1,49 @@ +where('date', $date) + ->with('customer','project') + ->get(); + } + + public function getMonthlyReports($year, $month) + { + return Payment::select(DB::raw("date, count(`id`) as count, sum(if(type = 1, amount, 0)) AS cashin, sum(if(type = 0, amount, 0)) AS cashout, type")) + ->where(DB::raw('YEAR(date)'), $year) + ->where(DB::raw('MONTH(date)'), $month) + ->groupBy('date') + ->orderBy('date','asc') + ->get(); + } + + public function getYearlyReports($year) + { + return Payment::select(DB::raw("MONTH(date) as month, count(`id`) as count, sum(if(type = 1, amount, 0)) AS cashin, sum(if(type = 0, amount, 0)) AS cashout, type")) + ->where(DB::raw('YEAR(date)'), $year) + ->groupBy(DB::raw('YEAR(date)')) + ->groupBy(DB::raw('MONTH(date)')) + ->orderBy('date','asc') + ->get(); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php new file mode 100755 index 0000000..ac54c88 --- /dev/null +++ b/app/Http/Controllers/ReportsController.php @@ -0,0 +1,58 @@ +repo = $repo; + } + + public function index(Request $req) + { + $reports = $this->repo->getAll($req->get('q')); + return view('reports.payments.index',compact('reports')); + } + + public function daily(Request $req) + { + $q = $req->get('q'); + $date = $req->get('date',date('Y-m-d')); + + $payments = $this->repo->getDailyReports($date, $q); + return view('reports.payments.daily', compact('payments','date')); + } + + public function monthly(Request $req) + { + $year = date('Y'); + $month = date('m'); + if ($req->has('year') && $req->has('month')) + { + $year = $req->get('year'); + $month = $req->get('month'); + } + $reports = $this->repo->getMonthlyReports($year, $month); + $months = \getMonths(); + $years = \getYears(); + return view('reports.payments.monthly', compact('reports','months','years','month','year')); + } + + public function yearly(Request $req) + { + $year = $req->get('year',date('Y')); + + $reports = $this->repo->getYearlyReports($year); + $years = \getYears(); + return view('reports.payments.yearly', compact('reports','years','year')); + } + +} diff --git a/app/Http/routes.php b/app/Http/routes.php index 92a925b..8a7094c 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -8,4 +8,5 @@ require __DIR__ . '/routes/account.php'; require __DIR__ . '/routes/backup.php'; require __DIR__ . '/routes/projects.php'; require __DIR__ . '/routes/payments.php'; -require __DIR__ . '/routes/subscriptions.php'; \ No newline at end of file +require __DIR__ . '/routes/subscriptions.php'; +require __DIR__ . '/routes/reports.php'; \ No newline at end of file diff --git a/app/Http/routes/reports.php b/app/Http/routes/reports.php new file mode 100644 index 0000000..ce61678 --- /dev/null +++ b/app/Http/routes/reports.php @@ -0,0 +1,11 @@ + ['web','role:admin'],'prefix' => 'reports'], function() { + /** + * Reports Routes + */ + Route::get('payments', ['as'=>'reports.payments.index', 'uses' => 'ReportsController@monthly']); + Route::get('payments/daily', ['as'=>'reports.payments.daily', 'uses' => 'ReportsController@daily']); + Route::get('payments/monthly', ['as'=>'reports.payments.monthly', 'uses' => 'ReportsController@monthly']); + Route::get('payments/yearly', ['as'=>'reports.payments.yearly', 'uses' => 'ReportsController@yearly']); +}); diff --git a/app/helpers.php b/app/helpers.php index ee84d2b..0a489da 100755 --- a/app/helpers.php +++ b/app/helpers.php @@ -121,7 +121,7 @@ function getMonths() function getYears() { - $yearRange = range(2015, date('Y')); + $yearRange = range(2014, date('Y')); foreach ($yearRange as $year) { $years[$year] = $year; } diff --git a/resources/views/layouts/partials/sidebar.blade.php b/resources/views/layouts/partials/sidebar.blade.php index fbc991d..a6c9735 100755 --- a/resources/views/layouts/partials/sidebar.blade.php +++ b/resources/views/layouts/partials/sidebar.blade.php @@ -21,6 +21,21 @@ @endcan + @can('see_reports') +
  • + {!! html_link_to_route('reports.payments.index', 'Laporan ', [], ['icon' => 'line-chart']) !!} + +
  • + @endcan @can('manage_subscriptions')
  • {!! html_link_to_route('subscriptions.index', trans('subscription.subscription'), [], ['icon' => 'retweet']) !!}
  • @endcan diff --git a/resources/views/reports/payments/daily.blade.php b/resources/views/reports/payments/daily.blade.php new file mode 100755 index 0000000..ec11a2b --- /dev/null +++ b/resources/views/reports/payments/daily.blade.php @@ -0,0 +1,80 @@ +@extends('layouts.app') + +@section('title', 'Laporan Harian : ' . dateId($date)) + +@section('content') + + + + +

    Laporan Harian : {{ dateId($date) }}

    + +{!! Form::open(['method'=>'get','class'=>'form-inline well well-sm']) !!} +{!! Form::text('date', $date, ['class'=>'form-control','required','id'=>'date']) !!} +{!! Form::submit('Lihat Laporan', ['class'=>'btn btn-primary']) !!} +{!! link_to_route('reports.payments.daily', 'Hari Ini', [], ['class'=>'btn btn-default']) !!} +{!! link_to_route('reports.payments.monthly', 'Lihat Bulanan', ['month' => monthNumber($dt->month), 'year' => $dt->year], ['class'=>'btn btn-default']) !!} +{!! Form::close() !!} + + + + + + + + + + + + + + @forelse($payments as $key => $payment) + + + + + + + + + + type == 0 ? $total - $payment->amount : $total + $payment->amount ?> + @empty + + @endforelse + + + + + + + + +
    {{ trans('app.table_no') }}{{ trans('payment.project') }}{{ trans('app.date') }}{{ trans('payment.amount') }}{{ trans('payment.customer') }}{{ trans('payment.description') }}{{ trans('app.action') }}
    {{ 1 + $key }}{{ $payment->project->name }}{{ $payment->date }}{{ $payment->present()->amount }}{{ $payment->customer->name }}{{ $payment->description }} + {!! link_to_route('payments.show','Lihat',[$payment->id],['title' => 'Lihat Detail Pembayaran','target' => '_blank','class'=>'btn btn-info btn-xs']) !!} +
    {{ trans('payment.not_found') }}
    Jumlah{{ formatRp($total) }}
    +@endsection + + +@section('ext_css') + {!! Html::style(url('assets/css/plugins/jquery.datetimepicker.css')) !!} +@endsection + +@section('ext_js') + {!! Html::script(url('assets/js/plugins/jquery.datetimepicker.js')) !!} +@endsection + +@section('script') + +@endsection \ No newline at end of file diff --git a/resources/views/reports/payments/monthly.blade.php b/resources/views/reports/payments/monthly.blade.php new file mode 100755 index 0000000..fa9343d --- /dev/null +++ b/resources/views/reports/payments/monthly.blade.php @@ -0,0 +1,110 @@ +@extends('layouts.app') + +@section('title', 'Laporan Bulanan : ' . $months[$month] . ' ' . $year) + +@section('content') + + +

    + Laporan Bulanan : {{ $months[$month] }} {{ $year }} +

    + +{!! Form::open(['method'=>'get','class'=>'form-inline well well-sm']) !!} +{!! Form::select('month', $months, $month, ['class'=>'form-control']) !!} +{!! Form::select('year', $years, $year, ['class'=>'form-control']) !!} +{!! Form::submit('Lihat Laporan', ['class'=>'btn btn-info']) !!} +{!! link_to_route('reports.payments.monthly','Bulan ini',[],['class'=>'btn btn-default']) !!} +{!! link_to_route('reports.payments.yearly','Lihat Tahunan',['year' => $year],['class'=>'btn btn-default']) !!} +{!! Form::close() !!} + +
    +

    Grafik Profit {{ $months[$month] }} {{ $year }}

    +
    + Rp. +
    +
    Tanggal
    +
    +
    +
    +

    Detail Laporan

    +
    + + + + + + + + + + + + @forelse($reports as $key => $report) + + + + + + + + + count; + $sumTotal += $report->cashin; + $sumCapital += $report->cashout; + $sumProfit += ($report->cashin - $report->cashout); + $cartData[] = ['date'=>dateId($report->date),'value'=>($report->cashin - $report->cashout)]; + ?> + @empty + + @endforelse + + + + + + + + + + + +
    TanggalJumlah TransferUang MasukUang KeluarProfitPilihan
    {{ dateId($report->date) }}{{ $report->count }}{{ formatRp($report->cashin) }}{{ formatRp($report->cashout) }}{{ formatRp(($report->cashin - $report->cashout)) }} + {!! link_to_route('reports.payments.daily','Lihat Harian',['date' => $report->date] , ['class'=>'btn btn-info btn-xs','title'=>'Lihat laporan harian ' . $report->date]) !!} +
    {{ trans('payment.not_found') }}
    Jumlah{{ $invoicesCount }}{{ formatRp($sumTotal) }}{{ formatRp($sumCapital) }}{{ formatRp($sumProfit) }}
    +
    +
    +@endsection + +@section('ext_css') + {!! Html::style(url('assets/css/plugins/morris.css')) !!} +@endsection + +@section('ext_js') + {!! Html::script(url('assets/js/plugins/morris/raphael.min.js')) !!} + {!! Html::script(url('assets/js/plugins/morris/morris.min.js')) !!} +@endsection + +@section('script') + +@endsection diff --git a/resources/views/reports/payments/yearly.blade.php b/resources/views/reports/payments/yearly.blade.php new file mode 100755 index 0000000..460a6c6 --- /dev/null +++ b/resources/views/reports/payments/yearly.blade.php @@ -0,0 +1,104 @@ +@extends('layouts.app') + +@section('title', 'Laporan Tahunan : ' . $year) + +@section('content') + + +

    Laporan Tahunan : {{ $year }}

    + +{!! Form::open(['method'=>'get','class'=>'form-inline well well-sm']) !!} +{!! Form::select('year', $years, $year, ['class'=>'form-control']) !!} +{!! Form::submit('Lihat Laporan', ['class'=>'btn btn-info']) !!} +{!! link_to_route('reports.payments.yearly','Tahun ini',[],['class'=>'btn btn-default']) !!} +{!! Form::close() !!} + +
    +

    Grafik Profit {{ $year }}

    +
    + Rp. +
    +
    Bulan
    +
    +
    +
    +

    Detail Laporan

    +
    + + + + + + + + + + + + @forelse($reports as $key => $report) + + + + + + + + + count; + $sumTotal += $report->cashin; + $sumCapital += $report->cashout; + $sumProfit += ($report->cashin - $report->cashout); + $cartData[] = ['month'=>monthId($report->month),'value'=>($report->cashin - $report->cashout)]; + ?> + @empty + + @endforelse + + + + + + + + + + + +
    BulanJumlah TransferUang MasukUang KeluarProfitPilihan
    {{ monthId($report->month) }}{{ $report->count }}{{ formatRp($report->cashin) }}{{ formatRp($report->cashout) }}{{ formatRp(($report->cashin - $report->cashout)) }}{!! link_to_route('reports.payments.monthly','Lihat Bulanan',['month' => monthNumber($report->month), 'year' => $year] , ['class'=>'btn btn-info btn-xs','title'=>'Lihat laporan bulanan ' . monthId($report->month)]) !!}
    {{ trans('payment.not_found') }}
    Jumlah{{ $invoicesCount }}{{ formatRp($sumTotal) }}{{ formatRp($sumCapital) }}{{ formatRp($sumProfit) }}
    +
    +
    +@endsection + +@section('ext_css') + {!! Html::style(url('assets/css/plugins/morris.css')) !!} +@endsection + +@section('ext_js') + {!! Html::script(url('assets/js/plugins/morris/raphael.min.js')) !!} + {!! Html::script(url('assets/js/plugins/morris/morris.min.js')) !!} +@endsection + +@section('script') + +@endsection