<?php

  
require_once __DIR__ . '/../magic/auth.php';

$auth = bdr_require_privilege([1, 27, 40], '../logout.php');
$user = $auth['user_id'];
$father = $auth['user_id'];
$branch = $auth['branch'];
$conn = $auth['conn'];
$db = $auth['conn'];

include "../op/number_text.php";
if (isset($_REQUEST["dd"])) {
	$myday = $_REQUEST["dd"];
} else {
	$myday = date("Y-m-d");
}
$mmm = new DateTime($myday);
$mms =  $mmm->format("m Y");
if (empty($_REQUEST["br"])) {
} else {
	$branch = $_REQUEST["br"];
}
$first_day = date('Y-m-01', strtotime($myday));
$last_day 	= date('Y-m-t', strtotime($myday));
?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">

<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>تحويلات نقدية للإدارة</title>
	<link rel="stylesheet" href="../dist/css/bootstrap.css" />
	<link rel="stylesheet" href="../css/day.css" media="print" />
	<script src="../js/jquery.js"></script>
	<script src="../dist/js/umd/popper.min.js"></script>
	<script src="../dist/js/bootstrap.js"></script>
</head>

<body onload="javascript: window.print(); setTimeout(window.close, 1000);">
	<div class="container-fluid">
		<div class="form-row">
			<div class="col">
				<h6 class="text-center" style="font-size:14px;font-weight:bold;"> تحويلات للإدارة من فرع <?php
						$dd = $conn->prepare("SELECT b_name from branches where branchID = ?");
						$dd->bindParam(1, $branch);
																											$dd->execute();
						if ($dd->rowCount() > 0) {
							$result = $dd->fetch(PDO::FETCH_ASSOC);
							echo $result['b_name'];
						}
						?> خلال شهر <?php echo $mms; ?></h6>
			</div>
		</div>
		<div class="form-row">
			<div class="col">
				<p style="font-size:13px;font-weight:bold;">الحولات النقدية </p>
			</div>
		</div>
		<div class="form-row">
			<div class="col">
				<table class="table table-bordered table-striped ">
					<thead>
						<tr>
							<th class="text-center" width="4%">م</th>
							<th class="text-center" width="8%">المبلغ</th>
							<th class="text-center" width="12%">التاريخ</th>
							<th class="text-center" width="8%">كود</th>
							<th class="text-center" width="20%">المستلم</th>
							<th class="text-center" width="28%">ملاحظات</th>
							<th class="text-center" width="12%">يومية</th>
						</tr>
					</thead>
					<tbody id="tstandby">
						<?php
						$output = '';
						$sql = $conn->prepare("SELECT box_id , printed_no , money_box , current_datee ,month_date, receipt , comm
															  from boxmoney WHERE pay_method = 1 AND branch = ? AND month_date BETWEEN ? AND ? order by box_id ");
						$sql->bindParam(1, $branch);
						$sql->bindParam(2, $first_day);
						$sql->bindParam(3, $last_day);
						$sql->execute();
						if ($sql->rowCount() > 0) {
							$sam = 0;
							$qq = 1;
							while ($row = $sql->fetch()) {
								$output .= '<tr>
												<td>' . $qq . '</td>
												<td>' . $row['money_box'] . '</td>
												<td>' . $row['current_datee'] . '</td>
												<td>' . $row['box_id'] . '</td>
												<td>' . $row['receipt'] . '</td>
												<td>' . $row['comm'] . '</td>
												<td>' . $row['month_date'] . '</td>
										   </tr> ';
								$sam = $sam + $row['money_box'];
								$qq = $qq + 1;
							}
							$output .= '<tr>
																						<td colspan="2" class="text-center">' . $sam . '</td>
																						<td>إجمالي</td>
																						</tr>';
						} else {
							$output .= '<tr><td colspan="7">لا يوجد سجلات ...</td></tr>';
						}
						echo $output;
						?>
					</tbody>
					<tfoot></tfoot>
				</table>
			</div><!-- home sanad in row -->
		</div><!-- end of banking money -->
		<div class="form-row">
			<div class="col">
				<p style="font-size:13px;font-weight:bold;">فواتير الفرع </p>
			</div>
		</div>
		<div class="form-row">
			<div class="col">
				<table class="table table-bordered table-striped ">
					<thead>
						<tr>
							<th class="text-center" width="4%">م</th>
							<th class="text-center" width="8%">المبلغ</th>
							<th class="text-center" width="12%">التاريخ</th>
							<th class="text-center" width="8%">كود</th>
							<th class="text-center" width="20%">المستلم</th>
							<th class="text-center" width="28%">ملاحظات</th>
							<th class="text-center" width="12%">يومية</th>
						</tr>
					</thead>
					<tbody id="tstandby">
						<?php
						$output = '';
						$sql = $conn->prepare("SELECT box_id , printed_no , money_box , current_datee ,month_date, receipt , comm
									from boxmoney WHERE pay_method = 4 AND branch = ? AND month_date BETWEEN ? AND ? order by box_id  ");
						$sql->bindParam(1, $branch);
						$sql->bindParam(2, $first_day);
						$sql->bindParam(3, $last_day);
						$sql->execute();
						if ($sql->rowCount() > 0) {
							$sam = 0;
							$qq = 1;
							while ($row = $sql->fetch()) {

								$output .= '<tr>
												<td>' . $qq . '</td>
												<td>' . $row['money_box'] . '</td>
												<td>' . $row['current_datee'] . '</td>
												<td>' . $row['box_id'] . '</td>
												<td>' . $row['receipt'] . '</td>
												<td>' . $row['comm'] . '</td>
												<td>' . $row['month_date'] . '</td>
											</tr>  ';
								$sam = $sam + $row['money_box'];
								$qq = $qq + 1;
							}
							$output .= '<tr>
															 <td colspan="2" class="text-center" >' . $sam . '</td>
															 <td>إجمالي</td>
															 </tr>';
						} else {
							$output .= '<tr><td colspan="7">لا يوجد سجلات ...</td></tr>';
						}
						echo $output;
						?>
					</tbody>
					<tfoot></tfoot>
				</table>
			</div><!-- home sanad in row -->
		</div><!-- end of cash points money -->

	</div>
</body>

</html>