feat(client): add client context to sales and expenses creation
- Disable branch selection in sale form when creating from client context - Pass client ID to create pages via URL parameter - Update breadcrumbs to reflect client navigation path - Simplify relation managers by reusing resource tables and adding custom create actions
This commit is contained in:
@@ -4,8 +4,10 @@ namespace App\Filament\Resources\SaleResource\Pages;
|
||||
|
||||
use App\Actions\Transactions\CreateTransactionAction;
|
||||
use App\DataObjects\CreateTransactionDTO;
|
||||
use App\Filament\Resources\ClientResource;
|
||||
use App\Filament\Resources\SaleResource;
|
||||
use App\Models\Branch;
|
||||
use App\Models\Client;
|
||||
use App\Models\Sale;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -17,6 +19,39 @@ class CreateSale extends CreateRecord
|
||||
{
|
||||
protected static string $resource = SaleResource::class;
|
||||
|
||||
public ?int $clientId = null;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
parent::mount();
|
||||
|
||||
$this->clientId = request()->integer('client_id');
|
||||
}
|
||||
|
||||
public function getBreadcrumbs(): array
|
||||
{
|
||||
$client = $this->getClient();
|
||||
|
||||
if (! $client) {
|
||||
return parent::getBreadcrumbs();
|
||||
}
|
||||
|
||||
return [
|
||||
ClientResource::getUrl('view', ['record' => $client->id]) => $client->company,
|
||||
ClientResource::getUrl('view', ['record' => $client->id]).'?activeRelationManager=3' => 'Sales',
|
||||
$this->getResource()::getUrl('create', ['client_id' => $client->id]) => 'Create',
|
||||
];
|
||||
}
|
||||
|
||||
protected function getClient(): Client|null
|
||||
{
|
||||
if (! $this->clientId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Client::find($this->clientId);
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
return $this->getFormDataMutation($data);
|
||||
|
||||
Reference in New Issue
Block a user