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\Models\ShippingEntry;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
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());
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
{
/**
* @return string[]
*/
public function rules(): array
{
// todo: required first name if no last name and vice versa

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

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

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

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

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

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

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

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

@ -3,7 +3,10 @@
namespace App\Livewire;
use Exception;
use Illuminate\Contracts\View\Factory;
use Illuminate\Foundation\Application;
use Illuminate\Support\Collection;
use Illuminate\View\View;
use Livewire\Component;
class OrderProductsCreate extends Component
@ -12,21 +15,30 @@ class OrderProductsCreate extends Component
public Collection $serviceInputs;
/**
* @var array<int>
*/
public array $sizes = [];
public array $totals = [];
public array $units = [];
/**
* @var array<int>
*/
public array $prices = [];
/**
* @var array<int>
*/
public array $priceTotals = [];
public int $totalQuantity = 0;
public string $totalPrice = '$0.00';
public function updated()
public function updated(): void
{
try {
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();
$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) {
$this->addProductInput();
}
}
public function determineAddServiceProductRow($index)
public function determineAddServiceProductRow(int $index): void
{
if ($index == $this->serviceInputs->count() - 1) {
$this->addServiceInput();
}
}
public function removeProductInput($key)
public function removeProductInput(int $key): void
{
if ($this->productInputs->count() > 1) {
$this->productInputs->pull($key);
}
}
public function addServiceInput()
public function addServiceInput(): void
{
$this->serviceInputs->push([
$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) {
$this->serviceInputs->pull($key);
}
}
public function mount()
public function mount(): void
{
$this->fill([
'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');
}

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save