From 9eb095ebe0a8d85cd3a3c939a872ceb115d3278a Mon Sep 17 00:00:00 2001 From: fifi97 <46933637+fifi97@users.noreply.github.com> Date: Wed, 9 Feb 2022 11:50:53 +0800 Subject: [PATCH] fix skit2 --- app/Http/Controllers/AdminPageController.php | 235 ++++++++++++++----- 1 file changed, 175 insertions(+), 60 deletions(-) diff --git a/app/Http/Controllers/AdminPageController.php b/app/Http/Controllers/AdminPageController.php index 3a7809b..5d0e85f 100644 --- a/app/Http/Controllers/AdminPageController.php +++ b/app/Http/Controllers/AdminPageController.php @@ -227,53 +227,109 @@ class AdminPageController extends Controller ->whereYear('bajettahunan.tahun', '=', $current->year) ->sum('nilaibajet'); - $lelongupahsimpan = Lelong::on($cawangan['mysql']) - ->selectRaw('SUM(bakiupah) AS totalupahlelong') - ->addSelect(DB::connection($cawangan['mysql']) - ->raw('DATE_FORMAT(t_jual, "%Y-%m") as t_jual')) - ->groupBy(DB::connection($cawangan['mysql']) - ->raw("DATE_FORMAT(t_jual,'%Y%m')")) - ->whereYear('t_jual',$current->year) - // ->where([['t_jual','<=',$current->toDateString()],['t_jual','>=',$monthly_date]]) - ->orderBy('t_jual','asc') - ->get(); + $tebus_arrahn = Tebus::on($cawangan['mysql']) + ->rightJoin('gadai', 'gadai.norujukan', '=', 'tebus.norujukan') + ->selectRaw('SUM(tebus.bakiupah) AS total') + ->addSelect(DB::connection($cawangan['mysql']) + ->raw('DATE_FORMAT(t_tebus, "%Y-%m") as tarikh')) + ->groupBy(DB::connection($cawangan['mysql']) + ->raw("DATE_FORMAT(t_tebus,'%Y%m')")) + ->whereYear('t_tebus',$current->year) + ->where([['tebus.jenistebus','=','T'],['gadai.hargajualan','=',null],['t_tebus','<=',$current->toDateString()]]) + ->orderBy('t_tebus','asc') + ->get()->toArray(); - $totallelong = 0; + $advansur = Advansur::on($cawangan['mysql']) + ->selectRaw('SUM(upahDibayar) AS total') + ->addSelect(DB::connection($cawangan['mysql']) + ->raw('DATE_FORMAT(tarikh, "%Y-%m") as tarikh')) + ->groupBy(DB::connection($cawangan['mysql']) + ->raw("DATE_FORMAT(tarikh,'%Y%m')")) + ->whereYear('tarikh',$current->year) + ->where([['tarikh','<=',$current->toDateString()]]) + ->get()->toArray(); + + $ansuran = Transaction::on('mysql7') + ->selectRaw('SUM(trans.bayaran_keuntungan) AS total') + ->addSelect(DB::connection($cawangan['mysql']) + ->raw('DATE_FORMAT(transaction.created_at, "%Y-%m") as tarikh')) + ->groupBy(DB::connection($cawangan['mysql']) + ->raw("DATE_FORMAT(transaction.created_at,'%Y%m')")) + ->whereYear('transaction.created_at',$current->year) + ->leftJoin('transaksi_keuntungan as trans', function($join) + { + $join->on('transaction.norujukan', '=', 'trans.norujukan'); + $join->on('transaction.created_at', '=', 'trans.tarikh_bayaran'); + }) + ->where('transaction.trans_type','=','A') + ->where([['trans.tarikh_bayaran','<=',$current->toDateString(). ' 23:59:59']]) + ->where('trans.kodcaw','=',$request->kodcaw) + ->get()->toArray(); + + $tebus_upah_tawarruq = Transaction::on('mysql7') + ->selectRaw('SUM(trans.keuntungan_rebet) AS total') + ->addSelect(DB::connection($cawangan['mysql']) + ->raw('DATE_FORMAT(transaction.created_at, "%Y-%m") as tarikh')) + ->groupBy(DB::connection($cawangan['mysql']) + ->raw("DATE_FORMAT(transaction.created_at,'%Y%m')")) + ->whereYear('transaction.created_at',$current->year) + ->leftJoin('transaksi_keuntungan as trans', function($join) + { + $join->on('transaction.norujukan', '=', 'trans.norujukan'); + $join->on('transaction.created_at', '=', 'trans.tarikh_bayaran'); + }) + ->where('transaction.trans_type','!=','A') + ->where([['trans.tarikh_bayaran','<=',$current->toDateString() . ' 23:59:59']]) + ->where('trans.kodcaw','=',$request->kodcaw) + ->get()->toArray(); + + + $lelongupahsimpan = Lelong::on($cawangan['mysql']) + ->selectRaw('SUM(bakiupah) AS total') + ->addSelect(DB::connection($cawangan['mysql']) + ->raw('DATE_FORMAT(t_jual, "%Y-%m") as tarikh')) + ->groupBy(DB::connection($cawangan['mysql']) + ->raw("DATE_FORMAT(t_jual,'%Y%m')")) + ->whereYear('t_jual',$current->year) + ->orderBy('t_jual','asc') + ->get()->toArray(); + + $totalall = 0; foreach($lelongupahsimpan as $index=>$lelong) { - $totallelong += $lelong['totalupahlelong']; + $totalall += $lelong['total'] + $tebus_arrahn[$index]['total'] + $advansur[$index]['total'] + $ansuran[$index]['total'] + $tebus_upah_tawarruq[$index]['total']; } - $tebus = Tebus::on($cawangan['mysql']) - ->selectRaw('SUM(bakiupah) AS totalupahsimpan') - ->addSelect(DB::connection($cawangan['mysql']) - ->raw('DATE_FORMAT(t_tebus, "%Y-%m") as t_tebus')) - ->groupBy(DB::connection($cawangan['mysql']) - ->raw("DATE_FORMAT(t_tebus,'%Y%m')")) - ->where(function($query) use ($current){ - $query - ->where([['jenistebus','=','T'],['t_tebus','<=',$current->toDateString()]]) - ->whereYear('t_tebus',$current->year); - }) - ->orWhere(function($query) use ($current){ - $query - ->where([['jenistebus','=','T'],['t_tebus','<=',$current->toDateString()]]) - ->whereYear('t_tebus',$current->year); - }) - ->orderBy('t_tebus','asc') - ->get(); + // $tebus = Tebus::on($cawangan['mysql']) + // ->selectRaw('SUM(bakiupah) AS totalupahsimpan') + // ->addSelect(DB::connection($cawangan['mysql']) + // ->raw('DATE_FORMAT(t_tebus, "%Y-%m") as t_tebus')) + // ->groupBy(DB::connection($cawangan['mysql']) + // ->raw("DATE_FORMAT(t_tebus,'%Y%m')")) + // ->where(function($query) use ($current){ + // $query + // ->where([['jenistebus','=','T'],['t_tebus','<=',$current->toDateString()]]) + // ->whereYear('t_tebus',$current->year); + // }) + // ->orWhere(function($query) use ($current){ + // $query + // ->where([['jenistebus','=','T'],['t_tebus','<=',$current->toDateString()]]) + // ->whereYear('t_tebus',$current->year); + // }) + // ->orderBy('t_tebus','asc') + // ->get(); - $totaltebus = 0; - foreach($tebus as $index=>$teb) - { - $totaltebus += $teb['totalupahsimpan']; - } + // $totaltebus = 0; + // foreach($tebus as $index=>$teb) + // { + // $totaltebus += $teb['totalupahsimpan']; + // } - $total = $totaltebus + $totallelong; + // $total = $totaltebus + $totallelong; - array_push($arrayKeuntungan,['bajet' => $bajetgroup,'total' => $total]); + array_push($arrayKeuntungan,['bajet' => $bajetgroup,'total' => $totalall]); return response()->json($arrayKeuntungan); @@ -829,47 +885,106 @@ class AdminPageController extends Controller $lelongupahsimpan = Lelong::on($cawangan['mysql']) - ->selectRaw('SUM(bakiupah) AS totalupahlelong') + ->selectRaw('SUM(bakiupah) AS total') ->addSelect(DB::connection($cawangan['mysql']) - ->raw('DATE_FORMAT(t_jual, "%Y-%m") as t_jual')) + ->raw('DATE_FORMAT(t_jual, "%Y-%m") as tarikh')) ->groupBy(DB::connection($cawangan['mysql']) ->raw("DATE_FORMAT(t_jual,'%Y%m')")) ->whereYear('t_jual',$current->year) ->where([['t_jual','<=',$current->toDateString()],['t_jual','>=',$monthly_date]]) ->orderBy('t_jual','asc') - ->get(); + ->get()->toArray(); - $tebus = Tebus::on($cawangan['mysql']) - ->selectRaw('SUM(bakiupah) AS totalupahsimpan') + $tebus_arrahn = Tebus::on($cawangan['mysql']) + ->rightJoin('gadai', 'gadai.norujukan', '=', 'tebus.norujukan') + ->selectRaw('SUM(tebus.bakiupah) AS total') ->addSelect(DB::connection($cawangan['mysql']) - ->raw('DATE_FORMAT(t_tebus, "%Y-%m") as t_tebus')) + ->raw('DATE_FORMAT(t_tebus, "%Y-%m") as tarikh')) ->groupBy(DB::connection($cawangan['mysql']) ->raw("DATE_FORMAT(t_tebus,'%Y%m')")) ->whereYear('t_tebus',$current->year) - ->where([['jenistebus','=','T'],['t_tebus','<=',$current->toDateString()],['t_tebus','>=',$monthly_date]]) - ->orWhere([['jenistebus','=','A'],['t_tebus','<=',$current->toDateString()],['t_tebus','>=',$monthly_date]]) + ->where([['tebus.jenistebus','=','T'],['gadai.hargajualan','=',null],['t_tebus','<=',$current->toDateString()],['t_tebus','>=',$monthly_date]]) ->orderBy('t_tebus','asc') - ->get(); + ->get()->toArray(); + $advansur = Advansur::on($cawangan['mysql']) + ->selectRaw('SUM(upahDibayar) AS total') + ->addSelect(DB::connection($cawangan['mysql']) + ->raw('DATE_FORMAT(tarikh, "%Y-%m") as tarikh')) + ->groupBy(DB::connection($cawangan['mysql']) + ->raw("DATE_FORMAT(tarikh,'%Y%m')")) + ->whereYear('tarikh',$current->year) + ->where([['tarikh','<=',$current->toDateString()],['tarikh','>=',$monthly_date]]) + ->get()->toArray(); + + $ansuran = Transaction::on('mysql7') + ->selectRaw('SUM(trans.bayaran_keuntungan) AS total') + ->addSelect(DB::connection($cawangan['mysql']) + ->raw('DATE_FORMAT(transaction.created_at, "%Y-%m") as tarikh')) + ->groupBy(DB::connection($cawangan['mysql']) + ->raw("DATE_FORMAT(transaction.created_at,'%Y%m')")) + ->whereYear('transaction.created_at',$current->year) + ->leftJoin('transaksi_keuntungan as trans', function($join) + { + $join->on('transaction.norujukan', '=', 'trans.norujukan'); + $join->on('transaction.created_at', '=', 'trans.tarikh_bayaran'); + }) + ->where('transaction.trans_type','=','A') + ->where([['trans.tarikh_bayaran','>=',$monthly_date . ' 00:00:00'],['trans.tarikh_bayaran','<=',$current->toDateString(). ' 23:59:59']]) + ->where('trans.kodcaw','=',$request->kodcaw) + ->get()->toArray(); + + $tebus_upah_tawarruq = Transaction::on('mysql7') + ->selectRaw('SUM(trans.keuntungan_rebet) AS total') + ->addSelect(DB::connection($cawangan['mysql']) + ->raw('DATE_FORMAT(transaction.created_at, "%Y-%m") as tarikh')) + ->groupBy(DB::connection($cawangan['mysql']) + ->raw("DATE_FORMAT(transaction.created_at,'%Y%m')")) + ->whereYear('transaction.created_at',$current->year) + ->leftJoin('transaksi_keuntungan as trans', function($join) + { + $join->on('transaction.norujukan', '=', 'trans.norujukan'); + $join->on('transaction.created_at', '=', 'trans.tarikh_bayaran'); + }) + ->where('transaction.trans_type','!=','A') + ->where([['trans.tarikh_bayaran','>=',$monthly_date . ' 00:00:00'],['trans.tarikh_bayaran','<=',$current->toDateString() . ' 23:59:59']]) + ->where('trans.kodcaw','=',$request->kodcaw) + ->get()->toArray(); + + + // dd($array_totalup); foreach($array_totalup as $array_index=>$totalup){ - foreach($lelongupahsimpan as $indexlelong=>$lelong_detail){ - if($totalup['tarikh'] == $lelong_detail['t_jual']){ - $total_lelong = $totalup['keuntungan']; - $total_lelong += $lelong_detail['totalupahlelong']; - $array_totalup[$array_index]['keuntungan'] = $total_lelong; - } - } + // foreach($lelongupahsimpan as $indexlelong=>$lelong_detail){ + // if($totalup['tarikh'] == $lelong_detail['t_jual']){ + // $total_lelong = $totalup['keuntungan']; + // $total_lelong += $lelong_detail['totalupahlelong']; + // $array_totalup[$array_index]['keuntungan'] = $total_lelong; + // } + // } - foreach($tebus as $indextebus=>$tebus_detail){ - if($totalup['tarikh'] == $tebus_detail['t_tebus']){ - $total_tebus = $array_totalup[$array_index]['keuntungan']; - $total_tebus += $tebus_detail['totalupahsimpan']; - $array_totalup[$array_index]['keuntungan'] = $total_tebus; - $array_totalup[$array_index]['bajetkeuntungan'] = (sizeof($bajetkeuntungan) > 0) ? $bajetkeuntungan[$array_index] : 0; + // foreach($tebus as $indextebus=>$tebus_detail){ + // if($totalup['tarikh'] == $tebus_detail['t_tebus']){ + // $total_tebus = $array_totalup[$array_index]['keuntungan']; + // $total_tebus += $tebus_detail['totalupahsimpan']; + // $array_totalup[$array_index]['keuntungan'] = $total_tebus; + // $array_totalup[$array_index]['bajetkeuntungan'] = (sizeof($bajetkeuntungan) > 0) ? $bajetkeuntungan[$array_index] : 0; + // } + // } + + foreach($lelongupahsimpan as $indexloop=>$looptambahan) + { + if($totalup['tarikh'] == $looptambahan['tarikh']){ + $total = 0; + $total = $looptambahan['total'] + $tebus_arrahn[$indexloop]['total'] + $advansur[$indexloop]['total'] + $ansuran[$indexloop]['total'] + $tebus_upah_tawarruq[$indexloop]['total']; + // $total_keuntungan = $array_totalup[$array_index]['keuntungan']; + $total_keuntungan = $total; + $array_totalup[$array_index]['keuntungan'] = $total_keuntungan; + $array_totalup[$array_index]['bajetkeuntungan'] = (sizeof($bajetkeuntungan) > 0) ? $bajetkeuntungan[$array_index] : 0; } - } + } + $goals[0]['value'] = (sizeof($bajetkeuntungan) > 0) ? $bajetkeuntungan[$array_index] : 0; array_push($arrayKeuntungan,['x' => $array_totalup[$array_index]['namabulan'],'y' => $array_totalup[$array_index]['keuntungan'],'goals' => (array) $goals]); }