Files
thetool/application/WarehouseOrder/WarehouseOrderController.php
2025-01-31 16:09:03 +01:00

77 lines
3.6 KiB
PHP

<?php
//TODO: enable switching distributors in the order preview
class WarehouseOrderController extends TTCrud {
protected string $headerTitle = 'Lieferantenbestellungen';
protected bool $createText = false;
protected array $columns = [
['key' => 'id', 'text' => 'ID', 'modal' => false],
['key' => 'orderNumber', 'text' => 'Bestellnummer', 'required' => true, 'modal' => false],
['key' => 'delAddrCity', 'text' => 'Stadt', 'required' => true, 'modal' => false],
['key' => 'delAddrEMail', 'text' => 'E-Mail', 'required' => true, 'modal' => false],
['key' => 'delAddrLine', 'text' => 'Adresse', 'required' => true, 'modal' => false],
['key' => 'delAddrName', 'text' => 'Name', 'required' => true, 'modal' => false],
['key' => 'delAddrPLZ', 'text' => 'PLZ', 'required' => true, 'modal' => false],
['key' => 'editor', 'text' => 'Bearbeiter', 'required' => true, 'modal' => false],
['key' => 'note', 'text' => 'Notiz', 'required' => true, 'modal' => false],
['key' => 'positions', 'text' => 'Positionen', 'required' => true, 'modal' => false],
['key' => 'create', 'text' => 'Erstellt', 'required' => true, 'modal' => false],
['key' => 'createBy', 'text' => 'Erstellt von', 'required' => true, 'modal' => ['type' => 'select']],
['key' => 'actions',
'text' => 'Aktionen',
'required' => false,
'modal' => false,
'table' => ['filter' => false, 'sortable' => false, 'class' => 'text-center']],
];
protected array $permissionCheck = ['WarehouseAdmin'];
protected array $additionalActions = [['key' => 'openHistory', 'title' => 'Historie', 'class' => 'fas fa-history text-primary']];
protected array $infoMessages = ['create' => 'Bestellung wurde erfolgreich erstellt.',
'update' => 'Bestellung wurde aktualisiert.',
'delete' => 'Bestellung wurde gelöscht',
'noChanges' => 'Keine Änderungen',];
protected function beforeCreate(): bool {
$currentCount = WarehouseOrderModel::count(['create' => ['from' => strtotime(date('Y-01-01'))]]);
$this->postData['orderNumber'] = 'PO' . date('Y') . '-' . str_pad($currentCount + 1, 4, '0', STR_PAD_LEFT);
return true;
}
protected function getArticleDistributorDataAction() {
$data = [];
$article = $this->request->articleId;
if ($this->request->allDistributor === 'true') {
foreach (WarehouseDistributorModel::getAll() as $distributor) {
$data[] = [
'id' => $distributor->id,
'name' => $distributor->name,
];
}
} elseif (!empty($article)) {
foreach (WarehouseArticleDistributorModel::getAll(['articleId' => $this->request->articleId]) as $distributor) {
$data[] = [
'id' => $distributor->distributorId,
'name' => WarehouseDistributorModel::get($distributor->distributorId)->name,
'purchasePrice' => $distributor->purchasePrice,
'externalArticleNumber' => $distributor->externalArticleNumber,
];
}
}
self::returnJson($data);
}
protected function beforeUpdate($postData): bool {
(new WarehouseHistoryController)->create($postData, $this->mod);
return true;
}
protected function getHistoryAction() {
self::returnJson((new WarehouseHistoryController)->getHistory($this->request->id, $this->mod, $this->columns));
}
}