WIP Tax Rates
This commit is contained in:
parent
306afd630b
commit
26532e281b
@ -11,7 +11,6 @@
|
|||||||
use Filament\Tables\Columns\Summarizers\Summarizer;
|
use Filament\Tables\Columns\Summarizers\Summarizer;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Query\Builder;
|
|
||||||
|
|
||||||
class CustomerReportResource extends Resource
|
class CustomerReportResource extends Resource
|
||||||
{
|
{
|
||||||
@ -45,14 +44,13 @@ public static function table(Table $table): Table
|
|||||||
|
|
||||||
Tables\Columns\TextColumn::make('subtotal')
|
Tables\Columns\TextColumn::make('subtotal')
|
||||||
->money()
|
->money()
|
||||||
->summarize(Summarizer::make()->using(function (Builder $query, Table $table) {
|
->summarize(Summarizer::make()->using(function ($query, Table $table) {
|
||||||
return '$'.
|
$createdAt = $table->getfilter('created_at')->getstate()['created_at'] ?? '1900-01-01';
|
||||||
number_format(
|
$createdUntil = $table->getfilter('created_until')->getstate()['created_until'] ?? '2100-01-01';
|
||||||
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, '.', ',');
|
|
||||||
|
|
||||||
|
$invoiceSum = invoice::wherebetween('date', [$createdAt, $createdUntil])->sum('subtotal');
|
||||||
|
|
||||||
|
return '$'.number_format(round($invoiceSum, 2), 2, '.', ',');
|
||||||
}))
|
}))
|
||||||
->alignRight()
|
->alignRight()
|
||||||
->getStateUsing(function (Table $table, Model $record) {
|
->getStateUsing(function (Table $table, Model $record) {
|
||||||
@ -86,14 +84,13 @@ public static function table(Table $table): Table
|
|||||||
|
|
||||||
Tables\Columns\TextColumn::make('total')
|
Tables\Columns\TextColumn::make('total')
|
||||||
->money()
|
->money()
|
||||||
->summarize(Summarizer::make()->using(function (Builder $query, Table $table) {
|
->summarize(summarizer::make()->using(function ($query, table $table) {
|
||||||
return '$'.
|
$createdAt = $table->getfilter('created_at')->getstate()['created_at'] ?? '1900-01-01';
|
||||||
number_format(
|
$createdUntil = $table->getfilter('created_until')->getstate()['created_until'] ?? '2100-01-01';
|
||||||
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, '.', ',');
|
|
||||||
|
|
||||||
|
$invoiceSum = invoice::wherebetween('date', [$createdAt, $createdUntil])->sum('total');
|
||||||
|
|
||||||
|
return '$'.number_format(round($invoiceSum, 2), 2, '.', ',');
|
||||||
}))
|
}))
|
||||||
->weight('bold')
|
->weight('bold')
|
||||||
->alignRight()
|
->alignRight()
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Filament\Admin\Resources\OrderResource\Pages;
|
namespace App\Filament\Admin\Resources\OrderResource\Pages;
|
||||||
|
|
||||||
use App\Enums\OrderAttributes;
|
use App\Enums\OrderAttributes;
|
||||||
|
use App\Enums\OrderStatus;
|
||||||
use App\Filament\Admin\Resources\OrderResource;
|
use App\Filament\Admin\Resources\OrderResource;
|
||||||
use App\Models\Order;
|
use App\Models\Order;
|
||||||
use App\Models\OrderProduct;
|
use App\Models\OrderProduct;
|
||||||
@ -148,7 +149,9 @@ protected function getHeaderActions(): array
|
|||||||
->label('Save changes')
|
->label('Save changes')
|
||||||
->action('save')
|
->action('save')
|
||||||
->icon('lucide-save'),
|
->icon('lucide-save'),
|
||||||
|
|
||||||
Actions\ReplicateAction::make()
|
Actions\ReplicateAction::make()
|
||||||
|
->label('Duplicate')
|
||||||
->icon('lucide-copy')
|
->icon('lucide-copy')
|
||||||
->color('info')
|
->color('info')
|
||||||
->mutateRecordDataUsing(function (array $data): array {
|
->mutateRecordDataUsing(function (array $data): array {
|
||||||
@ -157,12 +160,27 @@ protected function getHeaderActions(): array
|
|||||||
|
|
||||||
return $data;
|
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])),
|
->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')
|
Action::make('print')
|
||||||
->icon('lucide-printer')
|
->icon('lucide-printer')
|
||||||
->url(fn (Order $record) => route('orders.pdf', $record))
|
->url(fn (Order $record) => route('orders.pdf', $record))
|
||||||
->openUrlInNewTab(),
|
->openUrlInNewTab(),
|
||||||
|
|
||||||
Actions\DeleteAction::make()
|
Actions\DeleteAction::make()
|
||||||
->icon('lucide-trash-2'),
|
->icon('lucide-trash-2'),
|
||||||
];
|
];
|
||||||
|
@ -2,18 +2,16 @@
|
|||||||
|
|
||||||
namespace App\Filament\Admin\Resources;
|
namespace App\Filament\Admin\Resources;
|
||||||
|
|
||||||
use App\Filament\Admin\Resources\TaxResource\Pages;
|
use App\Filament\Admin\Resources\TaxRateResource\Pages;
|
||||||
use App\Models\Tax;
|
use App\Models\TaxRate;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Resources\Resource;
|
use Filament\Resources\Resource;
|
||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
class TaxResource extends Resource
|
class TaxRateResource extends Resource
|
||||||
{
|
{
|
||||||
// protected static ?string $model = Tax::class;
|
protected static ?string $model = TaxRate::class;
|
||||||
|
|
||||||
protected static ?string $navigationLabel = 'Service Tax';
|
|
||||||
|
|
||||||
protected static ?string $navigationIcon = 'lucide-circle-dollar-sign';
|
protected static ?string $navigationIcon = 'lucide-circle-dollar-sign';
|
||||||
|
|
||||||
@ -48,11 +46,6 @@ public static function table(Table $table): Table
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function canAccess(): bool
|
|
||||||
{
|
|
||||||
return auth()->user()->is_admin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getRelations(): array
|
public static function getRelations(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -60,12 +53,17 @@ public static function getRelations(): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function canAccess(): bool
|
||||||
|
{
|
||||||
|
return auth()->user()->is_admin;
|
||||||
|
}
|
||||||
|
|
||||||
public static function getPages(): array
|
public static function getPages(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'index' => Pages\ListTaxes::route('/'),
|
'index' => Pages\ListTaxRates::route('/'),
|
||||||
'create' => Pages\CreateTax::route('/create'),
|
'create' => Pages\CreateTaxRate::route('/create'),
|
||||||
'edit' => Pages\EditTax::route('/{record}/edit'),
|
'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,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(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
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'];
|
||||||
|
}
|
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 [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -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');
|
||||||
|
}
|
||||||
|
};
|
@ -27,6 +27,7 @@ public function run(): void
|
|||||||
QuoteSeeder::class,
|
QuoteSeeder::class,
|
||||||
InvoiceSeeder::class,
|
InvoiceSeeder::class,
|
||||||
InvoiceReportSeeder::class,
|
InvoiceReportSeeder::class,
|
||||||
|
TaxRateSeeder::class,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
User::factory()->create([
|
User::factory()->create([
|
||||||
|
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