Repo rebuild
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Platform\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Modules\Platform\app\Http\Middleware\EnsureLicensedTenant;
|
||||
use Modules\Platform\app\Http\Middleware\EnsurePlatformAdmin;
|
||||
use Modules\Platform\app\Http\Middleware\EnsureTenantAssigned;
|
||||
|
||||
class PlatformServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register module services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->mergeConfigFrom(__DIR__ . '/../config/platform.php', 'platform');
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap module services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'platform');
|
||||
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
|
||||
|
||||
Route::middleware('web')->group(__DIR__ . '/../routes/web.php');
|
||||
|
||||
app('router')->aliasMiddleware('tenant.assigned', EnsureTenantAssigned::class);
|
||||
app('router')->aliasMiddleware('tenant.licensed', EnsureLicensedTenant::class);
|
||||
app('router')->aliasMiddleware('platform.admin', EnsurePlatformAdmin::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Platform\app\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Company\Models\Company;
|
||||
use Modules\Platform\app\Models\LicenseKey;
|
||||
|
||||
class LicenseKeyController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display licence keys.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('platform::licenses.index', [
|
||||
'companies' => Company::orderBy('name')->get(),
|
||||
'licenses' => LicenseKey::with('company')->latest()->paginate(20),
|
||||
'plainKey' => session('plain_license_key'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue a new licence key.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'company_id' => ['required', 'exists:companies,id'],
|
||||
'label' => ['required', 'string', 'max:255'],
|
||||
'plan' => ['required', 'in:standard,professional,enterprise'],
|
||||
'max_users' => ['required', 'integer', 'min:1', 'max:10000'],
|
||||
]);
|
||||
|
||||
$company = Company::findOrFail($data['company_id']);
|
||||
$plainKey = LicenseKey::issueFor($company, $data['label'], $data['plan'], (int) $data['max_users']);
|
||||
|
||||
return back()->with('plain_license_key', $plainKey)->with('status', 'Licence key issued. Copy it now.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Platform\app\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Company\Models\Company;
|
||||
use Modules\Platform\app\Models\Payment;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display company payments.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('platform::payments.index', [
|
||||
'companies' => Company::orderBy('name')->get(),
|
||||
'payments' => Payment::with('company')->latest()->paginate(20),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a manual payment or admin override record.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'company_id' => ['required', 'exists:companies,id'],
|
||||
'amount' => ['required', 'integer', 'min:0'],
|
||||
'currency' => ['required', 'string', 'size:3'],
|
||||
'status' => ['required', 'in:pending,paid,failed,refunded,override'],
|
||||
'description' => ['nullable', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
Payment::create([
|
||||
...$data,
|
||||
'paid_at' => in_array($data['status'], ['paid', 'override'], true) ? now() : null,
|
||||
'metadata' => ['source' => 'manual_admin'],
|
||||
]);
|
||||
|
||||
return back()->with('status', 'Payment record created.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Platform\app\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Modules\Company\Models\Company;
|
||||
use Modules\Platform\app\Models\LicenseKey;
|
||||
use Modules\Platform\app\Models\Payment;
|
||||
use Modules\Platform\app\Models\PlatformPrice;
|
||||
use Modules\Warehouse\app\Models\Warehouse;
|
||||
|
||||
class PlatformDashboardController extends Controller
|
||||
{
|
||||
public function __invoke(): View
|
||||
{
|
||||
$companies = Company::query()
|
||||
->withCount(['users', 'warehouses', 'licenseKeys'])
|
||||
->latest('id')
|
||||
->limit(8)
|
||||
->get();
|
||||
|
||||
$prices = PlatformPrice::query()
|
||||
->when(Schema::hasColumn('platform_prices', 'is_active'), static function ($query): void {
|
||||
$query->where('is_active', true);
|
||||
})
|
||||
->when(Schema::hasColumn('platform_prices', 'active'), static function ($query): void {
|
||||
$query->where('active', true);
|
||||
})
|
||||
->orderBy('sort_order')
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
return view('platform::dashboard.index', [
|
||||
'companiesCount' => Company::query()->count(),
|
||||
'activeCompaniesCount' => Company::query()->where('status', 'active')->count(),
|
||||
'licensesCount' => LicenseKey::query()->count(),
|
||||
'warehousesCount' => Warehouse::query()->count(),
|
||||
'pricesCount' => PlatformPrice::query()->count(),
|
||||
'paymentsTotal' => Payment::query()->where('status', 'paid')->sum('amount'),
|
||||
'companies' => $companies,
|
||||
'prices' => $prices,
|
||||
'companyUsageChartLabels' => $companies->pluck('name')->values(),
|
||||
'companyUsageChartSeries' => [
|
||||
'Users' => $companies->pluck('users_count')->values(),
|
||||
'Warehouses' => $companies->pluck('warehouses_count')->values(),
|
||||
'Licences' => $companies->pluck('license_keys_count')->values(),
|
||||
],
|
||||
'platformMixChartLabels' => ['Companies', 'Warehouses', 'Licences'],
|
||||
'platformMixChartValues' => [
|
||||
Company::query()->count(),
|
||||
Warehouse::query()->count(),
|
||||
LicenseKey::query()->count(),
|
||||
],
|
||||
'companyStatusChartLabels' => ['Active', 'Inactive'],
|
||||
'companyStatusChartValues' => [
|
||||
Company::query()->where('status', 'active')->count(),
|
||||
Company::query()->where('status', 'inactive')->count(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Platform\app\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\View\View;
|
||||
use Modules\Platform\app\Models\PlatformPrice;
|
||||
|
||||
class PlatformPriceController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the customer-facing platform pricing cards.
|
||||
*/
|
||||
public function publicIndex(): View
|
||||
{
|
||||
return view('platform::prices.public', [
|
||||
'prices' => PlatformPrice::query()
|
||||
->where('is_active', true)
|
||||
->ordered()
|
||||
->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display platform prices in a card grid with administration actions.
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
return view('platform::prices.index', [
|
||||
'prices' => PlatformPrice::ordered()->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the create price form.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('platform::prices.create', [
|
||||
'price' => new PlatformPrice([
|
||||
'currency' => 'gbp',
|
||||
'sort_order' => 40,
|
||||
'is_active' => true,
|
||||
'features' => [],
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a new platform price.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
PlatformPrice::create($this->validatedPriceData($request));
|
||||
|
||||
return redirect()->route('platform.prices.index')->with('status', 'Price created.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the edit price form.
|
||||
*/
|
||||
public function edit(PlatformPrice $price): View
|
||||
{
|
||||
return view('platform::prices.edit', [
|
||||
'price' => $price,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing platform price.
|
||||
*/
|
||||
public function update(Request $request, PlatformPrice $price): RedirectResponse
|
||||
{
|
||||
$price->update($this->validatedPriceData($request, $price));
|
||||
|
||||
return redirect()->route('platform.prices.index')->with('status', 'Price updated.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a platform price.
|
||||
*/
|
||||
public function destroy(PlatformPrice $price): RedirectResponse
|
||||
{
|
||||
$price->delete();
|
||||
|
||||
return redirect()->route('platform.prices.index')->with('status', 'Price deleted.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate and normalise price request data.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function validatedPriceData(Request $request, ?PlatformPrice $price = null): array
|
||||
{
|
||||
$data = $request->validate([
|
||||
'code' => ['nullable', 'string', 'max:40', 'unique:platform_prices,code,' . ($price?->id ?? 'NULL')],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'strapline' => ['nullable', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string', 'max:2000'],
|
||||
'monthly_amount' => ['required', 'numeric', 'min:0', 'max:999999.99'],
|
||||
'annual_amount' => ['nullable', 'numeric', 'min:0', 'max:999999.99'],
|
||||
'currency' => ['required', 'string', 'size:3'],
|
||||
'badge_label' => ['nullable', 'string', 'max:60'],
|
||||
'features' => ['nullable', 'string', 'max:4000'],
|
||||
'sort_order' => ['required', 'integer', 'min:0', 'max:65535'],
|
||||
'is_featured' => ['nullable', 'boolean'],
|
||||
'is_active' => ['nullable', 'boolean'],
|
||||
]);
|
||||
|
||||
$data['code'] = Str::slug($data['code'] ?: $data['name']);
|
||||
$data['monthly_amount'] = (int) round(((float) $data['monthly_amount']) * 100);
|
||||
$data['annual_amount'] = $data['annual_amount'] === null || $data['annual_amount'] === ''
|
||||
? null
|
||||
: (int) round(((float) $data['annual_amount']) * 100);
|
||||
$data['currency'] = strtolower($data['currency']);
|
||||
$data['features'] = collect(preg_split('/\r\n|\r|\n/', (string) ($data['features'] ?? '')))
|
||||
->map(fn (string $feature): string => trim($feature))
|
||||
->filter()
|
||||
->values()
|
||||
->all();
|
||||
$data['is_featured'] = $request->boolean('is_featured');
|
||||
$data['is_active'] = $request->boolean('is_active');
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Platform\app\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Company\Models\Company;
|
||||
use Modules\Platform\app\Models\Payment;
|
||||
|
||||
class StripeWebhookController extends Controller
|
||||
{
|
||||
/**
|
||||
* Receive a Stripe webhook event.
|
||||
*/
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
$payload = $request->all();
|
||||
$eventType = data_get($payload, 'type');
|
||||
|
||||
if ($eventType === 'payment_intent.succeeded') {
|
||||
$intent = data_get($payload, 'data.object', []);
|
||||
$company = Company::where('stripe_customer_id', data_get($intent, 'customer'))->first();
|
||||
|
||||
if ($company) {
|
||||
Payment::updateOrCreate(
|
||||
['stripe_payment_intent_id' => data_get($intent, 'id')],
|
||||
[
|
||||
'company_id' => $company->id,
|
||||
'amount' => (int) data_get($intent, 'amount_received', 0),
|
||||
'currency' => (string) data_get($intent, 'currency', 'gbp'),
|
||||
'status' => 'paid',
|
||||
'description' => 'Stripe payment received',
|
||||
'paid_at' => now(),
|
||||
'metadata' => $intent,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json(['received' => true]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Platform\app\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class EnsureLicensedTenant
|
||||
{
|
||||
/**
|
||||
* Ensure the current company has an active licence unless it is the MPBA platform tenant.
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
$company = $user?->company;
|
||||
|
||||
abort_if(! $company, 403, 'No company is assigned to this account.');
|
||||
|
||||
if ($user->isMpbaPlatformAdmin()) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
abort_unless($company->hasActiveLicense(), 402, 'Payment Required');
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Platform\app\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class EnsurePlatformAdmin
|
||||
{
|
||||
/**
|
||||
* Ensure the current user is an MPBA platform administrator.
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
abort_unless($request->user()?->isMpbaPlatformAdmin(), 403);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Platform\app\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class EnsureTenantAssigned
|
||||
{
|
||||
/**
|
||||
* Ensure the authenticated user belongs to a company tenant.
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
abort_if(! $user || ! $user->company_id, 403, 'No company is assigned to this account.');
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Platform\app\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\Company\Models\Company;
|
||||
|
||||
class LicenseKey extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'company_id', 'key_hash', 'key_prefix', 'label', 'plan', 'max_users',
|
||||
'is_active', 'starts_at', 'expires_at', 'last_used_at', 'revoked_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'starts_at' => 'datetime',
|
||||
'expires_at' => 'datetime',
|
||||
'last_used_at' => 'datetime',
|
||||
'revoked_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function company(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
||||
public static function issueFor(Company $company, string $label, string $plan = 'standard', int $maxUsers = 10): string
|
||||
{
|
||||
$plainKey = 'WMS-' . Str::upper(Str::random(32));
|
||||
|
||||
self::create([
|
||||
'company_id' => $company->id,
|
||||
'key_hash' => hash('sha256', $plainKey),
|
||||
'key_prefix' => Str::substr($plainKey, 0, 12),
|
||||
'label' => $label,
|
||||
'plan' => $plan,
|
||||
'max_users' => $maxUsers,
|
||||
'is_active' => true,
|
||||
'starts_at' => now(),
|
||||
'expires_at' => now()->addYear(),
|
||||
]);
|
||||
|
||||
return $plainKey;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Platform\app\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Modules\Company\Models\Company;
|
||||
|
||||
class Payment extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'company_id', 'stripe_payment_intent_id', 'stripe_invoice_id', 'amount',
|
||||
'currency', 'status', 'description', 'paid_at', 'metadata',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'amount' => 'integer',
|
||||
'paid_at' => 'datetime',
|
||||
'metadata' => 'array',
|
||||
];
|
||||
|
||||
public function company(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Platform\app\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PlatformPrice extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'name',
|
||||
'strapline',
|
||||
'description',
|
||||
'monthly_amount',
|
||||
'annual_amount',
|
||||
'currency',
|
||||
'badge_label',
|
||||
'features',
|
||||
'sort_order',
|
||||
'is_featured',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'features' => 'array',
|
||||
'monthly_amount' => 'integer',
|
||||
'annual_amount' => 'integer',
|
||||
'sort_order' => 'integer',
|
||||
'is_featured' => 'boolean',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Scope prices into display order.
|
||||
*/
|
||||
public function scopeOrdered(Builder $query): Builder
|
||||
{
|
||||
return $query->orderBy('sort_order')->orderBy('name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the display currency symbol.
|
||||
*/
|
||||
public function currencySymbol(): string
|
||||
{
|
||||
return match (strtolower($this->currency)) {
|
||||
'gbp' => '£',
|
||||
'eur' => '€',
|
||||
'usd' => '$',
|
||||
default => strtoupper($this->currency) . ' ',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a stored minor-unit amount for display.
|
||||
*/
|
||||
public function formatAmount(?int $amount): string
|
||||
{
|
||||
if ($amount === null) {
|
||||
return '—';
|
||||
}
|
||||
|
||||
return $this->currencySymbol() . number_format($amount / 100, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return normalised feature rows.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function featureRows(): array
|
||||
{
|
||||
return collect($this->features ?? [])
|
||||
->filter(fn ($feature): bool => is_string($feature) && trim($feature) !== '')
|
||||
->map(fn (string $feature): string => trim($feature))
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'system_company_slug' => env('WMS_SYSTEM_COMPANY_SLUG', 'mpba-limited'),
|
||||
'system_admin_email' => env('WMS_SYSTEM_ADMIN_EMAIL', 'mark.gregory@mpba.co.uk'),
|
||||
'internal_api_key' => env('WMS_INTERNAL_API_KEY', 'local-dev-change-me'),
|
||||
'stripe' => [
|
||||
'key' => env('STRIPE_KEY'),
|
||||
'secret' => env('STRIPE_SECRET'),
|
||||
'webhook_secret' => env('STRIPE_WEBHOOK_SECRET'),
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('companies', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->uuid('uuid')->unique();
|
||||
$table->string('name');
|
||||
$table->string('slug')->unique();
|
||||
$table->string('status')->default('active')->index();
|
||||
$table->string('timezone')->default('Europe/London');
|
||||
$table->boolean('is_system_company')->default(false)->index();
|
||||
$table->string('stripe_customer_id')->nullable()->index();
|
||||
$table->string('billing_email')->nullable();
|
||||
$table->json('settings')->nullable();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
|
||||
Schema::table('users', function (Blueprint $table): void {
|
||||
$table->foreignId('company_id')->nullable()->after('id')->constrained('companies')->nullOnDelete();
|
||||
$table->boolean('is_platform_admin')->default(false)->after('password');
|
||||
$table->boolean('is_company_admin')->default(false)->after('is_platform_admin');
|
||||
$table->string('status')->default('active')->after('is_company_admin')->index();
|
||||
});
|
||||
|
||||
Schema::create('license_keys', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('company_id')->constrained('companies')->cascadeOnDelete();
|
||||
$table->string('key_hash', 64)->unique();
|
||||
$table->string('key_prefix', 16)->index();
|
||||
$table->string('label');
|
||||
$table->string('plan')->default('standard')->index();
|
||||
$table->unsignedInteger('max_users')->default(10);
|
||||
$table->boolean('is_active')->default(true)->index();
|
||||
$table->timestamp('starts_at')->nullable();
|
||||
$table->timestamp('expires_at')->nullable()->index();
|
||||
$table->timestamp('last_used_at')->nullable();
|
||||
$table->timestamp('revoked_at')->nullable()->index();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('payments', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('company_id')->constrained('companies')->cascadeOnDelete();
|
||||
$table->string('stripe_payment_intent_id')->nullable()->unique();
|
||||
$table->string('stripe_invoice_id')->nullable()->index();
|
||||
$table->unsignedInteger('amount')->default(0);
|
||||
$table->string('currency', 3)->default('gbp');
|
||||
$table->string('status')->default('pending')->index();
|
||||
$table->string('description')->nullable();
|
||||
$table->timestamp('paid_at')->nullable();
|
||||
$table->json('metadata')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::disableForeignKeyConstraints();
|
||||
|
||||
Schema::dropIfExists('payments');
|
||||
Schema::dropIfExists('license_keys');
|
||||
|
||||
Schema::table('users', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('company_id');
|
||||
$table->dropColumn([
|
||||
'is_platform_admin',
|
||||
'is_company_admin',
|
||||
'status',
|
||||
]);
|
||||
});
|
||||
|
||||
Schema::dropIfExists('companies');
|
||||
|
||||
Schema::enableForeignKeyConstraints();
|
||||
}
|
||||
};
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('platform_prices', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('code', 40)->unique();
|
||||
$table->string('name');
|
||||
$table->string('strapline')->nullable();
|
||||
$table->text('description')->nullable();
|
||||
$table->unsignedInteger('monthly_amount')->default(0);
|
||||
$table->unsignedInteger('annual_amount')->nullable();
|
||||
$table->string('currency', 3)->default('gbp');
|
||||
$table->string('badge_label')->nullable();
|
||||
$table->json('features')->nullable();
|
||||
$table->unsignedSmallInteger('sort_order')->default(0)->index();
|
||||
$table->boolean('is_featured')->default(false)->index();
|
||||
$table->boolean('is_active')->default(true)->index();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('platform_prices');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Platform\database\seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\Company\Models\Company;
|
||||
use Modules\Warehouse\app\Models\Warehouse;
|
||||
use Modules\Warehouse\app\Models\WarehouseValidationRule;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class PlatformSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Seed the MPBA system tenant and administrator.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$role = Role::findOrCreate('platform-admin', 'web');
|
||||
|
||||
$company = Company::updateOrCreate(
|
||||
['slug' => 'mpba-limited'],
|
||||
[
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'name' => 'MPBA Limited',
|
||||
'status' => 'active',
|
||||
'timezone' => 'Europe/London',
|
||||
'is_system_company' => true,
|
||||
'billing_email' => 'mark.gregory@mpba.co.uk',
|
||||
],
|
||||
);
|
||||
|
||||
$user = User::updateOrCreate(
|
||||
['email' => 'mark.gregory@mpba.co.uk'],
|
||||
[
|
||||
'company_id' => $company->id,
|
||||
'name' => 'Mark Gregory',
|
||||
'password' => Hash::make('987400Kmh'),
|
||||
'is_platform_admin' => true,
|
||||
'is_company_admin' => true,
|
||||
'status' => 'active',
|
||||
'email_verified_at' => now(),
|
||||
],
|
||||
);
|
||||
$user->assignRole($role);
|
||||
$user = User::updateOrCreate(
|
||||
['email' => 'david.price@mpba.co.uk'],
|
||||
[
|
||||
'company_id' => $company->id,
|
||||
'name' => 'David Price',
|
||||
'password' => Hash::make('Password1'),
|
||||
'is_platform_admin' => true,
|
||||
'is_company_admin' => true,
|
||||
'status' => 'active',
|
||||
'email_verified_at' => now(),
|
||||
],
|
||||
);
|
||||
$user->assignRole($role);
|
||||
$warehouse = Warehouse::firstOrNew([
|
||||
'company_id' => $company->id,
|
||||
'code' => 'MPBA-MAIN',
|
||||
]);
|
||||
|
||||
$warehouse->forceFill([
|
||||
'uuid' => $warehouse->uuid ?: (string) Str::uuid(),
|
||||
'name' => 'MPBA Main Warehouse',
|
||||
'status' => 'active',
|
||||
'timezone' => 'Europe/London',
|
||||
])->save();
|
||||
|
||||
WarehouseValidationRule::updateOrCreate(
|
||||
['warehouse_id' => $warehouse->id, 'rule_key' => 'stock.location.required'],
|
||||
['name' => 'Stock location required', 'severity' => 'error', 'is_active' => true, 'configuration' => ['required' => true]],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"name":"Platform","alias":"platform","description":"System administration, tenants, licences, Stripe payments and tenant guards.","keywords":["wms","multi-tenant","licensing"],"priority":0,"providers":["Modules\\Platform\\Providers\\PlatformServiceProvider"],"files":[]}
|
||||
@@ -0,0 +1,99 @@
|
||||
<x-layouts.app :title="__('Platform Dashboard')">
|
||||
<div class="space-y-6">
|
||||
<x-wms.page-hero title="Platform Dashboard"
|
||||
description="System-level tenant, licence, pricing and operational oversight for the WMS platform."
|
||||
eyebrow="Platform Administration" />
|
||||
|
||||
<section class="grid gap-4 md:grid-cols-2 xl:grid-cols-5">
|
||||
<article
|
||||
class="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm dark:border-slate-800 dark:bg-slate-950">
|
||||
<p class="text-sm font-medium text-slate-500 dark:text-slate-400">Companies</p>
|
||||
<p class="mt-2 text-3xl font-semibold text-slate-950 dark:text-white">
|
||||
{{ number_format($companiesCount ?? 0) }}</p>
|
||||
</article>
|
||||
|
||||
<article
|
||||
class="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm dark:border-slate-800 dark:bg-slate-950">
|
||||
<p class="text-sm font-medium text-slate-500 dark:text-slate-400">Active</p>
|
||||
<p class="mt-2 text-3xl font-semibold text-emerald-700 dark:text-emerald-300">
|
||||
{{ number_format($activeCompaniesCount ?? 0) }}</p>
|
||||
</article>
|
||||
|
||||
<article
|
||||
class="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm dark:border-slate-800 dark:bg-slate-950">
|
||||
<p class="text-sm font-medium text-slate-500 dark:text-slate-400">Warehouses</p>
|
||||
<p class="mt-2 text-3xl font-semibold text-slate-950 dark:text-white">
|
||||
{{ number_format($warehousesCount ?? 0) }}</p>
|
||||
</article>
|
||||
|
||||
<article
|
||||
class="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm dark:border-slate-800 dark:bg-slate-950">
|
||||
<p class="text-sm font-medium text-slate-500 dark:text-slate-400">Prices</p>
|
||||
<p class="mt-2 text-3xl font-semibold text-slate-950 dark:text-white">
|
||||
{{ number_format($pricesCount ?? 0) }}</p>
|
||||
</article>
|
||||
|
||||
<article
|
||||
class="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm dark:border-slate-800 dark:bg-slate-950">
|
||||
<p class="text-sm font-medium text-slate-500 dark:text-slate-400">Licences</p>
|
||||
<p class="mt-2 text-3xl font-semibold text-slate-950 dark:text-white">
|
||||
{{ number_format($licensesCount ?? 0) }}</p>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
|
||||
<section class="grid gap-6 xl:grid-cols-3">
|
||||
<article
|
||||
class="rounded-2xl border border-slate-200 bg-white p-6 shadow-sm dark:border-slate-800 dark:bg-slate-950 xl:col-span-1">
|
||||
<h2 class="text-lg font-semibold text-slate-950 dark:text-white">Administration shortcuts</h2>
|
||||
<div class="mt-4 grid gap-3">
|
||||
<a href="{{ route('platform.companies.index') }}"
|
||||
class="rounded-xl border border-slate-200 p-3 text-sm font-semibold hover:bg-slate-50 dark:border-slate-800 dark:hover:bg-slate-900">Manage
|
||||
companies</a>
|
||||
<a href="{{ route('platform.prices.index') }}"
|
||||
class="rounded-xl border border-slate-200 p-3 text-sm font-semibold hover:bg-slate-50 dark:border-slate-800 dark:hover:bg-slate-900">Manage
|
||||
prices</a>
|
||||
<a href="{{ route('platform.pricing.index') }}"
|
||||
class="rounded-xl border border-slate-200 p-3 text-sm font-semibold hover:bg-slate-50 dark:border-slate-800 dark:hover:bg-slate-900">View
|
||||
public pricing</a>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<article
|
||||
class="rounded-2xl border border-slate-200 bg-white p-6 shadow-sm dark:border-slate-800 dark:bg-slate-950 xl:col-span-2">
|
||||
<h2 class="text-lg font-semibold text-slate-950 dark:text-white">Recent companies</h2>
|
||||
<div class="mt-4 overflow-hidden rounded-xl border border-slate-200 dark:border-slate-800">
|
||||
<table class="min-w-full divide-y divide-slate-200 text-sm dark:divide-slate-800">
|
||||
<thead
|
||||
class="bg-slate-50 text-left text-xs uppercase tracking-wide text-slate-500 dark:bg-slate-900 dark:text-slate-400">
|
||||
<tr>
|
||||
<th class="px-4 py-3">Company</th>
|
||||
<th class="px-4 py-3">Users</th>
|
||||
<th class="px-4 py-3">Warehouses</th>
|
||||
<th class="px-4 py-3">Licences</th>
|
||||
<th class="px-4 py-3">Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-slate-200 dark:divide-slate-800">
|
||||
@forelse (($companies ?? collect()) as $company)
|
||||
<tr>
|
||||
<td class="px-4 py-3 font-medium text-slate-950 dark:text-white">
|
||||
{{ $company->name }}</td>
|
||||
<td class="px-4 py-3">{{ $company->users_count ?? 0 }}</td>
|
||||
<td class="px-4 py-3">{{ $company->warehouses_count ?? 0 }}</td>
|
||||
<td class="px-4 py-3">{{ $company->license_keys_count ?? 0 }}</td>
|
||||
<td class="px-4 py-3">{{ ucfirst($company->status ?? 'active') }}</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="5" class="px-4 py-6 text-center text-slate-500 dark:text-slate-400">
|
||||
No companies have been created yet.</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
</div>
|
||||
</x-layouts.app>
|
||||
@@ -0,0 +1,59 @@
|
||||
<x-layouts::app :title="__('Licence Keys')">
|
||||
<div class="space-y-6">
|
||||
<x-wms.page-hero eyebrow="Platform Administration" title="Licence Keys"
|
||||
description="Issue and monitor company licence keys, limits and platform access plans."
|
||||
icon="fa-solid fa-key" />
|
||||
@if ($plainKey)
|
||||
<div class="rounded-2xl bg-emerald-50 p-4 text-emerald-900 ring-1 ring-emerald-200">New key: <code
|
||||
class="font-bold">{{ $plainKey }}</code></div>
|
||||
@endif
|
||||
<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">Issue licence key</h2>
|
||||
<form method="POST" action="{{ route('platform.licenses.store') }}" class="mt-5 grid gap-4 md:grid-cols-5">
|
||||
@csrf
|
||||
<select name="company_id" class="rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950">
|
||||
@foreach ($companies as $company)
|
||||
<option value="{{ $company->id }}">{{ $company->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<input name="label" placeholder="Licence label"
|
||||
class="rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950" required>
|
||||
<select name="plan" class="rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950">
|
||||
<option>standard</option>
|
||||
<option>professional</option>
|
||||
<option>enterprise</option>
|
||||
</select>
|
||||
<input name="max_users" type="number" value="10"
|
||||
class="rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950" required>
|
||||
<button
|
||||
class="rounded-xl bg-zinc-900 px-4 py-2 font-semibold text-white dark:bg-white dark:text-zinc-900">Issue</button>
|
||||
</form>
|
||||
</div>
|
||||
<div
|
||||
class="overflow-x-auto rounded-2xl bg-white shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
|
||||
<table class="min-w-full text-sm">
|
||||
<thead>
|
||||
<tr class="border-b">
|
||||
<th class="p-4 text-left">Company</th>
|
||||
<th class="p-4 text-left">Label</th>
|
||||
<th class="p-4 text-left">Plan</th>
|
||||
<th class="p-4 text-left">Prefix</th>
|
||||
<th class="p-4 text-left">Expires</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($licenses as $license)
|
||||
<tr class="border-b border-zinc-100 dark:border-zinc-800">
|
||||
<td class="p-4">{{ $license->company->name }}</td>
|
||||
<td class="p-4 font-semibold">{{ $license->label }}</td>
|
||||
<td class="p-4">{{ $license->plan }}</td>
|
||||
<td class="p-4"><code>{{ $license->key_prefix }}</code></td>
|
||||
<td class="p-4">{{ optional($license->expires_at)->toDateString() }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{ $licenses->links() }}
|
||||
</div>
|
||||
</x-layouts::app>
|
||||
@@ -0,0 +1,7 @@
|
||||
@props(['title' => 'WMS Platform'])
|
||||
|
||||
<div class="min-h-screen bg-zinc-50 dark:bg-zinc-950">
|
||||
<div class="mx-auto flex max-w-7xl flex-col gap-6 px-4 py-6 sm:px-6 lg:px-8">
|
||||
{{ $slot }}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,58 @@
|
||||
<x-layouts::app :title="__('Payments')">
|
||||
<div class="space-y-6">
|
||||
<x-wms.page-hero eyebrow="Platform Administration" title="Payments and Overrides"
|
||||
description="Record platform payments, manual overrides and billing status by company."
|
||||
icon="fa-solid fa-credit-card" />
|
||||
<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">Add payment or override</h2>
|
||||
<form method="POST" action="{{ route('platform.payments.store') }}" class="mt-5 grid gap-4 md:grid-cols-6">
|
||||
@csrf
|
||||
<select name="company_id" class="rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950">
|
||||
@foreach ($companies as $company)
|
||||
<option value="{{ $company->id }}">{{ $company->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<input name="amount" type="number" value="0"
|
||||
class="rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950" required>
|
||||
<input name="currency" value="gbp"
|
||||
class="rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950" required>
|
||||
<select name="status" class="rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950">
|
||||
<option>paid</option>
|
||||
<option>pending</option>
|
||||
<option>failed</option>
|
||||
<option>refunded</option>
|
||||
<option>override</option>
|
||||
</select>
|
||||
<input name="description" placeholder="Description"
|
||||
class="rounded-xl border-zinc-300 dark:border-zinc-700 dark:bg-zinc-950">
|
||||
<button
|
||||
class="rounded-xl bg-zinc-900 px-4 py-2 font-semibold text-white dark:bg-white dark:text-zinc-900">Add</button>
|
||||
</form>
|
||||
</div>
|
||||
<div
|
||||
class="overflow-x-auto rounded-2xl bg-white shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-900 dark:ring-zinc-800">
|
||||
<table class="min-w-full text-sm">
|
||||
<thead>
|
||||
<tr class="border-b">
|
||||
<th class="p-4 text-left">Company</th>
|
||||
<th class="p-4 text-left">Amount</th>
|
||||
<th class="p-4 text-left">Status</th>
|
||||
<th class="p-4 text-left">Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($payments as $payment)
|
||||
<tr class="border-b border-zinc-100 dark:border-zinc-800">
|
||||
<td class="p-4">{{ $payment->company->name }}</td>
|
||||
<td class="p-4 font-semibold">{{ strtoupper($payment->currency) }}
|
||||
{{ number_format($payment->amount / 100, 2) }}</td>
|
||||
<td class="p-4">{{ $payment->status }}</td>
|
||||
<td class="p-4">{{ $payment->description }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{ $payments->links() }}
|
||||
</div>
|
||||
</x-layouts::app>
|
||||
@@ -0,0 +1,125 @@
|
||||
@php
|
||||
$featuresText = old('features', implode("\n", $price->featureRows()));
|
||||
@endphp
|
||||
|
||||
<div class="grid gap-5 lg:grid-cols-2">
|
||||
<div>
|
||||
<label for="name" class="text-sm font-semibold text-zinc-700 dark:text-zinc-200">Name</label>
|
||||
<input id="name" name="name" value="{{ old('name', $price->name) }}" required
|
||||
class="mt-2 w-full rounded-xl border-zinc-300 bg-white px-4 py-3 text-sm dark:border-zinc-700 dark:bg-zinc-950"
|
||||
placeholder="Basic">
|
||||
@error('name')
|
||||
<p class="mt-1 text-sm text-red-500">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="code" class="text-sm font-semibold text-zinc-700 dark:text-zinc-200">Code</label>
|
||||
<input id="code" name="code" value="{{ old('code', $price->code) }}"
|
||||
class="mt-2 w-full rounded-xl border-zinc-300 bg-white px-4 py-3 text-sm dark:border-zinc-700 dark:bg-zinc-950"
|
||||
placeholder="basic">
|
||||
@error('code')
|
||||
<p class="mt-1 text-sm text-red-500">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="strapline" class="text-sm font-semibold text-zinc-700 dark:text-zinc-200">Strapline</label>
|
||||
<input id="strapline" name="strapline" value="{{ old('strapline', $price->strapline) }}"
|
||||
class="mt-2 w-full rounded-xl border-zinc-300 bg-white px-4 py-3 text-sm dark:border-zinc-700 dark:bg-zinc-950"
|
||||
placeholder="Core warehouse visibility">
|
||||
@error('strapline')
|
||||
<p class="mt-1 text-sm text-red-500">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="badge_label" class="text-sm font-semibold text-zinc-700 dark:text-zinc-200">Badge label</label>
|
||||
<input id="badge_label" name="badge_label" value="{{ old('badge_label', $price->badge_label) }}"
|
||||
class="mt-2 w-full rounded-xl border-zinc-300 bg-white px-4 py-3 text-sm dark:border-zinc-700 dark:bg-zinc-950"
|
||||
placeholder="Popular">
|
||||
@error('badge_label')
|
||||
<p class="mt-1 text-sm text-red-500">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="monthly_amount" class="text-sm font-semibold text-zinc-700 dark:text-zinc-200">Monthly price</label>
|
||||
<input id="monthly_amount" name="monthly_amount" type="number" step="0.01" min="0"
|
||||
value="{{ old('monthly_amount', $price->exists ? number_format($price->monthly_amount / 100, 2, '.', '') : '0.00') }}"
|
||||
required
|
||||
class="mt-2 w-full rounded-xl border-zinc-300 bg-white px-4 py-3 text-sm dark:border-zinc-700 dark:bg-zinc-950"
|
||||
placeholder="99.00">
|
||||
@error('monthly_amount')
|
||||
<p class="mt-1 text-sm text-red-500">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="annual_amount" class="text-sm font-semibold text-zinc-700 dark:text-zinc-200">Annual price</label>
|
||||
<input id="annual_amount" name="annual_amount" type="number" step="0.01" min="0"
|
||||
value="{{ old('annual_amount', $price->annual_amount !== null ? number_format($price->annual_amount / 100, 2, '.', '') : '') }}"
|
||||
class="mt-2 w-full rounded-xl border-zinc-300 bg-white px-4 py-3 text-sm dark:border-zinc-700 dark:bg-zinc-950"
|
||||
placeholder="990.00">
|
||||
@error('annual_amount')
|
||||
<p class="mt-1 text-sm text-red-500">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="currency" class="text-sm font-semibold text-zinc-700 dark:text-zinc-200">Currency</label>
|
||||
<input id="currency" name="currency" value="{{ old('currency', $price->currency ?: 'gbp') }}" maxlength="3"
|
||||
required
|
||||
class="mt-2 w-full rounded-xl border-zinc-300 bg-white px-4 py-3 text-sm uppercase dark:border-zinc-700 dark:bg-zinc-950"
|
||||
placeholder="gbp">
|
||||
@error('currency')
|
||||
<p class="mt-1 text-sm text-red-500">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="sort_order" class="text-sm font-semibold text-zinc-700 dark:text-zinc-200">Sort order</label>
|
||||
<input id="sort_order" name="sort_order" type="number" min="0"
|
||||
value="{{ old('sort_order', $price->sort_order ?? 0) }}" required
|
||||
class="mt-2 w-full rounded-xl border-zinc-300 bg-white px-4 py-3 text-sm dark:border-zinc-700 dark:bg-zinc-950">
|
||||
@error('sort_order')
|
||||
<p class="mt-1 text-sm text-red-500">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="lg:col-span-2">
|
||||
<label for="description" class="text-sm font-semibold text-zinc-700 dark:text-zinc-200">Description</label>
|
||||
<textarea id="description" name="description" rows="3"
|
||||
class="mt-2 w-full rounded-xl border-zinc-300 bg-white px-4 py-3 text-sm dark:border-zinc-700 dark:bg-zinc-950"
|
||||
placeholder="Short customer-facing description">{{ old('description', $price->description) }}</textarea>
|
||||
@error('description')
|
||||
<p class="mt-1 text-sm text-red-500">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="lg:col-span-2">
|
||||
<label for="features" class="text-sm font-semibold text-zinc-700 dark:text-zinc-200">Features</label>
|
||||
<textarea id="features" name="features" rows="6"
|
||||
class="mt-2 w-full rounded-xl border-zinc-300 bg-white px-4 py-3 text-sm dark:border-zinc-700 dark:bg-zinc-950"
|
||||
placeholder="One feature per line">{{ $featuresText }}</textarea>
|
||||
@error('features')
|
||||
<p class="mt-1 text-sm text-red-500">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap gap-4 lg:col-span-2">
|
||||
<label
|
||||
class="inline-flex items-center gap-2 rounded-xl border border-zinc-200 bg-zinc-50 px-4 py-3 text-sm font-semibold dark:border-zinc-800 dark:bg-zinc-950">
|
||||
<input type="checkbox" name="is_featured" value="1" @checked(old('is_featured', $price->is_featured))
|
||||
class="rounded border-zinc-300">
|
||||
Featured price
|
||||
</label>
|
||||
|
||||
<label
|
||||
class="inline-flex items-center gap-2 rounded-xl border border-zinc-200 bg-zinc-50 px-4 py-3 text-sm font-semibold dark:border-zinc-800 dark:bg-zinc-950">
|
||||
<input type="checkbox" name="is_active" value="1" @checked(old('is_active', $price->is_active ?? true))
|
||||
class="rounded border-zinc-300">
|
||||
Active
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,29 @@
|
||||
<x-layouts::app :title="__('Create Price')">
|
||||
<div class="space-y-6">
|
||||
<x-wms.page-hero eyebrow="Administration" title="Create Price"
|
||||
description="Add a professional pricing card with billing values, feature bullets and visibility controls."
|
||||
icon="fa-solid fa-circle-plus">
|
||||
<a href="{{ route('platform.prices.index') }}" wire:navigate
|
||||
class="rounded-xl bg-white px-4 py-3 text-sm font-bold text-slate-950 shadow-lg hover:bg-cyan-50">
|
||||
Back to prices
|
||||
</a>
|
||||
</x-wms.page-hero>
|
||||
<section class="rounded-3xl border border-zinc-200 bg-white p-6 shadow-sm dark:border-zinc-800 dark:bg-zinc-900">
|
||||
<form method="POST" action="{{ route('platform.prices.store') }}" class="space-y-6">
|
||||
@csrf
|
||||
@include('platform::prices._form')
|
||||
|
||||
<div class="flex flex-wrap justify-end gap-3 border-t border-zinc-100 pt-5 dark:border-zinc-800">
|
||||
<a href="{{ route('platform.prices.index') }}" wire:navigate
|
||||
class="rounded-xl border border-zinc-200 px-5 py-3 text-sm font-semibold text-zinc-700 dark:border-zinc-700 dark:text-zinc-200">
|
||||
Cancel
|
||||
</a>
|
||||
<button type="submit"
|
||||
class="rounded-xl bg-cyan-600 px-5 py-3 text-sm font-bold text-white shadow-lg shadow-cyan-950/20 hover:bg-cyan-500">
|
||||
Create price
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
</x-layouts::app>
|
||||
@@ -0,0 +1,30 @@
|
||||
<x-layouts::app :title="__('Edit Price')">
|
||||
<div class="space-y-6">
|
||||
<x-wms.page-hero eyebrow="Administration" :title="'Edit ' . $price->name"
|
||||
description="Update pricing, feature text and card visibility while keeping the platform pricing display consistent."
|
||||
icon="fa-solid fa-pen-to-square">
|
||||
<a href="{{ route('platform.prices.index') }}" wire:navigate
|
||||
class="rounded-xl bg-white px-4 py-3 text-sm font-bold text-slate-950 shadow-lg hover:bg-cyan-50">
|
||||
Back to prices
|
||||
</a>
|
||||
</x-wms.page-hero>
|
||||
<section class="rounded-3xl border border-zinc-200 bg-white p-6 shadow-sm dark:border-zinc-800 dark:bg-zinc-900">
|
||||
<form method="POST" action="{{ route('platform.prices.update', $price) }}" class="space-y-6">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
@include('platform::prices._form')
|
||||
|
||||
<div class="flex flex-wrap justify-end gap-3 border-t border-zinc-100 pt-5 dark:border-zinc-800">
|
||||
<a href="{{ route('platform.prices.index') }}" wire:navigate
|
||||
class="rounded-xl border border-zinc-200 px-5 py-3 text-sm font-semibold text-zinc-700 dark:border-zinc-700 dark:text-zinc-200">
|
||||
Cancel
|
||||
</a>
|
||||
<button type="submit"
|
||||
class="rounded-xl bg-cyan-600 px-5 py-3 text-sm font-bold text-white shadow-lg shadow-cyan-950/20 hover:bg-cyan-500">
|
||||
Save changes
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
</x-layouts::app>
|
||||
@@ -0,0 +1,119 @@
|
||||
<x-layouts::app :title="__('Platform Prices')">
|
||||
<div class="space-y-6">
|
||||
<x-wms.page-hero eyebrow="Administration" title="Pricing Administration"
|
||||
description="Create, edit and publish the platform pricing cards shown under Platform."
|
||||
icon="fa-solid fa-tags">
|
||||
<a href="{{ route('platform.prices.create') }}" wire:navigate
|
||||
class="rounded-xl bg-white px-4 py-3 text-sm font-bold text-slate-950 shadow-lg hover:bg-cyan-50">
|
||||
Add price
|
||||
</a>
|
||||
</x-wms.page-hero>
|
||||
@if (session('status'))
|
||||
<div
|
||||
class="rounded-2xl border border-emerald-200 bg-emerald-50 px-5 py-4 text-sm font-semibold text-emerald-800 dark:border-emerald-900/60 dark:bg-emerald-950/40 dark:text-emerald-200">
|
||||
{{ session('status') }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<section class="grid gap-5 lg:grid-cols-3">
|
||||
@forelse ($prices as $price)
|
||||
@php
|
||||
$isBasic = $price->code === 'basic';
|
||||
$isAdvanced = $price->code === 'advanced';
|
||||
$headerClass = $isAdvanced
|
||||
? 'from-cyan-500 to-blue-600'
|
||||
: ($isBasic
|
||||
? 'from-slate-700 to-slate-900'
|
||||
: 'from-indigo-600 to-violet-700');
|
||||
@endphp
|
||||
|
||||
<article
|
||||
class="relative overflow-hidden rounded-3xl border border-zinc-200 bg-white shadow-sm transition hover:-translate-y-0.5 hover:shadow-xl dark:border-zinc-800 dark:bg-zinc-900">
|
||||
@if ($price->is_featured)
|
||||
<div
|
||||
class="absolute right-4 top-4 z-10 rounded-full bg-white px-3 py-1 text-xs font-extrabold uppercase tracking-wide text-cyan-700 shadow">
|
||||
Featured
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="bg-gradient-to-br {{ $headerClass }} p-5 text-white">
|
||||
<div class="flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<p class="text-xs font-bold uppercase tracking-[0.24em] text-white/70">
|
||||
{{ $price->badge_label ?: 'Plan' }}
|
||||
</p>
|
||||
<h2 class="mt-2 text-2xl font-black tracking-tight">{{ $price->name }}</h2>
|
||||
</div>
|
||||
|
||||
<span
|
||||
class="grid h-11 w-11 place-items-center rounded-2xl bg-white/15 text-lg backdrop-blur">
|
||||
<i class="fa-solid {{ $isBasic ? 'fa-box' : ($isAdvanced ? 'fa-layer-group' : 'fa-crown') }}"
|
||||
aria-hidden="true"></i>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<p class="mt-3 text-sm leading-6 text-white/80">{{ $price->strapline }}</p>
|
||||
</div>
|
||||
|
||||
<div class="p-5">
|
||||
<div class="flex items-end gap-2">
|
||||
<span class="text-4xl font-black tracking-tight text-zinc-950 dark:text-white">
|
||||
{{ $price->formatAmount($price->monthly_amount) }}
|
||||
</span>
|
||||
<span class="pb-1 text-sm font-semibold text-zinc-500">/ month</span>
|
||||
</div>
|
||||
|
||||
<p class="mt-2 text-sm text-zinc-500">
|
||||
Annual:
|
||||
<span class="font-semibold text-zinc-700 dark:text-zinc-200">
|
||||
{{ $price->formatAmount($price->annual_amount) }}
|
||||
</span>
|
||||
</p>
|
||||
|
||||
<p class="mt-4 min-h-12 text-sm leading-6 text-zinc-600 dark:text-zinc-300">
|
||||
{{ $price->description }}
|
||||
</p>
|
||||
|
||||
<ul class="mt-5 space-y-3 text-sm text-zinc-700 dark:text-zinc-200">
|
||||
@foreach ($price->featureRows() as $feature)
|
||||
<li class="flex gap-3">
|
||||
<i class="fa-solid fa-check mt-1 text-cyan-500" aria-hidden="true"></i>
|
||||
<span>{{ $feature }}</span>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
|
||||
<div
|
||||
class="mt-6 flex items-center justify-between gap-3 border-t border-zinc-100 pt-4 dark:border-zinc-800">
|
||||
<span
|
||||
class="rounded-full px-3 py-1 text-xs font-bold {{ $price->is_active ? 'bg-emerald-100 text-emerald-700 dark:bg-emerald-950 dark:text-emerald-200' : 'bg-zinc-100 text-zinc-600 dark:bg-zinc-800 dark:text-zinc-300' }}">
|
||||
{{ $price->is_active ? 'Active' : 'Hidden' }}
|
||||
</span>
|
||||
|
||||
<div class="flex items-center gap-2">
|
||||
<a href="{{ route('platform.prices.edit', $price) }}" wire:navigate
|
||||
class="rounded-lg border border-zinc-200 px-3 py-2 text-sm font-semibold text-zinc-700 hover:border-cyan-400 hover:text-cyan-700 dark:border-zinc-700 dark:text-zinc-200">
|
||||
Edit
|
||||
</a>
|
||||
<form method="POST" action="{{ route('platform.prices.destroy', $price) }}"
|
||||
onsubmit="return confirm('Delete this price?');">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit"
|
||||
class="rounded-lg border border-red-200 px-3 py-2 text-sm font-semibold text-red-600 hover:bg-red-50 dark:border-red-900/70 dark:hover:bg-red-950/40">
|
||||
Delete
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
@empty
|
||||
<article
|
||||
class="rounded-3xl border border-dashed border-zinc-300 bg-white p-6 text-sm text-zinc-500 shadow-sm dark:border-zinc-700 dark:bg-zinc-900 lg:col-span-3">
|
||||
No pricing plans have been created yet.
|
||||
</article>
|
||||
@endforelse
|
||||
</section>
|
||||
</div>
|
||||
</x-layouts::app>
|
||||
@@ -0,0 +1,77 @@
|
||||
<x-layouts::app :title="__('Pricing')">
|
||||
<div class="space-y-6">
|
||||
<x-wms.page-hero eyebrow="Platform" title="Pricing"
|
||||
description="Clear platform pricing for Basic, Advanced and Pro access." icon="fa-solid fa-tags" />
|
||||
<section class="grid gap-5 lg:grid-cols-3">
|
||||
@forelse ($prices as $price)
|
||||
@php
|
||||
$isBasic = $price->code === 'basic';
|
||||
$isAdvanced = $price->code === 'advanced';
|
||||
$headerClass = $isAdvanced
|
||||
? 'from-cyan-500 to-blue-600'
|
||||
: ($isBasic
|
||||
? 'from-slate-700 to-slate-950'
|
||||
: 'from-indigo-600 to-violet-700');
|
||||
@endphp
|
||||
|
||||
<article
|
||||
class="relative overflow-hidden rounded-3xl border border-zinc-200 bg-white shadow-sm transition hover:-translate-y-0.5 hover:shadow-xl dark:border-zinc-800 dark:bg-zinc-900">
|
||||
@if ($price->is_featured)
|
||||
<div
|
||||
class="absolute right-4 top-4 z-10 rounded-full bg-white px-3 py-1 text-xs font-extrabold uppercase tracking-wide text-cyan-700 shadow">
|
||||
{{ $price->badge_label ?: 'Popular' }}</div>
|
||||
@endif
|
||||
|
||||
<div class="bg-gradient-to-br {{ $headerClass }} p-6 text-white">
|
||||
<div class="flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<p class="text-xs font-bold uppercase tracking-[0.24em] text-white/70">
|
||||
{{ $price->badge_label ?: 'Plan' }}</p>
|
||||
<h2 class="mt-2 text-3xl font-black tracking-tight">{{ $price->name }}</h2>
|
||||
</div>
|
||||
<span
|
||||
class="grid h-12 w-12 place-items-center rounded-2xl bg-white/15 text-xl backdrop-blur">
|
||||
<i class="fa-solid {{ $isBasic ? 'fa-box' : ($isAdvanced ? 'fa-layer-group' : 'fa-crown') }}"
|
||||
aria-hidden="true"></i>
|
||||
</span>
|
||||
</div>
|
||||
<p class="mt-4 text-sm leading-6 text-white/80">{{ $price->strapline }}</p>
|
||||
</div>
|
||||
|
||||
<div class="p-6">
|
||||
<div class="flex items-end gap-2">
|
||||
<span
|
||||
class="text-4xl font-black tracking-tight text-zinc-950 dark:text-white">{{ $price->formatAmount($price->monthly_amount) }}</span>
|
||||
<span class="pb-1 text-sm font-semibold text-zinc-500">/ month</span>
|
||||
</div>
|
||||
|
||||
@if ($price->annual_amount)
|
||||
<p class="mt-2 text-sm text-zinc-500">Annual: <span
|
||||
class="font-semibold text-zinc-700 dark:text-zinc-200">{{ $price->formatAmount($price->annual_amount) }}</span>
|
||||
</p>
|
||||
@endif
|
||||
|
||||
<p class="mt-4 min-h-12 text-sm leading-6 text-zinc-600 dark:text-zinc-300">
|
||||
{{ $price->description }}</p>
|
||||
|
||||
<ul class="mt-5 space-y-3 text-sm text-zinc-700 dark:text-zinc-200">
|
||||
@foreach ($price->featureRows() as $feature)
|
||||
<li class="flex gap-3">
|
||||
<i class="fa-solid fa-check mt-1 text-cyan-500" aria-hidden="true"></i>
|
||||
<span>{{ $feature }}</span>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
</article>
|
||||
@empty
|
||||
<article
|
||||
class="rounded-3xl border border-zinc-200 bg-white p-6 shadow-sm dark:border-zinc-800 dark:bg-zinc-900">
|
||||
<h2 class="text-xl font-bold">No active prices</h2>
|
||||
<p class="mt-2 text-sm text-zinc-500">Add active pricing records from Administration to populate
|
||||
this page.</p>
|
||||
</article>
|
||||
@endforelse
|
||||
</section>
|
||||
</div>
|
||||
</x-layouts::app>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\Company\Http\Controllers\CompanyController;
|
||||
use Modules\Platform\app\Http\Controllers\LicenseKeyController;
|
||||
use Modules\Platform\app\Http\Controllers\PaymentController;
|
||||
use Modules\Platform\app\Http\Controllers\PlatformDashboardController;
|
||||
use Modules\Platform\app\Http\Controllers\PlatformPriceController;
|
||||
use Modules\Platform\app\Http\Controllers\StripeWebhookController;
|
||||
|
||||
Route::middleware(['auth', 'verified', 'tenant.assigned'])
|
||||
->prefix('platform')
|
||||
->name('platform.')
|
||||
->group(function (): void {
|
||||
Route::get('/pricing', [PlatformPriceController::class, 'publicIndex'])->name('pricing.index');
|
||||
});
|
||||
|
||||
Route::middleware(['auth', 'verified', 'tenant.assigned', 'platform.admin'])
|
||||
->prefix('admin')
|
||||
->name('platform.')
|
||||
->group(function (): void {
|
||||
Route::get('/', PlatformDashboardController::class)->name('dashboard');
|
||||
Route::get('/licenses', [LicenseKeyController::class, 'index'])->name('licenses.index');
|
||||
Route::post('/licenses', [LicenseKeyController::class, 'store'])->name('licenses.store');
|
||||
Route::get('/payments', [PaymentController::class, 'index'])->name('payments.index');
|
||||
Route::post('/payments', [PaymentController::class, 'store'])->name('payments.store');
|
||||
Route::resource('/prices', PlatformPriceController::class)->except(['show']);
|
||||
Route::resource('/companies', CompanyController::class);
|
||||
});
|
||||
|
||||
Route::post('/stripe/webhook', StripeWebhookController::class)->name('stripe.webhook');
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Platform\tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Modules\Company\Models\Company;
|
||||
use Modules\Platform\app\Models\LicenseKey;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LicenseKeyTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_license_key_is_hashed_and_not_stored_plain(): void
|
||||
{
|
||||
$company = Company::create(['name' => 'Tenant A', 'slug' => 'tenant-a']);
|
||||
|
||||
$plainKey = LicenseKey::issueFor($company, 'Production licence', 'enterprise', 50);
|
||||
$license = LicenseKey::firstOrFail();
|
||||
|
||||
$this->assertStringStartsWith('WMS-', $plainKey);
|
||||
$this->assertNotSame($plainKey, $license->key_hash);
|
||||
$this->assertSame(hash('sha256', $plainKey), $license->key_hash);
|
||||
$this->assertTrue($company->fresh()->hasActiveLicense());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Platform\tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Modules\Company\Models\Company;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PlatformAccessTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_mpba_platform_admin_can_access_admin_dashboard_without_licence(): void
|
||||
{
|
||||
$company = Company::create([
|
||||
'name' => 'MPBA Limited',
|
||||
'slug' => 'mpba-limited',
|
||||
'is_system_company' => true,
|
||||
'status' => 'active',
|
||||
]);
|
||||
|
||||
$user = User::factory()->create([
|
||||
'company_id' => $company->id,
|
||||
'email' => 'mark.gregory@mpba.co.uk',
|
||||
'is_platform_admin' => true,
|
||||
'is_company_admin' => true,
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get('/admin')
|
||||
->assertOk()
|
||||
->assertSee('Platform', false);
|
||||
}
|
||||
|
||||
public function test_non_system_company_requires_license(): void
|
||||
{
|
||||
$company = Company::create([
|
||||
'name' => 'Customer Limited',
|
||||
'slug' => 'customer-limited',
|
||||
'status' => 'active',
|
||||
]);
|
||||
|
||||
$user = User::factory()->create(['company_id' => $company->id]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get('/dashboard')
|
||||
->assertStatus(402);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user