Work on customer login
This commit is contained in:
parent
b320915fc1
commit
33f66a561e
@ -90,6 +90,16 @@ public static function form(Form $form): Form
|
|||||||
'true' => 'info',
|
'true' => 'info',
|
||||||
'false' => 'info',
|
'false' => 'info',
|
||||||
]),
|
]),
|
||||||
|
|
||||||
|
ToggleButtons::make('has_hst')
|
||||||
|
->label('HST')
|
||||||
|
->boolean('On', 'Off')
|
||||||
|
->default(false)
|
||||||
|
->inline()
|
||||||
|
->colors([
|
||||||
|
'true' => 'info',
|
||||||
|
'false' => 'info',
|
||||||
|
]),
|
||||||
])->columnSpan(1),
|
])->columnSpan(1),
|
||||||
])
|
])
|
||||||
->columns(3)
|
->columns(3)
|
||||||
@ -101,16 +111,16 @@ public static function form(Form $form): Form
|
|||||||
->label('ID')
|
->label('ID')
|
||||||
->content(fn (Invoice $record): ?string => $record->internal_id),
|
->content(fn (Invoice $record): ?string => $record->internal_id),
|
||||||
|
|
||||||
Placeholder::make('Tax Rates')
|
Placeholder::make('Tax Rates '.'(if applicable)')
|
||||||
->content(fn (Invoice $record): ?string => $record->gst_rate.'% GST, '.$record->pst_rate.'% PST'),
|
->content(fn (Invoice $record): ?string => $record->gst_rate.'% GST, '.$record->pst_rate.'% PST, '.$record->hst_rate.'% HST'),
|
||||||
|
|
||||||
Placeholder::make('created_at')
|
Placeholder::make('created_at')
|
||||||
->label('Created')
|
->label('Created')
|
||||||
->content(fn (Invoice $record): ?string => $record->created_at?->diffForHumans()),
|
->content(fn (Invoice $record): ?string => $record->created_at->format('Y-m-d')),
|
||||||
|
|
||||||
Placeholder::make('updated_at')
|
Placeholder::make('updated_at')
|
||||||
->label('Last modified')
|
->label('Last modified')
|
||||||
->content(fn (Invoice $record): ?string => $record->updated_at?->diffForHumans()),
|
->content(fn (Invoice $record): ?string => $record->updated_at->format('Y-m-d')),
|
||||||
|
|
||||||
])
|
])
|
||||||
->columnSpan(1)
|
->columnSpan(1)
|
||||||
@ -156,9 +166,10 @@ public static function table(Table $table): Table
|
|||||||
|
|
||||||
TextColumn::make('has_gst')
|
TextColumn::make('has_gst')
|
||||||
->label('GST')
|
->label('GST')
|
||||||
|
->money()
|
||||||
->formatStateUsing(function (Invoice $record) {
|
->formatStateUsing(function (Invoice $record) {
|
||||||
if ($record->has_gst) {
|
if ($record->has_gst) {
|
||||||
return '$'.$record->gst_amount;
|
return '$'.number_format($record->gst_amount, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return '-';
|
return '-';
|
||||||
@ -169,7 +180,18 @@ public static function table(Table $table): Table
|
|||||||
->label('PST')
|
->label('PST')
|
||||||
->formatStateUsing(function (Invoice $record) {
|
->formatStateUsing(function (Invoice $record) {
|
||||||
if ($record->has_pst) {
|
if ($record->has_pst) {
|
||||||
return '$'.$record->pst_amount;
|
return '$'.number_format($record->pst_amount, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return '-';
|
||||||
|
})
|
||||||
|
->alignRight(),
|
||||||
|
TextColumn::make('has_hst')
|
||||||
|
->label('HST')
|
||||||
|
->money()
|
||||||
|
->formatStateUsing(function (Invoice $record) {
|
||||||
|
if ($record->has_hst) {
|
||||||
|
return '$'.number_format($record->hst_amount, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return '-';
|
return '-';
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Filament\Forms\Components\Checkbox;
|
use Filament\Forms\Components\Checkbox;
|
||||||
use Filament\Forms\Components\Section;
|
use Filament\Forms\Components\Section;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Resources\Resource;
|
use Filament\Resources\Resource;
|
||||||
@ -48,7 +49,12 @@ public static function form(Form $form): Form
|
|||||||
->required(fn (string $operation) => $operation === 'create'),
|
->required(fn (string $operation) => $operation === 'create'),
|
||||||
|
|
||||||
Checkbox::make('is_admin')
|
Checkbox::make('is_admin')
|
||||||
->disabled(fn (User $record) => auth()->user()->id === $record->id),
|
->disabled(fn (?User $record, $operation) => $operation !== 'create' && auth()->user()->id === $record->id),
|
||||||
|
|
||||||
|
Select::make('customer_id')
|
||||||
|
->relationship('customer', 'company_name')
|
||||||
|
->searchable()
|
||||||
|
->preload(),
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
class Customer extends Model
|
class Customer extends Model
|
||||||
@ -100,4 +101,9 @@ public function invoices(): HasMany
|
|||||||
{
|
{
|
||||||
return $this->hasMany(Invoice::class);
|
return $this->hasMany(Invoice::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function user(): HasOne
|
||||||
|
{
|
||||||
|
return $this->hasOne(User::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
|
|
||||||
#[ObservedBy(InvoiceObserver::class)]
|
#[ObservedBy(InvoiceObserver::class)]
|
||||||
|
|
||||||
@ -31,10 +30,13 @@ class Invoice extends Model
|
|||||||
'total',
|
'total',
|
||||||
'pst_rate',
|
'pst_rate',
|
||||||
'gst_rate',
|
'gst_rate',
|
||||||
|
'hst_rate',
|
||||||
'pst_amount',
|
'pst_amount',
|
||||||
'gst_amount',
|
'gst_amount',
|
||||||
|
'hst_amount',
|
||||||
'has_pst',
|
'has_pst',
|
||||||
'has_gst',
|
'has_gst',
|
||||||
|
'has_hst',
|
||||||
'date',
|
'date',
|
||||||
'due_date',
|
'due_date',
|
||||||
];
|
];
|
||||||
@ -42,11 +44,13 @@ class Invoice extends Model
|
|||||||
protected $casts = [
|
protected $casts = [
|
||||||
'has_gst' => 'boolean',
|
'has_gst' => 'boolean',
|
||||||
'has_pst' => 'boolean',
|
'has_pst' => 'boolean',
|
||||||
|
'has_hst' => 'boolean',
|
||||||
'date' => 'datetime',
|
'date' => 'datetime',
|
||||||
'status' => InvoiceStatus::class,
|
'status' => InvoiceStatus::class,
|
||||||
'subtotal' => 'float',
|
'subtotal' => 'float',
|
||||||
'pst_amount' => 'float',
|
'pst_amount' => 'float',
|
||||||
'gst_amount' => 'float',
|
'gst_amount' => 'float',
|
||||||
|
'hst_amount' => 'float',
|
||||||
'total' => 'float',
|
'total' => 'float',
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -60,23 +64,26 @@ public function calculateTotals(): void
|
|||||||
$this->subtotal = 0;
|
$this->subtotal = 0;
|
||||||
$this->gst_amount = 0;
|
$this->gst_amount = 0;
|
||||||
$this->pst_amount = 0;
|
$this->pst_amount = 0;
|
||||||
|
$this->hst_amount = 0;
|
||||||
$this->total = 0;
|
$this->total = 0;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$subtotal = $this->orders->sum(fn (Order $order) => $order->total_service_price);
|
$subtotal = $this->orders->sum(fn (Order $order) => $order->total_service_price);
|
||||||
Log::debug('subtotal: '.$subtotal);
|
|
||||||
|
|
||||||
$this->subtotal = $subtotal;
|
$this->subtotal = $subtotal;
|
||||||
$this->saveQuietly();
|
$this->saveQuietly();
|
||||||
|
|
||||||
$gstAmount = $this->calculateTaxAmount($subtotal, $this->gst_rate, $this->has_gst);
|
$gstAmount = $this->calculateTaxAmount($subtotal, $this->gst_rate, $this->has_gst);
|
||||||
$pstAmount = $this->calculateTaxAmount($subtotal, $this->pst_rate, $this->has_pst);
|
$pstAmount = $this->calculateTaxAmount($subtotal, $this->pst_rate, $this->has_pst);
|
||||||
|
$hstAmount = $this->calculateTaxAmount($subtotal, $this->hst_rate, $this->has_hst);
|
||||||
|
|
||||||
$this->gst_amount = $gstAmount;
|
$this->gst_amount = $gstAmount;
|
||||||
$this->pst_amount = $pstAmount;
|
$this->pst_amount = $pstAmount;
|
||||||
$this->total = $subtotal + $gstAmount + $pstAmount;
|
$this->hst_amount = $hstAmount;
|
||||||
|
|
||||||
|
$this->total = $subtotal + $gstAmount + $pstAmount + $hstAmount;
|
||||||
|
|
||||||
$this->saveQuietly();
|
$this->saveQuietly();
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
use Database\Factories\UserFactory;
|
use Database\Factories\UserFactory;
|
||||||
use Filament\Models\Contracts\HasName;
|
use Filament\Models\Contracts\HasName;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
|
|
||||||
@ -22,6 +23,7 @@ class User extends Authenticatable implements HasName
|
|||||||
'username',
|
'username',
|
||||||
'is_admin',
|
'is_admin',
|
||||||
'password',
|
'password',
|
||||||
|
'customer_id',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,4 +52,9 @@ public function getFilamentName(): string
|
|||||||
{
|
{
|
||||||
return $this->username;
|
return $this->username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function customer(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Customer::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ public function creating(Invoice $invoice): void
|
|||||||
{
|
{
|
||||||
$invoice->pst_rate = TaxRate::where('name', 'PST')->value('value') ?? 0;
|
$invoice->pst_rate = TaxRate::where('name', 'PST')->value('value') ?? 0;
|
||||||
$invoice->gst_rate = TaxRate::where('name', 'GST')->value('value') ?? 0;
|
$invoice->gst_rate = TaxRate::where('name', 'GST')->value('value') ?? 0;
|
||||||
|
$invoice->hst_rate = TaxRate::where('name', 'HST')->value('value') ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,10 +19,12 @@ public function definition(): array
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'created_at' => Carbon::now()->subDays(rand(1, 30)),
|
'created_at' => Carbon::now()->subDays(rand(1, 30)),
|
||||||
'pst_rate' => TaxRate::where('name', 'PST')->value('value'),
|
'pst_rate' => TaxRate::where('name', 'PST')->value('value') ?? 0,
|
||||||
'gst_rate' => TaxRate::where('name', 'GST')->value('value'),
|
'gst_rate' => TaxRate::where('name', 'GST')->value('value') ?? 0,
|
||||||
|
'hst_rate' => TaxRate::where('name', 'HST')->value('value') ?? 0,
|
||||||
'has_gst' => true,
|
'has_gst' => true,
|
||||||
'has_pst' => $this->faker->boolean(40),
|
'has_pst' => $this->faker->boolean(40),
|
||||||
|
'has_hst' => false,
|
||||||
'date' => Carbon::now()->subDays(rand(1, 60)),
|
'date' => Carbon::now()->subDays(rand(1, 60)),
|
||||||
'status' => $this->faker->randomElement(InvoiceStatus::cases())->value,
|
'status' => $this->faker->randomElement(InvoiceStatus::cases())->value,
|
||||||
'customer_id' => $customer->id,
|
'customer_id' => $customer->id,
|
||||||
|
@ -13,6 +13,7 @@ public function up(): void
|
|||||||
{
|
{
|
||||||
Schema::create('users', function (Blueprint $table) {
|
Schema::create('users', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
|
$table->foreignId('customer_id')->nullable()->constrained();
|
||||||
$table->string('username')->unique();
|
$table->string('username')->unique();
|
||||||
$table->string('password');
|
$table->string('password');
|
||||||
$table->boolean('is_admin')->default(0);
|
$table->boolean('is_admin')->default(0);
|
||||||
|
@ -21,12 +21,15 @@ public function up(): void
|
|||||||
|
|
||||||
$table->decimal('pst_rate', 8, 2);
|
$table->decimal('pst_rate', 8, 2);
|
||||||
$table->decimal('gst_rate', 8, 2);
|
$table->decimal('gst_rate', 8, 2);
|
||||||
|
$table->decimal('hst_rate', 8, 2);
|
||||||
|
|
||||||
$table->decimal('pst_amount', 8, 2)->nullable();
|
$table->decimal('pst_amount', 8, 2)->nullable();
|
||||||
$table->decimal('gst_amount', 8, 2)->nullable();
|
$table->decimal('gst_amount', 8, 2)->nullable();
|
||||||
|
$table->decimal('hst_amount', 8, 2)->nullable();
|
||||||
|
|
||||||
$table->boolean('has_pst')->default(false);
|
$table->boolean('has_pst')->default(false);
|
||||||
$table->boolean('has_gst')->default(true);
|
$table->boolean('has_gst')->default(true);
|
||||||
|
$table->boolean('has_hst')->default(false);
|
||||||
|
|
||||||
$table->date('date')->default(today());
|
$table->date('date')->default(today());
|
||||||
$table->date('due_date')->nullable();
|
$table->date('due_date')->nullable();
|
||||||
|
@ -14,5 +14,6 @@ public function run(): void
|
|||||||
{
|
{
|
||||||
TaxRate::create(['name' => 'GST', 'value' => 5.00]);
|
TaxRate::create(['name' => 'GST', 'value' => 5.00]);
|
||||||
TaxRate::create(['name' => 'PST', 'value' => 7.00]);
|
TaxRate::create(['name' => 'PST', 'value' => 7.00]);
|
||||||
|
TaxRate::create(['name' => 'HST', 'value' => 13.00]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
$customer = Customer::factory()->create(); // Generates a customer
|
$customer = Customer::factory()->create(); // Generates a customer
|
||||||
$pst_rate = TaxRate::where('name', 'PST')->value('value') ?? 0;
|
$pst_rate = TaxRate::where('name', 'PST')->value('value') ?? 0;
|
||||||
$gst_rate = TaxRate::where('name', 'GST')->value('value') ?? 0;
|
$gst_rate = TaxRate::where('name', 'GST')->value('value') ?? 0;
|
||||||
|
$hst_rate = TaxRate::where('name', 'HST')->value('value') ?? 0;
|
||||||
|
|
||||||
$formData = [
|
$formData = [
|
||||||
'customer_id' => $customer->id,
|
'customer_id' => $customer->id,
|
||||||
@ -27,6 +28,7 @@
|
|||||||
'status' => InvoiceStatus::UNPAID->value,
|
'status' => InvoiceStatus::UNPAID->value,
|
||||||
'has_gst' => true,
|
'has_gst' => true,
|
||||||
'has_pst' => true,
|
'has_pst' => true,
|
||||||
|
'has_hst' => false,
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->livewire(CreateInvoice::class)
|
$this->livewire(CreateInvoice::class)
|
||||||
@ -40,8 +42,10 @@
|
|||||||
'status' => $formData['status'],
|
'status' => $formData['status'],
|
||||||
'has_gst' => $formData['has_gst'],
|
'has_gst' => $formData['has_gst'],
|
||||||
'has_pst' => $formData['has_pst'],
|
'has_pst' => $formData['has_pst'],
|
||||||
|
'has_hst' => $formData['has_hst'],
|
||||||
'gst_rate' => $gst_rate,
|
'gst_rate' => $gst_rate,
|
||||||
'pst_rate' => $pst_rate,
|
'pst_rate' => $pst_rate,
|
||||||
|
'hst_rate' => $hst_rate,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$invoice = Invoice::where('internal_id', 'INV400001')->firstOrFail();
|
$invoice = Invoice::where('internal_id', 'INV400001')->firstOrFail();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user