real_escape_string($reason) . "%'"; } if ($date !== '') { $where .= " AND DATE(FROM_UNIXTIME(date_create)) = '$date'"; } $countSql = "SELECT COUNT(DISTINCT CONCAT(reason, '|', DATE(FROM_UNIXTIME(date_create)))) FROM warehouse_reservation $where"; $countRes = $conn->query($countSql); $totalReasons = $countRes->fetch_row()[0]; $maxpage = ($totalReasons > 0) ? ceil($totalReasons / $maxperpage) : 1; if ($cpage < 1 || $cpage > $maxpage) { $cpage = 1; } $offset = ($cpage - 1) * $maxperpage; $orderbySQL = 'ORDER BY reason ASC, DATE(FROM_UNIXTIME(date_create)) ASC'; switch ($orderby) { case 'CBA': $orderbySQL = 'ORDER BY reason DESC, DATE(FROM_UNIXTIME(date_create)) ASC'; break; case 'FIRST': $orderbySQL = 'ORDER BY DATE(FROM_UNIXTIME(date_create)) ASC, reason'; break; case 'LAST': $orderbySQL = 'ORDER BY DATE(FROM_UNIXTIME(date_create)) DESC, reason'; break; case 'ABC': default: $orderbySQL = 'ORDER BY reason ASC, DATE(FROM_UNIXTIME(date_create)) ASC'; break; } $sql_reasons = "SELECT DISTINCT reason, DATE(FROM_UNIXTIME(date_create)) as order_date FROM warehouse_reservation $where $orderbySQL LIMIT ? OFFSET ?"; $stmt1 = $conn->prepare($sql_reasons); $stmt1->bind_param('ii', $maxperpage, $offset); $stmt1->execute(); $res1 = $stmt1->get_result(); $reason_date_combinations = []; while ($row = $res1->fetch_assoc()) { $reason_date_combinations[] = [ 'reason' => $row['reason'], 'order_date' => $row['order_date'] ]; } if (empty($reason_date_combinations)) { echo json_encode([ 'result' => 'ok', 'cpage' => $cpage, 'maxpage' => $maxpage, 'data' => [] ], JSON_UNESCAPED_UNICODE|JSON_NUMERIC_CHECK); exit; } $conditions = []; $bind_params = []; foreach ($reason_date_combinations as $combo) { $conditions[] = "(reason = ? AND DATE(FROM_UNIXTIME(date_create)) = ?)"; $bind_params[] = $combo['reason']; $bind_params[] = $combo['order_date']; } $sql_items = " SELECT reason, reserv_id, item_id, amount, date_create, taken_out, DATE(FROM_UNIXTIME(date_create)) as order_date FROM warehouse_reservation WHERE $is_active AND (" . implode(' OR ', $conditions) . ") $orderbySQL, item_id "; $stmt2 = $conn->prepare($sql_items); $types = str_repeat('s', count($bind_params)); $stmt2->bind_param($types, ...$bind_params); $stmt2->execute(); $res2 = $stmt2->get_result(); $data = []; while ($row = $res2->fetch_assoc()) { $key = $row['reason'] . '|' . $row['order_date']; $item_id = $row['item_id']; $amount = intval($row['amount']); if (!isset($data[$key])) { $data[$key] = [ 'megrendelo' => $row['reason'] . ' ' . str_replace('-', '. ', $row['order_date']) . '.', 'rendelesek' => [] ]; } $found = false; foreach ($data[$key]['rendelesek'] as &$rendeles) { if ($rendeles['cikkszam'] === $item_id) { $rendeles['mennyiseg'] += $amount; $rendeles['total_taken'] += intval($row['taken_out']); $found = true; break; } } unset($rendeles); if (!$found) { $data[$key]['rendelesek'][] = [ 'cikkszam' => $item_id, 'mennyiseg' => $amount, 'total_taken' => intval($row['taken_out']), 'levetel' => $coderclass->encode($row['reason'] . '|' . $row['order_date'], "SZ4TUN4") ]; } } $instock = []; $hidden = 0; foreach ($data as $index => &$megrendelo) { $OrderCount = 0; $InsufficientStockCount = 0; $hasInProcess = false; foreach ($megrendelo['rendelesek'] as &$rendeles) { $item_id = $rendeles['cikkszam']; $required_amount = $rendeles['mennyiseg']; $taken_amount = $rendeles['total_taken']; $remaining_amount = $required_amount - $taken_amount; if ($rendeles['total_taken'] > 0) { $hasInProcess = true; } if (!isset($instock[$item_id])) { $sql = mysqli_query($conn,"SELECT saleable_quantity FROM statistics_daily WHERE item_id = '$item_id'"); $result = mysqli_fetch_array($sql); if ($result == null) { $sql = mysqli_query($conn, "SELECT SUM(amount) AS total_amount FROM warehouse WHERE item_id = '$item_id' GROUP BY item_id"); $result = mysqli_fetch_array($sql); } $instock[$item_id] = $result ? intval($result[0]) : 0; } $available_stock = $instock[$item_id]; $free_space = $available_stock - $remaining_amount; $OrderCount++; if ($free_space < 0) { $InsufficientStockCount++; $shortage = abs($free_space); if ($is_active != "is_active = 0") { $rendeles['cikkszam'] .= ""; } } } unset($rendeles); if ($hasInProcess && $is_active != "is_active = 0") { $megrendelo['megrendelo'] .= ""; } $hasInsufficientStock = false; if ($InsufficientStockCount != 0) { $hasInsufficientStock = true; } if ($hasInsufficientStock && $hasInProcess && $is_active != "is_active = 0") { if ($InsufficientStockCount == $OrderCount) { $megrendelo['megrendelo'] .= ""; if (!in_array($fulfill, ['ALL', 'NOFULFILL'])) { unset($data[$index]); $hidden++; } } else { $megrendelo['megrendelo'] .= ""; if (!in_array($fulfill, ['ALL', 'PARTFULFILL'])) { unset($data[$index]); $hidden++; } } } else if ($hasInsufficientStock && $is_active != "is_active = 0") { if ($InsufficientStockCount == $OrderCount) { $megrendelo['megrendelo'] .= ""; if (!in_array($fulfill, ['ALL', 'NOFULFILL'])) { unset($data[$index]); $hidden++; } } else { $megrendelo['megrendelo'] .= ""; if (!in_array($fulfill, ['ALL', 'PARTFULFILL'])) { unset($data[$index]); $hidden++; } } } else if (!$hasInsufficientStock && !$hasInProcess && $is_active != "is_active = 0") { $megrendelo['megrendelo'] .= ""; if (!in_array($fulfill, ['ALL', 'CANFULFILL'])) { unset($data[$index]); $hidden++; } } } unset($megrendelo); $output = array_values($data); header('Content-Type: application/json; charset=utf-8'); echo json_encode([ 'result' => 'ok', 'cpage' => $cpage, 'maxpage' => $maxpage, 'is_active' => $return_is_active, 'hidden' => $hidden, 'data' => $output ], JSON_UNESCAPED_UNICODE|JSON_NUMERIC_CHECK); } else if (htmlspecialchars($_POST["func"]) == "Generatepicking_list") { require_once __DIR__ . '/../managers/OrderProcessor.php'; // Input adat előkészítése $inputData = []; // Manual pick feldolgozása $manualPickRaw = $_POST["manual_pick"] ?? ""; if ($manualPickRaw !== "") { $tmp = json_decode($manualPickRaw, true); if (is_array($tmp)) { $manualPick = []; foreach ($tmp as $row) { if (!isset($row["item_id"], $row["amount"], $row["primary_source"], $row["amount_type"])) { continue; } $itemId = htmlspecialchars(str_replace(' ', '+', trim($row["item_id"]))); $amt = intval($row["amount"]); $primarySource = intval(trim($row["primary_source"])); $amountType = intval(trim($row["amount_type"])); if ($itemId === "" || $amt <= 0) { continue; } $manualPick[] = [ "item_id" => $itemId, "amount" => $amt, "primary_source" => $primarySource, "amount_type" => $amountType ]; } if (!empty($manualPick)) { $inputData['manual'] = $manualPick; } } } // Reason mód (ha nem manual) if (empty($inputData) && isset($_POST['reason'])) { $inputData['reason'] = $_POST['reason']; } // Generálás $result = PickingListGenerator::generate($conn, $inputData, $coderclass); // JSON kiírás echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK); } else if (htmlspecialchars($_POST["func"]) == "RemoveFromWarehouse") { require_once __DIR__ . '/../managers/OrderProcessor.php'; $inputData = [ 'wid' => $_POST['wid'] ?? '', 'amount' => $_POST['amount'] ?? '', 'item_id' => $_POST['item_id'] ?? '', 'corrigate' => $_POST['corrigate'] ?? 'false', 'overal_order_id' => $_POST['overal_order_id'] ?? '', 'reason' => $_POST['reason'] ?? '' ]; $result = WarehouseRemover::remove($conn, $inputData, $coderclass); echo json_encode($result, JSON_UNESCAPED_UNICODE); /* LOG-olás */ $amount = $_POST['amount'] ?? '0'; $amount_left = $amount; $amount_right = $amount; if (substr($amount, 0, 1) == "J") { $amount_left = 0; $amount_right = substr($amount, 1); } else if (substr($amount, 0, 1) == "B") { $amount_left = substr($amount, 1); $amount_right = 0; } $encoded = htmlspecialchars($_POST['reason'] ?? ''); $to_place = $coderclass->decode($encoded, "SZ4TUN4"); $loggerclass->writeLogWarehouse(['reason' => 'Kivét rendelés miatt', 'reason_code' => 1, 'item_id' => $_POST['item_id'], 'from_place' => $_POST['tcHely'], 'to_place' => $to_place, 'amount_left' => intval($amount_left), 'amount_right' => intval($amount_right) ]); } else if (htmlspecialchars($_POST["func"]) == "Summarizepicking_list") { $encoded = htmlspecialchars($_POST['reason'] ?? ''); $is_active = intval(htmlspecialchars($_POST['is_active'] ?? 1)); $decoded = $coderclass->decode($encoded, "SZ4TUN4"); $parts = explode('|', $decoded); if (count($parts) !== 2) { echo json_encode(['result'=>'error','message'=>'Érvénytelen azonosító'], JSON_UNESCAPED_UNICODE); exit; } $reason = $parts[0]; $order_date = $parts[1]; $sql = " SELECT IFNULL(order_id,'') AS order_id, IFNULL(order_name,'') AS order_name, IFNULL(order_mail,'') AS order_mail, item_id, amount, taken_out, is_active FROM warehouse_reservation WHERE reason = ? AND DATE(FROM_UNIXTIME(date_create)) = ? AND is_active = ? ORDER BY order_name, order_id, item_id "; $stmt = $conn->prepare($sql); $stmt->bind_param('ssi', $reason, $order_date, $is_active); $stmt->execute(); $res = $stmt->get_result(); $lists = []; $is_active = null; while ($r = $res->fetch_assoc()) { $is_active = $r['is_active']; $hasOrder = $r['order_id'] !== '' || $r['order_name'] !== '' || $r['order_mail'] !== ''; if ($hasOrder) { $key = $r['order_id'].'|'.$r['order_name'].'|'.$r['order_mail']; $label = $r['order_name'].' - '.$r['order_id']; } else { $key = 'maradek'; $label = '!&maradek&! '; } if (!isset($lists[$key])) { $lists[$key] = [ 'overal_order_id' => $label, 'picking_list' => [] ]; } if (intval($r['taken_out']) > 0) { $lists[$key]['picking_list'][] = [ 'wid' => 0, 'item_id' => $r['item_id'], 'amount' => intval($r['taken_out']) ]; } $remaining = intval($r['amount']) - intval($r['taken_out']); if ($remaining > 0) { $lists[$key]['picking_list'][] = [ 'wid' => -1, 'item_id' => $r['item_id'], 'amount' => $remaining ]; } } $stmt->close(); $all = array_values($lists); echo json_encode([ 'result' => 'ok', 'is_active' => $is_active, 'reason' => $reason, 'date' => $order_date, 'all_picking_lists' => $all ], JSON_UNESCAPED_UNICODE|JSON_NUMERIC_CHECK); } else if (htmlspecialchars($_POST["func"]) == "CopyExcel") { $encoded = htmlspecialchars($_POST['reason'] ?? ''); $decoded = $coderclass->decode($encoded, "SZ4TUN4"); $parts = explode('|', $decoded); if (count($parts) !== 2) { echo json_encode(['result'=>'error','message'=>'Érvénytelen azonosító'], JSON_UNESCAPED_UNICODE); exit; } $reason = $parts[0]; $order_date = $parts[1]; $sql = " SELECT IFNULL(order_id,'') AS order_id, IFNULL(order_name,'') AS order_name, IFNULL(order_mail,'') AS order_mail, item_id, amount, taken_out, is_active FROM warehouse_reservation WHERE reason = ? AND DATE(FROM_UNIXTIME(date_create)) = ? ORDER BY order_name, order_id, item_id "; $stmt = $conn->prepare($sql); $stmt->bind_param('ss', $reason, $order_date); $stmt->execute(); $res = $stmt->get_result(); $lists = []; $is_active = null; while ($r = $res->fetch_assoc()) { $is_active = $r['is_active']; $hasOrder = $r['order_id'] !== '' || $r['order_name'] !== '' || $r['order_mail'] !== ''; if ($hasOrder) { $key = $r['order_id'].'|'.$r['order_name'].'|'.$r['order_mail']; } else { $key = 'maradek'; } if (!isset($lists[$key])) { if ($hasOrder) { $lists[$key] = [ 'order_id' => $r['order_id'], 'order_name' => $r['order_name'], 'order_mail' => $r['order_mail'], 'picking_list' => [] ]; } else { $lists[$key] = [ 'order_id' => $label, 'order_name' => $label, 'order_mail' => $label, 'picking_list' => [] ]; } } if (intval($r['taken_out']) > 0) { $lists[$key]['picking_list'][] = [ 'wid' => 0, 'item_id' => $r['item_id'], 'amount' => intval($r['taken_out']) ]; } } $stmt->close(); $lists = array_filter($lists, function($list) { return !empty($list['picking_list']); }); $all = array_values($lists); echo json_encode([ 'result' => 'ok', 'is_active' => $is_active, 'reason' => $reason, 'date' => $order_date, 'all_picking_lists' => $all ], JSON_UNESCAPED_UNICODE|JSON_NUMERIC_CHECK); } else if (htmlspecialchars($_POST["func"]) == "Closepicking_list") { $mode = intval($_POST['mode']); $encoded = htmlspecialchars($_POST['reason'] ?? ''); $decoded = $coderclass->decode($encoded, "SZ4TUN4"); $parts = explode('|', $decoded); if (count($parts) !== 2) { echo json_encode(['result'=>'error','message'=>'Érvénytelen azonosító'], JSON_UNESCAPED_UNICODE); exit; } $reason = $parts[0]; $order_date = $parts[1]; // 1. Lekérdezzük az eredeti rekordok reserv_id-jeit $sql_orig = " SELECT reserv_id FROM warehouse_reservation WHERE reason = ? AND DATE(FROM_UNIXTIME(date_create)) = ? AND is_active = 1 "; $stmt_orig = $conn->prepare($sql_orig); $stmt_orig->bind_param('ss', $reason, $order_date); $stmt_orig->execute(); $res_orig = $stmt_orig->get_result(); $orig_ids = []; while ($row = $res_orig->fetch_assoc()) { $orig_ids[] = $row['reserv_id']; } $stmt_orig->close(); if ($mode === 0) { // MODE 0: Csak eredeti rendelések lezárása if (!empty($orig_ids)) { $date_end = time(); $placeholders = implode(',', array_fill(0, count($orig_ids), '?')); $types = str_repeat('i', count($orig_ids)); $sql_close = "UPDATE warehouse_reservation SET is_active = 0, date_end = $date_end WHERE reserv_id IN ($placeholders)"; $stmt_close = $conn->prepare($sql_close); $stmt_close->bind_param($types, ...$orig_ids); $stmt_close->execute(); $stmt_close->close(); } echo json_encode(['result'=>'ok','message'=>'Rendelések lezárva'], JSON_UNESCAPED_UNICODE); } else { // MODE 1 és 2: Újrarendelés logika $sql = " SELECT item_id, order_id, order_name, order_mail, (amount - taken_out) AS remaining, receipt_method, note, primary_source, amount_type, note FROM warehouse_reservation WHERE reason = ? AND DATE(FROM_UNIXTIME(date_create)) = ? AND is_active = 1 AND (amount - taken_out) > 0 "; $stmt = $conn->prepare($sql); $stmt->bind_param('ss', $reason, $order_date); $stmt->execute(); $res = $stmt->get_result(); $new_reservations = []; while ($row = $res->fetch_assoc()) { $new_reservations[] = $row; } $stmt->close(); if (empty($new_reservations)) { // Ha nincs újrarendelendő tétel, csak az eredeti rekordok lezárása if (!empty($orig_ids)) { $placeholders = implode(',', array_fill(0, count($orig_ids), '?')); $types = str_repeat('i', count($orig_ids)); $date_end = time(); $sql_close = "UPDATE warehouse_reservation SET is_active = 0, date_end = $date_end WHERE reserv_id IN ($placeholders)"; $stmt_close = $conn->prepare($sql_close); $stmt_close->bind_param($types, ...$orig_ids); $stmt_close->execute(); $stmt_close->close(); } echo json_encode(['result'=>'ok','message'=>'Nincs újrarendelendő tétel, rendelések lezárva'], JSON_UNESCAPED_UNICODE); } else { // Beszúrjuk az újrarendelt tételeket if ($order_date === date('Y-m-d', time())) { $current_time = time() + 24 * 60 * 60; } else { $current_time = time(); } $success_count = 0; foreach ($new_reservations as $item) { $sql_insert = " INSERT INTO warehouse_reservation (item_id, amount, taken_out, reason, date_create, is_active, order_id, order_name, order_mail, receipt_method, note, primary_source, amount_type) VALUES (?, ?, 0, ?, ?, 1, ?, ?, ?, ?, ?, ?, ?) "; $stmt_insert = $conn->prepare($sql_insert); $savingReason = $reason; if ($item['order_name'] != "" && strpos($reason, " - ") === false) { $savingReason .= " - ".$item['order_name']; } $stmt_insert->bind_param( 'sisisssssii', $item['item_id'], $item['remaining'], $savingReason, $current_time, $item['order_id'], $item['order_name'], $item['order_mail'], $item['receipt_method'], $item['note'], $item['primary_source'], $item['amount_type'] ); if ($stmt_insert->execute()) { $success_count++; } $stmt_insert->close(); } // MODE 2: Email értesítés a hiányzókról $sent_count = 0; if ($mode === 2) { $missing_items = []; foreach ($new_reservations as $row) { $email = trim($row['order_mail']); if ($email !== '') { if (!isset($missing_items[$email])) { $missing_items[$email] = [ 'name' => $row['order_name'], 'order_id' => $row['order_id'], 'items' => [] ]; } $missing_items[$email]['items'][] = [ 'item_id' => $row['item_id'], 'remaining' => $row['remaining'] ]; } } if (!empty($missing_items) && file_exists(__DIR__ . '/../managers/mail.php')) { require_once __DIR__ . '/../managers/mail.php'; if (function_exists('sendFormattedEmail')) { foreach ($missing_items as $email => $data) { $c_order_id = $data['order_id']; $c_mail = $email; $c_name = $data['name']; $subject = "Rendelése nem teljesíthető - " . $c_order_id . " / Out of stock - ". $c_order_id; /* MAGYAR */ $content = "

Kedves " . htmlspecialchars($c_name) . "!

"; $content .= "Köszönjük a rendelését!

Sajnos az Ön által megrendelt légterelő jelenleg elfogyott, ezért most nem tudjuk feladni.
A termék várhatóan néhány héten belül újra raktárra kerül."; $content .= "

Az alábbi tételek nem állnak rendelkezésre a(z) ". htmlspecialchars($c_order_id) . " rendelésből:

"; $content .= ""; $content .= ""; foreach ($data['items'] as $it) { $content .= "" . ""; } $content .= "
CikkszámHiányzó mennyiség
" . htmlspecialchars($it['item_id']) . "" . $it['remaining'] . " db
"; $content .= "

Kérjük, kattintással jelezze felénk, hogyan szeretne tovább haladni:

"; $content .= 'Megvárom, amíg újra elérhető lesz
'; $content .= 'Kérem a rendelés törlését'; $content .= "

Köszönjük megértését és türelmét!

Üdvözlettel,
Haluskai Csilla
ügyfélkapcsolat

"; /* ANGOL */ $content .= "
"; $content .= "

Dear " . htmlspecialchars($c_name) . "!

"; $content .= "Thank you for your order!

Unfortunately, the wind deflector you ordered is currently out of stock, so we are unable to ship it right now.
The product is expected to be available again in a few weeks."; $content .= "

The following items are not available from order no. ". htmlspecialchars($c_order_id) . ":

"; $content .= ""; $content .= ""; foreach ($data['items'] as $it) { $content .= "" . ""; } $content .= "
Item numberQuantity
" . htmlspecialchars($it['item_id']) . "" . $it['remaining'] . " db
"; $content .= "

Please click below to let us know how you would like to proceed:

"; $content .= 'I’m happy to wait until it’s back in stock
'; $content .= 'I would like to cancel my order'; $content .= "

Thank you for your understanding!

Kind regards,
Csilla Haluskai
customer relations manager

"; $res_mail = sendFormattedEmail($email, $data['name'], $subject, $content); if ($res_mail['success']) { $sent_count++; } } } else { echo json_encode(['result'=>'error','message'=>'sendFormattedEmail nincs definiálva'], JSON_UNESCAPED_UNICODE); exit; } } } if (!empty($orig_ids)) { $placeholders = implode(',', array_fill(0, count($orig_ids), '?')); $types = str_repeat('i', count($orig_ids)); $date_end = time(); $sql_close = "UPDATE warehouse_reservation SET is_active = 0, date_end = $date_end WHERE reserv_id IN ($placeholders)"; $stmt_close = $conn->prepare($sql_close); $stmt_close->bind_param($types, ...$orig_ids); $stmt_close->execute(); $stmt_close->close(); } $message = "$success_count tétel újrarendelve"; if ($mode === 2) { $message .= ", $sent_count email elküldve"; } echo json_encode(['result'=>'ok','message'=>$message], JSON_UNESCAPED_UNICODE); } } /* Automata összeglő levél */ $sql = " SELECT IFNULL(order_id,'') AS order_id, IFNULL(order_name,'') AS order_name, IFNULL(order_mail,'') AS order_mail, item_id, amount, taken_out, receipt_method, note, is_active FROM warehouse_reservation WHERE reason = ? AND DATE(FROM_UNIXTIME(date_create)) = ? ORDER BY order_name, order_id, item_id "; $stmt = $conn->prepare($sql); $stmt->bind_param('ss', $reason, $order_date); $stmt->execute(); $res = $stmt->get_result(); $lists = []; $is_active = null; while ($r = $res->fetch_assoc()) { $is_active = $r['is_active']; $hasOrder = $r['order_id'] !== '' || $r['order_name'] !== '' || $r['order_mail'] !== ''; if ($hasOrder) { $key = $r['order_id'].'|'.$r['order_name'].'|'.$r['order_mail']; $label = $r['order_name'].' - '.$r['order_id']; } else { $key = 'maradek'; $label = ''; } if (!isset($lists[$key])) { if ($hasOrder) { $lists[$key] = [ 'order_id' => $r['order_id'], 'order_name' => $r['order_name'], 'order_mail' => $r['order_mail'], 'picking_list' => [] ]; } else { $lists[$key] = [ 'order_id' => $label, 'order_name' => $label, 'order_mail' => $label, 'picking_list' => [] ]; } } if (intval($r['taken_out']) > 0) { $lists[$key]['picking_list'][] = [ 'wid' => 0, 'item_id' => $r['item_id'], 'receipt_method' => $r['receipt_method'], 'note' => $r['note'], 'amount' => intval($r['taken_out']) ]; } } $stmt->close(); $lists = array_filter($lists, function($list) { return !empty($list['picking_list']); }); $all = array_values($lists); // HTML táblázat generálása a kimenetre $html_table = ''; $html_table .= ''; $html_table .= ''; $html_table .= ''; foreach ($all as $list) { foreach ($list['picking_list'] as $item) { $html_table .= ''; $html_table .= ''; $html_table .= ''; $html_table .= ''; $html_table .= ''; $html_table .= ''; $html_table .= ''; $html_table .= ''; $html_table .= ''; $html_table .= ''; } } $html_table .= '
CikkszámMennyiségIndokRendelés azonosítóRendelés névRendelés e-mailÁtvételi módMegjegyzés
' . htmlspecialchars($item['item_id']) . '' . htmlspecialchars($item['amount']) . '' . htmlspecialchars($reason) . '' . htmlspecialchars($list['order_id']) . '' . htmlspecialchars($list['order_name']) . '' . htmlspecialchars($list['order_mail']) . '' . htmlspecialchars($item['receipt_method']) . '' . htmlspecialchars($item['note']) . '
'; // Levél küldése if (!empty($html_table) && file_exists(__DIR__ . '/../managers/mail.php')) { require_once __DIR__ . '/../managers/mail.php'; if (function_exists('sendFormattedEmail')) { $subject = "Lezárt rendelés - " . $reason; $content = "

Tisztelt címzett!

"; $content .= "

Az alábbi tételek kerültek kiadásra a(z) ". $reason . " (" . str_replace('-', '. ', $order_date) . ") rendelésből:

"; $content .= $html_table; $content .= "

Az excelbe történő beillesztéshez jelölje ki a táblázatot, másolja ki majd illesze be egy excel-be

"; $content .= "

Üdvözlettel,
Szaturnusz Rendszer

"; $res_mail = sendFormattedEmail("rendeles@szatuna.hu", "Szatuna Kft", $subject, $content); } else { echo json_encode(['result'=>'error','message'=>'sendFormattedEmail nincs definiálva'], JSON_UNESCAPED_UNICODE); exit; } } } else if (htmlspecialchars($_POST["func"]) == "filter") { 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); $json = json_encode(array( 'perpage' => $perpageselect, 'result' => 'ok' )); echo $json; } else if (htmlspecialchars($_POST["func"]) == "openreport" && UserHasPerm('warehouse_reservation')) { $encoded = htmlspecialchars($_POST['reason'] ?? ''); $decoded = $coderclass->decode($encoded, "SZ4TUN4"); $parts = explode('|', $decoded); if (count($parts) !== 2) { echo json_encode(['result'=>'error','message'=>'Érvénytelen azonosító'], JSON_UNESCAPED_UNICODE); exit; } $reason = $parts[0]; $order_date = $parts[1]; $responseStr = ''; $query = "SELECT * FROM warehouse_reservation WHERE reason = '$reason' and DATE(FROM_UNIXTIME(date_create)) = '$order_date' and is_active = 1"; if ($result = $conn->query($query)) { while ($reserv_report = $result->fetch_assoc()) { if ($responseStr != "") { $responseStr .= "|%|"; } $order_id = empty($reserv_report['order_id']) ? ' - ' : $reserv_report['order_id']; $order_name = empty($reserv_report['order_name']) ? ' - ' : $reserv_report['order_name']; $order_mail = empty($reserv_report['order_mail']) ? ' - ' : $reserv_report['order_mail']; $receipt_method = empty($reserv_report['receipt_method']) ? ' - ' : $reserv_report['receipt_method']; $order_note = empty($reserv_report['note']) ? ' - ' : $reserv_report['note']; $primary_source = empty($reserv_report['primary_source']) ? 0 : $reserv_report['primary_source']; $primary_warehouse = empty($reserv_report['primary_warehouse']) ? "FŐ" : $reserv_report['primary_warehouse']; $responseStr .= $reserv_report['reason'].'/!/'.$reserv_report['amount'].'/!/'.date("Y. m. d.", $reserv_report['date_create']).'/!/'.$reserv_report['reserv_id'].'/!/'.$order_id.'/!/'.$order_name.'/!/'.$order_mail.'/!/'.$reserv_report['item_id'].'/!/'.$receipt_method.'/!/'.$order_note.'/!/'.$primary_source.'/!/'.$primary_warehouse; } } echo '{"result": "ok", "data": "'.$responseStr.'", "name_in_db": "'.$reason.'", "date": "'.str_replace('-', '. ', $order_date).'."}'; } else if (htmlspecialchars($_POST["func"]) == "reservitem" && UserHasPerm('warehouse_reservation_order')) { $item_id = htmlspecialchars(str_replace(' ', '+', $_POST['item_id'])); $amount = intval(htmlspecialchars($_POST["amount"])); $reason = preg_replace('/[^a-zA-Z0-9áéíóöőúüűÁÉÍÓÖŐÚÜŰ .-]/u', '', htmlspecialchars($_POST["reason"])); $order_id = empty(htmlspecialchars($_POST["order_id"])) ? null : htmlspecialchars($_POST["order_id"]); $order_name = empty(htmlspecialchars($_POST["order_name"])) ? null : htmlspecialchars($_POST["order_name"]); $order_mail = empty(htmlspecialchars($_POST["order_mail"])) ? null : htmlspecialchars($_POST["order_mail"]); $primary_source = intval($_POST["primary_source"] ?? 0); $amount_type = intval($_POST["amount_type"] ?? 0); $receipt_method = filter_var($_POST["receipt_method"] ?? '', FILTER_SANITIZE_STRING) ?: null; //Újfajta $primary_warehouse = filter_var($_POST["primary_warehouse"] ?? '', FILTER_SANITIZE_STRING) ?: null; $customer_type = filter_var($_POST["customer_type"] ?? '', FILTER_SANITIZE_STRING) ?: null; $note = empty(htmlspecialchars($_POST["note"])) ? null : htmlspecialchars($_POST["note"]); if ($reason == "") { echo json_encode(["result" => "Kötelező megadni egy megrendelőt vagy indoklásts!"]); exit(); } if (!filter_var($amount, FILTER_VALIDATE_INT) || intval($amount) <= 0) { echo json_encode(["result" => "A mennyiség csak pozitív egész szám lehet!"]); exit(); } $sql = mysqli_query($conn,"SELECT item_id FROM pr_parameters WHERE item_id = '$item_id'"); $item_id_sql = mysqli_fetch_array($sql); if ($item_id_sql != null) { $item_id = $item_id_sql['item_id']; } else { echo json_encode(["result" => "Nem létező cikkszám lett megadva!"]); exit(); } if (substr($item_id, 0, 2) !== "CL") { $sql = mysqli_query($conn,"SELECT size, foil_product_place FROM pr_warehouse_parameters WHERE item_id = '$item_id'"); $pr_warehouse_parameters = mysqli_fetch_array($sql); if (!($pr_warehouse_parameters != null && ($pr_warehouse_parameters[0] != "" || $pr_warehouse_parameters[1] != ""))) { if ($pr_warehouse_parameters == null) { echo json_encode(["result" => "Nem létező cikkszám lett megadva!"]); } else { echo json_encode(["result" => "A cikkszámhoz nem lett megadva doboz méret!"]); } exit(); } } if ($order_mail != null) { $emails = array_map('trim', explode(',', $order_mail)); foreach ($emails as $email) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo json_encode(["result" => "Az e-mail cím helytelen formátumban van: " . $email]); exit(); } } } $sql = mysqli_query($conn,"SELECT warehouse_total AS total_amount FROM statistics_daily WHERE item_id = '$item_id'"); $total_amount_warehouse = mysqli_fetch_array($sql)[0]; $test_space = intval($total_amount_warehouse) - $amount; $time = time(); $sql = mysqli_query($conn,"SELECT reserv_id, amount FROM warehouse_reservation WHERE item_id = '$item_id' and reason = '$reason' and is_active = 1 and order_id = '$order_id' and order_name = '$order_name' and order_mail = '$order_mail' and DATE(FROM_UNIXTIME(date_create)) = CURDATE() and amount_type = $amount_type"); $there_is_this_order = mysqli_fetch_array($sql); if ($there_is_this_order != null) { $new_amount = $amount + intval($there_is_this_order["amount"]); $reserv_id = $there_is_this_order['reserv_id']; $sql = mysqli_query($conn,"UPDATE warehouse_reservation SET amount = $new_amount, receipt_method = '$receipt_method', note = '$note', customer_type = '$customer_type', primary_warehouse = '$primary_warehouse', primary_source = $primary_source, amount_type = $amount_type WHERE reserv_id = '$reserv_id'"); } else { $sql = mysqli_query($conn,"INSERT INTO warehouse_reservation(item_id, amount, reason, is_active, date_create, order_id, order_name, order_mail, receipt_method, note, primary_source, amount_type, primary_warehouse, customer_type) VALUES ('$item_id', $amount, '$reason', 1, $time, '$order_id', '$order_name', '$order_mail','$receipt_method', '$note', $primary_source, $amount_type, '$primary_warehouse', '$customer_type')"); } echo json_encode(["result" => "ok", "rest" => $test_space]); $_GET['type'] = 'daily'; $_GET['item_id'] = $item_id; $_GET['silent'] = true; include '../managers/statistics.php'; } else if (htmlspecialchars($_POST["func"]) == "deleteReservation" && UserHasPerm('warehouse_reservation_order')) { $taken_out = null; if (isset($_POST["reserv_id"])) { $reserv_id = htmlspecialchars($_POST["reserv_id"]); $sql = mysqli_query($conn,"SELECT taken_out FROM warehouse_reservation WHERE reserv_id = '$reserv_id'"); $taken_out = mysqli_fetch_array($sql)[0]; $date_end = time(); $sql = mysqli_query($conn,"UPDATE warehouse_reservation SET is_active = 0, date_end = $date_end, is_deleted = 1 WHERE reserv_id = '$reserv_id'"); } else { $encoded = htmlspecialchars($_POST['reason'] ?? ''); $decoded = $coderclass->decode($encoded, "SZ4TUN4"); $parts = explode('|', $decoded); if (count($parts) !== 2) { echo json_encode(['result'=>'error','message'=>'Érvénytelen azonosító'], JSON_UNESCAPED_UNICODE); exit; } $reason = $parts[0]; $order_date = $parts[1]; $sql = mysqli_query($conn,"SELECT taken_out FROM warehouse_reservation WHERE reason = '$reason' and DATE(FROM_UNIXTIME(date_create)) = '$order_date' and is_active = 1"); $taken_out = mysqli_fetch_array($sql)[0]; $date_end = time(); $sql = mysqli_query($conn,"UPDATE warehouse_reservation SET is_active = 0, date_end = $date_end, is_deleted = 1 WHERE reason = '$reason' and DATE(FROM_UNIXTIME(date_create)) = '$order_date' and is_active = 1"); } echo json_encode(["result" => "ok", "taken_out" => $taken_out]); } else if (htmlspecialchars($_POST["func"]) == "statistics") { $countSql = "SELECT COUNT(DISTINCT CONCAT(reason, '|', DATE(FROM_UNIXTIME(date_create)))) as total FROM warehouse_reservation WHERE is_active = 1"; $totalRes = $conn->query($countSql); $totalOrders = $totalRes->fetch_assoc()['total']; $sql_reasons = "SELECT DISTINCT reason, DATE(FROM_UNIXTIME(date_create)) as order_date FROM warehouse_reservation WHERE is_active = 1"; $res1 = $conn->query($sql_reasons); $classic = ['canFulfill' => 0, 'cantFulfill' => 0]; $sporty = ['canFulfill' => 0, 'cantFulfill' => 0]; $injmold = ['canFulfill' => 0, 'cantFulfill' => 0]; $climair = ['canFulfill' => 0, 'cantFulfill' => 0]; $instock = []; while ($row = $res1->fetch_assoc()) { $reason = $row['reason']; $order_date = $row['order_date']; $itemsSql = "SELECT item_id, SUM(amount - COALESCE(taken_out, 0)) as remaining FROM warehouse_reservation WHERE reason = ? AND DATE(FROM_UNIXTIME(date_create)) = ? AND is_active = 1 GROUP BY item_id"; $stmt = $conn->prepare($itemsSql); $stmt->bind_param('ss', $reason, $order_date); $stmt->execute(); $itemsRes = $stmt->get_result(); $canFulfill = true; while ($itemRow = $itemsRes->fetch_assoc()) { $item_id = $itemRow['item_id']; $itemRemaining = intval($itemRow['remaining']); if ($itemRemaining <= 0) continue; if (!isset($instock[$item_id])) { $sql = mysqli_query($conn,"SELECT warehouse_total FROM statistics_daily WHERE item_id = '$item_id'"); $result = mysqli_fetch_array($sql); if ($result == null) { $sql = mysqli_query($conn, "SELECT SUM(amount) AS total_amount FROM warehouse WHERE item_id = '$item_id' GROUP BY item_id"); $result = mysqli_fetch_array($sql); } $instock[$item_id] = $result ? intval($result[0]) : 0; } $available_stock = $instock[$item_id]; $prefix = explode('+', $item_id)[0]; if (preg_match('/^[0-9]+$/', $prefix)) { $classic[$available_stock < $itemRemaining ? 'cantFulfill' : 'canFulfill'] += $itemRemaining; } elseif (preg_match('/^CL[P|M]?[0-9]+$/', $prefix)) { $climair[$available_stock < $itemRemaining ? 'cantFulfill' : 'canFulfill'] += $itemRemaining; } elseif (preg_match('/^FR[0-9]{4}$/', $prefix)) { $injmold[$available_stock < $itemRemaining ? 'cantFulfill' : 'canFulfill'] += $itemRemaining; } elseif (preg_match('/^F[0-9]{4}$/', $prefix)) { $sporty[$available_stock < $itemRemaining ? 'cantFulfill' : 'canFulfill'] += $itemRemaining; } } } echo json_encode([ 'result' => 'ok', 'classic' => $classic, 'sporty' => $sporty, 'injmold' => $injmold, 'climair' => $climair ], JSON_UNESCAPED_UNICODE ); } exit(); } else if (isset($_GET["saving"]) && $_GET["saving"] == 1 && UserHasPerm('warehouse_reservation_order')) { header("Content-Type: application/json"); $input = file_get_contents('php://input'); $tableData = json_decode($input, true); if (!empty($tableData)) { $errors = ""; $lines = ""; for ($i = 0; $i < count($tableData); $i++) { $row = $tableData[$i]; $time = time(); $item_id = $row['item_id']; $amount = $row['amount']; $note = $row['note']; $receipt_method = $row['receipt_method']; $primary_source = $row['primary_source']; $primary_warehouse = $row['primary_warehouse']; $customer_type = $row['customer_type']; $reason = preg_replace('/[^a-zA-Z0-9áéíóöőúüűÁÉÍÓÖŐÚÜŰ .-]/u', '', htmlspecialchars($row["reason"])); $order_id = empty(htmlspecialchars($row["order_id"])) ? null : htmlspecialchars($row["order_id"]); $order_name = empty(htmlspecialchars($row["order_name"])) ? null : htmlspecialchars($row["order_name"]); $order_mail = empty(htmlspecialchars($row["order_mail"])) ? null : htmlspecialchars($row["order_mail"]); if ($reason == "") { $errors .= "|#".$row['line']." - Kötelező megadni egy megrendelőt vagy indoklásts!"; $lines .= "|reserv_table-".$row['line']."-row"; continue; } if (!filter_var($amount, FILTER_VALIDATE_INT) || intval($amount) <= 0) { $errors .= "|#".$row['line']." - A mennyiség csak pozitív egész szám lehet!"; $lines .= "|reserv_table-".$row['line']."-row"; continue; } if ($order_mail != null) { $emails = array_map('trim', explode(',', $order_mail)); foreach ($emails as $email) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors .= "|#".$row['line']." - Az e-mail cím helytelen formátumban van: ".$email; $lines .= "|reserv_table-".$row['line']."-row"; continue 2; } } } $sql = mysqli_query($conn,"SELECT item_id FROM pr_parameters WHERE item_id = '$item_id'"); $item_id_sql = mysqli_fetch_array($sql); if ($item_id_sql != null) { $item_id = $item_id_sql['item_id']; } else { $errors .= "|#".$row['line']." - Nem létező cikkszám lett megadva!"; $lines .= "|reserv_table-".$row['line']."-row"; continue; } if (substr($item_id, 0, 2) !== "CL") { $sql = mysqli_query($conn,"SELECT size, foil_product_place FROM pr_warehouse_parameters WHERE item_id = '$item_id'"); $pr_warehouse_parameters = mysqli_fetch_array($sql); if (!($pr_warehouse_parameters != null && ($pr_warehouse_parameters[0] != "" || $pr_warehouse_parameters[1] != ""))) { if ($pr_warehouse_parameters == null) { $errors .= "|#".$row['line']." - Nem létező cikkszám!"; } else { $errors .= "|#".$row['line']." - A cikkszámhoz nem lett megadva doboz méret!"; } $lines .= "|reserv_table-".$row['line']."-row"; continue; } } $sql = mysqli_query($conn,"SELECT reserv_id, amount FROM warehouse_reservation WHERE item_id = '$item_id' and reason = '$reason' and is_active = 1 and order_id = '$order_id' and order_name = '$order_name' and order_mail = '$order_mail' and DATE(FROM_UNIXTIME(date_create)) = CURDATE()"); $there_is_this_order = mysqli_fetch_array($sql); if ($there_is_this_order != null) { $new_amount = $amount + intval($there_is_this_order["amount"]); $reserv_id = $there_is_this_order['reserv_id']; $sql = mysqli_query($conn,"UPDATE warehouse_reservation SET amount = $new_amount, receipt_method = '$receipt_method', note = '$note', customer_type = '$customer_type', primary_warehouse = '$primary_warehouse', primary_source = $primary_source WHERE reserv_id = '$reserv_id'"); } else { $sql = mysqli_query($conn,"INSERT INTO warehouse_reservation(item_id, amount, reason, is_active, date_create, order_id, order_name, order_mail, receipt_method, note, primary_source, primary_warehouse, customer_type) VALUES ('$item_id', $amount, '$reason', 1, $time, '$order_id', '$order_name', '$order_mail', '$receipt_method', '$note', $primary_source, '$primary_warehouse', '$customer_type')"); } } $_GET['type'] = 'daily'; $_GET['item_id'] = $item_id; $_GET['silent'] = true; include '../managers/statistics.php'; if ($errors == "") { echo json_encode(["status" => "done"]); } else { echo json_encode(["status" => "error", "message" => substr($errors, 1), "line" => substr($lines, 1)]); } } else { echo json_encode(["status" => "error", "message" => "Hibás adat", "line" => ""]); } exit(); } $customer_type_selector = ''; $query = "SELECT DISTINCT type_name FROM customer_types ORDER BY type_name ASC"; if ($result = $conn->query($query)) { while ($customer_type_sql = $result->fetch_assoc()) { $customer_type_selector .= ''; } } $customer_type_selector = str_replace('value="Magyar web"', 'value="Magyar web" SELECTED', $customer_type_selector); ?> Kezelőfelület

Title

Rendelések

marketing

Rendelés neve / Indoklás:

Rendezési szempont:

Dátum kiválasztása:

Rendelés állapota:

Kiszedhetőség:

Oldalanként:

:

:

:

'; } ?>


Rendelés neve / Indoklás Cikkszám Mennyiség (Kiszedve / Igény) Műveletek

<    0 / 0    >