Addec crud entries for a company / companies
This commit is contained in:
@@ -16,48 +16,56 @@ class CompanyController extends Controller
|
||||
public function index()
|
||||
{
|
||||
return view('company::index', [
|
||||
'companies' => Company::withCount(['users', 'warehouses', 'licenseKeys'])->latest('id')->paginate(20),
|
||||
'companies' => Company::query()
|
||||
->withCount(['users', 'warehouses', 'licenseKeys'])
|
||||
->latest('id')
|
||||
->paginate(20),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a company tenant.
|
||||
* Show the create company screen.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('company::create', [
|
||||
'company' => new Company([
|
||||
'status' => 'active',
|
||||
'timezone' => 'Europe/London',
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a company tenant.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'billing_email' => ['nullable', 'email', 'max:255'],
|
||||
'status' => ['required', 'in:active,suspended'],
|
||||
]);
|
||||
|
||||
Company::create([
|
||||
...$data,
|
||||
'slug' => Str::slug($data['name']),
|
||||
'timezone' => 'Europe/London',
|
||||
]);
|
||||
|
||||
return back()->with('status', 'Company created.');
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
|
||||
return view('company::create', [
|
||||
|
||||
'company' => new Company,
|
||||
|
||||
]);
|
||||
$company = Company::create($this->validated($request));
|
||||
|
||||
return redirect()
|
||||
->route('platform.companies.show', $company)
|
||||
->with('status', 'Company created.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a company workbench.
|
||||
*/
|
||||
public function show(Company $company)
|
||||
{
|
||||
$company->loadCount(['users', 'warehouses', 'licenseKeys', 'payments']);
|
||||
|
||||
return view('company::show', [
|
||||
'company' => $company,
|
||||
'recentUsers' => $company->users()->latest('id')->limit(5)->get(),
|
||||
'recentWarehouses' => $company->warehouses()->latest('id')->limit(5)->get(),
|
||||
'recentLicenseKeys' => $company->licenseKeys()->latest('id')->limit(5)->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the edit company screen.
|
||||
*/
|
||||
public function edit(Company $company)
|
||||
{
|
||||
return view('company::edit', [
|
||||
@@ -65,6 +73,9 @@ class CompanyController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a company tenant.
|
||||
*/
|
||||
public function update(Request $request, Company $company)
|
||||
{
|
||||
$company->update($this->validated($request, $company));
|
||||
@@ -74,8 +85,13 @@ class CompanyController extends Controller
|
||||
->with('status', 'Company updated.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a company tenant.
|
||||
*/
|
||||
public function destroy(Company $company)
|
||||
{
|
||||
abort_if($company->is_system_company, 403, 'The system company cannot be deleted.');
|
||||
|
||||
$company->delete();
|
||||
|
||||
return redirect()
|
||||
@@ -85,10 +101,16 @@ class CompanyController extends Controller
|
||||
|
||||
private function validated(Request $request, ?Company $company = null): array
|
||||
{
|
||||
return $request->validate([
|
||||
$data = $request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'billing_email' => ['required', 'email', 'max:255'],
|
||||
'status' => ['required', Rule::in(['active', 'inactive'])],
|
||||
'billing_email' => ['nullable', 'email', 'max:255'],
|
||||
'status' => ['required', Rule::in(['active', 'suspended', 'inactive'])],
|
||||
'timezone' => ['nullable', 'string', 'max:64'],
|
||||
]);
|
||||
|
||||
$data['slug'] = Str::slug($data['name']);
|
||||
$data['timezone'] = $data['timezone'] ?: ($company?->timezone ?: 'Europe/London');
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +1,75 @@
|
||||
{{-- Modules/Company/resources/views/companies/_form.blade.php --}}
|
||||
|
||||
@csrf
|
||||
|
||||
<div class="space-y-6">
|
||||
<div class="grid gap-5 md:grid-cols-2">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700">Name</label>
|
||||
<label for="name" class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200">Company name</label>
|
||||
<input
|
||||
id="name"
|
||||
name="name"
|
||||
value="{{ old('name', $company->name) }}"
|
||||
class="mt-1 w-full rounded-lg border-gray-300"
|
||||
class="mt-2 w-full rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white"
|
||||
required
|
||||
>
|
||||
@error('name') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
@error('name')
|
||||
<p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700">Billing email</label>
|
||||
<label for="billing_email" class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200">Billing email</label>
|
||||
<input
|
||||
id="billing_email"
|
||||
type="email"
|
||||
name="billing_email"
|
||||
value="{{ old('billing_email', $company->billing_email) }}"
|
||||
class="mt-1 w-full rounded-lg border-gray-300"
|
||||
required
|
||||
placeholder="billing@example.com"
|
||||
class="mt-2 w-full rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white"
|
||||
>
|
||||
@error('billing_email') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
@error('billing_email')
|
||||
<p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700">Status</label>
|
||||
<select name="status" class="mt-1 w-full rounded-lg border-gray-300" required>
|
||||
<label for="status" class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200">Status</label>
|
||||
<select
|
||||
id="status"
|
||||
name="status"
|
||||
class="mt-2 w-full rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white"
|
||||
required
|
||||
>
|
||||
<option value="active" @selected(old('status', $company->status) === 'active')>Active</option>
|
||||
<option value="suspended" @selected(old('status', $company->status) === 'suspended')>Suspended</option>
|
||||
<option value="inactive" @selected(old('status', $company->status) === 'inactive')>Inactive</option>
|
||||
</select>
|
||||
@error('status') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
@error('status')
|
||||
<p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-3">
|
||||
<button class="rounded-lg bg-blue-600 px-4 py-2 text-white">
|
||||
Save company
|
||||
</button>
|
||||
|
||||
<a href="{{ route('platform.companies.index') }}" class="text-sm text-gray-600">
|
||||
Cancel
|
||||
</a>
|
||||
<div>
|
||||
<label for="timezone" class="block text-sm font-semibold text-zinc-700 dark:text-zinc-200">Timezone</label>
|
||||
<input
|
||||
id="timezone"
|
||||
name="timezone"
|
||||
value="{{ old('timezone', $company->timezone ?? 'Europe/London') }}"
|
||||
class="mt-2 w-full rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950 dark:text-white"
|
||||
>
|
||||
@error('timezone')
|
||||
<p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 flex flex-wrap items-center gap-3">
|
||||
<button class="rounded-xl bg-zinc-900 px-4 py-2 text-sm font-semibold text-white shadow-sm hover:bg-zinc-700 dark:bg-white dark:text-zinc-900">
|
||||
Save company
|
||||
</button>
|
||||
|
||||
<a
|
||||
href="{{ $company->exists ? route('platform.companies.show', $company) : route('platform.companies.index') }}"
|
||||
class="rounded-xl border border-zinc-300 px-4 py-2 text-sm font-semibold text-zinc-700 hover:bg-zinc-50 dark:border-zinc-700 dark:text-zinc-200 dark:hover:bg-zinc-800"
|
||||
>
|
||||
Cancel
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
{{-- Modules/Company/resources/views/companies/create.blade.php --}}
|
||||
|
||||
<x-layouts::app :title="__('Create Company')">
|
||||
<x-wms.page-hero title="Create company" subtitle="Add a new tenant company." />
|
||||
<div class="space-y-6">
|
||||
<x-wms.page-hero
|
||||
eyebrow="Platform Administration"
|
||||
title="Create company"
|
||||
description="Add a new tenant company and prepare it for users, warehouses and licences."
|
||||
icon="fa-solid fa-building-circle-plus"
|
||||
/>
|
||||
|
||||
<form method="POST" action="{{ route('platform.companies.store') }}" class="max-w-3xl">
|
||||
@include('company::companies._form')
|
||||
</form>
|
||||
<div class="rounded-3xl bg-white p-6 shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
|
||||
<form method="POST" action="{{ route('platform.companies.store') }}">
|
||||
@include('company::_form')
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</x-layouts::app>
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
<x-wms.page-hero
|
||||
eyebrow="Platform Administration"
|
||||
title="Edit company"
|
||||
description="Update tenant company details."
|
||||
description="Update tenant company details, status and billing contact."
|
||||
icon="fa-solid fa-building"
|
||||
/>
|
||||
|
||||
<div class="rounded-3xl bg-white p-6 shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
|
||||
<form method="POST" action="{{ route('platform.companies.update', $company) }}" class="space-y-5">
|
||||
<form method="POST" action="{{ route('platform.companies.update', $company) }}">
|
||||
@method('PUT')
|
||||
@include('company::_form')
|
||||
</form>
|
||||
|
||||
@@ -1,51 +1,143 @@
|
||||
<x-layouts::app :title="$company->name">
|
||||
<div class="space-y-6">
|
||||
<x-wms.page-hero
|
||||
eyebrow="Platform Administration"
|
||||
eyebrow="Company Workbench"
|
||||
:title="$company->name"
|
||||
description="Company details and administration."
|
||||
description="Review tenant health, linked records and administration shortcuts."
|
||||
icon="fa-solid fa-building"
|
||||
/>
|
||||
|
||||
<div class="rounded-3xl bg-white p-6 shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
|
||||
<dl class="grid gap-5 md:grid-cols-2">
|
||||
<div>
|
||||
<dt class="text-sm font-medium text-zinc-500 dark:text-zinc-400">Billing email</dt>
|
||||
<dd class="mt-1 font-semibold text-zinc-900 dark:text-white">{{ $company->billing_email ?? '—' }}</dd>
|
||||
</div>
|
||||
<div class="grid gap-4 md:grid-cols-2 xl:grid-cols-4">
|
||||
<div class="rounded-3xl bg-white p-5 shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
|
||||
<p class="text-sm font-medium text-zinc-500 dark:text-zinc-400">Users</p>
|
||||
<p class="mt-2 text-3xl font-bold text-zinc-900 dark:text-white">{{ $company->users_count }}</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<dt class="text-sm font-medium text-zinc-500 dark:text-zinc-400">Status</dt>
|
||||
<dd class="mt-1 font-semibold text-zinc-900 dark:text-white">
|
||||
<div class="rounded-3xl bg-white p-5 shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
|
||||
<p class="text-sm font-medium text-zinc-500 dark:text-zinc-400">Warehouses</p>
|
||||
<p class="mt-2 text-3xl font-bold text-zinc-900 dark:text-white">{{ $company->warehouses_count }}</p>
|
||||
</div>
|
||||
|
||||
<div class="rounded-3xl bg-white p-5 shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
|
||||
<p class="text-sm font-medium text-zinc-500 dark:text-zinc-400">Licences</p>
|
||||
<p class="mt-2 text-3xl font-bold text-zinc-900 dark:text-white">{{ $company->license_keys_count }}</p>
|
||||
</div>
|
||||
|
||||
<div class="rounded-3xl bg-white p-5 shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
|
||||
<p class="text-sm font-medium text-zinc-500 dark:text-zinc-400">Payments</p>
|
||||
<p class="mt-2 text-3xl font-bold text-zinc-900 dark:text-white">{{ $company->payments_count }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-6 xl:grid-cols-3">
|
||||
<div class="rounded-3xl bg-white p-6 shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800 xl:col-span-2">
|
||||
<div class="flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h2 class="text-lg font-bold text-zinc-900 dark:text-white">Company profile</h2>
|
||||
<p class="mt-1 text-sm text-zinc-500 dark:text-zinc-400">Core tenant identity and operational status.</p>
|
||||
</div>
|
||||
|
||||
<span class="inline-flex rounded-full px-3 py-1 text-xs font-semibold
|
||||
@if ($company->is_system_company)
|
||||
bg-blue-100 text-blue-700 dark:bg-blue-950 dark:text-blue-300
|
||||
@elseif ($company->status === 'active')
|
||||
bg-green-100 text-green-700 dark:bg-green-950 dark:text-green-300
|
||||
@else
|
||||
bg-red-100 text-red-700 dark:bg-red-950 dark:text-red-300
|
||||
@endif
|
||||
">
|
||||
{{ $company->is_system_company ? 'System' : ucfirst($company->status) }}
|
||||
</dd>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<dt class="text-sm font-medium text-zinc-500 dark:text-zinc-400">Timezone</dt>
|
||||
<dd class="mt-1 font-semibold text-zinc-900 dark:text-white">{{ $company->timezone }}</dd>
|
||||
<dl class="mt-6 grid gap-5 md:grid-cols-2">
|
||||
<div>
|
||||
<dt class="text-sm font-medium text-zinc-500 dark:text-zinc-400">Billing email</dt>
|
||||
<dd class="mt-1 font-semibold text-zinc-900 dark:text-white">{{ $company->billing_email ?? '—' }}</dd>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<dt class="text-sm font-medium text-zinc-500 dark:text-zinc-400">Timezone</dt>
|
||||
<dd class="mt-1 font-semibold text-zinc-900 dark:text-white">{{ $company->timezone }}</dd>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<dt class="text-sm font-medium text-zinc-500 dark:text-zinc-400">Slug</dt>
|
||||
<dd class="mt-1 font-semibold text-zinc-900 dark:text-white">{{ $company->slug }}</dd>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<dt class="text-sm font-medium text-zinc-500 dark:text-zinc-400">Created</dt>
|
||||
<dd class="mt-1 font-semibold text-zinc-900 dark:text-white">{{ $company->created_at?->format('d M Y') }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<div class="rounded-3xl bg-white p-6 shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
|
||||
<h2 class="text-lg font-bold text-zinc-900 dark:text-white">Quick actions</h2>
|
||||
<div class="mt-5 space-y-3">
|
||||
<a href="{{ route('platform.companies.edit', $company) }}" class="block rounded-xl bg-blue-600 px-4 py-2 text-center text-sm font-semibold text-white hover:bg-blue-700">
|
||||
Edit company
|
||||
</a>
|
||||
|
||||
<a href="{{ route('platform.companies.index') }}" class="block rounded-xl border border-zinc-300 px-4 py-2 text-center text-sm font-semibold text-zinc-700 hover:bg-zinc-50 dark:border-zinc-700 dark:text-zinc-200 dark:hover:bg-zinc-800">
|
||||
Back to companies
|
||||
</a>
|
||||
|
||||
@unless ($company->is_system_company)
|
||||
<form method="POST" action="{{ route('platform.companies.destroy', $company) }}" onsubmit="return confirm('Delete this company? This cannot be undone.');">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="w-full rounded-xl bg-red-600 px-4 py-2 text-sm font-semibold text-white hover:bg-red-700">
|
||||
Delete company
|
||||
</button>
|
||||
</form>
|
||||
@endunless
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<dt class="text-sm font-medium text-zinc-500 dark:text-zinc-400">Slug</dt>
|
||||
<dd class="mt-1 font-semibold text-zinc-900 dark:text-white">{{ $company->slug }}</dd>
|
||||
<div class="grid gap-6 xl:grid-cols-3">
|
||||
<div class="rounded-3xl bg-white p-6 shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
|
||||
<h2 class="text-lg font-bold text-zinc-900 dark:text-white">Recent users</h2>
|
||||
<div class="mt-5 space-y-3">
|
||||
@forelse ($recentUsers as $user)
|
||||
<div class="rounded-2xl border border-zinc-200 p-3 dark:border-zinc-800">
|
||||
<p class="font-semibold text-zinc-900 dark:text-white">{{ $user->name }}</p>
|
||||
<p class="text-sm text-zinc-500 dark:text-zinc-400">{{ $user->email }}</p>
|
||||
</div>
|
||||
@empty
|
||||
<p class="text-sm text-zinc-500 dark:text-zinc-400">No users found.</p>
|
||||
@endforelse
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 flex gap-3">
|
||||
<a
|
||||
href="{{ route('platform.companies.edit', $company) }}"
|
||||
class="rounded-xl bg-blue-600 px-4 py-2 text-sm font-semibold text-white hover:bg-blue-700"
|
||||
>
|
||||
Edit
|
||||
</a>
|
||||
<div class="rounded-3xl bg-white p-6 shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
|
||||
<h2 class="text-lg font-bold text-zinc-900 dark:text-white">Recent warehouses</h2>
|
||||
<div class="mt-5 space-y-3">
|
||||
@forelse ($recentWarehouses as $warehouse)
|
||||
<div class="rounded-2xl border border-zinc-200 p-3 dark:border-zinc-800">
|
||||
<p class="font-semibold text-zinc-900 dark:text-white">{{ $warehouse->name }}</p>
|
||||
<p class="text-sm text-zinc-500 dark:text-zinc-400">{{ $warehouse->code ?? '—' }}</p>
|
||||
</div>
|
||||
@empty
|
||||
<p class="text-sm text-zinc-500 dark:text-zinc-400">No warehouses found.</p>
|
||||
@endforelse
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a
|
||||
href="{{ route('platform.companies.index') }}"
|
||||
class="rounded-xl border border-zinc-300 px-4 py-2 text-sm font-semibold text-zinc-700 hover:bg-zinc-50 dark:border-zinc-700 dark:text-zinc-200 dark:hover:bg-zinc-800"
|
||||
>
|
||||
Back
|
||||
</a>
|
||||
<div class="rounded-3xl bg-white p-6 shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
|
||||
<h2 class="text-lg font-bold text-zinc-900 dark:text-white">Recent licences</h2>
|
||||
<div class="mt-5 space-y-3">
|
||||
@forelse ($recentLicenseKeys as $license)
|
||||
<div class="rounded-2xl border border-zinc-200 p-3 dark:border-zinc-800">
|
||||
<p class="font-semibold text-zinc-900 dark:text-white">{{ ucfirst($license->plan ?? 'Licence') }}</p>
|
||||
<p class="text-sm text-zinc-500 dark:text-zinc-400">{{ ucfirst($license->status ?? 'unknown') }}</p>
|
||||
</div>
|
||||
@empty
|
||||
<p class="text-sm text-zinc-500 dark:text-zinc-400">No licences found.</p>
|
||||
@endforelse
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
latest: 1.1.0
|
||||
|
||||
versions:
|
||||
- version: 1.1.0
|
||||
date: 2026-07-02
|
||||
changes:
|
||||
- Added full company create, show, edit, update and delete workflow.
|
||||
- Added company workbench show page with profile, KPI cards, recent users, warehouses and licences.
|
||||
- Added guarded deletion so the system company cannot be deleted.
|
||||
- Standardised Company module views on x-layouts::app and company::_form includes.
|
||||
- version: 1.0.0
|
||||
date: 2026-07-02
|
||||
changes:
|
||||
- Initial Company module skeleton.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "Company",
|
||||
"alias": "company",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"description": "",
|
||||
"keywords": [],
|
||||
"priority": 0,
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Modules\Helpdesk\Tests\Feature;
|
||||
|
||||
use Modules\Company\Models\Company
|
||||
use Modules\Company\Models\Company;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
Reference in New Issue
Block a user