feat(webstatement): tambah fitur request dan pengelolaan print statement
- Tambah menu baru untuk "Print Statement" di konfigurasi module. - Tambah route baru untuk pengelolaan statement seperti list, download, otorisasi, dan datatables. - Implementasi `PrintStatementController` untuk operasi terkait request dan manajemen statement. - Implementasi model `PrintStatementLog` untuk mencatat log request statement, termasuk validasi dan relasi yang dibutuhkan. - Tambah form request `PrintStatementRequest` untuk validasi input. - Tambah migration untuk tabel `print_statement_logs` yang menyimpan rekaman log statement. - Tambah halaman blade untuk index dan form request statement. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
281
app/Http/Controllers/PrintStatementController.php
Normal file
281
app/Http/Controllers/PrintStatementController.php
Normal file
@@ -0,0 +1,281 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Webstatement\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Modules\Webstatement\Http\Requests\PrintStatementRequest;
|
||||
use Modules\Webstatement\Models\PrintStatementLog;
|
||||
use Modules\Basicdata\Models\Branch;
|
||||
|
||||
class PrintStatementController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the statements.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$branches = Branch::orderBy('name')->get();
|
||||
|
||||
return view('webstatement::statements.index', compact('branches'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new statement request.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$branches = Branch::orderBy('name')->get();
|
||||
return view('webstatement::statements.create', compact('branches',));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created statement request.
|
||||
*/
|
||||
public function store(PrintStatementRequest $request)
|
||||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
// Add user tracking data
|
||||
$validated['user_id'] = Auth::id();
|
||||
$validated['created_by'] = Auth::id();
|
||||
$validated['ip_address'] = $request->ip();
|
||||
$validated['user_agent'] = $request->userAgent();
|
||||
|
||||
// Create the statement log
|
||||
$statement = PrintStatementLog::create($validated);
|
||||
|
||||
// Process statement availability check (this would be implemented based on your system)
|
||||
$this->checkStatementAvailability($statement);
|
||||
|
||||
return redirect()->route('webstatement.statements.show', $statement->id)
|
||||
->with('success', 'Statement request has been created successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified statement.
|
||||
*/
|
||||
public function show(PrintStatementLog $statement)
|
||||
{
|
||||
$statement->load(['user', 'branch', 'creator', 'authorizer']);
|
||||
return view('webstatement::statements.show', compact('statement'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the statement if available and authorized.
|
||||
*/
|
||||
public function download(PrintStatementLog $statement)
|
||||
{
|
||||
// Check if statement is available and authorized
|
||||
if (!$statement->is_available) {
|
||||
return back()->with('error', 'Statement is not available for download.');
|
||||
}
|
||||
|
||||
if ($statement->authorization_status !== 'approved') {
|
||||
return back()->with('error', 'Statement download requires authorization.');
|
||||
}
|
||||
|
||||
// Update download status
|
||||
$statement->update([
|
||||
'is_downloaded' => true,
|
||||
'downloaded_at' => now(),
|
||||
'updated_by' => Auth::id()
|
||||
]);
|
||||
|
||||
// Generate or fetch the statement file (implementation depends on your system)
|
||||
$filePath = $this->generateStatementFile($statement);
|
||||
|
||||
// Return file download response
|
||||
return response()->download($filePath, $this->generateFileName($statement));
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorize a statement request.
|
||||
*/
|
||||
public function authorize(Request $request, PrintStatementLog $statement)
|
||||
{
|
||||
$request->validate([
|
||||
'authorization_status' => ['required', Rule::in(['approved', 'rejected'])],
|
||||
'remarks' => ['nullable', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
// Update authorization status
|
||||
$statement->update([
|
||||
'authorization_status' => $request->authorization_status,
|
||||
'authorized_by' => Auth::id(),
|
||||
'authorized_at' => now(),
|
||||
'remarks' => $request->remarks,
|
||||
'updated_by' => Auth::id()
|
||||
]);
|
||||
|
||||
$statusText = $request->authorization_status === 'approved' ? 'approved' : 'rejected';
|
||||
|
||||
return redirect()->route('webstatement.statements.show', $statement->id)
|
||||
->with('success', "Statement request has been {$statusText} successfully.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the statement is available in the system.
|
||||
* This is a placeholder method - implement according to your system.
|
||||
*/
|
||||
protected function checkStatementAvailability(PrintStatementLog $statement)
|
||||
{
|
||||
// This would be implemented based on your system's logic
|
||||
// For example, checking an API or database for statement availability
|
||||
|
||||
// Placeholder implementation - set to available for demo
|
||||
$statement->update([
|
||||
'is_available' => true,
|
||||
'updated_by' => Auth::id()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate or fetch the statement file.
|
||||
* This is a placeholder method - implement according to your system.
|
||||
*/
|
||||
protected function generateStatementFile(PrintStatementLog $statement)
|
||||
{
|
||||
// This would be implemented based on your system's logic
|
||||
// For example, calling an API to generate a PDF or fetching from storage
|
||||
|
||||
// Placeholder implementation - return a dummy path
|
||||
$tempFile = tempnam(sys_get_temp_dir(), 'statement_');
|
||||
file_put_contents($tempFile, 'Statement content would go here');
|
||||
return $tempFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a filename for the statement download.
|
||||
*/
|
||||
protected function generateFileName(PrintStatementLog $statement)
|
||||
{
|
||||
$accountNumber = $statement->account_number;
|
||||
|
||||
if ($statement->is_period_range) {
|
||||
return "statement_{$accountNumber}_{$statement->period_from}_to_{$statement->period_to}.pdf";
|
||||
}
|
||||
|
||||
return "statement_{$accountNumber}_{$statement->period_from}.pdf";
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide data for datatables.
|
||||
*/
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
// Check permissions if needed
|
||||
// if (!auth()->user()->can('view_statements')) {
|
||||
// abort(403, 'Sorry! You are not allowed to view statements.');
|
||||
// }
|
||||
|
||||
// Retrieve data from the database
|
||||
$query = PrintStatementLog::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('account_number', 'LIKE', "%$search%")
|
||||
->orWhere('branch_code', 'LIKE', "%$search%")
|
||||
->orWhere('period_from', 'LIKE', "%$search%")
|
||||
->orWhere('period_to', 'LIKE', "%$search%")
|
||||
->orWhere('authorization_status', 'LIKE', "%$search%");
|
||||
});
|
||||
}
|
||||
|
||||
// Apply column filters if provided
|
||||
if ($request->has('filters') && !empty($request->get('filters'))) {
|
||||
$filters = json_decode($request->get('filters'), true);
|
||||
|
||||
foreach ($filters as $filter) {
|
||||
if (!empty($filter['value'])) {
|
||||
if ($filter['column'] === 'branch_code') {
|
||||
$query->where('branch_code', $filter['value']);
|
||||
} elseif ($filter['column'] === 'authorization_status') {
|
||||
$query->where('authorization_status', $filter['value']);
|
||||
} elseif ($filter['column'] === 'is_downloaded') {
|
||||
$query->where('is_downloaded', filter_var($filter['value'], FILTER_VALIDATE_BOOLEAN));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Apply sorting if provided
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
|
||||
// Map frontend column names to database column names if needed
|
||||
$columnMap = [
|
||||
'branch' => 'branch_code',
|
||||
'account' => 'account_number',
|
||||
'period' => 'period_from',
|
||||
'status' => 'authorization_status',
|
||||
// Add more mappings as needed
|
||||
];
|
||||
|
||||
$dbColumn = $columnMap[$column] ?? $column;
|
||||
$query->orderBy($dbColumn, $order);
|
||||
} else {
|
||||
// Default sorting
|
||||
$query->latest('created_at');
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
// Eager load relationships to avoid N+1 query problems
|
||||
$query->with(['user', 'branch', 'authorizer']);
|
||||
|
||||
// Get the data for the current page
|
||||
$data = $query->get()->map(function ($item) {
|
||||
// Transform data for frontend if needed
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'branch_code' => $item->branch_code,
|
||||
'branch_name' => $item->branch->name ?? 'N/A',
|
||||
'account_number' => $item->account_number,
|
||||
'period_from' => $item->period_from,
|
||||
'period_to' => $item->is_period_range ? $item->period_to : null,
|
||||
'authorization_status' => $item->authorization_status,
|
||||
'is_available' => $item->is_available,
|
||||
'is_downloaded' => $item->is_downloaded,
|
||||
'created_at' => $item->created_at->format('Y-m-d H:i:s'),
|
||||
'created_by' => $item->user->name ?? 'N/A',
|
||||
'authorized_by' => $item->authorizer ? $item->authorizer->name : null,
|
||||
'authorized_at' => $item->authorized_at ? $item->authorized_at->format('Y-m-d H:i:s') : null,
|
||||
];
|
||||
});
|
||||
|
||||
// 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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
81
app/Http/Requests/PrintStatementRequest.php
Normal file
81
app/Http/Requests/PrintStatementRequest.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Webstatement\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class PrintStatementRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize()
|
||||
: bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules()
|
||||
: array
|
||||
{
|
||||
$rules = [
|
||||
'branch_code' => ['required', 'string', 'exists:branches,code'],
|
||||
'account_number' => ['required', 'string'],
|
||||
'is_period_range' => ['sometimes', 'boolean'],
|
||||
'period_from' => ['required', 'string', 'regex:/^\d{6}$/'], // YYYYMM format
|
||||
];
|
||||
|
||||
// If it's a period range, require period_to
|
||||
if ($this->input('is_period_range')) {
|
||||
$rules['period_to'] = [
|
||||
'required',
|
||||
'string',
|
||||
'regex:/^\d{6}$/', // YYYYMM format
|
||||
'gte:period_from' // period_to must be greater than or equal to period_from
|
||||
];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom messages for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function messages()
|
||||
: array
|
||||
{
|
||||
return [
|
||||
'branch_code.required' => 'Branch code is required',
|
||||
'branch_code.exists' => 'Selected branch does not exist',
|
||||
'account_number.required' => 'Account number is required',
|
||||
'period_from.required' => 'Period is required',
|
||||
'period_from.regex' => 'Period must be in YYYYMM format',
|
||||
'period_to.required' => 'End period is required for period range',
|
||||
'period_to.regex' => 'End period must be in YYYYMM format',
|
||||
'period_to.gte' => 'End period must be after or equal to start period',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation()
|
||||
: void
|
||||
{
|
||||
// Convert is_period_range to boolean if it exists
|
||||
if ($this->has('is_period_range')) {
|
||||
$this->merge([
|
||||
'is_period_range' => filter_var($this->is_period_range, FILTER_VALIDATE_BOOLEAN),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
183
app/Models/PrintStatementLog.php
Normal file
183
app/Models/PrintStatementLog.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Webstatement\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Modules\Basicdata\Models\Branch;
|
||||
use Modules\Usermanagement\Models\User;
|
||||
|
||||
class PrintStatementLog extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'branch_code',
|
||||
'account_number',
|
||||
'period_from',
|
||||
'period_to',
|
||||
'is_period_range',
|
||||
'is_available',
|
||||
'is_downloaded',
|
||||
'ip_address',
|
||||
'user_agent',
|
||||
'downloaded_at',
|
||||
'authorization_status',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
'authorized_by',
|
||||
'authorized_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_period_range' => 'boolean',
|
||||
'is_available' => 'boolean',
|
||||
'is_downloaded' => 'boolean',
|
||||
'downloaded_at' => 'datetime',
|
||||
'authorized_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the formatted period display
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPeriodDisplayAttribute()
|
||||
{
|
||||
if ($this->is_period_range) {
|
||||
return $this->formatPeriod($this->period_from) . ' - ' . $this->formatPeriod($this->period_to);
|
||||
}
|
||||
|
||||
return $this->formatPeriod($this->period_from);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format period from YYYYMM to Month Year
|
||||
*
|
||||
* @param string $period
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function formatPeriod($period)
|
||||
{
|
||||
if (strlen($period) !== 6) {
|
||||
return $period;
|
||||
}
|
||||
|
||||
$year = substr($period, 0, 4);
|
||||
$month = substr($period, 4, 2);
|
||||
|
||||
return date('F Y', mktime(0, 0, 0, (int) $month, 1, (int) $year));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user who requested the statement
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user who created the record
|
||||
*/
|
||||
public function creator()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user who updated the record
|
||||
*/
|
||||
public function updater()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'updated_by');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user who authorized the record
|
||||
*/
|
||||
public function authorizer()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'authorized_by');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include pending authorization records
|
||||
*/
|
||||
public function scopePending($query)
|
||||
{
|
||||
return $query->where('authorization_status', 'pending');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include approved records
|
||||
*/
|
||||
public function scopeApproved($query)
|
||||
{
|
||||
return $query->where('authorization_status', 'approved');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include rejected records
|
||||
*/
|
||||
public function scopeRejected($query)
|
||||
{
|
||||
return $query->where('authorization_status', 'rejected');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include downloaded records
|
||||
*/
|
||||
public function scopeDownloaded($query)
|
||||
{
|
||||
return $query->where('is_downloaded', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include available records
|
||||
*/
|
||||
public function scopeAvailable($query)
|
||||
{
|
||||
return $query->where('is_available', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the statement is for a single period
|
||||
*/
|
||||
public function isSinglePeriod()
|
||||
{
|
||||
return !$this->is_period_range;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the statement is authorized
|
||||
*/
|
||||
public function isAuthorized()
|
||||
{
|
||||
return $this->authorization_status === 'approved';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the statement is rejected
|
||||
*/
|
||||
public function isRejected()
|
||||
{
|
||||
return $this->authorization_status === 'rejected';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the statement is pending authorization
|
||||
*/
|
||||
public function isPending()
|
||||
{
|
||||
return $this->authorization_status === 'pending';
|
||||
}
|
||||
|
||||
public function branch(){
|
||||
return $this->belongsTo(Branch::class, 'branch_code','code');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('print_statement_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id')->nullable()->comment('User who requested the statement');
|
||||
$table->string('branch_code')->comment('Branch code');
|
||||
$table->string('account_number')->comment('Account number');
|
||||
$table->string('period_from')->comment('Statement period start (YYYYMM format)');
|
||||
$table->string('period_to')->nullable()->comment('Statement period end (YYYYMM format), null if single period');
|
||||
$table->boolean('is_period_range')->default(false)->comment('Whether the statement is for a period range');
|
||||
$table->boolean('is_available')->default(false)->comment('Whether the statement was found');
|
||||
$table->boolean('is_downloaded')->default(false)->comment('Whether the statement was downloaded');
|
||||
$table->string('ip_address')->nullable()->comment('IP address of requester');
|
||||
$table->string('user_agent')->nullable()->comment('User agent of requester');
|
||||
$table->timestamp('downloaded_at')->nullable()->comment('When the statement was downloaded');
|
||||
|
||||
$table->enum('authorization_status', ['pending', 'approved', 'rejected'])->default('pending');
|
||||
|
||||
// Add index for faster searching
|
||||
$table->index(['branch_code', 'account_number', 'period_from', 'period_to']);
|
||||
$table->index(['user_id', 'is_downloaded']);
|
||||
$table->index('authorization_status');
|
||||
|
||||
// User tracking fields
|
||||
$table->unsignedBigInteger('created_by')->nullable();
|
||||
$table->unsignedBigInteger('updated_by')->nullable();
|
||||
$table->unsignedBigInteger('deleted_by')->nullable();
|
||||
$table->unsignedBigInteger('authorized_by')->nullable();
|
||||
$table->timestamp('authorized_at')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('print_statement_logs');
|
||||
}
|
||||
};
|
||||
11
module.json
11
module.json
@@ -22,6 +22,17 @@
|
||||
"administrator"
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Print Statement",
|
||||
"path": "statements",
|
||||
"icon": "ki-filled ki-calendar text-lg text-primary",
|
||||
"classes": "",
|
||||
"attributes": [],
|
||||
"permission": "",
|
||||
"roles": [
|
||||
"administrator"
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Kartu ATM",
|
||||
"path": "kartu-atm",
|
||||
|
||||
38
resources/views/statements/create.blade.php
Normal file
38
resources/views/statements/create.blade.php
Normal file
@@ -0,0 +1,38 @@
|
||||
@extends('layouts.main')
|
||||
|
||||
@section('breadcrumbs')
|
||||
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Validate that end date is after start date
|
||||
const startDateInput = document.getElementById('start_date');
|
||||
const endDateInput = document.getElementById('end_date');
|
||||
|
||||
function validateDates() {
|
||||
const startDate = new Date(startDateInput.value);
|
||||
const endDate = new Date(endDateInput.value);
|
||||
|
||||
if (startDate > endDate) {
|
||||
endDateInput.setCustomValidity('End date must be after start date');
|
||||
} else {
|
||||
endDateInput.setCustomValidity('');
|
||||
}
|
||||
}
|
||||
|
||||
startDateInput.addEventListener('change', validateDates);
|
||||
endDateInput.addEventListener('change', validateDates);
|
||||
|
||||
// Set max date for date inputs to today
|
||||
const today = new Date().toISOString().split('T')[0];
|
||||
startDateInput.setAttribute('max', today);
|
||||
endDateInput.setAttribute('max', today);
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
349
resources/views/statements/index.blade.php
Normal file
349
resources/views/statements/index.blade.php
Normal file
@@ -0,0 +1,349 @@
|
||||
@extends('layouts.main')
|
||||
|
||||
@section('breadcrumbs')
|
||||
{{ Breadcrumbs::render(request()->route()->getName()) }}
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="grid">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">Request Print Stetement</h3>
|
||||
<div class="card-toolbar">
|
||||
<a href="{{ route('statements.index') }}" class="btn btn-sm btn-light">
|
||||
<i class="ki-outline ki-arrow-left fs-2"></i> Back
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="{{ isset($statement) ? route('statements.update', $statement->id) : route('statements.store') }}" method="POST">
|
||||
@csrf
|
||||
@if(isset($statement))
|
||||
@method('PUT')
|
||||
@endif
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-5">
|
||||
<div class="form-group">
|
||||
<label class="form-label required" for="branch_code">Branch</label>
|
||||
<select class="select tomselect @error('branch_code') is-invalid @enderror" id="branch_code" name="branch_code" required>
|
||||
<option value="">Select Branch</option>
|
||||
@foreach($branches as $branch)
|
||||
<option value="{{ $branch->code }}" {{ (old('branch_code', $statement->branch_code ?? '') == $branch->code) ? 'selected' : '' }}>
|
||||
{{ $branch->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('branch_code')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label required" for="account_number">Account Number</label>
|
||||
<input type="text" class="input form-control @error('account_number') is-invalid @enderror" id="account_number" name="account_number" value="{{ old('account_number', $statement->account_number ?? '') }}" required>
|
||||
@error('account_number')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label required" for="start_date">Start Date</label>
|
||||
|
||||
<input class="input @error('period_from') border-danger bg-danger-light @enderror"
|
||||
type="month"
|
||||
name="period_from"
|
||||
value="{{ $statement->period_from ?? old('period_from') }}"
|
||||
max="{{ date('Y-m', strtotime('-1 month')) }}">
|
||||
@error('period_from')
|
||||
<em class="alert text-danger text-sm">{{ $message }}</em>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label required" for="end_date">End Date</label>
|
||||
<input class="input @error('period_to') border-danger bg-danger-light @enderror"
|
||||
type="month"
|
||||
name="period_to"
|
||||
value="{{ $statement->period_to ?? old('period_to') }}"
|
||||
max="{{ date('Y-m', strtotime('-1 month')) }}">
|
||||
@error('period_to')
|
||||
<em class="alert text-danger text-sm">{{ $message }}</em>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-5 text-end">
|
||||
<button type="reset" class="btn btn-light me-3">Reset</button>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="ki-outline ki-check fs-2"></i> Submit
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid mt-5">
|
||||
<div class="card card-grid min-w-full" data-datatable="false" data-datatable-page-size="10" data-datatable-state-save="false" id="statement-table" data-api-url="{{ route('statements.datatables') }}">
|
||||
<div class="card-header py-5 flex-wrap">
|
||||
<h3 class="card-title">
|
||||
Daftar Statement Request
|
||||
</h3>
|
||||
<div class="flex flex-wrap gap-2 lg:gap-5">
|
||||
<div class="flex">
|
||||
<label class="input input-sm"> <i class="ki-filled ki-magnifier"> </i>
|
||||
<input placeholder="Search Statement" id="search" type="text" value="">
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="scrollable-x-auto">
|
||||
<table class="table table-auto table-border align-middle text-gray-700 font-medium text-sm" data-datatable-table="true">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="w-14">
|
||||
<input class="checkbox checkbox-sm" data-datatable-check="true" type="checkbox"/>
|
||||
</th>
|
||||
<th class="min-w-[100px]" data-datatable-column="id">
|
||||
<span class="sort"> <span class="sort-label"> ID </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[150px]" data-datatable-column="branch_name">
|
||||
<span class="sort"> <span class="sort-label"> Branch </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[150px]" data-datatable-column="account_number">
|
||||
<span class="sort"> <span class="sort-label"> Account Number </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[150px]" data-datatable-column="period">
|
||||
<span class="sort"> <span class="sort-label"> Period </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[150px]" data-datatable-column="authorization_status">
|
||||
<span class="sort"> <span class="sort-label"> Status </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[150px]" data-datatable-column="is_available">
|
||||
<span class="sort"> <span class="sort-label"> Available </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[150px]" data-datatable-column="is_downloaded">
|
||||
<span class="sort"> <span class="sort-label"> Downloaded </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[180px]" data-datatable-column="created_at">
|
||||
<span class="sort"> <span class="sort-label"> Created At </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[50px] text-center" data-datatable-column="actions">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
<div class="card-footer justify-center md:justify-between flex-col md:flex-row gap-3 text-gray-600 text-2sm font-medium">
|
||||
<div class="flex items-center gap-2">
|
||||
Show
|
||||
<select class="select select-sm w-16" data-datatable-size="true" name="perpage"> </select> per page
|
||||
</div>
|
||||
<div class="flex items-center gap-4">
|
||||
<span data-datatable-info="true"> </span>
|
||||
<div class="pagination" data-datatable-pagination="true">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<script type="text/javascript">
|
||||
function deleteData(data) {
|
||||
Swal.fire({
|
||||
title: 'Are you sure?',
|
||||
text: "You won't be able to revert this!",
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#3085d6',
|
||||
cancelButtonColor: '#d33',
|
||||
confirmButtonText: 'Yes, delete it!'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
$.ajaxSetup({
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||
}
|
||||
});
|
||||
|
||||
$.ajax(`webstatement/statements/${data}`, {
|
||||
type: 'DELETE'
|
||||
}).then((response) => {
|
||||
swal.fire('Deleted!', 'Statement request has been deleted.', 'success').then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
}).catch((error) => {
|
||||
console.error('Error:', error);
|
||||
Swal.fire('Error!', 'An error occurred while deleting the record.', 'error');
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="module">
|
||||
const element = document.querySelector('#statement-table');
|
||||
const searchInput = document.getElementById('search');
|
||||
|
||||
const apiUrl = element.getAttribute('data-api-url');
|
||||
const dataTableOptions = {
|
||||
apiEndpoint: apiUrl,
|
||||
pageSize: 10,
|
||||
columns: {
|
||||
select: {
|
||||
render: (item, data, context) => {
|
||||
const checkbox = document.createElement('input');
|
||||
checkbox.className = 'checkbox checkbox-sm';
|
||||
checkbox.type = 'checkbox';
|
||||
checkbox.value = data.id.toString();
|
||||
checkbox.setAttribute('data-datatable-row-check', 'true');
|
||||
return checkbox.outerHTML.trim();
|
||||
},
|
||||
},
|
||||
id: {
|
||||
title: 'ID',
|
||||
},
|
||||
branch_name: {
|
||||
title: 'Branch',
|
||||
},
|
||||
account_number: {
|
||||
title: 'Account Number',
|
||||
},
|
||||
period: {
|
||||
title: 'Period',
|
||||
},
|
||||
authorization_status: {
|
||||
title: 'Status',
|
||||
render: (item, data) => {
|
||||
let statusClass = 'badge badge-light-primary';
|
||||
|
||||
if (data.authorization_status === 'approved') {
|
||||
statusClass = 'badge badge-light-success';
|
||||
} else if (data.authorization_status === 'rejected') {
|
||||
statusClass = 'badge badge-light-danger';
|
||||
} else if (data.authorization_status === 'pending') {
|
||||
statusClass = 'badge badge-light-warning';
|
||||
}
|
||||
|
||||
return `<span class="${statusClass}">${data.authorization_status}</span>`;
|
||||
},
|
||||
},
|
||||
is_available: {
|
||||
title: 'Available',
|
||||
render: (item, data) => {
|
||||
let statusClass = data.is_available ? 'badge badge-light-success' : 'badge badge-light-danger';
|
||||
let statusText = data.is_available ? 'Yes' : 'No';
|
||||
return `<span class="${statusClass}">${statusText}</span>`;
|
||||
},
|
||||
},
|
||||
is_downloaded: {
|
||||
title: 'Downloaded',
|
||||
render: (item, data) => {
|
||||
let statusClass = data.is_downloaded ? 'badge badge-light-success' : 'badge badge-light-danger';
|
||||
let statusText = data.is_downloaded ? 'Yes' : 'No';
|
||||
let downloadInfo = data.is_downloaded && data.downloaded_at ?
|
||||
`<div class="text-muted text-xs mt-1">${new Date(data.downloaded_at).toLocaleString()}</div>` : '';
|
||||
return `<span class="${statusClass}">${statusText}</span>${downloadInfo}`;
|
||||
},
|
||||
},
|
||||
created_at: {
|
||||
title: 'Created At',
|
||||
render: (item, data) => {
|
||||
return data.created_at ? new Date(data.created_at).toLocaleString() : '';
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
title: 'Actions',
|
||||
render: (item, data) => {
|
||||
let buttons = `<div class="flex flex-nowrap justify-center">
|
||||
<a class="btn btn-sm btn-icon btn-clear btn-info" href="statements/${data.id}">
|
||||
<i class="ki-outline ki-eye"></i>
|
||||
</a>`;
|
||||
|
||||
// Only show edit button if status is pending
|
||||
if (data.authorization_status === 'pending') {
|
||||
buttons += `<a class="btn btn-sm btn-icon btn-clear btn-primary" href="statements/${data.id}/edit">
|
||||
<i class="ki-outline ki-notepad-edit"></i>
|
||||
</a>`;
|
||||
}
|
||||
|
||||
// Show download button if statement is approved and available but not downloaded
|
||||
if (data.authorization_status === 'approved' && data.is_available && !data.is_downloaded) {
|
||||
buttons += `<a class="btn btn-sm btn-icon btn-clear btn-success" href="statements/${data.id}/download">
|
||||
<i class="ki-outline ki-document-download"></i>
|
||||
</a>`;
|
||||
}
|
||||
|
||||
// Only show delete button if status is pending
|
||||
if (data.authorization_status === 'pending') {
|
||||
buttons += `<a onclick="deleteData(${data.id})" class="delete btn btn-sm btn-icon btn-clear btn-danger">
|
||||
<i class="ki-outline ki-trash"></i>
|
||||
</a>`;
|
||||
}
|
||||
|
||||
buttons += `</div>`;
|
||||
return buttons;
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let dataTable = new KTDataTable(element, dataTableOptions);
|
||||
// Custom search functionality
|
||||
searchInput.addEventListener('input', function () {
|
||||
const searchValue = this.value.trim();
|
||||
dataTable.search(searchValue, true);
|
||||
});
|
||||
|
||||
// Handle the "select all" checkbox
|
||||
const selectAllCheckbox = document.querySelector('input[data-datatable-check="true"]');
|
||||
if (selectAllCheckbox) {
|
||||
selectAllCheckbox.addEventListener('change', function() {
|
||||
const isChecked = this.checked;
|
||||
const rowCheckboxes = document.querySelectorAll('input[data-datatable-row-check="true"]');
|
||||
|
||||
rowCheckboxes.forEach(checkbox => {
|
||||
checkbox.checked = isChecked;
|
||||
});
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Validate that end date is after start date
|
||||
const startDateInput = document.getElementById('start_date');
|
||||
const endDateInput = document.getElementById('end_date');
|
||||
|
||||
function validateDates() {
|
||||
const startDate = new Date(startDateInput.value);
|
||||
const endDate = new Date(endDateInput.value);
|
||||
|
||||
if (startDate > endDate) {
|
||||
endDateInput.setCustomValidity('End date must be after start date');
|
||||
} else {
|
||||
endDateInput.setCustomValidity('');
|
||||
}
|
||||
}
|
||||
|
||||
startDateInput.addEventListener('change', validateDates);
|
||||
endDateInput.addEventListener('change', validateDates);
|
||||
|
||||
// Set max date for date inputs to today
|
||||
const today = new Date().toISOString().split('T')[0];
|
||||
startDateInput.setAttribute('max', today);
|
||||
endDateInput.setAttribute('max', today);
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
@@ -109,3 +109,8 @@
|
||||
$trail->parent('periode-statements.index');
|
||||
$trail->push('View Periode Statement', route('periode-statements.show', $data));
|
||||
});
|
||||
|
||||
Breadcrumbs::for('statements.index', function (BreadcrumbTrail $trail) {
|
||||
$trail->parent('home');
|
||||
$trail->push('Print Stetement', route('statements.index'));
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\Webstatement\Http\Controllers\PeriodeStatementController;
|
||||
use Modules\Webstatement\Http\Controllers\PrintStatementController;
|
||||
use Modules\Webstatement\Http\Controllers\SyncLogsController;
|
||||
use Modules\Webstatement\Http\Controllers\JenisKartuController;
|
||||
use Modules\Webstatement\Http\Controllers\KartuAtmController;
|
||||
@@ -78,7 +79,13 @@ Route::middleware(['auth'])->group(function () {
|
||||
|
||||
Route::resource('periode-statements', PeriodeStatementController::class);
|
||||
|
||||
Route::group(['prefix' => 'statements', 'as' => 'statements.', 'middleware' => ['auth']], function () {
|
||||
Route::get('/datatables', [PrintStatementController::class, 'dataForDatatables'])->name('datatables');
|
||||
Route::get('/{statement}/download', [PrintStatementController::class, 'download'])->name('download');
|
||||
Route::post('/{statement}/authorize', [PrintStatementController::class, 'authorize'])->name('authorize');
|
||||
});
|
||||
|
||||
Route::resource('statements', PrintStatementController::class);
|
||||
});
|
||||
|
||||
Route::get('migrasi', [MigrasiController::class, 'index'])->name('migrasi.index');
|
||||
|
||||
Reference in New Issue
Block a user