<?php 
session_start();
 if(!isset($_SESSION['aid']))
 {
   	echo '<script>location.href="../index.php"</script>';
 }

include "../connection/config.php";

//for header
$clquery="select * from company";
$clex=mysqli_query($con,$clquery);
$clf=mysqli_fetch_assoc($clex);

$dateString=$expiry=$clf['expiry'];
$de = new DateTime($dateString);
$formattedDate = $de->format('d/m/Y');

$regdate=$clf['regdate'];
$date= date( 'Y-m-d' );
//for expiry day
$date1 = new DateTime($date);
$date2 = new DateTime($expiry);
$interval = $date1->diff($date2);
$days= $interval->format('%a days');

//get ip
$ipsql="select * from adminlog";
$ipexe=mysqli_query($con,$ipsql);
$ipf=mysqli_fetch_assoc($ipexe);

$category="select * from item_category";
$catexe=mysqli_query($con,$category);


$editflag= (isset($_REQUEST['flag']) ? strip_tags($_REQUEST['flag']): 0);
if ($editflag==2)
{
	$iidedit= (isset($_REQUEST['iid']) ? strip_tags($_REQUEST['iid']): 0);
	
$sd="select * from item_details where iid=$iidedit";
$sdex=mysqli_query($con,$sd);
$sdf = mysqli_fetch_assoc($sdex);

$itemname=$sdf['item_name']; 
$size=$sdf['size']; 
$color=$sdf['color'];
$material=$sdf['material'];
$price=$sdf['item_price'];
$image=$sdf['item_img'];  
$reorder_lvl=$sdf['item_reorder_lvl']; 
$item_unit=$sdf['item_unit'];  
$description=$sdf['item_description'];
$usg=$sdf['usefor'];
$categ=$sdf['cid'];  

$c=mysqli_query($con,"select * from item_category where cid='$categ'");
$cf=mysqli_fetch_assoc($c);
$cat=$cf['category']; 
}
?>

<html><head>


<script>
function printData()
{
   var divToPrint=document.getElementById("printTable");
   newWin= window.open("");
   newWin.document.write(divToPrint.outerHTML);
   newWin.print();
   newWin.close();
}

$('button').on('click',function(){
printData();
})
</script>

 <!--Automatic no-->
 <!-- <style type="text/css">
		body
		{
		    counter-reset: Serial;          
		}

		table
		{
		    border-collapse: separate;
		}

		tr td:first-child:before
		{
		  counter-increment: Serial;      
		  content: counter(Serial); 
		}
	</style> -->

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Admin Console</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
     <!-- DataTables -->
    <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="dist/css/style.css">
    <link rel="stylesheet" href="css/print.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script>
	function isNumeric(evt){
	 var charCode = (evt.which) ? evt.which : event.keyCode
	 if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46)
		return false;
	
	 return true;
	}

	</script>
	 <style>
         @font-face {
         font-family: "Kerala";
         src: url("KERALI_1.TTF") format("truetype"); 
    }
	</style>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  </head>
      
  <body class="skin-green  sidebar-mini">
    <!-- Site wrapper -->
    <div class="wrapper">
 
      <!-- =============================================== -->

      <!-- Left side column. contains the sidebar -->
      
<header class="main-header">

<div class="row" style="background-color:#4d6c9c; color:#E1EBEE; text-align:center">
<div class="col-md-12"  style="margin-top:10px; ">

<div class="col-md-2"><b style="font-size:20px; float:left;">Billing Software<span style="font-size:10px;">ver1.23</span></b></div>  

<div class="col-md-2">License To : <?php echo $clf['company']; ?> <span style="float:right;">|<span></div>

<div class="col-md-2">Left : <?php echo $days;  ?><span style="float:right;">|<span></div>

<div class="col-md-2">Expiry : <?php echo $formattedDate; ?> <span style="float:right;">|<span></div>

<div class="col-md-2">Powered By : PROGRAMERS Inc <span style="float:right;">|<span></div>

<div class="col-md-1"> Ip - <?php echo $ipf['ip']; ?> </div>
</div><div>

  </header>

<aside class="main-sidebar">
          <!-- sidebar: style can be found in sidebar.less -->
          <section class="sidebar" style="height: auto;">
          <!-- Sidebar user panel -->
          <div class="user-panel"></div>
         
          <ul class="sidebar-menu">
            <li class="treeview "> 
            <a href="home.php"><span>Home</span><i class="fa fa-angle-left pull-right"></i></a></li>
            <li class="treeview "> 
            <a href="#"><span>Master</span><i class="fa fa-angle-left pull-right"></i></a>
            <ul class="treeview-menu">
            <li class=""><a href="item_category.php">Item Category</a></li>
            <li class=""><a href="item_details.php">Item Details</a></li>
            <li class=""><a href="customer.php">Customer Details</a></li>
            </ul> </li> 

            <li class="treeview "> 
            <a href="#"><span>Transaction</span><i class="fa fa-angle-left pull-right"></i></a>
            <ul class="treeview-menu">
            <li class=""><a href="stock_input.php">Stock Input</a></li>
            <li class=""><a href="billing.php">Billing</a></li>
            <!-- <li class=""><a href="sales_return.php">Sales Return</a></li> -->
            </ul> </li> 

            <li class="treeview "> 
            <a href="#"><span>Reports</span><i class="fa fa-angle-left pull-right"></i></a>
            <ul class="treeview-menu">
            <li class=""><a href="item_report.php">Item List</a></li>  
            <li class=""><a href="sales_report.php">Sales Register</a></li>  
            <!-- <li class=""><a href="sales_return_report.php">Sales Return Register</a></li>   -->
            <li class=""><a href="stock_input_register.php">Stock Translation Register</a></li>   
            <li class=""><a href="stock_register.php">Stock Register</a></li>
            <li class=""><a href="stock_reorder.php">Item Reorder Register</a></li> 
            <li class=""><a href="dead_stock_register.php">Dead Stock Register</a></li>      
            </ul>
            </li> 
           
            <li class="treeview "> 
            <a href="#"><span>Settings</span><i class="fa fa-angle-left pull-right"></i></a>
            <ul class="treeview-menu">
            <li class=""><a href="company.php">Company Setup</a></li>  
            <li class=""><a href="password.php">Password Reset</a></li>  
            <li class=""><a href="logout.php">Logout</a></li>   
            </ul>
            </li> 

            </ul>
        </section>
        <!-- /.sidebar -->
      </aside>
      <!-- =============================================== -->

      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper" style="min-height: 700px;">
        <!-- Content Header (Page header) -->
        <section class="content-header"></section>
        <!-- Main content -->
        <section class="content">


		 <div class="row">

<!----------------------------------------------------------------- 2nd section--------------------------------------------------------------------------------------------------------->
              
      <div class="col-md-10" style="margin-left:110px;">
      <div class="box" id="box_edit">
      <img class="img-responsiv" alt="" src="public/assets/images/<?php echo $clf['logo']; ?>" width="250px">
      <!-- <div class="box-header with-border"><h3 class="box-title">Item Report</h3></div> -->
   
   <!-- search bar --->
  
   <form action="<?php $_SERVER['PHP_SELF']?>" method="post"> 

   <div class="col-md-12" style="margin-top:-60px;">
   <div class="col-md-2" style="margin-left:520px;">
    
   <input type="text" class="form-control" name="iid" placeholder="Code" style=" margin-left:10px;"> </div>


   <div class="col-md-2">
   <select class="form-control" name="category" style=" margin-left:10px;">
   <option value="">--Select Category--</option>
   <?php $cate=mysqli_query($con,"select * from item_category");
   while($fe=mysqli_fetch_assoc($cate)){ ?>
   <option value="<?php echo $fe['cid']; ?>"><?php echo $fe['category']; ?></option>     
   <?php } ?>
   </select>  </div>


   <div class="col-md-2">
   <button type="submit" name="search" style=" background:white; border-color:white; color:#4d6c9c;"><i class="fa fa-search" style="font-size:25px; "></i></button> 
   <button type="button" name="case_form" onclick="printData()" class="btn btn-info" style="background-color:#fff; border-color:#fff;"> <i class="fa fa-print" aria-hidden="true" style="color:#4d6c9c; font-size:25px; margin-top:-5px;"></i></button> </div>
  
  </div>
  </form>  
  
  <div class="box-header with-border" style="margin-top:-30px;"><h3 class="box-title">Item Report</h3></div>

<?php 
if(isset($_POST['search']))
{
  $iid=$_POST['iid'];
  $category=$_POST['category'];

  $searchquery="select * from item_details where iid='$iid' OR cid='$category' ";
  $searchexe=mysqli_query($con,$searchquery);
 
?>
 <style type="text/css">
		body
		{
		    counter-reset: Serial;          
		}

		table
		{
		    border-collapse: separate;
		}

		tr td:first-child:before
		{
		  counter-increment: Serial;      
		  content: counter(Serial); 
		}
	</style>
  <table id="printTable" class="table table-bordered table-striped" align="center">
      <thead>
      <tr style="background-color:#fff; color:#4d6c9c;">
          <th>#</th>
          <th> Category </th>
          <th> Code  </th>
          <th> Item </th>
          <th> Gender </th>
          <th> Size </th>
          <th> Material </th>
          <th> Color  </th>
          <th> Price </th>
          <th> Unit </th>
          <th> Description </th>
      </tr></thead>
      <tbody>
      <?php while($searchfetch=mysqli_fetch_assoc($searchexe)){ 
$cid = $searchfetch['cid'];       
$cidsq= mysqli_query($con,"select * from item_category where cid = $cid");
$cidfet = mysqli_fetch_assoc($cidsq) ;
        ?>

      <tr> 
            <td></td>
            <td><?php echo $cidfet['category'];?></td>
            <td><?php echo $searchfetch['iid'];?></td>
            <td><?php echo $searchfetch['item_name'];?></td>
            <td><?php echo $searchfetch['usefor'];?></td>  
            <td><?php echo $searchfetch['size'];?></td>
            <td><?php echo $searchfetch['material'];?></td>
            <td><?php echo $searchfetch['color'];?></td>
            <td><?php echo $searchfetch['item_price'];?></td>
            <td><?php echo $searchfetch['item_unit'];?></td>       
            <td><?php echo $searchfetch['item_description'];?></td>     
      </tr>  <?php } ?>                             
      </tbody>
      <tfoot></tfoot>
      </table>

<?php } 

else  
{  ?>
    <table id="printTable" class="table table-bordered table-striped" align="center">
    <thead>
    <tr style=" background-color:#fff; color:#4d6c9c;">
    <th>#</th>
    <th> Category </th>
    <th> Code  </th>
    <th> Item </th>
    <th> Gender </th>
    <th> Size </th>
    <th> Material </th>
    <th> Color  </th>
    <th> Price </th>
    <th> Unit </th>
    <th> Description </th>
    </tr>
    </thead>
    <tbody>
                            
<tr>  <?php

// PAGINATION
$num_per_page=15;
if(isset($_GET["page"]))
  {
$page=$_GET["page"];
  }
else 
  {
$page=1;
  }
 $start_from=($page-1) * 15;

// Display all datas
include "config1.php";
$sqli = "select * from item_details  order by iid desc limit $start_from,$num_per_page";
$stmt = $pdo->query($sqli);
$data = $stmt->fetchAll();
// Initialize counter
$serial = count($data);

foreach ($data as $billfetch) { 
  $cid= $billfetch['cid'];

$cidsq= mysqli_query($con,"select * from item_category where cid = $cid");
$cidfet = mysqli_fetch_assoc($cidsq) ;
  // $catsql=mysqli_query(
// )

?>
    <td><?php echo  $serial-- ?></td>
    <td><?php echo $cidfet['category']; ?></td>
    <td><?php echo $billfetch['iid']; ?></td>
    <td><?php echo $billfetch['item_name']; ?></td>
    <td><?php echo $billfetch['usefor'];?></td>  
    <td><?php echo $billfetch['size']; ?></td>
    <td><?php echo $billfetch['material']; ?></td>
    <td><?php echo $billfetch['color']; ?></td>
    <td><?php echo $billfetch['item_price']; ?></td>
    <td><?php echo $billfetch['item_unit']; ?></td>
    <td><?php echo $billfetch['item_description']; ?></td>
              </tr>
              <?php }  ?>                               
              </tbody>    <tfoot></tfoot>
             </table>  
<?php 

//number pagination code 
$sqlp="select * from item_details  order by iid desc";
$exep=mysqli_query($con,$sqlp);
 $total_records=mysqli_num_rows($exep);
//echo $total_records;
 $total_pages=ceil($total_records/$num_per_page);
//echo $total_pages;  
                       
for($i=1; $i<=$total_pages; $i++)
{
echo "<b><a href='item_report.php?page=".$i."' class='btn'>".$i."</a></b>"; echo " ";
}

} ?>
<div class="box" id="box_edit"  style="margin-top:10px;"></div>
           </div>
           </div>
<!--------------------------------------------------------------------------end 2nd section-------------------------------------------------------------------------->

</div>
</div> 
     
         <!-- /.box -->
        
        </section><!-- /.content -->
</div><!-- /.content-wrapper -->

  <footer class="main-footer"><strong>Copyright © 2023 <a href="javascript:void(0)">Perfect Uniform Llc</a></strong> All rights reserved.</footer>

    <!-- ./wrapper -->

    <!-- jQuery 2.1.4 -->
    <script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="bootstrap/js/bootstrap.min.js"></script>
    <!-- SlimScroll -->
    <script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <!-- FastClick -->
    <script src="plugins/fastclick/fastclick.min.js"></script>
    <!-- AdminLTE App -->
    <script src="dist/js/app.min.js"></script> 
 <!--<script>
 	function displayEdit(id)
	{
		$.ajax({
			type: "POST",
			url: "country_edit.php",
			data:{country_id: id},
			success: function(data){
				$('#box_edit').html(data);
			}
		});
	}
 </script>-->

</body></html>

