Update WarehouseShippingNoteController.php

This commit is contained in:
Luca Haid
2024-11-21 09:10:39 +00:00
parent 21e5c828f1
commit 11ec0cf97b

View File

@@ -4,50 +4,35 @@ class WarehouseShippingNoteController extends TTCrud {
protected string $headerTitle = 'Lieferscheine';
protected bool $createText = false;
protected array $columns = [['key' => 'id', 'text' => 'LS-Nr.', 'required' => false, 'modal' => false, 'table' => ['class' => 'text-nowrap']],
['key' => 'billingAddressId',
'text' => 'Rechnungsadresse',
'required' => true,
'type' => 'autocomplete',
'table' => ['class' => 'text-nowrap', 'filter' => 'autocomplete'],
'modal' => ['apiUrl' => 'Address/api?do=findAddress', 'items' => '/Address/Api?do=findAddress', 'type' => 'autocomplete']],
['key' => 'deliveryAddressName', 'text' => 'L.-Adr. Name', 'required' => true],
['key' => 'deliveryAddressLine', 'text' => 'L.-Adr.', 'required' => true],
['key' => 'deliveryAddressPLZ', 'text' => 'L.-Adr. PLZ', 'required' => true],
['key' => 'deliveryAddressEMail', 'text' => 'L.-Adr. EMail', 'required' => false, 'table' => false],
['key' => 'note', 'text' => 'Art der Arbeit', 'required' => true, 'table' => false],
['key' => 'status',
'text' => 'Status',
'required' => true,
'table' => ['filter' => 'select'],
'modal' => ['type' => 'select',
'items' => [['value' => 'new', 'text' => 'Neu'],
['value' => 'accepted', 'text' => 'Akzeptiert'],
['value' => 'invoiced', 'text' => 'In Rechnung gestellt'],]]],
['key' => 'positions', 'text' => 'Positionen', 'required' => true, 'table' => false, 'modal' => false],
['key' => 'create', 'text' => 'Erstellt', 'required' => false, 'modal' => false, 'table' => ['filter' => 'date']],
['key' => 'createBy',
'text' => 'Erstellt von',
'required' => true,
'type' => 'autocomplete',
'table' => ['class' => 'text-nowrap', 'filter' => 'select'],
'modal' => ['items' => [], 'type' => 'select',]],
//@formatter:off
protected array $columns = [
['key' => 'id', 'text' => 'LS-Nr.', 'required' => false, 'modal' => false, 'table' => ['class' => 'text-nowrap']],
['key' => 'billingAddressId', 'text' => 'Rechnungsadresse', 'required' => true, 'type' => 'autocomplete', 'table' => ['class' => 'text-nowrap', 'filter' => 'autocomplete'], 'modal' => ['apiUrl' => 'Address/api?do=findAddress', 'items' => '/Address/Api?do=findAddress', 'type' => 'autocomplete']],
['key' => 'deliveryAddressName', 'text' => 'L.-Adr. Name', 'required' => true],
['key' => 'deliveryAddressLine', 'text' => 'L.-Adr.', 'required' => true],
['key' => 'deliveryAddressPLZ', 'text' => 'L.-Adr. PLZ', 'required' => true],
['key' => 'deliveryAddressEMail', 'text' => 'L.-Adr. EMail', 'required' => false, 'table' => false],
['key' => 'note', 'text' => 'Art der Arbeit', 'required' => true, 'table' => false],
['key' => 'status', 'text' => 'Status', 'required' => true, 'table' => ['filter' => 'select'], 'modal' => ['type' => 'select', 'items' => [['value' => 'new', 'text' => 'Neu'], ['value' => 'inProgress', 'text' => 'In Bearbeitung'], ['value' => 'accepted', 'text' => 'Akzeptiert'], ['value' => 'invoiced', 'text' => 'In Rechnung gestellt'],]]],
['key' => 'positions', 'text' => 'Positionen', 'required' => true, 'table' => false, 'modal' => false],
['key' => 'create', 'text' => 'Erstellt', 'required' => false, 'modal' => false, 'table' => ['filter' => 'date']],
['key' => 'createBy', 'text' => 'Erstellt von', 'required' => true, 'type' => 'autocomplete', 'table' => ['class' => 'text-nowrap', 'filter' => 'select'], 'modal' => ['items' => [], 'type' => 'select',]],
['key' => 'actions', 'text' => 'Aktionen', 'required' => false, 'modal' => false, 'table' => ['filter' => false, 'sortable' => false, 'class' => 'text-center']],];
['key' => 'actions',
'text' => 'Aktionen',
'required' => false,
'modal' => false,
'table' => ['filter' => false, 'sortable' => false, 'class' => 'text-center']],];
protected array $defaultOrder = ['key' => 'create', 'order' => 'DESC'];
protected array $additionalActions = [['key' => 'openHistory', 'title' => 'Historie', 'class' => 'fas fa-history text-primary'],
['key' => 'print', 'title' => 'Drucken', 'class' => 'fas fa-print text-primary'],
['key' => 'printWithPrice', 'title' => 'Drucken mit Preis', 'class' => 'fas fa-print text-success'],
];
protected array $additionalJSVariables = ['WAREHOUSE_ADMIN' => true];
protected array $infoMessages = ['create' => 'Lieferschein wurde erstellt.',
'update' => 'Lieferschein wurde aktualisiert',
'delete' => 'Lieferschein wurde gelöscht',
'noChanges' => 'Keine Änderungen vorgenommen'];
//@formatter:on
protected function prepareCrudConfig() {
$users = array_map(function ($user) {
@@ -55,6 +40,10 @@ class WarehouseShippingNoteController extends TTCrud {
}, UserModel::search());
$this->columns[array_search('createBy', array_column($this->columns, 'key'))]['modal']['items'] = $users;
if (!$this->user->can('WarehouseAdmin')) {
$this->additionalJSVariables['WAREHOUSE_ADMIN'] = false;
}
}
protected function beforeCreate($postData): bool {
@@ -81,6 +70,14 @@ class WarehouseShippingNoteController extends TTCrud {
}
protected function beforeUpdate($postData): bool {
$shippingNote = WarehouseShippingNoteModel::get($postData['id']);
if ($shippingNote->status === 'accepted' || $shippingNote->status === 'invoiced') {
http_response_code(500);
self::returnJson(['success' => false, 'message' => 'Änderungen nicht mehr möglich']);
die();
}
$postData['positions'] = json_encode($postData['positions']);
(new WarehouseHistoryController)->create($postData, $this->mod);
return true;
@@ -242,9 +239,10 @@ class WarehouseShippingNoteController extends TTCrud {
// json decode hoursEntries and add to positions
$hoursEntries = json_decode($shippingNote->hoursEntries, true);
foreach ($hoursEntries as $hoursEntry) {
// die(json_encode($hoursEntry));
$positions[] = [
'articleTitle' => "Arbeitsstunden",
'articleDescription' => "Mitarbeiter: " . UserModel::getOne($hoursEntry['userId'])->name,
'articleDescription' => "Datum: ". date("d.m.Y", strtotime($hoursEntry['date'])) . " | Mitarbeiter: " . UserModel::getOne($hoursEntry['userId'])->name,
'articleUnit' => 'Std.',
'amount' => $hoursEntry['hourCount'],
'price' => $hoursEntry['hourlyPrice'] * $hoursEntry['hourCount'] ?? 0,
@@ -277,8 +275,8 @@ class WarehouseShippingNoteController extends TTCrud {
}
$pdf_vars = ["shippingNote" => $shippingNote,
"positions" => $positions,
"textElements" => $textElements,
"positions" => $positions,
"textElements" => $textElements,
"showPrices" => isset($_GET['price']) && $_GET['price'] == "true",
"bank_iban" => TT_INVOICE_BANK_IBAN,
"bank_bic" => TT_INVOICE_BANK_BIC,
@@ -328,7 +326,7 @@ class WarehouseShippingNoteController extends TTCrud {
// TODO: either move this to UserController or make it better
protected function userAutoCompleteAction() {
$users = array_map(function($user) {
$users = array_map(function ($user) {
return ['value' => $user->id, 'text' => $user->name];
}, UserModel::search(['employee' => true]));
@@ -336,11 +334,11 @@ class WarehouseShippingNoteController extends TTCrud {
$searchedID = $this->request->searchedID;
if (strlen($searchedID) > 0) {
// find user with value searchedID
$out = array_filter($users, function($user) use ($searchedID) {
$out = array_filter($users, function ($user) use ($searchedID) {
return $user['value'] == $searchedID;
});
} else {
$out = array_filter($users, function($user) {
$out = array_filter($users, function ($user) {
;
return strpos(strtolower($user['text']), strtolower($this->request->q)) !== false;
});
@@ -353,19 +351,20 @@ class WarehouseShippingNoteController extends TTCrud {
//TODO: either move this to TimerecordingCarController or make it better
protected function timerecordingCarAutoCompleteAction() {
$timerecordingCars = array_map(function($timerecordingCar) {
return ['value' => $timerecordingCar->id, 'text' => $timerecordingCar->number_plate . " " . $timerecordingCar->brand . " " . $timerecordingCar->model];
$timerecordingCars = array_map(function ($timerecordingCar) {
return ['value' => $timerecordingCar->id,
'text' => $timerecordingCar->number_plate . " " . $timerecordingCar->brand . " " . $timerecordingCar->model];
}, TimerecordingCarModel::getAll());
$out = null;
$searchedID = $this->request->searchedID;
if (strlen($searchedID) > 0) {
// find user with value searchedID
$out = array_filter($timerecordingCars, function($timerecordingCar) use ($searchedID) {
$out = array_filter($timerecordingCars, function ($timerecordingCar) use ($searchedID) {
return $timerecordingCar['value'] == $searchedID;
});
} else {
$out = array_filter($timerecordingCars, function($timerecordingCar) {
$out = array_filter($timerecordingCars, function ($timerecordingCar) {
return strpos(strtolower($timerecordingCar['text']), strtolower($this->request->q)) !== false;
});
@@ -395,10 +394,9 @@ class WarehouseShippingNoteController extends TTCrud {
$out = [];
foreach ($data as $entry) {
$parsedDisplayNameParts = [];
foreach(explode(',', $entry['display_name']) as $part) {
foreach (explode(',', $entry['display_name']) as $part) {
// if str_includes Bezirk remove it
if (strpos($part, 'Bezirk') !== false) {
continue;