Merge pull request #5 from kingjaypee12/jp/fix-sales-breadcrumbs
feat(client): add client context to sales and expenses creation
This commit is contained in:
@@ -24,31 +24,13 @@ class ExpensesRelationManager extends RelationManager
|
|||||||
|
|
||||||
public function table(Table $table): Table
|
public function table(Table $table): Table
|
||||||
{
|
{
|
||||||
return $table
|
return ExpenseResource::table($table)->headerActions([
|
||||||
->recordTitleAttribute('supplier')
|
Tables\Actions\Action::make('New Expense')->action('openCreateForm'),
|
||||||
->columns([
|
|
||||||
TextColumn::make('supplier'),
|
|
||||||
TextColumn::make('reference_number'),
|
|
||||||
TextColumn::make('voucher_number'),
|
|
||||||
TextColumn::make('branch.code'),
|
|
||||||
TextColumn::make('happened_on'),
|
|
||||||
])
|
|
||||||
->filters([
|
|
||||||
//
|
|
||||||
])
|
|
||||||
->headerActions([
|
|
||||||
Tables\Actions\CreateAction::make()
|
|
||||||
->url(fn () => ExpenseResource::getUrl('create', ['client_id' => $this->getOwnerRecord()->id])),
|
|
||||||
])
|
|
||||||
->actions([
|
|
||||||
Tables\Actions\EditAction::make()
|
|
||||||
->url(fn (Expense $record) => ExpenseResource::getUrl('edit', ['record' => $record])),
|
|
||||||
Tables\Actions\DeleteAction::make(),
|
|
||||||
])
|
|
||||||
->bulkActions([
|
|
||||||
Tables\Actions\BulkActionGroup::make([
|
|
||||||
Tables\Actions\DeleteBulkAction::make(),
|
|
||||||
]),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function openCreateForm()
|
||||||
|
{
|
||||||
|
return redirect()->route('filament.admin.resources.expenses.create', ['client_id' => $this->getOwnerRecord()->id]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,36 +24,13 @@ class SalesRelationManager extends RelationManager
|
|||||||
|
|
||||||
public function table(Table $table): Table
|
public function table(Table $table): Table
|
||||||
{
|
{
|
||||||
return $table
|
return SaleResource::table($table)->headerActions([
|
||||||
->recordTitleAttribute('title')
|
Tables\Actions\Action::make('New Sale')->action('openCreateForm'),
|
||||||
->columns([
|
|
||||||
TextColumn::make('id')->label('ID')->sortable(),
|
|
||||||
TextColumn::make('branch.code')->label('Branch')->sortable(),
|
|
||||||
TextColumn::make('happened_on')->label('Date')->date()->sortable(),
|
|
||||||
TextColumn::make('gross_amount')->label('Gross Amount')->numeric()->sortable(),
|
|
||||||
TextColumn::make('exempt')->label('Exempt')->numeric()->sortable(),
|
|
||||||
TextColumn::make('vatable_amount')->label('Vatable Amount')->numeric()->sortable(),
|
|
||||||
TextColumn::make('output_tax')->label('Output Tax')->numeric()->sortable(),
|
|
||||||
TextColumn::make('payable_withholding_tax')->label('Payable Withholding Tax')->numeric()->sortable(),
|
|
||||||
TextColumn::make('discount')->label('Discount')->numeric()->sortable(),
|
|
||||||
TextColumn::make('net_amount')->label('Net Amount')->numeric()->sortable(),
|
|
||||||
])
|
|
||||||
->filters([
|
|
||||||
//
|
|
||||||
])
|
|
||||||
->headerActions([
|
|
||||||
Tables\Actions\CreateAction::make()
|
|
||||||
->url(fn () => SaleResource::getUrl('create', ['client_id' => $this->getOwnerRecord()->id])),
|
|
||||||
])
|
|
||||||
->actions([
|
|
||||||
Tables\Actions\EditAction::make()
|
|
||||||
->url(fn (Sale $record) => SaleResource::getUrl('edit', ['record' => $record])),
|
|
||||||
Tables\Actions\DeleteAction::make(),
|
|
||||||
])
|
|
||||||
->bulkActions([
|
|
||||||
Tables\Actions\BulkActionGroup::make([
|
|
||||||
Tables\Actions\DeleteBulkAction::make(),
|
|
||||||
]),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function openCreateForm()
|
||||||
|
{
|
||||||
|
return redirect()->route('filament.admin.resources.sales.create', ['client_id' => $this->getOwnerRecord()->id]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ namespace App\Filament\Resources\ExpenseResource\Pages;
|
|||||||
|
|
||||||
use App\Actions\Transactions\CreateTransactionAction;
|
use App\Actions\Transactions\CreateTransactionAction;
|
||||||
use App\DataObjects\CreateTransactionDTO;
|
use App\DataObjects\CreateTransactionDTO;
|
||||||
|
use App\Filament\Resources\ClientResource;
|
||||||
use App\Filament\Resources\ExpenseResource;
|
use App\Filament\Resources\ExpenseResource;
|
||||||
|
use App\Models\Client;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Filament\Resources\Pages\CreateRecord;
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
@@ -15,6 +17,39 @@ class CreateExpense extends CreateRecord
|
|||||||
{
|
{
|
||||||
protected static string $resource = ExpenseResource::class;
|
protected static string $resource = ExpenseResource::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=4' => 'Expenses',
|
||||||
|
$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
|
protected function mutateFormDataBeforeCreate(array $data): array
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ class SaleResource extends Resource
|
|||||||
->afterStateUpdated(function ($set, $get) {
|
->afterStateUpdated(function ($set, $get) {
|
||||||
$set('branch_id', '');
|
$set('branch_id', '');
|
||||||
})
|
})
|
||||||
|
->disabled()
|
||||||
->required()
|
->required()
|
||||||
->live(),
|
->live(),
|
||||||
Select::make('branch_id')
|
Select::make('branch_id')
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ namespace App\Filament\Resources\SaleResource\Pages;
|
|||||||
|
|
||||||
use App\Actions\Transactions\CreateTransactionAction;
|
use App\Actions\Transactions\CreateTransactionAction;
|
||||||
use App\DataObjects\CreateTransactionDTO;
|
use App\DataObjects\CreateTransactionDTO;
|
||||||
|
use App\Filament\Resources\ClientResource;
|
||||||
use App\Filament\Resources\SaleResource;
|
use App\Filament\Resources\SaleResource;
|
||||||
use App\Models\Branch;
|
use App\Models\Branch;
|
||||||
|
use App\Models\Client;
|
||||||
use App\Models\Sale;
|
use App\Models\Sale;
|
||||||
use Filament\Resources\Pages\CreateRecord;
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
@@ -17,6 +19,39 @@ class CreateSale extends CreateRecord
|
|||||||
{
|
{
|
||||||
protected static string $resource = SaleResource::class;
|
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
|
protected function mutateFormDataBeforeCreate(array $data): array
|
||||||
{
|
{
|
||||||
return $this->getFormDataMutation($data);
|
return $this->getFormDataMutation($data);
|
||||||
|
|||||||
Reference in New Issue
Block a user