<?php 
	$header_file=APPPATH.'views/include/header.php';
	require($header_file);
	
	?>

    <!-- BEGIN: Content-->
    <div class="app-content content">
      <div class="content-overlay"></div>
      <div class="content-wrapper">
        <div class="content-header row">
          <div class="content-header-left col-md-12 col-12 mb-2 breadcrumb-new">
            <h3 class="content-header-title mb-0 d-inline-block">Stock Ledger</h3>
            <div class="row breadcrumbs-top d-inline-block">
              <div class="breadcrumb-wrapper col-12">
                <ol class="breadcrumb">
                  <li class="breadcrumb-item"><a href="#">Home</a>
                  </li>
                  <li class="breadcrumb-item"><a href="#">Stock Management</a>
                  </li>
                  <li class="breadcrumb-item active">Stock Ledger
                  </li>
                </ol>
              </div>
            </div>
          </div>
        
        </div>
        <div class="content-body"><!-- Zero configuration table -->
<section id="configuration">
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                
                <div class="card-content collapse show">
                    <div class="card-body card-dashboard">
                       
                       
							<form method="post" autocomplete="off" action="<?php echo site_url('StockManagement/searchStockLedger/');?>" method="POST">
                        	<div class="row justify-content-md-center card_margin">
							
								<div class="col-md-3">
									<div class="form-group">
										<input class="form-control pickadate datepicker picker__input picker__input--active" type="text" name="from_date"  id="from_date" required data-uk-datepicker="{format:'DD-MM-YYYY'}" placeholder="From Date">
									</div>
								</div>
								<div class="col-md-3">
									<div class="form-group">
										<input class="form-control pickadate datepicker picker__input picker__input--active" type="text" name="to_date"  id="to_date" required data-uk-datepicker="{format:'DD-MM-YYYY'}" placeholder="To Date">
									</div>
								</div>
								<div class="col-md-3">
									<div class="form-group">
										<select id="item_name" name="item_name" class="select2" >
											<option value="">Select Item</option>
											<?php  foreach($items as $row)
												{
											?>
												<option value="<?php echo $row->item_name; ?>"><?php echo $row->item_name; ?></option>
											<?php
												} 
											?>
										</select>
									</div>
								</div>
								<div class="col-md-3">
									<div class="form-group">
										<input type="submit" name="submit" class="btn btn-primary" value="Stock Ledger">
									</div>
								</div>
							
						</div>
						</form>
						<br/>
						 <div class="table-responsive">
						<?php
				if(isset($_POST['submit'])) {
					 
					if (isset($result_display)) {
						//echo "<p><u>Result</u></p>";
						if ($result_display == 'No record found !') {
							echo $result_display;
							} else {
						?>
						<?php if($_POST['from_date']!="" && $_POST['to_date']!="" && $_POST['item_name']!=""){ ?>
                           <!--     <form method="post" autocomplete="off" action="<?php //echo site_url('StockManagement/exportStockLedger/');?>" method="POST">-->
                            <div class="row justify-content-md-center">
							
								<div class="col-md-3">
									<div class="form-group">
										<input class="form-control" type="text" name="fdate"  id="fdate" value="<?php echo $_POST['from_date']?>" readonly>
									</div>
								</div>
								<div class="col-md-3">
									<div class="form-group">
										<input class="form-control" type="text" name="tdate"  id="tdate" value="<?php echo $_POST['to_date']?>" readonly>
									</div>
								</div>
								<div class="col-md-3">
									<div class="form-group">
										<input class="form-control" type="text" name="iname"  id="iname" value="<?php echo $_POST['item_name']?>" readonly>
										<?php 
											$branchname = $_SESSION['branch_name']; 
											?>
									</div>
								</div>
								<div class="col-md-3">
									<div class="form-group">
								<!--	<input type="submit" name="submit_export" class="btn btn-primary" value="Export Report">-->
										<button onclick="method(btn)" class="btn btn-info">Export to Excel</button>
									</div>
								</div>
						    </div>
					<!--	</form>-->
								 <table id="tableID" class="table table-bordered dataex-html5-export">
						<thead>
						    
						    <tr>
						        <th>Sl No</th>
						        <th>Date</th>
    							<th>Transactions</th>
    							<th>Opening Stock</th>
    							<th>Inward</th>
    							<th>Outward</th>
    							<th>Closing Stock</th>
						    </tr>
						</thead>
						<tbody>
							<?php 
							if(isset($result_display) && is_array($result_display) && count($result_display)): $i=1;
							foreach ($result_display as $data) { 
								
								
							?>
								<tr>
								    <td><?php echo $i; ?></td>
									<td><?php echo $data['trans_date']; ?></td>
									<td><?php echo $data['trans_ref_no']; ?></td>
									<td><?php echo $data['opening_stock']; ?></td>
									<td><?php echo $data['in_qty']; ?></td>
									<td><?php echo $data['out_qty']; ?></td>
									<td><?php echo $data['closing_stock']; ?></td>
								</tr>
													
								<?php
									$i++;
									} ?>
									<?php else:
								?>
								<tr>
									<td colspan="8" align="center" >No Records Found..</td>
								</tr>
								<?php
									endif;
								?>
						</tbody>
					</table>

						
						<?php }
					} }
				} ?>
					    </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<!--/ Zero configuration table -->



<!--/ Language - Comma decimal place table -->

        </div>
      </div>
    </div>
    <!-- END: Content-->

   <?php //require('include/theme_customizer.php');?>
 <?php 
  $footer_file=APPPATH.'views/include/footer.php';
	require($footer_file);
	?>
<script>
	$('.param_check').each(function() { $(this).on( {'click contextmenu': function() {
		//contextmenu
		var i = $(this).data('value');
		var anchor = $("a");
		var anchorTarget = $(this).parent().find('.parmetre').val();
		var submodid = $(this).parent().find('.submod_id').val();
		var link = $(this).attr('href');
		$(this).attr("href", link + submodid +'/'+anchorTarget);

		location.reload();
	}
	})
	})
</script>  
<script type="text/javascript">
	var btn='NewReport';
</script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js_pdf/tableToExcel.js"></script>
<script type="text/javascript">
	function method(s) {
	//alert(s);
	//tableToExcel('table', s);
	tableToExcel('tableID', s);
	}
</script>