card type functionality works
This commit is contained in:
parent
18d2e2b78b
commit
41b7cd37c0
|
@ -0,0 +1,414 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class CardTypeController extends Controller
|
||||
{
|
||||
protected $apiBaseUrl = 'http://192.168.100.6:8081/api/cms';
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$user = Session::get('user');
|
||||
$accessToken = $user['access_token'] ?? null;
|
||||
|
||||
if (!$accessToken) {
|
||||
Log::info('No access token found, redirecting to login from card-types');
|
||||
return redirect()->route('login')->with('error', 'Please log in to view card types.');
|
||||
}
|
||||
|
||||
$page = $request->input('page', 1);
|
||||
$pageSize = 5;
|
||||
$search = $request->input('_search', null);
|
||||
|
||||
$response = Http::withHeaders([
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $accessToken,
|
||||
])->get("{$this->apiBaseUrl}/cardType", [
|
||||
'page' => $page,
|
||||
'page_size' => $pageSize,
|
||||
'_search' => $search,
|
||||
]);
|
||||
|
||||
if ($response->status() === 401 || $response->status() === 403) {
|
||||
Log::warning('Unauthorized or Forbidden API response: ', $response->json());
|
||||
return redirect()->route('login')->with('error', 'Your session has expired. Please log in again.');
|
||||
}
|
||||
|
||||
$json = $response->json();
|
||||
|
||||
if ($response->successful() && isset($json['data']) && is_array($json['data'])) {
|
||||
$cardTypes = array_map(function ($item) {
|
||||
return [
|
||||
'id' => $item['cardtype_uuid'] ?? null,
|
||||
'cardCode' => $item['code'] ?? '',
|
||||
'cardTypeDescription' => $item['description'] ?? '',
|
||||
'cardTypeShortDescription' => $item['short_description'] ?? '',
|
||||
'cardTypeImage' => $item['image'] ?? '',
|
||||
'virtualCardFontColor' => $item['virtual_card_font_color'] ?? '',
|
||||
'cardTypeCoverImage' => $item['bg_image'] ?? '',
|
||||
'idNumberRequired' => $item['id_number'] ? 'Yes' : 'No',
|
||||
'idNumberDescription' => $item['id_number_description'] ?? '',
|
||||
'termsAndConditions' => $item['terms_and_conditions'] ?? '',
|
||||
'faqs' => $item['faqs'] ?? '',
|
||||
'type' => $item['type'] ?? '',
|
||||
];
|
||||
}, $json['data']);
|
||||
|
||||
$total = $json['meta']['total'] ?? count($cardTypes);
|
||||
$lastPage = $json['meta']['last_page'] ?? ceil($total / $pageSize);
|
||||
} else {
|
||||
Log::warning('No card types data found or invalid API response: ', $json);
|
||||
$cardTypes = [];
|
||||
$total = 0;
|
||||
$lastPage = 1;
|
||||
}
|
||||
|
||||
return view('pages.about us.card-types', [
|
||||
'cardTypes' => $cardTypes,
|
||||
'currentPage' => $page,
|
||||
'lastPage' => $lastPage,
|
||||
'total' => $total,
|
||||
'search' => $search,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error fetching card types: ' . $e->getMessage());
|
||||
return view('pages.about us.card-types', [
|
||||
'cardTypes' => [],
|
||||
'currentPage' => 1,
|
||||
'lastPage' => 1,
|
||||
'total' => 0,
|
||||
'search' => $search,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
try {
|
||||
$user = Session::get('user');
|
||||
$accessToken = $user['access_token'] ?? null;
|
||||
|
||||
if (!$accessToken) {
|
||||
return redirect()->route('login')->with('error', 'Please log in to add a card type.');
|
||||
}
|
||||
|
||||
return view('pages.add-card-types', [
|
||||
'fontColors' => ['White', 'Black'],
|
||||
'idNumberOptions' => ['Yes', 'No'],
|
||||
'cardTypes' => ['Visa', 'MasterCard', 'Amex'],
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error loading create card type page: ' . $e->getMessage());
|
||||
return view('pages.add-card-types', [
|
||||
'fontColors' => ['White', 'Black'],
|
||||
'idNumberOptions' => ['Yes', 'No'],
|
||||
'cardTypes' => ['Visa', 'MasterCard', 'Amex'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
try {
|
||||
$user = Session::get('user');
|
||||
$accessToken = $user['access_token'] ?? null;
|
||||
|
||||
if (!$accessToken) {
|
||||
return redirect()->route('login')->with('error', 'Please log in to add a card type.');
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'code' => 'required|string|max:50',
|
||||
'type' => 'required|in:Visa,MasterCard,Amex',
|
||||
'description' => 'required|string|max:255',
|
||||
'short_description' => 'required|string|max:100',
|
||||
'image' => 'nullable|file|mimes:jpeg,png,jpg,gif|max:2048',
|
||||
'bg_image' => 'nullable|file|mimes:jpeg,png,jpg,gif|max:2048',
|
||||
'virtual_card_font_color' => 'required|in:White,Black',
|
||||
'id_number' => 'required|in:Yes,No',
|
||||
'id_number_description' => 'nullable|string|max:255',
|
||||
'terms_and_conditions' => 'required|string',
|
||||
'faqs' => 'required|string',
|
||||
]);
|
||||
|
||||
$payload = [
|
||||
'code' => $request->input('code'),
|
||||
'type' => $request->input('type'),
|
||||
'description' => $request->input('description'),
|
||||
'short_description' => $request->input('short_description'),
|
||||
'virtual_card_font_color' => $request->input('virtual_card_font_color'),
|
||||
'id_number' => $request->input('id_number') === 'Yes' ? 1 : 0,
|
||||
'id_number_description' => $request->input('id_number_description', ''),
|
||||
'terms_and_conditions' => $request->input('terms_and_conditions'),
|
||||
'faqs' => $request->input('faqs'),
|
||||
];
|
||||
|
||||
$client = Http::withHeaders([
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $accessToken,
|
||||
]);
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
$image = $request->file('image');
|
||||
$client = $client->attach('image', file_get_contents($image->getPathname()), $image->getClientOriginalName());
|
||||
}
|
||||
|
||||
if ($request->hasFile('bg_image')) {
|
||||
$bgImage = $request->file('bg_image');
|
||||
$client = $client->attach('bg_image', file_get_contents($bgImage->getPathname()), $bgImage->getClientOriginalName());
|
||||
}
|
||||
|
||||
$response = $client->post("{$this->apiBaseUrl}/cardType", $payload);
|
||||
|
||||
$json = $response->json();
|
||||
Log::info('API response for creating card type: ', $json);
|
||||
|
||||
if ($response->successful()) {
|
||||
Log::info('Card type created successfully: ', $json);
|
||||
return redirect()->route('card-types')->with('success', $json['message'] ?? 'Card type added successfully.');
|
||||
} else {
|
||||
$errorMessage = $json['message'] ?? 'Failed to add card type. Please try again.';
|
||||
if (isset($json['errors'])) {
|
||||
$errorMessage .= ' Errors: ' . json_encode($json['errors']);
|
||||
}
|
||||
throw new \Exception($errorMessage);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error creating card type: ' . $e->getMessage());
|
||||
return redirect()->back()->withErrors(['error' => 'An error occurred while adding the card type: ' . $e->getMessage()])->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
public function show($uuid)
|
||||
{
|
||||
try {
|
||||
$user = Session::get('user');
|
||||
$accessToken = $user['access_token'] ?? null;
|
||||
|
||||
if (!$accessToken) {
|
||||
return redirect()->route('login')->with('error', 'Please log in to view a card type.');
|
||||
}
|
||||
|
||||
$response = Http::withHeaders([
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $accessToken,
|
||||
])->get("{$this->apiBaseUrl}/cardType/{$uuid}");
|
||||
|
||||
$json = $response->json();
|
||||
|
||||
if ($response->successful() && isset($json['data'])) {
|
||||
$cardType = [
|
||||
'id' => $json['data']['cardtype_uuid'] ?? null,
|
||||
'cardCode' => $json['data']['code'] ?? '',
|
||||
'cardTypeDescription' => $json['data']['description'] ?? '',
|
||||
'cardTypeShortDescription' => $json['data']['short_description'] ?? '',
|
||||
'cardTypeImage' => $json['data']['image'] ?? '',
|
||||
'virtualCardFontColor' => $json['data']['virtual_card_font_color'] ?? '',
|
||||
'cardTypeCoverImage' => $json['data']['bg_image'] ?? '',
|
||||
'idNumberRequired' => $json['data']['id_number'] ? 'Yes' : 'No',
|
||||
'idNumberDescription' => $json['data']['id_number_description'] ?? '',
|
||||
'termsAndConditions' => $json['data']['terms_and_conditions'] ?? '',
|
||||
'faqs' => $json['data']['faqs'] ?? '',
|
||||
'type' => $json['data']['type'] ?? '',
|
||||
];
|
||||
return view('pages.view-card-types', ['cardType' => $cardType]);
|
||||
} else {
|
||||
Log::warning('No card type found or invalid API response: ', $json);
|
||||
return redirect()->back()->with('error', 'Card type not found.');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error fetching card type for view: ' . $e->getMessage());
|
||||
return redirect()->back()->with('error', 'An error occurred while loading the card type.');
|
||||
}
|
||||
}
|
||||
|
||||
public function edit($uuid)
|
||||
{
|
||||
try {
|
||||
$user = Session::get('user');
|
||||
$accessToken = $user['access_token'] ?? null;
|
||||
|
||||
if (!$accessToken) {
|
||||
return redirect()->route('login')->with('error', 'Please log in to edit a card type.');
|
||||
}
|
||||
|
||||
$response = Http::withHeaders([
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $accessToken,
|
||||
])->get("{$this->apiBaseUrl}/cardType/{$uuid}");
|
||||
|
||||
$json = $response->json();
|
||||
|
||||
if ($response->successful() && isset($json['data'])) {
|
||||
$cardType = [
|
||||
'id' => $json['data']['cardtype_uuid'] ?? null,
|
||||
'cardCode' => $json['data']['code'] ?? '',
|
||||
'cardTypeDescription' => $json['data']['description'] ?? '',
|
||||
'cardTypeShortDescription' => $json['data']['short_description'] ?? '',
|
||||
'cardTypeImage' => $json['data']['image'] ?? '',
|
||||
'virtualCardFontColor' => $json['data']['virtual_card_font_color'] ?? '',
|
||||
'cardTypeCoverImage' => $json['data']['bg_image'] ?? '',
|
||||
'idNumberRequired' => $json['data']['id_number'] ? 'Yes' : 'No',
|
||||
'idNumberDescription' => $json['data']['id_number_description'] ?? '',
|
||||
'termsAndConditions' => $json['data']['terms_and_conditions'] ?? '',
|
||||
'faqs' => $json['data']['faqs'] ?? '',
|
||||
'type' => $json['data']['type'] ?? '',
|
||||
];
|
||||
return view('pages.edit-card-types', [
|
||||
'cardType' => $cardType,
|
||||
'fontColors' => ['White', 'Black'],
|
||||
'idNumberOptions' => ['Yes', 'No'],
|
||||
'cardTypes' => ['Visa', 'MasterCard', 'Amex'],
|
||||
]);
|
||||
} else {
|
||||
Log::warning('No card type found or invalid API response: ', $json);
|
||||
return redirect()->back()->with('error', 'Card type not found.');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error fetching card type for edit: ' . $e->getMessage());
|
||||
return redirect()->back()->with('error', 'An error occurred while loading the card type.');
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request, $uuid)
|
||||
{
|
||||
try {
|
||||
$user = Session::get('user');
|
||||
$accessToken = $user['access_token'] ?? null;
|
||||
|
||||
if (!$accessToken) {
|
||||
return redirect()->route('login')->with('error', 'Please log in to update a card type.');
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'code' => 'required|string|max:50',
|
||||
'type' => 'required|in:Visa,MasterCard,Amex',
|
||||
'description' => 'required|string|max:255',
|
||||
'short_description' => 'required|string|max:100',
|
||||
'image' => 'nullable|file|mimes:jpeg,png,jpg,gif|max:2048',
|
||||
'bg_image' => 'nullable|file|mimes:jpeg,png,jpg,gif|max:2048',
|
||||
'virtual_card_font_color' => 'required|in:White,Black',
|
||||
'id_number' => 'required|in:Yes,No',
|
||||
'id_number_description' => 'nullable|string|max:255',
|
||||
'terms_and_conditions' => 'required|string',
|
||||
'faqs' => 'required|string',
|
||||
]);
|
||||
|
||||
$payload = [
|
||||
'code' => $request->input('code'),
|
||||
'type' => $request->input('type'),
|
||||
'description' => $request->input('description'),
|
||||
'short_description' => $request->input('short_description'),
|
||||
'virtual_card_font_color' => $request->input('virtual_card_font_color'),
|
||||
'id_number' => $request->input('id_number') === 'Yes' ? 1 : 0,
|
||||
'id_number_description' => $request->input('id_number_description', ''),
|
||||
'terms_and_conditions' => $request->input('terms_and_conditions'),
|
||||
'faqs' => $request->input('faqs'),
|
||||
];
|
||||
|
||||
$client = Http::withHeaders([
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $accessToken,
|
||||
]);
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
$image = $request->file('image');
|
||||
$client = $client->attach('image', file_get_contents($image->getPathname()), $image->getClientOriginalName());
|
||||
}
|
||||
|
||||
if ($request->hasFile('bg_image')) {
|
||||
$bgImage = $request->file('bg_image');
|
||||
$client = $client->attach('bg_image', file_get_contents($bgImage->getPathname()), $bgImage->getClientOriginalName());
|
||||
}
|
||||
|
||||
$response = $client->post("{$this->apiBaseUrl}/cardTypeUpdate/{$uuid}", $payload);
|
||||
|
||||
$json = $response->json();
|
||||
Log::info('API response for updating card type: ', $json);
|
||||
|
||||
if ($response->successful()) {
|
||||
Log::info('Card type updated successfully: ', $json);
|
||||
return redirect()->route('card-types')->with('success', $json['message'] ?? 'Card type updated successfully.');
|
||||
} else {
|
||||
$errorMessage = $json['message'] ?? 'Failed to update card type. Please try again.';
|
||||
if (isset($json['errors'])) {
|
||||
$errorMessage .= ' Errors: ' . json_encode($json['errors']);
|
||||
}
|
||||
return redirect()->back()->withErrors(['error' => $errorMessage]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error updating card type: ' . $e->getMessage());
|
||||
return redirect()->back()->withErrors(['error' => 'An error occurred while updating the card type: ' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy($uuid)
|
||||
{
|
||||
try {
|
||||
$user = Session::get('user');
|
||||
$accessToken = $user['access_token'] ?? null;
|
||||
|
||||
if (!$accessToken) {
|
||||
return redirect()->route('login')->with('error', 'Please log in to delete a card type.');
|
||||
}
|
||||
|
||||
$response = Http::withHeaders([
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $accessToken,
|
||||
])->delete("{$this->apiBaseUrl}/cardType/{$uuid}");
|
||||
|
||||
if ($response->successful()) {
|
||||
Log::info('Card type deleted successfully: ' . $uuid);
|
||||
return redirect()->route('card-types')->with('success', 'Card type deleted successfully.');
|
||||
} else {
|
||||
Log::warning('Failed to delete card type: ', $response->json());
|
||||
return redirect()->back()->with('error', $response->json()['message'] ?? 'Failed to delete card type. Please try again.');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error deleting card type: ' . $e->getMessage());
|
||||
return redirect()->back()->with('error', 'An error occurred while deleting the card type.');
|
||||
}
|
||||
}
|
||||
|
||||
public function batchDelete(Request $request)
|
||||
{
|
||||
try {
|
||||
$user = Session::get('user');
|
||||
$accessToken = $user['access_token'] ?? null;
|
||||
|
||||
if (!$accessToken) {
|
||||
return redirect()->route('login')->with('error', 'Please log in to delete card types.');
|
||||
}
|
||||
|
||||
$uuids = $request->input('cardtype_uuid', []);
|
||||
|
||||
if (empty($uuids)) {
|
||||
return redirect()->back()->with('error', 'No card types selected for deletion.');
|
||||
}
|
||||
|
||||
$response = Http::withHeaders([
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $accessToken,
|
||||
])->delete("{$this->apiBaseUrl}/cardTypeBatchDelete", [
|
||||
'cardtype_uuid' => $uuids,
|
||||
]);
|
||||
|
||||
if ($response->successful()) {
|
||||
Log::info('Card types batch deleted successfully: ', $uuids);
|
||||
return redirect()->route('card-types')->with('success', 'Selected card types deleted successfully.');
|
||||
} else {
|
||||
Log::warning('Failed to batch delete card types: ', $response->json());
|
||||
return redirect()->back()->with('error', $response->json()['message'] ?? 'Failed to delete card types. Please try again.');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error batch deleting card types: ' . $e->getMessage());
|
||||
return redirect()->back()->with('error', 'An error occurred while deleting the card types.');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,166 @@
|
|||
@props([
|
||||
'pageTitle' => '',
|
||||
'data' => [],
|
||||
'columns' => [],
|
||||
'actions' => [],
|
||||
'showAddButton' => false,
|
||||
'addButtonUrl' => '#',
|
||||
'currentPage' => 1,
|
||||
'lastPage' => 1,
|
||||
'total' => 0,
|
||||
])
|
||||
|
||||
<div class="card-header border-0 bg-transparent">
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<h5 class="mb-0 fw-bold text-dark">{{ $pageTitle }}</h5>
|
||||
@if ($showAddButton)
|
||||
<a href="{{ $addButtonUrl }}" class="btn btn-primary btn-sm px-3">
|
||||
<i class="fa-solid fa-plus me-1"></i> Add {{ $pageTitle }}
|
||||
</a>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<!-- Search -->
|
||||
<div class="row mb-3">
|
||||
<div class="col-12 col-md-6">
|
||||
<div class="input-group input-group-sm">
|
||||
<span class="input-group-text bg-light border-end-0">
|
||||
<i class="fa-solid fa-magnifying-glass text-muted"></i>
|
||||
</span>
|
||||
<input type="text" class="form-control border-start-0" placeholder="Search..." id="searchInput">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Table -->
|
||||
<div class="table-container">
|
||||
<table class="table table-hover align-middle">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
@foreach ($columns as $index => $column)
|
||||
<th class="{{ $column['sortable'] ? 'sortable' : '' }}" data-column="{{ $index }}">
|
||||
{{ $column['name'] }}
|
||||
@if ($column['sortable'])
|
||||
<i class="fa-solid fa-sort"></i>
|
||||
@endif
|
||||
</th>
|
||||
@endforeach
|
||||
@if (!empty($actions))
|
||||
<th class="text-center" style="width: 120px;">Action</th>
|
||||
@endif
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tableBody"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
<div class="d-flex justify-content-end mt-4">
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination pagination-sm" id="pagination"></ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.table-container { overflow-x: auto; }
|
||||
.table th, .table td { white-space: nowrap; }
|
||||
.sortable { cursor: pointer; }
|
||||
.sortable:hover { background-color: #f8f9fa; }
|
||||
.sortable i { margin-left: 5px; color: #6c757d; }
|
||||
.view-btn { border-color: #0d6efd; color: #0d6efd; }
|
||||
.view-btn:hover { background-color: #0d6efd; color: #fff; }
|
||||
.edit-btn { border-color: #ffc107; color: #ffc107; }
|
||||
.edit-btn:hover { background-color: #ffc107; color: #fff; }
|
||||
.delete-btn { border-color: #dc3545; color: #dc3545; }
|
||||
.delete-btn:hover { background-color: #dc3545; color: #fff; }
|
||||
</style>
|
||||
|
||||
<script>
|
||||
const tableConfig = {
|
||||
data: @json($data),
|
||||
columns: @json($columns),
|
||||
actions: @json($actions),
|
||||
pageTitle: @json($pageTitle),
|
||||
csrfToken: '{{ csrf_token() }}',
|
||||
currentPage: {{ $currentPage }},
|
||||
lastPage: {{ $lastPage }},
|
||||
total: {{ $total }},
|
||||
};
|
||||
|
||||
const rowsPerPage = 5;
|
||||
let currentPage = tableConfig.currentPage;
|
||||
let filteredRows = [...tableConfig.data];
|
||||
|
||||
function renderTable() {
|
||||
const tableBody = document.getElementById('tableBody');
|
||||
tableBody.innerHTML = '';
|
||||
|
||||
const startIndex = (currentPage - 1) * rowsPerPage;
|
||||
const endIndex = startIndex + rowsPerPage;
|
||||
const paginatedRows = filteredRows.slice(startIndex, endIndex);
|
||||
|
||||
paginatedRows.forEach(row => {
|
||||
let rowHtml = `<tr>`;
|
||||
tableConfig.columns.forEach(col => {
|
||||
rowHtml += `<td>${row[col.key] || ''}</td>`;
|
||||
});
|
||||
if (tableConfig.actions.length > 0) {
|
||||
rowHtml += `<td class="text-center">`;
|
||||
const routeBase = tableConfig.pageTitle.toLowerCase().replace(/\s+/g, '-');
|
||||
tableConfig.actions.forEach(action => {
|
||||
if (action === 'view') {
|
||||
rowHtml += `<a href="/${routeBase}/${row.id}" class="btn btn-sm view-btn me-1" title="View"><i class="fa-solid fa-eye"></i></a>`;
|
||||
} else if (action === 'edit') {
|
||||
rowHtml += `<a href="/${routeBase}/${row.id}/edit" class="btn btn-sm edit-btn me-1" title="Edit"><i class="fa-solid fa-pen"></i></a>`;
|
||||
} else if (action === 'delete') {
|
||||
rowHtml += `<a href="/${routeBase}/${row.id}" class="btn btn-sm delete-btn" title="Delete" onclick="event.preventDefault(); if(confirm('Are you sure you want to delete this ${tableConfig.pageTitle.toLowerCase()}?')) { document.getElementById('delete-form-${row.id}').submit(); }"><i class="fa-solid fa-trash"></i></a>
|
||||
<form id="delete-form-${row.id}" action="/${routeBase}/${row.id}" method="POST" style="display: none;">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
</form>`;
|
||||
}
|
||||
});
|
||||
rowHtml += `</td>`;
|
||||
}
|
||||
rowHtml += `</tr>`;
|
||||
tableBody.innerHTML += rowHtml;
|
||||
});
|
||||
}
|
||||
|
||||
function renderPagination() {
|
||||
const pagination = document.getElementById('pagination');
|
||||
pagination.innerHTML = '';
|
||||
|
||||
const totalPages = Math.ceil(filteredRows.length / rowsPerPage);
|
||||
const routeBase = tableConfig.pageTitle.toLowerCase().replace(/\s+/g, '-');
|
||||
|
||||
pagination.innerHTML += `<li class="page-item ${currentPage === 1 ? 'disabled' : ''}">
|
||||
<a class="page-link" href="/${routeBase}?page=${currentPage - 1}" aria-label="Previous">«</a>
|
||||
</li>`;
|
||||
for (let i = 1; i <= totalPages; i++) {
|
||||
pagination.innerHTML += `<li class="page-item ${currentPage === i ? 'active' : ''}">
|
||||
<a class="page-link" href="/${routeBase}?page=${i}">${i}</a>
|
||||
</li>`;
|
||||
}
|
||||
pagination.innerHTML += `<li class="page-item ${currentPage === totalPages ? 'disabled' : ''}">
|
||||
<a class="page-link" href="/${routeBase}?page=${currentPage + 1}" aria-label="Next">»</a>
|
||||
</li>`;
|
||||
}
|
||||
|
||||
document.getElementById('searchInput')?.addEventListener('input', function() {
|
||||
const searchTerm = this.value.toLowerCase();
|
||||
filteredRows = tableConfig.data.filter(row =>
|
||||
Object.values(row).some(value =>
|
||||
value && value.toString().toLowerCase().includes(searchTerm)
|
||||
)
|
||||
);
|
||||
currentPage = 1;
|
||||
renderTable();
|
||||
renderPagination();
|
||||
});
|
||||
|
||||
renderTable();
|
||||
renderPagination();
|
||||
</script>
|
|
@ -3,123 +3,53 @@
|
|||
@section('page_title', 'Card Types')
|
||||
|
||||
@section('content')
|
||||
@php
|
||||
$cardTypes = [
|
||||
[
|
||||
'id' => 1,
|
||||
'cardCode' => 'VISA01',
|
||||
'cardTypeDescription' => 'Visa Platinum Card',
|
||||
'cardTypeShortDescription' => 'Premium Visa card',
|
||||
'cardTypeImage' => '',
|
||||
'virtualCardFontColor' => 'White',
|
||||
'cardTypeCoverImage' => '',
|
||||
'idNumberRequired' => 'Yes',
|
||||
'idNumberDescription' => 'Government-issued ID required',
|
||||
'termsAndConditions' => 'Valid for 5 years. Annual fee applies.',
|
||||
'faqs' => 'Q: What is the credit limit? A: Up to $10,000.'
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'cardCode' => 'MC02',
|
||||
'cardTypeDescription' => 'MasterCard Gold',
|
||||
'cardTypeShortDescription' => 'Gold MasterCard',
|
||||
'cardTypeImage' => '',
|
||||
'virtualCardFontColor' => 'Black',
|
||||
'cardTypeCoverImage' => '',
|
||||
'idNumberRequired' => 'No',
|
||||
'idNumberDescription' => '',
|
||||
'termsAndConditions' => 'No annual fee for first year.',
|
||||
'faqs' => 'Q: Can I use it abroad? A: Yes, globally accepted.'
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'cardCode' => 'AMEX03',
|
||||
'cardTypeDescription' => 'Amex Rewards Card',
|
||||
'cardTypeShortDescription' => 'Amex Rewards',
|
||||
'cardTypeImage' => '',
|
||||
'virtualCardFontColor' => 'White',
|
||||
'cardTypeCoverImage' => '',
|
||||
'idNumberRequired' => 'Yes',
|
||||
'idNumberDescription' => 'Passport or driver’s license',
|
||||
'termsAndConditions' => 'Earn 2x points on travel.',
|
||||
'faqs' => 'Q: How to redeem points? A: Via app.'
|
||||
],
|
||||
[
|
||||
'id' => 4,
|
||||
'cardCode' => 'VISA04',
|
||||
'cardTypeDescription' => 'Visa Classic Card',
|
||||
'cardTypeShortDescription' => 'Basic Visa card',
|
||||
'cardTypeImage' => '',
|
||||
'virtualCardFontColor' => 'Black',
|
||||
'cardTypeCoverImage' => '',
|
||||
'idNumberRequired' => 'No',
|
||||
'idNumberDescription' => '',
|
||||
'termsAndConditions' => 'Standard rates apply.',
|
||||
'faqs' => 'Q: Is there a fee? A: No hidden fees.'
|
||||
],
|
||||
[
|
||||
'id' => 5,
|
||||
'cardCode' => 'MC05',
|
||||
'cardTypeDescription' => 'MasterCard Premium',
|
||||
'cardTypeShortDescription' => 'Premium MasterCard',
|
||||
'cardTypeImage' => '',
|
||||
'virtualCardFontColor' => 'White',
|
||||
'cardTypeCoverImage' => '',
|
||||
'idNumberRequired' => 'Yes',
|
||||
'idNumberDescription' => 'ID for verification',
|
||||
'termsAndConditions' => 'Free lounge access.',
|
||||
'faqs' => 'Q: Lounge access? A: At major airports.'
|
||||
],
|
||||
[
|
||||
'id' => 6,
|
||||
'cardCode' => 'AMEX06',
|
||||
'cardTypeDescription' => 'Amex Business Card',
|
||||
'cardTypeShortDescription' => 'Business Amex',
|
||||
'cardTypeImage' => '',
|
||||
'virtualCardFontColor' => 'Black',
|
||||
'cardTypeCoverImage' => '',
|
||||
'idNumberRequired' => 'No',
|
||||
'idNumberDescription' => '',
|
||||
'termsAndConditions' => 'For business expenses.',
|
||||
'faqs' => 'Q: Tax benefits? A: Consult accountant.'
|
||||
]
|
||||
];
|
||||
@endphp
|
||||
|
||||
@include('components.table-component', [
|
||||
<div id="card-types-table">
|
||||
@if (session('success'))
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
{{ session('success') }}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
@endif
|
||||
@if (session('error'))
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
{{ session('error') }}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
@endif
|
||||
@include('components.card-type-component', [
|
||||
'pageTitle' => 'Card Types',
|
||||
'data' => $cardTypes,
|
||||
'data' => $cardTypes ?? [],
|
||||
'columns' => [
|
||||
['name' => 'Card Type Code', 'key' => 'cardCode', 'sortable' => true],
|
||||
['name' => 'Card Type Description', 'key' => 'cardTypeDescription', 'sortable' => true]
|
||||
['name' => 'Type', 'key' => 'type', 'sortable' => true],
|
||||
['name' => 'Card Type Description', 'key' => 'cardTypeDescription', 'sortable' => true],
|
||||
],
|
||||
'allFields' => [
|
||||
['name' => 'Card Code', 'key' => 'cardCode', 'type' => 'text', 'required' => true],
|
||||
['name' => 'Card Type Description', 'key' => 'cardTypeDescription', 'type' => 'text', 'required' => true],
|
||||
['name' => 'Card Type Short Description', 'key' => 'cardTypeShortDescription', 'type' => 'text', 'required' => true],
|
||||
['name' => 'Card Type Image', 'key' => 'cardTypeImage', 'type' => 'file'],
|
||||
['name' => 'Virtual Card Font Color', 'key' => 'virtualCardFontColor', 'type' => 'select', 'options' => ['White', 'Black'], 'required' => true],
|
||||
['name' => 'Card Type Cover Image', 'key' => 'cardTypeCoverImage', 'type' => 'file'],
|
||||
['name' => 'ID Number Required?', 'key' => 'idNumberRequired', 'type' => 'select', 'options' => ['Yes', 'No'], 'required' => true],
|
||||
['name' => 'ID Number Description', 'key' => 'idNumberDescription', 'type' => 'text'],
|
||||
['name' => 'Terms and Conditions', 'key' => 'termsAndConditions', 'type' => 'textarea', 'required' => true],
|
||||
['name' => 'FAQs', 'key' => 'faqs', 'type' => 'textarea', 'required' => true]
|
||||
['name' => 'Card Code', 'key' => 'code', 'type' => 'text', 'required' => true],
|
||||
['name' => 'Type', 'key' => 'type', 'type' => 'select', 'options' => ['Visa', 'MasterCard', 'Amex'], 'required' => true],
|
||||
['name' => 'Card Type Description', 'key' => 'description', 'type' => 'text', 'required' => true],
|
||||
['name' => 'Card Type Short Description', 'key' => 'short_description', 'type' => 'text', 'required' => true],
|
||||
['name' => 'Card Type Image', 'key' => 'image', 'type' => 'file'],
|
||||
['name' => 'Virtual Card Font Color', 'key' => 'virtual_card_font_color', 'type' => 'select', 'options' => ['White', 'Black'], 'required' => true],
|
||||
['name' => 'Card Type Cover Image', 'key' => 'bg_image', 'type' => 'file'],
|
||||
['name' => 'ID Number Required?', 'key' => 'id_number', 'type' => 'select', 'options' => ['Yes', 'No'], 'required' => true],
|
||||
['name' => 'ID Number Description', 'key' => 'id_number_description', 'type' => 'text'],
|
||||
['name' => 'Terms and Conditions', 'key' => 'terms_and_conditions', 'type' => 'textarea', 'required' => true],
|
||||
['name' => 'FAQs', 'key' => 'faqs', 'type' => 'textarea', 'required' => true],
|
||||
],
|
||||
'actions' => ['edit', 'view', 'delete'],
|
||||
'showAddButton' => true,
|
||||
'addButtonUrl' => '/add-card-types',
|
||||
'addButtonUrl' => route('card-types.create'),
|
||||
'showCheckboxes' => true,
|
||||
'showBatchDelete' => true,
|
||||
'showEditModal' => true,
|
||||
'showViewModal' => true
|
||||
'showViewModal' => true,
|
||||
'currentPage' => $currentPage ?? 1,
|
||||
'lastPage' => $lastPage ?? 1,
|
||||
'total' => $total ?? 0,
|
||||
])
|
||||
|
||||
<script>
|
||||
const storedCardTypes = JSON.parse(sessionStorage.getItem('cardTypes') || '[]');
|
||||
if (storedCardTypes.length > 0) {
|
||||
tableConfig.data = [...tableConfig.data, ...storedCardTypes];
|
||||
renderTable();
|
||||
renderPagination();
|
||||
}
|
||||
</script>
|
||||
<div id="no-data-message" style="display: {{ empty($cardTypes ?? []) ? 'block' : 'none' }}; text-align: center; margin-top: 20px;">
|
||||
<p>No card types found.</p>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
|
@ -3,129 +3,121 @@
|
|||
@section('page_title', 'Add Card Type')
|
||||
|
||||
@section('content')
|
||||
<div class="card-header border-0 bg-transparent py-2">
|
||||
<h5 class="mb-0 fw-bold text-dark" style="font-size: 1.25rem;">Add Card Type</h5>
|
||||
<div class="container">
|
||||
<h2>Add Card Type</h2>
|
||||
@if (session('success'))
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
{{ session('success') }}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="row justify-content-center">
|
||||
<div class="card-body p-3">
|
||||
<form id="addCardTypeForm">
|
||||
@endif
|
||||
@if ($errors->any())
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
<ul>
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<form method="POST" action="{{ route('card-types.store') }}" enctype="multipart/form-data">
|
||||
@csrf
|
||||
<div class="mb-3">
|
||||
<label for="cardCode" class="form-label">Card Code</label>
|
||||
<input type="text" class="form-control" id="cardCode" placeholder="Enter card code" required>
|
||||
<label for="code" class="form-label">Card Code *</label>
|
||||
<input type="text" class="form-control @error('code') is-invalid @enderror" id="code" name="code" value="{{ old('code') }}" required maxlength="50">
|
||||
@error('code')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="cardTypeDescription" class="form-label">Card Type Description</label>
|
||||
<input type="text" class="form-control" id="cardTypeDescription" placeholder="Enter description" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="cardTypeShortDescription" class="form-label">Card Type Short Description</label>
|
||||
<input type="text" class="form-control" id="cardTypeShortDescription" placeholder="Enter short description" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="cardTypeImage" class="form-label">Upload Card Type Image</label>
|
||||
<input type="file" class="form-control" id="cardTypeImage" accept=".jpg,.jpeg,.png">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="virtualCardFontColor" class="form-label">Virtual Card Font Color</label>
|
||||
<select class="form-select" id="virtualCardFontColor" required>
|
||||
<option value="" disabled selected>Select font color</option>
|
||||
<option value="White">White</option>
|
||||
<option value="Black">Black</option>
|
||||
<label for="type" class="form-label">Card Type *</label>
|
||||
<select class="form-select @error('type') is-invalid @enderror" id="type" name="type" required>
|
||||
<option value="" disabled {{ old('type') ? '' : 'selected' }}>Select card type</option>
|
||||
@foreach ($cardTypes as $type)
|
||||
<option value="{{ $type }}" {{ old('type') == $type ? 'selected' : '' }}>{{ $type }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('type')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="cardTypeCoverImage" class="form-label">Upload Card Type Cover Image</label>
|
||||
<input type="file" class="form-control" id="cardTypeCoverImage" accept=".jpg,.jpeg,.png">
|
||||
<label for="description" class="form-label">Card Type Description *</label>
|
||||
<input type="text" class="form-control @error('description') is-invalid @enderror" id="description" name="description" value="{{ old('description') }}" required maxlength="255">
|
||||
@error('description')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="idNumberRequired" class="form-label">ID Number Required?</label>
|
||||
<select class="form-select" id="idNumberRequired" required>
|
||||
<option value="" disabled selected>Select option</option>
|
||||
<option value="Yes">Yes</option>
|
||||
<option value="No">No</option>
|
||||
<label for="short_description" class="form-label">Card Type Short Description *</label>
|
||||
<input type="text" class="form-control @error('short_description') is-invalid @enderror" id="short_description" name="short_description" value="{{ old('short_description') }}" required maxlength="100">
|
||||
@error('short_description')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="image" class="form-label">Card Type Image</label>
|
||||
<input type="file" class="form-control @error('image') is-invalid @enderror" id="image" name="image" accept="image/*">
|
||||
@error('image')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="virtual_card_font_color" class="form-label">Virtual Card Font Color *</label>
|
||||
<select class="form-select @error('virtual_card_font_color') is-invalid @enderror" id="virtual_card_font_color" name="virtual_card_font_color" required>
|
||||
<option value="" disabled {{ old('virtual_card_font_color') ? '' : 'selected' }}>Select color</option>
|
||||
@foreach ($fontColors as $color)
|
||||
<option value="{{ $color }}" {{ old('virtual_card_font_color') == $color ? 'selected' : '' }}>{{ $color }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('virtual_card_font_color')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="idNumberDescription" class="form-label">ID Number Description</label>
|
||||
<input type="text" class="form-control" id="idNumberDescription" placeholder="Enter ID description">
|
||||
<label for="bg_image" class="form-label">Card Type Cover Image</label>
|
||||
<input type="file" class="form-control @error('bg_image') is-invalid @enderror" id="bg_image" name="bg_image" accept="image/*">
|
||||
@error('bg_image')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="termsAndConditions" class="form-label">Terms and Conditions</label>
|
||||
<textarea class="form-control" id="termsAndConditions" rows="4" placeholder="Enter terms and conditions" required></textarea>
|
||||
<label for="id_number" class="form-label">ID Number Required? *</label>
|
||||
<select class="form-select @error('id_number') is-invalid @enderror" id="id_number" name="id_number" required>
|
||||
<option value="" disabled {{ old('id_number') ? '' : 'selected' }}>Select option</option>
|
||||
@foreach ($idNumberOptions as $option)
|
||||
<option value="{{ $option }}" {{ old('id_number') == $option ? 'selected' : '' }}>{{ $option }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('id_number')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="faqs" class="form-label">FAQs</label>
|
||||
<textarea class="form-control" id="faqs" rows="4" placeholder="Enter FAQs" required></textarea>
|
||||
<label for="id_number_description" class="form-label">ID Number Description</label>
|
||||
<input type="text" class="form-control @error('id_number_description') is-invalid @enderror" id="id_number_description" name="id_number_description" value="{{ old('id_number_description') }}" maxlength="255">
|
||||
@error('id_number_description')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="d-flex justify-content-end mt-3">
|
||||
<button type="button" class="btn btn-outline-secondary me-2" style="margin-right:5px">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">Add Card Type</button>
|
||||
<div class="mb-3">
|
||||
<label for="terms_and_conditions" class="form-label">Terms and Conditions *</label>
|
||||
<textarea class="form-control @error('terms_and_conditions') is-invalid @enderror" id="terms_and_conditions" name="terms_and_conditions" rows="5" required>{{ old('terms_and_conditions') }}</textarea>
|
||||
@error('terms_and_conditions')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="faqs" class="form-label">FAQs *</label>
|
||||
<textarea class="form-control @error('faqs') is-invalid @enderror" id="faqs" name="faqs" rows="5" required>{{ old('faqs') }}</textarea>
|
||||
@error('faqs')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
<a href="{{ route('card-types') }}" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.card {
|
||||
border-radius: 5px;
|
||||
border: 1px solid #dee2e6;
|
||||
}
|
||||
.form-label {
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
.form-control,
|
||||
.form-select,
|
||||
textarea.form-control {
|
||||
font-size: 0.9rem;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
document.getElementById('addCardTypeForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const cardCode = document.getElementById('cardCode').value;
|
||||
const cardTypeDescription = document.getElementById('cardTypeDescription').value;
|
||||
const cardTypeShortDescription = document.getElementById('cardTypeShortDescription').value;
|
||||
const cardTypeImage = document.getElementById('cardTypeImage').files[0]?.name || '';
|
||||
const virtualCardFontColor = document.getElementById('virtualCardFontColor').value;
|
||||
const cardTypeCoverImage = document.getElementById('cardTypeCoverImage').files[0]?.name || '';
|
||||
const idNumberRequired = document.getElementById('idNumberRequired').value;
|
||||
const idNumberDescription = document.getElementById('idNumberDescription').value;
|
||||
const termsAndConditions = document.getElementById('termsAndConditions').value;
|
||||
const faqs = document.getElementById('faqs').value;
|
||||
|
||||
if (!cardCode || !cardTypeDescription || !cardTypeShortDescription ||
|
||||
!virtualCardFontColor || !idNumberRequired || !termsAndConditions || !faqs) {
|
||||
alert('Please fill out all required fields.');
|
||||
return;
|
||||
}
|
||||
|
||||
const newCardType = {
|
||||
id: Date.now(),
|
||||
cardCode,
|
||||
cardTypeDescription,
|
||||
cardTypeShortDescription,
|
||||
cardTypeImage,
|
||||
virtualCardFontColor,
|
||||
cardTypeCoverImage,
|
||||
idNumberRequired,
|
||||
idNumberDescription,
|
||||
termsAndConditions,
|
||||
faqs
|
||||
};
|
||||
|
||||
let cardTypes = JSON.parse(sessionStorage.getItem('cardTypes') || '[]');
|
||||
cardTypes.push(newCardType);
|
||||
sessionStorage.setItem('cardTypes', JSON.stringify(cardTypes));
|
||||
|
||||
alert('Card Type added successfully!');
|
||||
window.location.href = '/card-types';
|
||||
});
|
||||
|
||||
document.querySelector('.btn-outline-secondary').addEventListener('click', function() {
|
||||
window.location.href = '/card-types';
|
||||
});
|
||||
</script>
|
||||
@endsection
|
|
@ -0,0 +1,130 @@
|
|||
@extends('layouts.app')
|
||||
|
||||
@section('page_title', 'Edit Card Type')
|
||||
|
||||
@section('content')
|
||||
<div class="container">
|
||||
<h2>Edit Card Type</h2>
|
||||
@if (session('success'))
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
{{ session('success') }}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
@endif
|
||||
@if ($errors->any())
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
<ul>
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<form method="POST" action="{{ route('card-types.update', $cardType['id']) }}" enctype="multipart/form-data">
|
||||
@csrf
|
||||
@method('POST')
|
||||
<div class="mb-3">
|
||||
<label for="code" class="form-label">Card Code *</label>
|
||||
<input type="text" class="form-control @error('code') is-invalid @enderror" id="code" name="code" value="{{ old('code', $cardType['cardCode']) }}" required maxlength="50">
|
||||
@error('code')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="type" class="form-label">Card Type *</label>
|
||||
<select class="form-select @error('type') is-invalid @enderror" id="type" name="type" required>
|
||||
<option value="" disabled {{ old('type', $cardType['type']) ? '' : 'selected' }}>Select card type</option>
|
||||
@foreach ($cardTypes as $type)
|
||||
<option value="{{ $type }}" {{ old('type', $cardType['type']) == $type ? 'selected' : '' }}>{{ $type }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('type')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="description" class="form-label">Card Type Description *</label>
|
||||
<input type="text" class="form-control @error('description') is-invalid @enderror" id="description" name="description" value="{{ old('description', $cardType['cardTypeDescription']) }}" required maxlength="255">
|
||||
@error('description')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="short_description" class="form-label">Card Type Short Description *</label>
|
||||
<input type="text" class="form-control @error('short_description') is-invalid @enderror" id="short_description" name="short_description" value="{{ old('short_description', $cardType['cardTypeShortDescription']) }}" required maxlength="100">
|
||||
@error('short_description')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="image" class="form-label">Card Type Image</label>
|
||||
<input type="file" class="form-control @error('image') is-invalid @enderror" id="image" name="image" accept="image/*">
|
||||
@if ($cardType['cardTypeImage'])
|
||||
<p>Current image: <a href="{{ $cardType['cardTypeImage'] }}" target="_blank">View</a></p>
|
||||
@endif
|
||||
@error('image')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="virtual_card_font_color" class="form-label">Virtual Card Font Color *</label>
|
||||
<select class="form-select @error('virtual_card_font_color') is-invalid @enderror" id="virtual_card_font_color" name="virtual_card_font_color" required>
|
||||
<option value="" disabled {{ old('virtual_card_font_color', $cardType['virtualCardFontColor']) ? '' : 'selected' }}>Select color</option>
|
||||
@foreach ($fontColors as $color)
|
||||
<option value="{{ $color }}" {{ old('virtual_card_font_color', $cardType['virtualCardFontColor']) == $color ? 'selected' : '' }}>{{ $color }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('virtual_card_font_color')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="bg_image" class="form-label">Card Type Cover Image</label>
|
||||
<input type="file" class="form-control @error('bg_image') is-invalid @enderror" id="bg_image" name="bg_image" accept="image/*">
|
||||
@if ($cardType['cardTypeCoverImage'])
|
||||
<p>Current image: <a href="{{ $cardType['cardTypeCoverImage'] }}" target="_blank">View</a></p>
|
||||
@endif
|
||||
@error('bg_image')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="id_number" class="form-label">ID Number Required? *</label>
|
||||
<select class="form-select @error('id_number') is-invalid @enderror" id="id_number" name="id_number" required>
|
||||
<option value="" disabled {{ old('id_number', $cardType['idNumberRequired']) ? '' : 'selected' }}>Select option</option>
|
||||
@foreach ($idNumberOptions as $option)
|
||||
<option value="{{ $option }}" {{ old('id_number', $cardType['idNumberRequired']) == $option ? 'selected' : '' }}>{{ $option }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('id_number')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="id_number_description" class="form-label">ID Number Description</label>
|
||||
<input type="text" class="form-control @error('id_number_description') is-invalid @enderror" id="id_number_description" name="id_number_description" value="{{ old('id_number_description', $cardType['idNumberDescription']) }}" maxlength="255">
|
||||
@error('id_number_description')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="terms_and_conditions" class="form-label">Terms and Conditions *</label>
|
||||
<textarea class="form-control @error('terms_and_conditions') is-invalid @enderror" id="terms_and_conditions" name="terms_and_conditions" rows="5" required>{{ old('terms_and_conditions', $cardType['termsAndConditions']) }}</textarea>
|
||||
@error('terms_and_conditions')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="faqs" class="form-label">FAQs *</label>
|
||||
<textarea class="form-control @error('faqs') is-invalid @enderror" id="faqs" name="faqs" rows="5" required>{{ old('faqs', $cardType['faqs']) }}</textarea>
|
||||
@error('faqs')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Update</button>
|
||||
<a href="{{ route('card-types') }}" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
</div>
|
||||
@endsection
|
|
@ -0,0 +1,42 @@
|
|||
@extends('layouts.app')
|
||||
|
||||
@section('page_title', 'View Card Type')
|
||||
|
||||
@section('content')
|
||||
<div class="container">
|
||||
<h2>View Card Type</h2>
|
||||
@if (session('success'))
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
{{ session('success') }}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
@endif
|
||||
@if (session('error'))
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
{{ session('error') }}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{{ $cardType['cardTypeDescription'] }}</h5>
|
||||
<p class="card-text"><strong>Card Code:</strong> {{ $cardType['cardCode'] }}</p>
|
||||
<p class="card-text"><strong>Type:</strong> {{ $cardType['type'] }}</p>
|
||||
<p class="card-text"><strong>Short Description:</strong> {{ $cardType['cardTypeShortDescription'] }}</p>
|
||||
@if ($cardType['cardTypeImage'])
|
||||
<p class="card-text"><strong>Card Image:</strong> <a href="{{ $cardType['cardTypeImage'] }}" target="_blank">View</a></p>
|
||||
@endif
|
||||
<p class="card-text"><strong>Font Color:</strong> {{ $cardType['virtualCardFontColor'] }}</p>
|
||||
@if ($cardType['cardTypeCoverImage'])
|
||||
<p class="card-text"><strong>Cover Image:</strong> <a href="{{ $cardType['cardTypeCoverImage'] }}" target="_blank">View</a></p>
|
||||
@endif
|
||||
<p class="card-text"><strong>ID Number Required:</strong> {{ $cardType['idNumberRequired'] }}</p>
|
||||
<p class="card-text"><strong>ID Number Description:</strong> {{ $cardType['idNumberDescription'] ?: 'N/A' }}</p>
|
||||
<p class="card-text"><strong>Terms and Conditions:</strong> {{ $cardType['termsAndConditions'] }}</p>
|
||||
<p class="card-text"><strong>FAQs:</strong> {{ $cardType['faqs'] }}</p>
|
||||
<a href="{{ route('card-types') }}" class="btn btn-secondary">Back</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
|
@ -10,6 +10,8 @@ use App\Http\Controllers\NotificationController;
|
|||
use App\Http\Controllers\CardMemberController;
|
||||
use App\Http\Controllers\PromotionController;
|
||||
use App\Http\Controllers\TermsAndPrivacyController;
|
||||
use App\Http\Controllers\CardTypeController;
|
||||
|
||||
|
||||
|
||||
Route::get('/', function () {
|
||||
|
@ -204,3 +206,13 @@ Route::get('/terms-and-privacy/{uuid}/edit', [TermsAndPrivacyController::class,
|
|||
Route::put('/terms-and-privacy/{uuid}', [TermsAndPrivacyController::class, 'update'])->name('terms-and-privacy.update');
|
||||
Route::delete('/terms-and-privacy/{uuid}', [TermsAndPrivacyController::class, 'destroy'])->name('terms-and-privacy.destroy');
|
||||
Route::delete('/terms-and-privacy/batch-delete', [TermsAndPrivacyController::class, 'batchDelete'])->name('terms-and-privacy.batchDelete');
|
||||
|
||||
//Card Types
|
||||
Route::get('/card-types', [CardTypeController::class, 'index'])->name('card-types');
|
||||
Route::get('/card-types/create', [CardTypeController::class, 'create'])->name('card-types.create');
|
||||
Route::post('/card-types', [CardTypeController::class, 'store'])->name('card-types.store');
|
||||
Route::get('/card-types/{uuid}', [CardTypeController::class, 'show'])->name('card-types.show');
|
||||
Route::get('/card-types/{uuid}/edit', [CardTypeController::class, 'edit'])->name('card-types.edit');
|
||||
Route::post('/card-types/{uuid}', [CardTypeController::class, 'update'])->name('card-types.update');
|
||||
Route::delete('/card-types/{uuid}', [CardTypeController::class, 'destroy'])->name('card-types.destroy');
|
||||
Route::delete('/card-types/batch-delete', [CardTypeController::class, 'batchDelete'])->name('card-types.batchDelete');
|
Loading…
Reference in New Issue