<?php
require_once __DIR__ . '/../../classes/Branding.php';
$companyName = Branding::companyName();
$companyLogo = Branding::logoUrl();
$companyLogoFile = Branding::logoFilePath();
session_start();
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../classes/Database.php';
require_once __DIR__ . '/../../classes/Notifications.php';

$t_id=$_GET['quotation_id'];
if (!isset($_SESSION['user_id'])) {
    header('Location: /IMS/login.php');
    exit();
}

$database = new Database();
$conn = $database->getConnection();
$auth = new Auth($conn);
//$notifications = new Notifications($conn);

if (!$auth->isBranchManager($_SESSION['user_id'])) {
    header('Location: weekly2.php?error=' . urlencode('Access denied. Only branch managers can delete deposits.'));
    exit();
}


if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['btn_generate_invoice'])) {
    $invoice_date=$_POST['invoice_date'];

	header("Location: generate_invoice.php?quotation_id=$t_id&invoice_date=$invoice_date");
	
   // $t_id = (int)$_POST['t_id'];
	//echo $t_id;
	
   
	/*
   if (!$notifications->markMessage($notification_id)) {
        header('Location: branch.php?error=' . urlencode('Cannot delete a verified deposit.'));
        exit();
			
    }
	else{
		  header('Location: branch.php?error=' . urlencode('Cannot delete a verified deposit.'));
		
	} */
	
	//header('Location: edit_sale.php');
		
}

/*

    if ($deposit->deleteDeposit($depositId)) {
        header('Location: weekly2.php?success=' . urlencode('Deposit deleted successfully.'));
    } else {
        header('Location: weekly2.php?error=' . urlencode('Error deleting deposit. Please try again.'));
    }
} else {
    header('Location: weekly2.php?error=' . urlencode('Invalid request.'));
}


*/
//exit();
?>

<?php include __DIR__ . '/../../includes/header.php'; ?>
    <style>
        .table-container {
            max-width: 1200px;
            margin: 20px auto;
            padding: 20px;
        }
        .table thead th {
            background-color: #f5f5f5;
            text-align: center;
        }
        .action-btn {
            margin: 0 5px;
        }
        .clickable-row {
            cursor: pointer;
        }
        .clickable-row:hover {
            background-color: #f0f0f0;
        }
        .action-btn {
            pointer-events: auto;
        }
        .disabled-btn {
            pointer-events: none;
            opacity: 0.6;
        }
        @media print {
            .no-print {
                display: none;
            }
        }
    </style>
    <div class="container table-container">
        <h2 class="mb-4">Generating Invoice from Quotation: <?php echo $t_id; ?></h2>
		<form method="POST" action="#">	
			<div class="row">
				<div class="col-xs-4 col-md-4 float-end"  style="align:right;">
					<a href="list_quotations.php" class="btn btn-outline-secondary">
						<i class="fas fa-arrow-left"></i> Back to Quotation List
					</a>							
				</div>
				<div class="col-xs-4 col-md-4"> 
					<input type="date" class="form-control" id="invoice_date" name="invoice_date" required>
				</div>
				
				<div class="col-xs-4 col-md-4"> 
					 <button type="submit" class="btn btn-primary" name="btn_generate_invoice" > Generate Invoice</button>
				</div>
			</div>
		</form>
     
    </div>

    <script>
	//function generateInvoice(id){
		//alert(id);
		//$("#datee").html("Hallo");
	//	$('#invoice_modal').modal('show');
		 var invoice_date=$('#invoice_date').val();
		$('#btn_generate_invoice').click(function() {
		  alert(invoice_date);
		});
	//}
</script>
<?php include __DIR__ . '/../../includes/footer.php'; ?>

