- AP-09 Produktbestand inkl. Bewegungshistorie (product_stock_movements, ProductStockService) - AP-10 Rohstoffbestand-Ansicht je Lager (RawMaterialStockController) - AP-11 Bestandsschwellen / Out-of-Stock-Handling fuer Produkte und Shop - AP-12 Ausgang/Ausschuss (stock_disposals, StockDisposalController, InventoryService) - Set-Produkte (product_set_items) inkl. Aufloesung - Produktentwicklung & Hinweise-Verwaltung (Notices) - AP-13 Entwicklungskonzept Shop-Bestandsabzug im Plan dokumentiert - Feature-Tests fuer neue Module + aktualisierter Entwicklungsplan Co-authored-by: Cursor <cursoragent@cursor.com>
70 lines
1.3 KiB
PHP
70 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
|
|
class ProductStockMovement extends Model
|
|
{
|
|
protected $fillable = [
|
|
'product_id',
|
|
'direction',
|
|
'quantity',
|
|
'reason',
|
|
'source',
|
|
'note',
|
|
'user_id',
|
|
'reference_type',
|
|
'reference_id',
|
|
];
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'quantity' => 'integer',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Product, $this>
|
|
*/
|
|
public function product(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Product::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<User, $this>
|
|
*/
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* @return MorphTo<Model, $this>
|
|
*/
|
|
public function reference(): MorphTo
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
public function isIn(): bool
|
|
{
|
|
return $this->direction === 'in';
|
|
}
|
|
|
|
/**
|
|
* Vorzeichenbehaftete Menge (Eingang positiv, Ausgang negativ).
|
|
*/
|
|
public function signedQuantity(): int
|
|
{
|
|
return $this->isIn() ? (int) $this->quantity : -(int) $this->quantity;
|
|
}
|
|
}
|