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));
$stagefilter = intval(htmlspecialchars($_POST['stage'] ?? 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_display = $maxperpage / 5;
$item_filter = '';
if (!empty($item_id)) {
$item_filter = " AND item_id LIKE '%" . mysqli_real_escape_string($conn, $item_id) . "%'";
}
if ($stagefilter != null) {
$item_filter = " AND stage = '$stagefilter'";
}
$tables = ['classic','injmold','sporty'];
if (!empty($category) && in_array($category,$tables)) {
$tables = [$category];
}
$date_field_mapping = [
'classic' => [
1 => ['date_start', 'ordered'],
2 => 'date_prep',
3 => 'date_cut',
4 => 'date_press',
5 => 'date_process',
6 => 'date_clean'
],
'injmold' => [
1 => ['date_start', 'ordered'],
2 => 'date_prep',
3 => null,
4 => 'date_process',
5 => null,
6 => 'date_clean'
],
'sporty' => [
1 => ['date_start', 'ordered'],
2 => null,
3 => 'date_cut',
4 => 'date_press',
5 => null,
6 => null
]
];
$results_by_stage = [];
for ($stage=1; $stage<=7; $stage++) {
$stage_results = [];
$union_parts = [];
foreach ($tables as $t) {
$date_fields_select = [];
for ($s = 1; $s <= 6; $s++) {
$field = $date_field_mapping[$t][$s] ?? null;
if ($field === null) {
$date_fields_select[] = "NULL AS date_stage_{$s}";
} elseif (is_array($field)) {
$date_fields_select[] = "{$field[0]} AS date_stage_{$s}_0";
$date_fields_select[] = "{$field[1]} AS date_stage_{$s}_1";
} else {
$date_fields_select[] = "{$field} AS date_stage_{$s}";
}
}
$union_parts[] = "(SELECT pr_id, item_id, stage, db_start, date_start,
" . implode(', ', $date_fields_select) . ",
'$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']);
$current_stage = intval($row['stage']);
switch ($current_stage) {
case 1:
$hasStagePerm = UserHasPerm('production_prep');
break;
case 2:
$hasStagePerm = UserHasPerm('production_tools');
break;
case 3:
$hasStagePerm = UserHasPerm('production_cut');
break;
case 4:
$hasStagePerm = UserHasPerm('production_press');
break;
case 5:
$hasStagePerm = UserHasPerm('production_process');
break;
case 6:
$hasStagePerm = UserHasPerm('production_postprocess');
break;
case 7:
$hasStagePerm = UserHasPerm('warehouse_add');
break;
default:
$hasStagePerm = false;
}
$rowHasPerm = $hasCategoryPerm && $hasStagePerm;
$print_info = '';
if ($current_stage === 1) {
$date_start = $row["date_stage_1_0"] ?? null;
$ordered = $row["date_stage_1_1"] ?? null;
if (empty($date_start)) {
$print_info = 'Gyártásba kerül';
} elseif (!empty($ordered)) {
$print_info = 'ordered';
} else {
$print_info = 'Előkészítés';
}
} elseif ($current_stage === 7) {
$print_info = 'Raktározás';
} else {
$field = $date_field_mapping[$row['category']][$current_stage] ?? null;
if ($field !== null) {
$date_value = $row["date_stage_{$current_stage}"] ?? null;
$print_info = !empty($date_value) ? 'Elindult' : '';
}
}
$amount_in_wh = 0;
$item_id = $row['item_id'];
$sql_wh = mysqli_query($conn,"SELECT free_stock FROM statistics_daily WHERE item_id = '$item_id'");
$daily_stat = mysqli_fetch_array($sql_wh);
if ($daily_stat != null) {
$amount_in_wh = intval($daily_stat['free_stock']);
}
$stage_results[] = [
'pr_id' => $row['pr_id'],
'item_id' => $item_id,
'stage' => $row['stage'],
'category' => $row['category'],
'db_start' => $row['db_start'],
'hasperm' => $rowHasPerm,
'print_info' => $print_info,
'amount_in_wh' => $amount_in_wh
];
}
usort($stage_results, function($a, $b) {
$a_wh = $a['amount_in_wh'] > 0 ? 1 : $a['amount_in_wh'];
$b_wh = $b['amount_in_wh'] > 0 ? 1 : $b['amount_in_wh'];
if ($a_wh != $b_wh) {
return $a_wh <=> $b_wh;
}
$a_started = ($a['print_info'] === 'Elindult') ? 0 : 1;
$b_started = ($b['print_info'] === 'Elindult') ? 0 : 1;
return $a_started <=> $b_started;
});
$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_display) : 1;
$offset = max(0, ($cpage - 1) * $maxperpage_display);
$sliced = array_slice($stage_data, $offset, $maxperpage_display);
$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'] ?? '');
$category = htmlspecialchars($_POST['category'] ?? '');
$validCategories = [
'classic' => 'production_classic',
'injmold' => 'production_injmold',
'sporty' => 'production_sporty'
];
if (!array_key_exists($category, $validCategories)) {
echo json_encode(['result' => 'Érvénytelen kategória']);
exit;
}
$table = $validCategories[$category];
$productionId = mysqli_real_escape_string($conn, $productionId);
$sql = "SELECT * FROM `$table` 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, 'production_editor' => UserHasPerm('production_editor')]);
} else if (isset($_POST['func']) && $_POST['func'] === 'UpdateProdPar') {
$productionId = $_POST['productionId'] ?? '';
$category = $_POST['category'] ?? '';
$rawData = $_POST['data'] ?? '';
$allowedCategories = ['classic', 'injmold', 'sporty', 'boxing'];
if (!in_array($category, $allowedCategories, true)) {
echo 'Érvénytelen kategória';
exit;
}
$jsonData = json_decode($rawData, true);
if (!is_array($jsonData)) {
echo 'Hibás adatstruktúra';
exit;
}
$HasReload = false;
foreach ($jsonData as $item) {
if (!isset($item['name'], $item['value'])) {
continue;
}
$paramName = $item['name'];
$paramValue = $item['value'];
/* Jogrendszer */
$categoryPerm = 'production_' . $category;
$hasCategoryPerm = UserHasPerm($categoryPerm);
$isParamEditable = false;
$ParamPermID = '';
if ($paramName == 'stage') {
$isParamEditable = true;
} else {
$permData = json_decode(file_get_contents($currentUrl."/managers/prdb.json"), true);
if (isset($permData['ProductionPerms'])) {
foreach ($permData['ProductionPerms'] as $permEntry) {
if ($permEntry['PARAM'] === $paramName) {
$isParamEditable = UserHasPerm($permEntry['PERM']);
$ParamPermID = $permEntry['PERM'];
break;
}
}
}
}
if (!($hasCategoryPerm && $isParamEditable)) {
echo 'Nincs jogosultsága az adott részhez!';
exit;
}
/* Jogrendszer vége */
if ($paramName == 'stage') {
$HasReload = true;
}
/* Paraméter verifikációk */
if (!preg_match('/^[a-z_]+$/', $paramName)) {
continue;
}
if ($paramName == "item_id") {
$sql = mysqli_query($conn,"SELECT name_in_db FROM pr_parameters WHERE item_id = '$paramValue'");
$pr_parameters = mysqli_fetch_array($sql);
if ($pr_parameters == null) {
echo 'Nem létező cikkszámot adott meg!';
exit;
}
$HasReload = true;
}
if ($paramName == 'db_start' && $category == 'boxing') {
$sql = mysqli_query($conn,"SELECT item_id FROM production_".$category." WHERE pr_id = '$productionId'");
$item_id_from_prod = mysqli_fetch_array($sql)[0];
$sql = mysqli_query($conn,"SELECT warehouse_total - warehouse_box FROM statistics_daily WHERE item_id = '$item_id_from_prod'");
$maximum_available_pair = mysqli_fetch_array($sql)[0];
if (intval($maximum_available_pair) < intval($paramValue)) {
echo 'Nem lehet ennyi pár terméket bedobozolni! Nincs elegendő pár a fóliás raktárban.';
exit;
}
}
if ($paramName == "db_start" && intval($paramValue) < 1) {
echo 'Nem lehet 1 párnál kevesebb az induló mennyiség';
exit;
}
if ($paramName == "db_start" && ($category == 'classic' || $category == 'sporty')) {
$table = intval($paramValue) * 2;
$sql = mysqli_query($conn,"SELECT item_id FROM production_".$category." WHERE pr_id = '$productionId'");
$item_id_from_prod = mysqli_fetch_array($sql)[0];
$sql = mysqli_query($conn,"SELECT pcs FROM pr_cutting_parameters WHERE item_id = '$item_id_from_prod'");
$pcs = mysqli_fetch_array($sql)[0];
if (is_numeric($pcs)) {
$tablepcs = ceil($table / intval($pcs));
$sql = mysqli_query($conn,"UPDATE production_$category SET db_table = '$tablepcs' WHERE pr_id = '$productionId'");
}
}
if ($paramValue === '$[TIMESTAMP]') {
$paramValue = time();
$type = 'i';
} else {
$paramValue = htmlspecialchars($paramValue, ENT_QUOTES, 'UTF-8');
$type = 's';
}
$table = $conn->real_escape_string("production_{$category}");
$column = $conn->real_escape_string($paramName);
$sql = "UPDATE `{$table}` SET `{$column}` = ? WHERE `pr_id` = ?";
$stmt = $conn->prepare($sql);
if (!$stmt) {
continue;
}
if ($paramValue == null || trim($paramValue) == '') {
$nullVar = NULL;
$stmt->bind_param($type . 'i', $nullVar, $productionId);
} else {
$stmt->bind_param($type . 'i', $paramValue, $productionId);
}
$stmt->execute();
$stmt->close();
}
if ($HasReload) {
echo 'reload - ';
}
echo 'ok';
} else if (htmlspecialchars($_POST["func"]) == "SearchTable") {
$category = $_POST['category'] ?? '';
$allowedCategories = ['classic', 'sporty', 'injmold', 'all'];
if (!in_array($category, $allowedCategories, true)) {
echo '{"result": "Érvénytelen kategória"}';
exit;
}
$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_revenue > '".$timestamp."'";
$isfirst = false;
}
if ($end_datetime != "") {
$timestamp = strtotime($end_datetime);
if ($isfirst) {
$addquery = $addquery." WHERE date_revenue < '".$timestamp."'";
$isfirst = false;
} else {
$addquery = $addquery." and date_revenue < '".$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";
}
$categories = ($category === 'all') ? ['classic', 'sporty', 'injmold'] : [$category];
$count = 0;
foreach ($categories as $cat) {
$table = $conn->real_escape_string("production_{$cat}");
$sql = mysqli_query($conn, "SELECT COUNT(*) FROM ".$table.$addquery);
$count += mysqli_fetch_array($sql)[0];
}
$addquery = $addquery." ORDER BY date_revenue DESC";
$maxpage = ceil($count / $maxperpage);
if (!($cpage >= 1 && $cpage <= $maxpage)) {
$cpage = 1;
}
$limit = ($cpage - 1) * $maxperpage;
$responseStr = '';
$remaining = $maxperpage;
$offset = $limit;
foreach ($categories as $cat) {
if ($remaining <= 0) break;
$table = $conn->real_escape_string("production_{$cat}");
$cat_count_sql = mysqli_query($conn, "SELECT COUNT(*) FROM ".$table.$addquery);
$cat_count = mysqli_fetch_array($cat_count_sql)[0];
if ($offset >= $cat_count) {
$offset -= $cat_count;
continue;
}
$cat_limit = min($remaining, $cat_count - $offset);
$query = "SELECT pr_id, item_id, (db_revenue * 2) + db_revenue_bulk_r + db_revenue_bulk_l AS total_revenue, date_start, date_revenue FROM $table".$addquery." LIMIT $offset, $cat_limit";
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_revenue']).'/!/'.$c_prod['total_revenue'].'/!/'.$c_prod['pr_id'].'/!/'.$cat;
}
}
$remaining -= $cat_limit;
$offset = 0;
}
echo '{"result": "ok", "data": "'.$responseStr.'", "maxpage": "'.$maxpage.'", "cpage": "'.$cpage.'", "category": "'.$category.'"}';
}
else if (htmlspecialchars($_POST["func"]) == "OpenCatalogue") {
$param = htmlspecialchars($_POST["param"]);
$item_id = htmlspecialchars( str_replace(' ', '+', $_POST['item_id']) ?? '' );
$LocalData = json_decode(file_get_contents($currentUrl."/managers/prdb.json"), true);
$SendedParam = explode(",", $param);
$pr_items = [];
$wh_items = [];
$st_items = [];
foreach ($SendedParam as $item) {
if (strpos($item, 'pr_') === 0) {
$pr_items[] = $item;
} elseif (strpos($item, 'wh_') === 0) {
$wh_items[] = $item;
} elseif (strpos($item, 'st_') === 0) {
$st_items[] = $item;
}
}
$result_list = [];
$parameters = [];
$response_arr = [];
if ($LocalData && !empty($pr_items)) {
foreach ($LocalData["DBList"] as $table) {
if (UserHasPerm($table["ID"] . "_read")) {
foreach ($pr_items as $key) {
if (strpos($key, $table["ID"] . "_") === 0) {
$param = substr($key, strlen($table["ID"]) + 1);
$result_list[$table["ID"]][] = ['param' => $param, 'param_code' => $key];
}
}
}
}
if (!empty($result_list)) {
foreach ($result_list as $table_id => $parameters) {
foreach ($parameters as $param) {
$param_name = $param['param'];
$param_code = $param['param_code'];
$param_print_name = "N/A";
$is_valid = false;
foreach ($LocalData["Parameters"] as $ParamData) {
if ($ParamData["ID"] === $param_code) {
$is_valid = true;
$param_print_name = $ParamData["NAME"];
}
}
if ($is_valid) {
$sql = mysqli_query($conn,"SELECT $param_name FROM $table_id WHERE item_id = '$item_id'");
$value = mysqli_fetch_array($sql);
if ($value != null) {
$response_arr[] = [
"param" => $param_name,
"name" => $param_print_name,
"value" => $value[0]
];
}
}
}
}
}
}
if (!empty($wh_items) && UserHasPerm("warehouse_statistic")) {
foreach ($wh_items as $item) {
if ($item == "wh_foil_left") {
$sql = mysqli_query($conn,"SELECT sum(left_db) as left_db FROM warehouse_foil WHERE item_id = '$item_id'");
$value = mysqli_fetch_array($sql);
if ($value != null) {
$response_arr[] = [
"param" => 'wh_foil_left',
"name" => 'Bal fóliás darabszám',
"value" => $value[0].' db'
];
}
} else if ($item == "wh_foil_right") {
$sql = mysqli_query($conn,"SELECT sum(right_db) as right_db FROM warehouse_foil WHERE item_id = '$item_id'");
$value = mysqli_fetch_array($sql);
if ($value != null) {
$response_arr[] = [
"param" => 'wh_foil_right',
"name" => 'Jobb fóliás darabszám',
"value" => $value[0].' db'
];
}
}
}
}
if (!empty($st_items) && UserHasPerm("production_statistics")) {
$StatPrintName = [
"st_daily_warehouse_box" => "Raktárkészlet dobozos",
"st_daily_warehouse_total" => "Teljes raktárkészlet",
"st_daily_stock_endurance" => "Készlet kitartás",
"st_daily_stock_box_endurance" => "Dobozos kitartás",
"st_daily_priority_score" => "Sürgősségi score",
"st_daily_boxing_score" => "Dobozolási score",
"st_daily_under_production" => "Gyártás alatt van",
"st_daily_under_boxing" => "Dobozolás alatt van",
"st_daily_under_sales" => "Eladás alatt van",
"st_annual_total_consumption" => "Éves fogyás",
"st_annual_average_production" => "Gyártási átlagidő",
"st_annual_produced_quantity" => "Legyártott mennyiség",
"st_annual_went_into_production" => "Gyártásba került",
"st_annual_average_scrap" => "Átlag selejtszám"
];
foreach ($st_items as $item) {
if (!array_key_exists($item, $StatPrintName)) {
$response_arr[] = [
"param" => $item,
"name" => "HHIBÁS PARAMÉTER",
"value" => $item
];
continue;
}
if (str_starts_with($item, 'st_annual_')) {
$param = substr($item, strlen('st_annual_'));
$sql = mysqli_query($conn,"SELECT `$param` FROM statistics_annual WHERE item_id = '$item_id' ORDER BY year DESC LIMIT 1");
if ($sql && $value = mysqli_fetch_array($sql)) {
$response_arr[] = [
"param" => $item,
"name" => $StatPrintName[$item],
"value" => $value[0] ?? 'N/A'
];
}
} else if (str_starts_with($item, 'st_daily_')) {
$param = substr($item, strlen('st_daily_'));
$sql = mysqli_query($conn,"SELECT `$param` FROM statistics_daily WHERE item_id = '$item_id'");
if ($sql && $value = mysqli_fetch_array($sql)) {
$response_arr[] = [
"param" => $item,
"name" => $StatPrintName[$item],
"value" => $value[0] ?? 'N/A'
];
}
}
}
}
echo json_encode(["result"=>"ok","response_arr"=>$response_arr], JSON_UNESCAPED_UNICODE|JSON_NUMERIC_CHECK);
} else if (htmlspecialchars($_POST["func"]) == "DuplicateProduction") {
$productionId = $_POST['productionId'] ?? '';
$category = $_POST['category'] ?? '';
$allowedCategories = ['classic', 'injmold', 'sporty', 'boxing'];
$section = $_POST['section'] ?? 0;
if (!UserHasPerm("production_editor")) {
echo 'Jogosultság megtagadva';
exit;
}
if (!in_array($category, $allowedCategories, true)) {
echo 'Érvénytelen kategória';
exit;
}
if ($section == 0) {
echo 'Érvénytelen szekciók';
exit;
}
$table = $conn->real_escape_string("production_{$category}");
$productionId = $conn->real_escape_string($productionId);
$sql = mysqli_query($conn,"SELECT * FROM $table WHERE pr_id = '$productionId'");
$original = mysqli_fetch_array($sql);
if (!$original) {
echo 'Nincs ilyen rekord';
exit;
}
$new_db_start = intval($original['db_start']) - intval($section);
mysqli_query($conn, "UPDATE $table SET db_start = '$new_db_start' WHERE pr_id = '$productionId'");
$fields = [];
$values = [];
foreach ($original as $key => $value) {
if ($key !== 'pr_id' && is_string($key) && !empty($key) && !is_numeric($key) && $value !== null && $value !== '') {
$fields[] = $key;
if ($key === 'db_start') {
$val = intval($section);
$values[] = $val;
} elseif (is_numeric($value) && intval($value) == $value) {
$val = intval($value);
$values[] = $val;
} else {
$values[] = "'".$conn->real_escape_string($value)."'";
}
}
}
$fields_str = implode(', ', $fields);
$values_str = implode(', ', $values);
mysqli_query($conn, "INSERT INTO $table ($fields_str) VALUES ($values_str)");
echo "ok";
}
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ékgyártás
Gyártási típus:
Gyártás stádiuma:
Oldalanként:
Lezárt gyártási folyamatok áttekintése
Gyártási típus:
Oldalanként:
| Cikkszám |
Kezdési dátum |
Bevételezési dátum |
Legyártott darabszám Jobb + Bal |
Adatlap |