<?php
include 'includes/config.php'; 

$purchase_date = isset($_POST['purchase_date']) ? $_POST['purchase_date'] : '';
$new_ref_no = isset($_POST['new_ref_no']) ? $_POST['new_ref_no'] : '';

// Validate inputs
if (!empty($purchase_date) && !empty($new_ref_no)) {
    $purchase_date = htmlspecialchars($purchase_date);
    $new_ref_no = htmlspecialchars($new_ref_no);

    $query = "UPDATE purchase_lines
              SET ref_no = :new_ref_no
              WHERE purchase_date = :purchase_date";

    $stmt = $conn->prepare($query);
    $stmt->bindParam(':purchase_date', $purchase_date);
    $stmt->bindParam(':new_ref_no', $new_ref_no);
    
    if ($stmt->execute()) {
        echo "Reference No updated successfully.";
    } else {
        echo "Error updating Reference No.";
    }
}
?>
