changed shipping note

This commit is contained in:
Luca Haid
2024-12-09 13:14:44 +01:00
parent 0434c5942b
commit 5e5feb3ce6
5 changed files with 105 additions and 19 deletions

View File

@@ -13,7 +13,7 @@ class WarehouseShippingNoteController extends TTCrud {
['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' => 'status', 'text' => 'Status', 'required' => true, 'table' => ['filter' => 'select'], 'modal' => ['type' => 'select', 'items' => [['value' => 'new', 'text' => 'Neu'], ['value' => 'in_progress', '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',]],
@@ -247,18 +247,20 @@ class WarehouseShippingNoteController extends TTCrud {
$articleTitle = "Arbeitsstunden (100% Zuschlag)";
}
$positions[] = [
'articleTitle' => $articleTitle,
'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,
];
if (intval($hoursEntry['hourCount']) > 0) {
$positions[] = [
'articleTitle' => $articleTitle,
'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,
];
}
if ($hoursEntry['carId']) {
$positions[] = [
'articleTitle' => "Fahrkostenpauschale",
'articleDescription' => "Fahrzeug: " . TimerecordingCarModel::getOne($hoursEntry['carId'])->number_plate,
'articleTitle' => "Fahrkostenpauschale (hin und retour)",
'articleDescription' => "Datum: ". date("d.m.Y", strtotime($hoursEntry['date'])) . " | Fahrzeug: " . TimerecordingCarModel::getOne($hoursEntry['carId'])->number_plate,
'articleUnit' => 'Km',
'amount' => $hoursEntry['kilometerCount'],
'price' => 1 * $hoursEntry['kilometerCount'] ?? 0,
@@ -268,6 +270,21 @@ class WarehouseShippingNoteController extends TTCrud {
}
usort($positions, function ($a, $b) {
$aHasMitarbeiter = str_contains($a['articleDescription'], 'Mitarbeiter');
$bHasMitarbeiter = str_contains($b['articleDescription'], 'Mitarbeiter');
$aHasFahrzeug = str_contains($a['articleDescription'], 'Fahrzeug');
$bHasFahrzeug = str_contains($b['articleDescription'], 'Fahrzeug');
if ($aHasMitarbeiter && !$bHasMitarbeiter) return -1;
if (!$aHasMitarbeiter && $bHasMitarbeiter) return 1;
if ($aHasFahrzeug && !$bHasFahrzeug) return -1;
if (!$aHasFahrzeug && $bHasFahrzeug) return 1;
return 0;
});
$textElements = [];
// parse shippingNote.textElements ({"1":true,"2":true}) to array, fetch each text element and put content into array
$shippingNoteTextElements = json_decode($shippingNote->textElements, true);
@@ -356,6 +373,28 @@ class WarehouseShippingNoteController extends TTCrud {
self::returnJson(array_values($out));
}
protected function changeStatusAction() {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
$json = json_decode(file_get_contents('php://input'), true);
$id = $json['id'];
$status = $json['status'];
if (strlen($id) < 1) {
http_response_code(500);
self::returnJson(['success' => false, 'message' => 'Lieferschein wurde nicht gefunden']);
}
$shippingNote = (array) WarehouseShippingNoteModel::get($id);
if ($shippingNote['status'] === 'accepted' || $shippingNote['status'] === 'invoiced') {
http_response_code(500);
self::returnJson(['success' => false, 'message' => 'Status kann nicht geändert werden']);
}
$shippingNote['status'] = $status;
WarehouseShippingNoteModel::update($shippingNote);
self::returnJson(['success' => true, 'message' => 'Status wurde geändert']);
}
//TODO: either move this to TimerecordingCarController or make it better
protected function timerecordingCarAutoCompleteAction() {
$timerecordingCars = array_map(function ($timerecordingCar) {