More work on invoices
This commit is contained in:
parent
256cc1f7ed
commit
562e499d12
@ -3,10 +3,10 @@
|
|||||||
namespace App\Filament\Resources;
|
namespace App\Filament\Resources;
|
||||||
|
|
||||||
use App\Filament\Resources\InvoiceResource\Pages;
|
use App\Filament\Resources\InvoiceResource\Pages;
|
||||||
|
use App\Filament\Resources\InvoiceResource\RelationManagers\OrdersRelationManager;
|
||||||
use App\Filament\Resources\InvoiceResource\RelationManagers\ProductServicesRelationManager;
|
use App\Filament\Resources\InvoiceResource\RelationManagers\ProductServicesRelationManager;
|
||||||
use App\Models\Customer;
|
use App\Models\Customer;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Order;
|
|
||||||
use Filament\Forms\Components\DatePicker;
|
use Filament\Forms\Components\DatePicker;
|
||||||
use Filament\Forms\Components\Grid;
|
use Filament\Forms\Components\Grid;
|
||||||
use Filament\Forms\Components\Section;
|
use Filament\Forms\Components\Section;
|
||||||
@ -43,15 +43,6 @@ public static function form(Form $form): Form
|
|||||||
->searchable()
|
->searchable()
|
||||||
->columnSpan(2),
|
->columnSpan(2),
|
||||||
|
|
||||||
Select::make('orders')
|
|
||||||
->options(fn ($get): array => Order::where('customer_id', $get('customer_id') ?? null)->whereNull('invoice_id')
|
|
||||||
->get()
|
|
||||||
->pluck('customer_po', 'id')
|
|
||||||
->toArray())
|
|
||||||
->multiple()
|
|
||||||
->searchable()
|
|
||||||
->columnSpan(2),
|
|
||||||
|
|
||||||
Split::make([
|
Split::make([
|
||||||
DatePicker::make('date')
|
DatePicker::make('date')
|
||||||
->required()
|
->required()
|
||||||
@ -114,9 +105,6 @@ public static function table(Table $table): Table
|
|||||||
->defaultSort('created_at', 'desc')
|
->defaultSort('created_at', 'desc')
|
||||||
->actions([
|
->actions([
|
||||||
Tables\Actions\EditAction::make(),
|
Tables\Actions\EditAction::make(),
|
||||||
// ->after(function (Invoice $record) {
|
|
||||||
// return redirect(EditInvoice::getUrl(['record' => $record->id]));
|
|
||||||
// }),
|
|
||||||
])
|
])
|
||||||
->bulkActions([
|
->bulkActions([
|
||||||
Tables\Actions\BulkActionGroup::make([
|
Tables\Actions\BulkActionGroup::make([
|
||||||
@ -128,6 +116,7 @@ public static function table(Table $table): Table
|
|||||||
public static function getRelations(): array
|
public static function getRelations(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
OrdersRelationManager::class,
|
||||||
ProductServicesRelationManager::class,
|
ProductServicesRelationManager::class,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -3,50 +3,17 @@
|
|||||||
namespace App\Filament\Resources\InvoiceResource\Pages;
|
namespace App\Filament\Resources\InvoiceResource\Pages;
|
||||||
|
|
||||||
use App\Filament\Resources\InvoiceResource;
|
use App\Filament\Resources\InvoiceResource;
|
||||||
use App\Models\Invoice;
|
|
||||||
use App\Models\Order;
|
|
||||||
use Filament\Actions;
|
use Filament\Actions;
|
||||||
use Filament\Resources\Pages\EditRecord;
|
use Filament\Resources\Pages\EditRecord;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class EditInvoice extends EditRecord
|
class EditInvoice extends EditRecord
|
||||||
{
|
{
|
||||||
protected static string $resource = InvoiceResource::class;
|
protected static string $resource = InvoiceResource::class;
|
||||||
|
|
||||||
protected function mutateFormDataBeforeFill(array $data): array
|
|
||||||
{
|
|
||||||
$invoice = Invoice::findOrFail($data['id']);
|
|
||||||
|
|
||||||
foreach ($invoice->orders as $order) {
|
|
||||||
$data['orders'][] = $order->customer_po;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function handleRecordUpdate(Model $record, array $data): Model
|
|
||||||
{
|
|
||||||
foreach ($record->orders as $order) {
|
|
||||||
$order->invoice()->disassociate();
|
|
||||||
$order->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
$record->orders()->saveMany(Order::findMany($data['orders']));
|
|
||||||
|
|
||||||
$record->calculateTotals();
|
|
||||||
|
|
||||||
return $record;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Actions\DeleteAction::make(),
|
Actions\DeleteAction::make(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getRedirectUrl(): string
|
|
||||||
{
|
|
||||||
return $this->getResource()::getUrl('edit', ['record' => $this->record->id]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
use Filament\Resources\RelationManagers\RelationManager;
|
use Filament\Resources\RelationManagers\RelationManager;
|
||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
class OrdersRelationManager extends RelationManager
|
class OrdersRelationManager extends RelationManager
|
||||||
{
|
{
|
||||||
@ -18,7 +19,7 @@ public function form(Form $form): Form
|
|||||||
->schema([
|
->schema([
|
||||||
Forms\Components\TextInput::make('customer_po')
|
Forms\Components\TextInput::make('customer_po')
|
||||||
->required()
|
->required()
|
||||||
->maxLength(255),
|
->maxLength(100),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,22 +28,36 @@ public function table(Table $table): Table
|
|||||||
return $table
|
return $table
|
||||||
->recordTitleAttribute('customer_po')
|
->recordTitleAttribute('customer_po')
|
||||||
->columns([
|
->columns([
|
||||||
Tables\Columns\TextColumn::make('customer_po'),
|
Tables\Columns\TextColumn::make('customer_po')
|
||||||
|
->color('code')
|
||||||
|
->weight('bold'),
|
||||||
|
Tables\Columns\TextColumn::make('total_product_quantity'),
|
||||||
|
Tables\Columns\TextColumn::make('total_service_price')
|
||||||
|
->prefix('$'),
|
||||||
])
|
])
|
||||||
->filters([
|
->filters([
|
||||||
//
|
//
|
||||||
])
|
])
|
||||||
->headerActions([
|
->headerActions([
|
||||||
Tables\Actions\AssociateAction::make()
|
Tables\Actions\AssociateAction::make()
|
||||||
->multiple(),
|
->multiple()
|
||||||
|
->preloadRecordSelect()
|
||||||
|
->recordSelectOptionsQuery(fn (Builder $query) => $query->where('customer_id', $this->ownerRecord->customer->id))
|
||||||
|
->after(function () {
|
||||||
|
$this->ownerRecord->calculateTotals();
|
||||||
|
}),
|
||||||
])
|
])
|
||||||
->actions([
|
->actions([
|
||||||
Tables\Actions\DeleteAction::make(),
|
Tables\Actions\DissociateAction::make()
|
||||||
|
->after(function () {
|
||||||
|
$this->ownerRecord->calculateTotals();
|
||||||
|
}),
|
||||||
])
|
])
|
||||||
->bulkActions([
|
->bulkActions([
|
||||||
Tables\Actions\BulkActionGroup::make([
|
Tables\Actions\BulkActionGroup::make([
|
||||||
Tables\Actions\DeleteBulkAction::make(),
|
Tables\Actions\DissociateBulkAction::make(),
|
||||||
]),
|
]),
|
||||||
]);
|
])
|
||||||
|
->inverseRelationship('invoice');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ class Order extends Model
|
|||||||
|
|
||||||
protected $appends = [
|
protected $appends = [
|
||||||
'total_service_price',
|
'total_service_price',
|
||||||
|
'total_product_quantity',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
@ -79,7 +80,7 @@ public function generateInternalPo(int $id): string
|
|||||||
return 'TN'.$year.'-'.$po;
|
return 'TN'.$year.'-'.$po;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function totalProductQuantity(): int
|
public function getTotalProductQuantityAttribute(): int
|
||||||
{
|
{
|
||||||
$total = 0;
|
$total = 0;
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ public function up(): void
|
|||||||
|
|
||||||
$table->boolean('gst')->default(0);
|
$table->boolean('gst')->default(0);
|
||||||
$table->boolean('pst')->default(0);
|
$table->boolean('pst')->default(0);
|
||||||
|
$table->boolean('paid')->default(0);
|
||||||
|
|
||||||
$table->date('date')->default(today());
|
$table->date('date')->default(today());
|
||||||
$table->date('due_date')->nullable();
|
$table->date('due_date')->nullable();
|
||||||
|
@ -313,7 +313,7 @@ class="py-0 form-control-plaintext text-secondary"
|
|||||||
<label for="total-quantity" class="text-nowrap col-form-label">Total Quantity:</label>
|
<label for="total-quantity" class="text-nowrap col-form-label">Total Quantity:</label>
|
||||||
|
|
||||||
<input type="number" name="total-quantity" id="" class="form-control-plaintext" readonly
|
<input type="number" name="total-quantity" id="" class="form-control-plaintext" readonly
|
||||||
value="{{$order->totalProductQuantity()}}">
|
value="{{$order->getTotalProductQuantity()}}">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Product Services -->
|
<!-- Product Services -->
|
||||||
|
@ -172,7 +172,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row mt-3 text-end" style="font-size: 11px">
|
<div class="row mt-3 text-end" style="font-size: 11px">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
TOTAL QUANTITY: {{$order->totalProductQuantity()}}
|
TOTAL QUANTITY: {{$order->totalProductQuantity}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user