<?php session_name('CAKEPHP'); session_start();
error_reporting(FALSE);
$PageSecurity = 11;
include('includes/DefinePOClass.php');
include('includes/DefineSerialItems.php');
include('includes/SQL_CommonFunctions.inc');
$title = _('Job Indent Register');
?>
<script language="javascript" type="text/javascript">
function get_division()
  {
        $('#division').html('<option>Loading...</option>');  
        $.ajax({
            url : "ajax_get_breakDown_type.php",
            type : "POST",
            data : {
            branchCode:$('#site').val()
            },
            success : function(data) {//alert(data);
             $('#division').html(data);  
                          }
                 });

  }
function get_itemsubgroup(str)
{
	if(str=="")
  {
  document.getElementById("sub_id").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("sub_id").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","item_subcategory.php?main="+str,true);
xmlhttp.send();
}
function get_item(str)
{
if(str=="")
  {
  document.getElementById("itemid").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("itemid").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","Get_itemcode.php?sub="+str,true);
xmlhttp.send();
}
function showItems(str)
{
    if(str=="")
  {
  document.getElementById("itemid").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("itemid").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","Get_itemcode.php?partName="+str,true);
xmlhttp.send();
}



function showsitename160(str)
{

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	var data=xmlhttp.responseText.split("__");	
	document.getElementById("storedata7").innerHTML=data[0];
	  }
  }
  xmlhttp.open("GET","get_sitenamedata2.php?site="+str,true);
	xmlhttp.send();

//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);

	
}

function showResult(str)
{ 
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {  
    var data=xmlhttp.responseText.split("__");	
    document.getElementById("storecode").innerHTML=data['0'];
    document.getElementById("employee").innerHTML=data['1'];
	
    }
  }

xmlhttp.open("GET","check_data_fin.php?section=showStoreEmpIssue&site="+str,true);
xmlhttp.send();
}
function getSubCategory()
{    
	var xmlhttp;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{   
		 var data=xmlhttp.responseText.split("__");
	document.getElementById("itm_subgrp").innerHTML=data['0'];
	document.getElementById("itemdata").innerHTML=data['1'];
	}
	}
        var category=document.getElementById("itm_grp").value;
        var subcat=document.getElementById("itm_subgrp").value;
        if(category=='')
        {	category=0;}
        if(subcat=='')
        {   subcat=0;}
    xmlhttp.open("GET","check_data_fin.php?section=showItemByCat&cat="+category+"&subcat="+subcat,true);
	xmlhttp.send();
}
function getItemBySub()
{    
	var xmlhttp;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{   
	document.getElementById("itemdata").innerHTML=xmlhttp.responseText;
       // getdata1();
	}
	}
        var category=document.getElementById("itm_grp").value;
        var subcat=document.getElementById("itm_subgrp").value;
        if(category=='')
        {	category=0;
        }
        if(subcat=='')
        	{subcat=0;}
	xmlhttp.open("GET","check_data_fin.php?section=showItemBySub&cat="+category+"&subcat="+subcat,true);
	xmlhttp.send();
}
function chkValidation()
{
   if($('#site').val()=='')
   {
   	alert('Please select site.');
   	return false;
   }
   return true;
 
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">  
<div class="tab_div">
<h1>Job Indent Register</h1>
<form method="post" action="" onsubmit="return chkValidation();">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td width="13%" class="tabledata1"><strong>Branch</strong></td>
    <td width="20%">
			<?php
	if($_SESSION['AssignedBranch']!='')
	  {	  	
                 $ss1="Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
	  	 $site_sql1=DB_query($ss1,$db);
	  }
	  else
	  {
		$ss1="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$site_sql1=DB_query($ss1,$db);
	  }
	?>
			<select name="site" id="site" onchange="get_division()" style="width:100%;">
<!--                            onchange="showsitename160(this.value)"-->
                <option value="">Select Site</option>
                <?php 
				
				while($site_row = DB_fetch_array($site_sql1))
				{
					$p='';
					if($site_row['loccode'] == $_POST['site'])	
					$p="selected";
				?>
                <option value="<?php echo $site_row['loccode']; ?>" <?php echo $p;?>><?php echo $site_row['locationname']; ?></option>
                <?php } ?>
            </select>
          </td>
	      <td width="13%" class="tabledata1"><strong>From Date</strong></td>
    <td width="20%"><input type="text" name="from_date" style="width:100%;" value="<?php echo $_POST['from_date'];?>" class="datepicker"></td>
	<td width="13%" class="tabledata1"><strong>To Date</strong></td>
    <td><input type="text" name="to_date" style="width:100%;" value="<?php echo $_POST['to_date'];?>" class="datepicker"></td>
</tr>
	<tr class="row1">
    <td><strong>Department</strong></td>
    <td><select style="width:100%;" name="department" id="department">
      <option value="">Select</option>
     <?php
     $resultDept=DB_query("select * from deptmaster where CompanyId='".$_SESSION['ACGCompanyId']."'" ,$db);
     while($rowDept=DB_fetch_array($resultDept))
     {?>
     <option value="<?php echo $rowDept['id']; ?>" <?php echo ($rowDept['id']==$_POST['department'])?'selected':''; ?>><?php echo $rowDept['deptname']; ?></option>
     <?php
     }

     ?>
    </select></td>
    <td><strong>Division</strong></td>
    <td><select style="width:100%;" id="division" name="division">
   <option value="">Select</option>
    </select></td>
    <td></td>
    <td></td>
</tr>

<tr class="row1">
	<td class="tabledata1" style="text-align:center;" colspan="6">
	<input type="submit" name="view" class="search" value="Search">
	</td>
</tr>
</table>
		

</form>
<?php 
if($_REQUEST['view']!='')
{
	$fromdate=$_REQUEST['from_date'];
	$todate=$_REQUEST['to_date'];
	$emp=$_REQUEST['employee'];
	$cont=$_REQUEST['contactor'];
	$fromdate_brk=explode('/',$fromdate);
	$from=$fromdate_brk[2]."-".$fromdate_brk[1]."-".$fromdate_brk[0];
	$todate_brk=explode('/',$todate);
	$to=$todate_brk[2]."-".$todate_brk[1]."-".$todate_brk[0];
	$sitename=$s->getField('locations','loccode',$_REQUEST['site'],'locationname');
	$filter=array();
	if($_REQUEST['site']!='')
	$filter[]="site = '".$_REQUEST['site']."'";
	if($_REQUEST['from_date']!='' && $_REQUEST['to_date']!='')
	$filter[]="work_indent_date BETWEEN '$from' and '$to'";
	if($_REQUEST['department']!='')
	$filter[]="department = '".$_REQUEST['department']."'";
    if($_REQUEST['division']!='')
	$filter[]="division = '".$_REQUEST['division']."'";
	
	if($filter!='')
	{
		$filter=implode(' and ',$filter);
	}
	if($_REQUEST['site']!='' && $_REQUEST['from_date']!='' && $_REQUEST['to_date']!='')
	{
	$message="Showing Records of Branch ".$sitename."   From  ".$from." to ".$to."";
	}
	else if($_REQUEST['site']!='' && $_REQUEST['from_date']=='' && $_REQUEST['to_date']=='')
	{
	$message="Showing Records of Branch ".$sitename." ";
	}
	if($filter!='')
	{
		 $sql ="Select * from tpl_work_indent where $filter and companyID='".$_SESSION['ACGCompanyId']."' ORDER BY id DESC ";
	}
	$_SESSION['jobindentreport']=$sql;
	$_SESSION['mess']=$message;
?>
<p align="right"><a href="JobIndentRegister_print.php?site=<?php echo $_REQUEST['site'];?>&store_code=<?php echo $_REQUEST['store1']?>&fromdate=<?php echo $_REQUEST['from_date']?>&todate=<?php echo $_REQUEST['to_date']?>" target="_blank">
<input type="button" name="Print" value="Print" class="search" /></a></p>
<h1 align="center"><?php echo $message; ?></h1>
  <table width="100%" cellpadding="3" cellspacing="0" border="1" style="border:#808080 1px solid;">
    <tr bgcolor="#CCCCCC" style="height: 30px">
      <td width="9%"><strong>Indent No.</strong></td>
      <td width="6%"><strong>Date</strong></td>	  
      <td width="100"><strong>Asset Code </strong></td>
      <td width="100"><strong>Name</strong></td>
      <td width="70"><strong>Justification</strong></td>
      <td width="80"><strong>Activity Code</strong></td>
      <td width="150"><strong>Name</strong></td>
      <td width="40"><strong>Unit</strong></td>
      <td width="60"><strong>Qty</strong></td>
      <td width="70"><strong>Completion Date</strong></td>
      <td width="100"><strong>Remarks</strong></td>
      <td><strong>Prepared By</strong></td>
    </tr>
    <?php 
  $result=DB_query($sql,$db);
  $numrow1=DB_num_rows($result);
  while($myrow=DB_fetch_array($result))
  { ?>
    <tr bgcolor="#FFFFFF">
      <td nowrap="nowrap"><?php echo $myrow['work_indent_no']; ?></td>
      <td><?php echo ConvertSQLDate($myrow['work_indent_date']); ?></td>
      <td colspan="9" style="padding:0px;">
      	 <table cellpadding="3" cellspacing="0" width="100%" border="0" style="border:none;">
      	    <?php  
			      $resultIndent=DB_query("select * from tpl_work_indent_asset where work_indent_id='".$myrow['id']."'",$db);
			      while($rowAsset=DB_fetch_array($resultIndent))
			      {
			       $resultItem=DB_query("select * from machine_center where id='".$rowAsset['asset_id']."'",$db);
			      $rowItem=DB_fetch_array($resultItem);

			        ?> 
      	 	 <tr>
      	 	 	<td width="100" style="border-right:#808080 1px solid;"><?php echo $rowItem['code']; ?></td>
      	 	 	<td width="100" style="border-right:#808080 1px solid;"><?php echo $rowItem['name']; ?></td>
      	 	 	<td width="70" style="border-right:#808080 1px solid;"><?php echo $rowAsset['junction_file']; ?></td>

      	 	 	<td colspan="5" style="padding:0px;">
      	 	 		<table cellpadding="3" cellspacing="0" width="100%" border="0" style="border:none;">
      	 	 		<?php
					      $resultAssetDet=DB_query("select * from tpl_work_indent_asset_details where work_indent_id='".$myrow['id']."' and work_indent_asset_id='".$rowAsset['id']."'",$db);
					      while($rowAssetDet=DB_fetch_array($resultAssetDet))
					      {
					        $resultActivity=DB_query("select * from sub_activity_defination where id='".$rowAssetDet['activity_id']."'",$db);
					        $rowActivity=DB_fetch_array($resultActivity);

					        ?> 
      	 	 			<tr>
      	 	 				<td width="80" style="border-right:#808080 1px solid;"><?php echo $rowActivity['activity_code']; ?></td>
      	 	 				<td width="150" style="border-right:#808080 1px solid;"><?php echo $rowActivity['activity_name']; ?></td>
      	 	 				<td width="40" style="border-right:#808080 1px solid;"><?php echo $s->getField('unitsofmeasure','unitid',$rowActivity['unit'],'unitname'); ?></td>
   	 	 				    <td width="60" style="border-right:#808080 1px solid;"><?php echo $rowAssetDet['activity_qty']; $qty[]=$rowAssetDet['activity_qty']; ?></td>
      	 	 				<td width="70" style="border-right:#808080 1px solid;"><?php echo date('d/m/Y',strtotime($rowAssetDet['work_completion_date'])) ?></td>
      	 	 				<td width="100"><?php echo $rowAssetDet['remark'];  ?></td>
      	 	 			</tr>
      	 	 			<?php } ?>
      	 	 		</table>
      	 	 	</td>
      	 	 </tr>
      	 	 <?php } ?>
      	 </table>
      </td>
      <td><?php echo $myrow['prepared_by']; ?></td>
    </tr>
    <?php } if($numrow1>0) { ?>
    <tr style="height: 25px">
      <td colspan="8" style="text-align:right;"><strong>Total</strong></td>
      <?php if($_REQUEST['site']=='') { ?> <?php } ?>
       <td colspan="4"><strong><?php echo array_sum($qty); ?></strong></td>
	  </tr>
      <?php } else { ?>
	   <tr bgcolor="#e7e7e7" style="height: 25px">
      <td class="jjrs_tabledata1" colspan="12" align="center"><strong>No Records</strong></td>
    </tr>
	  
      <?php } ?>     
  </table>

<?php } ?>
</div>
</div>