<?php
ini_set('display_errors', 0);
//error_reporting(E_ALL);
//ini_set('display_errors', 1);

session_start();
ob_start();

require_once('configuration/server_connect.php');
require_once('configuration/all_function.php');

$active_id=$_REQUEST['active_id'];
$menu_id=$_REQUEST['menu_id'];

 // Common Information

$page_title="Products/Services Information";
$page="37_product_all.php";	


?>





<!DOCTYPE html>
<html lang="en">

<!-- ======= <head> ======= -->
 <?php require_once('inc_files/inc_head.php'); ?>
<!-- ======= </head> ======= -->



<script>



function getXMLHTTP() { //fuction to return the xml http object



		var xmlhttp=false;	



		try{



			xmlhttp=new XMLHttpRequest();



		}



		catch(e)	{		



			try{			



				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");

			}

			catch(e){



				try{



				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");



				}



				catch(e1){



					xmlhttp=false;



				}



			}



		}



		 	



		return xmlhttp;



    }



	function update_value(id)
	{

var item_id=id; // Rent


var sale_price=(document.getElementById('sale_price_'+id).value)*1;
var cost_price=(document.getElementById('cost_price_'+id).value)*1;


var strURL="37_product_all_ajax.php?item_id="+item_id+"&sale_price="+sale_price+"&cost_price="+cost_price;



		var req = getXMLHTTP();



		if (req) {



			req.onreadystatechange = function() {

				if (req.readyState == 4) {

					// only if "OK"

					if (req.status == 200) {						

						document.getElementById('divi_'+id).style.display='inline';

						document.getElementById('divi_'+id).innerHTML=req.responseText;						

					} else {

						alert("There was a problem while using XMLHTTP:\n" + req.statusText);

					}

				}				

			}

			req.open("GET", strURL, true);

			req.send(null);

		}	



}




function cal_all(id)

	{
var item_id=id; // Rent
var pack_size=(document.getElementById('pack_size_'+id).value)*1;
var sale_price=(document.getElementById('sale_price_'+id).value)*1; 

var bag_price=(document.getElementById('bag_price_'+id).value)=(pack_size*sale_price);

	}




</script>


<body>

  <!-- ======= Header ======= -->
  <?php require_once('inc_files/inc_header.php'); ?><!-- End Header -->

  <!-- ======= Sidebar ======= -->
  <?php  require_once('inc_files/inc_menu.php'); ?><!-- End Sidebar-->

  <main id="main" class="main">

    <div class="pagetitle">
      <h1><?php echo $page_title;?></h1>
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="home.php">Home</a></li>
          <li class="breadcrumb-item">Products &amp; Services</li>
          <li class="breadcrumb-item active"><?php echo $page_title;?></li>
        </ol>
      </nav>
    </div><!-- End Page Title -->
	
	
    <section class="section">
      <div class="row">
	  
	  
	  <div class="col-lg-12"> 

          <div class="card">
            <div class="card-body">
              <h5 class="card-title"><strong><?php echo $page_title;?></strong></h5>

              <!-- No Labels Form -->
              <form class="row g-3" action="" method="post" name="codz" id="codz">
                
       
                <div class="col-md-2">
                  <strong>Item Category</strong>
			
                </div>
                <div class="col-md-3">
                   <select id="item_category" name="item_category"  class="form-select" style="font-size:12px;" >
				   <option></option>
	
			<?php foreign_relation($conn,'item_category','id','item_category',$_POST['item_category'],'1 order by id');?>
		
        	</select>
                </div>
                
				<div class="col-md-2">
				 <button type="submit" class="btn btn-success rounded-pill btn-sm">&nbsp;<i class="bi bi-filter me-1"></i> Run Report&nbsp;&nbsp;</button>
				</div>
				
				<div class="col-md-3">&nbsp;</div>
				
				<div class="col-md-2" align="right">
				<a href="32_product_add.php?active_id=402&menu_id=4"><button type="button" class="btn btn-primary btn-sm"><i class="bi bi-plus-lg me-1"></i> New Item&nbsp;&nbsp;&nbsp;</button></a>
				</div>
                
              </form><!-- End No Labels Form -->

            </div>
          </div>
		
		</div>
        

        <div class="col-lg-12">

          <div class="card">
            <div class="card-body">
             
			 <br>
			  
			

              <!-- Multi Columns Form -->
             
			  
			  
			  
			  <table class="table table-sm" style="font-size:12px;">
                <thead>
                  <tr style="text-transform:uppercase; color:#012970; background:#f6f9ff;  border-top: 1px solid #CCCCCC;">
                    <th width="15%" scope="col">Category</th>
                    <th width="10%" scope="col">SKU CODE </th>
                    <th width="20%" scope="col">ITEM NAME</th>
                    <th width="10%" scope="col">Unit Name </th>
                    <th width="10%" scope="col">Unit price </th>
                    <th width="10%" scope="col">Cost Price </th>
                    <th width="5%" scope="col">Action</th>
                  </tr>
                </thead>
                <tbody>
		<?php
		
		$sql = "select id, item_type from item_type where 1 group by id";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $item_type[$info->id]=$info->item_type;
		}
		
		$sql = "select id, item_category from item_category where 1 group by id";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $item_category[$info->id]=$info->item_category;
		}
		
		
					
					if($_POST['item_type']!='')
					$con=" and item_type='".$_POST['item_type']."'";
					
					if($_POST['item_category']!='')
					$con=" and item_category='".$_POST['item_category']."'";
					
					
					
						$sql = 'select * from item_info where 1 '.$con.' order by item_type,item_category,item_id';
						$query = mysqli_query($conn,$sql);
						while ($data = mysqli_fetch_object($query)) {

					?>
				
                 <tr>
                   <td><?php echo $item_category[$data->item_category]?></td>
                   <td><?php echo $data->sku_code;?></td>
     			   <td><?php echo $data->item_name;?></td>
 				   <td><?php echo $data->unit_name;?>
				   			   </td>
 				   <td><input type="text" class="form-control" id="sale_price_<?php echo $data->item_id;?>" name="sale_price_<?php echo $data->item_id;?>" value="<?php echo $data->sale_price;?>" style="width:80%; height:30px;" onKeyUp="cal_all(<?php echo $data->item_id?>)"  ></td>
 				   <td><input type="text" class="form-control" id="cost_price_<?php echo $data->item_id;?>" name="cost_price_<?php echo $data->item_id;?>" value="<?php echo $data->cost_price;?>" style="width:80%; height:30px;" ></td>
                   <td><span id="divi_<?php echo $data->item_id?>">
				   <input class="form-control" type="button" name="Button" value="Update"  onclick="update_value(<?php echo $data->item_id?>)" 
				   style="width:100%; height:30px;background-color: #85c1e9;   font-weight:700; font-size:12px;"/></span></td>
                 </tr>
				  <?php }?>
                </tbody>
              </table>
                
				
		
			
				
				
				
                
		
			
            
                
                
                
              <!-- End Multi Columns Form -->

            </div>
          </div>

        </div>
		
		
		
		
      </div>
    </section>

  </main><!-- End #main -->

  <!-- ======= Footer ======= -->
 <?php require_once('inc_files/inc_footer.php'); ?>
<!-- ======= Footer ======= -->

</body>

</html>