added notification and sound to the admin and added record of autoserahan

This commit is contained in:
Hafifie PKB
2025-03-25 00:55:53 +08:00
parent dff57b269e
commit 2c8a44eaab
8 changed files with 385 additions and 60 deletions
+89 -5
View File
@@ -6,10 +6,78 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Log;
use Carbon\Carbon;
class AutoSerahanController extends Controller
{
public function index(Request $request)
{
$response = Http::get(config('api.url') . '/api/autoserahan/list', [
'page' => request('page', 1) // Get current page from request
])->json();
$items = $response['data'] ?? []; // Data array
$total = $response['total'] ?? 0; // Total items
$perPage = $response['per_page'] ?? 10; // Items per page
$currentPage = $response['current_page'] ?? 1; // Current page
$items = array_map(function ($item) {
$time_created = Carbon::parse($item['created_at']);
$item['cawangan_name'] = $this->CawanganKod($item['kodcaw']);
$item['tarikh'] = $time_created->toDateString();
$item['masa'] = $time_created->format('h:i A');
return $item;
}, $items);
// Create Laravel paginator
$list = new LengthAwarePaginator($items, $total, $perPage, $currentPage, [
'path' => request()->url(), // Current URL
'query' => request()->query(), // Append other query params
]);
return view('autoserahan.index', compact('list'));
}
public function record(Request $request){
$response = Http::get(config('api.url') . '/api/autoserahan/allrecord', [
'page' => request('page', 1),
'kodcaw' => request('kodcaw', null),
'tarikh_mula' => request('tarikh_mula', null),
'tarikh_hingga' => request('tarikh_hingga', null),
'masa_mula' => request('masa_mula', null),
'masa_hingga' => request('masa_hingga', null),
'status' => request('status', null),
'transaksi' => request('transaksi', null),
])->json();
$items = $response['data'] ?? []; // Data array
$total = $response['total'] ?? 0; // Total items
$perPage = $response['per_page'] ?? 10; // Items per page
$currentPage = $response['current_page'] ?? 1; // Current page
$items = array_map(function ($item) {
$time_created = Carbon::parse($item['created_at']);
$item['cawangan_name'] = $this->CawanganKod($item['kodcaw']);
$item['tarikh'] = $time_created->toDateString();
$item['masa'] = $time_created->format('h:i A');
return $item;
}, $items);
$list = new LengthAwarePaginator($items, $total, $perPage, $currentPage, [
'path' => request()->url(), // Current URL
'query' => request()->query(), // Append other query params
]);
$filteredCawangan = $this->listkodcaw();
return view('autoserahan.rekod', compact('list','filteredCawangan'));
}
public function getList(Request $request){
// Fetch paginated data from API
$response = Http::get(config('api.url') . '/api/autoserahan/list', [
'page' => request('page', 1) // Get current page from request
@@ -32,7 +100,8 @@ class AutoSerahanController extends Controller
'path' => request()->url(), // Current URL
'query' => request()->query(), // Append other query params
]);
return view('autoserahan.index', compact('list'));
return response()->json($list);
}
public function approve(Request $request)
@@ -128,10 +197,25 @@ class AutoSerahanController extends Controller
}
}
private function listkodcaw(){
$cawangan = Http::get(config('api.url_koop') . '/api/cawangan/')->json();
private function CawanganKod($kodcaw) {
$cawangan = Http::get(config('api.url_koop') . '/api/cawangan/' . $kodcaw)->json();
// Extract only kodcaw and details_caw
$filteredCawangan = array_map(function ($item) {
return [
'kodcaw' => $item['kodcaw'],
'details_caw' => $item['details_caw']
];
}, $cawangan);
return $cawangan['details_caw'] ?? 'Undefined';
}
return $filteredCawangan;
}
private function CawanganKod($kodcaw) {
$cawangan = Http::get(config('api.url_koop') . '/api/cawangan/' . $kodcaw)->json();
return $cawangan['details_caw'] ?? 'Undefined';
}
}