<?php 
    require_once ("../var/res.php");
    
    if(isset($_GET['typeid'])){
        $a=$_GET['typeid'];
        $sql= "SELECT * FROM tbl_items i
        INNER JOIN tbl_units u ON u.unit_id=i.iUnit
        WHERE itype='".$a."' ";
        $stmt = $conn->query($sql);
        $num = $stmt->rowCount();
        if($num>0){?>
        <option></option>
        <?php
    	while ($row = $stmt->fetch()) { 
    	?>
        <option value="<?php echo $row['item_id'];?>"><?php echo $row['item_name']." [".$row['unit_name']."]";?></option>
       <?php 
    	}  
    }
 }

 if(isset($_GET['ctgid'])){
    $c=$_GET['ctgid'];
    $sql= "SELECT * FROM tbl_items i
    INNER JOIN tbl_units u ON u.unit_id=i.iUnit
    WHERE icateg_id='".$c."' ";
    $stmt = $conn->query($sql);
    $num = $stmt->rowCount();
    if($num>0){?>
    <option></option>
    <?php
    while ($row = $stmt->fetch()) { 
    ?>
    <option value="<?php echo $row['item_id'];?>"><?php echo $row['item_name']." [".$row['unit_name']."]";?></option>
   <?php 
    }  
}
}

if(isset($_GET['dept'])){
    $a=$_GET['dept'];
    $sql= "SELECT * FROM tbl_title where department_id='".$a."' ";
    $stmt = $conn->query($sql);
    $num = $stmt->rowCount();
    if($num>0){?>
    <option></option>
    <?php
    while ($row = $stmt->fetch()) { 
    ?>
    <option value="<?php echo $row['title_id'];?>"><?php echo $row['title_name'];?></option>
   <?php 
    }  
}
}

if(isset($_GET['tpid'])){
    $a=$_GET['tpid'];
    $sql= "SELECT * FROM tbl_categ_su where ss_type='".$a."' ";
    $stmt = $conn->query($sql);
    $num = $stmt->rowCount();
    if($num>0){?>
    <option></option>
    <?php
    while ($row = $stmt->fetch()) { 
    ?>
    <option value="<?php echo $row['ctg_id'];?>"><?php echo $row['ctg_name'];?></option>
   <?php 
    }  
}
}

if(isset($_GET['boqcomp'])){
    $a=$_GET['boqcomp'];
    $sql= "SELECT * FROM tbl_boq_div where dv_cmpnt='".$a."' ";
    $stmt = $conn->query($sql);
    $num = $stmt->rowCount();
    if($num>0){?>
    <option></option>
    <?php
    while ($row = $stmt->fetch()) { 
    ?>
    <option value="<?php echo $row['bdiv_id'];?>"><?php echo $row['boqdiv_name'];?></option>
   <?php 
    }  
}
}

if(isset($_GET['elem'])){
    $a=$_GET['elem'];
    $sql= "SELECT * FROM tbl_ictgs where elemi='".$a."' and ictg_sts=1";
    $stmt = $conn->query($sql);
    $num = $stmt->rowCount();
    if($num>0){?>
    <option></option>
    <?php
    while ($row = $stmt->fetch()) { 
    if($row['ctgdesc']==""){
        $dash="";
    }else{
        $dash=" | ";  
    }
    ?>
    <option value="<?php echo $row['ictg_id'];?>"><?php echo $row['ctgi_name'].$dash.$row['ctgdesc'];?></option>
   <?php 
    }  
}
} 

###### PROJECT ######
if(isset($_GET['clnt'])){
    $a=$_GET['clnt'];
    $sql= "SELECT * FROM tbl_projects where clnt='".$a."' AND prces=3";
    $stmt = $conn->query($sql);
    $num = $stmt->rowCount();
    if($num>0){?>
      <option></option>
    <?php
    while ($row = $stmt->fetch()) { 
    ?>
    <option value="<?php echo $row['projid'];?>"><?php echo $row['codeproj'];?></option>
   <?php 
    }  
}
} 

###### PROJECT ######
if(isset($_GET['supsub'])){
    $a=$_GET['supsub'];
    $sql= "SELECT * FROM tbl_projects p
    inner join tbl_invoices i on i.projInv=p.projid
    where ssinv='".$a."' AND stsinvce=1";
    $stmt = $conn->query($sql);
    $num = $stmt->rowCount();
    if($num>0){?>
      <option></option>
    <?php
    while ($row = $stmt->fetch()) { 
    ?>
    <option value="<?php echo $row['projid'];?>"><?php echo $row['codeproj'];?></option>
   <?php 
    }  
}
} 
?>	 