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

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

include "../op/co_wanted.php";
if(isset($_REQUEST["dd"])){ $myday = $_REQUEST["dd"];	}
				else{$myday = date("Y-m-d"); }
				$first_day = date('Y-m-01', strtotime($myday));
				$last_day 	= date('Y-m-t', strtotime($myday));
				// $mms  = DateTime::createFromFormat( 'm-Y', $myday );
				$mmm = new DateTime($myday);
				$mms =  $mmm->format("m Y");
				?>
<!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.min.css"/>
      	 <link rel="stylesheet" href="../dist/css/day.css" />
	 </head>
    <body onload="javascript: window.print(); setTimeout(window.close, 1000);">
			<div class="container-fluid">
			<div class="row" style="padding:5 ;">
				<div class="col-9"style="float:right;">
					<h6 style="font-weight:bold;padding:3px;font-size:10pt;">مصروفات شهر <?php echo $mms ; ?> </h6>
				</div>
				<div class="col-3" style="float:left;">
					<p style="font-size:8pt;float:left;" ><?php echo date("Y-m-d"); ?></p>
				</div>
			</div>
			<div class="form-row">
				<div class="col">
			 		<table class="table table-bordered">
			 					<thead>
			 							<tr>
			 								<th class="align-middle text-center" width="5%">م</th>
			 								<th class="align-middle text-center" width="25%">اسم الفرع</th>
			 							  <th class="align-middle text-center" width="20%">المنصرف</th>
			 								<th class="align-middle text-center" width="50%">ملاحظات</th>
			 						</tr>
			 			</thead>
			 		  <tbody >
<?php
		$output = '';
		$sql =$db->prepare("SELECT sum(tot_price) as price , branches.b_name as branch from item_line_out , branches
									where item_line_out.branch = branches.branchID  AND date_out between  ? AND ? GROUP BY branches.branchID" );
		$sql->bindParam(1,$first_day );
		$sql->bindParam(2,$last_day );
	  $sql->execute();
			if($sql->rowCount()>0)
				{$money = 0 ; $n = 1 ;
			while($row = $sql->fetch())
					{	$output .= '<tr>
													<td>' . $n . '</td>
													<td>' . $row['price'] . '</td>
													<td>' . $row['branch'] . '</td>
													<td></td>
											</tr>'; $n = $n +1 ;
											$money = $money + $row['price'] ;
														}
	$output .= '<tr><td colspan="4"></td></tr><tr><td colspan="2" >إجمالي</td><td>' . $money. '</td></tr>';
  } else {$output .= '<tr><td colspan="4">لا يوجد سجلات ...</td></tr>';}
		 echo $output; ?>
									</tbody>
			 					<tfoot></tfoot>
			 		     </table>
</div>
</div>
</div>
<script src="../js/jquery.js"></script>
<script src="../dist/js/umd/popper.min.js"></script>
<script src="../dist/js/bootstrap.js"></script>
    </body>
</html>
