Erster Upload
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\User\Resources\ProductSaleResource\Pages;
|
||||
|
||||
use App\Filament\User\Resources\ProductSaleResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
class CreateProductSale extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ProductSaleResource::class;
|
||||
|
||||
protected function handleRecordCreation(array $data): Model
|
||||
{
|
||||
$count = DB::table('products_inventory')
|
||||
->where('product_id', '=', $data['product_id'])
|
||||
->where('size_id', '=', $data['size_id'])
|
||||
->count();
|
||||
|
||||
if ($count < $data['amount']) {
|
||||
Notification::make()
|
||||
->warning()
|
||||
->title('Fehler!')
|
||||
->body('Nicht genügend Produkte in dieser Größe lagernd.')
|
||||
->send();
|
||||
$this->halt();
|
||||
return false;
|
||||
}
|
||||
$record = static::getModel()::create($data);
|
||||
|
||||
DB::table('products_inventory')
|
||||
->where('product_id', '=', $data['product_id'])
|
||||
->where('size_id', '=', $data['size_id'])
|
||||
->limit($data['amount'] ?? 1)
|
||||
->update(['out_at' => now()]);
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\User\Resources\ProductSaleResource\Pages;
|
||||
|
||||
use App\Filament\User\Resources\ProductSaleResource;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditProductSale extends EditRecord
|
||||
{
|
||||
protected static string $resource = ProductSaleResource::class;
|
||||
|
||||
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
\Filament\Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\User\Resources\ProductSaleResource\Pages;
|
||||
|
||||
use App\Filament\User\Resources\ProductSaleResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListProductSales extends ListRecords
|
||||
{
|
||||
protected static string $resource = ProductSaleResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\User\Resources\ProductSaleResource\Widgets;
|
||||
|
||||
use Leandrocfe\FilamentApexCharts\Widgets\ApexChartWidget;
|
||||
use Flowframe\Trend\Trend;
|
||||
use Flowframe\Trend\TrendValue;
|
||||
use App\Models\ProductSale;
|
||||
|
||||
class SalesChart extends ApexChartWidget {
|
||||
protected static ?string $chartId = 'productSalesChart';
|
||||
protected static ?string $heading = 'Verkäufe dieses Quartal';
|
||||
|
||||
protected function getOptions(): array {
|
||||
$data = Trend::model(ProductSale::class)
|
||||
->between(
|
||||
start: now()->startOfQuarter(),
|
||||
end: now()->endOfQuarter(),
|
||||
)
|
||||
->perWeek()
|
||||
->count();
|
||||
|
||||
return [
|
||||
'chart' => [
|
||||
'type' => 'line',
|
||||
'height' => 300,
|
||||
],
|
||||
'series' => [
|
||||
[
|
||||
'name' => 'Anzahl Verkäufe',
|
||||
'data' => $data->map(fn(TrendValue $value) => $value->aggregate),
|
||||
],
|
||||
],
|
||||
'xaxis' => [
|
||||
'categories' => $data->map(fn(TrendValue $value) => $value->date),
|
||||
'labels' => [
|
||||
'style' => [
|
||||
'fontFamily' => 'inherit',
|
||||
],
|
||||
],
|
||||
],
|
||||
'yaxis' => [
|
||||
'labels' => [
|
||||
'style' => [
|
||||
'fontFamily' => 'inherit',
|
||||
],
|
||||
],
|
||||
],
|
||||
'colors' => ['#f59e0b'],
|
||||
'stroke' => [
|
||||
'curve' => 'smooth',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user