<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link href="includes/css-js/admin.css" rel="stylesheet" type="text/css" />
<style type="text/css">
	table,
	td,
	th {
		font-family:
			Arial,
			Helvetica,
			sans-serif;
		font-size:
			10px;
		font-weight:
			normal;
		color:
			#000000;
		text-decoration:
			none;
		line-height:
			12px;
	}
</style>
<?php
include('includes/config/config.php');
include('includes/functions.php');
if (isset($_REQUEST['stock_issue_id'])) {
	$sql = "SELECT stock_issue_id,issue_ref_no,req_id,issue_date,remarks,ohc_location_id,status FROM stock_issue where stock_issue_id='" . $_REQUEST['stock_issue_id'] . "'";
	// echo "query:".$sql;
	$result = mysqli_query($conn, $sql);
	$num_rows = @mysqli_num_rows($result);
	$row = null;
	if ($num_rows > 0) {
		$row = @mysqli_fetch_array($result);
	}
	@extract($row);
}
?>

<style>
	hr {
		margin-top: 10px;
		margin-bottom: 10px;
		padding: 0px;
		border: 0;
		border-top: 1px solid #000;
	}
</style>

<html>

<body>





	<div id="pdfModal" style="">
		<div class="panel-body">

			<?php

			$unitMap = getKeyValueMap('unit_master', 'unit_id', 'unit_name');

			$query = "select * from company_profile ";

			// echo $query;

			$result = mysqli_query($conn, $query);

			$row_company = mysqli_fetch_array($result);

			@extract($row_company);

			?>

			<table style="width: 95%; cellspacing: 0px; cellpadding: 0px; line-height:10px;">
				<tr>
					<td><?php include_once 'pdf_ohc_header.php'; ?></td>
				</tr>
				<tr>

					<td width="80%" style="text-align: center; width: 100%;line-height: 12px;">
						<table width="100%" cellpadding="0" align="center" style="text-align: center; width: 100%; cellspacing: 0px; cellpadding: 0px;">

							<tr>

								<td>
									<h5 style="text-align: center; text-decoration: bold;">ISSUE/RECEIPT
										VOUCHER</h5>
								</td>

							</tr>

						</table>
					</td>


				</tr>

			</table>

			<hr />

			<table border="0" width="100%">
				<tr>
					<td width="15%" align="left">Issue Voucher No:</td>
					<td width="45%" align="left">
						<div id="reqStore"><?php echo $issue_ref_no; ?></div>
					</td>
					<td width="15%" align="left">Issue Date :</td>
					<td width="45%" align="left">
						<div id="reqRequestedBy"><?php echo date_format(date_create($row['issue_date']), "d-M-Y"); ?></div>
					</td>

				</tr>



				<tr>
					<td width="15%" align="left">Issue To :</td>
					<td width="22.5%" align="left">
						<div id="reqRefNo"><?php echo getFieldFromTable("ohc_desc", "ohc_type", "ohc_type_id", $row['ohc_location_id']); ?></div>
					</td>
					<td width="15%" align="left">Requistion No</td>
					<td width="20%" align="left">
						<div id="reqReqDate"> <?php echo getTableFieldValue('requisition', 'req_ref_no', 'req_id', $req_id, ''); ?></div>
					</td>

				</tr>



			</table>


			<table border="1" width="100%" id="reqPdfTable">
				<tr>
					<td bgcolor="#eeeeee" border="1" align="center" width="3%">Sr</td>
					<td bgcolor="#eeeeee" border="1" align="left" width="50%">Item
						Description</td>
					<td bgcolor="#eeeeee" border="1" align="right" width="10%">UOM</td>

					<td bgcolor="#eeeeee" border="1" align="center" width="15%">Issue
						Quantity</td>
					<td bgcolor="#eeeeee" border="1" align="center">Remarks</td>
				</tr>

				<tr>
					<td align="center"></td>
					<td align="left"></td>
					<td align="right"></td>

				</tr>
				<?php
				$count = 1;
				$unitMap = getKeyValueMap('unit_master', 'unit_id', 'unit_name');
				$sql_stock_issue_items = "SELECT stock_issue_item_id,stock_issue_id,item_id,req_id,req_item_id,issue_qty,req_qty,item_batch_no FROM stock_issue_items where stock_issue_id=$stock_issue_id ";
				//echo $sql_stock_issue_items;
				$result_stock_issue = @mysqli_query($conn, $sql_stock_issue_items);
				while ($row_stock_issue = @mysqli_fetch_assoc($result_stock_issue)) {
				?>
					<tr>
						<td align="center"><?php echo $count; ?></td>
						<td align="left"><?php echo getTableFieldValue('tbl_items', 'item_name', 'item_id', $row_stock_issue['item_id']); ?>&nbsp;(Batch:<?php echo $row_stock_issue['item_batch_no'] . ',  Expiry:' . date_format(date_create(getStoreItemExpiryDate($row_stock_issue['item_id'], $row_stock_issue['item_batch_no'])), "M-Y ") . '' ?>)</td>
						<td align="right"><?php echo $unitMap[getTableFieldValue('tbl_items', 'unit_id', 'item_id', $row_stock_issue['item_id'])]; ?></td>

						<td align="right"><?php echo $row_stock_issue['issue_qty'] ?>&nbsp;&nbsp;</td>
						<td align="center"></td>
					</tr>
				<?php

					$count++;
				}

				?>


			</table>

			<br>
			<br>
			<br>
			<?
			$sql_sign = "SELECT * FROM stock_issue where stock_issue_id=$stock_issue_id ";
			$result_sign = mysqli_query($conn, $sql_sign);
			$row_sign = mysqli_fetch_assoc($result_sign);
			@extract($row_sign);
			error_log("sign:" . $sql_sign);

			$sql_signature = "select * from employee_signature where emp_id = '" . $row_sign['stock_issue_emp_id'] . "'";

			$result_signature = mysqli_query($conn, $sql_signature);

			$row_signature = mysqli_fetch_array($result_signature);

			$sql_signature1 = "select * from employee_signature where emp_id = '" . $row_sign['approving_doc_emp_id'] . "'";

			$result_signature1 = mysqli_query($conn, $sql_signature1);

			$row_signature1 = mysqli_fetch_array($result_signature1);

			?>
			<table style="width: 100%; line-height:10px;">
				<td style="width: 30%;">Issued By:- <img src="data:<?= $row_signature['image_type'] ?>;base64,<?= base64_encode($row_signature['emp_sign']) ?>" style="width: 150px; height: 60px; margin: 0px; padding: 0px;"></td>
				<td style="width: 40%; ">HOD:- <img src="data:<?= $row_signature1['image_type'] ?>;base64,<?= base64_encode($row_signature1['emp_sign']) ?>" style="width: 150px; height: 60px; margin: 0px; padding: 0px;"></td>
				<td style="width: 30%; ">Received By</td>
			</table>




		</div>
		</form>
	</div>






	<style>
		.modal-dialog {
			padding: 15px;
			width: 90%;
		}

		@media print {
			@page {
				margin: 0;
			}

			body {
				margin: 1.6cm;
			}
		}
	</style>
	<form class="form" id="reqPDFForm" name="reqPDFForm" method="post">
		<input type="hidden" name="htmlText" id="htmlText">
	</form>
</body>

</html>
<script>
	//generateReqPdf();

	function generateReqPdf() {

		var content = $("#pdfModal").html();
		$("#htmlText").val(content);
		document.reqPDFForm.action = "dynamic_pdf.php";
		document.reqPDFForm.method = "POST";
		document.getElementById("reqPDFForm").submit();


	}
</script>