<?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'];

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="10%">كود</th>
							<th class="text-center" width="45%">اسم العميل</th>
							<th class="text-center" width="10%">رقم العقد</th>
							<th class="text-center" width="10%">حالة العقد</th>
						</tr>
					</thead>
					<tbody id="tstandby">
						<?php
						$output = '';
						$sql = $conn->prepare("SELECT money_in , sanad_date , in_id , printed_no , cust_name , contract_id , cont_status
																  FROM sanad_in WHERE branchID = ? AND payMethod = 2 AND sanad_date between ? AND ?  order by in_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()) {
								$cont = $row['cont_status'];
								switch ($cont) {
									case "1":
										$contt =  "ساري";
										break;
									case "2":
										$contt = "مغلق";
										break;
									case "3":
										$contt = "مديون";
										break;
								}
								$output .= '<tr>
												<td>' . $qq . '</td>
												<td>' . $row['money_in'] . '</td>
												<td>' . $row['sanad_date'] . '</td>
												<td>' . $row['in_id'] . '</td>
												<td>' . $row['cust_name'] . '</td>
												<td>' . $row['contract_id'] . '</td>
												<td>' . $contt . '</td>
										</tr>  ';
								$sam = $sam + $row['money_in'];
								$qq = $qq + 1;
							}
							$output .= '<tr>
											<td class="text-center" colspan="2" >' . $sam . '</td>
											<td>إجمالي</td>
											</tr>';
						} else {
							$output .= '<tr><td colspan="8">لا يوجد سجلات ...</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="10%">كود</th>
							<th class="text-center" width="45%">اسم العميل</th>
							<th class="text-center" width="10%">رقم العقد</th>
							<th class="text-center" width="10%">حالة العقد</th>
						</tr>
					</thead>
					<tbody id="tstandby">
						<?php
						$output = '';
						$sql = $conn->prepare("SELECT money_in , sanad_date , in_id , printed_no , cust_name , contract_id , cont_status
																  FROM sanad_in WHERE branchID = ? AND payMethod = 5 AND sanad_date between ? AND ?  order by in_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()) {
								$cont = $row['cont_status'];
								switch ($cont) {
									case "1":
										$contt =  "ساري";
										break;
									case "2":
										$contt = "مغلق";
										break;
									case "3":
										$contt = "مديون";
										break;
								}
								$output .= '<tr>
												<td>' . $qq . '</td>
												<td>' . $row['money_in'] . '</td>
												<td>' . $row['sanad_date'] . '</td>
												<td>' . $row['in_id'] . '</td>
												<td>' . $row['cust_name'] . '</td>
												<td>' . $row['contract_id'] . '</td>
												<td>' . $contt . '</td>
										</tr>  ';
								$sam = $sam + $row['money_in'];
								$qq = $qq + 1;
							}
							$output .= '<tr>
											<td class="text-center" colspan="2" >' . $sam . '</td>
											<td>إجمالي</td>
											</tr>';
						} else {
							$output .= '<tr><td colspan="8">لا يوجد سجلات ...</td></tr>';
						}
						echo $output;
						?>
					</tbody>
					<tfoot></tfoot>
				</table>
			</div><!-- home sanad in row -->
		</div><!-- end of banking ahly 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="10%">كود</th>
							<th class="text-center" width="45%">اسم العميل</th>
							<th class="text-center" width="10%">رقم العقد</th>
							<th class="text-center" width="10%">حالة العقد</th>
						</tr>
					</thead>
					<tbody id="tstandby">
						<?php
						$output = '';
						$sql = $conn->prepare("SELECT money_in , sanad_date , in_id , printed_no , cust_name , contract_id , cont_status
										FROM sanad_in WHERE branchID = ? AND payMethod = 3 AND sanad_date between ? AND ?  order by in_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()) {
								$cont = $row['cont_status'];
								switch ($cont) {
									case "1":
										$contt =  "ساري";
										break;
									case "2":
										$contt = "مغلق";
										break;
									case "3":
										$contt = "مديون";
										break;
								}
								$output .= '<tr>
												<td>' . $qq . '</td>
												<td>' . $row['money_in'] . '</td>
												<td>' . $row['sanad_date'] . '</td>
												<td>' . $row['in_id'] . '</td>
												<td>' . $row['cust_name'] . '</td>
												<td>' . $row['contract_id'] . '</td>
												<td>' . $contt . '</td>
											</tr>  ';
								$sam = $sam + $row['money_in'];
								$qq = $qq + 1;
							}
							$output .= '<tr>
											<td class="text-center" colspan="2" >' . $sam . '</td>
											<td>إجمالي</td>
											</tr>';
						} else {
							$output .= '<tr><td colspan="8">لا يوجد سجلات ...</td></tr>';
						}
						echo $output;
						?>
					</tbody>
					<tfoot></tfoot>
				</table>
			</div><!-- home sanad in row -->
		</div>
</html>