Skip to content

Commit ae3ddfc

Browse files
Merge pull request #73 from khalidmaquilang/hotfix/si-75-sale-view-fix
SI-75 | Hotfix | sale view fix
2 parents 0e53865 + db59966 commit ae3ddfc

File tree

6 files changed

+122
-5
lines changed

6 files changed

+122
-5
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace App\Filament\Resources\PurchaseOrderResource\RelationManagers;
44

5-
use Filament\Facades\Filament;
65
use Filament\Resources\RelationManagers\RelationManager;
76
use Filament\Tables;
87
use Filament\Tables\Table;
@@ -13,8 +12,6 @@ class PurchaseOrderItemsRelationManager extends RelationManager
1312

1413
public function table(Table $table): Table
1514
{
16-
$currency = Filament::getTenant()->getCurrency();
17-
1815
return $table
1916
->recordTitleAttribute('id')
2017
->columns([

app/Filament/Resources/SaleResource.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ function ($component) {
211211

212212
public static function table(Table $table): Table
213213
{
214-
$currency = Filament::getTenant()->getCurrency();
215-
216214
return $table
217215
->columns([
218216
Tables\Columns\TextColumn::make('invoice_number')
@@ -311,6 +309,7 @@ public static function getPages(): array
311309
return [
312310
'index' => Pages\ListSales::route('/'),
313311
'create' => Pages\CreateSale::route('/create'),
312+
'view' => Pages\ViewSales::route('/{record}'),
314313
];
315314
}
316315

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace App\Filament\Resources\SaleResource\Pages;
4+
5+
use App\Filament\Resources\SaleResource;
6+
use Filament\Facades\Filament;
7+
use Filament\Infolists\Components\Fieldset;
8+
use Filament\Infolists\Components\Section;
9+
use Filament\Infolists\Components\TextEntry;
10+
use Filament\Infolists\Infolist;
11+
use Filament\Resources\Pages\ViewRecord;
12+
use Filament\Support\Enums\FontWeight;
13+
14+
class ViewSales extends ViewRecord
15+
{
16+
protected static string $resource = SaleResource::class;
17+
18+
public function infolist(Infolist $infolist): Infolist
19+
{
20+
$currency = Filament::getTenant()->getCurrency();
21+
22+
return $infolist
23+
->schema([
24+
Section::make('Sales Details')
25+
->columns(2)
26+
->schema([
27+
TextEntry::make('invoice_number')
28+
->size(TextEntry\TextEntrySize::Medium)
29+
->weight(FontWeight::Bold),
30+
TextEntry::make('sale_date')
31+
->date(),
32+
TextEntry::make('pay_until')
33+
->label('Due Date')
34+
->formatStateUsing(fn ($state) => now()->addDays($state)->format('M d, Y')),
35+
TextEntry::make('customer.name'),
36+
Fieldset::make('Payment Information')
37+
->schema([
38+
TextEntry::make('vat'),
39+
TextEntry::make('formatted_discount')
40+
->label('Discount'),
41+
TextEntry::make('total_amount')
42+
->formatStateUsing(fn ($state) => number_format($state, 2).' '.$currency),
43+
TextEntry::make('paid_amount')
44+
->formatStateUsing(fn ($state) => number_format($state, 2).' '.$currency),
45+
TextEntry::make('paymentType.name'),
46+
]),
47+
TextEntry::make('notes'),
48+
]),
49+
50+
]);
51+
}
52+
53+
/**
54+
* @return string[]
55+
*/
56+
public function getRelationManagers(): array
57+
{
58+
return [
59+
SaleResource\RelationManagers\SaleItemsRelationManager::class,
60+
];
61+
}
62+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App\Filament\Resources\SaleResource\RelationManagers;
4+
5+
use Filament\Resources\RelationManagers\RelationManager;
6+
use Filament\Tables;
7+
use Filament\Tables\Table;
8+
9+
class SaleItemsRelationManager extends RelationManager
10+
{
11+
protected static string $relationship = 'saleItems';
12+
13+
public function table(Table $table): Table
14+
{
15+
return $table
16+
->recordTitleAttribute('id')
17+
->columns([
18+
Tables\Columns\TextColumn::make('sku')
19+
->label('SKU'),
20+
Tables\Columns\TextColumn::make('name')
21+
->label('Product Name'),
22+
Tables\Columns\TextColumn::make('quantity'),
23+
Tables\Columns\TextColumn::make('unit_cost')
24+
->money(fn ($record) => $record->company->getCurrency()),
25+
Tables\Columns\TextColumn::make('total_amount')
26+
->getStateUsing(function ($record): float {
27+
return $record->quantity * $record->unit_cost;
28+
})
29+
->money(filament()->getTenant()->getCurrency()),
30+
]);
31+
}
32+
}

app/Models/Sale.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Sale extends Model
3636
protected $appends = [
3737
'remaining_amount',
3838
'formatted_remaining_amount',
39+
'formatted_discount',
3940
];
4041

4142
/**
@@ -54,6 +55,18 @@ public function getFormattedRemainingAmountAttribute(): string
5455
return number_format($this->getRemainingAmountAttribute(), 2).' '.$this->company->getCurrency();
5556
}
5657

58+
/**
59+
* @return string
60+
*/
61+
public function getFormattedDiscountAttribute(): string
62+
{
63+
if ($this->discount_type === DiscountTypeEnum::FIXED) {
64+
return number_format($this->discount, 2).' '.$this->company->getCurrency();
65+
}
66+
67+
return $this->discount.'%';
68+
}
69+
5770
/**
5871
* @return string
5972
*/

app/Models/SaleItem.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,25 @@ class SaleItem extends Model
2121
'product_id' => 'integer',
2222
];
2323

24+
/**
25+
* @return BelongsTo
26+
*/
27+
public function company(): BelongsTo
28+
{
29+
return $this->belongsTo(Company::class);
30+
}
31+
32+
/**
33+
* @return BelongsTo
34+
*/
2435
public function sale(): BelongsTo
2536
{
2637
return $this->belongsTo(Sale::class);
2738
}
2839

40+
/**
41+
* @return BelongsTo
42+
*/
2943
public function product(): BelongsTo
3044
{
3145
return $this->belongsTo(Product::class);

0 commit comments

Comments
 (0)