<?php
$PageSecurity=2;
include('includes/session.inc');
include('includes/function_lib.php');
include('includes/SQL_CommonFunctions.inc');
global $db;
if($_REQUEST['section']!=''){
switch($_REQUEST['section']){


case 'chk_employee' :
$chk_date=$_REQUEST['year']."-".$_REQUEST['month']."-01";
$chk_date1=$_REQUEST['year']."-".$_REQUEST['month']."-31";

?>
	
	<?php 
			        //$emp_query = "SELECT * FROM empmaster WHERE CompanyId='".$_SESSION['ACGCompanyId']."' AND MONTH(doj)>='".$_REQUEST['month']."' AND  ((YEAR(dol)>='".$_REQUEST['year']."' AND YEAR(doj)<='".$_REQUEST['year']."') OR (YEAR(doj)<='".$_REQUEST['year']."' AND dol='00-00-0000')) ORDER BY emp_name ASC"; 
                                $emp_query = "SELECT * FROM empmaster WHERE CompanyId='".$_SESSION['ACGCompanyId']."' AND emp_site='".$_REQUEST['site']."' AND (dol>='".$chk_date."' OR dol='0000-00-00') AND doj<='".$chk_date1."' ORDER BY emp_name ASC";
				$emp_res = DB_query($emp_query,$db) or die(DB_error());
                                if(DB_num_rows($emp_res)>0)
				{?>
        <option value="">All</option>
				<?php while($emp_result = DB_fetch_array($emp_res))
				{
			?>
			 <option value="<?php echo $emp_result['id'];?>" <?php if($_REQUEST['employee_code']==$emp_result['id']) { ?> selected="selected" <?php } ?>><?php echo $emp_result['emp_name'];?></option>
                                <?php }} ?>

<?php
break;

case 'chk_employee_all' :

?>
	<?php 
				$emp_query = "SELECT * FROM empmaster WHERE CompanyId='".$_SESSION['ACGCompanyId']."' AND emp_site='".$_REQUEST['site']."' AND ((YEAR(dol)>='".$_REQUEST['year']."' AND YEAR(doj)<='".$_REQUEST['year']."') OR (YEAR(doj)<='".$_REQUEST['year']."' AND dol='00-00-0000')) ORDER BY emp_name ASC";
				$emp_res = DB_query($emp_query,$db) or die(DB_error());
                                if(DB_num_rows($emp_res)>0){?>
                         <option value="">All</option>
                                <?php 
				while($emp_result = DB_fetch_array($emp_res))
				{
			?>
			 <option value="<?php echo $emp_result['id'];?>" <?php if($_REQUEST['employee_code']==$emp_result['id']) { ?> selected="selected" <?php } ?>><?php echo $emp_result['emp_name'];?></option>
                                <?php }} ?>
<?php
break;

case 'chk_type_employee' :
$chk_date=$_REQUEST['year']."-".$_REQUEST['month']."-01";
$chk_date1=$_REQUEST['year']."-".$_REQUEST['month']."-31";
?>
	<?php 
				//$emp_query = "SELECT * FROM empmaster WHERE CompanyId='".$_SESSION['ACGCompanyId']."' AND employment_type='".$_REQUEST['type']."' AND ((YEAR(dol)>='".$_REQUEST['year']."' AND YEAR(doj)<='".$_REQUEST['year']."') 
                                   // OR (MONTH(doj)<='".$_REQUEST['month']."' AND YEAR(doj)<='".$_REQUEST['year']."' AND dol='00-00-0000')) ORDER BY emp_name ASC";
               $emp_query = "SELECT * FROM empmaster WHERE CompanyId='".$_SESSION['ACGCompanyId']."' 
              AND staff_type='".$_REQUEST['type']."' AND emp_site='".$_REQUEST['site']."'
               AND (dol>='".$chk_date."' OR dol='0000-00-00') AND doj<='".$chk_date1."' 
              ORDER BY emp_name ASC";
				$emp_res = DB_query($emp_query,$db) or die(DB_error());
                                if(DB_num_rows($emp_res)>0){?>
                         <option value="All">All</option>
                               <?php  
				while($emp_result = DB_fetch_array($emp_res))
				{
			?>
			 <option value="<?php echo $emp_result['id'];?>" <?php if($_REQUEST['employee_code']==$emp_result['id']) { ?> selected="selected" <?php } ?>><?php echo $emp_result['emp_name'];?></option>
                                <?php } }?>
<?php
break;

case 'dept_wise_employee' :
$chk_date=$_REQUEST['year']."-".$_REQUEST['month']."-01";
$chk_date1=$_REQUEST['year']."-".$_REQUEST['month']."-31";
?>
	<?php 
				//$emp_query = "SELECT * FROM empmaster WHERE CompanyId='".$_SESSION['ACGCompanyId']."' AND employment_type='".$_REQUEST['type']."' AND ((YEAR(dol)>='".$_REQUEST['year']."' AND YEAR(doj)<='".$_REQUEST['year']."') 
                                   // OR (MONTH(doj)<='".$_REQUEST['month']."' AND YEAR(doj)<='".$_REQUEST['year']."' AND dol='00-00-0000')) ORDER BY emp_name ASC";
                $emp_query = "SELECT * FROM empmaster WHERE CompanyId='".$_SESSION['ACGCompanyId']."' 
              AND department='".$_REQUEST['type']."' AND emp_site='".$_REQUEST['site']."'
               AND (dol>='".$chk_date."' OR dol='0000-00-00') AND doj<='".$chk_date1."' 
              ORDER BY emp_name ASC";
              ?>
               <option value="">All</option>
              <?php
				$emp_res = DB_query($emp_query,$db) or die(DB_error());
                                if(DB_num_rows($emp_res)>0){?>
                        
                               <?php  
				while($emp_result = DB_fetch_array($emp_res))
				{
			?>
			 <option value="<?php echo $emp_result['id'];?>" <?php if($_REQUEST['employee_code']==$emp_result['id']) { ?> selected="selected" <?php } ?>><?php echo $emp_result['emp_name'];?></option>
                                <?php } }?>
<?php
break;

case 'showcolorCode' :
         $code = DB_query("SELECT color_code FROM qc_color_master WHERE CompanyId='".$_SESSION['ACGCompanyId']."' AND id='".$_REQUEST['str']."'",$db);
         $code_color = DB_fetch_array($code);
         echo $code_color['color_code'];
                 
break;

case 'getitemcode' :

    $Mainprefixcode=$s->getField('stockmaincategory','id',$_REQUEST['cat'],'stockmaincategoryid');
	$prefixcode=$s->getField('stockcategory','id',$_REQUEST['subcat'],'item_prefix');
         $sql="select StockID as MAXCODE from item_master where CategoryID='".$_REQUEST['cat']."' 
		and  SubCategoryID = '".$_REQUEST['subcat']."' ORDER BY id DESC LIMIT 0,1";
		
		$result = DB_query($sql,$db);
		$numrows=DB_num_rows($result);
		if($numrows>0)
		{
			$myrow=DB_Fetch_array($result);
			$strdata=substr($myrow['MAXCODE'],-4,4);
			$nextid=$strdata+1;
		}
		else
		{
			$nextid=1;
		}
		$strChar=$Mainprefixcode.$prefixcode;
		echo $strBothFinal = $strChar.str_pad($nextid,5,"0",STR_PAD_LEFT);
                 
break;

case 'chk_code' :
	$code = DB_fetch_array(DB_query("SELECT id FROM item_master WHERE StockID='".$_REQUEST['code']."' AND id<>'".$_REQUEST['id']."'",$db));
	if($code){
		$data="Dup";
	}
  echo $data;
break;


}
}
?>