Updated WarehouseShippingNote
This commit is contained in:
@@ -36,21 +36,24 @@ class WarehouseHistoryController {
|
||||
|
||||
if (isset($columns[array_search($item['key'], array_column($columns, 'key'))]['modal']['type'])) {
|
||||
|
||||
if($columns[array_search($item['key'], array_column($columns, 'key'))]['modal']['type'] === 'checkbox') {
|
||||
if ($columns[array_search($item['key'], array_column($columns, 'key'))]['modal']['type'] === 'checkbox') {
|
||||
$item['old_value'] = $item['old_value'] === '1' ? 'Ja' : 'Nein';
|
||||
$item['new_value'] = $item['new_value'] === '1' ? 'Ja' : 'Nein';
|
||||
}
|
||||
|
||||
if($columns[array_search($item['key'], array_column($columns, 'key'))]['modal']['type'] === 'select') {
|
||||
if ($columns[array_search($item['key'], array_column($columns, 'key'))]['modal']['type'] === 'select') {
|
||||
$column = $columns[array_search($item['key'], array_column($columns, 'key'))];
|
||||
$item['old_value'] = $column['modal']['items'][array_search($item['old_value'], array_column($column['modal']['items'], 'value'))]['text'];
|
||||
$item['new_value'] = $column['modal']['items'][array_search($item['new_value'], array_column($column['modal']['items'], 'value'))]['text'];
|
||||
|
||||
if (isset($column['modal']['items'][array_search($item['old_value'], array_column($column['modal']['items'], 'value'))]) &&
|
||||
isset($column['modal']['items'][array_search($item['new_value'], array_column($column['modal']['items'], 'value'))])) {
|
||||
$item['old_value'] = $column['modal']['items'][array_search($item['old_value'], array_column($column['modal']['items'], 'value'))]['text'];
|
||||
$item['new_value'] = $column['modal']['items'][array_search($item['new_value'], array_column($column['modal']['items'], 'value'))]['text'];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$item['columnHeader'] = $columns[array_search($item['key'], array_column($columns, 'key'))]['text'];
|
||||
return $item;
|
||||
}, $history);
|
||||
|
||||
@@ -14,7 +14,8 @@ class WarehouseShippingNoteController extends TTCrud {
|
||||
['key' => 'deliveryAddressName', 'text' => 'L.-Adr. Name', 'required' => true],
|
||||
['key' => 'deliveryAddressLine', 'text' => 'L.-Adr.', 'required' => true],
|
||||
['key' => 'deliveryAddressPLZ', 'text' => 'L.-Adr. PLZ', 'required' => true],
|
||||
['key' => 'deliveryAddressCity', 'text' => 'L.-Adr. Ort', 'required' => true],
|
||||
['key' => 'deliveryAddressEMail', 'text' => 'L.-Adr. EMail', 'required' => true, 'table' => false],
|
||||
['key' => 'note', 'text' => 'Notiz', 'required' => true, 'table' => false],
|
||||
['key' => 'status',
|
||||
'text' => 'Status',
|
||||
'required' => true,
|
||||
@@ -63,6 +64,7 @@ class WarehouseShippingNoteController extends TTCrud {
|
||||
self::returnJson(['success' => false, 'message' => 'Status muss "Neu" sein']);
|
||||
die();
|
||||
}
|
||||
|
||||
$postData['positions'] = json_encode($postData['positions']);
|
||||
return true;
|
||||
}
|
||||
@@ -75,6 +77,7 @@ class WarehouseShippingNoteController extends TTCrud {
|
||||
"\r"], " ", $address->getCompanyOrName())) . " (" . $address->zip . " " . $address->city . ", " . $address->street . ")" . (($address->customer_number) ? " [" . $address->customer_number . "]" : "")];
|
||||
return $result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function beforeUpdate($postData): bool {
|
||||
@@ -169,6 +172,40 @@ class WarehouseShippingNoteController extends TTCrud {
|
||||
self::returnJson($textElements);
|
||||
}
|
||||
|
||||
protected function signAction() {
|
||||
$id = $this->request->id;
|
||||
if (strlen($id) < 1) {
|
||||
http_response_code(500);
|
||||
self::returnJson(['success' => false, 'message' => 'Lieferschein wurde nicht gefunden']);
|
||||
}
|
||||
|
||||
$shippingNote = WarehouseShippingNoteModel::get($id);
|
||||
|
||||
if ($shippingNote->signature || $shippingNote->signatureName) {
|
||||
http_response_code(500);
|
||||
self::returnJson(['success' => false, 'message' => 'Lieferschein wurde bereits unterschrieben']);
|
||||
}
|
||||
$post = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
$shippingNote = (array) $shippingNote;
|
||||
$shippingNote['signature'] = $post['signature'];
|
||||
$shippingNote['signatureName'] = $post['signatureName'];
|
||||
|
||||
if (strlen($shippingNote['signature']) < 1 || strlen($shippingNote['signatureName']) < 1) {
|
||||
http_response_code(500);
|
||||
self::returnJson(['success' => false, 'message' => 'Unterschrift oder Name fehlt']);
|
||||
}
|
||||
|
||||
try {
|
||||
$shippingNote['signatureDate'] = date("Y-m-d");
|
||||
WarehouseShippingNoteModel::update($shippingNote);
|
||||
self::returnJson(['success' => true, 'message' => 'Unterschrift wurde gespeichert']);
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
self::returnJson(['success' => false, 'message' => 'Unterschrift konnte nicht gespeichert werden']);
|
||||
}
|
||||
}
|
||||
|
||||
protected function createPDFAction() {
|
||||
$id = $this->request->id;
|
||||
if (strlen($id) < 1) {
|
||||
@@ -194,9 +231,38 @@ class WarehouseShippingNoteController extends TTCrud {
|
||||
$position['articleDescription'] = $articlePacket->description === $articlePacket->title ? "" : $articlePacket->description;
|
||||
$position['articleUnit'] = 'Stk.';
|
||||
$positions[] = $position;
|
||||
} elseif (isset($position['articleText'])) {
|
||||
$position['articleTitle'] = $position['articleText'];
|
||||
$position['articleDescription'] = "";
|
||||
$position['articleUnit'] = 'Stk.';
|
||||
$positions[] = $position;
|
||||
}
|
||||
}
|
||||
|
||||
// json decode hoursEntries and add to positions
|
||||
$hoursEntries = json_decode($shippingNote->hoursEntries, true);
|
||||
foreach ($hoursEntries as $hoursEntry) {
|
||||
$positions[] = [
|
||||
'articleTitle' => "Arbeitsstunden",
|
||||
'articleDescription' => $hoursEntry['note'],
|
||||
'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,
|
||||
'articleUnit' => 'Km',
|
||||
'amount' => $hoursEntry['kilometerCount'],
|
||||
'price' => 1 * $hoursEntry['kilometerCount'] ?? 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);
|
||||
@@ -259,4 +325,148 @@ class WarehouseShippingNoteController extends TTCrud {
|
||||
header('Content-Disposition: inline; filename="' . $filename . '"');
|
||||
readfile($filename);
|
||||
}
|
||||
|
||||
// TODO: either move this to UserController or make it better
|
||||
protected function userAutoCompleteAction() {
|
||||
$users = array_map(function($user) {
|
||||
return ['value' => $user->id, 'text' => $user->name];
|
||||
}, UserModel::search(['employee' => true]));
|
||||
|
||||
$out = null;
|
||||
$searchedID = $this->request->searchedID;
|
||||
if (strlen($searchedID) > 0) {
|
||||
// find user with value searchedID
|
||||
$out = array_filter($users, function($user) use ($searchedID) {
|
||||
return $user['value'] == $searchedID;
|
||||
});
|
||||
} else {
|
||||
$out = array_filter($users, function($user) {
|
||||
;
|
||||
return strpos(strtolower($user['text']), strtolower($this->request->q)) !== false;
|
||||
});
|
||||
|
||||
$out = array_slice($out, 0, 10);
|
||||
}
|
||||
|
||||
self::returnJson(array_values($out));
|
||||
}
|
||||
|
||||
//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];
|
||||
}, 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) {
|
||||
return $timerecordingCar['value'] == $searchedID;
|
||||
});
|
||||
} else {
|
||||
$out = array_filter($timerecordingCars, function($timerecordingCar) {
|
||||
return strpos(strtolower($timerecordingCar['text']), strtolower($this->request->q)) !== false;
|
||||
});
|
||||
|
||||
$out = array_slice($out, 0, 10);
|
||||
}
|
||||
|
||||
self::returnJson(array_values($out));
|
||||
}
|
||||
|
||||
protected function timerecordingCarForUserAction() {
|
||||
$timerecordingCars = TimerecordingCarModel::getAll();
|
||||
$out = null;
|
||||
foreach ($timerecordingCars as $timerecordingCar) {
|
||||
if ($timerecordingCar->user_id == $this->user->id) {
|
||||
header('Content-Type: application/json');
|
||||
die(json_encode(['success' => true, 'id' => $timerecordingCar->id]));
|
||||
}
|
||||
}
|
||||
die(json_encode(['success' => true, 'id' => 2]));
|
||||
}
|
||||
|
||||
|
||||
//TODO: export this to an api class for openstreetmap
|
||||
protected function getDistanceAction() {
|
||||
// $filename = TEMP_DIR . "/DeviceMonitoring/interfacesWithCongestion.json";
|
||||
// use dir TEMP_DIR /OpenStreetMap/from-to.json to cache the results
|
||||
|
||||
$filename = TEMP_DIR . "/OpenStreetMap/" . urlencode($this->request->from) . "-" . urlencode($this->request->to) . ".json";
|
||||
|
||||
if (file_exists($filename)) {
|
||||
$data = file_get_contents($filename);
|
||||
self::returnJson(json_decode($data, true));
|
||||
}
|
||||
|
||||
|
||||
$from = $this->request->from;
|
||||
$to = $this->request->to;
|
||||
$from = urlencode($from);
|
||||
$to = urlencode($to);
|
||||
|
||||
function geocode($address) {
|
||||
if ($address === 'Xinon GmbH') {
|
||||
return [['lat' => 46.99555015, 'lon' => 15.77507876755547]];
|
||||
}
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => "https://nominatim.openstreetmap.org/search?q=$address&format=json",
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => "GET",
|
||||
CURLOPT_HTTPHEADER => [
|
||||
"accept: application/json",
|
||||
"accept-language: de-AT,de;q=0.9,en;q=0.8",
|
||||
"origin: https://routing.openstreetmap.de",
|
||||
"referer: https://routing.openstreetmap.de/",
|
||||
"user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36"
|
||||
],
|
||||
]);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
|
||||
if ($err) {
|
||||
die(json_encode(['success' => false, 'message' => 'Error while geocoding']));
|
||||
}
|
||||
|
||||
curl_close($curl);
|
||||
return json_decode($response, true);
|
||||
}
|
||||
|
||||
function route($from, $to) {
|
||||
$fromData = geocode($from);
|
||||
$toData = geocode($to);
|
||||
$fromLat = $fromData[0]['lat'];
|
||||
$fromLon = $fromData[0]['lon'];
|
||||
$toLat = $toData[0]['lat'];
|
||||
$toLon = $toData[0]['lon'];
|
||||
$url = "https://router.project-osrm.org/route/v1/driving/$fromLon,$fromLat;$toLon,$toLat?overview=false";
|
||||
$data = json_decode(file_get_contents($url), true);
|
||||
$distance = $data['routes'][0]['distance'];
|
||||
return $distance;
|
||||
}
|
||||
|
||||
$fromData = geocode($from);
|
||||
$toData = geocode($to);
|
||||
|
||||
$distance = route($from, $to);
|
||||
|
||||
$roundedDistanceKm = round($distance / 1000, 0);
|
||||
|
||||
if (!file_exists(dirname($filename))) {
|
||||
mkdir(dirname($filename), 0777, true);
|
||||
}
|
||||
file_put_contents($filename, json_encode(['success' => true, 'distance' => $roundedDistanceKm]));
|
||||
|
||||
self::returnJson(['success' => true, 'distance' => $roundedDistanceKm]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,9 +7,15 @@ class WarehouseShippingNoteModel extends TTCrudBaseModel {
|
||||
public string $deliveryAddressLine;
|
||||
public string $deliveryAddressPLZ;
|
||||
public string $deliveryAddressCity;
|
||||
public string $deliveryAddressEMail;
|
||||
public string $note;
|
||||
public string $status; // 'new'|'accepted'|'invoiced'
|
||||
public string $positions;
|
||||
public string $textElements;
|
||||
public string $hoursEntries;
|
||||
public ?string $signature;
|
||||
public ?string $signatureName;
|
||||
public ?string $signatureDate;
|
||||
public ?int $eShopOrderId;
|
||||
public int $create;
|
||||
public int $createBy;
|
||||
|
||||
Reference in New Issue
Block a user