feat(sync-logs): tambah fitur sinkronisasi log biaya kartu - Menambahkan route, controller, model, dan migration untuk fitur baru `sync-logs`. - Mengganti referensi `BiayaKartuController` menjadi `SyncLogsController`. - Menyediakan halaman untuk menampilkan data log sinkronisasi dengan filter, pencarian, dan pagination. - Menambahkan kemampuan melihat detail proses sinkronisasi langsung dari modal. - Memperbarui `module.json` dengan item menu baru untuk fitur log sinkronisasi. - Menghapus `BiayaKartuController` yang sudah tidak digunakan lagi. ``` Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
127 lines
4.1 KiB
PHP
127 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace Modules\Webstatement\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\File;
|
|
use Carbon\Carbon;
|
|
use Modules\Webstatement\Jobs\GenerateBiayaKartuCsvJob;
|
|
use Modules\Webstatement\Models\KartuSyncLog;
|
|
|
|
class SyncLogsController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
return view('webstatement::sync-logs.index');
|
|
}
|
|
|
|
/**
|
|
* Provide data for datatables - sync logs
|
|
*/
|
|
public function dataForDatatables(Request $request)
|
|
{
|
|
// Retrieve data from the database
|
|
$query = KartuSyncLog::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('periode', 'LIKE', "%$search%")
|
|
->orWhere('sync_notes', 'LIKE', "%$search%")
|
|
->orWhere('csv_notes', 'LIKE', "%$search%")
|
|
->orWhere('ftp_notes', 'LIKE', "%$search%")
|
|
->orWhere('file_name', 'LIKE', "%$search%");
|
|
});
|
|
}
|
|
|
|
// Apply filter for sync status if provided
|
|
if ($request->has('is_sync') && $request->get('is_sync') !== '') {
|
|
$query->where('is_sync', $request->get('is_sync') == '1');
|
|
}
|
|
|
|
// Apply filter for CSV status if provided
|
|
if ($request->has('is_csv') && $request->get('is_csv') !== '') {
|
|
$query->where('is_csv', $request->get('is_csv') == '1');
|
|
}
|
|
|
|
// Apply filter for FTP status if provided
|
|
if ($request->has('is_ftp') && $request->get('is_ftp') !== '') {
|
|
$query->where('is_ftp', $request->get('is_ftp') == '1');
|
|
}
|
|
|
|
// Apply sorting if provided
|
|
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
|
$order = $request->get('sortOrder');
|
|
$column = $request->get('sortField');
|
|
$query->orderBy($column, $order);
|
|
} else {
|
|
// Default sort by created_at descending
|
|
$query->orderBy('created_at', 'desc');
|
|
}
|
|
|
|
// 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;
|
|
|
|
$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;
|
|
|
|
// 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,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Format file size to human readable format
|
|
*/
|
|
private function formatSize($bytes)
|
|
{
|
|
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
|
|
$bytes = max($bytes, 0);
|
|
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
|
|
$pow = min($pow, count($units) - 1);
|
|
|
|
$bytes /= pow(1024, $pow);
|
|
|
|
return round($bytes, 2) . ' ' . $units[$pow];
|
|
}
|
|
|
|
public function show($id){
|
|
$syncLog = KartuSyncLog::find($id);
|
|
$csvSize = $this->formatSize(File::size($syncLog->csv_path));
|
|
$ftpSize = $this->formatSize(File::size($syncLog->ftp_path));
|
|
|
|
return response()->json($syncLog, 200, ['Content-Type' => 'application/json'], JSON_PRETTY_PRINT);
|
|
}
|
|
}
|