« Back to History
save_open_box.php
|
20260723_000646.php
Initial Domain Snapshot
Copy Code
<?php require_once __DIR__ . '/../../modules/auth/page_acl.php'; $ctx = page_require_access('mesr_stock_entry'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; if ($_SERVER['REQUEST_METHOD'] !== 'POST') { exit('Invalid Request'); } // Form data capture $month = !empty($_POST['month']) ? $_POST['month'] . '-01' : null; $location_id = (int)($_POST['location_id'] ?? 0); $machine_id = (int)($_POST['machine_id'] ?? 0); // Basic Validation if (!$month || $location_id <= 0 || $machine_id <= 0) { http_response_code(400); exit("Error: Month, Location, and Machine are required."); } try { $pdo->beginTransaction(); // Sirf Fresh rows insert karna (DELETE query puri tarah hata di gayi hai) $ins = $pdo->prepare(" INSERT INTO mesr_yarn_in_open_box (company_id, month, location_id, machine_id, denier, color, total_cons, per_cone_weight, empty_cone_weight, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW()) "); if (isset($_POST['denier']) && is_array($_POST['denier'])) { foreach ($_POST['denier'] as $i => $denier) { // Validation: Agar denier, color aur weight teeno khali hain to skip karein $color = $_POST['color'][$i] ?? ''; $cones = (float)($_POST['total_cons'][$i] ?? 0); if (empty($denier) && empty($color) && $cones <= 0) { continue; } $ins->execute([ $company_id, $month, $location_id, $machine_id, $denier, $color, $cones, (float)($_POST['per_cone_weight'][$i] ?? 0), (float)($_POST['empty_cone_weight'][$i] ?? 0) ]); } } $pdo->commit(); echo "Success: New Open Box Stock added successfully."; } catch (Throwable $e) { if ($pdo->inTransaction()) { $pdo->rollBack(); } http_response_code(500); echo "Error: " . $e->getMessage(); }