<?php

include 'load.php';
require_once 'db_connection.php'; 
?>


<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
	<meta name="description" content="POS - Eat More Resturant   | Pos & Invetory System | Dashboard

">
	<meta name="keywords" content="Eat More Resturant   | Pos & Invetory System | Dashboard

">
	<meta name="author" content="Eat More Resturant   | Pos & Invetory System | Dashboard

">
	<meta name="robots" content="noindex, nofollow">

	<title>Stock Transfer Orders | Eat More Resturant   | Pos & Invetory System | Dashboard

</title>


	<?php
	require_once 'headercss.php';
	?>
</head>
<body>
	<div id="global-loader">
		<div class="whirly-loader"> </div>
	</div>

	<div class="main-wrapper">
		<?php
		require_once 'header.php';
		?>

		<?php
		require_once 'navbar.php';
		?>

		<div class="page-wrapper">
			<div class="content">
				<div class="page-header">
					<div class="page-title">
						<h4>Stock Transfer</h4>
						<h6>Stock Transfer Orders</h6>
					</div>
					<div class="pcredit-btn">
						<a href="agency-stock-transfer.php" class="btn btn-added"><img src="assets/img/icons/plus.svg" alt="img" class="me-1">Add Stock Transfer Order</a>
					</div>
				</div>

				<div class="card">
					<div class="card-body">
					<table class="table datanew">
					<thead>
								<tr>
									<th scope="col">#</th>
									<th scope="col">Order No</th>
									<th scope="col">Agency Name</th>
									<th scope="col">Value</th>
									<th scope="col">Date</th>
									<th>Show</th></tr>
								</thead>
								<tbody style="padding: 0px;">
									<?php
									$total_amount = 0; 

									$sql = "SELECT *  FROM mobileagency_stock_transfer_notes LEFT JOIN mobileagency ON mobileagency.agid=mobileagency_stock_transfer_notes.tr_agency
									ORDER BY mobileagency_stock_transfer_notes.tr_note_id DESC";

									$result = $conn->query($sql);
									$rowCount = 0;
									if ($result->num_rows > 0) {
										while($row = $result->fetch_assoc()) {
											$rowCount = $rowCount+1;
											$tr_note_id = $row["tr_note_id"];
											$tr_agency = $row["tr_agency"];
											$tr_amount = $row["tr_amount"];
											$tr_user = $row["tr_user"];
											$tr_date = $row["tr_date"];
											$agname =$row["agname"];
											$total_amount = $total_amount+$tr_amount;
											?>

											<tr>
												<th scope="row"><?php echo $rowCount; ?></th>
												<td><?php echo $tr_note_id; ?></td>
												<td><?php echo $agname; ?></td>
												<td><?php echo number_format((float)$tr_amount,2); ?></td>
												<td><?php echo $tr_date; ?></td>
												<td>
													<a onclick="showTrNote(<?php echo $tr_note_id;  ?>);"> Show</a>
												</td>
											</tr>
											<?php
										}
									}else{
										echo "Not found items..";
									}
									?>
								</tbody>
							</table>
						</div>
					</div>

					<?php
					require_once 'footerjs.php';
					?>
				</body>
				</html>



				<script type="text/javascript">
					function showTrNote(tr_note_id) {
						$.ajax({
							url : "agency-stock-transfer-orders-view.php",
							type : "POST",
							data : "tr_note_id="+tr_note_id+"&",
							success: function(data){
								document.getElementById("msg").innerHTML=data;
								$('#modal44').modal('show');
							},
							error: function(jXHR, textStatus, errorThrown){
								alert(jXHR.responseText);
							}
						})
					}
				</script>

				<div class="modal" tabindex="-1" id="modal44">
					<div class="modal-dialog modal-xl">
						<div class="modal-content">
							<div class="modal-header">
								<h5 class="modal-title">Modal title</h5>
								<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
							</div>
							<div class="modal-body" id="msg">
								
							</div>
							<div class="modal-footer">
								<button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="modal">Close</button>
							</div>
						</div>
					</div>
				</div>
