From ab598c12c92dedfc1c00cfd3dec2e3d8701ae9b5 Mon Sep 17 00:00:00 2001 From: Hafifie PKB Date: Wed, 4 Mar 2026 09:36:29 +0800 Subject: [PATCH 1/6] 1. added page for edit mutu 2. change from max pinjaman with a static 75% and 80% to manipulate value --- .../Controllers/MaxPinjamanController.php | 107 ++++++++++++- app/MaxMutuEmas.php | 40 +++++ bootstrap/app.php | 2 +- config/parameter.php | 5 + ...02_12_144445_create_max_mutuemas_table.php | 140 ++++++++++++++++++ routes/web.php | 2 + 6 files changed, 293 insertions(+), 3 deletions(-) create mode 100644 app/MaxMutuEmas.php create mode 100644 config/parameter.php create mode 100644 database/migrations/2026_02_12_144445_create_max_mutuemas_table.php diff --git a/app/Http/Controllers/MaxPinjamanController.php b/app/Http/Controllers/MaxPinjamanController.php index 734d04b..540abe7 100644 --- a/app/Http/Controllers/MaxPinjamanController.php +++ b/app/Http/Controllers/MaxPinjamanController.php @@ -2,14 +2,117 @@ namespace App\Http\Controllers; +use App\MaxMutuEmas; use App\MaxPinjaman; use Illuminate\Http\Request; class MaxPinjamanController extends Controller { - public function getAllMaxPinjaman(){ - $pinjaman = MaxPinjaman::on('mysql7')->get(); + public function getAllMaxPinjaman(Request $request) + { + if (config('parameter.max_mutuemas')) { + $data = MaxMutuEmas::on('mysql7')->select('karat', 'teller', 'pc', 'operasi')->get(); + $calculateMargin = $this->calculateMaxPinjamanMutu($data, $request->mutu,$request->total_nilai_marhun); + + $pinjaman = [ + [ + "user_type" => "teller", + "max" => $calculateMargin['teller'] + ], + [ + "user_type" => "khazanah", + "max" => $calculateMargin['pc'] + ], + [ + "user_type" => "operasi", + "max" => $calculateMargin['operasi'] + ] + ]; + } else { + $pinjaman = MaxPinjaman::on('mysql7')->get(); + } return response()->json($pinjaman); } + + public function calculateMaxPinjamanMutu($data, $mutu,$totalMarhun) + { + $totalMaxPC = 0; + $totalMaxTeller = 0; + $totalMaxOperasi = 0; + + if($mutu == null || $totalMarhun == 0){ + return [ + "pc" => 0, + "teller" => 0, + "operasi" => 0 + ]; + } + $mutuKarat = array_map(function($item) { + return $item[0]; + }, $mutu); + $mutuNilai = array_map(function($item) { + return $item[1]; + }, $mutu); + + foreach($mutuKarat as $index => $karat){ + $margin = $data->where('karat', $karat)->first(); + if($margin){ + $nilai = $mutuNilai[$index]; + $totalMaxPC += ($margin->pc/100) * $nilai; + $totalMaxTeller += ($margin->teller/100) * $nilai; + $totalMaxOperasi += ($margin->operasi/100) * $nilai; + } + } + $totalMaxPC = $totalMarhun > 0 ? ($totalMaxPC / $totalMarhun) * 100 : 0; + $totalMaxTeller = $totalMarhun > 0 ? ($totalMaxTeller / $totalMarhun) * 100 : 0; + $totalMaxOperasi = $totalMarhun > 0 ? ($totalMaxOperasi / $totalMarhun) * 100 : 0; + + + return [ + "pc" => round($totalMaxPC,2), + "teller" => round($totalMaxTeller,2), + "operasi" => round($totalMaxOperasi,2) + ]; + } + + + public function getAllMaxMutuEmas(Request $request) + { + $maxmutuemas = MaxMutuEmas::on('mysql7')->get(); + return response()->json($maxmutuemas); + } + + public function updateMaxMutuEmas(Request $request) + { + $recno = $request->recno; + $karat = $request->karat; + $keterangan = $request->keterangan; + $teller = $request->teller; + $pc = $request->pc; + $operasi = $request->operasi; + + $maxmutuemas = MaxMutuEmas::on('mysql7')->where('recno', $recno)->first(); + + if ($maxmutuemas) { + $maxmutuemas->karat = $karat; + $maxmutuemas->keterangan = $keterangan; + $maxmutuemas->teller = $teller; + $maxmutuemas->pc = $pc; + $maxmutuemas->operasi = $operasi; + $maxmutuemas->tarikhupdate = \Carbon\Carbon::now(); + $maxmutuemas->save(); + + return response()->json([ + 'status' => 'success', + 'message' => 'Max Mutu Emas updated successfully', + 'data' => $maxmutuemas + ]); + } else { + return response()->json([ + 'status' => 'error', + 'message' => 'Record not found' + ], 404); + } + } } \ No newline at end of file diff --git a/app/MaxMutuEmas.php b/app/MaxMutuEmas.php new file mode 100644 index 0000000..4512185 --- /dev/null +++ b/app/MaxMutuEmas.php @@ -0,0 +1,40 @@ + 'decimal:2', + 'pc' => 'decimal:2', + 'operasi' => 'decimal:2', + 'tarikhupdate' => 'datetime', + ]; + + /** + * The attributes excluded from the model's JSON form. + * + * @var array + */ + // protected $hidden = []; +} \ No newline at end of file diff --git a/bootstrap/app.php b/bootstrap/app.php index 16b5e30..d358544 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -64,7 +64,7 @@ $app->configure('tinker'); $app->configure('tennant_database'); $app->configure('report'); $app->configure('app_parameter'); - +$app->configure('parameter'); /* |-------------------------------------------------------------------------- | Register Middleware diff --git a/config/parameter.php b/config/parameter.php new file mode 100644 index 0000000..8af8857 --- /dev/null +++ b/config/parameter.php @@ -0,0 +1,5 @@ + env('MAX_MUTUEMAS', true), +]; \ No newline at end of file diff --git a/database/migrations/2026_02_12_144445_create_max_mutuemas_table.php b/database/migrations/2026_02_12_144445_create_max_mutuemas_table.php new file mode 100644 index 0000000..718a8fb --- /dev/null +++ b/database/migrations/2026_02_12_144445_create_max_mutuemas_table.php @@ -0,0 +1,140 @@ +id('recno'); + $table->string('karat'); + $table->string('keterangan'); + $table->decimal('teller', 8, 2); + $table->decimal('pc', 8, 2); + $table->decimal('operasi', 8, 2); + $table->timestamp('tarikhupdate'); + }); + + // Insert data + DB::table('max_mutuemas')->insert([ + [ + 'recno' => 1, + 'karat' => '24.0Kgb', + 'keterangan' => '999 gb', + 'teller' => 75.00000, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 2, + 'karat' => '24.0K', + 'keterangan' => '999', + 'teller' => 75.00000, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 3, + 'karat' => '23.0K', + 'keterangan' => '950', + 'teller' => 74.00000, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 4, + 'karat' => '22.0K', + 'keterangan' => '916', + 'teller' => 73.66667, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 5, + 'karat' => '21.0K', + 'keterangan' => '900', + 'teller' => 73.16667, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 6, + 'karat' => '20.0K', + 'keterangan' => '835', + 'teller' => 72.66667, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 7, + 'karat' => '18.0Kp', + 'keterangan' => '750', + 'teller' => 72.16667, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 8, + 'karat' => '18.0K', + 'keterangan' => '750', + 'teller' => 71.66667, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 21, + 'karat' => '14.0K', + 'keterangan' => '585', + 'teller' => 71.16667, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 22, + 'karat' => '14.0Kp', + 'keterangan' => '585', + 'teller' => 70.66667, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + [ + 'recno' => 23, + 'karat' => '9.0K', + 'keterangan' => '375', + 'teller' => 70.16667, + 'pc' => 80.00000, + 'operasi' => 80.00000, + 'tarikhupdate' => '2025-01-12 00:00:00', + ], + ]); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('max_mutuemas'); + } +} \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 2c3c1be..1faced3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -262,6 +262,8 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->get('maxpinjaman',['uses'=>'MaxPinjamanController@getAllMaxPinjaman']); + $router->get('maxmutuemas',['uses'=>'MaxPinjamanController@getAllMaxMutuEmas']); + $router->post('maxmutuemas/update',['uses'=>'MaxPinjamanController@updateMaxMutuEmas']); $router->get('transaksi_keuntungan/{norujukan}',['uses'=>'TransaksiKeuntunganController@getTransaksiKeuntunganByRujukan']); $router->get('transaksi_keuntungan_latest/{norujukan}',['uses'=>'TransaksiKeuntunganController@getTransaksiKeuntunganByRujukanLatest']); From 041369e04960b4ae073d49a56e6c243745713003 Mon Sep 17 00:00:00 2001 From: Hafifie PKB Date: Tue, 10 Mar 2026 09:55:08 +0800 Subject: [PATCH 2/6] add specific mutuemas API --- .../Controllers/MaxPinjamanController.php | 23 +++++++++++++++++++ routes/web.php | 1 + 2 files changed, 24 insertions(+) diff --git a/app/Http/Controllers/MaxPinjamanController.php b/app/Http/Controllers/MaxPinjamanController.php index 540abe7..5948442 100644 --- a/app/Http/Controllers/MaxPinjamanController.php +++ b/app/Http/Controllers/MaxPinjamanController.php @@ -83,6 +83,29 @@ class MaxPinjamanController extends Controller return response()->json($maxmutuemas); } + public function getSpecificMaxMutuEmas(Request $request) + { + $karat = $request->karat; + $nilaimarhun = $request->nilaimarhun; + + $nilaimarhun = preg_replace('/[^0-9.]/', '', $nilaimarhun); // Remove non-numeric characters except decimal point + $nilaimarhun = is_numeric($nilaimarhun) ? (float)$nilaimarhun : 0; + + $maxmutuemas = MaxMutuEmas::on('mysql7')->where('karat', $karat)->first(); + + if($maxmutuemas && $nilaimarhun > 0){ + $maxmutuemas->maxteller = ($maxmutuemas->teller/100) * $nilaimarhun; + $maxmutuemas->maxpc = ($maxmutuemas->pc/100) * $nilaimarhun; + $maxmutuemas->maxoperasi = ($maxmutuemas->operasi/100) * $nilaimarhun; + } else if($maxmutuemas) { + $maxmutuemas->maxteller = 0; + $maxmutuemas->maxpc = 0; + $maxmutuemas->maxoperasi = 0; + } + + return response()->json($maxmutuemas); + } + public function updateMaxMutuEmas(Request $request) { $recno = $request->recno; diff --git a/routes/web.php b/routes/web.php index 1faced3..f74c21e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -263,6 +263,7 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->get('maxpinjaman',['uses'=>'MaxPinjamanController@getAllMaxPinjaman']); $router->get('maxmutuemas',['uses'=>'MaxPinjamanController@getAllMaxMutuEmas']); + $router->get('maxmutuemas/specific',['uses'=>'MaxPinjamanController@getSpecificMaxMutuEmas']); $router->post('maxmutuemas/update',['uses'=>'MaxPinjamanController@updateMaxMutuEmas']); $router->get('transaksi_keuntungan/{norujukan}',['uses'=>'TransaksiKeuntunganController@getTransaksiKeuntunganByRujukan']); From d540a3461d0208631e4d5ab4b4a597ff29917dee Mon Sep 17 00:00:00 2001 From: Hafifie PKB Date: Tue, 10 Mar 2026 10:23:07 +0800 Subject: [PATCH 3/6] add validation for editing mutu marhun --- .../Controllers/MaxPinjamanController.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/Http/Controllers/MaxPinjamanController.php b/app/Http/Controllers/MaxPinjamanController.php index 5948442..1dc0a41 100644 --- a/app/Http/Controllers/MaxPinjamanController.php +++ b/app/Http/Controllers/MaxPinjamanController.php @@ -108,6 +108,45 @@ class MaxPinjamanController extends Controller public function updateMaxMutuEmas(Request $request) { + // Validate the request manually for Lumen + $validator = \Illuminate\Support\Facades\Validator::make($request->all(), [ + 'recno' => 'required|integer', + 'karat' => 'required|string|max:10', + 'keterangan' => 'required|string|max:255', + 'teller' => 'required|numeric|min:0|max:100', + 'pc' => 'required|numeric|min:0|max:100', + 'operasi' => 'required|numeric|min:0|max:100', + ], [ + 'recno.required' => 'Nombor rekod diperlukan.', + 'recno.integer' => 'Nombor rekod mesti berupa nombor.', + 'karat.required' => 'Karat diperlukan.', + 'karat.string' => 'Karat mesti berupa teks.', + 'karat.max' => 'Karat tidak boleh lebih dari 10 aksara.', + 'keterangan.required' => 'Keterangan diperlukan.', + 'keterangan.string' => 'Keterangan mesti berupa teks.', + 'keterangan.max' => 'Keterangan tidak boleh lebih dari 255 aksara.', + 'teller.required' => 'Peratus teller diperlukan.', + 'teller.numeric' => 'Peratus teller mesti berupa nombor.', + 'teller.min' => 'Peratus teller mestilah sekurang-kurangnya 0.', + 'teller.max' => 'Peratus teller tidak boleh melebihi 100.', + 'pc.required' => 'Peratus PC diperlukan.', + 'pc.numeric' => 'Peratus PC mesti berupa nombor.', + 'pc.min' => 'Peratus PC mestilah sekurang-kurangnya 0.', + 'pc.max' => 'Peratus PC tidak boleh melebihi 100.', + 'operasi.required' => 'Peratus operasi diperlukan.', + 'operasi.numeric' => 'Peratus operasi mesti berupa nombor.', + 'operasi.min' => 'Peratus operasi mestilah sekurang-kurangnya 0.', + 'operasi.max' => 'Peratus operasi tidak boleh melebihi 100.', + ]); + + if ($validator->fails()) { + return response()->json([ + 'status' => 'error', + 'message' => 'Pengesahan gagal', + 'errors' => $validator->errors() + ], 422); + } + $recno = $request->recno; $karat = $request->karat; $keterangan = $request->keterangan; From 860b57285dbfa1b07aa4b7c7b0eb38e8e2464733 Mon Sep 17 00:00:00 2001 From: Hafifie PKB Date: Wed, 11 Mar 2026 00:55:04 +0800 Subject: [PATCH 4/6] added nilaimarhun for marign teller and pc --- .../Controllers/MaxPinjamanController.php | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/app/Http/Controllers/MaxPinjamanController.php b/app/Http/Controllers/MaxPinjamanController.php index 1dc0a41..7cecc9f 100644 --- a/app/Http/Controllers/MaxPinjamanController.php +++ b/app/Http/Controllers/MaxPinjamanController.php @@ -5,7 +5,7 @@ namespace App\Http\Controllers; use App\MaxMutuEmas; use App\MaxPinjaman; use Illuminate\Http\Request; - +use Illuminate\Support\Facades\Log; class MaxPinjamanController extends Controller { public function getAllMaxPinjaman(Request $request) @@ -18,15 +18,19 @@ class MaxPinjamanController extends Controller $pinjaman = [ [ "user_type" => "teller", - "max" => $calculateMargin['teller'] + "max" => $calculateMargin['teller'], + "teller_pinjaman" => $calculateMargin['teller_pinjaman'] + ], [ "user_type" => "khazanah", - "max" => $calculateMargin['pc'] + "max" => $calculateMargin['pc'], + "pc_pinjaman" => $calculateMargin['pc_pinjaman'] ], [ "user_type" => "operasi", - "max" => $calculateMargin['operasi'] + "max" => $calculateMargin['operasi'], + "operasi_pinjaman" => $calculateMargin['operasi_pinjaman'] ] ]; } else { @@ -37,15 +41,18 @@ class MaxPinjamanController extends Controller public function calculateMaxPinjamanMutu($data, $mutu,$totalMarhun) { - $totalMaxPC = 0; - $totalMaxTeller = 0; - $totalMaxOperasi = 0; + $totalMaxMarhunPC = 0; + $totalMaxMarhunTeller = 0; + $totalMaxMarhunOperasi = 0; if($mutu == null || $totalMarhun == 0){ return [ "pc" => 0, + "pc_pinjaman" => 0, "teller" => 0, - "operasi" => 0 + "teller_pinjaman" => 0, + "operasi" => 0, + "operasi_pinjaman" => 0 ]; } $mutuKarat = array_map(function($item) { @@ -59,20 +66,22 @@ class MaxPinjamanController extends Controller $margin = $data->where('karat', $karat)->first(); if($margin){ $nilai = $mutuNilai[$index]; - $totalMaxPC += ($margin->pc/100) * $nilai; - $totalMaxTeller += ($margin->teller/100) * $nilai; - $totalMaxOperasi += ($margin->operasi/100) * $nilai; + $totalMaxMarhunPC += round(($margin->pc/100) * $nilai, 2); + $totalMaxMarhunTeller += round(($margin->teller/100) * $nilai, 2); + $totalMaxMarhunOperasi += round(($margin->operasi/100) * $nilai, 2); } } - $totalMaxPC = $totalMarhun > 0 ? ($totalMaxPC / $totalMarhun) * 100 : 0; - $totalMaxTeller = $totalMarhun > 0 ? ($totalMaxTeller / $totalMarhun) * 100 : 0; - $totalMaxOperasi = $totalMarhun > 0 ? ($totalMaxOperasi / $totalMarhun) * 100 : 0; - + $totalMaxPC = $totalMarhun > 0 ? ($totalMaxMarhunPC / $totalMarhun) * 100 : 0; + $totalMaxTeller = $totalMarhun > 0 ? ($totalMaxMarhunTeller / $totalMarhun) * 100 : 0; + $totalMaxOperasi = $totalMarhun > 0 ? ($totalMaxMarhunOperasi / $totalMarhun) * 100 : 0; return [ "pc" => round($totalMaxPC,2), + "pc_pinjaman" => round(($totalMaxPC / 100) * $totalMarhun, 2), "teller" => round($totalMaxTeller,2), - "operasi" => round($totalMaxOperasi,2) + "teller_pinjaman" => round(($totalMaxTeller / 100) * $totalMarhun, 2), + "operasi" => round($totalMaxOperasi,2), + "operasi_pinjaman" => round(($totalMaxOperasi / 100) * $totalMarhun, 2) ]; } @@ -94,9 +103,9 @@ class MaxPinjamanController extends Controller $maxmutuemas = MaxMutuEmas::on('mysql7')->where('karat', $karat)->first(); if($maxmutuemas && $nilaimarhun > 0){ - $maxmutuemas->maxteller = ($maxmutuemas->teller/100) * $nilaimarhun; - $maxmutuemas->maxpc = ($maxmutuemas->pc/100) * $nilaimarhun; - $maxmutuemas->maxoperasi = ($maxmutuemas->operasi/100) * $nilaimarhun; + $maxmutuemas->maxteller = round(($maxmutuemas->teller/100) * $nilaimarhun, 2); + $maxmutuemas->maxpc = round(($maxmutuemas->pc/100) * $nilaimarhun, 2); + $maxmutuemas->maxoperasi = round(($maxmutuemas->operasi/100) * $nilaimarhun, 2); } else if($maxmutuemas) { $maxmutuemas->maxteller = 0; $maxmutuemas->maxpc = 0; From c76fce70c3da12d359499ca916e9bdc0131fe655 Mon Sep 17 00:00:00 2001 From: Hafifie PKB Date: Wed, 11 Mar 2026 11:06:04 +0800 Subject: [PATCH 5/6] added audit logs for operasi --- app/Http/Controllers/MaxPinjamanController.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/Http/Controllers/MaxPinjamanController.php b/app/Http/Controllers/MaxPinjamanController.php index 7cecc9f..ed996cd 100644 --- a/app/Http/Controllers/MaxPinjamanController.php +++ b/app/Http/Controllers/MaxPinjamanController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Audit; use App\MaxMutuEmas; use App\MaxPinjaman; use Illuminate\Http\Request; @@ -125,6 +126,7 @@ class MaxPinjamanController extends Controller 'teller' => 'required|numeric|min:0|max:100', 'pc' => 'required|numeric|min:0|max:100', 'operasi' => 'required|numeric|min:0|max:100', + 'username' => 'required|string|max:255' ], [ 'recno.required' => 'Nombor rekod diperlukan.', 'recno.integer' => 'Nombor rekod mesti berupa nombor.', @@ -162,10 +164,15 @@ class MaxPinjamanController extends Controller $teller = $request->teller; $pc = $request->pc; $operasi = $request->operasi; + $username = $request->username; + + $current = \Carbon\Carbon::now(); $maxmutuemas = MaxMutuEmas::on('mysql7')->where('recno', $recno)->first(); if ($maxmutuemas) { + $oldmax = $maxmutuemas->toJson(); + $maxmutuemas->karat = $karat; $maxmutuemas->keterangan = $keterangan; $maxmutuemas->teller = $teller; @@ -174,6 +181,17 @@ class MaxPinjamanController extends Controller $maxmutuemas->tarikhupdate = \Carbon\Carbon::now(); $maxmutuemas->save(); + Audit::create([ + 'users' => $username, + 'actions' => 'Penukaran Mutu Margin', + 'norujukan' => '-', + 'new_data' => $maxmutuemas->toJson(), + 'old_data' => $oldmax, + 'kodcaw' => 'OPERASI', + 'created_at' => $current, + 'updated_at' => $current, + ]); + return response()->json([ 'status' => 'success', 'message' => 'Max Mutu Emas updated successfully', From 0dcf421d0efb97575806a48370fe900cc9ce249a Mon Sep 17 00:00:00 2001 From: Hafifie PKB Date: Thu, 12 Mar 2026 12:21:22 +0800 Subject: [PATCH 6/6] added laporan audit in operasi --- .../Reports/AuditTrailController.php | 78 +++++++++++++++++++ routes/report.php | 3 +- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/Reports/AuditTrailController.php diff --git a/app/Http/Controllers/Reports/AuditTrailController.php b/app/Http/Controllers/Reports/AuditTrailController.php new file mode 100644 index 0000000..a24ff1a --- /dev/null +++ b/app/Http/Controllers/Reports/AuditTrailController.php @@ -0,0 +1,78 @@ +get('limit', 100); + + $audit_trails = Audit::query() + ->when($request->filled('norujukan'), fn($q) => $q->where('norujukan', $request->norujukan)) + ->when($request->filled('actions'), fn($q) => $q->where('actions', $request->actions)) + ->orderBy('created_at', 'desc') + ->limit($limit) + ->get(); + + return response()->json($audit_trails); + } + + public function AuditTrailOperasi(Request $request) + { + $date_first = $request->get('date', null); + $date_till = $request->get('date_till', null); + + $audit_trails = Audit::query() + ->where('kodcaw', 'operasi') + ->whereDate('created_at', '>=', $date_first) + ->whereDate('created_at', '<=', $date_till) + ->orderBy('created_at', 'asc') + ->get(); + + $audit_trails->map(function ($audit) { + // Convert from UTC to Malaysia timezone (UTC+8) + $audit->created_at = $audit->created_at->format('Y-m-d H:i:s'); + + // Get differences between old_data and new_data + $old_data = json_decode($audit->old_data, true) ?? []; + $new_data = json_decode($audit->new_data, true) ?? []; + + $differences = []; + + // Find changed fields + foreach ($new_data as $key => $new_value) { + if ($key === 'tarikhupdate') continue; + + $old_value = $old_data[$key] ?? null; + if ($old_value !== $new_value) { + $differences[$key] = [ + 'old' => $old_value, + 'new' => $new_value + ]; + } + } + + // Check for removed fields + foreach ($old_data as $key => $old_value) { + if ($key === 'tarikhupdate') continue; + + if (!array_key_exists($key, $new_data)) { + $differences[$key] = [ + 'old' => $old_value, + 'new' => null + ]; + } + } + + $audit->differences = $differences; + return $audit; + }); + + return response()->json($audit_trails); + } +} \ No newline at end of file diff --git a/routes/report.php b/routes/report.php index c202553..0046b76 100644 --- a/routes/report.php +++ b/routes/report.php @@ -55,7 +55,8 @@ $router->group(['prefix' => 'api/reports'], function () use ($router) { $router->get('gadaitebus', ['uses' => 'GadaianController@getSummaryLaporanGadaiTebus']); $router->get('gadaitebusmasa', ['uses' => 'GadaianController@getSummaryLaporanGadaiTebusMasa']); $router->get('gadaitebusmasa/{kod_cawangan}', ['uses' => 'GadaianController@getLaporanGadaiTebusMasaCawangan']); - + $router->get('audit-trail', ['uses' => 'AuditTrailController@getAuditTrail']); + $router->get('audittrail/operasi',['uses'=>'AuditTrailController@AuditTrailOperasi']); $router->get('saringan/gadaian', ['uses' => 'SaringanGadaianController@getLaporanGadai']); $router->get('data-pelanggan', ['uses' => 'AnalisaController@getSummaryLaporanDataPelanggan']);