<?php session_start();
include('../accesscheck2.php');
require_once('../Connections/courier.php'); 
require_once '../functions/functions.php';
mysql_select_db($database_courier, $courier);
$report_type = $_GET['id'];

?>


<head>
        <meta charset="utf-8" />
        <title> Report Generation </title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta content="width=device-width, initial-scale=0" name="viewport" />
        <meta content="" name="description" />
        <meta content="" name="author" />
		<script src="../assets/global/plugins/jquery.min.js" type="text/javascript"></script>
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css" media="all" />
        <link href="../assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" media="all"/>
</head>
<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>



<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('MASTER STOCK REPORT'); ?> </h3>
                                                        <h5 class="text-danger"> BRANCHES : <?php if($report_type=='branch_stock'){ echo strtoupper($_SESSION['name_code']); }else{ echo 'ALL BRANCHES';} ?>  </h5>
						</div>
					</div>
					<div class="col-xs-4 col-sm-4 col-md-4">
						<div class="receipt-left">
							<h1>Report</h1>
						</div>
					</div>
				</div>
            </div>
		
               
<?php if($report_type == 'master_stock_report'){
	$report_qry = mysql_query("SELECT a.*,b.cost_price,b.quantity_available from service_items a INNER JOIN stock_items b ON a.id=b.item_id where a.service_type='Optical Frame';");
	$total_count = mysql_num_rows($report_qry);
	?>
			    <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>SN</th>
                            <th>Item Code</th>
                            <th>Item Name</th>
                            <th>Cost Price</th>
                            <th>Selling Price</th>
                            <th colspan="9" style="text-align:center;">QUANTITY AVAILABLE</th>
                        </tr>
                        <tr>
                            <th colspan="3"></th>
                            <th class="amount">GHS</th>
                            <th class="amount">GHS</th>
                            <th style="text-align:center;">ADABRAKA</th>
                            <th style="text-align:center;">DANQUAH</th>
                            <th style="text-align:center;">WEIJA</th>
                            <th style="text-align:center;">KUMASI</th>
                            <th style="text-align:center;">ADENTA</th>
                            <th style="text-align:center;">TEMA</th>
                            <th style="text-align:center;">AHODWO</th>
                            <th style="text-align:center;">EAST LEGON</th>
                            <th style="text-align:center;">MAIN STORE</th>
                            <th style="text-align:center;">TOTAL</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        if($total_count > 0){
                            $i=1;
                            while($row = mysql_fetch_assoc($report_qry)){ ?>
                        <tr>
                            <td class=""> <?php echo $i;?> </td>
                            <td class=""> <?php echo $row['ins_item_code'];?> </td>
                            <td class=""> <?php echo $row['item'];?> </td>
                            <td class="amount"><i class="fa fa-inr"></i> <?php echo number_format($row['cost_price'],2);?> </td>
                            <td class="amount"><i class="fa fa-inr"></i> <?php echo number_format($row['price_adabraka'],2);?> </td>
                            <td style="text-align:center;"><i class="fa fa-inr"></i> <?php echo $row['quantity_available_adabraka'];  $total_adabraka+=$row['quantity_available_adabraka']; ?> </td>
                            <td style="text-align:center;"><i class="fa fa-inr"></i> <?php echo $row['quantity_available_danquah']; $total_danquah+=$row['quantity_available_danquah']; ?> </td>
                            <td style="text-align:center;"><i class="fa fa-inr"></i> <?php echo $row['quantity_available_weija']; $total_weija+=$row['quantity_available_weija'];?> </td>
                            <td style="text-align:center;"><i class="fa fa-inr"></i> <?php echo $row['quantity_available_kumasi']; $total_kumasi+=$row['quantity_available_kumasi'];?> </td>
                            <td style="text-align:center;"><i class="fa fa-inr"></i> <?php echo $row['quantity_available_adenta']; $total_adenta+=$row['quantity_available_adenta'];?> </td>
                            <td style="text-align:center;"><i class="fa fa-inr"></i> <?php echo $row['quantity_available_tema']; $total_tema+=$row['quantity_available_tema'];?> </td>
                            <td style="text-align:center;"><i class="fa fa-inr"></i> <?php echo $row['quantity_available_ahodwo']; $total_ahodwo+=$row['quantity_available_ahodwo'];?> </td>
                            <td style="text-align:center;"><i class="fa fa-inr"></i> <?php echo $row['quantity_available_east_legon']; $total_east_legon+=$row['quantity_available_east_legon'];?> </td>
                            <td style="text-align:center;"><i class="fa fa-inr"></i> <?php echo $row['quantity_available']; $total_qty_available+=$row['quantity_available']; ?> </td>
							<td style="text-align:center;font-weight:bold !important;"><i class="fa fa-inr"></i> <?php 
									$total_stock = $row['quantity_available_adabraka']+$row['quantity_available_danquah']+$row['quantity_available_weija']+$row['quantity_available_kumasi']+$row['quantity_available_adenta']+$row['quantity_available_tema']+$row['quantity_available_ahodwo']+$row['quantity_available_east_legon']+$row['quantity_available'];
									echo $total_stock;
									 ?> 
							 </td>
                        </tr>
                        <?php $i++; }  ?>
						<tr>
							<td colspan="5">TOTAL</td>
							<td style="text-align:center;"><i class="fa fa-inr"></i><?php echo $total_adabraka; ?></td>
							<td style="text-align:center;"><i class="fa fa-inr"></i><?php echo $total_danquah; ?></td>
							<td style="text-align:center;"><i class="fa fa-inr"></i><?php echo $total_weija; ?></td>
							<td style="text-align:center;"><i class="fa fa-inr"></i><?php echo $total_kumasi; ?></td>
							<td style="text-align:center;"><i class="fa fa-inr"></i><?php echo $total_adenta; ?></td>
							<td style="text-align:center;"><i class="fa fa-inr"></i><?php echo $total_tema; ?></td>
							<td style="text-align:center;"><i class="fa fa-inr"></i><?php echo $total_ahodwo; ?></td>
							<td style="text-align:center;"><i class="fa fa-inr"></i><?php echo $total_east_legon; ?></td>
							<td style="text-align:center;"><i class="fa fa-inr"></i><?php echo $total_qty_available; ?></td>
							</tr>
                        <?php }else{ ?>
                        <tr><td colspan="7" style="text-align: center;">No Records Found</td></tr>
                         <?php } ?>
                    </tbody>
                </table>
						<?php } 


if($report_type == 'master_frames_range'){ ?>
				<table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>SN</th>
                            <th>PRICE RANGE (GHS)</th>
                            <th style="text-align:center;">ADABRAKA</th>
                            <th style="text-align:center;">DANQUAH</th>
                            <th style="text-align:center;">WEIJA</th>
                            <th style="text-align:center;">KUMASI</th>
                            <th style="text-align:center;">ADENTA</th>
                            <th style="text-align:center;">TEMA</th>
                            <th style="text-align:center;">AHODWO</th>
                            <th style="text-align:center;">EAST LEGON</th>
                            <th style="text-align:center;">MAIN STORE</th>
                            <th style="text-align:center;">TOTAL</th>
                        </tr>
                    </thead>
                    <tbody>
					
					<?php
						$price_range = array('0-200','201-400','401-600','601-800','801-1000','1001-2000','2001-3500','3501-100000');
						$i=1;
						foreach($price_range AS $price){
							list($lower_price, $upper_price) = explode('-',$price);
							// $qry_price_range = mysql_query("SELECT SUM() FROM service_items WHERE service_type='Optical Frame' AND price_adabraka BETWEEN $lower_price AND $upper_price;");
							$qry_price_range = mysql_query("SELECT SUM(quantity_available_adabraka) AS adabraka,SUM(quantity_available_danquah) AS danquah,SUM(quantity_available_weija) AS weija,SUM(quantity_available_kumasi) AS kumasi,SUM(quantity_available_adenta) AS adenta,SUM(quantity_available_tema) AS tema,SUM(quantity_available_ahodwo) AS ahodwo,SUM(quantity_available_east_legon) AS east_legon,SUM(quantity_available) AS main_stock FROM service_items a INNER JOIN stock_items b ON a.id=b.item_id where a.service_type='Optical Frame' AND price_adabraka BETWEEN $lower_price AND $upper_price;");
							$row = mysql_fetch_assoc($qry_price_range);?>
								<tr style="cursor:pointer;" onclick="$('.details_<?php echo str_replace("-","_",$price);?>').slideToggle();">
									<td><?php echo $i;?></td>
									<td style="font-weight:bold !important;"><?php  if($price=='0-200'){echo 'UP TO 200';} else if($price=='3501-100000'){echo '3501 UPWARDS';}else{echo $price;}?></td>
									<td style="font-weight:bold !important;"><?php echo $row['adabraka']; ?></td>
									<td style="font-weight:bold !important;"><?php echo $row['danquah']; ?></td>
									<td style="font-weight:bold !important;"><?php echo $row['weija']; ?></td>
									<td style="font-weight:bold !important;"><?php echo $row['kumasi']; ?></td>
									<td style="font-weight:bold !important;"><?php echo $row['adenta']; ?></td>
									<td style="font-weight:bold !important;"><?php echo $row['tema']; ?></td>
									<td style="font-weight:bold !important;"><?php echo $row['ahodwo']; ?></td>
									<td style="font-weight:bold !important;"><?php echo $row['east_legon']; ?></td>
									<td style="font-weight:bold !important;"><?php echo $row['main_stock']; ?></td>
									<td style="font-weight:bold !important;"><?php
											$total_qty = $row['adabraka']+$row['danquah']+$row['weija']+$row['kumasi']+$row['adenta']+$row['tema']+$row['ahodwo']+$row['east_legon']+$row['main_stock'];
											echo $total_qty;
											$total_qty=0;
									?></td>
								</tr>
								<tr class="details_<?php echo str_replace("-","_",$price);?>" style="display:none;">
									<td class="details_<?php echo str_replace("-","_",$price);?>" colspan="11" style="display:none;">
										<div class="details_<?php echo str_replace("-","_",$price);?>" style="display:none;">
									<?php
										$list_items = mysql_query("SELECT a.item,price_adabraka,quantity_available_adabraka AS adabraka,quantity_available_danquah AS danquah,quantity_available_weija AS weija,quantity_available_kumasi AS kumasi,quantity_available_adenta AS adenta,quantity_available_tema AS tema,quantity_available_ahodwo AS ahodwo,quantity_available_east_legon AS east_legon,quantity_available AS main_stock FROM service_items a INNER JOIN stock_items b ON a.id=b.item_id where a.service_type='Optical Frame' AND price_adabraka BETWEEN $lower_price AND $upper_price;");?>
										
										<table class="table table-bordered">
										<thead>
                        					<tr>
                            					<th>Item Name</th>
                            					<th>Item Price (GHS)</th>
                            					<th>ADABRAKA</th>
                            					<th>DANQUAH</th>
                            					<th>WEIJA</th>
                            					<th>KUMASI</th>
                            					<th>ADENTA</th>
                            					<th>TEMA</th>
                            					<th>AHODWO</th>
                            					<th>EAST LEGON</th>
                            					<th>MAIN STOCK</th>
                            					<th>TOTAL</th>
											</tr>
										</thead>
										<?php while($r=mysql_fetch_assoc($list_items)){ ?>
											<tr>
												<td><?php echo $r['item']; ?></td>
												<td style="font-weight:bold !important;"><?php echo number_format($r['price_adabraka'],2); ?></td>
												<td style="font-weight:bold !important;"><?php echo $r['adabraka']; $total1_adabraka+=$row['adabraka'];?></td>
												<td style="font-weight:bold !important;"><?php echo $r['danquah']; $total1_danquah+=$row['danquah'];?></td>
												<td style="font-weight:bold !important;"><?php echo $r['weija']; $total1_weija+=$row['weija'];?></td>
												<td style="font-weight:bold !important;"><?php echo $r['kumasi']; $total1_kumasi+=$row['kumasi'];?></td>
												<td style="font-weight:bold !important;"><?php echo $r['adenta']; $total1_adenta+=$row['adenta'];?></td>
												<td style="font-weight:bold !important;"><?php echo $r['tema']; $total1_tema+=$row['tema'];?></td>
												<td style="font-weight:bold !important;"><?php echo $r['ahodwo']; $total1_ahodwo+=$row['ahodwo'];?></td>
												<td style="font-weight:bold !important;"><?php echo $r['east_legon']; $total1_east_legon+=$row['east_legon'];?></td>
												<td style="font-weight:bold !important;"><?php echo $r['main_stock']; $total1_main_stock+=$row['main_stock'];?></td>
												<td style="font-weight:bold !important;"><?php
												$total_qty = $r['adabraka']+$r['danquah']+$r['weija']+$r['kumasi']+$r['adenta']+$r['tema']+$r['ahodwo']+$r['east_legon']+$r['main_stock'];
												echo $total_qty;
												$total_qty=0;
									?></td>
											</tr>
										<?php  } ?>
										<tr> <td colspan="2">TOTAL</td>
											<td style="font-weight:bold !important;"><?php echo $total1_adabraka ?></td>
											<td style="font-weight:bold !important;"><?php echo $total1_danquah ?></td>
											<td style="font-weight:bold !important;"><?php echo $total1_weija ?></td>
											<td style="font-weight:bold !important;"><?php echo $total1_kumasi ?></td>
											<td style="font-weight:bold !important;"><?php echo $total1_adenta ?></td>
											<td style="font-weight:bold !important;"><?php echo $total1_tema ?></td>
											<td style="font-weight:bold !important;"><?php echo $total1_ahodwo ?></td>
											<td style="font-weight:bold !important;"><?php echo $total1_east_legon ?></td>
											<td style="font-weight:bold !important;"><?php echo $total1_main_stock ?></td>
										</tr>
										</table>
										</div>
									</td>
								</tr>
							<?php $i++; } ?>
					</tbody>
					</table>
				<?php }  
			
if($report_type == 'branch_stock'){
$report_qry = mysql_query("SELECT a.*,b.cost_price,b.quantity_available from service_items a INNER JOIN stock_items b ON a.id=b.item_id where a.service_type='Optical Frame';");
$total_count = mysql_num_rows($report_qry);?>

<table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>SN</th>
                            <th>Item Code</th>
                            <th>Item Name</th>
                            <th>Selling Price</th>
                            <th colspan="9" style="text-align:center;">QUANTITY AVAILABLE</th>
                        </tr>
                        <tr>
                            <th colspan="3"></th>
                            <th class="amount">GHS</th>
                            <th style="text-align:center;"><?php echo strtoupper($_SESSION['name_code']); ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        if($total_count > 0){
                            $i=1;
                            while($row = mysql_fetch_assoc($report_qry)){ ?>
                        <tr>
                            <td class=""> <?php echo $i;?> </td>
                            <td class=""> <?php echo $row['ins_item_code'];?> </td>
                            <td class=""> <?php echo $row['item'];?> </td>
                            <td class="amount"><i class="fa fa-inr"></i> <?php echo number_format($row['price_'.$_SESSION['name_code']],2);?> </td>
                            <td style="text-align:center;"><i class="fa fa-inr"></i> <?php echo $row['quantity_available_'.$_SESSION['name_code']];?> </td>
                        </tr>
                        <?php $i++; }  ?>
                        <?php }else{ ?>
                        <tr><td colspan="7" style="text-align: center;">No Records Found</td></tr>
                         <?php } ?>
                    </tbody>
                </table>
			
			
			<?php } ?>
			
        </div>    
	</div>
</div>
