Skip to content

Commit 75d0946

Browse files
Merge pull request #96 from khalidmaquilang/dev
v2.4.0 - SI-89 | Hotfix | Fix Edit Role+SI-88 | Hotfix | negative numbers issue on stock movement+SI-90 | Hotfix | rename return in stock movement+SI-90 | Hotfix | update plan resource+SI-92 | Hotfix | add checksubscription scheduler+SI-93 | Hotfix | fix plans features+SI-69 | Feature | alert low on stock+SI-99 | Hotfix | fix total amount when there is no vat+SI-100 | Feature | add reference number+SI-87 | Feature | shipping fee purchase order sale+SI-94 | Feature | add notes+SI-70 | Feature | add current stock+SI-103 | Feature | revise invoice+SI-104 | Feature | show full amount of the tax
2 parents f8eeadd + 221f998 commit 75d0946

File tree

56 files changed

+2051
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2051
-200
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ AWS_USE_PATH_STYLE_ENDPOINT=false
6363

6464
VITE_APP_NAME="${APP_NAME}"
6565
SENTRY_LARAVEL_DSN=
66+
CHROME_PATH=

.github/workflows/laravel.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Simple Inventory
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- main
7+
- dev
8+
pull_request:
9+
branches: [ "dev" ]
10+
11+
jobs:
12+
laravel-tests:
13+
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
18+
with:
19+
php-version: '8.3'
20+
- uses: actions/checkout@v4
21+
- name: Copy .env
22+
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
23+
- name: Install Dependencies
24+
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
25+
- name: Generate key
26+
run: php artisan key:generate
27+
- name: Directory Permissions
28+
run: chmod -R 777 storage bootstrap/cache
29+
- name: Check Code Quality
30+
run: vendor/bin/pint --test
31+
- name: Execute tests (Unit and Feature tests) via PHPUnit
32+
run: vendor/bin/phpunit

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ yarn-error.log
1818
/.fleet
1919
/.idea
2020
/.vscode
21+
.cache

app/Filament/Resources/InventoryResource/Pages/ViewInventory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ public function infolist(Infolist $infolist): Infolist
1919
return $infolist
2020
->schema([
2121
Section::make('Inventory Details')
22-
->columns(3)
22+
->columns(4)
2323
->schema([
2424
TextEntry::make('product.name'),
2525
TextEntry::make('quantity_on_hand'),
2626
TextEntry::make('formatted_average_cost')
2727
->label('Average Cost'),
28+
TextEntry::make('product.reorder_point')
29+
->label('Reorder Point'),
2830
]),
2931
]);
3032
}

app/Filament/Resources/ProductResource.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ public static function table(Table $table): Table
2828
{
2929
return $table
3030
->columns([
31-
Tables\Columns\TextColumn::make('category.name'),
31+
Tables\Columns\TextColumn::make('category.name')
32+
->sortable(),
3233
Tables\Columns\TextColumn::make('sku')
3334
->label('SKU')
35+
->sortable()
3436
->searchable(),
3537
Tables\Columns\TextColumn::make('name')
3638
->searchable(),
@@ -40,6 +42,8 @@ public static function table(Table $table): Table
4042
Tables\Columns\TextColumn::make('selling_price')
4143
->money(fn ($record) => $record->company->getCurrency())
4244
->sortable(),
45+
Tables\Columns\TextColumn::make('reorder_point')
46+
->sortable(),
4347
Tables\Columns\TextColumn::make('created_at')
4448
->dateTime()
4549
->sortable()
@@ -66,7 +70,8 @@ public static function table(Table $table): Table
6670
Tables\Actions\DeleteBulkAction::make(),
6771
Tables\Actions\RestoreBulkAction::make(),
6872
]),
69-
]);
73+
])
74+
->defaultSort('created_at', 'desc');
7075
}
7176

7277
public static function getRelations(): array

app/Filament/Resources/PurchaseOrderResource.php

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public static function form(Form $form): Form
4040
->required(),
4141
TableRepeater::make('purchaseOrderItems')
4242
->relationship()
43+
->addActionLabel('Click to add more products')
4344
->headers([
4445
Header::make('sku')
4546
->label('SKU'),
@@ -124,6 +125,18 @@ function ($component) {
124125
Forms\Components\Section::make('Payment')
125126
->columns(2)
126127
->schema([
128+
Forms\Components\TextInput::make('sub_total')
129+
->suffix($currency)
130+
->lazy()
131+
->disabled(),
132+
TextInput::make('shipping_fee')
133+
->numeric()
134+
->lazy()
135+
->default(0)
136+
->minValue(0)
137+
->afterStateUpdated(function (Forms\Get $get, Forms\Set $set) {
138+
self::updateTotals($get, $set);
139+
}),
127140
Forms\Components\TextInput::make('total_amount')
128141
->minValue(0)
129142
->suffix($currency)
@@ -133,9 +146,13 @@ function ($component) {
133146
->mutateDehydratedStateUsing(function ($state) {
134147
return floatval(str_replace(',', '', $state));
135148
}),
136-
Forms\Components\Select::make('payment_type_id')
137-
->relationship('paymentType', 'name')
138-
->required(),
149+
Forms\Components\Group::make([
150+
Forms\Components\Select::make('payment_type_id')
151+
->relationship('paymentType', 'name')
152+
->required(),
153+
Forms\Components\TextInput::make('reference_number'),
154+
])
155+
->columns(2),
139156
Forms\Components\Group::make([
140157
Forms\Components\TextInput::make('paid_amount')
141158
->suffix($currency)
@@ -169,11 +186,15 @@ public static function table(Table $table): Table
169186
->date()
170187
->sortable(),
171188
Tables\Columns\TextColumn::make('supplier.company_name')
172-
->numeric()
173189
->sortable(),
190+
Tables\Columns\TextColumn::make('shipping_fee')
191+
->sortable()
192+
->money(fn ($record) => $record->company->getCurrency()),
174193
Tables\Columns\TextColumn::make('total_amount')
194+
->sortable()
175195
->money(fn ($record) => $record->company->getCurrency()),
176196
Tables\Columns\TextColumn::make('remaining_amount')
197+
->sortable()
177198
->money(fn ($record) => $record->company->getCurrency()),
178199
Tables\Columns\TextColumn::make('status')
179200
->badge()
@@ -240,7 +261,7 @@ public static function table(Table $table): Table
240261
->visible(fn ($record) => $record->isAvailable()),
241262
]),
242263
])
243-
->defaultSort('created_at', 'desc');
264+
->defaultSort('order_date', 'desc');
244265
}
245266

246267
public static function getWidgets(): array
@@ -277,8 +298,11 @@ public static function updateTotals(Forms\Get $get, Forms\Set $set): void
277298
$subtotal = $selectedProducts->reduce(function ($subtotal, $product) {
278299
return $subtotal + ((float) $product['unit_cost'] * $product['quantity']);
279300
}, 0);
301+
$set('sub_total', number_format($subtotal, 2));
302+
303+
$shippingFee = (float) $get('shipping_fee');
280304

281305
// Update the state with the new values
282-
$set('total_amount', number_format($subtotal, 2));
306+
$set('total_amount', number_format($subtotal + $shippingFee, 2));
283307
}
284308
}

app/Filament/Resources/PurchaseOrderResource/Pages/ViewPurchaseOrder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ public function infolist(Infolist $infolist): Infolist
3838
TextEntry::make('supplier.company_name'),
3939
Fieldset::make('Payment Information')
4040
->schema([
41+
TextEntry::make('shipping_fee')
42+
->formatStateUsing(fn ($state) => number_format($state, 2).' '.$currency),
4143
TextEntry::make('total_amount')
4244
->formatStateUsing(fn ($state) => number_format($state, 2).' '.$currency),
4345
TextEntry::make('paid_amount')
4446
->formatStateUsing(fn ($state) => number_format($state, 2).' '.$currency),
4547
TextEntry::make('paymentType.name'),
46-
]),
48+
TextEntry::make('reference_number'),
49+
])
50+
->columns(3),
4751
]),
4852

4953
]);

app/Filament/Resources/SaleResource.php

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ public static function form(Form $form): Form
5353
->columnSpanFull(),
5454
TableRepeater::make('saleItems')
5555
->relationship()
56+
->addActionLabel('Click to add more products')
5657
->headers([
5758
Header::make('sku')
5859
->label('SKU'),
5960
Header::make('Product Name'),
61+
Header::make('Current Stock'),
6062
Header::make('Quantity'),
6163
Header::make('Unit Cost'),
6264
Header::make('Total Cost'),
@@ -76,6 +78,7 @@ public static function form(Form $form): Form
7678
$set('unit_cost', '');
7779
$set('formatted_unit_cost', '');
7880
$set('quantity', '');
81+
$set('current_stock', '');
7982

8083
return;
8184
}
@@ -85,6 +88,7 @@ public static function form(Form $form): Form
8588
$set('name', $product->name);
8689
$set('unit_cost', $product->selling_price);
8790
$set('formatted_unit_cost', number_format($product->selling_price, 2));
91+
$set('current_stock', $product->current_stock);
8892
})
8993
->rules([
9094
function ($component) {
@@ -99,6 +103,8 @@ function ($component) {
99103
},
100104
])
101105
->required(),
106+
Forms\Components\TextInput::make('current_stock')
107+
->disabled(),
102108
Forms\Components\TextInput::make('quantity')
103109
->lazy()
104110
->minValue(1)
@@ -151,11 +157,20 @@ function ($component) {
151157
->lazy()
152158
->suffix($currency)
153159
->disabled(),
160+
Forms\Components\TextInput::make('shipping_fee')
161+
->lazy()
162+
->default(0)
163+
->minValue(0)
164+
->afterStateUpdated(function (Forms\Set $set, Forms\Get $get) {
165+
self::updateTotalAmount($get, $set);
166+
})
167+
->numeric(),
154168
Forms\Components\TextInput::make('vat')
155169
->label('VAT (Value-Added Tax)')
156170
->suffix('%')
157171
->lazy()
158172
->default(0)
173+
->minValue(0)
159174
->afterStateUpdated(function (Forms\Set $set, Forms\Get $get) {
160175
self::updateTotalAmount($get, $set);
161176
})
@@ -197,19 +212,19 @@ function ($component) {
197212
->default(0)
198213
->required()
199214
->minValue(0)
200-
->maxValue(fn($get) => floatval(str_replace(',', '', $get('total_amount'))) ?? 0)
215+
->maxValue(fn ($get) => floatval(str_replace(',', '', $get('total_amount'))) ?? 0)
201216
->numeric(),
202217
Forms\Components\Actions::make([
203218
Forms\Components\Actions\Action::make('pay_full')
204219
->label('Pay in full')
205220
->color('success')
206221
->action(
207-
fn($set, $get) => $set(
222+
fn ($set, $get) => $set(
208223
'paid_amount',
209224
str_replace(',', '', $get('total_amount'))
210225
)
211226
)
212-
->visible(fn($operation) => $operation === 'create'),
227+
->visible(fn ($operation) => $operation === 'create'),
213228
]),
214229
]),
215230
]),
@@ -228,13 +243,16 @@ public static function table(Table $table): Table
228243
->sortable(),
229244
Tables\Columns\TextColumn::make('pay_until')
230245
->label('Due Date')
231-
->formatStateUsing(fn($state) => now()->addDays($state)->format('M d, Y'))
246+
->formatStateUsing(fn ($state) => now()->addDays($state)->format('M d, Y'))
247+
->sortable(),
248+
Tables\Columns\TextColumn::make('shipping_fee')
249+
->money(fn ($record) => $record->company->getCurrency())
232250
->sortable(),
233251
Tables\Columns\TextColumn::make('total_amount')
234-
->money(fn($record) => $record->company->getCurrency())
252+
->money(fn ($record) => $record->company->getCurrency())
235253
->sortable(),
236254
Tables\Columns\TextColumn::make('remaining_amount')
237-
->money(fn($record) => $record->company->getCurrency())
255+
->money(fn ($record) => $record->company->getCurrency())
238256
->sortable(),
239257
Tables\Columns\TextColumn::make('customer.name')
240258
->numeric()
@@ -290,7 +308,7 @@ public static function table(Table $table): Table
290308
])
291309
->color('info')
292310
->icon('heroicon-m-banknotes')
293-
->visible(fn($record) => $record->remaining_amount > 0)
311+
->visible(fn ($record) => $record->remaining_amount > 0)
294312
->action(function ($record, array $data) {
295313
$record->paid_amount += $data['paid_amount'];
296314
$record->reference_number = $data['reference_number'];
@@ -299,8 +317,8 @@ public static function table(Table $table): Table
299317
Tables\Actions\Action::make('Download Invoice')
300318
->icon('heroicon-o-document-arrow-down')
301319
->color('success')
302-
->url(fn(Sale $record) => route('app.sales.generate-invoice', [
303-
'company' => session('company_id'),
320+
->url(fn (Sale $record) => route('app.sales.generate-invoice', [
321+
'company' => filament()->getTenant()->id,
304322
'sale' => $record,
305323
]))
306324
->openUrlInNewTab(),
@@ -349,12 +367,12 @@ public static function updateSubTotal(Forms\Get $get, Forms\Set $set): void
349367
{
350368
// Retrieve all selected products and remove empty rows
351369
$selectedProducts = collect($get('saleItems'))->filter(
352-
fn($item) => !empty($item['product_id']) && !empty($item['quantity'])
370+
fn ($item) => ! empty($item['product_id']) && ! empty($item['quantity'])
353371
);
354372

355373
// Calculate subtotal based on the selected products and quantities
356374
$subtotal = $selectedProducts->reduce(function ($subtotal, $product) {
357-
return $subtotal + ((float)$product['unit_cost'] * (float)$product['quantity']);
375+
return $subtotal + ((float) $product['unit_cost'] * (float) $product['quantity']);
358376
}, 0);
359377

360378
// Update the state with the new values
@@ -369,21 +387,24 @@ public static function updateSubTotal(Forms\Get $get, Forms\Set $set): void
369387
*/
370388
public static function updateTotalAmount(Forms\Get $get, Forms\Set $set): void
371389
{
372-
$subTotal = (float)str_replace(',', '', $get('sub_total'));
373-
$vatField = $get('vat');
374-
$discount = (float)str_replace(',', '', $get('discount'));
390+
$subTotal = (float) str_replace(',', '', $get('sub_total'));
391+
$vatField = (float) $get('vat');
392+
$shippingFee = (float) $get('shipping_fee');
393+
$discount = (float) str_replace(',', '', $get('discount'));
375394
$discountType = $get('discount_type');
376395

377396
if (empty($subTotal)) {
378397
$subTotal = 0;
379398
}
380399

381-
if (!empty($discount)) {
400+
if (! empty($discount)) {
382401
$subTotal = self::calculateAfterDiscount($subTotal, $discount, $discountType);
383402
}
384403

404+
$subTotal += $shippingFee;
405+
385406
$vat = 0;
386-
if (!empty($vatField)) {
407+
if (! empty($vatField)) {
387408
$vat = $subTotal * ($vatField / 100);
388409
}
389410

0 commit comments

Comments
 (0)