<?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="row">
							<div class="col">
<?php
$dsd =$db->prepare("SELECT carid , kind , model ,concat(letters,' ' ,numbers) as PL , color from cars
		WHERE carid in(SELECT DISTINCT carid FROM car_ment_items WHERE date_out BETWEEN ? AND ? )
		 ORDER BY kind ");
		 $dsd->bindParam(1,$first_day);
		 $dsd->bindParam(2,$last_day);
	   $dsd->execute();
		if($dsd->rowCount()>0)
					{
					$master = 0 ; $qq = 1 ;
		while($row = $dsd->fetch())
								 {
									 $carid 	= $row["carid"];
									 $kind 		= $row["kind"];
									 $model 	= $row["model"];
									 $PL 			= $row["PL"];
									 $color 	= $row["color"];
	 echo "<h6 style='font-weight:bold;padding:3px;font-size:9pt;'>".$qq."~ ".$kind." لوحة رقم " .$PL. " اللون " .$color." " .$model."</h6>"   ;
									 ?>
				</div>
			 	</div>
			 		<table class="table table-bordered">
			 					<thead>
			 							<tr>
			 								<th class="align-middle text-center" width="7%">المبلغ</th>
			 								<th class="align-middle text-center" width="35%">اسم الصنف</th>
			 							  <th class="align-middle text-center" width="5%">الكمية</th>
			 								<th class="align-middle text-center" width="23%">المورد</th>
			 								<th class="align-middle text-center" width="5%">الصرف</th>
			 								<th class="align-middle text-center" width="10%">اسم الفني</th>
			 						</tr>
			 			</thead>
			 		  <tbody >
<?php
		$output = '';
		$sql =$db->prepare("SELECT car_ment_items.tot_price , car_ment_items.item_name,
			 car_ment_items.qty,  car_ment_items.date_out , car_ment_items.technician
			 from car_ment_items  where   carid = ? AND date_out between ? AND ? order by date_out ");
		$sql->bindParam(1,$carid );
		$sql->bindParam(2,$first_day);
		$sql->bindParam(3,$last_day);
	  $sql->execute();
				if($sql->rowCount()>0)
							{$money = 0 ;
								while($row = $sql->fetch())
												{
													$date_out = date_create($row['date_out']);
			                     $date_out = date_format($date_out,"m/d");
											$output .= '<tr>
																	<td>' . $row['tot_price'] . '</td>
																	<td>' . $row['item_name'] . '</td>
																	<td>' . $row['qty'] . '</td>
																	<td>' . $row['item_name'] . '</td>
																	<td>'. $date_out .'</td>
																	<td>' . $row['technician'] . '</td>
															</tr>  ';
																			 $money = $money + $row['tot_price'] ;
														}
	$output .= '<tr><td>' . $money. '</td>	<td>إجمالي</td></tr>';
		 } else {$output .= '<tr><td colspan="6">لا يوجد سجلات ...</td></tr>';}
		 echo $output; ?>
									</tbody>
			 					<tfoot></tfoot>
			 		     </table>
	<?php
				$master = $master + $money		; $qq = $qq +1 ;
													}
		echo "<h6 style='font-weight:bold;padding:3px;font-size:10pt;' > إجمالي مصروفات السيارات $master</h6>";}
	?>
</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>
