Skip to content

Commit

Permalink
Merge pull request #96 from khalidmaquilang/dev
Browse files Browse the repository at this point in the history
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
  • Loading branch information
khalidmaquilang authored Jun 22, 2024
2 parents f8eeadd + 221f998 commit 75d0946
Show file tree
Hide file tree
Showing 56 changed files with 2,051 additions and 200 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ AWS_USE_PATH_STYLE_ENDPOINT=false

VITE_APP_NAME="${APP_NAME}"
SENTRY_LARAVEL_DSN=
CHROME_PATH=
32 changes: 32 additions & 0 deletions .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Simple Inventory

on:
push:
branches-ignore:
- main
- dev
pull_request:
branches: [ "dev" ]

jobs:
laravel-tests:

runs-on: ubuntu-latest

steps:
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
with:
php-version: '8.3'
- uses: actions/checkout@v4
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Check Code Quality
run: vendor/bin/pint --test
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ yarn-error.log
/.fleet
/.idea
/.vscode
.cache
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ public function infolist(Infolist $infolist): Infolist
return $infolist
->schema([
Section::make('Inventory Details')
->columns(3)
->columns(4)
->schema([
TextEntry::make('product.name'),
TextEntry::make('quantity_on_hand'),
TextEntry::make('formatted_average_cost')
->label('Average Cost'),
TextEntry::make('product.reorder_point')
->label('Reorder Point'),
]),
]);
}
Expand Down
9 changes: 7 additions & 2 deletions app/Filament/Resources/ProductResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('category.name'),
Tables\Columns\TextColumn::make('category.name')
->sortable(),
Tables\Columns\TextColumn::make('sku')
->label('SKU')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('name')
->searchable(),
Expand All @@ -40,6 +42,8 @@ public static function table(Table $table): Table
Tables\Columns\TextColumn::make('selling_price')
->money(fn ($record) => $record->company->getCurrency())
->sortable(),
Tables\Columns\TextColumn::make('reorder_point')
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
Expand All @@ -66,7 +70,8 @@ public static function table(Table $table): Table
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]),
]);
])
->defaultSort('created_at', 'desc');
}

public static function getRelations(): array
Expand Down
36 changes: 30 additions & 6 deletions app/Filament/Resources/PurchaseOrderResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static function form(Form $form): Form
->required(),
TableRepeater::make('purchaseOrderItems')
->relationship()
->addActionLabel('Click to add more products')
->headers([
Header::make('sku')
->label('SKU'),
Expand Down Expand Up @@ -124,6 +125,18 @@ function ($component) {
Forms\Components\Section::make('Payment')
->columns(2)
->schema([
Forms\Components\TextInput::make('sub_total')
->suffix($currency)
->lazy()
->disabled(),
TextInput::make('shipping_fee')
->numeric()
->lazy()
->default(0)
->minValue(0)
->afterStateUpdated(function (Forms\Get $get, Forms\Set $set) {
self::updateTotals($get, $set);
}),
Forms\Components\TextInput::make('total_amount')
->minValue(0)
->suffix($currency)
Expand All @@ -133,9 +146,13 @@ function ($component) {
->mutateDehydratedStateUsing(function ($state) {
return floatval(str_replace(',', '', $state));
}),
Forms\Components\Select::make('payment_type_id')
->relationship('paymentType', 'name')
->required(),
Forms\Components\Group::make([
Forms\Components\Select::make('payment_type_id')
->relationship('paymentType', 'name')
->required(),
Forms\Components\TextInput::make('reference_number'),
])
->columns(2),
Forms\Components\Group::make([
Forms\Components\TextInput::make('paid_amount')
->suffix($currency)
Expand Down Expand Up @@ -169,11 +186,15 @@ public static function table(Table $table): Table
->date()
->sortable(),
Tables\Columns\TextColumn::make('supplier.company_name')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('shipping_fee')
->sortable()
->money(fn ($record) => $record->company->getCurrency()),
Tables\Columns\TextColumn::make('total_amount')
->sortable()
->money(fn ($record) => $record->company->getCurrency()),
Tables\Columns\TextColumn::make('remaining_amount')
->sortable()
->money(fn ($record) => $record->company->getCurrency()),
Tables\Columns\TextColumn::make('status')
->badge()
Expand Down Expand Up @@ -240,7 +261,7 @@ public static function table(Table $table): Table
->visible(fn ($record) => $record->isAvailable()),
]),
])
->defaultSort('created_at', 'desc');
->defaultSort('order_date', 'desc');
}

public static function getWidgets(): array
Expand Down Expand Up @@ -277,8 +298,11 @@ public static function updateTotals(Forms\Get $get, Forms\Set $set): void
$subtotal = $selectedProducts->reduce(function ($subtotal, $product) {
return $subtotal + ((float) $product['unit_cost'] * $product['quantity']);
}, 0);
$set('sub_total', number_format($subtotal, 2));

$shippingFee = (float) $get('shipping_fee');

// Update the state with the new values
$set('total_amount', number_format($subtotal, 2));
$set('total_amount', number_format($subtotal + $shippingFee, 2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ public function infolist(Infolist $infolist): Infolist
TextEntry::make('supplier.company_name'),
Fieldset::make('Payment Information')
->schema([
TextEntry::make('shipping_fee')
->formatStateUsing(fn ($state) => number_format($state, 2).' '.$currency),
TextEntry::make('total_amount')
->formatStateUsing(fn ($state) => number_format($state, 2).' '.$currency),
TextEntry::make('paid_amount')
->formatStateUsing(fn ($state) => number_format($state, 2).' '.$currency),
TextEntry::make('paymentType.name'),
]),
TextEntry::make('reference_number'),
])
->columns(3),
]),

]);
Expand Down
53 changes: 37 additions & 16 deletions app/Filament/Resources/SaleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ public static function form(Form $form): Form
->columnSpanFull(),
TableRepeater::make('saleItems')
->relationship()
->addActionLabel('Click to add more products')
->headers([
Header::make('sku')
->label('SKU'),
Header::make('Product Name'),
Header::make('Current Stock'),
Header::make('Quantity'),
Header::make('Unit Cost'),
Header::make('Total Cost'),
Expand All @@ -76,6 +78,7 @@ public static function form(Form $form): Form
$set('unit_cost', '');
$set('formatted_unit_cost', '');
$set('quantity', '');
$set('current_stock', '');

return;
}
Expand All @@ -85,6 +88,7 @@ public static function form(Form $form): Form
$set('name', $product->name);
$set('unit_cost', $product->selling_price);
$set('formatted_unit_cost', number_format($product->selling_price, 2));
$set('current_stock', $product->current_stock);
})
->rules([
function ($component) {
Expand All @@ -99,6 +103,8 @@ function ($component) {
},
])
->required(),
Forms\Components\TextInput::make('current_stock')
->disabled(),
Forms\Components\TextInput::make('quantity')
->lazy()
->minValue(1)
Expand Down Expand Up @@ -151,11 +157,20 @@ function ($component) {
->lazy()
->suffix($currency)
->disabled(),
Forms\Components\TextInput::make('shipping_fee')
->lazy()
->default(0)
->minValue(0)
->afterStateUpdated(function (Forms\Set $set, Forms\Get $get) {
self::updateTotalAmount($get, $set);
})
->numeric(),
Forms\Components\TextInput::make('vat')
->label('VAT (Value-Added Tax)')
->suffix('%')
->lazy()
->default(0)
->minValue(0)
->afterStateUpdated(function (Forms\Set $set, Forms\Get $get) {
self::updateTotalAmount($get, $set);
})
Expand Down Expand Up @@ -197,19 +212,19 @@ function ($component) {
->default(0)
->required()
->minValue(0)
->maxValue(fn($get) => floatval(str_replace(',', '', $get('total_amount'))) ?? 0)
->maxValue(fn ($get) => floatval(str_replace(',', '', $get('total_amount'))) ?? 0)
->numeric(),
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('pay_full')
->label('Pay in full')
->color('success')
->action(
fn($set, $get) => $set(
fn ($set, $get) => $set(
'paid_amount',
str_replace(',', '', $get('total_amount'))
)
)
->visible(fn($operation) => $operation === 'create'),
->visible(fn ($operation) => $operation === 'create'),
]),
]),
]),
Expand All @@ -228,13 +243,16 @@ public static function table(Table $table): Table
->sortable(),
Tables\Columns\TextColumn::make('pay_until')
->label('Due Date')
->formatStateUsing(fn($state) => now()->addDays($state)->format('M d, Y'))
->formatStateUsing(fn ($state) => now()->addDays($state)->format('M d, Y'))
->sortable(),
Tables\Columns\TextColumn::make('shipping_fee')
->money(fn ($record) => $record->company->getCurrency())
->sortable(),
Tables\Columns\TextColumn::make('total_amount')
->money(fn($record) => $record->company->getCurrency())
->money(fn ($record) => $record->company->getCurrency())
->sortable(),
Tables\Columns\TextColumn::make('remaining_amount')
->money(fn($record) => $record->company->getCurrency())
->money(fn ($record) => $record->company->getCurrency())
->sortable(),
Tables\Columns\TextColumn::make('customer.name')
->numeric()
Expand Down Expand Up @@ -290,7 +308,7 @@ public static function table(Table $table): Table
])
->color('info')
->icon('heroicon-m-banknotes')
->visible(fn($record) => $record->remaining_amount > 0)
->visible(fn ($record) => $record->remaining_amount > 0)
->action(function ($record, array $data) {
$record->paid_amount += $data['paid_amount'];
$record->reference_number = $data['reference_number'];
Expand All @@ -299,8 +317,8 @@ public static function table(Table $table): Table
Tables\Actions\Action::make('Download Invoice')
->icon('heroicon-o-document-arrow-down')
->color('success')
->url(fn(Sale $record) => route('app.sales.generate-invoice', [
'company' => session('company_id'),
->url(fn (Sale $record) => route('app.sales.generate-invoice', [
'company' => filament()->getTenant()->id,
'sale' => $record,
]))
->openUrlInNewTab(),
Expand Down Expand Up @@ -349,12 +367,12 @@ public static function updateSubTotal(Forms\Get $get, Forms\Set $set): void
{
// Retrieve all selected products and remove empty rows
$selectedProducts = collect($get('saleItems'))->filter(
fn($item) => !empty($item['product_id']) && !empty($item['quantity'])
fn ($item) => ! empty($item['product_id']) && ! empty($item['quantity'])
);

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

// Update the state with the new values
Expand All @@ -369,21 +387,24 @@ public static function updateSubTotal(Forms\Get $get, Forms\Set $set): void
*/
public static function updateTotalAmount(Forms\Get $get, Forms\Set $set): void
{
$subTotal = (float)str_replace(',', '', $get('sub_total'));
$vatField = $get('vat');
$discount = (float)str_replace(',', '', $get('discount'));
$subTotal = (float) str_replace(',', '', $get('sub_total'));
$vatField = (float) $get('vat');
$shippingFee = (float) $get('shipping_fee');
$discount = (float) str_replace(',', '', $get('discount'));
$discountType = $get('discount_type');

if (empty($subTotal)) {
$subTotal = 0;
}

if (!empty($discount)) {
if (! empty($discount)) {
$subTotal = self::calculateAfterDiscount($subTotal, $discount, $discountType);
}

$subTotal += $shippingFee;

$vat = 0;
if (!empty($vatField)) {
if (! empty($vatField)) {
$vat = $subTotal * ($vatField / 100);
}

Expand Down
Loading

0 comments on commit 75d0946

Please sign in to comment.