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

if(isset($_REQUEST["start"])){
	include "../op/co_wanted.php";
$start = $_REQUEST["start"];
				$end   = $_REQUEST["end"];
				$myday = date("Y-m-d");
				$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" />
				 <script src="../js/jquery.js"></script>
				 <script src="../dist/js/umd/popper.min.js"></script>
			 	<script src="../dist/js/bootstrap.min.js"></script>
	 </head>
	 <!-- onLoad="javscript:window.close( window.print() )" -->
    <body >
			<div class="container-fluid">
			<div class="form-row" style="padding:5 ;">
				<div class="col-4">
					<h6 style="font-weight:bold;padding:3px;font-size:11px;">مؤسسة الوسام المعتمد فرع تأجير السيارات</h6>
				</div>
				<div class="col-4">
					<h6 style="font-weight:bold;padding:3px;font-size:11px;">الرقم الضريبي  ٣٠٠٠٩٨٥٣٢٥٠٠٠٠٣ </h6>
				</div>
				<div class="col-4" style="float:left;">
					<h6 style="font-weight:bold;padding:3px;font-size:10px;"> وارد القيمة المضافة من <?php echo $start ; ?> إلي <?php echo $end ;?> </h6>
				</div>
			</div>
						<!-- <div class="form-row">
							<div class="col"> -->
								<div class="table-responsive">
			 											<table class="table table-bordered">
			 												<thead>
			 													 <tr>
																	 		<th class="align-middle text-center" width="4%"> م </th>
			 																<th class="align-middle text-center" width="6%">رقم العقد</th>
			 																<th class="align-middle text-center" width="27%">اسم المستأجر</th>
			 																<th class="align-middle text-center" width="12%">إقفال العقد</th>
																			<th class="align-middle text-center" width="6%">تعويضات</th>
																			<th class="align-middle text-center" width="6%">قيمة العقد</th>
																			<th class="align-middle text-center" width="4%">الضريبة</th>
			 																<th class="align-middle text-center" width="5%">بعد الضريبة</th>
			 																<th class="align-middle text-center" width="5%">المدفوع</th>
																			<th class="align-middle text-center" width="2%">المستحق</th>
																			<th class="align-middle text-center" width="22%">تعليق</th>
			 																<th class="align-middle text-center" width="2%">الفرع</th>
			 													 </tr>
			 												 </thead>
			 												<tbody >
<?php
			$output = '';
		$sr = 1 ; $a = 0 ; $b = 0; $c =0 ; $d = 0; $e = 0; $nader = 0 ;
						$joker =$db->prepare("SELECT contracts.contract_id , contracts.date_out , contracts.date_in , contracts.branch , contracts.cont_status , contracts.addtion_desc , customers.cust_name FROM contracts , customers WHERE contracts.cust_id = customers.cust_id
 														AND date_in BETWEEN ? AND ?  ORDER BY branch, date_in ");
								$joker->bindParam(1,$start);
								$joker->bindParam(2,$end);
								$joker->execute();
						if($joker->rowCount()>0)
											{
									while($bo = $joker->fetch())
																	{
																$contract_id = $bo['contract_id'] ;
															$wb =	wanted($contract_id);
															$zero = $wb['after_vat'] ;
															if($zero == 0){
																$comm = $bo['addtion_desc'] ;
															}else { $comm = "";}
										$output .= '<tr>
																		<td>' . $sr . '</td>
																		<td>' . $bo['contract_id'] . '</td>
																		<td>' . $bo['cust_name'] . '</td>
																		<td>' . $bo['date_in'] . '</td>
																		<td>' . $wb['addtion_cost'] . '</td>
																		<td>' . $wb['net_cost'] . '</td>
																		<td>' . $wb['vat_req'] . '</td>
																		<td>' . $wb['after_vat'] . '</td>
																		<td>' . $wb['payed'] . '</td>
																		<td>' . $wb['wanted'] . '</td>
																		<td>' . $comm . '</td>
																		<td>' . $bo['branch'] . '</td>
																</tr>  ';
																				$nader = $nader + $wb['addtion_cost'] ;
																				$a = $a + $wb['net_cost'] ;
																				$b = $b + $wb['after_vat'] ;
																				$c = $c + $wb['payed'] ;
																				$d = $d + $wb['wanted'] ;
																				$e = $e + $wb['vat_req'] ;
																				 $sr = $sr + 1;
																			}
																$output .= '<tr>
																								<td colspan="4" >إجمالي</td>
																								<td >' . $nader. '</td>
																								<td >' . $a. '</td>
																								<td >' . $e. '</td>
																								<td >' . $b. '</td>
																								<td >' . $c. '</td>
																								<td >' . $d. '</td>
																						</tr>';
																 }
															 else
															 {	$output .= '<tr><td colspan="10">لا يوجد سجلات ...</td></tr>'; }

															 echo $output; }?>
															</tbody>
			 												 <tfoot></tfoot>
			 											 </table>
								</div>
			<!-- </div>
			 </div> -->
</div><!-- نهاية المطاف -->
    </body>
</html>
