25 db / oldal "; $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"])); $cpage = intval(htmlspecialchars($_POST["cpage"])); $item_id = htmlspecialchars(str_replace(' ', '+', $_POST['item_id'])); $score = htmlspecialchars($_POST["score"]); $under_production = htmlspecialchars($_POST["under_production"]); $under_boxing = htmlspecialchars($_POST["under_boxing"]); $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; } if ($under_production == "1") { if ($isfirst) { $addquery = $addquery." WHERE under_production = '0'"; $isfirst = false; } else { $addquery = $addquery." and under_production = '0'"; } } if ($under_boxing == "1") { if ($isfirst) { $addquery = $addquery." WHERE under_boxing = '0'"; $isfirst = false; } else { $addquery = $addquery." and under_boxing = '0'"; } } if ($score != "") { if ($isfirst && $score == "priority_score") { $addquery = $addquery." WHERE priority_score IS NOT NULL"; } else if ($score == "priority_score") { $addquery = $addquery." and priority_score IS NOT NULL"; } else if ($isfirst && $score == "boxing_score") { $addquery = $addquery." WHERE boxing_score IS NOT NULL"; } else if ($score == "boxing_score") { $addquery = $addquery." and boxing_score IS NOT NULL"; } $addquery = $addquery." ORDER BY ".$score; $isfirst = false; } $sql = mysqli_query($conn,"SELECT COUNT(*) FROM statistics_daily".$addquery); $count = mysqli_fetch_array($sql)[0]; $maxpage = ceil($count / $maxperpage); if (!($cpage >= 1 && $cpage <= $maxpage)) { $cpage = 1; } $limit = ($cpage - 1) * $maxperpage; $sql = mysqli_query($conn,"SELECT param_value FROM system_params WHERE param_key = 'inventory_alert'"); $inventory_alert = intval(mysqli_fetch_array($sql)[0]); $sql = mysqli_query($conn,"SELECT param_value FROM system_params WHERE param_key = 'box_alert'"); $box_alert = intval(mysqli_fetch_array($sql)[0]); $responseStr = ''; $query = "SELECT * FROM statistics_daily".$addquery." LIMIT $limit, $maxperpage"; if ($result = $conn->query($query)) { while ($statistics_daily = $result->fetch_assoc()) { if ($responseStr != "") { $responseStr .= "|%|"; } $sql = mysqli_query($conn,"SELECT total_consumption FROM statistics_annual WHERE item_id = '" . $statistics_daily['item_id'] . "' ORDER BY year DESC LIMIT 1"); $av_prod_sql = mysqli_fetch_array($sql); $av_prod = "N/A"; $is_new = "0"; if ($av_prod_sql != null) { if ($av_prod_sql[0] != 0) { $av_prod = $av_prod_sql[0]; } } else { $sql = mysqli_query($conn,"SELECT data_status FROM pr_parameters WHERE item_id = '" . $statistics_daily['item_id'] . "'"); $data_stat = mysqli_fetch_array($sql)['data_status']; if ($data_stat == 1) { $is_new = "1"; } } $stock_endurance = ($score === "priority_score") ? intval($statistics_daily['stock_endurance']) : intval($statistics_daily['stock_box_endurance']); $show_alert = ($score === "priority_score") ? $inventory_alert : $box_alert; if ($show_alert > $stock_endurance) { $stock_endurance = '' . $stock_endurance . ''; } $responseStr .= $statistics_daily['item_id'].'/!/'.$statistics_daily['warehouse_box'].'/!/'.(intval($statistics_daily['warehouse_total']) - intval($statistics_daily['warehouse_box'])).'/!/'.$stock_endurance.'/!/'.$av_prod.'/!/'.$statistics_daily['under_production'].'/!/'.$statistics_daily['under_boxing'].'/!/'.$is_new; } } echo '{"result": "ok", "data": "'.$responseStr.'", "maxpage": "'.$maxpage.'", "cpage": "'.$cpage.'"}'; } else if (htmlspecialchars($_POST["func"]) == "OpenSettings") { $keys = ['default_average_production', 'default_total_consumption', 'inventory_holding', 'inventory_alert', 'box_holding', 'box_alert']; $placeholders = implode(',', array_fill(0, count($keys), '?')); $stmt = $conn->prepare("SELECT param_key, param_value FROM system_params WHERE param_key IN ($placeholders)"); $stmt->bind_param(str_repeat('s', count($keys)), ...$keys); $stmt->execute(); $result = $stmt->get_result(); $params = []; while ($row = $result->fetch_assoc()) { $params[$row['param_key']] = $row['param_value']; } $sql = mysqli_query($conn,"SELECT day_date FROM statistics_daily ORDER BY day_date ASC LIMIT 1"); $oldest_statistics = mysqli_fetch_array($sql)[0]; $statistics_daily = date('Y.m.d. H:i', $oldest_statistics); echo json_encode([ 'default_average_production' => $params['default_average_production'], 'default_total_consumption' => $params['default_total_consumption'], 'inventory_holding' => $params['inventory_holding'], 'inventory_alert' => $params['inventory_alert'], 'box_holding' => $params['box_holding'], 'box_alert' => $params['box_alert'], 'statistics_daily' => $statistics_daily, 'result' => 'ok' ]); } else if (htmlspecialchars($_POST["func"]) == "SaveSettings") { $params = [ 'default_total_consumption' => htmlspecialchars($_POST["default_total_consumption"]), 'default_average_production' => htmlspecialchars($_POST["default_average_production"]), 'inventory_holding' => htmlspecialchars($_POST["inventory_holding"]), 'inventory_alert' => htmlspecialchars($_POST["inventory_alert"]), 'box_holding' => htmlspecialchars($_POST["box_holding"]), 'box_alert' => htmlspecialchars($_POST["box_alert"]) ]; $stmt = $conn->prepare("UPDATE system_params SET param_value = ? WHERE param_key = ?"); foreach ($params as $key => $value) { $stmt->bind_param('ss', $value, $key); $stmt->execute(); } $stmt->close(); echo json_encode(['result' => 'ok']); } else if (htmlspecialchars($_POST["func"]) == "OpenInfo") { $item_id = htmlspecialchars(str_replace(' ', '+', $_POST['item_id'])); $sql = mysqli_query($conn,"SELECT * FROM statistics_daily WHERE item_id = '$item_id'"); $statistics_daily = mysqli_fetch_array($sql); $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 * FROM system_params"); $system_params = []; while ($row = mysqli_fetch_assoc($sql)) { $system_params[$row['param_key']] = $row['param_value']; } echo json_encode([ 'day_date' => date('Y.m.d. H:i', $statistics_daily['day_date']) ?? 'N/A', 'year' => $statistics_annual['year'] ?? 'N/A', 'warehouse_total' => $statistics_daily['warehouse_total'] ?? 'N/A', 'stock_endurance' => $statistics_daily['stock_endurance'] ?? 'N/A', 'under_production' => $statistics_daily['under_production'] ?? 'N/A', 'under_boxing' => $statistics_daily['under_boxing'] ?? 'N/A', 'under_sales' => $statistics_daily['under_sales'] ?? 'N/A', 'total_consumption' => $statistics_annual['total_consumption'] ?? 'N/A', 'average_production' => $statistics_annual['average_production'] ?? 'N/A', 'average_scrap' => $statistics_annual['average_scrap'] ?? 'N/A', 'inventory_alert' => $system_params['inventory_alert'], 'warehouse_box' => $statistics_daily['warehouse_box'] ?? 'N/A', 'warehouse_foil' => (intval($statistics_daily['warehouse_total']) - intval($statistics_daily['warehouse_box'])) ?? 'N/A', 'stock_box_endurance' => $statistics_daily['stock_box_endurance'] ?? 'N/A', 'free_stock' => $statistics_daily['free_stock'] ?? 'N/A', 'result' => 'ok' ]); } else if (htmlspecialchars($_POST["func"]) == "CreateProduction") { $item_id = htmlspecialchars(str_replace(' ', '+', $_POST['item_id']) ?? ''); $category = htmlspecialchars($_POST['type'] ?? ''); /* Tábla validálás */ $validCategories = [ 'classic' => 'production_classic', 'injmold' => 'production_injmold', 'sporty' => 'production_sporty' ]; if (!array_key_exists($category, $validCategories)) { echo json_encode(['result' => 'Érvénytelen típus']); exit; } $sql_table = $validCategories[$category]; /* Gyártandó termék mennyisége */ $sql = mysqli_query($conn,"SELECT * FROM statistics_daily WHERE item_id = '$item_id'"); $statistics_daily = mysqli_fetch_array($sql); if ($statistics_daily['priority_score'] == null || $statistics_daily['priority_score'] == '') { echo json_encode(['result' => 'Ez a cikkszám nem vehető fel gyártásba!']); exit(); } $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 * FROM system_params"); $system_params = []; while ($row = mysqli_fetch_assoc($sql)) { $system_params[$row['param_key']] = $row['param_value']; } $daily_consumption = ($statistics_annual["total_consumption"] ?? $system_params["default_total_consumption"]) / 365; $inventory_holding_amount = $daily_consumption * ($system_params["inventory_holding"] + ($statistics_annual['average_production'] ?? $system_params['default_average_production'])); $to_invholding = $inventory_holding_amount - ($statistics_daily["warehouse_total"] ?? 0) + ($statistics_annual['average_scrap'] ?? 0); $db_start = ceil($to_invholding / 10) * 10; /* SQL */ $sql = mysqli_query($conn,"INSERT INTO $sql_table(item_id, db_start) VALUES ('$item_id', $db_start)"); $prid = mysqli_insert_id($conn); $_GET['type'] = 'daily'; $_GET['item_id'] = $item_id; $_GET['silent'] = true; include '../managers/statistics.php'; /* Táblázati adatok kitöltése */ if ($category == "classic" || $category == "sporty") { $sql = mysqli_query($conn,"SELECT tablesize_x, tablesize_y FROM pr_cutting_parameters WHERE item_id = '$item_id'"); $pr_cutting_parameters = mysqli_fetch_array($sql); if ($pr_cutting_parameters != null) { $tablesize_x = intval($pr_cutting_parameters['tablesize_x']) ?? 0; $tablesize_y = intval($pr_cutting_parameters['tablesize_y']) ?? 0; $sql = mysqli_query($conn,"SELECT sum(left_db) as left_db, sum(right_db) as right_db FROM warehouse_foil WHERE item_id = '$item_id'"); $value = mysqli_fetch_array($sql); $difference = intval($value["left_db"]) - intval($value["right_db"]); $remain_l = abs($difference); $remain_r = abs($difference); if ($difference > 0) { $remain_r = 0; } else { $remain_l = 0; } $sql = mysqli_query($conn,"UPDATE $sql_table SET tablesize_x = $tablesize_x, tablesize_y = $tablesize_y, remain_r = $remain_r, remain_l = $remain_l WHERE pr_id = '$prid'"); } } echo json_encode(['result' => 'ok', 'db_start' => $db_start]); } else if (htmlspecialchars($_POST["func"]) == "CreateBoxing") { $item_id = htmlspecialchars(str_replace(' ', '+', $_POST['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,"INSERT INTO production_boxing(item_id, db_start) VALUES ('$item_id', $min_db)"); echo json_encode(['result' => 'ok', 'db_start' => $min_db]); $_GET['type'] = 'daily'; $_GET['item_id'] = $item_id; $_GET['silent'] = true; include '../managers/statistics.php'; } else if (htmlspecialchars($_POST["func"]) == "statistics") { $data = []; // Classic adatok $classicQuery = "SELECT stage, COUNT(*) as item_count, SUM(db_start) as total_db_start FROM production_classic WHERE stage != 0 GROUP BY stage"; $classicResult = $conn->query($classicQuery); if ($classicResult) { while ($row = $classicResult->fetch_assoc()) { $data[] = [ 'stage' => $row['stage'], 'item_count' => $row['item_count'], 'is_boxing' => false, 'type' => 'classic', 'db_start' => $row['total_db_start'] ]; } } // Sports adatok $sportyQuery = "SELECT stage, COUNT(*) as item_count, SUM(db_start) as total_db_start FROM production_sporty WHERE stage != 0 GROUP BY stage"; $sportyResult = $conn->query($sportyQuery); if ($sportyResult) { while ($row = $sportyResult->fetch_assoc()) { $data[] = [ 'stage' => $row['stage'], 'item_count' => $row['item_count'], 'is_boxing' => false, 'type' => 'sporty', 'db_start' => $row['total_db_start'] ]; } } // Injmold adatok $injmoldQuery = "SELECT stage, COUNT(*) as item_count, SUM(db_start) as total_db_start FROM production_injmold WHERE stage != 0 GROUP BY stage"; $injmoldResult = $conn->query($injmoldQuery); if ($injmoldResult) { while ($row = $injmoldResult->fetch_assoc()) { $data[] = [ 'stage' => $row['stage'], 'item_count' => $row['item_count'], 'is_boxing' => false, 'type' => 'injmold', 'db_start' => $row['total_db_start'] ]; } } // Boxing adatok $boxingQuery = "SELECT stage, COUNT(*) as item_count, SUM(db_start) as total_db_start, 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 FROM production_boxing WHERE stage != 0 GROUP BY stage, category"; $boxingResult = $conn->query($boxingQuery); if ($boxingResult) { while ($row = $boxingResult->fetch_assoc()) { $data[] = [ 'stage' => $row['stage'], 'item_count' => $row['item_count'], 'is_boxing' => true, 'type' => $row['category'], 'db_start' => $row['total_db_start'] ]; } } // Összesítő: classic, sporty, injmold $stageTypes = []; $totals = []; foreach ($data as $item) { if (in_array($item['type'], ['classic', 'sporty', 'injmold'])) { $stage = $item['stage']; $isBoxing = $item['is_boxing'] ? 'boxing' : 'production'; if (!isset($stageTypes[$stage])) { $stageTypes[$stage] = []; } $stageTypes[$stage][] = $item['type']; $key = $stage . '_' . $isBoxing; if (!isset($totals[$key])) { $totals[$key] = [ 'stage' => $stage, 'item_count' => 0, 'is_boxing' => $item['is_boxing'], 'type' => 'total', 'db_start' => 0 ]; } $totals[$key]['item_count'] += $item['item_count']; $totals[$key]['db_start'] += $item['db_start']; } } foreach ($totals as $key => $total) { list($stage, $isBoxing) = explode('_', $key); $boxingTypes = array_filter($stageTypes[$stage], function($type) use ($data, $stage, $isBoxing) { foreach ($data as $item) { if ($item['stage'] == $stage && $item['type'] == $type && ($item['is_boxing'] ? 'boxing' : 'production') == $isBoxing) { return true; } } return false; }); if (count(array_unique($boxingTypes)) > 1) { $data[] = $total; } } echo json_encode(['result' => 'ok', 'data' => $data]); } exit(); } ?> Kezelőfelület

Title

Gyártástervező

marketing

Cikkszám:

Rendezés:

Gyártás alatt lévők:

Dobozolás alatt lévők:

Oldalanként:

:

:



Cikkszám Raktáron Készletkitartás nap Éves fogyás Info

<    0 / 0    >