feat(webstatement): tambahkan fitur pengelolaan kartu ATM
- Tambahkan menu "Kartu ATM" pada konfigurasi menu module. - Implementasi controller `KartuAtmController` dengan fungsi `index` dan `dataForDatatables`. - Tambahkan route untuk pengelolaan "Kartu ATM" termasuk datatables. - Tambahkan model relasi `biaya` pada model `Atmcard`. - Tambahkan view halaman daftar kartu ATM dengan fitur datatables. - Tambahkan breadcrumbs untuk halaman "Kartu ATM". Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
105
app/Http/Controllers/KartuAtmController.php
Normal file
105
app/Http/Controllers/KartuAtmController.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Webstatement\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Webstatement\Models\Atmcard;
|
||||
|
||||
class KartuAtmController extends Controller
|
||||
{
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('webstatement::kartu-atm.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide data for datatables.
|
||||
*/
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
|
||||
// Retrieve data from the database
|
||||
$query = Atmcard::query();
|
||||
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('crdno', 'LIKE', "%$search%")
|
||||
->orWhere('accflag', 'LIKE', "%$search%")
|
||||
->orWhere('cracc1', 'LIKE', "%$search%")
|
||||
->orWhere('cracc2', 'LIKE', "%$search%")
|
||||
->orWhere('cracc3', 'LIKE', "%$search%")
|
||||
->orWhere('cracc4', 'LIKE', "%$search%")
|
||||
->orWhere('cracc5', 'LIKE', "%$search%")
|
||||
->orWhere('craccnam1', 'LIKE', "%$search%")
|
||||
->orWhere('craccnam2', 'LIKE', "%$search%")
|
||||
->orWhere('craccnam3', 'LIKE', "%$search%")
|
||||
->orWhere('craccnam4', 'LIKE', "%$search%")
|
||||
->orWhere('craccnam5', 'LIKE', "%$search%")
|
||||
->orWhere('crsts', 'LIKE', "%$search%")
|
||||
->orWhere('cttype', 'LIKE', "%$search%")
|
||||
->orWhere('ctdesc', 'LIKE', "%$search%")
|
||||
->orWhere('crdate', 'LIKE', "%$search%")
|
||||
->orWhere('branch', 'LIKE', "%$search%")
|
||||
->orWhere('fee', 'LIKE', "%$search%")
|
||||
->orWhere('currency', 'LIKE', "%$search%");
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
// Apply sorting if provided
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
$query->orderBy($column, $order);
|
||||
}
|
||||
|
||||
// Get the total count of records
|
||||
$totalRecords = $query->count();
|
||||
|
||||
// Apply pagination if provided
|
||||
if ($request->has('page') && $request->has('size')) {
|
||||
$page = $request->get('page');
|
||||
$size = $request->get('size');
|
||||
$offset = ($page - 1) * $size; // Calculate the offset
|
||||
|
||||
$query->skip($offset)->take($size);
|
||||
}
|
||||
|
||||
// Get the filtered count of records
|
||||
$filteredRecords = $query->count();
|
||||
|
||||
// Get the data for the current page
|
||||
$data = $query->get();
|
||||
|
||||
// Calculate the page count
|
||||
$pageCount = ceil($filteredRecords / ($request->get('size') ?: 1));
|
||||
|
||||
// Calculate the current page number
|
||||
$currentPage = $request->get('page') ?: 1;
|
||||
|
||||
$data = $data->map(function ($item) {
|
||||
$item->fee = $item->biaya->biaya;
|
||||
return $item;
|
||||
});
|
||||
|
||||
// Return the response data as a JSON object
|
||||
return response()->json([
|
||||
'draw' => $request->get('draw'),
|
||||
'recordsTotal' => $totalRecords,
|
||||
'recordsFiltered' => $filteredRecords,
|
||||
'pageCount' => $pageCount,
|
||||
'page' => $currentPage,
|
||||
'totalCount' => $totalRecords,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user