Work on PHPStan error fixing

orders
Nisse Lommerde 2 months ago
parent 61831b1940
commit 7074596cb7

@ -4,26 +4,27 @@ namespace App\Http\Controllers;
use App\Http\Requests\ShippingEntryRequest; use App\Http\Requests\ShippingEntryRequest;
use App\Models\ShippingEntry; use App\Models\ShippingEntry;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class ShippingEntryController extends Controller class ShippingEntryController extends Controller
{ {
public function index() {} public function index(): void {}
public function create() {} public function create(): void {}
public function store(ShippingEntryRequest $request) public function store(ShippingEntryRequest $request): RedirectResponse
{ {
$entry = ShippingEntry::create($request->validated()); $entry = ShippingEntry::create($request->validated());
return redirect()->route('customers.show', [$entry->customer, 'tab' => 'shipping']); return redirect()->route('customers.show', [$entry->customer, 'tab' => 'shipping']);
} }
public function show($id) {} public function show(int $id): void {}
public function edit($id) {} public function edit(int $id): void {}
public function update(Request $request, $id) {} public function update(Request $request, int $id): void {}
public function destroy($id) {} public function destroy(int $id): void {}
} }

@ -6,6 +6,9 @@ use Illuminate\Foundation\Http\FormRequest;
class ContactRequest extends FormRequest class ContactRequest extends FormRequest
{ {
/**
* @return string[]
*/
public function rules(): array public function rules(): array
{ {
// todo: required first name if no last name and vice versa // todo: required first name if no last name and vice versa

@ -6,18 +6,21 @@ use Illuminate\Foundation\Http\FormRequest;
class CustomerRequest extends FormRequest class CustomerRequest extends FormRequest
{ {
/**
* @return array<array<string>>
*/
public function rules() public function rules()
{ {
return [ return [
'company_name' => 'required', 'company_name' => ['required'],
'internal_name' => 'required', 'internal_name' => ['required'],
'shipping_address' => 'required', 'shipping_address' => ['required'],
'billing_address' => 'required', 'billing_address' => ['required'],
'phone' => 'required', 'phone' => ['required'],
]; ];
} }
public function authorize() public function authorize(): bool
{ {
return true; return true;
} }

@ -6,6 +6,9 @@ use Illuminate\Foundation\Http\FormRequest;
class OrderProductRequest extends FormRequest class OrderProductRequest extends FormRequest
{ {
/**
* @return array<array<string>>
*/
public function rules(): array public function rules(): array
{ {
return [ return [

@ -6,6 +6,9 @@ use Illuminate\Foundation\Http\FormRequest;
class OrderRequest extends FormRequest class OrderRequest extends FormRequest
{ {
/**
* @return array<array<string>>
*/
public function rules(): array public function rules(): array
{ {
return [ return [

@ -6,15 +6,18 @@ use Illuminate\Foundation\Http\FormRequest;
class PackingSlipRequest extends FormRequest class PackingSlipRequest extends FormRequest
{ {
/**
* @return string<array<string>>
*/
public function rules(): array public function rules(): array
{ {
return [ return [
'date_received' => 'required|date', 'date_received' => ['required|date'],
'customer_id' => 'required|exists:customers,id', 'customer_id' => ['required|exists:customers,id'],
'order_id' => 'string|nullable', 'order_id' => ['string|nullable'],
'amount' => 'required|string', 'amount' => ['required|string'],
'contents' => 'required|string', 'contents' => ['required|string'],
'from_customer' => 'required|bool', 'from_customer' => ['required|bool'],
]; ];
} }

@ -6,6 +6,9 @@ use Illuminate\Foundation\Http\FormRequest;
class ProductServiceRequest extends FormRequest class ProductServiceRequest extends FormRequest
{ {
/**
* @return array<array<string>>
*/
public function rules(): array public function rules(): array
{ {
return [ return [

@ -6,6 +6,9 @@ use Illuminate\Foundation\Http\FormRequest;
class ProductSizeRequest extends FormRequest class ProductSizeRequest extends FormRequest
{ {
/**
* @return array<array<string>>
*/
public function rules(): array public function rules(): array
{ {
return [ return [

@ -6,6 +6,9 @@ use Illuminate\Foundation\Http\FormRequest;
class ServiceFileRequest extends FormRequest class ServiceFileRequest extends FormRequest
{ {
/**
* @return array<array<string>>
*/
public function rules(): array public function rules(): array
{ {
return [ return [

@ -6,6 +6,9 @@ use Illuminate\Foundation\Http\FormRequest;
class ShippingEntryRequest extends FormRequest class ShippingEntryRequest extends FormRequest
{ {
/**
* @return array<array<string>>
*/
public function rules(): array public function rules(): array
{ {
return [ return [

@ -3,7 +3,10 @@
namespace App\Livewire; namespace App\Livewire;
use Exception; use Exception;
use Illuminate\Contracts\View\Factory;
use Illuminate\Foundation\Application;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\View\View;
use Livewire\Component; use Livewire\Component;
class OrderProductsCreate extends Component class OrderProductsCreate extends Component
@ -12,21 +15,30 @@ class OrderProductsCreate extends Component
public Collection $serviceInputs; public Collection $serviceInputs;
/**
* @var array<int>
*/
public array $sizes = []; public array $sizes = [];
public array $totals = []; public array $totals = [];
public array $units = []; public array $units = [];
/**
* @var array<int>
*/
public array $prices = []; public array $prices = [];
/**
* @var array<int>
*/
public array $priceTotals = []; public array $priceTotals = [];
public int $totalQuantity = 0; public int $totalQuantity = 0;
public string $totalPrice = '$0.00'; public string $totalPrice = '$0.00';
public function updated() public function updated(): void
{ {
try { try {
foreach ($this->sizes as $index => $size) { foreach ($this->sizes as $index => $size) {
@ -48,7 +60,7 @@ class OrderProductsCreate extends Component
} }
public function addProductInput() public function addProductInput(): void
{ {
$index = $this->productInputs->count(); $index = $this->productInputs->count();
$this->productInputs->push([ $this->productInputs->push([
@ -69,28 +81,28 @@ class OrderProductsCreate extends Component
]); ]);
} }
public function determineAddProductRow($index) public function determineAddProductRow(int $index): void
{ {
if ($index == $this->productInputs->count() - 1) { if ($index == $this->productInputs->count() - 1) {
$this->addProductInput(); $this->addProductInput();
} }
} }
public function determineAddServiceProductRow($index) public function determineAddServiceProductRow(int $index): void
{ {
if ($index == $this->serviceInputs->count() - 1) { if ($index == $this->serviceInputs->count() - 1) {
$this->addServiceInput(); $this->addServiceInput();
} }
} }
public function removeProductInput($key) public function removeProductInput(int $key): void
{ {
if ($this->productInputs->count() > 1) { if ($this->productInputs->count() > 1) {
$this->productInputs->pull($key); $this->productInputs->pull($key);
} }
} }
public function addServiceInput() public function addServiceInput(): void
{ {
$this->serviceInputs->push([ $this->serviceInputs->push([
$this->serviceInputs->count() => [ $this->serviceInputs->count() => [
@ -108,14 +120,14 @@ class OrderProductsCreate extends Component
]); ]);
} }
public function removeServiceInput($key) public function removeServiceInput(int $key): void
{ {
if ($this->serviceInputs->count() > 1) { if ($this->serviceInputs->count() > 1) {
$this->serviceInputs->pull($key); $this->serviceInputs->pull($key);
} }
} }
public function mount() public function mount(): void
{ {
$this->fill([ $this->fill([
'productInputs' => collect([ 'productInputs' => collect([
@ -151,7 +163,7 @@ class OrderProductsCreate extends Component
]); ]);
} }
public function render() public function render(): \Illuminate\Contracts\View\View|Factory|Application|View
{ {
return view('livewire.order-products-create'); return view('livewire.order-products-create');
} }

@ -3,7 +3,10 @@
namespace App\Livewire; namespace App\Livewire;
use App\Models\Order; use App\Models\Order;
use Illuminate\Contracts\View\Factory;
use Illuminate\Foundation\Application;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Illuminate\View\View;
use Livewire\Component; use Livewire\Component;
use Livewire\WithPagination; use Livewire\WithPagination;
@ -11,7 +14,7 @@ class OrdersTable extends Component
{ {
use WithPagination; use WithPagination;
protected $paginationTheme = 'bootstrap'; protected string $paginationTheme = 'bootstrap';
public bool $showCustomerColumn; public bool $showCustomerColumn;
@ -25,7 +28,7 @@ class OrdersTable extends Component
public Carbon $today; public Carbon $today;
public function mount(bool $showCustomerColumn, string $orderType, string $title, ?string $customer_id = null) public function mount(bool $showCustomerColumn, string $orderType, string $title, ?string $customer_id = null): void
{ {
$this->today = Carbon::today(); $this->today = Carbon::today();
$this->showCustomerColumn = $showCustomerColumn; $this->showCustomerColumn = $showCustomerColumn;
@ -34,7 +37,7 @@ class OrdersTable extends Component
$this->customer_id = $customer_id ?? ''; $this->customer_id = $customer_id ?? '';
} }
public function render() public function render(): \Illuminate\Contracts\View\View|Factory|Application|View
{ {
return view('livewire.orders-table', [ return view('livewire.orders-table', [
'orders' => Order::with('customer') 'orders' => Order::with('customer')

@ -2,6 +2,7 @@
namespace App\Models; namespace App\Models;
use Database\Factories\ContactFactory;
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\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -9,6 +10,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class Contact extends Model class Contact extends Model
{ {
/** @use HasFactory<ContactFactory> */
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
protected $fillable = [ protected $fillable = [
@ -25,6 +27,9 @@ class Contact extends Model
return $this->first_name.' '.$this->last_name; return $this->first_name.' '.$this->last_name;
} }
/**
* @return BelongsTo<Customer, self>
*/
public function customer(): BelongsTo public function customer(): BelongsTo
{ {
return $this->belongsTo(Customer::class); return $this->belongsTo(Customer::class);

@ -2,6 +2,7 @@
namespace App\Models; namespace App\Models;
use Database\Factories\CustomerFactory;
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;
@ -9,6 +10,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class Customer extends Model class Customer extends Model
{ {
/** @use HasFactory<CustomerFactory> */
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
protected $fillable = [ protected $fillable = [
@ -19,21 +21,33 @@ class Customer extends Model
'phone', 'phone',
]; ];
/**
* @return HasMany<Contact>
*/
public function contacts(): HasMany public function contacts(): HasMany
{ {
return $this->hasMany(Contact::class); return $this->hasMany(Contact::class);
} }
/**
* @return HasMany<PackingSlip>
*/
public function packingSlips(): HasMany public function packingSlips(): HasMany
{ {
return $this->hasMany(PackingSlip::class); return $this->hasMany(PackingSlip::class);
} }
/**
* @return HasMany<ShippingEntry>
*/
public function shippingEntries(): HasMany public function shippingEntries(): HasMany
{ {
return $this->hasMany(ShippingEntry::class); return $this->hasMany(ShippingEntry::class);
} }
/**
* @return HasMany<Order>
*/
public function orders(): HasMany public function orders(): HasMany
{ {
return $this->hasMany(Order::class); return $this->hasMany(Order::class);

@ -3,7 +3,9 @@
namespace App\Models; namespace App\Models;
use App\Enums\OrderStatus; use App\Enums\OrderStatus;
use Database\Factories\OrderFactory;
use DateTimeInterface; use DateTimeInterface;
use Illuminate\Database\Eloquent\Builder;
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\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -12,6 +14,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class Order extends Model class Order extends Model
{ {
/** @use HasFactory<OrderFactory> */
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
protected $fillable = [ protected $fillable = [
@ -36,7 +39,7 @@ class Order extends Model
'active', 'active',
]; ];
public static function boot() public static function boot(): void
{ {
parent::boot(); parent::boot();
@ -46,9 +49,9 @@ class Order extends Model
}); });
} }
public function generateInternalPo($id): string public function generateInternalPo(int $id): string
{ {
$po = str_pad($id, 4, '0', STR_PAD_LEFT); $po = str_pad(strval($id), 4, '0', STR_PAD_LEFT);
$year = date('y'); $year = date('y');
return 'TN'.$year.'-'.$po; return 'TN'.$year.'-'.$po;
@ -64,38 +67,63 @@ class Order extends Model
return false; return false;
} }
public function scopeActive($query) /**
* @param Builder<Order> $query
* @return Builder<Order>
*/
public function scopeActive(Builder $query): Builder
{ {
return $query->where('status', 'approved') return $query->where('status', 'approved')
->orWhere('status', 'production'); ->orWhere('status', 'production');
} }
public function scopeFinished($query) /**
* @param Builder<Order> $query
* @return Builder<Order>
*/
public function scopeFinished(Builder $query): Builder
{ {
return $query->where('status', 'shipped') return $query->where('status', 'shipped')
->orWhere('status', 'completed'); ->orWhere('status', 'completed');
} }
public function scopeInvoiced($query) /**
* @param Builder<Order> $query
* @return Builder<Order>
*/
public function scopeInvoiced(Builder $query): Builder
{ {
return $query->where('status', 'invoiced'); return $query->where('status', 'invoiced');
} }
public function scopeRush($query) /**
* @param Builder<Order> $query
* @return Builder<Order>
*/
public function scopeRush(Builder $query): Builder
{ {
return $query->where('rush', true); return $query->where('rush', true);
} }
/**
* @return BelongsTo<Customer, self>
*/
public function customer(): BelongsTo public function customer(): BelongsTo
{ {
return $this->belongsTo(Customer::class); return $this->belongsTo(Customer::class);
} }
/**
* @return HasMany<OrderProduct>
*/
public function orderProducts(): HasMany public function orderProducts(): HasMany
{ {
return $this->hasMany(OrderProduct::class); return $this->hasMany(OrderProduct::class);
} }
/**
* @return HasMany<ProductService>
*/
public function productServices(): HasMany public function productServices(): HasMany
{ {
return $this->hasMany(ProductService::class); return $this->hasMany(ProductService::class);

@ -2,6 +2,7 @@
namespace App\Models; namespace App\Models;
use Database\Factories\OrderProductFactory;
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\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -11,6 +12,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class OrderProduct extends Model class OrderProduct extends Model
{ {
/** @use HasFactory<OrderProductFactory> */
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
protected $fillable = [ protected $fillable = [
@ -20,16 +22,25 @@ class OrderProduct extends Model
'color', 'color',
]; ];
/**
* @return BelongsTo<Order, self>
*/
public function order(): BelongsTo public function order(): BelongsTo
{ {
return $this->belongsTo(Order::class); return $this->belongsTo(Order::class);
} }
/**
* @return HasOne<ServiceFile>
*/
public function serviceFile(): HasOne public function serviceFile(): HasOne
{ {
return $this->hasOne(ServiceFile::class); return $this->hasOne(ServiceFile::class);
} }
/**
* @return HasMany<ProductSize>
*/
public function productSize(): HasMany public function productSize(): HasMany
{ {
return $this->hasMany(ProductSize::class); return $this->hasMany(ProductSize::class);

@ -2,6 +2,7 @@
namespace App\Models; namespace App\Models;
use Database\Factories\PackingSlipFactory;
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\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -9,6 +10,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class PackingSlip extends Model class PackingSlip extends Model
{ {
/** @use HasFactory<PackingSlipFactory> */
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
protected $fillable = [ protected $fillable = [
@ -19,6 +21,9 @@ class PackingSlip extends Model
'contents', 'contents',
]; ];
/**
* @return BelongsTo<Customer, self>
*/
public function customer(): BelongsTo public function customer(): BelongsTo
{ {
return $this->belongsTo(Customer::class); return $this->belongsTo(Customer::class);

@ -2,6 +2,7 @@
namespace App\Models; namespace App\Models;
use Database\Factories\ProductServiceFactory;
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\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -10,6 +11,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class ProductService extends Model class ProductService extends Model
{ {
/** @use HasFactory<ProductServiceFactory> */
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
protected $fillable = [ protected $fillable = [
@ -21,11 +23,17 @@ class ProductService extends Model
'amount_price', 'amount_price',
]; ];
/**
* @return BelongsTo<Order, self>
*/
public function order(): BelongsTo public function order(): BelongsTo
{ {
return $this->belongsTo(Order::class); return $this->belongsTo(Order::class);
} }
/**
* @return HasOne<ServiceFile>
*/
public function serviceFile(): HasOne public function serviceFile(): HasOne
{ {
return $this->hasOne(ServiceFile::class); return $this->hasOne(ServiceFile::class);

@ -2,6 +2,7 @@
namespace App\Models; namespace App\Models;
use Database\Factories\ProductSizeFactory;
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\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -9,6 +10,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class ProductSize extends Model class ProductSize extends Model
{ {
/** @use HasFactory<ProductSizeFactory> */
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
protected $fillable = [ protected $fillable = [
@ -17,6 +19,9 @@ class ProductSize extends Model
'amount', 'amount',
]; ];
/**
* @return BelongsTo<OrderProduct, self>
*/
public function orderProduct(): BelongsTo public function orderProduct(): BelongsTo
{ {
return $this->belongsTo(OrderProduct::class); return $this->belongsTo(OrderProduct::class);

@ -2,6 +2,7 @@
namespace App\Models; namespace App\Models;
use Database\Factories\ServiceFileFactory;
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\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -9,6 +10,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class ServiceFile extends Model class ServiceFile extends Model
{ {
/** @use HasFactory<ServiceFileFactory> */
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
protected $fillable = [ protected $fillable = [
@ -21,6 +23,9 @@ class ServiceFile extends Model
'setup_number', 'setup_number',
]; ];
/**
* @return BelongsTo<ProductService, self>
*/
public function productService(): BelongsTo public function productService(): BelongsTo
{ {
return $this->belongsTo(ProductService::class); return $this->belongsTo(ProductService::class);

@ -3,6 +3,7 @@
namespace App\Models; namespace App\Models;
use App\Enums\ShippingType; use App\Enums\ShippingType;
use Database\Factories\ShippingEntryFactory;
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\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -10,6 +11,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class ShippingEntry extends Model class ShippingEntry extends Model
{ {
/** @use HasFactory<ShippingEntryFactory> */
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
protected $casts = [ protected $casts = [
@ -29,6 +31,9 @@ class ShippingEntry extends Model
'notes', 'notes',
]; ];
/**
* @return BelongsTo<Customer,self>
*/
public function customer(): BelongsTo public function customer(): BelongsTo
{ {
return $this->belongsTo(Customer::class); return $this->belongsTo(Customer::class);

@ -3,12 +3,14 @@
namespace App\Models; namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail; // use Illuminate\Contracts\Auth\MustVerifyEmail;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
class User extends Authenticatable class User extends Authenticatable
{ {
/** @use HasFactory<UserFactory> */
use HasFactory, Notifiable; use HasFactory, Notifiable;
/** /**

Loading…
Cancel
Save