<?php namespace App\Http\Controllers;

    use Session;
	use Request;
	use DB;
	use Carbon;

    class LaporanBanjirController extends Controller {
        public function getIndex() {
            $data = [];
            $data['app_name'] = "Laporan Banjir";
            
            $data['jumlah_warga_banjarbaru'] = DB::table('warga_bjb')->count();
            
            $data['jumlah_warga_terdampak'] = DB::table('laporan_banjir')->sum('jumlah_terdampak');
            
        //     $data['jumlah_warga_terdampak'] = DB::table('laporan_warga')->where('nama_kel','6372041004')->whereExists(function ($query) {
        //       $query->select(DB::raw(1))
        //              ->from('history_bantuan')
        //              ->whereRaw('history_bantuan.warga_bjb_id = warga_bjb.id');
        //   })->count();
           
        //   $data['jumlah_penerima_bansos_by_jk'] = DB::table('warga_bjb')->where('nama_kel','6372041004')->whereExists(function ($query) {
        //       $query->select(DB::raw(1))
        //              ->from('history_bantuan')
        //              ->whereRaw('history_bantuan.warga_bjb_id = warga_bjb.id');
        //   })->select(DB::raw('sum(case when jk="L" then 1 else 0 end) as laki,sum(case when jk="P" then 1 else 0 end) as perempuan'))->get();
            
            $data['penerima_bansos'] = DB::table('laporan_banjir')
                ->join('villages','laporan_banjir.village_id','villages.id')
                ->where('laporan_banjir.district_id','637202')
                ->paginate(10);
           
            
            return view('simpul-bansos.examples.banjir',$data);
        }
    }