query($query); $locations = []; if ($result) { while ($row = $result->fetch_assoc()) { $locations[$row['location']][] = [ 'code' => $row['code'], 'capacity' => intval($row['full_capacity']), 'warehouse_id' => intval($row['warehouse_id']) ]; } } function commonPrefix($str1, $str2) { $len = min(strlen($str1), strlen($str2)); for ($i = 0; $i < $len; $i++) { if ($str1[$i] !== $str2[$i]) { return substr($str1, 0, $i); } } return substr($str1, 0, $len); } $commonPrefixes = []; foreach ($locations as $location => $codes) { $firstCode = array_shift($codes); $prefix = $firstCode['code']; $totalCapacity = $firstCode['capacity']; $totalAmount = 0; // Első raktár tartalmának lekérése $amountQuery = "SELECT SUM(amount) as total_amount FROM warehouse WHERE warehouse_id = " . $firstCode['warehouse_id']; $amountResult = $conn->query($amountQuery); if ($amountResult) { $amountRow = $amountResult->fetch_assoc(); $totalAmount += intval($amountRow['total_amount']); } foreach ($codes as $codeData) { $prefix = commonPrefix($prefix, $codeData['code']); $totalCapacity += $codeData['capacity']; // Többi raktár tartalmának lekérése $amountQuery = "SELECT SUM(amount) as total_amount FROM warehouse WHERE warehouse_id = " . $codeData['warehouse_id']; $amountResult = $conn->query($amountQuery); if ($amountResult) { $amountRow = $amountResult->fetch_assoc(); $totalAmount += intval($amountRow['total_amount']); } if ($prefix === "") break; } $commonPrefixes[$location] = [ 'prefix' => $prefix, 'capacity' => $totalCapacity, 'amount' => $totalAmount ]; } $responseStrLoc = ''; $responseStrCode = ''; $responseStrCapacity = ''; $responseStrAmount = ''; foreach ($commonPrefixes as $location => $data) { if ($responseStrLoc != "") { $responseStrLoc .= "|%|"; $responseStrCode .= "|%|"; $responseStrCapacity .= "|%|"; $responseStrAmount .= "|%|"; } $responseStrLoc .= $location; $responseStrCode .= $data['prefix']; $responseStrCapacity .= $data['capacity']; $responseStrAmount .= $data['amount']; } echo '{"result": "ok", "loc": "'.$responseStrLoc.'", "code": "'.$responseStrCode.'", "capacity": "'.$responseStrCapacity.'", "amount": "'.$responseStrAmount.'"}'; } else if (htmlspecialchars($_POST["func"]) == "OpenLoc") { $location = htmlspecialchars($_POST["location"]); $responseStr = ''; $query = "SELECT name, warehouse_id, status, code FROM warehouse_structure WHERE location = '$location' ORDER BY CAST(SUBSTRING_INDEX(name, '.', 1) AS UNSIGNED) ASC"; if ($result = $conn->query($query)) { while ($warehouse = $result->fetch_assoc()) { if ($responseStr != "") { $responseStr = $responseStr."|%|"; } $responseStr = $responseStr.$warehouse["name"]."|".$warehouse["warehouse_id"]."|".$warehouse["status"]."|".$warehouse["code"]; } } echo '{"result": "ok", "data": "'.$responseStr.'"}'; } else if (htmlspecialchars($_POST["func"]) == "OpenWarehouse") { $warehouse_id = htmlspecialchars($_POST["id"]); $sql = mysqli_query($conn,"SELECT * FROM warehouse_structure WHERE warehouse_id = '$warehouse_id'"); $warehouse_structure = mysqli_fetch_array($sql); $SizeJSON = json_decode(base64_decode($warehouse_structure["size"]), true); $size = $SizeJSON['globalSize']; $capacity = $SizeJSON['globalCapacity']; $inwarehouse = ''; $query = "SELECT item_id, position, amount FROM warehouse WHERE warehouse_id = '$warehouse_id' and amount != 0 ORDER BY item_id ASC"; if ($result = $conn->query($query)) { while ($warehouse = $result->fetch_assoc()) { if ($inwarehouse != "") { $inwarehouse = $inwarehouse."|%|"; } $item_id = $warehouse["item_id"]; $item_name = ""; $inwarehouse = $inwarehouse.$item_id."|".$warehouse["position"]."|".$warehouse["amount"]."|".$item_name; } } if ($warehouse_structure != null) { $json = json_encode([ "result" => "ok", "name" => $warehouse_structure["name"], "location" => $warehouse_structure["location"], "code" => $warehouse_structure["code"], "row" => $warehouse_structure["row"], "columns" => $warehouse_structure["columns"], "fullcapacity" => $warehouse_structure["full_capacity"], "status" => $warehouse_structure["status"], "inwarehouse" => $inwarehouse, "canedit" => UserHasPerm('warehouse_editor'), "canstatistic" => UserHasPerm('warehouse_statistic'), "size" => $warehouse_structure["size"] ]); } else { $json = json_encode(["result" => "Nem létezik raktár ezzel az azonosítóval! Próbálja újra."]); } echo $json; } else if (htmlspecialchars($_POST["func"]) == "OpenCell") { $warehouse_id = htmlspecialchars($_POST["warehouse_id"]); $column = htmlspecialchars($_POST["column"]); $row = htmlspecialchars($_POST["row"]); $sql = mysqli_query($conn,"SELECT size FROM warehouse_structure WHERE warehouse_id = '$warehouse_id'"); $warehouse_structure = mysqli_fetch_array($sql); $sizeJSON = json_decode(base64_decode($warehouse_structure["size"]), true); $size = $sizeJSON['globalSize']; if (isset($sizeJSON['customSizes'][$column.':'.$row])) { $size = $sizeJSON['customSizes'][$column.':'.$row]; } $capacity = $sizeJSON['globalCapacity']; if (isset($sizeJSON['customCapacity'][$column.':'.$row])) { $capacity = $sizeJSON['customCapacity'][$column.':'.$row]; } $inwarehouse = ''; $position = ($row + 1).':'.($column + 1); $query = "SELECT item_id, amount FROM warehouse WHERE warehouse_id = '$warehouse_id' and position = '$position' and amount != 0 ORDER BY amount ASC"; if ($result = $conn->query($query)) { while ($warehouse = $result->fetch_assoc()) { $inwarehouse = $inwarehouse.'
  • '.$warehouse['item_id'].' - '.$warehouse['amount'].' db
  • '; } } if ($inwarehouse == "") { $inwarehouse = "
  • Üres
  • "; } if ($warehouse_structure != null) { $json = json_encode([ "result" => "ok", "capacity" => $capacity, "size" => $size, "content" => $inwarehouse, "box_stock_taking" => UserHasPerm("box_stock_taking") ]); } else { $json = json_encode(["result" => "Nem létezik raktár ezzel az azonosítóval! Próbálja újra."]); } echo $json; } else if (htmlspecialchars($_POST["func"]) == "SaveNewWarehouse") { $name = htmlspecialchars($_POST["name"]); $loc = htmlspecialchars($_POST["location"]); $code = htmlspecialchars($_POST["code"]); $row = $_POST["row"]; $columns = $_POST["columns"]; $capacity = $_POST["capacity"]; $sql = mysqli_query($conn,"SELECT warehouse_id FROM warehouse_structure WHERE name = '$name' and location = '$loc'"); $warehouse_structure = mysqli_fetch_array($sql); if (!UserHasPerm('warehouse_editor')) { $json = json_encode(["result" => "Önnek nincsen joga új raktárat létrehozni!"]); } else if ($warehouse_structure != null) { $json = json_encode(["result" => "Ezen a raktárhelyen létezik ilyen nevű raktár!"]); } else if ($name == "" || $loc == "" || $code == "" || $row == "" || $columns == "" || $capacity == "") { $json = json_encode(["result" => "Az összes paraméter megadása kötelező!"]); } else if (!(ctype_digit($row) && ctype_digit($columns) && ctype_digit($capacity))) { $json = json_encode(["result" => "Egyes paraméterek nem felelnek meg a formai követelményeknek!"]); } else { $size = base64_encode('{"globalSize": "Univerzális", "customSizes": {}, "globalCapacity": "'.$capacity.'", "customCapacity":{}}'); $sql = mysqli_query($conn,"INSERT INTO warehouse_structure (`name`, `location`, `code`, `row`, `columns`, `size`, `capacity`) VALUES ('$name', '$loc', '$code', '$row', '$columns', '$size', '$capacity')"); $sql = mysqli_query($conn,"SELECT warehouse_id FROM warehouse_structure WHERE name = '$name' and location = '$loc'"); $warehouse_structure = mysqli_fetch_array($sql); $json = json_encode(["result" => "ok", "wid" => $warehouse_structure["warehouse_id"]]); } echo $json; } else if (htmlspecialchars($_POST["func"]) == "EditWarehouse") { $warehouse_id = htmlspecialchars($_POST["warehouse_id"]); $sql = mysqli_query($conn,"SELECT * FROM warehouse_structure WHERE warehouse_id = '$warehouse_id'"); $warehouse_structure = mysqli_fetch_array($sql); if ($warehouse_structure == null) { $json = json_encode(["result" => "Nem létező raktár azonosító lett megadva! Próbálja újra."]); } else if (!UserHasPerm('warehouse_editor')) { $json = json_encode(["result" => "Önnek nincsen joga raktárat módosítani!"]); } else { $sql = mysqli_query($conn,"SELECT count(amount) FROM warehouse WHERE warehouse_id = '$warehouse_id' and amount != 0"); $isempty = mysqli_fetch_array($sql)[0]; $canedit = false; if ($isempty == 0) { $canedit = true; } $canedit = true; // --> Átmenetileg bekapcsolva $json = json_encode([ "result" => "ok", "name" => $warehouse_structure["name"], "location" => $warehouse_structure["location"], "code" => $warehouse_structure["code"], "row" => $warehouse_structure["row"], "columns" => $warehouse_structure["columns"], "size" => $warehouse_structure["size"], "capacity" => $warehouse_structure["capacity"], "status" => $warehouse_structure["status"], "multiitem_row" => $warehouse_structure["multiitem_row"], "canedit" => $canedit, ]); } echo $json; } else if (htmlspecialchars($_POST["func"]) == "SaveWarehouse") { $name = htmlspecialchars($_POST["name"]); $loc = htmlspecialchars($_POST["location"]); $code = htmlspecialchars($_POST["code"]); $row = $_POST["row"]; $columns = $_POST["columns"]; $capacity = $_POST["capacity"]; $status = $_POST["status"]; $multiitem_row = $_POST["multiitem_row"]; $size = htmlspecialchars($_POST["size"]); $warehouse_id = htmlspecialchars($_POST["warehouse_id"]); $SizeJSON = json_decode(base64_decode($size), true); $capacity = $SizeJSON['globalCapacity']; $cellcount = intval($row) * intval($columns); $fullcapacity = 0; foreach ($SizeJSON['customCapacity'] as $key => $cap) { $cellcount--; $fullcapacity += intval($cap); } $fullcapacity += $cellcount * intval($capacity); if (!UserHasPerm('warehouse_editor')) { $json = json_encode(["result" => "Önnek nincsen joga új raktárat módosítani!"]); } else if ($name == "" || $loc == "" || $code == "" || $row == "" || $columns == "" || $capacity == "") { $json = json_encode(["result" => "Az összes paraméter megadása kötelező!"]); } else { $sql = mysqli_query($conn,"UPDATE warehouse_structure SET `name`='$name',`location`='$loc',`code`='$code',`row`='$row',`columns`='$columns',`size`='$size',`capacity`='$capacity',`status`='$status',`full_capacity`=$fullcapacity,`multiitem_row`=$multiitem_row WHERE warehouse_id = '$warehouse_id'"); $json = json_encode(["result" => "ok"]); } echo $json; } else if (htmlspecialchars($_POST["func"]) == "search") { $maxperpage = intval(htmlspecialchars($_POST["perpage"])); $cpage = intval(htmlspecialchars($_POST["cpage"])); $orderby = htmlspecialchars($_POST["orderby"]); $item_id = htmlspecialchars(str_replace(' ', '+', $_POST['item_id'])); $location = htmlspecialchars($_POST["location"]); $addquery = ""; $isfirst = true; if ($cpage == 0) { $cpage = 1; } setcookie("maxperpage", $maxperpage, time() + (86400 * 90), "/"); if ($item_id != "") { $addquery = $addquery." WHERE item_id LIKE '%".$item_id."%'"; $isfirst = false; } $WarehouseData = array(); $finded_place = false; if ($location != "") { $locationquery = 'warehouse_id IN ('; $query = "SELECT warehouse_id, name, location FROM warehouse_structure WHERE code LIKE '%$location%'"; if ($result = $conn->query($query)) { while ($warehouse = $result->fetch_assoc()) { $finded_place = true; $locationquery = $locationquery."'".$warehouse["warehouse_id"]."',"; $WarehouseData[$warehouse["warehouse_id"]] = [ "name" => $warehouse["name"], "location" =>$warehouse["location"] ]; } } $locationquery = substr($locationquery, 0, -1).')'; if ($finded_place) { if ($isfirst) { $addquery = $addquery." WHERE ".$locationquery; $isfirst = false; } else { $addquery = $addquery." AND ".$locationquery; } } } if ($location == "" || !$finded_place) { $query = "SELECT warehouse_id, name, location FROM warehouse_structure"; if ($result = $conn->query($query)) { while ($warehouse = $result->fetch_assoc()) { $WarehouseData[$warehouse["warehouse_id"]] = [ "name" => $warehouse["name"], "location" =>$warehouse["location"] ]; } } } if ($isfirst) { $addquery = $addquery." WHERE amount != 0"; $isfirst = false; } else { $addquery = $addquery." AND amount != 0"; } // Raktár darabszám $countQuery = "SELECT COUNT(*) as total FROM ( SELECT item_id, warehouse_id FROM warehouse".$addquery." GROUP BY item_id, warehouse_id ) as grouped_results"; $sql = mysqli_query($conn, $countQuery); $warehouse_count = mysqli_fetch_array($sql)['total']; // Fóliás darabszám $foil_count = 0; $foil_count_query = "SELECT COUNT(*) as total FROM warehouse_foil WHERE is_active = 1"; if ($item_id != "") { $foil_count_query .= " AND item_id LIKE '%".$item_id."%'"; } if ($location != "") { $foil_count_query .= " AND place LIKE '%".$location."%'"; } $foil_sql = mysqli_query($conn, $foil_count_query); $foil_count = mysqli_fetch_array($foil_sql)['total']; $total_count = $warehouse_count + $foil_count; $maxpage = ceil($total_count / $maxperpage); if (!($cpage >= 1 && $cpage <= $maxpage)) { $cpage = 1; } $responseArr = array(); // Raktár adatok lekérdezése $offset = ($cpage - 1) * $maxperpage; $query = "SELECT item_id, warehouse_id, SUM(amount) as total_amount FROM warehouse".$addquery." GROUP BY item_id, warehouse_id LIMIT $offset, $maxperpage"; if ($result = $conn->query($query)) { while ($warehouse_result = $result->fetch_assoc()) { $responseArr[] = [ "item_id" => $warehouse_result['item_id'], "amount" => $warehouse_result['total_amount'], "location" => $WarehouseData[$warehouse_result['warehouse_id']]['location'], "name" => $WarehouseData[$warehouse_result['warehouse_id']]['name'], "warehouse_id" => $warehouse_result['warehouse_id'], "type" => "warehouse" ]; } } // Ha szükséges fóliás adatok lekérdezése if (count($responseArr) < $maxperpage) { $remaining = $maxperpage - count($responseArr); $foil_offset = max(0, $offset - $warehouse_count); if ($offset < $warehouse_count + $foil_count) { $foil_query = "SELECT wid, item_id, place, right_db, left_db FROM warehouse_foil WHERE is_active = 1"; if ($item_id != "") { $foil_query .= " AND item_id LIKE '%".$item_id."%'"; } if ($location != "") { $foil_query .= " AND place LIKE '%".$location."%'"; } $foil_query .= " LIMIT $foil_offset, $remaining"; if ($result = $conn->query($foil_query)) { while ($foil_result = $result->fetch_assoc()) { $min_amount = min(intval($foil_result['left_db']), intval($foil_result['right_db'])); $responseArr[] = [ "item_id" => $foil_result['item_id'], "amount" => $min_amount, "location" => "Fóliás raktár", "name" => $foil_result['place'], "warehouse_id" => "foil", "type" => "foil" ]; } } } } $reverse = false; if (!empty($orderby) && $orderby[0] === '!') { $reverse = true; $orderby = substr($orderby, 1); } if ($orderby == "amount") { usort($responseArr, function($a, $b) use ($orderby, $reverse) { $result = $a[$orderby] <=> $b[$orderby]; return $reverse ? -$result : $result; }); } else { usort($responseArr, function($a, $b) use ($orderby, $reverse) { $result = strcmp($a[$orderby], $b[$orderby]); return $reverse ? -$result : $result; }); } $responseStr = ""; for ($i=0; $i < count($responseArr); $i++) { if ($responseStr != "") { $responseStr .= "|%|"; } $warehouse_id = ($responseArr[$i]['type'] == 'foil') ? 'foil' : $responseArr[$i]['warehouse_id']; $responseStr .= $responseArr[$i]['item_id'].'/!/'.$responseArr[$i]['amount'].'/!/'.$responseArr[$i]['location'].'/!/'.$responseArr[$i]['name'].'/!/'.$warehouse_id; } echo '{"result": "ok", "data": "'.$responseStr.'", "maxpage": "'.$maxpage.'", "cpage": "'.$cpage.'"}'; } else if (htmlspecialchars($_POST["func"]) == "SearchFoilItem") { $item_id = htmlspecialchars(str_replace(' ', '+', $_POST['item_id'])); $sql = mysqli_query($conn, "SELECT foil_product_place, item_id FROM pr_warehouse_parameters WHERE item_id = '$item_id'"); $warehouse_foil_param = mysqli_fetch_array($sql); if ($warehouse_foil_param == null) { echo json_encode(["result" => "A termék nem szerepel a katalógusban!"]); exit(); } else if (preg_replace('/^\s+|\s+$/', '', $warehouse_foil_param['foil_product_place']) == "") { echo json_encode(["result" => "A terméknek nincs fóliás raktárhelye"]); exit(); } $item_id = $warehouse_foil_param['item_id']; $places = array_map('trim', explode(',', $warehouse_foil_param['foil_product_place'])); $deactivate_sql = mysqli_query($conn, "UPDATE warehouse_foil SET is_active = 0 WHERE item_id = '$item_id' AND place NOT IN ('" . implode("','", $places) . "') AND is_active = 1"); $result_arr = []; foreach ($places as $place) { $sql = mysqli_query($conn, "SELECT wid, left_db, right_db FROM warehouse_foil WHERE item_id = '$item_id' AND place = '$place' AND is_active = 1"); $warehouse_foil = mysqli_fetch_array($sql); if ($warehouse_foil == null) { $sql = mysqli_query($conn, "SELECT wid FROM warehouse_foil WHERE is_active = 0 LIMIT 1"); $inactive_foil = mysqli_fetch_array($sql); if ($inactive_foil != null) { $wid = $inactive_foil['wid']; $sql = mysqli_query($conn, "UPDATE warehouse_foil SET left_db = 0, right_db = 0, place = '$place', item_id = '$item_id', is_active = 1 WHERE wid = $wid"); } else { $sql = mysqli_query($conn, "INSERT INTO warehouse_foil(item_id, place, right_db, left_db, is_active) VALUES ('$item_id', '$place', 0, 0, 1)"); $wid = mysqli_insert_id($conn); } $left_db = 0; $right_db = 0; } else { $wid = $warehouse_foil['wid']; $left_db = $warehouse_foil['left_db']; $right_db = $warehouse_foil['right_db']; } $result_arr[] = [ 'wid' => $wid, 'place' => $place, 'left_db' => $left_db, 'right_db' => $right_db ]; } echo json_encode(["result" => "ok", "data" => $result_arr, "warehouse_editor" => UserHasPerm('warehouse_editor')]); } else if (htmlspecialchars($_POST["func"]) == "EditFoilItem") { $left_db = intval($_POST["left"]); $right_db = intval($_POST["right"]); $reason = htmlspecialchars($_POST["reason"] ?? ''); $result = array(); $wid_list = []; if (isset($_POST["wid"])) { $wid = htmlspecialchars($_POST["wid"]); $wid_list = explode('/', $wid); } else { $item_id = htmlspecialchars(str_replace(' ', '+', $_POST['item_id'])); $set_item_id = splitSetitem_id($item_id); if ($set_item_id != null) { $item1 = $set_item_id['item1']; $item2 = $set_item_id['item2']; $sql = mysqli_query($conn, "SELECT wid FROM warehouse_foil WHERE item_id = '$item1' LIMIT 1 AND is_active = 1"); $wid_list[] = mysqli_fetch_array($sql)[0]; $sql = mysqli_query($conn, "SELECT wid FROM warehouse_foil WHERE item_id = '$item2' LIMIT 1 AND is_active = 1"); $wid_list[] = mysqli_fetch_array($sql)[0]; } else { $sql = mysqli_query($conn, "SELECT wid FROM warehouse_foil WHERE item_id = '$item_id' LIMIT 1 AND is_active = 1"); $wid_list[] = mysqli_fetch_array($sql)[0]; } } for ($i=0; $i < count($wid_list); $i++) { $TempWID = $wid_list[$i]; $sql = mysqli_query($conn,"SELECT * FROM warehouse_foil WHERE wid = '$TempWID' AND is_active = 1"); $warehouse_sql_foil = mysqli_fetch_array($sql); $inWarehouse = max($warehouse_sql_foil['left_db'], $warehouse_sql_foil['right_db']); if ($warehouse_sql_foil == null) { echo json_encode(['result'=>'error','reset'=>'true','message'=>'Érvénytelen raktár azonosító'], JSON_UNESCAPED_UNICODE); exit; } else { $sql = mysqli_query($conn,"UPDATE warehouse_foil SET left_db = CASE WHEN left_db + $left_db < 0 THEN 0 ELSE left_db + $left_db END, right_db = CASE WHEN right_db + $right_db < 0 THEN 0 ELSE right_db + $right_db END WHERE wid = '$TempWID'"); $loggerclass->writeLogWarehouse(['reason' => 'Fóliás mennyiség szerkesztése', 'reason_code' => 1, 'item_id' => $warehouse_sql_foil['item_id'], 'from_place' => $reason, 'to_place' => $warehouse_sql_foil['place'], 'amount_left' => $left_db, 'amount_right' => $right_db ]); } } $TempWID = $wid_list[0]; $sql = mysqli_query($conn, "SELECT item_id FROM warehouse_foil WHERE wid = '$TempWID'"); $warehouse_foil = mysqli_fetch_array($sql); $result['result'] = "ok"; $result['item_id'] = $warehouse_foil["item_id"]; if ($reason != null && $reason != "" ) { $reasonData = explode("#", $reason); if ($reasonData[0] == "Production") { $validCategories = [ 'classic' => 'production_classic', 'injmold' => 'production_injmold', 'sporty' => 'production_sporty', 'boxing' => 'production_boxing' ]; if (!array_key_exists($reasonData[1], $validCategories)) { $result['result'] = "A termék elhelyezve a raktárban, de az indoklás nem került elmentésre!"; } else { $table = $validCategories[$reasonData[1]]; $pr_id = htmlspecialchars($reasonData[2]); $sql = mysqli_query($conn, "SELECT db_revenue_bulk_r, db_revenue_bulk_l FROM $table WHERE pr_id = $pr_id"); $db_revenue = mysqli_fetch_array($sql); if ($db_revenue != null) { $new_db_revenue_bulk_r = intval($right_db) + intval($db_revenue['db_revenue_bulk_r']); $new_db_revenue_bulk_l = intval($left_db) + intval($db_revenue['db_revenue_bulk_l']); $sql = mysqli_query($conn, "UPDATE $table SET db_revenue_bulk_r = $new_db_revenue_bulk_r, db_revenue_bulk_l = $new_db_revenue_bulk_l WHERE pr_id = $pr_id"); } } } } echo json_encode($result); } else if (htmlspecialchars($_POST["func"]) == "statistics") { $sql = " SELECT CASE WHEN SUBSTRING_INDEX(item_id, '+', 1) REGEXP '^[0-9]+$' THEN 'classic' WHEN SUBSTRING_INDEX(item_id, '+', 1) REGEXP '^CL[P|M]?[0-9]+$' THEN 'climair' WHEN SUBSTRING_INDEX(item_id, '+', 1) REGEXP '^FR[0-9]{4}$' THEN 'injmold' WHEN SUBSTRING_INDEX(item_id, '+', 1) REGEXP '^F[0-9]{4}$' THEN 'sporty' ELSE 'unknown' END AS category, SUM(CASE WHEN item_id LIKE '%+%' THEN amount * 2 ELSE amount END) AS amount FROM warehouse GROUP BY category UNION ALL SELECT 'all' AS category, SUM(CASE WHEN item_id LIKE '%+%' THEN amount * 2 ELSE amount END) AS amount FROM warehouse; "; $db_box = $conn->query($sql); $box_arr = []; if ($db_box) { while ($row = $db_box->fetch_assoc()) { $box_arr[$row["category"]] = [ "category" => $row["category"], "amount" => $row["amount"] ]; } } $sql = " SELECT CASE WHEN item_id REGEXP '^[0-9]+$' THEN 'classic' WHEN item_id REGEXP '^FR[0-9]{4}$' THEN 'injmold' WHEN item_id REGEXP '^F[0-9]{4}$' THEN 'sporty' ELSE 'unknown' END AS category, SUM(right_db) AS right_db, SUM(left_db) AS left_db FROM warehouse_foil WHERE is_active = 1 GROUP BY category UNION ALL SELECT 'all' AS category, SUM(right_db) AS right_db, SUM(left_db) AS left_db FROM warehouse_foil WHERE is_active = 1; "; $db_foil = $conn->query($sql); $foil_arr = []; if ($db_foil) { while ($row = $db_foil->fetch_assoc()) { $foil_arr[$row["category"]] = [ "category" => $row["category"], "right_db" => $row["right_db"], "left_db" => $row["left_db"] ]; } } $all_arr['classic'] = [ 'amount' => ($box_arr['classic']['amount'] ?? 0) + min($foil_arr['classic']['right_db'] ?? 0, $foil_arr['classic']['left_db'] ?? 0), 'category' => 'classic' ]; $all_arr['climair'] = [ 'amount' => $box_arr['climair']['amount'] ?? 0, 'category' => 'climair' ]; $all_arr['injmold'] = [ 'amount' => ($box_arr['injmold']['amount'] ?? 0) + min($foil_arr['injmold']['right_db'] ?? 0, $foil_arr['injmold']['left_db'] ?? 0), 'category' => 'injmold' ]; $all_arr['sporty'] = [ 'amount' => ($box_arr['sporty']['amount'] ?? 0) + min($foil_arr['sporty']['right_db'] ?? 0, $foil_arr['sporty']['left_db'] ?? 0), 'category' => 'sporty' ]; $shortage = []; $sql = " SELECT CASE WHEN SUBSTRING_INDEX(item_id, '+', 1) REGEXP '^[0-9]+$' THEN 'classic' WHEN SUBSTRING_INDEX(item_id, '+', 1) REGEXP '^CL[P|M]?[0-9]+[A-Z]?$' THEN 'climair' WHEN SUBSTRING_INDEX(item_id, '+', 1) REGEXP '^FR[0-9]{4}$' THEN 'injmold' WHEN SUBSTRING_INDEX(item_id, '+', 1) REGEXP '^F[0-9]{4}$' THEN 'sporty' ELSE 'unknown' END AS category, SUM(CASE WHEN free_stock = 0 THEN 1 ELSE 0 END) AS nullas_db, SUM(CASE WHEN free_stock < 0 THEN 1 ELSE 0 END) AS negatv_db FROM statistics_daily GROUP BY category UNION ALL SELECT 'all' AS category, SUM(CASE WHEN free_stock = 0 THEN 1 ELSE 0 END), SUM(CASE WHEN free_stock < 0 THEN 1 ELSE 0 END) FROM statistics_daily; "; $db_shortage = $conn->query($sql); if ($db_shortage) { while ($row = $db_shortage->fetch_assoc()) { $shortage[$row["category"]] = [ 'zero' => intval($row['nullas_db']), 'neg' => intval($row['negatv_db']), 'category' => $row["category"] ]; } } echo json_encode([ "result" => "ok", "box" => $box_arr, "foil" => $foil_arr, "all" => $all_arr, "shortage" => $shortage, ]); } else if (htmlspecialchars($_POST["func"]) == "EditFoilWarehouse") { $wid = htmlspecialchars($_POST["wid"] ?? ''); $new_place = htmlspecialchars($_POST["new_place"] ?? ''); if ($new_place == "") { echo json_encode(array('result' => 'Kötelező megadni egy raktárhelyet!')); exit(); } $item_id = ""; $old_place = ""; $right_db = 0; $left_db = 0; $sql = mysqli_query($conn,"SELECT item_id, place, right_db, left_db FROM warehouse_foil WHERE wid = '$wid'"); $data = mysqli_fetch_array($sql); if ($data != null) { $item_id = $data['item_id']; $old_place = $data['place']; $right_db = $data['right_db']; $left_db = $data['left_db']; } else { echo json_encode(array('result' => 'Hiibás raktár azonosító!')); exit(); } $foil_product_place = ""; $sql = mysqli_query($conn,"SELECT foil_product_place FROM pr_warehouse_parameters WHERE item_id = '$item_id'"); $data = mysqli_fetch_array($sql); if ($data != null) { $foil_product_place = $data['foil_product_place']; } else { echo json_encode(array('result' => 'Hiibás cikkszám bejegyzés!')); exit(); } $foil_product_place = str_replace($old_place, $new_place, $foil_product_place); mysqli_query($conn,"UPDATE pr_warehouse_parameters SET foil_product_place='$foil_product_place' WHERE item_id = '$item_id'"); mysqli_query($conn,"UPDATE warehouse_foil SET place='$new_place' WHERE wid = '$wid'"); $loggerclass->writeLogWarehouse(['reason' => 'Fóliás raktárhely szerkesztése', 'reason_code' => 2, 'item_id' => $item_id, 'from_place' => $old_place, 'to_place' => $new_place, 'amount_left' => $left_db, 'amount_right' => $right_db ]); echo json_encode(array('result' => 'ok')); } else if (htmlspecialchars($_POST["func"]) == "MoveBox") { $wh_id = htmlspecialchars($_POST["wh_id"] ?? ''); $wh_id_new = htmlspecialchars($_POST["wh_id_new"] ?? ''); $amount = intval($_POST["amount"] ?? 0); $item_id = htmlspecialchars(str_replace(' ', '+', $_POST['item_id'])); /* -- Jog Ellenőrzés -- */ if (!UserHasPerm("box_stock_taking")) { echo json_encode(array( 'result' => 'Önnek nincsen joga a művelethez!' )); exit(); } /* -- Cikkszám ellenőrzés -- */ $sql = mysqli_query($conn,"SELECT item_id FROM pr_parameters WHERE item_id = '$item_id'"); $result = mysqli_fetch_array($sql); if ($result != null) { $item_id = $result['item_id']; } else { echo json_encode(array( 'result' => 'Nem létező cikkszámot adott meg!' )); exit(); } /* -- Raktárhely feldolgozás -- */ /* Eredeti raktárhely */ $warehouse_id_old = null; $position_old = null; $position = substr($wh_id, -3); $wcode = substr($wh_id, 0, strlen($wh_id) - 3); $letter = $position[0]; $numberFromLetter = ord(strtoupper($letter)) - ord('A') + 1; $number = ltrim(substr($position, 1, 2), '0'); $position = $numberFromLetter . ':' . $number; $position_old = $position; $sql = mysqli_query($conn,"SELECT warehouse_id FROM warehouse_structure WHERE code = '$wcode'"); $warehouse_structure = mysqli_fetch_array($sql); if ($warehouse_structure != null) { $warehouse_id = $warehouse_structure['warehouse_id']; $warehouse_id_old = $warehouse_id; $sql = mysqli_query($conn,"SELECT wid, amount FROM warehouse WHERE warehouse_id = '$warehouse_id' and item_id = '$item_id' and position = '$position'"); $warehouse_box = mysqli_fetch_array($sql); if ($warehouse_box == null) { echo json_encode(array( 'result' => 'A cikkszám nem található meg ezen a raktárazonosítón!' )); exit(); } else if ($warehouse_box['amount'] < $amount) { echo json_encode(array( 'result' => 'Nincs elegendő cikkszám a forrás polcon!' )); exit(); } } else { echo json_encode(array( 'result' => 'Nem létező raktár azonosítót adott meg forrásnak!' )); exit(); } /* Új raktárhely */ $warehouse_id_new = null; $position_new = null; $position = substr($wh_id_new, -3); $wcode = substr($wh_id_new, 0, strlen($wh_id_new) - 3); $letter = $position[0]; $numberFromLetter = ord(strtoupper($letter)) - ord('A') + 1; $number = ltrim(substr($position, 1, 2), '0'); $position_new = $numberFromLetter . ':' . $number; $sql = mysqli_query($conn,"SELECT warehouse_id FROM warehouse_structure WHERE code = '$wcode'"); $warehouse_structure = mysqli_fetch_array($sql); if ($warehouse_structure != null) { $warehouse_id_new = $warehouse_structure['warehouse_id']; } else { echo json_encode(array( 'result' => 'Nem létező raktár azonosítót adott meg célhelynek!' )); exit(); } /* -- Return -- */ echo json_encode(array( 'result' => 'ok', 'position_old' => $position_old, 'wid_old' => $warehouse_id_old, 'position_new' => $position_new, 'wid_new' => $warehouse_id_new, 'code_old' => $wh_id, 'item_id' => $item_id, 'amount' => $amount )); $loggerclass->writeLogWarehouse(['reason' => 'Doboz áthelyezése', 'reason_code' => 1, 'item_id' => $item_id, 'from_place' => $position_old, 'to_place' => $position_new, 'amount_left' => $amount, 'amount_right' => $amount ]); } exit(); } else if (isset($_GET['boxsize']) && $_GET['boxsize'] == '1') { $jsonString = file_get_contents('../managers/prdb.json'); $data = json_decode($jsonString, true); header('Content-Type: application/json; charset=utf-8'); echo json_encode($data['BoxSizes']); exit(); } $WarehouseLocSelect = ''; $query = "SELECT DISTINCT location FROM warehouse_structure ORDER BY location ASC"; if ($result = $conn->query($query)) { while ($warehouse = $result->fetch_assoc()) { $WarehouseLocSelect = $WarehouseLocSelect.''; } } if (!isset($_COOKIE['maxperpage'])) { setcookie("maxperpage", "25", time() + (86400 * 90), "/"); $maxperpage = "25"; } else { $maxperpage = $_COOKIE['maxperpage']; } setcookie("maxperpage", strval($maxperpage), time() + (86400 * 90), "/"); $perpageselect = " "; $perpageselect = str_replace("value='".$maxperpage."'", "value='".$maxperpage."' selected", $perpageselect); ?> Kezelőfelület

    Title

    Raktárak

    move-by-trolley'; } ?> marketing label-printer



    Raktár kereső

    Cikkszám:

    Raktárhely:

    Oldalanként:

    :


    Cikkszám Mennyiség Raktárhely Szektor Link

    <    0 / 0    >

    Raktártartalom

    Cikkszám Mennyiség Helye (Sor:Oszlop)