diff --git a/app/AuditCustomer.php b/app/AuditCustomer.php new file mode 100644 index 0000000..b86564b --- /dev/null +++ b/app/AuditCustomer.php @@ -0,0 +1,23 @@ +where('kodcaw','=',$request->kodcaw)->first(); + + $year = $request->year; + $month = $request->month; + + if($request->jenistebus == 'T') + { + $bukanansuran_data = TransaksiKeuntungan::on('mysql7') + ->leftJoin('transaction as trans', function($join) + { + $join->on('transaksi_keuntungan.norujukan', '=', 'trans.norujukan'); + $join->on('transaksi_keuntungan.tarikh_bayaran', '=', 'trans.created_at'); + }) + ->where('trans.trans_type','!=','A') + // ->whereDate('transaksi_keuntungan.tarikh_bayaran' ,'>=', $request->mula) + // ->whereDate('transaksi_keuntungan.tarikh_bayaran' ,'<=', $request->hingga) + ->whereMonth('transaksi_keuntungan.tarikh_bayaran','=',$month) + ->whereYear('tarikh_bayaran','=',$year) + ->where('trans.kodcaw',$request->kodcaw); + + $bukanansuran_get = $bukanansuran_data->get(); + $bukanansuran_pluck = $bukanansuran_data->pluck('trans.norujukan'); + + $intersection = $bukanansuran_get->intersectByKeys(Gadai::on($cawangan['mysql'])->whereNotNull('hargajualan')->get()); + $collectionbukanansurandata = $intersection->toArray(); + + return response()->json($collectionbukanansurandata,200); + }else if($request->jenistebus == 'A'){ + $ansuran_data = TransaksiKeuntungan::on('mysql7') + // ->join($cawangan['db_name'].'.gadai as db2','transaksi_keuntungan.norujukan','=','db2.norujukan') + ->leftJoin('transaction as trans', function($join) + { + $join->on('transaksi_keuntungan.norujukan', '=', 'trans.norujukan'); + $join->on('transaksi_keuntungan.tarikh_bayaran', '=', 'trans.created_at'); + }) + ->where('trans.trans_type','=','A') + // ->whereDate('transaksi_keuntungan.tarikh_bayaran' ,'>=', $request->mula) + // ->whereDate('transaksi_keuntungan.tarikh_bayaran' ,'<=', $request->hingga) + ->whereMonth('transaksi_keuntungan.tarikh_bayaran','=',$month) + ->whereYear('tarikh_bayaran','=',$year) + ->where('trans.kodcaw',$request->kodcaw); + + $ansuran_get = $ansuran_data->get(); + $ansuran_pluck = $ansuran_data->pluck('trans.norujukan'); + + $intersection = $ansuran_get->intersectByKeys(Gadai::on($cawangan['mysql'])->whereNotNull('hargajualan')->get()); + + $collectionansurandata = $intersection->toArray(); + + return response()->json($collectionansurandata,200); + }else{ + $upahlelong = Lelong::on($cawangan['mysql']) + ->where('t_jual','>','2013-12-31') + ->whereMonth('t_lelong','=',$month) + ->whereYear('t_lelong','=',$year) + ->get(); + + return response()->json($upahlelong,200); + } + } } \ No newline at end of file diff --git a/app/Http/Controllers/CustomerController.php b/app/Http/Controllers/CustomerController.php index 66b17e9..9bfc451 100644 --- a/app/Http/Controllers/CustomerController.php +++ b/app/Http/Controllers/CustomerController.php @@ -10,10 +10,13 @@ use App\Lelong; use App\Cawangan; use App\Poskod; use App\Blacklist; +use App\AuditCustomer; use Illuminate\Http\Request; use Carbon\Carbon; +use DB; + class CustomerController extends Controller { @@ -377,26 +380,73 @@ class CustomerController extends Controller } public function customerUpdateKhazanah($nokp,Request $request){ - - $poskod = Poskod::on('mysql7')->where('poskod','=',$request->poskod)->first(); + + DB::connection('mysql7')->beginTransaction(); - $customer_update = Customer::on('mysql7') - ->where('kplama','=',$nokp) - ->orWhere('kpbaru','=',$nokp) - ->update(array( - 'telefon' => $request->telefon1, - 'telefon2' => $request->telefon2, - 'kodbank' => $request->kodbank, - 'noakaun' => $request->noakaun, - 'nota' => $request->nota, - 'nama' => $request->nama, - 'alamat1' => $request->alamat, - 'poskod' => $request->poskod, - 'koddaerah' => $poskod['koddaerah'], - 'kodnegeri' => $poskod['kodnegeri'] - )); + try{ + $poskod = DB::connection('mysql7')->table('poskod')->where('poskod','=',$request->poskod)->first(); + + $customer_info = DB::connection('mysql7')->table('customer') + ->select('kodcaw','tarikhdaftar','nopelanggan','kpbaru','kplama','nama','t_lahir','jantina','alamat1','poskod') + ->where('kplama','=',$nokp) + ->orWhere('kpbaru','=',$nokp) + ->get()->toArray(); + + $old_data = json_encode($customer_info); + + $customer_update = DB::connection('mysql7') + ->table('customer') + ->where('kplama','=',$nokp) + ->orWhere('kpbaru','=',$nokp) + ->update(array( + 'telefon' => $request->telefon1, + 'telefon2' => $request->telefon2, + 'kodbank' => $request->kodbank, + 'noakaun' => $request->noakaun, + 'nota' => $request->nota, + 'nama' => $request->nama, + 'alamat1' => $request->alamat, + 'poskod' => $request->poskod, + 'koddaerah' => $poskod->koddaerah, + 'kodnegeri' => $poskod->kodnegeri + )); + + + if($customer_update) + { + $customer_info_new = DB::connection('mysql7')->table('customer') + ->select('kodcaw','tarikhdaftar','nopelanggan','kpbaru','kplama','nama','t_lahir','jantina','alamat1','poskod') + ->where('kplama','=',$nokp) + ->orWhere('kpbaru','=',$nokp) + ->get()->toArray(); + + $new_data = json_encode($customer_info_new); + + $audit_customer = DB::connection('mysql7') + ->table('audit_customer') + ->insert([ + 'username' => $request->namakhazanah, + 'old_data' => $old_data, + 'new_data' => $new_data, + 'kodcaw' => $request->kodcaw, + 'created_at' => Carbon::now()->toDateTimeString(), + 'updated_at' => Carbon::now()->toDateTimeString(), + 'customer_name' => $request->nama, + 'customer_nokp' => $nokp, + ]); + } + + + DB::connection('mysql7')->commit(); + + return response()->json($customer_update, 200); + + }catch (\Exception $e) { + DB::connection('mysql7')->rollback(); + return response()->json($e->getMessage(),400); + + } - return response()->json($customer_update, 200); } public function customerUpdateAdmin(Request $request){ diff --git a/app/Http/Controllers/LelongController.php b/app/Http/Controllers/LelongController.php index 54a50b4..2367aad 100644 --- a/app/Http/Controllers/LelongController.php +++ b/app/Http/Controllers/LelongController.php @@ -802,6 +802,89 @@ class LelongController extends Controller } } + public function getSenaraiBatchNoTuntutBaki($kodcaw,Request $request) + { + $current = Carbon::now(); + $current = new Carbon(); + + $arraybatch = []; + + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first(); + + $batchleltuntutbaki = BatchLel::on($cawangan['mysql']) + ->selectRaw('count(lel.norujukan) as bilangan,batchlel.batchno as batchno,lel.t_lelong as tarikhlelong') + ->leftJoin('lelong as lel', 'lel.batchno', '=', 'batchlel.batchno') + ->leftJoin('gadai as gad', 'gad.norujukan', '=', 'lel.norujukan') + ->whereNotNull('gad.upah12') + ->whereNotNull('lel.hargajual') + ->whereNull('lel.trkhtuntut') + ->where('lel.baki','>',0) + ->groupBy('batchlel.batchno') + ->get()->toArray(); + + $batchlelrugi = BatchLel::on($cawangan['mysql']) + ->selectRaw('count(lel.norujukan) as bilangan,batchlel.batchno as batchno,lel.t_lelong as tarikhlelong') + ->leftJoin('lelong as lel', 'lel.batchno', '=', 'batchlel.batchno') + ->leftJoin('gadai as gad', 'gad.norujukan', '=', 'lel.norujukan') + ->whereNotNull('gad.upah12') + ->whereNotNull('lel.hargajual') + ->whereNull('lel.trkhtuntut') + ->where('lel.baki','<',0) + ->groupBy('batchlel.batchno') + ->get()->toArray(); + + $batchnosama = []; + if(sizeof($batchleltuntutbaki) > 0 && sizeof($batchlelrugi) > 0) + { + foreach($batchleltuntutbaki as $index=>$bl) + { + foreach($batchlelrugi as $index=>$rl) + { + if($bl['batchno'] == $rl['batchno']) + { + array_push($arraybatch,['batchno' => $bl['batchno'], 'bilangantuntutbaki' => $bl['bilangan'], 'bilanganrugi' => $rl['bilangan'],'tarikhlelong' => $bl['tarikhlelong']]); + array_push($batchnosama,$bl['batchno']); + } + } + + } + + } + + $countsama = 0; + foreach($batchleltuntutbaki as $index=>$bl) + { + + if($batchnosama) + { + $dif=array_intersect($bl,$batchnosama); + + if(!$dif) + { + array_push($arraybatch,['batchno' => $bl['batchno'], 'bilangantuntutbaki' => $bl['bilangan'], 'bilanganrugi' => 0,'tarikhlelong' => $bl['tarikhlelong']]); + } + } + + } + + foreach($batchlelrugi as $index=>$br) + { + + if($batchnosama) + { + $dif=array_intersect($br,$batchnosama); + + if(!$dif) + { + array_push($arraybatch,['batchno' => $br['batchno'], 'bilangantuntutbaki' => 0, 'bilanganrugi' => $br['bilangan'],'tarikhlelong' => $br['tarikhlelong']]); + } + } + + } + + return response()->json($arraybatch); + } + public function getSenaraiTuntutBaki($kodcaw,Request $request){ $current = Carbon::now(); @@ -812,16 +895,31 @@ class LelongController extends Controller $bulanlepas = $current->subMonth()->toDateString(); - $lelong = Lelong::on($cawangan['mysql']) + if($request->jenis == 'tuntutbaki') + { + $lelong = Lelong::on($cawangan['mysql']) ->select('lelong.t_lelong','lelong.norujukan','gadai.nokp','gadai.bakipjm','lelong.bakiupah','lelong.t_jual','lelong.cajlelong','lelong.baki','lelong.cajlain','lelong.gst_hj','lelong.gst_cl','lelong.hargajual') ->leftJoin('gadai', 'gadai.norujukan', '=', 'lelong.norujukan') ->where('baki','>',0) - ->where('lelong.t_lelong','>=',$bulanlepas) + ->where('batchno',$request->batchno) ->whereNotNull('t_jual') ->whereNull('trkhtuntut') ->orderBy('gadai.t_gadai','asc') ->orderBy('gadai.sirig','asc') ->where('gadai.taglel','=', 1); + }else{ + $lelong = Lelong::on($cawangan['mysql']) + ->select('lelong.t_lelong','lelong.norujukan','gadai.nokp','gadai.bakipjm','lelong.bakiupah','lelong.t_jual','lelong.cajlelong','lelong.baki','lelong.cajlain','lelong.gst_hj','lelong.gst_cl','lelong.hargajual') + ->leftJoin('gadai', 'gadai.norujukan', '=', 'lelong.norujukan') + ->where('baki','<',0) + ->where('batchno',$request->batchno) + ->whereNotNull('t_jual') + ->whereNull('trkhtuntut') + ->orderBy('gadai.t_gadai','asc') + ->orderBy('gadai.sirig','asc') + ->where('gadai.taglel','=', 1); + } + $lelonglist = $lelong->get(); foreach($lelonglist as $index=>$lel) diff --git a/routes/web.php b/routes/web.php index 7d0da34..66c1438 100644 --- a/routes/web.php +++ b/routes/web.php @@ -267,6 +267,7 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->get('senaraibatch/aktif/{kodcaw}/{fasa}',['uses'=>'LelongController@getSenaraiLelongAktif']); $router->get('senaraibatch/laporan/{kodcaw}/{fasa}',['uses'=>'LelongController@getSenaraiBatchNoAktif']); $router->get('details/notislelong/{kodcaw}',['uses'=>'LelongController@DetailsNotisLelong']); + $router->get('senaraituntutbaki/aktif_batch/{kodcaw}/',['uses'=>'LelongController@getSenaraiBatchNoTuntutBaki']); $router->get('senaraituntutbaki/laporan/{kodcaw}',['uses'=>'LelongController@getSenaraiTuntutBaki']); @@ -715,6 +716,9 @@ $router->group(['prefix'=>'admin'], function () use ($router){ $router->get('wtd/rekod',['uses'=>'AdminPageController@rekodWTD']); $router->get('wtd/rekod/{batchno}',['uses'=>'AdminPageController@rekodWTDByBatchNo']); + $router->get('audit/keuntungansebenar',['uses'=>'AdminPageController@KeuntunganSebenarExport']); + +