5 db / oszlop
";
$perpageselect = str_replace("value='".$maxperpage."'", "value='".$maxperpage."' selected", $perpageselect);
$json = json_encode(array(
'perpage' => $perpageselect,
'result' => 'ok'
));
echo $json;
} else if (htmlspecialchars($_POST["func"]) == "table") {
$maxperpage = intval(htmlspecialchars($_POST['perpage'] ?? 25));
$cpage = intval(htmlspecialchars($_POST['cpage'] ?? 1));
$item_id = htmlspecialchars(str_replace(' ', '+', $_POST['item_id']) ?? '');
$category = htmlspecialchars($_POST['category'] ?? '');
if ($maxperpage < 1) $maxperpage = 25;
if ($cpage < 1) $cpage = 1;
setcookie("maxperpage", $maxperpage, time() + 86400*90, "/");
$maxperpage = $maxperpage / 5;
$offset = max(0, ($cpage - 1) * $maxperpage);
$item_filter = '';
if (!empty($item_id)) {
$item_filter = " AND item_id LIKE '%" . mysqli_real_escape_string($conn, $item_id) . "%'";
}
$tables = ['boxing'];
$results_by_stage = [];
$all_items = [];
for ($stage = 1; $stage <= 2; $stage++) {
$stage_results = [];
$union_parts = [];
foreach ($tables as $t) {
$union_parts[] = "(SELECT pr_id, item_id, stage, date_start, db_start, '$t' AS category
FROM production_{$t}
WHERE stage=$stage $item_filter)";
}
$sql = "SELECT * FROM (" . implode(" UNION ALL ", $union_parts) . ") AS u";
$res = mysqli_query($conn, $sql);
while ($res && $row = mysqli_fetch_assoc($res)) {
$hasCategoryPerm = UserHasPerm('production_' . $row['category']);
$hasStagePerm = ($row['stage'] == 1) ? UserHasPerm('production_prep') : UserHasPerm('warehouse_add');
$rowHasPerm = $hasCategoryPerm && $hasStagePerm;
$amount_in_wh = 0;
$item_id_val = $row['item_id'];
$daily_sql = mysqli_query($conn, "SELECT free_stock FROM statistics_daily WHERE item_id = '$item_id_val'");
$daily_stat = mysqli_fetch_array($daily_sql);
if ($daily_stat != null) {
$amount_in_wh = intval($daily_stat['free_stock']);
}
$stage_results[] = [
'pr_id' => $row['pr_id'],
'item_id' => $row['item_id'],
'stage' => intval($row['stage']),
'category' => $row['category'],
'db_start' => $row['db_start'],
'hasperm' => $rowHasPerm,
'amount_in_wh' => $amount_in_wh
];
}
usort($stage_results, function($a, $b) {
return $a['amount_in_wh'] <=> $b['amount_in_wh'];
});
$results_by_stage[$stage] = $stage_results;
}
$final_results = [];
$pages_per_stage = [];
foreach ($results_by_stage as $stage => $stage_data) {
$total_in_stage = count($stage_data);
$pages_per_stage[$stage] = $total_in_stage > 0 ? ceil($total_in_stage / $maxperpage) : 1;
$offset = max(0, ($cpage - 1) * $maxperpage);
$sliced = array_slice($stage_data, $offset, $maxperpage);
$final_results = array_merge($final_results, $sliced);
}
$maxpage = max($pages_per_stage);
$response = [
'result' => 'ok',
'data' => $final_results,
'cpage' => $cpage,
'maxpage' => $maxpage
];
echo json_encode($response);
} else if (htmlspecialchars($_POST["func"]) == "openDetails") {
$productionId = htmlspecialchars($_POST['productionId'] ?? '');
$productionId = mysqli_real_escape_string($conn, $productionId);
$sql = "SELECT * FROM production_boxing WHERE pr_id = '$productionId'";
$result = mysqli_query($conn, $sql);
if (!$result) {
echo json_encode(['result' => 'Adatbázis hiba']);
exit;
}
$data = [];
while ($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
echo json_encode(['result' => 'ok', 'data' => $data]);
} else if (htmlspecialchars($_POST["func"]) == "SearchTable") {
$maxperpage = intval(htmlspecialchars($_POST["perpage"]));
$cpage = intval(htmlspecialchars($_POST["cpage"]));
$start_datetime = htmlspecialchars($_POST["start_datetime"]);
$end_datetime = htmlspecialchars($_POST["end_datetime"]);
$item_id = htmlspecialchars(str_replace(' ', '+', $_POST['item_id']));
$addquery = "";
$isfirst = true;
if ($cpage == 0) {
$cpage = 1;
}
setcookie("maxperpage", $maxperpage, time() + (86400 * 90), "/");
if ($start_datetime != "") {
$timestamp = strtotime($start_datetime);
$addquery = $addquery." WHERE date_warehouseend > '".$timestamp."'";
$isfirst = false;
}
if ($end_datetime != "") {
$timestamp = strtotime($end_datetime);
if ($isfirst) {
$addquery = $addquery." WHERE date_warehouseend < '".$timestamp."'";
$isfirst = false;
} else {
$addquery = $addquery." and date_warehouseend < '".$timestamp."'";
}
}
if ($item_id != "") {
if ($isfirst) {
$addquery = $addquery." WHERE item_id LIKE '%".$item_id."%'";
$isfirst = false;
} else {
$addquery = $addquery." and item_id LIKE '%".$item_id."%'";
}
}
if ($isfirst) {
$addquery = $addquery." WHERE stage = 0";
$isfirst = false;
} else {
$addquery = $addquery." and stage = 0";
}
$table = "production_boxing";
$sql = mysqli_query($conn,"SELECT COUNT(*) FROM ".$table.$addquery);
$count = mysqli_fetch_array($sql)[0];
$addquery = $addquery." ORDER BY date_warehouseend DESC";
$maxpage = ceil($count / $maxperpage);
if (!($cpage >= 1 && $cpage <= $maxpage)) {
$cpage = 1;
}
$limit = ($cpage - 1) * $maxperpage;
$responseStr = '';
$query = "SELECT pr_id, item_id, db_revenue, date_start, date_warehouseend FROM $table".$addquery." LIMIT $limit, $maxperpage";
if ($result = $conn->query($query)) {
while ($c_prod = $result->fetch_assoc()) {
if ($responseStr != "") {
$responseStr .= "|%|";
}
$responseStr .= $c_prod['item_id'].'/!/'.date("Y. m. d.", $c_prod['date_start']).'/!/'.date("Y. m. d.", $c_prod['date_warehouseend']).'/!/'.$c_prod['db_revenue'].'/!/'.$c_prod['pr_id'];
}
}
echo '{"result": "ok", "data": "'.$responseStr.'", "maxpage": "'.$maxpage.'", "cpage": "'.$cpage.'"}';
} else if (htmlspecialchars($_POST["func"]) == "RefreshDbStart") {
$productionId = htmlspecialchars($_POST['productionId'] ?? '');
$productionId = mysqli_real_escape_string($conn, $productionId);
$item_id = "";
$sql = "SELECT item_id FROM production_boxing WHERE pr_id = '$productionId'";
$result = mysqli_query($conn, $sql);
if (!$result) {
echo json_encode(['result' => 'Adatbázis hiba']);
exit;
}
$item_id = mysqli_fetch_assoc($result)['item_id'];
$annual_result = mysqli_query($conn, "SELECT * FROM statistics_annual WHERE item_id = '$item_id' AND year = (SELECT MAX(year) FROM statistics_annual WHERE item_id = '$item_id') LIMIT 1");
$statistics_annual = mysqli_fetch_assoc($annual_result);
$sql = mysqli_query($conn,"SELECT warehouse_total, warehouse_box FROM statistics_daily WHERE item_id = '$item_id'");
$statistics_daily = mysqli_fetch_array($sql);
$sql = mysqli_query($conn,"SELECT * FROM system_params");
$system_params = [];
while ($row = mysqli_fetch_assoc($sql)) {
$system_params[$row['param_key']] = $row['param_value'];
}
$in_foil_warehouse = intval($statistics_daily['warehouse_total']) - intval($statistics_daily['warehouse_box']);
$daily_consumption = ($statistics_annual["total_consumption"] ?? $system_params["default_total_consumption"]) / 365;
$need_to_box = intval($system_params['box_holding']) * $daily_consumption - intval($statistics_daily['warehouse_box']);
$min_db = min(max(5, ceil($need_to_box)), $in_foil_warehouse);
$sql = mysqli_query($conn,"UPDATE production_boxing SET db_start = '$min_db' WHERE pr_id = '$productionId'");
echo json_encode(['result' => 'ok', 'db_start' => $min_db]);
}
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.'';
}
}
?>
Kezelőfelület
Termékdobozolás
Oldalanként:
Lezárt dobozolási folyamatok áttekintése
Oldalanként:
| Cikkszám |
Kezdési dátum |
Lezárás dátum |
Dobozolt darabszám Dobozszám |
Adatlap |