<?php
require_once 'functions.php';

$clients = getAllClients();

$protocol_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;

if (!$protocol_id) {
    header('Location: protocols.php');
    exit;
}

$protocol = getProtocolWithItems($protocol_id);

if (!$protocol) {
    header('Location: protocols.php');
    exit;
}

$next = $protocol['id']+1;
?>

<!DOCTYPE html>
<html lang="bg">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=0.6">
    <title>Протокол №<?php echo $protocol['id']; ?> </title>
	<style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 10px;
            background-color: #f4f4f4;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background-color: white;
            padding: 12px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            text-align: center;
            margin-bottom: 5px;
        }
        .protocol-header {
            background-color: #f8f9fa;
            padding: 20px;
            border-radius: 5px;
            margin-bottom: 5px;
        }
        .protocol-info {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 10px;
            margin-bottom: 5px;
        }
        .info-item {
            background-color: white;
            padding: 12px;
            border-radius: 5px;
            border: 1px solid #ddd;
        }
        .info-label {
            font-weight: bold;
            color: #666;
            margin-bottom: 5px;
        }
        .info-value {
            font-size: 12px;
            color: #333;
        }
        table {
            width: 90%;
            border-collapse: collapse;
            margin-top: 1px;
        }
        th, td {
            border: 0px solid #ddd;
            padding: 12px;
            text-align: left;
        }
        th {
            background-color: #f8f9fa;
            font-weight: bold;
        }
        tr:nth-child(even) {
            background-color: #f9f9f9;
        }
        .btn {
            background-color: #007bff;
            color: white;
            padding: 8px 12px;
            text-decoration: none;
            border-radius: 4px;
            border: none;
            cursor: pointer;
            margin: 2px;
        }
        .btn:hover {
            background-color: #0056b3;
        }
        .btn-success {
            background-color: #28a745;
        }
        .btn-success:hover {
            background-color: #218838;
        }
        .actions {
            text-align: center;
            margin-top: 10px;
        }
        .print-version {
            display: none;
        }
     @media print {
            .nav, .actions {
                display: none;
				align-items: center;
            }
            body {
                background-color: white;
				align-items: center;
            }
            .container {
                box-shadow: none;
                padding: 0;
				align-items: center;
            }
        }
        @media (max-width: 768px) {
            .nav {
                flex-direction: column;
                align-items: center;
            }
            .offer-info {
                grid-template-columns: 1fr;
            }
            table {
                font-size: 10px;
            }
            .container {
                padding: 10px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
      
    
        <h3></h3>
        <?php if (empty($protocol['items'])): ?>
            <p>Няма добавени артикули към този протокол.</p>
			<table>
			<td>
        <?php else: ?>
		       
		 <table style="width: 99%;  border-collapse: collapse; ">
                <tbody>
                    <tr>
					    <td colspan="3">
							<img src="logo.jpg" style="width: 40%; height: 50%;"></img>
						</td>
                       
                    </tr>
                    <tr style="border:0pt; border-collapse: collapse; width: 99%;">
                        <td >
                            <p style="font-size:10pt;">Поръчка № 000- <?php echo $next; ?> / <?php echo date('d.m.Y', strtotime($protocol['protocol_date'])); ?></p>
                            <p style="font-size:10pt;">обект: <strong><?php echo htmlspecialchars($protocol['issuer']); ?></strong></p>
                            <p style="font-size:10pt;">aдрес: <strong><?php echo htmlspecialchars($protocol['issuer_address']); ?></strong></p>
                        </td>
                        <td colspan="2" style="border:0pt;">
                            <p style="text-align:left; font-size:12px;"><strong>ОБСЛЕДВАНЕ</strong></p>
                            <p style="text-align:left; font-size:10px;"><strong>за изграждане охрана</strong></p>
                            <p style="text-align:left; font-size:10px;"><strong>с технически средства</strong></p>
                        </td>
                        
                    </tr>
                    <tr style="height:19.7pt;">
                        <td style="width:216pt;vertical-align:middle;">
                            <p style="font-size:10pt;"><strong>Счетоводител :</strong></p>
                        </td>
                        <td style="width:201.8pt; vertical-align:middle;">
                            <p style="font-size:10pt;"><strong>№ 000- <?php echo $next; ?> / <?php echo date('d.m.Y', strtotime($protocol['protocol_date'])); ?></strong></p>
                        </td>
                        <td style="width:96.05pt; vertical-align:top;">
                            <p style="font-size:10pt;"><strong>дата: <?php echo date('d.m.Y', strtotime($protocol['protocol_date'])); ?></strong></p>
                        </td>
                    </tr>
            <p class="Header" style="font-size:10pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-size:12pt;">&nbsp;</span></p>
        </div>
        <table style="margin-left: 3pt; padding: 0pt; border-collapse: collapse; width: 99%;">
	 <thead>
                <tr style="height:14pt;">
                    <td style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:top;">
                        <p style="text-align:center; font-size:8pt;"><strong>№</strong><strong>&nbsp;&nbsp;</strong><strong>по ред</strong></p>
                    </td>
                    <td colspan="5" style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;">
                      <p  style="text-align:center;"><strong>Артикул</strong></p>
                    </td>
                    <td style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:top;">
                        <p style="text-align:center;"><strong>Мярка</strong></p>
                    </td>
                    <td colspan="1" style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:top;">
                        <p style="text-align:right;"><strong>Кол</strong></p>
                    </td>
                    <td colspan="1" style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:top;">
                        <p style="text-align:center;"><strong>Ед. цена</strong></p>
                    </td>
                    <td colspan="2" style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:top;">
                        <p style="text-align:center;"><strong>Обща стойност</strong></p>
                    </td>
                    <td style="border:0.75pt solid #000000; padding:0pt 5.03pt; vertical-align:middle;">
                        <p style="text-align:center;"><strong>Забележка:</strong></p>
                    </td>                
</tr>
	
                </thead>
				
               
     
        <?php endif; ?>
 
				 <tbody>
                    <?php foreach ($protocol['items'] as $index => $item): ?>
                    <tr style="height:14pt; margin-left: 0pt; border: 0.75pt solid rgb(0, 0, 0); padding: 0pt; border-collapse: collapse; width: 99%;">
                        <td style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;"><?php echo $index + 1; ?></td>
                        <td colspan="5" style=" border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:left;"><strong><?php echo htmlspecialchars($item['article_name']); ?></strong></td>
                        <td style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;"><?php echo htmlspecialchars($item['unit']); ?></td>
					  <td colspan="1"  style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;">   </td>
						<td colspan="1" style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;">
                      
                    </td>
                    <td colspan="2" style="border:0.75pt solid #000000; padding:0pt 5.03pt; vertical-align:middle;">
                      </td>      
                    </tr>
                    <?php endforeach; ?>
                <tr>
              
                    <td colspan="12" style="width:45.65pt; border:0.75pt solid #000000; padding:0pt 5.03pt; vertical-align:middle;">
                        <p style="text-align:right;"><em></em></p>
                    </td>
                </tr>


					<tr style="height:14pt; margin-left: 0pt; border: 0.75pt solid rgb(0, 0, 0); padding: 0pt; border-collapse: collapse; width: 99%;">
                        <td style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;"></td>
                        <td colspan="5" style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;">Стикери</td>
                        <td style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;"></td>
						<td style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;"><p style="text-align:right;"><strong></strong></p></td>
                        <td style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;">   </td>
						<td  colspan="2"  style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;">
                      
                    </td>
                    <td colspan="5" style="width:39.85pt; border:0.75pt solid #000000; padding:0pt 5.03pt; vertical-align:middle;">                      </td>      
                    </tr>
					<tr style="height:14pt; margin-left: 0pt; border: 0.75pt solid rgb(0, 0, 0); padding: 0pt; border-collapse: collapse; width: 99%;">
                        <td style="width:10pt; border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;"></td>
                        <td colspan="5" style="width:100pt; border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;">Консумативи</td>
                        <td style=" border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;"></td>
						<td style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;"><p style="text-align:right;"><strong></strong></p></td>
                        <td style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;">   </td>
						<td colspan="2" style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;"></td>
                    <td style="border:0.75pt solid #000000; padding:0pt 5.03pt; vertical-align:middle;">
                      </td>      
                    </tr>
					
					<tr style="height:14pt; margin-left: 0pt; border: 0.75pt solid rgb(0, 0, 0); padding: 0pt; border-collapse: collapse; width: 99%;">
                        <td style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;"></td>
                        <td colspan="5" style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;">Монтаж</td>
                        <td style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;"></td>
						<td style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;"><p style="text-align:right;"><strong></strong></p></td>
                        <td style="width:31.7pt; border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;">   </td>
						<td colspan="2" style="width:53pt; border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;">
                      
                    </td>
                     <td style="border:0.75pt solid #000000; padding:0pt 5.03pt; vertical-align:middle;">                      </td>      
                    </tr>
					
					<tr style="height:14pt; margin-left: 0pt; border: 0.75pt solid rgb(0, 0, 0); padding: 0pt; border-collapse: collapse; width: 99%;">
                 	<td colspan="7" style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;"><p style="text-align:right;"><strong></strong></p></td>
                        <td colspan="2" style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:лефт;"><p style="text-align: right;"><strong>Сума без ДДС<strong></p>   </td>
					           </tr>
					
					<tr style="height:14pt; margin-left: 0pt; border: 0.75pt solid rgb(0, 0, 0); padding: 0pt; border-collapse: collapse; width: 99%;">
                     <td colspan="7" style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:center;"></td>
					<td colspan="2" style="border-top:0.75pt solid #000000; border-left:0.75pt solid #000000; border-bottom:0.75pt solid #000000; padding:0pt 5.4pt 0pt 5.03pt; vertical-align:лефт;"><p style="text-align: right;"><strong>Сума без ДДС<strong></p>   </td>                      
                    </tr>
                        


			</tbody>
    
                <tr style="height:28.6pt;">
                    <td colspan="10">
                        <p>&nbsp;</p>
                        <p>Извършил обследването:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /........................................../</p>
                        <p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</em><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</em><em>&nbsp;&nbsp;&nbsp;&nbsp;</em><em>подпис</em></p>
                    </td>
                </tr>
                <tr style="height:1pt; margin-left: 30pt;">
                    <td colspan="2">
                        <p style="text-align:center; font-size:10px;"><strong><span style="font-family:Arial;">&nbsp;</span></strong></p>
                    </td>
                    <td style="width:31.35pt; vertical-align:middle;">
                        <p style="text-align:center; font-size:12px;"><strong><span style="font-family:Arial;">Длъжност</span></strong></p>
                    </td>
                    <td colspan="5" style="width:54.35pt; vertical-align:middle;">
                        <p style="text-align:center; font-size:12px;"><strong><span style="font-family:Arial;">Име и Фамилия</span></strong></p>
                    </td>
                    <td colspan="1" style="width:31.95pt; vertical-align:middle;">
                        <p style="text-align:center; font-size:12px;"><strong><span style="font-family:Arial;">Подпис</span></strong></p>
                    </td>
                    <td colspan="2" style="width:31.85pt;vertical-align:middle;">
                        <p style="text-align:center; font-size:12px;"><strong><span style="font-family:Arial;">Дата: </span></strong></p>
                    </td>
                </tr>
                <tr style="height:16pt;">
                    <td colspan="2" style="width:82.75pt;vertical-align:middle;">
                        <p style="text-align:center; font-size:12px;"><strong><span style="font-family:Arial;">Утвърдил</span></strong></p>
                    </td>
                    <td style="width:81.35pt; vertical-align:middle;">
                        <p style="text-align:center; font-size:12px;"><strong><span style="font-family:Arial;">Управител</span></strong></p>
                    </td>
                    <td colspan="5" style="width:124.35pt; vertical-align:middle;">
                        <p style="text-align:center; font-size:12px;"><strong><span style="font-family:Arial;">АНТОНИЙ АНДОНОВ</span></strong></p>
                    </td>
                    <td colspan="1" style="width:121.95pt;vertical-align:middle;">
                        <p style="font-size:11pt;"><strong><span style="font-family:Arial;">&nbsp;</span></strong></p>
                    </td>
                    <td colspan="2" style="width:81.85pt; vertical-align:middle;">
                        <p style="text-align: right; font-size:12pt;"><strong><span style="font-family:Arial;"><span><?php echo date('d.m.Y', strtotime($protocol['protocol_date'])); ?></span></strong></p>
                    </td>
                </tr>
                
            </tbody>
        </table>
		
		
		
		
		
		
		
		
		
		
        <div class="actions">
            <button onclick="window.print()" class="btn btn-success">Печат</button>
			<button type="button" class="btn btn-danger" onclick="window.open('', '_self', ''); window.close();">Затвори</button>
 	
        </div>
    </div>
</body>
</html>

