<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<title>Sudila Printers</title>
<meta name="description" content="overview &amp; stats" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<!-- bootstrap & fontawesome -->
<link rel="stylesheet" href="assets/css/bootstrap.min.css" />
<link rel="stylesheet" href="assets/font-awesome/4.5.0/css/font-awesome.min.css" />
<!-- page specific plugin styles -->
<link rel="stylesheet" href="assets/css/chosen.min.css" />
<!-- text fonts -->
<link rel="stylesheet" href="assets/css/fonts.googleapis.com.css" />
<!-- ace styles -->
<link rel="stylesheet" href="assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style" />
<!--[if lte IE 9]>
    <link rel="stylesheet" href="assets/css/ace-part2.min.css" class="ace-main-stylesheet" />
<![endif]-->
<link rel="stylesheet" href="assets/css/ace-skins.min.css" />
<link rel="stylesheet" href="assets/css/ace-rtl.min.css" />
<link rel="stylesheet" href="assets/css/bootstrap-datepicker3.min.css" />
<link rel="stylesheet" href="assets/css/daterangepicker.min.css" />
<!--[if lte IE 9]>
  <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
<![endif]-->
<!-- inline styles related to this page -->
<!-- ace settings handler -->
<script src="assets/js/ace-extra.min.js"></script>
<!-- HTML5shiv and Respond.js for IE8 to support HTML5 elements and media queries -->
<!--[if lte IE 8]>
    <script src="assets/js/html5shiv.min.js"></script>
    <script src="assets/js/respond.min.js"></script>
<![endif]-->
</head>
<body class="no-skin">
<?php include 'common/navbar.php';
	if(isset($_GET['date']) && !empty($_GET['date'])) {
		$daterange = htmlspecialchars(strip_tags(trim($_GET['date'])), ENT_QUOTES, 'UTF-8');
		$date1 = substr($daterange, 0, 10);
		$date2 = substr($daterange, 13, 23);

	} else {
		$daterange = '';
		$date1 = $date2 = $date;
	}
	
	if(isset($_GET['item']) && !empty($_GET['item'])) {
		$item = htmlspecialchars(strip_tags(trim($_GET['item'])), ENT_QUOTES, 'UTF-8');

	} else {
		$item = 0;
	}
?>
<div class="main-container ace-save-state" id="main-container">
  <?php include 'common/sidebar.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">Home</a> </li>
          <li class="active">Stock Details Report</li>
        </ul>
        <!-- /.breadcrumb --> 
      </div>
      <div class="page-content">
        <div class="page-header">
          <h1> Stock Details Report </h1>
        </div>
        <!-- /.page-header -->
        <div class="row">
          <div class="col-xs-12"> 
            <!-- PAGE CONTENT BEGINS -->
            <div class="widget-box">
              <div class="widget-body">
                <div class="widget-main"> <br>
                  <!-- Content -->
				  <form id="form_submit" method="get">
					  <div class="form-group">
						<label>Select Date-range:<sup class="red">*</sup></label>
						<div class="input-group">
							<span class="input-group-addon">
								<i class="fa fa-calendar bigger-110"></i>
							</span>
							<input class="form-control" type="text" name="date" value="<?php echo $date1.' '.'-'.' '.$date2;?>" required>
						</div>
						<span class="help-block"></span>
					  </div>
					  <div class="form-group">
						<label>Select Item:<sup class="red">*</sup></label>
						<select class="chosen-select form-control" data-placeholder="Select Item..." name="item" required>
							<?php
							echo "<option></option>";
							$sql = "SELECT * FROM bookdetails ORDER BY name";
							$result = mysqli_query($conn, $sql);
							while ($row = mysqli_fetch_array($result)){ ?>
								<option value='<?php echo $row['id'] ?>' <?php if($row['id'] == $item) { echo 'selected'; } ?>><?php echo $row['name'] ?></option>
							<?php } ?>
						</select>
						<span class="help-block"></span>
					  </div>
					  <br>
					  <div class="form-group">
						<button class="btn btn-danger btn-sm"> SEARCH</button>
					  </div>
				  </form>
                  <!-- End Content --> 
                </div>
              </div>
            </div>
            <!-- /End .widget-box --> 
          </div>
        </div>
		<?php if(!empty($item) && !empty($daterange)) { ?>
        <div class="space-10"></div>
        <div class="row">
          <div class="col-xs-12">
            <div class="widget-box">
              <div class="widget-body">
                <div class="widget-main">
				<div class="page-header">
				  <h5 class="blue">Date: <?php echo $daterange; ?> </h5>
				  <h5 class="blue">Item: <?php $sql_itm = mysqli_fetch_assoc(mysqli_query($conn, "SELECT name FROM bookdetails WHERE id='$item'"));
				  echo $sql_itm['name']; ?> </h5>
				</div>
                  <div class="table-header"> Stock Details</div>
                  <!-- div.table-responsive --> 
                  <!-- div.dataTables_borderWrap -->
                  <div class="table-responsive">
                    <table id="dynamic-table" class="table table-striped table-bordered table-hover">
                      <thead>
                        <tr>
							<th>ID</th>
							<th>Date</th>
							<th>Type</th>
							<th>Invoice No</th>
							<th>Order No</th>
							<th>Debit Qty</th>
							<th>Credit Qty</th>
                        </tr>
                      </thead>
                      <tbody>
                        <?php
						$sql = mysqli_query($conn, "SELECT * FROM stock_details WHERE stock_card='$item' AND date BETWEEN '$date1' AND '$date2' ORDER BY date DESC");
						$x = $tot_drq = $tot_crq = 0;
						while ($row = mysqli_fetch_array($sql)) {
							$x++;
						?>
                        <tr>
                          <td><?php echo $x; ?>.</td>
                          <td><?php echo $row['date']; ?></td>
                          <td><?php echo $row['type']; ?></td>
                          <td><?php echo $row['invoice']; ?></td>
                          <td><?php echo $row['order_no']; ?></td>
                          <td><?php echo $drq = $row['dr_qty']; ?></td>
                          <td><?php echo $crq = $row['cr_qty']; ?></td>
                        </tr>
                        <?php $tot_drq += $drq; $tot_crq += $crq; } ?>
                      </tbody>
                    </table>
                  </div>
				  <hr>
				  <h5 class="blue">Total Debit Qty &nbsp;: <span class="red"><?php echo $tot_drq; ?></span></h5>
				  <h5 class="blue">Total Credit Qty : <span class="red"><?php echo $tot_crq; ?></span></h5>
				  <h5 class="blue">Total Balance &nbsp;&nbsp;&nbsp;&nbsp;: <span class="red"><?php echo ($tot_drq-$tot_crq); ?></span></h5>
                </div>
              </div>
            </div>
            <!-- PAGE CONTENT ENDS --> 
          </div>
          <!-- /.col --> 
        </div>
		<?php } ?>
        <!-- /.row --> 
      </div>
      <!-- /.page-content --> 
    </div>
  </div>
  <!-- /.main-content -->
  <?php include 'common/footer.php'; ?>
</div>
<!-- /.main-container -->

<!-- basic scripts --> 
<!--[if !IE]> -->
<script src="assets/js/jquery-2.1.4.min.js"></script>
<!-- <![endif]--> 
<!--[if IE]>
<script src="assets/js/jquery-1.11.3.min.js"></script>
<![endif]--> 
<script type="text/javascript">
	if('ontouchstart' in document.documentElement) document.write("<script src='assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
</script> 
<script src="assets/js/bootstrap.min.js"></script> 
<!-- page specific plugin scripts --> 
<!--[if lte IE 8]>
  <script src="assets/js/excanvas.min.js"></script>
<![endif]-->
<script src="assets/js/jquery.dataTables.min.js"></script>
<script src="assets/js/jquery.dataTables.bootstrap.min.js"></script>
<!-- ace scripts -->
<script src="assets/js/chosen.jquery.min.js"></script>
<script src="assets/js/ace-elements.min.js"></script>
<script src="assets/js/ace.min.js"></script>
<script src="assets/jquery.validate.min.js"></script>
<link rel="stylesheet" href="bootstrap-sweetalert/lib/sweet-alert.css" />
<script src="bootstrap-sweetalert/lib/sweet-alert.min.js"></script>
<script src="assets/js/bootstrap-datepicker.min.js"></script>
<script src="assets/js/moment.min.js"></script>
<script src="assets/js/daterangepicker.min.js"></script>
<!-- inline scripts related to this page --> 
<script type="text/javascript">
jQuery(function ($) {
	//initiate dataTables plugin
	var myTable =
	$('#dynamic-table')
	//.wrap("<div class='dataTables_borderWrap' />")   //if you are applying horizontal scrolling (sScrollX)
	.DataTable({
		bAutoWidth: false,
		"aaSorting": [],
	});
	
	$('input[name=date]').daterangepicker({
		'applyClass' : 'btn-xs btn-success',
		'cancelClass' : 'btn-xs btn-default',
		locale: {
			applyLabel: 'Apply',
			cancelLabel: 'Cancel',
			format: 'YYYY-MM-DD'
		},
	})
	.prev().on(ace.click_event, function(){
		$(this).next().focus();
	});
	
	if(!ace.vars['touch']) {
		$('.chosen-select').chosen({allow_single_deselect:true}); 
		//resize the chosen on window resize

		$(window)
		.off('resize.chosen')
		.on('resize.chosen', function() {
			$('.chosen-select').each(function() {
				 var $this = $(this);
				 $this.next().css({'width': $this.parent().width()});
			})
		}).trigger('resize.chosen');
		//resize chosen on sidebar collapse/expand
		$(document).on('settings.ace.chosen', function(e, event_name, event_val) {
			if(event_name != 'sidebar_collapsed') return;
			$('.chosen-select').each(function() {
				 var $this = $(this);
				 $this.next().css({'width': $this.parent().width()});
			})
		});
	}
});
</script>
</body>
</html>