<?php
require "_header.php";

// Assuming this section gets the values from your request
$email_ids = ""; // You can set this to a valid value if needed
$order_no = trim($_REQUEST['order_no']);
$product_name = $_REQUEST['product_hidden'];
$import_date = $_REQUEST['import_date'];
$courier_company = $_REQUEST['courier_hidden'];
$startdate = DateConversion($import_date,"Y-m-d","d/m/Y");
if($order_no == "")
    {
        header("Location: csc-address.php");
    
    }
$cond = "";
if ($order_no != "") {
    $cond .= " AND order_no IN( '$order_no' )";
}
if ($product_name != "") {
    $cond .= " AND product_name ='$product_name'";
}
if ($import_date != "") {
    $cond .= " AND import_date ='$startdate'";
}
if ($courier_company != "") {
    $cond .= " AND courier_company ='$courier_company'";
}

$sql = "SELECT * FROM csc_customer WHERE 1=1 ";
$sql .= $cond;

$result = dbQuery($sql);
$srno = 1;
$temp = "";
$page_break = 1;

if (dbRows($result) > 0) {
    while ($row = dbArray($result)) {
        $estore_name = $row['estore_name'];
        $vendor_name = $row['vendor_name'];
        $address1 = $row['address1'];
        $district = $row['district'];
        $state = $row['state'];
        $estore_phoneno = $row['estore_phoneno'];
		$alternate_number = $row['alternate_number'];
        if($alternate_number == "" || $alternate_number==0)
        {
            $alternate_number="";
        }
        else
        {
            $alternate_number=" / ".$alternate_number;

        }
        $order_no = $row['order_no'];
        $barcode = $order_no; // Changed from $orderno to $order_no
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Print Example</title>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <style>
		.card-text
		{
			
            margin-bottom: 0px;
            
		}
        /* Custom styles can go here */
    </style>
</head>
<body>

<div class="container mt-4">
    <div class="card" style="width: 30rem;">
        <div class="card-body text-center"> 
            <p class="card-title">To :- <?php echo $district . " - " . $state; ?></p>
            <p class="card-text"><?php echo $estore_name; ?></p>
			<b><p class="card-text"> <?php echo $vendor_name; ?></p>
            <p class="card-text">Address: <?php echo $address1; ?></p>
           <p class="card-text">District: <?php echo $district; ?></p>
            <p class="card-text">State: <?php echo $state; ?></p>
            <p class="card-text">Contact No: <?php echo $estore_phoneno.$alternate_number; ?></p>
            <p class="card-text">Order No: (<?php echo $order_no; ?>)</p></b>

			<br>
            
            <h5 class="card-title">From :- </h5>
            <p class="card-title">Aum Imagineering Pvt Ltd.</p>
            <p class="card-text">602-603A, Shapth-1, S.G. Highway,</p>
            <p class="card-text">Opp. Rajpath Club, Ahmedabad-380015</p>
            <p class="card-text">State - Gujarat</p>
            <p class="card-text">Phone No - 7600045520</p>
           
        </div>
    </div>
</div>
<br>
<button class="btn btn-primary" onclick="printDiv('printableArea')">Print</button>

<script>
    function printDiv(divId) {
    var printContents = document.querySelector('.card-body').innerHTML; 
    var originalContents = document.body.innerHTML;

    document.body.innerHTML = '<html><head><title>Print</title>' +
    '<style>' +
    'body {' +
    '  display: flex;' +
    '  justify-content: center;' +
    '  text-align:center;' + 
    '  align-items: center;' +
    '  height: 100vh;' +
    '  font-size: 25px;' +
    '  font-family: Arial, sans-serif;' +
    '  line-height: 2;' + 
    '}' +
    '.printable-content {' +
    '  width: 100%;' +
    '  max-width: 600px;' +
    '  padding: 20px;' +
    '}' +
    '</style></head><body>' +
    '<div class="printable-content">' + printContents + '</div>' +
    '</body></html>';


    window.print();

    window.location.href="view-delivery-address-report.php";
    document.body.innerHTML = originalContents;
   
}

</script>


</body>
</html>
