« Back to History
mesr_month_closing_direct_entry.php
|
20260723_000646.php
Initial Domain Snapshot
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('month_closing_direct_entry'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; $u = $ctx['user']; require_once __DIR__ . '/partials/header.php'; // Fetch technical names $stmt = $pdo->prepare(" SELECT DISTINCT TRIM(technical_name) AS technical_name FROM yarn_master WHERE company_id = :cid AND is_active = 1 AND technical_name IS NOT NULL AND TRIM(technical_name) <> '' ORDER BY technical_name ASC "); $stmt->execute([':cid' => $company_id]); $yarns = $stmt->fetchAll(PDO::FETCH_COLUMN); $form_month = date('Y-m'); $form_technical_name = ''; $form_total_weight = ''; $flash_message = ''; $flash_type = 'success'; // Handle form submit if ($_SERVER['REQUEST_METHOD'] === 'POST') { $month_input = trim($_POST['month'] ?? ''); $technical_name = trim($_POST['technical_name'] ?? ''); $total_weight = trim((string)($_POST['total_weight'] ?? '')); $month = ''; $form_month = $month_input !== '' ? $month_input : $form_month; $form_technical_name = $technical_name; $form_total_weight = $total_weight; if (preg_match('/^\d{4}-\d{2}$/', $month_input)) { $month = $month_input . '-01'; } if ($month && $technical_name !== '' && $total_weight !== '' && is_numeric($total_weight) && (float)$total_weight >= 0) { $stmt = $pdo->prepare(" INSERT INTO yarn_monthly_closing (company_id, month, technical_name, total_weight, created_at) VALUES (:cid, :month, :technical_name, :total_weight, NOW()) "); $stmt->execute([ ':cid' => $company_id, ':month' => $month, ':technical_name' => $technical_name, ':total_weight' => (float)$total_weight ]); $flash_message = 'Saved successfully: Month ' . htmlspecialchars($month_input, ENT_QUOTES, 'UTF-8') . ', Technical Name ' . htmlspecialchars($technical_name, ENT_QUOTES, 'UTF-8') . ', Total Weight ' . htmlspecialchars($total_weight, ENT_QUOTES, 'UTF-8'); $form_technical_name = ''; $form_total_weight = ''; } else { $flash_type = 'danger'; $flash_message = 'All fields required'; } } ?> <div class="container mt-4"> <div class="card"> <div class="card-header"> <h5>Month Closing Direct Entry</h5> </div> <div class="card-body"> <?php if ($flash_message !== ''): ?> <div class="alert alert-<?= $flash_type ?>"><?= $flash_message ?></div> <?php endif; ?> <form method="POST" class="row g-3"> <!-- Month --> <div class="col-md-4"> <label class="form-label">Month</label> <input type="month" name="month" class="form-control" value="<?= htmlspecialchars($form_month, ENT_QUOTES, 'UTF-8') ?>" required> </div> <!-- Technical Name --> <div class="col-md-4"> <label class="form-label">Technical Name</label> <select name="technical_name" class="form-select" required> <option value="">Select</option> <?php foreach ($yarns as $y): ?> <option value="<?= htmlspecialchars($y, ENT_QUOTES, 'UTF-8') ?>" <?= ($form_technical_name === $y) ? 'selected' : '' ?>> <?= htmlspecialchars($y) ?> </option> <?php endforeach; ?> </select> </div> <!-- Total Weight --> <div class="col-md-4"> <label class="form-label">Total Weight</label> <input type="number" step="0.001" name="total_weight" class="form-control" value="<?= htmlspecialchars($form_total_weight, ENT_QUOTES, 'UTF-8') ?>" required> </div> <div class="col-12 text-end"> <button class="btn btn-primary">Save Entry</button> </div> </form> </div> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>