WIP Tax Rates
This commit is contained in:
parent
306afd630b
commit
0d68062055
@ -11,7 +11,6 @@
|
||||
use Filament\Tables\Columns\Summarizers\Summarizer;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
class CustomerReportResource extends Resource
|
||||
{
|
||||
@ -45,14 +44,13 @@ public static function table(Table $table): Table
|
||||
|
||||
Tables\Columns\TextColumn::make('subtotal')
|
||||
->money()
|
||||
->summarize(Summarizer::make()->using(function (Builder $query, Table $table) {
|
||||
return '$'.
|
||||
number_format(
|
||||
round(Invoice::whereBetween('date', [
|
||||
$table->getFilter('created_at')->getState()['created_at'] ?? '1900-01-01',
|
||||
$table->getFilter('created_until')->getState()['created_until'] ?? '2100-01-01',
|
||||
])->sum('subtotal'), 2), 2, '.', ',');
|
||||
->summarize(Summarizer::make()->using(function ($query, Table $table) {
|
||||
$createdAt = $table->getfilter('created_at')->getstate()['created_at'] ?? '1900-01-01';
|
||||
$createdUntil = $table->getfilter('created_until')->getstate()['created_until'] ?? '2100-01-01';
|
||||
|
||||
$invoiceSum = invoice::wherebetween('date', [$createdAt, $createdUntil])->sum('subtotal');
|
||||
|
||||
return '$'.number_format(round($invoiceSum, 2), 2, '.', ',');
|
||||
}))
|
||||
->alignRight()
|
||||
->getStateUsing(function (Table $table, Model $record) {
|
||||
@ -77,23 +75,23 @@ public static function table(Table $table): Table
|
||||
->label('PST')
|
||||
->money()
|
||||
->alignRight()
|
||||
->getStateUsing(function (Table $table, Model $record) {
|
||||
return $record->getPstAttribute(
|
||||
$table->getFilter('created_at')->getState()['created_at'],
|
||||
$table->getFilter('created_until')->getState()['created_until']
|
||||
);
|
||||
->getStateUsing(function (Table $table, Customer $record) {
|
||||
// return $record->invoices()->;
|
||||
// return $record->getPstAttribute(
|
||||
// $table->getFilter('created_at')->getState()['created_at'],
|
||||
// $table->getFilter('created_until')->getState()['created_until']
|
||||
// );
|
||||
}),
|
||||
|
||||
Tables\Columns\TextColumn::make('total')
|
||||
->money()
|
||||
->summarize(Summarizer::make()->using(function (Builder $query, Table $table) {
|
||||
return '$'.
|
||||
number_format(
|
||||
round(Invoice::whereBetween('date', [
|
||||
$table->getFilter('created_at')->getState()['created_at'] ?? '1900-01-01',
|
||||
$table->getFilter('created_until')->getState()['created_until'] ?? '2100-01-01',
|
||||
])->sum('total'), 2), 2, '.', ',');
|
||||
->summarize(summarizer::make()->using(function ($query, table $table) {
|
||||
$createdAt = $table->getfilter('created_at')->getstate()['created_at'] ?? '1900-01-01';
|
||||
$createdUntil = $table->getfilter('created_until')->getstate()['created_until'] ?? '2100-01-01';
|
||||
|
||||
$invoiceSum = invoice::wherebetween('date', [$createdAt, $createdUntil])->sum('total');
|
||||
|
||||
return '$'.number_format(round($invoiceSum, 2), 2, '.', ',');
|
||||
}))
|
||||
->weight('bold')
|
||||
->alignRight()
|
||||
|
@ -70,8 +70,9 @@ public static function form(Form $form): Form
|
||||
|
||||
Grid::make(1)
|
||||
->schema([
|
||||
ToggleButtons::make('gst')
|
||||
->boolean()
|
||||
ToggleButtons::make('has_gst')
|
||||
->label('GST')
|
||||
->boolean('On', 'Off')
|
||||
->default(true)
|
||||
->inline()
|
||||
->colors([
|
||||
@ -79,8 +80,9 @@ public static function form(Form $form): Form
|
||||
'false' => 'info',
|
||||
]),
|
||||
|
||||
ToggleButtons::make('pst')
|
||||
->boolean()
|
||||
ToggleButtons::make('has_pst')
|
||||
->label('PST')
|
||||
->boolean('On', 'Off')
|
||||
->default(false)
|
||||
->inline()
|
||||
->colors([
|
||||
@ -94,13 +96,21 @@ public static function form(Form $form): Form
|
||||
|
||||
Section::make()
|
||||
->schema([
|
||||
Placeholder::make('Id')
|
||||
->label('ID')
|
||||
->content(fn (Invoice $record): ?string => $record->internal_id),
|
||||
|
||||
Placeholder::make('Tax Rates')
|
||||
->content(fn (Invoice $record): ?string => $record->gst_rate.'% GST, '.$record->pst_rate.'% PST'),
|
||||
|
||||
Placeholder::make('created_at')
|
||||
->label('Created at')
|
||||
->label('Created')
|
||||
->content(fn (Invoice $record): ?string => $record->created_at?->diffForHumans()),
|
||||
|
||||
Placeholder::make('updated_at')
|
||||
->label('Last modified at')
|
||||
->label('Last modified')
|
||||
->content(fn (Invoice $record): ?string => $record->updated_at?->diffForHumans()),
|
||||
|
||||
])
|
||||
->columnSpan(1)
|
||||
->hidden(fn (?Invoice $record) => $record === null),
|
||||
@ -143,17 +153,25 @@ public static function table(Table $table): Table
|
||||
->money()
|
||||
->alignRight(),
|
||||
|
||||
TextColumn::make('gst_amount')
|
||||
TextColumn::make('has_gst')
|
||||
->label('GST')
|
||||
->formatStateUsing(function ($state) {
|
||||
return $state == 0 ? '-' : '$'.number_format($state, 2);
|
||||
->formatStateUsing(function (Invoice $record) {
|
||||
if ($record->has_gst) {
|
||||
return '$'.$record->gst_amount;
|
||||
}
|
||||
|
||||
return '-';
|
||||
})
|
||||
->alignRight(),
|
||||
|
||||
TextColumn::make('pst_amount')
|
||||
TextColumn::make('has_pst')
|
||||
->label('PST')
|
||||
->formatStateUsing(function ($state) {
|
||||
return $state == 0 ? '-' : '$'.number_format($state, 2);
|
||||
->formatStateUsing(function (Invoice $record) {
|
||||
if ($record->has_pst) {
|
||||
return '$'.$record->pst_amount;
|
||||
}
|
||||
|
||||
return '-';
|
||||
})
|
||||
->alignRight(),
|
||||
TextColumn::make('total')
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Filament\Admin\Resources\OrderResource\Pages;
|
||||
|
||||
use App\Enums\OrderAttributes;
|
||||
use App\Enums\OrderStatus;
|
||||
use App\Filament\Admin\Resources\OrderResource;
|
||||
use App\Models\Order;
|
||||
use App\Models\OrderProduct;
|
||||
@ -148,7 +149,9 @@ protected function getHeaderActions(): array
|
||||
->label('Save changes')
|
||||
->action('save')
|
||||
->icon('lucide-save'),
|
||||
|
||||
Actions\ReplicateAction::make()
|
||||
->label('Duplicate')
|
||||
->icon('lucide-copy')
|
||||
->color('info')
|
||||
->mutateRecordDataUsing(function (array $data): array {
|
||||
@ -157,12 +160,27 @@ protected function getHeaderActions(): array
|
||||
|
||||
return $data;
|
||||
})
|
||||
->beforeReplicaSaved(function (Model $replica): void {})
|
||||
->beforeReplicaSaved(function (Order $replica): void {
|
||||
$replica->customer_po = 'Repeat of '.$replica->customer_po;
|
||||
$replica->status = OrderStatus::DRAFT;
|
||||
$replica->printed = false;
|
||||
$replica->pre_production = false;
|
||||
$replica->order_date = today();
|
||||
$replica->due_date = today()->addDays(10);
|
||||
$replica->save();
|
||||
})
|
||||
->successRedirectUrl(fn (Model $replica): string => OrderResource::getUrl('edit', [$replica])),
|
||||
|
||||
// Action::make('invoice')
|
||||
// ->visible(fn () => auth()->user()->is_admin)
|
||||
// ->label('To Invoice')
|
||||
// ->icon('lucide-receipt-text'),
|
||||
//
|
||||
Action::make('print')
|
||||
->icon('lucide-printer')
|
||||
->url(fn (Order $record) => route('orders.pdf', $record))
|
||||
->openUrlInNewTab(),
|
||||
|
||||
Actions\DeleteAction::make()
|
||||
->icon('lucide-trash-2'),
|
||||
];
|
||||
|
100
app/Filament/Admin/Resources/TaxRateResource.php
Normal file
100
app/Filament/Admin/Resources/TaxRateResource.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources;
|
||||
|
||||
use App\Filament\Admin\Resources\TaxRateResource\Pages;
|
||||
use App\Models\TaxRate;
|
||||
use Filament\Forms\Components\Placeholder;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Support\Enums\FontWeight;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class TaxRateResource extends Resource
|
||||
{
|
||||
protected static ?string $model = TaxRate::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'lucide-circle-dollar-sign';
|
||||
|
||||
protected static ?string $navigationGroup = 'Settings';
|
||||
|
||||
protected static ?int $navigationSort = 11;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Section::make([
|
||||
TextInput::make('name')
|
||||
->disabledOn('edit'),
|
||||
TextInput::make('value')
|
||||
->label('Value in percentage')
|
||||
->numeric()
|
||||
->prefix('%'),
|
||||
])
|
||||
->columns(1)
|
||||
->columnSpan(2),
|
||||
|
||||
Section::make()
|
||||
->schema([
|
||||
Placeholder::make('created_at')
|
||||
->label('Created')
|
||||
->content(fn (TaxRate $record): ?string => $record->created_at?->diffForHumans()),
|
||||
|
||||
Placeholder::make('updated_at')
|
||||
->label('Last modified')
|
||||
->content(fn (TaxRate $record): ?string => $record->updated_at?->diffForHumans()),
|
||||
])
|
||||
->columnSpan(1)
|
||||
->hidden(fn (?TaxRate $record) => $record === null),
|
||||
])->columns(3);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->weight(FontWeight::Bold),
|
||||
TextColumn::make('value')
|
||||
->extraHeaderAttributes(['class' => 'w-full'])
|
||||
->suffix(' %'),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return auth()->user()->is_admin;
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListTaxRates::route('/'),
|
||||
'create' => Pages\CreateTaxRate::route('/create'),
|
||||
'edit' => Pages\EditTaxRate::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\TaxRateResource\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\TaxRateResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateTaxRate extends CreateRecord
|
||||
{
|
||||
protected static string $resource = TaxRateResource::class;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\TaxRateResource\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\TaxRateResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditTaxRate extends EditRecord
|
||||
{
|
||||
protected static string $resource = TaxRateResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\TaxRateResource\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\TaxRateResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListTaxRates extends ListRecords
|
||||
{
|
||||
protected static string $resource = TaxRateResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources;
|
||||
|
||||
use App\Filament\Admin\Resources\TaxResource\Pages;
|
||||
use App\Models\Tax;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class TaxResource extends Resource
|
||||
{
|
||||
// protected static ?string $model = Tax::class;
|
||||
|
||||
protected static ?string $navigationLabel = 'Service Tax';
|
||||
|
||||
protected static ?string $navigationIcon = 'lucide-circle-dollar-sign';
|
||||
|
||||
protected static ?string $navigationGroup = 'Settings';
|
||||
|
||||
protected static ?int $navigationSort = 11;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
//
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return auth()->user()->is_admin;
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListTaxes::route('/'),
|
||||
'create' => Pages\CreateTax::route('/create'),
|
||||
'edit' => Pages\EditTax::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\TaxResource\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\TaxResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateTax extends CreateRecord
|
||||
{
|
||||
protected static string $resource = TaxResource::class;
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\TaxResource\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\TaxResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditTax extends EditRecord
|
||||
{
|
||||
protected static string $resource = TaxResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Admin\Resources\TaxResource\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\TaxResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListTaxes extends ListRecords
|
||||
{
|
||||
protected static string $resource = TaxResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
@ -16,27 +16,25 @@ class Invoice extends Model
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'customer_id',
|
||||
'internal_id',
|
||||
'customer_id',
|
||||
'status',
|
||||
'subtotal',
|
||||
'total',
|
||||
'gst',
|
||||
'pst',
|
||||
'date',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'gst_amount',
|
||||
'pst_rate',
|
||||
'gst_rate',
|
||||
'pst_amount',
|
||||
'gst_amount',
|
||||
'has_pst',
|
||||
'has_gst',
|
||||
'date',
|
||||
'due_date',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'date' => 'datetime',
|
||||
'total' => 'decimal:2',
|
||||
'subtotal' => 'decimal:2',
|
||||
'gst' => 'bool',
|
||||
'pst' => 'bool',
|
||||
'status' => InvoiceStatus::class,
|
||||
];
|
||||
|
||||
@ -46,29 +44,46 @@ public static function boot(): void
|
||||
|
||||
static::created(function ($model) {
|
||||
$model->attributes['internal_id'] = 'TN4'.str_pad($model->id, 4, '0', STR_PAD_LEFT);
|
||||
$model->attributes['pst_rate'] = TaxRate::where('name', 'PST')->value('value');
|
||||
$model->attributes['gst_rate'] = TaxRate::where('name', 'GST')->value('value');
|
||||
$model->save();
|
||||
});
|
||||
}
|
||||
|
||||
public function setPstAttribute(int $value): void
|
||||
public function setHasPstAttribute(bool $value): void
|
||||
{
|
||||
$this->attributes['pst'] = $value;
|
||||
$this->attributes['has_pst'] = $value;
|
||||
$this->save();
|
||||
|
||||
$this->calculateTotals();
|
||||
}
|
||||
|
||||
public function setGstAttribute(int $value): void
|
||||
public function setHasGstAttribute(bool $value): void
|
||||
{
|
||||
$this->attributes['gst'] = $value;
|
||||
$this->attributes['has_gst'] = $value;
|
||||
$this->save();
|
||||
|
||||
$this->calculateTotals();
|
||||
|
||||
// dd('value: '.$value.', model: '.$this->gst);
|
||||
}
|
||||
|
||||
public function setStatus(InvoiceStatus $status)
|
||||
public function calculateTotals(): void
|
||||
{
|
||||
$subtotal = 0;
|
||||
|
||||
// $gst_amount = ($this->gst_rate / 100) * $this->gst ?? 0;
|
||||
// $pst_amount = ($this->pst_rate / 100) * $this->pst ?? 0;
|
||||
|
||||
foreach ($this->orders as $order) {
|
||||
$subtotal += $order->total_service_price;
|
||||
}
|
||||
|
||||
$this->subtotal = $subtotal;
|
||||
// $this->total = $subtotal + $gst_amount + $pst_amount;
|
||||
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function setStatus(InvoiceStatus $status): void
|
||||
{
|
||||
if ($this->status !== $status) {
|
||||
$this->status = $status;
|
||||
@ -76,37 +91,23 @@ public function setStatus(InvoiceStatus $status)
|
||||
}
|
||||
}
|
||||
|
||||
public function calculateTotals(): void
|
||||
{
|
||||
$subtotal = 0;
|
||||
|
||||
foreach ($this->orders as $order) {
|
||||
$subtotal += $order->total_service_price;
|
||||
}
|
||||
|
||||
$this->subtotal = $subtotal;
|
||||
$this->total = $subtotal + $this->gst_amount + $this->pst_amount;
|
||||
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function getGstAmountAttribute(): float
|
||||
{
|
||||
if ($this->gst) {
|
||||
return number_format($this->subtotal * 0.05, 2);
|
||||
}
|
||||
|
||||
return 0.00;
|
||||
}
|
||||
|
||||
public function getPstAmountAttribute(): float
|
||||
{
|
||||
if ($this->pst) {
|
||||
return number_format($this->subtotal * 0.07, 2);
|
||||
}
|
||||
|
||||
return 0.00;
|
||||
}
|
||||
// public function getGstAmountAttribute(): float
|
||||
// {
|
||||
// if ($this->gst) {
|
||||
// return round($this->subtotal * ($this->gst_rate / 100), 2);
|
||||
// }
|
||||
//
|
||||
// return 0.00;
|
||||
// }
|
||||
//
|
||||
// public function getPstAmountAttribute(): float
|
||||
// {
|
||||
// if ($this->pst) {
|
||||
// return round($this->subtotal * ($this->pst_rate / 100), 2);
|
||||
// }
|
||||
//
|
||||
// return 0.00;
|
||||
// }
|
||||
|
||||
public function orders(): HasMany
|
||||
{
|
||||
|
14
app/Models/TaxRate.php
Normal file
14
app/Models/TaxRate.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TaxRate extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\TaxRateFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['name', 'value'];
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
use App\Enums\InvoiceStatus;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\TaxRate;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
@ -17,9 +18,11 @@ public function definition(): array
|
||||
$customer = Customer::all()->shuffle()->first();
|
||||
|
||||
return [
|
||||
'created_at' => Carbon::now()->subDays(rand(1, 30)),
|
||||
'gst' => true,
|
||||
'pst' => $this->faker->boolean(40),
|
||||
'created_at' => Carbon::now()->subDays(rand(1, 30)),
|
||||
'pst_rate' => TaxRate::where('name', 'PST')->value('value'),
|
||||
'gst_rate' => TaxRate::where('name', 'GST')->value('value'),
|
||||
// 'gst' => true,
|
||||
// 'pst' => $this->faker->boolean(40),
|
||||
'date' => Carbon::now()->subDays(rand(1, 60)),
|
||||
'status' => $this->faker->randomElement(InvoiceStatus::cases())->value,
|
||||
'customer_id' => $customer->id,
|
||||
|
23
database/factories/TaxRateFactory.php
Normal file
23
database/factories/TaxRateFactory.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\TaxRate>
|
||||
*/
|
||||
class TaxRateFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
29
database/migrations/003_create_tax_rates_table.php
Normal file
29
database/migrations/003_create_tax_rates_table.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('tax_rates', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->decimal('value', 8, 2);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('tax_rates');
|
||||
}
|
||||
};
|
@ -19,8 +19,14 @@ public function up(): void
|
||||
$table->decimal('subtotal', 8, 2)->default(0.00);
|
||||
$table->decimal('total', 8, 2)->default(0.00);
|
||||
|
||||
$table->boolean('gst')->default(false);
|
||||
$table->boolean('pst')->default(false);
|
||||
$table->decimal('pst_rate', 8, 2);
|
||||
$table->decimal('gst_rate', 8, 2);
|
||||
|
||||
$table->decimal('pst_amount', 8, 2)->nullable();
|
||||
$table->decimal('gst_amount', 8, 2)->nullable();
|
||||
|
||||
$table->boolean('has_pst')->default(false);
|
||||
$table->boolean('has_gst')->default(true);
|
||||
|
||||
$table->date('date')->default(today());
|
||||
$table->date('due_date')->nullable();
|
@ -15,6 +15,7 @@ class DatabaseSeeder extends Seeder
|
||||
public function run(): void
|
||||
{
|
||||
$this->call([
|
||||
TaxRateSeeder::class,
|
||||
CustomerSeeder::class,
|
||||
ContactSeeder::class,
|
||||
ShippingEntrySeeder::class,
|
||||
|
18
database/seeders/TaxRateSeeder.php
Normal file
18
database/seeders/TaxRateSeeder.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\TaxRate;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class TaxRateSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
TaxRate::create(['name' => 'GST', 'value' => 5.00]);
|
||||
TaxRate::create(['name' => 'PST', 'value' => 7.00]);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user