« Back to History
sales_entry_add.php
|
20260920_164915.php
Initial Domain Snapshot
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; require_once __DIR__ . '/modules/activity/activity_logger.php'; $ctx = page_require_access('sales_entry'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; $u = $ctx['user'] ?? null; require_once __DIR__ . '/partials/header.php'; function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } /* ================= FETCH DROPDOWN ================= */ $party = $pdo->prepare(" SELECT id, party_name FROM billing_party WHERE company_id=? AND is_active=1 ORDER BY party_name "); $party->execute([$company_id]); $parties = $party->fetchAll(PDO::FETCH_ASSOC); $item = $pdo->prepare(" SELECT id, item_name FROM item_master WHERE company_id=? AND is_active=1 ORDER BY item_name "); $item->execute([$company_id]); $items = $item->fetchAll(PDO::FETCH_ASSOC); /* ================= SAVE ================= */ if($_SERVER['REQUEST_METHOD']=='POST'){ $party_id = (int)($_POST['party_id'] ?? 0); $item_id = (int)($_POST['item_id'] ?? 0); $date = $_POST['sale_date'] ?? ''; $bill = (int)($_POST['bill_no'] ?? 0); $pcs = (float)($_POST['pcs'] ?? 0); $mts = (float)($_POST['mts'] ?? 0); $cut = (float)($_POST['cut'] ?? 0); if($party_id<=0 || $item_id<=0 || !$date || !$bill){ echo "<div class='alert alert-danger'>Required fields missing</div>"; } else { /* fetch names */ $pname = $pdo->prepare("SELECT party_name FROM billing_party WHERE id=? AND company_id=?"); $pname->execute([$party_id,$company_id]); $pname = $pname->fetchColumn(); $iname = $pdo->prepare("SELECT item_name FROM item_master WHERE id=? AND company_id=?"); $iname->execute([$item_id,$company_id]); $iname = $iname->fetchColumn(); try { $stmt = $pdo->prepare(" INSERT INTO sales_entry (company_id, sale_date, bill_no, customer_name, screen_name, pcs, mts, cut) VALUES (?,?,?,?,?,?,?,?) "); $stmt->execute([ $company_id, $date, $bill, $pname, $iname, $pcs, $mts, $cut ]); $insert_id = (int)$pdo->lastInsertId(); activity_log([ 'company_id' => $company_id ?? 0, 'user_id' => $u['id'] ?? ($_SESSION['user_id'] ?? 0), 'module' => 'sales', 'action_name' => 'create', 'entity_type' => 'sales_entry', 'entity_id' => $insert_id ?? 0, 'remarks' => 'Sales entry created' ]); echo "<div class='alert alert-success'>Saved Successfully</div>"; } catch (PDOException $e){ if($e->errorInfo[1] == 1062){ echo "<div class='alert alert-danger'>Duplicate Bill No</div>"; } else { echo "<div class='alert alert-danger'>Error</div>"; } } } } ?> <div class="container py-4"> <h4 class="fw-bold mb-3">Sales Entry</h4> <div class="card"> <div class="card-body"> <form method="post"> <div class="row g-3"> <div class="col-md-3"> <label class="form-label">Party</label> <select name="party_id" class="form-select" required> <option value="">Select</option> <?php foreach($parties as $p): ?> <option value="<?= $p['id'] ?>"><?= h($p['party_name']) ?></option> <?php endforeach; ?> </select> </div> <div class="col-md-3"> <label class="form-label">Screen Name</label> <select name="item_id" class="form-select" required> <option value="">Select</option> <?php foreach($items as $i): ?> <option value="<?= $i['id'] ?>"><?= h($i['item_name']) ?></option> <?php endforeach; ?> </select> </div> <div class="col-md-2"> <label class="form-label">Date</label> <input type="date" name="sale_date" class="form-control" required> </div> <div class="col-md-2"> <label class="form-label">Bill No</label> <input type="number" name="bill_no" class="form-control" required> </div> <div class="col-md-1"> <label class="form-label">PCS</label> <input type="number" step="0.01" name="pcs" class="form-control"> </div> <div class="col-md-1"> <label class="form-label">MTS</label> <input type="number" step="0.01" name="mts" class="form-control"> </div> <div class="col-md-1"> <label class="form-label">CUT</label> <input type="number" step="0.01" name="cut" class="form-control"> </div> <div class="col-12 text-end"> <button class="btn btn-primary px-4">Save</button> </div> </div> </form> </div> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>