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('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/app/Http/Controllers/TebusController.php b/app/Http/Controllers/TebusController.php index 1c58952..72c370c 100644 --- a/app/Http/Controllers/TebusController.php +++ b/app/Http/Controllers/TebusController.php @@ -1121,7 +1121,7 @@ class TebusController extends Controller ->sum('upahdibayar'); $upahlelong = Lelong::on($cawangan['mysql']) - ->where([['t_jual','<=',$request->tarikh],['t_jual','>','2013-12-31']]) + ->where([['t_jual','<=',$request->tarikh],['t_jual','>','2013-12-31'],['t_jual','<=','2022-07-24']]) ->whereYear('t_jual','=',$current->year) ->sum('bakiupah'); @@ -1708,7 +1708,13 @@ class TebusController extends Controller // dd($ansuran); - $total = ($keuntungan + $keuntunganreducing + $ansuran + $bukanansuran); + $upahlelong = Lelong::on($cawangan['mysql']) + ->where([['t_jual','<=',$request->tarikh],['t_jual','>','2022-07-24']]) + ->whereYear('t_jual','=',$current->year) + ->sum('bakiupah'); + + + $total = ($keuntungan + $keuntunganreducing + $ansuran + $bukanansuran + $upahlelong); } diff --git a/routes/web.php b/routes/web.php index 34bb9a9..8699d27 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']);