feat: Enhance product creation UI with radio buttons and switch, correct product VPS OS foreign key, remove transaction UUID migration, and refactor customer add/edit views.

This commit is contained in:
pbao9
2026-02-25 13:45:02 +07:00
parent 2ff2095062
commit 5c97768707
5 changed files with 296 additions and 239 deletions
@@ -17,7 +17,7 @@ return new class extends Migration
$table->integer('product_type')->nullable(); $table->integer('product_type')->nullable();
$table->unsignedBigInteger('os_id')->index(); $table->unsignedBigInteger('os_id')->index();
$table->foreign('product_id')->references('id')->on('vps')->onDelete('cascade'); $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
$table->foreign('os_id')->references('id')->on('os')->onDelete('cascade'); $table->foreign('os_id')->references('id')->on('os')->onDelete('cascade');
$table->timestamps(); $table->timestamps();
}); });
@@ -1,22 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up()
{
Schema::table('transactions', function (Blueprint $table) {
$table->uuid('uuid')->unique()->nullable()->after('id');
$table->string('public_code')->unique()->nullable()->after('uuid');
});
}
public function down()
{
Schema::table('transactions', function (Blueprint $table) {
$table->dropColumn(['uuid', 'public_code']);
});
}
};
@@ -1,115 +1,152 @@
@extends("administrator.layout.master") @extends('administrator.layout.master')
@section("content") @push('plugin-styles')
@foreach (config('assets.datatable.css') as $datatable)
<link href="{{ asset($datatable) }}" rel="stylesheet" />
@endforeach
@endpush
@section('breadcrumb')
@php
$breadcrumbItems = [
['label' => 'Customer'],
['label' => 'Customer Management', 'url' => route('customer.index')],
['label' => 'Add Customer', 'active' => true],
];
@endphp
<x-admin-breadcrumb :items="$breadcrumbItems" />
@endsection
@section('content')
@if(auth()->guard('admins')->user()->can("add customer")) @if(auth()->guard('admins')->user()->can("add customer"))
<div class="card card-outline card-primary"> <form action="{{ route('customer.store') }}" method="post">
<form action="{{ route('customer.store') }}" method="post"> @csrf
@csrf <div class="row align-items-start">
<div class="card-body"> <div class="col-md-8">
<div class="row"> <div class="card card-primary card-outline rounded-4 shadow-none">
<div class="col"> <div class="card-header rounded-top-4">
{{--Fullname--}} <h5 class="card-title m-0">Basic Information</h5>
<div class="form-group row">
<label class="col-md-4" for="fullname">Fullname</label>
<div class="col-md-8">
<input type="text" id="fullname" name="fullname" placeholder="Fullname"
value="{{ old('fullname') }}" class="form-control">
</div>
</div>
{{--Company--}}
<div class="form-group row">
<label class="col-md-4" for="company">Company</label>
<div class="col-md-8">
<input type="text" id="company" name="company" placeholder="Company"
value="{{ old('company') }}" class="form-control">
</div>
</div>
{{--Email--}}
<div class="form-group row">
<label class="col-md-4" for="email">Email Address</label>
<div class="col-md-8">
<input type="email" id="email" name="email" placeholder="Email Address"
value="{{ old('email') }}" class="form-control">
</div>
</div>
{{--Phone--}}
<div class="form-group row">
<label class="col-md-4" for="phone">Phone Number</label>
<div class="col-md-8">
<input type="text" id="phone" name="phone" placeholder="(+84) 123. 456. 789)"
value="{{ old('phone') }}" class="form-control">
</div>
</div>
{{--Password--}}
<div class="form-group row">
<label class="col-md-4" for="password">Password</label>
<div class="col-md-8">
<input type="password" id="password" name="password" placeholder="******"
value="{{ old('password') }}" class="form-control">
</div>
</div>
</div> </div>
<div class="col"> <div class="card-body">
{{--Address--}} <div class="mb-4">
<div class="form-group row"> <h5 class="text-primary border-bottom mb-3 pb-2">Personal Information</h5>
<label class="col-md-4" for="address">Address</label> <div class="row mb-3">
<div class="col-md-8"> <div class="col-md-6">
<input type="text" id="address" name="address" placeholder="Address" <div class="form-group">
value="{{ old('address') }}" class="form-control"> <label for="fullname">Fullname <span class="text-danger">*</span></label>
<input type="text" id="fullname" name="fullname" value="{{ old('fullname') }}"
class="form-control" required placeholder="Enter fullname">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="company">Company</label>
<input type="text" id="company" name="company" value="{{ old('company') }}"
class="form-control" placeholder="Enter company name">
</div>
</div>
</div>
<div class="row mb-3">
<div class="col-md-6">
<div class="form-group">
<label for="email">Email Address <span class="text-danger">*</span></label>
<input type="email" id="email" name="email" value="{{ old('email') }}"
class="form-control" required placeholder="Enter email address">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="phone">Phone Number</label>
<input type="text" id="phone" name="phone" value="{{ old('phone') }}"
class="form-control" placeholder="(+84) 123. 456. 789">
</div>
</div>
</div>
<div class="row mb-3">
<div class="col-md-12">
<div class="form-group">
<label for="password">Password <span class="text-danger">*</span></label>
<input type="password" id="password" name="password" class="form-control" required placeholder="******">
</div>
</div>
</div> </div>
</div> </div>
{{--City--}}
<div class="form-group row"> <div class="mb-4">
<label class="col-md-4" for="city">City</label> <h5 class="text-primary border-bottom mb-3 pb-2">Address Information</h5>
<div class="col-md-8"> <div class="row mb-3">
<input type="text" id="city" name="city" placeholder="City" <div class="col-md-12">
value="{{ old('city') }}" class="form-control"> <div class="form-group">
<label for="address">Address</label>
<input type="text" id="address" name="address" value="{{ old('address') }}"
class="form-control" placeholder="Enter address">
</div>
</div>
</div> </div>
</div> <div class="row mb-3">
{{--State--}} <div class="col-md-6">
<div class="form-group row"> <div class="form-group">
<label class="col-md-4" for="state">State</label> <label for="city">City</label>
<div class="col-md-8"> <input type="text" id="city" name="city" value="{{ old('city') }}"
<input type="text" id="state" name="state" placeholder="State" class="form-control" placeholder="Enter city">
value="{{ old('state') }}" class="form-control"> </div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="state">State</label>
<input type="text" id="state" name="state" value="{{ old('state') }}"
class="form-control" placeholder="Enter state">
</div>
</div>
</div> </div>
</div> <div class="row mb-3">
{{--Postcode--}} <div class="col-md-6">
<div class="form-group row"> <div class="form-group">
<label class="col-md-4" for="postcode">Postcode</label> <label for="postcode">Postcode</label>
<div class="col-md-8"> <input type="text" id="postcode" name="postcode" value="{{ old('postcode') }}"
<input type="text" id="postcode" name="postcode" placeholder="Postcode" class="form-control" placeholder="Enter postcode">
value="{{ old('postcode') }}" class="form-control"> </div>
</div> </div>
</div> <div class="col-md-6">
{{--Country--}} <div class="form-group">
<div class="form-group row"> <label for="country">Country</label>
<label class="col-md-4" for="country">Country</label> <input type="text" id="country" name="country" value="{{ old('country') }}"
<div class="col-md-8"> class="form-control" placeholder="Enter country">
<input type="text" id="country" name="country" placeholder="Country" </div>
value="{{ old('country') }}" class="form-control"> </div>
</div>
</div>
{{--Password--}}
<div class="form-group row">
<label class="col-md-4" for="email_marketing">Marketing Emails Opt-in</label>
<div class="col-md-8">
<input type="checkbox" name="email_marketing" id="email_marketing" @checked(old('email_marketing') === "on")>
Send Client Marketing Emails
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="card-footer">
<button type="submit" class="btn btn-outline-primary">Save</button>
</div>
</form>
</div> <div class="col-md-4 sticky-top top-10 z-0">
<div class="card card-secondary card-outline mb-3 rounded-4 shadow-none">
<div class="card-header rounded-top-4">
<h5 class="card-title m-0">Settings</h5>
</div>
<div class="card-body">
<div class="form-group mb-3">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="email_marketing"
name="email_marketing" value="1" {{ old('email_marketing') === "on" ? 'checked' : '' }}>
<label class="form-check-label" for="email_marketing">Marketing Emails Opt-in</label>
</div>
<small class="text-muted">Send client marketing emails</small>
</div>
</div>
</div>
</div>
</div>
<x-fixed-action-bar>
<x-button-crm type="button" variant="secondary" size="sm" icon="arrow-left"
route="customer.index">Cancel</x-button-crm>
<x-button-crm type="submit" variant="primary" size="sm" icon="plus-circle">Create Customer</x-button-crm>
</x-fixed-action-bar>
</form>
@else @else
<div class="alert alert-danger alert-dismissible"> <div class="alert alert-danger alert-dismissible">
<h5 class="mb-0"><i class="icon fas fa-ban"></i> Access Denied - You are not assigned to any Customer <h5 class="mb-0"><i class="icon fas fa-ban"></i> Access Denied - You are not assigned to any Customer management department</h5>
management department</h5>
</div> </div>
@endif @endif
@endsection @endsection
@@ -1,116 +1,153 @@
@extends("administrator.layout.master") @extends('administrator.layout.master')
@section("content") @push('plugin-styles')
@foreach (config('assets.datatable.css') as $datatable)
<link href="{{ asset($datatable) }}" rel="stylesheet" />
@endforeach
@endpush
@section('breadcrumb')
@php
$breadcrumbItems = [
['label' => 'Customer'],
['label' => 'Customer Management', 'url' => route('customer.index')],
['label' => 'Edit Customer', 'active' => true],
];
@endphp
<x-admin-breadcrumb :items="$breadcrumbItems" />
@endsection
@section('content')
@if(auth()->guard('admins')->user()->can("edit customer")) @if(auth()->guard('admins')->user()->can("edit customer"))
<div class="card card-outline card-primary"> <form action="{{ route('customer.update', ['id' => $customer->id]) }}" method="post">
<form action="{{ route('customer.update', ['id' => $customer->id]) }}" method="post"> @csrf
@csrf @method('PUT')
@method('PUT') <div class="row align-items-start">
<div class="card-body"> <div class="col-md-8">
<div class="row"> <div class="card card-primary card-outline rounded-4 shadow-none">
<div class="col"> <div class="card-header rounded-top-4">
{{--Fullname--}} <h5 class="card-title m-0">Basic Information</h5>
<div class="form-group row">
<label class="col-md-4" for="fullname">Fullname</label>
<div class="col-md-8">
<input type="text" id="fullname" name="fullname" placeholder="Fullname"
value="{{ old('fullname', $customer->fullname) }}" class="form-control">
</div>
</div>
{{--Company--}}
<div class="form-group row">
<label class="col-md-4" for="company">Company</label>
<div class="col-md-8">
<input type="text" id="company" name="company" placeholder="Company"
value="{{ old('company', $customer->company) }}" class="form-control">
</div>
</div>
{{--Email--}}
<div class="form-group row">
<label class="col-md-4" for="email">Email Address</label>
<div class="col-md-8">
<input type="email" id="email" name="email" placeholder="Email Address"
value="{{ old('email', $customer->email) }}" class="form-control">
</div>
</div>
{{--Phone--}}
<div class="form-group row">
<label class="col-md-4" for="phone">Phone Number</label>
<div class="col-md-8">
<input type="text" id="phone" name="phone" placeholder="(+84) 123. 456. 789)"
value="{{ old('phone', $customer->phone) }}" class="form-control">
</div>
</div>
{{--Password--}}
<div class="form-group row">
<label class="col-md-4" for="password">Password (leave blank to keep current)</label>
<div class="col-md-8">
<input type="password" id="password" name="password" placeholder="******"
value="" class="form-control">
</div>
</div>
</div> </div>
<div class="col"> <div class="card-body">
{{--Address--}} <div class="mb-4">
<div class="form-group row"> <h5 class="text-primary border-bottom mb-3 pb-2">Personal Information</h5>
<label class="col-md-4" for="address">Address</label> <div class="row mb-3">
<div class="col-md-8"> <div class="col-md-6">
<input type="text" id="address" name="address" placeholder="Address" <div class="form-group">
value="{{ old('address', $customer->address) }}" class="form-control"> <label for="fullname">Fullname <span class="text-danger">*</span></label>
<input type="text" id="fullname" name="fullname" value="{{ old('fullname', $customer->fullname) }}"
class="form-control" required placeholder="Enter fullname">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="company">Company</label>
<input type="text" id="company" name="company" value="{{ old('company', $customer->company) }}"
class="form-control" placeholder="Enter company name">
</div>
</div>
</div>
<div class="row mb-3">
<div class="col-md-6">
<div class="form-group">
<label for="email">Email Address <span class="text-danger">*</span></label>
<input type="email" id="email" name="email" value="{{ old('email', $customer->email) }}"
class="form-control" required placeholder="Enter email address">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="phone">Phone Number</label>
<input type="text" id="phone" name="phone" value="{{ old('phone', $customer->phone) }}"
class="form-control" placeholder="(+84) 123. 456. 789">
</div>
</div>
</div>
<div class="row mb-3">
<div class="col-md-12">
<div class="form-group">
<label for="password">Password (leave blank to keep current)</label>
<input type="password" id="password" name="password" class="form-control" placeholder="******">
</div>
</div>
</div> </div>
</div> </div>
{{--City--}}
<div class="form-group row"> <div class="mb-4">
<label class="col-md-4" for="city">City</label> <h5 class="text-primary border-bottom mb-3 pb-2">Address Information</h5>
<div class="col-md-8"> <div class="row mb-3">
<input type="text" id="city" name="city" placeholder="City" <div class="col-md-12">
value="{{ old('city', $customer->city) }}" class="form-control"> <div class="form-group">
<label for="address">Address</label>
<input type="text" id="address" name="address" value="{{ old('address', $customer->address) }}"
class="form-control" placeholder="Enter address">
</div>
</div>
</div> </div>
</div> <div class="row mb-3">
{{--State--}} <div class="col-md-6">
<div class="form-group row"> <div class="form-group">
<label class="col-md-4" for="state">State</label> <label for="city">City</label>
<div class="col-md-8"> <input type="text" id="city" name="city" value="{{ old('city', $customer->city) }}"
<input type="text" id="state" name="state" placeholder="State" class="form-control" placeholder="Enter city">
value="{{ old('state', $customer->state) }}" class="form-control"> </div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="state">State</label>
<input type="text" id="state" name="state" value="{{ old('state', $customer->state) }}"
class="form-control" placeholder="Enter state">
</div>
</div>
</div> </div>
</div> <div class="row mb-3">
{{--Postcode--}} <div class="col-md-6">
<div class="form-group row"> <div class="form-group">
<label class="col-md-4" for="postcode">Postcode</label> <label for="postcode">Postcode</label>
<div class="col-md-8"> <input type="text" id="postcode" name="postcode" value="{{ old('postcode', $customer->postcode) }}"
<input type="text" id="postcode" name="postcode" placeholder="Postcode" class="form-control" placeholder="Enter postcode">
value="{{ old('postcode', $customer->postcode) }}" class="form-control"> </div>
</div> </div>
</div> <div class="col-md-6">
{{--Country--}} <div class="form-group">
<div class="form-group row"> <label for="country">Country</label>
<label class="col-md-4" for="country">Country</label> <input type="text" id="country" name="country" value="{{ old('country', $customer->country) }}"
<div class="col-md-8"> class="form-control" placeholder="Enter country">
<input type="text" id="country" name="country" placeholder="Country" </div>
value="{{ old('country', $customer->country) }}" class="form-control"> </div>
</div>
</div>
{{--Marketing Emails--}}
<div class="form-group row">
<label class="col-md-4" for="email_marketing">Marketing Emails Opt-in</label>
<div class="col-md-8">
<input type="checkbox" name="email_marketing" id="email_marketing" @checked(old('email_marketing', $customer->email_marketing) == 1)>
Send Client Marketing Emails
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="card-footer">
<button type="submit" class="btn btn-outline-primary">Update</button>
</div>
</form>
</div> <div class="col-md-4 sticky-top top-10 z-0">
<div class="card card-secondary card-outline mb-3 rounded-4 shadow-none">
<div class="card-header rounded-top-4">
<h5 class="card-title m-0">Settings</h5>
</div>
<div class="card-body">
<div class="form-group mb-3">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="email_marketing"
name="email_marketing" value="1" {{ old('email_marketing', $customer->email_marketing) == 1 ? 'checked' : '' }}>
<label class="form-check-label" for="email_marketing">Marketing Emails Opt-in</label>
</div>
<small class="text-muted">Send client marketing emails</small>
</div>
</div>
</div>
</div>
</div>
<x-fixed-action-bar>
<x-button-crm type="button" variant="secondary" size="sm" icon="arrow-left"
route="customer.index">Cancel</x-button-crm>
<x-button-crm type="submit" variant="primary" size="sm" icon="save">Update Customer</x-button-crm>
</x-fixed-action-bar>
</form>
@else @else
<div class="alert alert-danger alert-dismissible"> <div class="alert alert-danger alert-dismissible">
<h5 class="mb-0"><i class="icon fas fa-ban"></i> Access Denied - You are not assigned to any Customer <h5 class="mb-0"><i class="icon fas fa-ban"></i> Access Denied - You are not assigned to any Customer management department</h5>
management department</h5>
</div> </div>
@endif @endif
@endsection @endsection
@@ -221,16 +221,21 @@
</div> </div>
{{-- Product Type --}} {{-- Product Type --}}
<div class="form-group mb-3"> <div class="form-group mb-3">
<label for="product_type" class="mb-2">Product Type</label> <label class="mb-2">Product Type</label>
<select class="form-control select2" name="product_type" id="product_type"> <div class="row">
<option value="">-- Select Type --</option>
@foreach (\App\Enums\Product\ProductTypeEnums::cases() as $type) @foreach (\App\Enums\Product\ProductTypeEnums::cases() as $type)
<option value="{{ $type->value }}" <div class="col-md-6 mb-2">
{{ old('product_type') == $type->value ? 'selected' : '' }}> <div class="form-check">
{{ $type->label() }} <input class="form-check-input" type="radio" name="product_type"
</option> id="product_type_{{ $type->value }}" value="{{ $type->value }}"
{{ old('product_type') == $type->value ? 'checked' : '' }}>
<label class="form-check-label" for="product_type_{{ $type->value }}">
{{ $type->label() }}
</label>
</div>
</div>
@endforeach @endforeach
</select> </div>
</div> </div>
{{-- Operating System (for VPS) --}} {{-- Operating System (for VPS) --}}
<div class="form-group mb-3" id="os-section"> <div class="form-group mb-3" id="os-section">
@@ -289,14 +294,11 @@
{{-- Status --}} {{-- Status --}}
<div class="form-group mb-3"> <div class="form-group mb-3">
<label for="is_active" class="mb-2">Status</label> <label for="is_active" class="mb-2">Status</label>
<select class="form-control select2" name="is_active" id="is_active"> <div class="form-check form-switch">
@foreach (\App\Enums\Status::cases() as $status) <input class="form-check-input" type="checkbox" role="switch" id="is_active"
<option value="{{ $status->value }}" name="is_active" value="1" {{ old('is_active', true) ? 'checked' : '' }}>
{{ old('is_active', \App\Enums\Status::ACTIVE->value) == $status->value ? 'selected' : '' }}> <label class="form-check-label" for="is_active">Active</label>
{{ $status->label() }} </div>
</option>
@endforeach
</select>
</div> </div>
<div class="form-group mb-3"> <div class="form-group mb-3">
@@ -350,13 +352,16 @@
@endforeach @endforeach
<script> <script>
$(document).ready(function() { $(document).ready(function() {
// Initialize Select2 FIRST
if ($(".select2").length) { if ($(".select2").length) {
$(".select2").select2(); $(".select2").select2({
allowClear: true
});
} }
// Toggle OS/Control Panel sections based on Product Type // Toggle OS/Control Panel sections based on Product Type
function toggleProductSections() { function toggleProductSections() {
const productType = $('#product_type').val(); const productType = $('input[name="product_type"]:checked').val();
if (productType === 'hosting') { if (productType === 'hosting') {
$('#os-section').hide(); $('#os-section').hide();
@@ -394,7 +399,7 @@
toggleProductSections(); toggleProductSections();
// Toggle when product type changes // Toggle when product type changes
$('#product_type').on('change', toggleProductSections); $('input[name="product_type"]').on('change', toggleProductSections);
// Trigger initial panel price display // Trigger initial panel price display
$('#control_panel_ids').trigger('change'); $('#control_panel_ids').trigger('change');