Skip to content

Commit 7461c14

Browse files
Merge pull request #59 from khalidmaquilang/dev
v2.1.0 - Hotfix | id is null on invoice + Hotfix | fix invoice + Feature | create directory for company logo + Task | change generate code format + Feature | add sku + Feature | format unit cost on purchase order + Hotfix | fix pay in full + Feature | use money function + Feature | added admin panel and company resource
2 parents 194e161 + bf5de1b commit 7461c14

File tree

17 files changed

+287
-60
lines changed

17 files changed

+287
-60
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
3+
namespace App\Filament\Admin\Resources;
4+
5+
use App\Filament\Admin\Resources\CompanyResource\Pages;
6+
use App\Models\Company;
7+
use Filament\Forms;
8+
use Filament\Forms\Form;
9+
use Filament\Resources\Resource;
10+
use Filament\Tables;
11+
use Filament\Tables\Table;
12+
13+
class CompanyResource extends Resource
14+
{
15+
protected static ?string $model = Company::class;
16+
17+
protected static ?string $navigationIcon = 'heroicon-o-building-office';
18+
19+
public static function form(Form $form): Form
20+
{
21+
return $form
22+
->schema([
23+
Forms\Components\Select::make('user_id')
24+
->relationship('owner', 'name')
25+
->searchable()
26+
->required(),
27+
Forms\Components\TextInput::make('name')
28+
->required()
29+
->maxLength(255),
30+
Forms\Components\TextInput::make('slug')
31+
->required()
32+
->maxLength(255),
33+
Forms\Components\TextInput::make('logo')
34+
->maxLength(255),
35+
Forms\Components\TextInput::make('phone')
36+
->tel()
37+
->required()
38+
->maxLength(255),
39+
Forms\Components\TextInput::make('email')
40+
->email()
41+
->required()
42+
->maxLength(255),
43+
Forms\Components\Textarea::make('address')
44+
->required()
45+
->columnSpanFull(),
46+
Forms\Components\TextInput::make('currency')
47+
->required()
48+
->maxLength(255),
49+
]);
50+
}
51+
52+
public static function table(Table $table): Table
53+
{
54+
return $table
55+
->columns([
56+
Tables\Columns\TextColumn::make('owner.name')
57+
->label('Company Owner')
58+
->sortable(),
59+
Tables\Columns\TextColumn::make('name')
60+
->searchable(),
61+
Tables\Columns\TextColumn::make('slug')
62+
->searchable(),
63+
Tables\Columns\TextColumn::make('phone')
64+
->searchable(),
65+
Tables\Columns\TextColumn::make('email')
66+
->searchable(),
67+
Tables\Columns\TextColumn::make('currency')
68+
->searchable(),
69+
Tables\Columns\TextColumn::make('created_at')
70+
->dateTime()
71+
->sortable()
72+
->toggleable(isToggledHiddenByDefault: true),
73+
Tables\Columns\TextColumn::make('updated_at')
74+
->dateTime()
75+
->sortable()
76+
->toggleable(isToggledHiddenByDefault: true),
77+
])
78+
->filters([
79+
//
80+
])
81+
->actions([
82+
Tables\Actions\EditAction::make(),
83+
])
84+
->bulkActions([
85+
Tables\Actions\BulkActionGroup::make([
86+
Tables\Actions\DeleteBulkAction::make(),
87+
]),
88+
]);
89+
}
90+
91+
public static function getRelations(): array
92+
{
93+
return [
94+
//
95+
];
96+
}
97+
98+
public static function getPages(): array
99+
{
100+
return [
101+
'index' => Pages\ListCompanies::route('/'),
102+
'create' => Pages\CreateCompany::route('/create'),
103+
'edit' => Pages\EditCompany::route('/{record}/edit'),
104+
];
105+
}
106+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace App\Filament\Admin\Resources\CompanyResource\Pages;
4+
5+
use App\Filament\Admin\Resources\CompanyResource;
6+
use Filament\Resources\Pages\CreateRecord;
7+
8+
class CreateCompany extends CreateRecord
9+
{
10+
protected static string $resource = CompanyResource::class;
11+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Filament\Admin\Resources\CompanyResource\Pages;
4+
5+
use App\Filament\Admin\Resources\CompanyResource;
6+
use Filament\Actions;
7+
use Filament\Resources\Pages\EditRecord;
8+
9+
class EditCompany extends EditRecord
10+
{
11+
protected static string $resource = CompanyResource::class;
12+
13+
protected function getHeaderActions(): array
14+
{
15+
return [
16+
Actions\DeleteAction::make(),
17+
];
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Filament\Admin\Resources\CompanyResource\Pages;
4+
5+
use App\Filament\Admin\Resources\CompanyResource;
6+
use Filament\Actions;
7+
use Filament\Resources\Pages\ListRecords;
8+
9+
class ListCompanies extends ListRecords
10+
{
11+
protected static string $resource = CompanyResource::class;
12+
13+
protected function getHeaderActions(): array
14+
{
15+
return [
16+
Actions\CreateAction::make(),
17+
];
18+
}
19+
}

app/Filament/Resources/CustomerResource/RelationManagers/SalesRelationManager.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ public function table(Table $table): Table
2020
->searchable(),
2121
Tables\Columns\TextColumn::make('sale_date')
2222
->date(),
23-
Tables\Columns\TextColumn::make('total_amount'),
24-
Tables\Columns\TextColumn::make('paid_amount'),
23+
Tables\Columns\TextColumn::make('total_amount')
24+
->money($this->getOwnerRecord()->company->getCurrency()),
25+
Tables\Columns\TextColumn::make('paid_amount')
26+
->money($this->getOwnerRecord()->company->getCurrency()),
2527
Tables\Columns\TextColumn::make('paymentType.name'),
2628
])
2729
->filters([

app/Filament/Resources/InventoryResource.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,17 @@ public static function form(Form $form): Form
4545

4646
public static function table(Table $table): Table
4747
{
48-
$currency = Filament::getTenant()->getCurrency();
49-
5048
return $table
5149
->columns([
50+
Tables\Columns\TextColumn::make('product.sku')
51+
->label('SKU')
52+
->sortable(),
5253
Tables\Columns\TextColumn::make('product.name')
5354
->sortable(),
5455
Tables\Columns\TextColumn::make('quantity_on_hand')
5556
->sortable(),
56-
Tables\Columns\TextColumn::make('formatted_average_cost')
57-
->label('Average Cost'),
57+
Tables\Columns\TextColumn::make('average_cost')
58+
->money(fn ($record) => $record->company->getCurrency()),
5859
Tables\Columns\TextColumn::make('user.name')
5960
->label('Created By'),
6061
Tables\Columns\TextColumn::make('created_at')

app/Filament/Resources/ProductResource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public static function table(Table $table): Table
3535
Tables\Columns\TextColumn::make('name')
3636
->searchable(),
3737
Tables\Columns\TextColumn::make('purchase_price')
38-
->numeric()
38+
->money(fn ($record) => $record->company->getCurrency())
3939
->sortable(),
4040
Tables\Columns\TextColumn::make('selling_price')
41-
->numeric()
41+
->money(fn ($record) => $record->company->getCurrency())
4242
->sortable(),
4343
Tables\Columns\TextColumn::make('created_at')
4444
->dateTime()

app/Filament/Resources/PurchaseOrderResource.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public static function form(Form $form): Form
5050
->schema([
5151
Forms\Components\TextInput::make('sku')
5252
->readOnly(),
53+
Forms\Components\Hidden::make('unit_cost'),
5354
Forms\Components\Hidden::make('name'),
5455
Forms\Components\Select::make('product_id')
5556
->relationship('product', 'name')
@@ -58,6 +59,9 @@ public static function form(Form $form): Form
5859
if (empty($state)) {
5960
$set('sku', '');
6061
$set('name', '');
62+
$set('quantity', '');
63+
$set('unit_cost', '');
64+
$set('formatted_unit_cost', '');
6165

6266
return;
6367
}
@@ -66,6 +70,7 @@ public static function form(Form $form): Form
6670
$set('sku', $product->sku);
6771
$set('name', $product->name);
6872
$set('unit_cost', $product->purchase_price);
73+
$set('formatted_unit_cost', number_format($product->purchase_price, 2));
6974
})
7075
->rules([
7176
function ($component) {
@@ -92,7 +97,7 @@ function ($component) {
9297
})
9398
->required()
9499
->numeric(),
95-
Forms\Components\TextInput::make('unit_cost')
100+
Forms\Components\TextInput::make('formatted_unit_cost')
96101
->suffix($currency)
97102
->afterStateUpdated(function (Forms\Set $set, Forms\Get $get, $state) {
98103
$quantity = $get('quantity');
@@ -143,7 +148,7 @@ function ($component) {
143148
Forms\Components\Actions\Action::make('pay_full')
144149
->label('Pay in full')
145150
->color('success')
146-
->action(fn ($set, $get) => $set('paid_amount', $get('total_amount'))),
151+
->action(fn ($set, $get) => $set('paid_amount', str_replace(',', '', $get('total_amount')))),
147152
]),
148153
]),
149154
]),
@@ -152,8 +157,6 @@ function ($component) {
152157

153158
public static function table(Table $table): Table
154159
{
155-
$currency = Filament::getTenant()->getCurrency();
156-
157160
return $table
158161
->columns([
159162
Tables\Columns\TextColumn::make('purchase_code')
@@ -165,9 +168,9 @@ public static function table(Table $table): Table
165168
->numeric()
166169
->sortable(),
167170
Tables\Columns\TextColumn::make('total_amount')
168-
->formatStateUsing(fn ($state): string => number_format($state, 2).' '.$currency),
171+
->money(fn ($record) => $record->company->getCurrency()),
169172
Tables\Columns\TextColumn::make('remaining_amount')
170-
->formatStateUsing(fn ($state): string => number_format($state, 2).' '.$currency),
173+
->money(fn ($record) => $record->company->getCurrency()),
171174
Tables\Columns\TextColumn::make('status')
172175
->badge()
173176
->sortable(),

app/Filament/Resources/PurchaseOrderResource/RelationManagers/GoodsReceiptsRelationManager.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ public function table(Table $table): Table
6161
->searchable(),
6262
Tables\Columns\TextColumn::make('product.name'),
6363
Tables\Columns\TextColumn::make('quantity'),
64-
Tables\Columns\TextColumn::make('formatted_unit_cost')
65-
->label('Unit cost'),
66-
Tables\Columns\TextColumn::make('formatted_total_cost')
67-
->label('Total cost'),
64+
Tables\Columns\TextColumn::make('unit_cost')
65+
->money(fn ($record) => $record->company->getCurrency()),
66+
Tables\Columns\TextColumn::make('total_cost')
67+
->money(fn ($record) => $record->company->getCurrency()),
6868
Tables\Columns\TextColumn::make('received_date')
6969
->date(),
7070
Tables\Columns\TextColumn::make('user.name')

app/Filament/Resources/PurchaseOrderResource/RelationManagers/PurchaseOrderItemsRelationManager.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ public function table(Table $table): Table
2424
->label('Product Name'),
2525
Tables\Columns\TextColumn::make('quantity'),
2626
Tables\Columns\TextColumn::make('unit_cost')
27-
->formatStateUsing(fn ($state) => number_format($state, 2).' '.$currency),
27+
->money(fn ($record) => $record->company->getCurrency()),
2828
Tables\Columns\TextColumn::make('quantity_received'),
2929
Tables\Columns\TextColumn::make('remaining_quantity')
3030
->getStateUsing(function ($record): int {
3131
return $record->quantity - $record->quantity_received;
32-
}),
32+
})
33+
->money(fn ($record) => $record->company->getCurrency()),
3334
])
3435
->filters([
3536
//

0 commit comments

Comments
 (0)