<?php session_start();
include('../accesscheck2.php');
require_once('../Connections/courier.php'); 
require_once '../functions/functions.php';
mysql_select_db($database_courier, $courier);

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}


$start_date = $_GET['start_date'];
$end_date = $_GET['end_date'];
$branch_id = $_GET['branch_id'];
list($report_type, $report_type_txt) = explode("@@@", $_GET['report_type']);
//echo $report_type;

$date_range = "AND (a.date_of_order>='$start_date' AND a.date_of_order<='$end_date')";
$query_rsodest = "SELECT date_format(a.date_of_order,'%e %M %Y') as purchase_order_date, date_format(a.supplied_date,'%e %M %Y') as purchase_received_date, b.branch_name as supplier_name, c.branch_name as deliver_to, a.* FROM transfer_orders a LEFT JOIN branches b on a.supplier=b.id LEFT JOIN branches c on a.delivery_location=c.id WHERE a.delivery_location='$branch_id' $date_range order by purchase_order_no desc";
$rsodest = mysql_query($query_rsodest);
$totalRows_rsodest = mysql_num_rows($rsodest);?>

<html lang="en">
    <!--<![endif]-->
    <!-- BEGIN HEAD -->

    <head>
        <meta charset="utf-8" />
        <title> Optical Management System </title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta content="width=device-width, initial-scale=1" name="viewport" />
        <meta content="" name="description" />
        <meta content="" name="author" />
        <!-- BEGIN GLOBAL MANDATORY STYLES -->
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css" />
        <!--<link href="../assets/global/css/font.css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css" />-->
        <link href="../assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
        <link href="../assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css" />
        <link href="../assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
        <link href="../assets/global/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css" />
        <link href="../assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css" rel="stylesheet" type="text/css" />

<style type="text/css" media="all">
    body{
        margin: 0;
    }
    .text-danger strong {
    		color: #9f181c;
		}
    .text-danger {
    		color: #9f181c;
		}
		.receipt-main {
			background: #ffffff none repeat scroll 0 0;
			/*border-bottom: 12px solid #333333;*/
			border-top: 12px solid #9f181c;
			/*margin-top: 50px;*/
			margin-bottom: 50px;
			padding: 40px 30px !important;
			position: relative;
			box-shadow: 0 1px 21px #acacac;
			color: #333333;
			font-family: open sans;
		}
		.receipt-main p {
			color: #333333;
			font-family: open sans;
			line-height: 1.42857;
		}
		.receipt-footer h1 {
			font-size: 15px;
			font-weight: 400 !important;
			margin: 0 !important;
		}
		.receipt-main::after {
			background: #414143 none repeat scroll 0 0;
			content: "";
			height: 5px;
			left: 0;
			position: absolute;
			right: 0;
			top: -13px;
		}
		.receipt-main thead {
			background: #414143 none repeat scroll 0 0;
		}
		.receipt-main thead th {
			color:#fff;
		}
		.receipt-main .amount {
                        text-align: right
		}
		.receipt-right h5 {
			font-size: 16px;
			font-weight: bold;
			margin: 0 0 7px 0;
		}
		.receipt-right p {
			font-size: 12px;
			margin: 0px;
		}
		.receipt-right p i {
			text-align: center;
			width: 18px;
		}
		.receipt-main td {
			padding: 9px 20px !important;
		}
		.receipt-main th {
			padding: 12px 15px !important;
		}
		.receipt-main td {
			font-size: 13px;
			font-weight: initial !important;
		}
		.receipt-main td p:last-child {
			margin: 0;
			padding: 0;
		}	
		.receipt-main td h2 {
			font-size: 20px;
			font-weight: 900;
			margin: 0;
			text-transform: uppercase;
		}
		.receipt-header-mid .receipt-left h1 {
			font-weight: 100;
			margin: 34px 0 0;
			text-align: right;
			text-transform: uppercase;
		}
		.receipt-header-mid {
			margin: 24px 0;
			overflow: hidden;
		}
		
		#container {
			background-color: #dcdcdc;
		}
</style>

</head>

<body>

<div class="container-fluid">
	<div class="row">
        <div class="receipt-main col-xs-12 col-sm-12 col-md-12">
            <div class="row">
    			<div class="receipt-header">
					<div class="col-xs-6 col-sm-6 col-md-6">
						<div class="receipt-left">
							<img class="img-responsive" src="../images/app_pics/rns_logo.jpeg" style="width: 71px;">
						</div>
					</div>
					<div class="col-xs-6 col-sm-6 col-md-6 text-right">
						<div class="receipt-right">
							<h5>ROBERT AND SONS LTD.</h5>
							<p>+233034789/09678909 <i class="fa fa-phone"></i></p>
							<p>INFO@ROBERTANDSON.COM <i class="fa fa-envelope-o"></i></p>
							<p>ADABRAKA BRANCH <i class="fa fa-location-arrow"></i></p>
						</div>
					</div>
				</div>
            </div>
			
			<div class="row">
				<div class="receipt-header receipt-header-mid">
					<div class="col-xs-8 col-sm-8 col-md-8 text-left">
						<div class="receipt-right">
                                                    <h3> <?php echo strtoupper($report_type_txt); ?> </h3>
                                                        <h4 class="text-danger"> DATE RANGE :  <?php echo date('jS M, Y',  strtotime($start_date));?> - <?php echo date('jS M, Y',  strtotime($end_date)); ?> </h4>
						</div>
					</div>
					<div class="col-xs-4 col-sm-4 col-md-4">
						<div class="receipt-left">
							<h1>Report</h1>
						</div>
					</div>
				</div>
            </div>

<table class="table table-striped table-bordered table-hover dataTable no-footer" id="datatable_products" aria-describedby="datatable_products_info" role="grid">
                                    <thead>
                                        <tr>
                                            <th>SN</th>
                                            <th>DATE TIME</th>
                                            <th>ORDER NO</th>
                                            <th>SUPPLIER NAME</th>
                                            <th>DELIVERY BRANCH</th>
                                            <th>ORDER STATUS</th>
                                            <th>CREATED BY</th>
                                            <th>APPROVED BY</th>
                                            <th>APPROVED DATE</th>
                                        </tr>
                                    </thead>
                                    <tbody>

                              <?php if($totalRows_rsodest>0){ 
								       $i=1;
            while ($row_rsodest = mysql_fetch_assoc($rsodest)){ ?>
            <tr>
                  <td height="23" valign="top" class="count"><span><?php echo $i; ?></span></td>
                  <td valign="top" style="cursor: pointer;"><?php echo strtoupper($row_rsodest['purchase_order_date']); ?></td>
                  <td valign="top" style="cursor: pointer;"><?php echo strtoupper($row_rsodest['purchase_order_no']); ?></td>
                  <td valign="top" style="cursor: pointer;"><?php echo strtoupper($row_rsodest['supplier_name']); ?></td>
                  <td valign="top" style="cursor: pointer;"><?php echo strtoupper($row_rsodest['deliver_to']); ?></td>
                  <td valign="top" style="cursor: pointer;"><?php echo strtoupper($row_rsodest['order_status']); ?></td>
                  <td valign="top" style="cursor: pointer;"><?php echo strtoupper($row_rsodest['user_name']); ?></td>
                  <td valign="top" style="cursor: pointer;"><?php echo strtoupper($row_rsodest['approved_by_user_name']); ?></td>
                  <td valign="top" style="cursor: pointer;"><?php echo date('jS M,Y',strtotime($row_rsodest['approved_date'])); ?></td>
            </tr>

<?php if($report_type == "tordi"){
	
	?>
                <tr>
                    <td colspan="8">
                        <div>
								<table class="table">
								<tr>
									<th>Date Time</th>
									<th>Item Name</th>
									<th>Unit Price</th>
									<th>Quantity</th>
									<th>Order Status</th>
									</tr>
									<tbody>
										<?php
											$rs = mysql_query("SELECT * FROM transfer_order_details WHERE purchase_order_no='".$row_rsodest['purchase_order_no']."'");
											while($r = mysql_fetch_assoc($rs)){ ?>
												<tr>
													<td><?php date('jS F,Y', strtotime($r['date_time'])); ?></td>
													<td><?php echo $r['item']; ?></td>
													<td><?php echo $r['unit_price']; ?></td>
													<td><?php echo $r['qty']; ?></td>
													<td><?php echo $r['order_status']; ?></td>
												</tr>
											<?php	} ?>
									</tbody>
								</table>
						</div>
                    </td>
                </tr>
				  <?php } ?>

                                         <?php $i++; } 
                                 } else { echo '<tr><td colspan="10" style="color:red;text-align:center;">No Records Found.</td></tr>'; } ?>
             </tbody>
                                </table>






</body>

</html>