<?PHP
ob_start();
session_start();
include 'connect.php';
if(isset($_SESSION['adminemail']))
{
$user=$_SESSION['adminemail'];

$gtp=mysql_query("select * from admin where username='$user'");
$gtp1=mysql_fetch_array($gtp);

include 'top.php';
?>



<div class="main-content">
				<div class="main-content-inner">
					<div class="breadcrumbs ace-save-state" id="breadcrumbs">
						<ul class="breadcrumb">
							<li>
								<i class="ace-icon fa fa-home home-icon"></i>
								<a href="#">Home</a>
							</li>
							<li class="active">Production</li>
						</ul><!-- /.breadcrumb -->
					</div>

					<div class="page-content">
			

						<div class="page-header">
                        
<?php

$aca=mysql_query("select * from financial where user='$user' order by ID desc");
$aca1=mysql_fetch_array($aca);

$financial=$aca1['financial'];

?>
                        
                        <table style="width:100%;">
                        
                        <tr><td style="width:50%;">

                        
							<h1>
								Production
							</h1>
                            
                            </td>
                            
                            <td style="width:50%; text-align:right; padding-right:15px; font-size:15px;">
                            
                            <i class="fa fa-calendar"></i>&nbsp; <?php echo $financial; ?>
                            
                            </td></tr></table>
                            
						</div><!-- /.page-header -->
<br />

						<div class="row">
							<div class="col-xs-12">
                            
								<!-- PAGE CONTENT BEGINS -->

<script src="assets/js/jquery.js"></script>

<script>

  $(".bank").live('change',function()
		  {
		  var bank=$(this).val();
		  var dataString = 'bank='+ bank;
		  //alert(dataString);
		  $.ajax
		  ({
		  type: "GET",
		  url: "getacc.php",
		  data: dataString,
		  cache: false,
		  success: function(resp)
		  {
		  //alert(resp);
		  //var company=$(resp).filter('#company').text();
		  //alert(company);
		  $('.account').html($('#account',resp).html());
		  }
		  });
		  });
		  
</script>

<script>
	
jQuery(function($){
		   
	// simple jQuery validation script
	$('#work').submit(function(){
		
		var valid = true;
		var errormsg = 'This field is required!';
		var errorcn = 'error';
		
		$('.' + errorcn, this).remove();			
		
		$('#required', this).each(function(){
			var parent = $(this).parent();
			if( $(this).val() == '' ){
				var msg = $(this).attr('title');
				msg = (msg != '') ? msg : errormsg;
				$('<span style="font-size:13px;color:#FF0000; padding-left:3px;" class="'+ errorcn +'">'+ msg +'</span>')
					.appendTo(parent)
					.fadeIn('fast')
					.click(function(){ $(this).remove(); });
				valid = false;
			};
		});
		
		return valid;
	});
	
});	

</script>

<?php

	if(isset($_GET['s'])) 
	{
	 $status=$_GET['s'];
		 if($status=='3')
		 {
		 echo '<div class="alert alert-success">
				<a class="close" data-dismiss="alert">x</a>
					Production Edited Successfully.
			  </div>';
		 }
		 elseif($status=='7')
		 {
		 echo '<div class="alert alert-success">
				<a class="close" data-dismiss="alert">x</a>
					Production Deleted Successfully.
			  </div>';
		 }
		 elseif($status=='4')
		 {
		 echo '<div class="alert alert-error">
				<a class="close" data-dismiss="alert">x</a>
					Values not edited. Try again.
			  </div>';
		 }		
	}
	
	
if(isset($_GET['submit']))
{
	
	$fromdate=$_GET['fromdate'];
	$todate=$_GET['todate'];
	
	$frm=date('Y-m-d',strtotime($fromdate));
	$tod=date('Y-m-d',strtotime($todate));
	
	echo"<center><b>Report From ".$fromdate." to ".$todate."</b></center><br />";
	
	echo'<table id="dynamic-table" class="table table-striped table-bordered table-hover">
<thead><tr><th rowspan="2" style="width:8%;">P.No</th><th rowspan="2" style="width:12%;">Date</th><th colspan="2">Input</th><th colspan="2">Output</th></tr>
<tr><th style="width:20%;">Product</th><th style="width:10%;">Qty</th><th style="width:20%;">Product</th><th style="width:10%;">Qty</th></tr></thead>';

$prod=mysql_query("select * from production where date between '$frm' and '$tod' group by pno order by pno asc");
while($prod1=mysql_fetch_array($prod))
{

echo"<tr><td>".$prod1['pno']." <a href='editproduction.php?id=".$prod1['pno']."'><i class='ace-icon fa fa-pencil bigger-100 green'></i></a> &nbsp; <a href='del.php?id=".$prod1['pno']."&desc=production'><i class='ace-icon fa fa-trash bigger-100 red'></i></a></td><td>".date('d-m-Y',strtotime($prod1['date']))."</td><td style='padding:0;'>

<table style='width:100%; height:100%;'>";

$sprod=mysql_query("select * from production where pno='$prod1[pno]'");
$nrs=mysql_num_rows($sprod);
$rw=0;
while($sprod1=mysql_fetch_array($sprod))
{
$rw=$rw+1;

$pnm=mysql_query("select * from product where ID='$sprod1[input_product]'");
$pnm1=mysql_fetch_array($pnm);

if($rw==$nrs)
{
echo"<tr><td style='padding:4px 3px;'>".$pnm1['product']."</td></tr>";
}
else
{
echo"<tr><td style='border-bottom:1px solid #ddd; padding:4px 3px;'>".$pnm1['product']."</td></tr>";
}

}

echo"</table>

</td><td style='padding:0;'>

<table style='width:100%; height:100%;'>";

$sprod=mysql_query("select * from production where pno='$prod1[pno]'");
$nrs=mysql_num_rows($sprod);
$rw=0;
while($sprod1=mysql_fetch_array($sprod))
{
$rw=$rw+1;
	
if($rw==$nrs)
{
echo"<tr><td style='padding:4px 3px;'>".$sprod1['input_qty']."</td></tr>";
}
else
{
echo"<tr><td style='border-bottom:1px solid #ddd; padding:4px 3px;'>".$sprod1['input_qty']."</td></tr>";
}

}

echo"</table>

</td><td style='padding:0;'>

<table style='width:100%; height:100%;'>";

$sprod=mysql_query("select * from production where pno='$prod1[pno]'");
$nrs=mysql_num_rows($sprod);
$rw=0;
while($sprod1=mysql_fetch_array($sprod))
{
$rw=$rw+1;

$pnm=mysql_query("select * from product where ID='$sprod1[output_product]'");
$pnm1=mysql_fetch_array($pnm);

if($rw==$nrs)
{
echo"<tr><td style='padding:4px 3px;'>".$pnm1['product']."</td></tr>";
}
else
{
echo"<tr><td style='border-bottom:1px solid #ddd; padding:4px 3px;'>".$pnm1['product']."</td></tr>";
}

}

echo"</table>

</td><td style='padding:0;'>

<table style='width:100%; height:100%;'>";

$sprod=mysql_query("select * from production where pno='$prod1[pno]'");
$nrs=mysql_num_rows($sprod);
$rw=0;
while($sprod1=mysql_fetch_array($sprod))
{
$rw=$rw+1;

if($rw==$nrs)
{
echo"<tr><td style='padding:4px 3px;'>".$sprod1['output_qty']."</td></tr>";
}
else
{
echo"<tr><td style='border-bottom:1px solid #ddd; padding:4px 3px;'>".$sprod1['output_qty']."</td></tr>";
}

}

echo"</table>

</td></tr>";
	
}

echo'</table><br />

<center><a href="viewproduction.php">Back</a></center>';
	
}
else
{
	
	
echo"<center>

	<form action='viewproduction.php' method='get' id='wrk'>

	<table>	

	<tr><td>From Date : <input type='text' name='fromdate' class='fromdate' id='required' title='*' /></td>	

	<td style='padding-left:15px;'>To Date : <input type='text' name='todate' class='todate' id='required' title='*' /></td></tr>	

	</table>

	<br>

	<button type='submit' name='submit' value='submit' class='btn btn-sm btn-primary'>Submit</button><br>	

	</form>

</center><br>";


echo'<table style="width:99%; margin:auto;">
                                        
                                        <tr><td style="width:20%;">
                                        <a href="production.php"><button class="btn btn-minier btn-info">+ Add New</button></a>
                                        </td>
                                        
                                        <td style="width:50%;"></td>
                                        
                                        <td style="width:30%;">
                                        <div class="clearfix" style="padding-top:5px;">
											<div class="pull-right tableTools-container"></div>
										</div>
                                        </td>
                                        
                                        </tr>
                                        
                                        </table>';

echo'<table id="dynamic-table" class="table table-striped table-bordered table-hover">
<thead><tr><th rowspan="2" style="width:8%;">P.No</th><th rowspan="2" style="width:12%;">Date</th><th colspan="2">Input</th><th colspan="2">Output</th></tr>
<tr><th style="width:20%;">Product</th><th style="width:10%;">Qty</th><th style="width:20%;">Product</th><th style="width:10%;">Qty</th></tr></thead>';

$prod=mysql_query("select * from production where date between '$aca1[fromdate]' and '$aca1[todate]' group by pno order by pno asc");
while($prod1=mysql_fetch_array($prod))
{

echo"<tr><td>".$prod1['pno']." <a href='editproduction.php?id=".$prod1['pno']."'><i class='ace-icon fa fa-pencil bigger-100 green'></i></a> &nbsp; <a href='del.php?id=".$prod1['pno']."&desc=production'><i class='ace-icon fa fa-trash bigger-100 red'></i></a></td><td>".date('d-m-Y',strtotime($prod1['date']))."</td><td style='padding:0;'>

<table style='width:100%; height:100%;'>";

$sprod=mysql_query("select * from production where pno='$prod1[pno]'");
$nrs=mysql_num_rows($sprod);
$rw=0;
while($sprod1=mysql_fetch_array($sprod))
{
$rw=$rw+1;

$pnm=mysql_query("select * from product where ID='$sprod1[input_product]'");
$pnm1=mysql_fetch_array($pnm);

if($rw==$nrs)
{
echo"<tr><td style='padding:4px 3px;'>".$pnm1['product']."</td></tr>";
}
else
{
echo"<tr><td style='border-bottom:1px solid #ddd; padding:4px 3px;'>".$pnm1['product']."</td></tr>";
}

}

echo"</table>

</td><td style='padding:0;'>

<table style='width:100%; height:100%;'>";

$sprod=mysql_query("select * from production where pno='$prod1[pno]'");
$nrs=mysql_num_rows($sprod);
$rw=0;
while($sprod1=mysql_fetch_array($sprod))
{
$rw=$rw+1;
	
if($rw==$nrs)
{
echo"<tr><td style='padding:4px 3px;'>".$sprod1['input_qty']."</td></tr>";
}
else
{
echo"<tr><td style='border-bottom:1px solid #ddd; padding:4px 3px;'>".$sprod1['input_qty']."</td></tr>";
}

}

echo"</table>

</td><td style='padding:0;'>

<table style='width:100%; height:100%;'>";

$sprod=mysql_query("select * from production where pno='$prod1[pno]'");
$nrs=mysql_num_rows($sprod);
$rw=0;
while($sprod1=mysql_fetch_array($sprod))
{
$rw=$rw+1;

$pnm=mysql_query("select * from product where ID='$sprod1[output_product]'");
$pnm1=mysql_fetch_array($pnm);

if($rw==$nrs)
{
echo"<tr><td style='padding:4px 3px;'>".$pnm1['product']."</td></tr>";
}
else
{
echo"<tr><td style='border-bottom:1px solid #ddd; padding:4px 3px;'>".$pnm1['product']."</td></tr>";
}

}

echo"</table>

</td><td style='padding:0;'>

<table style='width:100%; height:100%;'>";

$sprod=mysql_query("select * from production where pno='$prod1[pno]'");
$nrs=mysql_num_rows($sprod);
$rw=0;
while($sprod1=mysql_fetch_array($sprod))
{
$rw=$rw+1;

if($rw==$nrs)
{
echo"<tr><td style='padding:4px 3px;'>".$sprod1['output_qty']."</td></tr>";
}
else
{
echo"<tr><td style='border-bottom:1px solid #ddd; padding:4px 3px;'>".$sprod1['output_qty']."</td></tr>";
}

}

echo"</table>

</td></tr>";
	
}

echo'</table>';

}

?>                                
                               
								

								<!-- PAGE CONTENT ENDS -->
							</div><!-- /.col -->
						</div><!-- /.row -->
					

</div><!-- /.page-content -->
				</div>
			</div><!-- /.main-content -->


<?php
include 'bottom.php';
}
else
{

 header("location:login.php");
}
ob_flush();
?>