138 lines
4.1 KiB
PHP
138 lines
4.1 KiB
PHP
<?php
|
|
|
|
class WarehouseMovementModel extends TTCrudBaseModel {
|
|
public int $id;
|
|
public ?string $movementNumber = null;
|
|
public string $movementType;
|
|
public int $articleId;
|
|
public int $warehouseLocationId;
|
|
public ?int $warehouseItemId = null;
|
|
public float $quantity;
|
|
public ?float $quantityBefore = null;
|
|
public ?float $quantityAfter = null;
|
|
public string $reasonCategory;
|
|
public ?string $note = null;
|
|
public int $userId;
|
|
public int $createBy;
|
|
public int $create;
|
|
|
|
/**
|
|
* Generate next movement number (WM-YYYY-X000001)
|
|
*/
|
|
public static function generateMovementNumber(): string {
|
|
$year = date('Y');
|
|
$prefix = "WM-{$year}-X";
|
|
|
|
$db = FronkDB::singleton();
|
|
$result = $db->query("SELECT movementNumber FROM WarehouseMovement
|
|
WHERE movementNumber LIKE '{$prefix}%'
|
|
ORDER BY movementNumber DESC LIMIT 1");
|
|
|
|
if ($row = $result->fetch_assoc()) {
|
|
$lastNumber = intval(substr($row['movementNumber'], -6));
|
|
$nextNumber = $lastNumber + 1;
|
|
} else {
|
|
$nextNumber = 1;
|
|
}
|
|
|
|
return $prefix . str_pad((string)$nextNumber, 6, '0', STR_PAD_LEFT);
|
|
}
|
|
|
|
/**
|
|
* Get reason categories for a movement type
|
|
*/
|
|
public static function getReasonCategories(?string $type = null): array {
|
|
$categories = [
|
|
'IN' => [
|
|
'Warenlieferung' => 'Warenlieferung',
|
|
'Rueckgabe' => 'Rückgabe',
|
|
'Gefunden' => 'Gefunden/Inventurdifferenz',
|
|
'UmlagerungEingang' => 'Umlagerung (Eingang)',
|
|
'Erstbestand' => 'Erstbestand',
|
|
'Sonstiges' => 'Sonstiges'
|
|
],
|
|
'OUT' => [
|
|
'Verbrauch' => 'Verbrauch',
|
|
'Beschaedigung' => 'Beschädigung/Defekt',
|
|
'Verlust' => 'Verlust/Schwund',
|
|
'UmlagerungAusgang' => 'Umlagerung (Ausgang)',
|
|
'Entsorgung' => 'Entsorgung',
|
|
'Sonstiges' => 'Sonstiges'
|
|
],
|
|
'ADJUSTMENT' => [
|
|
'Inventurkorrektur' => 'Inventurkorrektur',
|
|
'Buchungsfehler' => 'Buchungsfehler',
|
|
'Systemkorrektur' => 'Systemkorrektur',
|
|
'SonstigeKorrektur' => 'Sonstige Korrektur'
|
|
]
|
|
];
|
|
|
|
if ($type && isset($categories[$type])) {
|
|
return $categories[$type];
|
|
}
|
|
|
|
return $categories;
|
|
}
|
|
|
|
/**
|
|
* Get movement type labels
|
|
*/
|
|
public static function getMovementTypes(): array {
|
|
return [
|
|
'IN' => 'Einbuchung',
|
|
'OUT' => 'Ausbuchung',
|
|
'ADJUSTMENT' => 'Korrektur'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get article object
|
|
*/
|
|
public function getArticle(): ?ArticleModel {
|
|
return ArticleModel::get($this->articleId);
|
|
}
|
|
|
|
/**
|
|
* Get location object
|
|
*/
|
|
public function getLocation(): ?WarehouseLocationModel {
|
|
return WarehouseLocationModel::get($this->warehouseLocationId);
|
|
}
|
|
|
|
/**
|
|
* Get user who made the movement
|
|
*/
|
|
public function getUser(): ?UserModel {
|
|
return UserModel::get($this->userId);
|
|
}
|
|
|
|
/**
|
|
* Get warehouse item if linked
|
|
*/
|
|
public function getWarehouseItem(): ?WarehouseItemModel {
|
|
if (!$this->warehouseItemId) return null;
|
|
return WarehouseItemModel::get($this->warehouseItemId);
|
|
}
|
|
|
|
/**
|
|
* Get formatted movement type label
|
|
*/
|
|
public function getMovementTypeLabel(): string {
|
|
$types = self::getMovementTypes();
|
|
return $types[$this->movementType] ?? $this->movementType;
|
|
}
|
|
|
|
/**
|
|
* Get formatted reason category label
|
|
*/
|
|
public function getReasonCategoryLabel(): string {
|
|
$allCategories = self::getReasonCategories();
|
|
foreach ($allCategories as $typeCategories) {
|
|
if (isset($typeCategories[$this->reasonCategory])) {
|
|
return $typeCategories[$this->reasonCategory];
|
|
}
|
|
}
|
|
return $this->reasonCategory;
|
|
}
|
|
}
|