<?php error_reporting(FALSE);
include('functions.php');
include('functionsgetdep.php');
include('includes/Class_Client.php');
include('Class_PickListEditor.php');
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<script>
	function displatPeriod(){
		if(document.getElementById("getperiod").style.display!='block'){
			document.getElementById("getperiod").style.display="block";
			document.getElementById("getparty").style.display="none";
			document.getElementById("gettech").style.display="none";
			document.getElementById("pty").style.display="none";
			document.getElementById("tec").style.display="none";
		}
		/*if(document.getElementById("pr").style.display!='block'){
			document.getElementById("pr").style.display="block";
			document.getElementById("pty").style.display="none";
			document.getElementById("tec").style.display="none";
		}*/
	}
	function displatParty(){
	 if(document.getElementById("getparty").style.display!='block'){
			document.getElementById("getparty").style.display="block";
			document.getElementById("getperiod").style.display="none";
			document.getElementById("gettech").style.display="none";
			document.getElementById("pr").style.display="none";
			document.getElementById("tec").style.display="none";
		}
		
	}
	function displatech(){
		if(document.getElementById("gettech").style.display!='block'){
			document.getElementById("gettech").style.display="block";
			document.getElementById("getperiod").style.display="none";
			document.getElementById("getparty").style.display="none";
			document.getElementById("pty").style.display="none";
			document.getElementById("pr").style.display="none";
			
			
		}
	}
		
</script>
<?php 
if($_REQUEST['SearchPeriod']=='Search'){

	$fromdate=$_REQUEST['fromdate'];
	$fromDateBrk=explode("/",$fromdate);
	$fromDate=$fromDateBrk[0];
	$fromMonth=$fromDateBrk[1];
	$fromYear=$fromDateBrk[2];
	$From=$fromYear."-".$fromMonth."-".$fromDate;
	
	$todate=$_REQUEST['todate'];
	$toDateBrk=explode("/",$todate);
	$toDate=$toDateBrk[0];
	$toMonth=$toDateBrk[1];
	$toYear=$toDateBrk[2];
	$To=$toYear."-".$toMonth."-".$toDate;

	//$todate=ConvertSQLDate($_REQUEST['todate']);
	//$fromdate=ConvertSQLDate($_REQUEST['fromdate']);	
	
	if($todate!='' && $fromdate!=''){
		$filter[]="job_card_date between '".$From."' and '".$To."'";
	}
	if($_REQUEST['site']!='0'){
		$filter[]="branch = '".$_REQUEST['site']."'";
	}
	if($filter!=''){
		$filter1=implode(" and ",$filter);
		$sql = "Select * from trouble_ticket_jobcard where $filter1";
		$GetPeriodData= DB_query($sql,$db);
	}else{
		$sql = "Select * from trouble_ticket_jobcard";
		$GetPeriodData= DB_query($sql,$db);
	}
	
}
if($_REQUEST['SearchTech']){
	$fromdate1=$_REQUEST['fromDate'];
	$fromDateBreak=explode("/",$fromdate1);
	$fromDt=$fromDateBreak[0];
	$fromMth=$fromDateBreak[1];
	$fromYr=$fromDateBreak[2];
	$From1=$fromYr."-".$fromMth."-".$fromDt;
	
	$todate1=$_REQUEST['toDate'];
	$fromDateBreak=explode("/",$todate1);
	$toDt=$fromDateBreak[0];
	$toMth=$fromDateBreak[1];
	$toYr=$fromDateBreak[2];
	$To1=$toYr."-".$toMth."-".$toDt;
	
	if($todate1!='' && $fromdate1!=''){
		$filtertt[]="job_card_date between '".$From1."' and '".$To1."'";
	}
	if($_REQUEST['site']!='0'){
		$filtertt[]="branch = '".$_REQUEST['site']."'";
	}
	if($_REQUEST['technician']!=''){
		$filtertt[]="technician = '".$_REQUEST['technician']."'";
	}
	if($filtertt!=''){
		$filter2=implode(" and ",$filtertt);
	
	$sql = "select * from trouble_ticket_jobcard where $filter2";
	$GetTechData= DB_query($sql,$db);
	}else{
		$sql = "select * from trouble_ticket_jobcard";
		$GetTechData= DB_query($sql,$db);
	}
	
}
if($_REQUEST['SearchParty']){

	$fDate=$_REQUEST['fDate'];
	$fDateBrk=explode("/",$fDate);
	$fDate=$fDateBrk[0];
	$fMonth=$fDateBrk[1];

	$fYear=$fDateBrk[2];
	$From2=$fYear."-".$fMonth."-".$fDate;
	
	$tDate=$_REQUEST['tDate'];
	$tDateBrk=explode("/",$tDate);
	$tDate=$tDateBrk[0];
	$tMonth=$tDateBrk[1];
	$tYear=$tDateBrk[2];
	$To2=$tYear."-".$tMonth."-".$tDate;
	
	if($fDate != '' && $tDate!=''){
		$filter3[]= "job_card_date between '".$From2."' and '".$To2."'";
	}
	
	if($_REQUEST['site']!='0'){
		$filter3[]="branch = '".$_REQUEST['site']."'";
	}
	
	if($_REQUEST['client']!=''){
		$filter3[]="party_name = '".$_REQUEST['client']."'";
	}
	
	if($filter3!=''){
		$Fil = implode(" and ",$filter3);
		$sql = "SELECT * FROM trouble_ticket_jobcard where $Fil";
		$GetParty = DB_query($sql,$db);
		
	}
	else{
		$sql = "SELECT * FROM trouble_ticket_jobcard";
		$GetParty = DB_query($sql,$db);
	}
	
}
?>
<div class="body_contain">
<div class="tab_div">
<h1>Job Card Register </h1>
<?php //print_r($_REQUEST); ?>
<!--<input name="radiobutton" type="radio" value="technician" onclick="displatPeriod('getperiod')" />
    Period Wise
    <input name="radiobutton" type="radio" value="assignment" onclick="displatParty('getparty')"/>
    Party Wise
    <input name="radiobutton" type="radio" value="register" onclick="displatech('gettech')"/>
    Technician Wise <br />-->
<input name="period" type="radio" value="period" <?php if($_REQUEST['SearchPeriod']=='Search'){ echo 'checked' ;}else{ }?> onclick="displatPeriod(this.value)"/>
Period Wise
<input name="period" type="radio" value="party" <?php if($_REQUEST['SearchParty']=='Search'){ echo 'checked' ;}else{ }?> onclick="displatParty(this.value)"/>
Party Wise
<input name="period" type="radio" value="tech" <?php if($_REQUEST['SearchTech']=='Search'){ echo 'checked' ;}else{ }?> onclick="displatech(this.value)"/>
Technician Wise <br />
<br />
<div style="display:none" id="getperiod">
  <form action="" method="post">
    <table width="100%" border="0" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
      <tr>
        <td nowrap="nowrap" scope="row">Branch</td>
        <td nowrap="nowrap"><select name="site"  style="width:150px;">
            <option value="0">--All--</option>
            <?php
					$Sitesql="select * from locations where  CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
					$SiteRes=DB_query($Sitesql,$db);
					while($SiteRow=DB_fetch_array($SiteRes))
					{?>
            <option value="<?php  echo $SiteRow['loccode'];?>" <?php  echo $_REQUEST['site']==$SiteRow['loccode']?'selected':''?> >
            <?php  echo $SiteRow['locationname'];?>
            </option>
            <?php 
					}
					?>
          </select>
        </td>
        <td nowrap="nowrap" scope="row">From Date</td>
        <td nowrap="nowrap"><input name="fromdate" id="fromdate" type="text"  class="datepicker"  style="width:150px;" value="<?php echo $_REQUEST['fromdate'];?>" /></td>
        <td nowrap="nowrap" scope="row">To Date</td>
        <td nowrap="nowrap"><input name="todate" id="todate" type="text"  class="datepicker"  style="width:150px;"  value="<?php echo $_REQUEST['todate'];?>" /></td>
		<td><input type="submit" name="SearchPeriod" value="Search" class="bottonsview"/></td>
      </tr>
    </table>
  </form>
</div>
<div style="display:none" id="getparty">
  <form action="" method="post">
    <table width="100%" border="0" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
      <tr>
        <td nowrap="nowrap" scope="row">Branch</td>
        <td nowrap="nowrap"><select name="site" style="width:150px;">
            <option value="0">--All--</option>
            <?php
					$Sitesql="select * from locations where  CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
					$SiteRes=DB_query($Sitesql,$db);
					while($SiteRow=DB_fetch_array($SiteRes))
					{?>
            <option value="<?php  echo $SiteRow['loccode'];?>" <?php  echo $_REQUEST['site']==$SiteRow['loccode']?'selected':''?> >
            <?php  echo $SiteRow['locationname'];?>
            </option>
            <?php 
					}
					?>
          </select>
        </td>
        <td nowrap="nowrap" scope="row">Party</td>
        <td nowrap="nowrap"><select name="client" style="width:150px;">
            <option value="">--All--</option>
            <?php
					$Client="select * from clientmaster";
					$ClientRes=DB_query($Client,$db);
					while($ClientResRow=DB_fetch_array($ClientRes))
					{
					$sel='';
					if($_REQUEST['client']==$ClientResRow['id'])
					$sel='selected';
					?>
            <option value="<?php  echo $ClientResRow['id'];?>" <?php echo $sel; ?>>
            <?php  echo $ClientResRow['c_name'];?>
            </option>
            <?php 
					}
					?>
          </select>
          <?php echo $ClientSQL= $s->GetFieldValue('clientmaster', 'id="'.$fetch_tt_qry['part_name'].'"','c_name');
								?></td>
        <td nowrap="nowrap" scope="row">From Date</td>
        <td nowrap="nowrap"><input name="fDate" id="fDate" type="text"  class="datepicker" style="width:150px;" value="<?php echo $_REQUEST['fDate'];?>" /></td>
        <td nowrap="nowrap" scope="row">To Date</td>
        <td nowrap="nowrap"><input name="tDate" id="tDate" type="text"  class="datepicker" style="width:150px;"  value="<?php echo $_REQUEST['tDate'];?>" /></td>
		<td><input type="submit" name="SearchParty" value="Search" class="bottonsview" /></td>
      </tr>
    </table>
  </form>
</div>
<div style="display:none;" id="gettech">
  <form action="" method="post">
    <table width="100%" border="0" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
      <tr>
        <td nowrap="nowrap" scope="row">Branch</td>
        <td nowrap="nowrap"><select name="site" style="width:150px;">
            <option value="0">--All--</option>
            <?php
					$Sitesql="select * from locations where  CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
					$SiteRes=DB_query($Sitesql,$db);
					while($SiteRow=DB_fetch_array($SiteRes))
					{?>
            <option value="<?php  echo $SiteRow['loccode'];?>" <?php  echo $_REQUEST['site']==$SiteRow['loccode']?'selected':''?> >
            <?php  echo $SiteRow['locationname'];?>
            </option>
            <?php 
					}
					?>
          </select>
        </td>
        <td nowrap="nowrap" scope="row">Technician</td>
        <td nowrap="nowrap"><?php $technicians = DB_query("select *  from technicians",$db);
				   //echo $tech['technician'];
					/*echo $ClientSQL= $s->GetFieldValue('clientmaster', 'id="'.$fetch_tt_qry['part_name'].'"','c_name');*/
				?>
          <select name="technician" style="width:150px;">
            <option value="">--All--</option>
            <?php while($tech = DB_fetch_array($technicians)) {
				$sel1='';
				if($_REQUEST['technician']==$tech['id'])
				$sel1='selected';
			?>
            <option id="<?php echo $tech['id'];?>" value="<?php echo $tech['id'];?>"<?php echo $sel1; ?>><?php echo $tech['technician'];?></option>
            <?php } ?>
          </select>
        </td>
        <td nowrap="nowrap" scope="row">From Date</td>
        <td nowrap="nowrap"><input name="fromDate" id="fromDate" type="text"  class="datepicker" style="width:150px;" value="<?php echo $_REQUEST['fromDate'];?>" /></td>
        <td nowrap="nowrap" scope="row">To Date</td>
        <td nowrap="nowrap"><input name="toDate" id="ToDate" type="text"  class="datepicker" style="width:150px;"  value="<?php echo $_REQUEST['toDate'];?>" /></td>
		<td><input type="submit" name="SearchTech" value="Search" class="bottonsview" /></td>
      </tr>
    </table>
  </form>
</div>
</p>
<?php if($_REQUEST['SearchPeriod']){?>
<script>document.getElementById("getperiod").style.display="block";</script>
<div id="pr">
  <table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
    <tr>
      <td colspan="10" class="tabledata"><strong>Showing Job Card Register From <?php echo $_REQUEST['fromdate']; ?> To <?php echo $_REQUEST['todate']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $s->GetFieldValue('locations',"loccode='".$_REQUEST['site']."'",'locationname'); ?></strong></td>
    </tr>
    <tr>
      <td class="tabledata"><strong>S. No.</strong></td>
      <td class="tabledata"><strong>JC Date</strong></td>
      <td class="tabledata"><strong>JC No.</strong></td>
	  <td class="tabledata"><strong>TT No.</strong></td>
      <td class="tabledata"><strong>Party Name</strong></td>
      <td class="tabledata"><strong>Product Name</strong></td>
      <td class="tabledata"><strong>Serial No.</strong></td>
      <td class="tabledata"><strong>Fault Details</strong></td>
      <td class="tabledata"><strong>Technician</strong></td>
      <td class="tabledata"><strong>Current Status</strong></td>
    </tr>
    <?php if(DB_num_rows($GetPeriodData)>0){
			$i=1;
			while($fetchData = DB_fetch_array($GetPeriodData)){
		?>
    <tr>
      <td class="tabledata"><?php echo $i;?></td>
      <td class="tabledata"><?php echo $fetchData['job_card_date'];?></td>
      <td class="tabledata"><?php echo $fetchData['job_card_number'];?></td>
      <td class="tabledata"><?php echo $s->GetFieldValue('trouble_ticket_creation', 'id="'.$fetchData['ticket_number'].'"','ticket_number');?></td>
	  
      <td class="tabledata"><?php echo $s->GetFieldValue('clientmaster', 'id="'.$fetchData['party_name'].'"','c_name');?></td>
      <td class="tabledata"><?php echo $s->GetFieldValue('item_master', 'id="'.$fetchData['product_name'].'"','item_name');?></td>
      <td class="tabledata"><?php echo $fetchData['serial_number'];?></td>
      <td class="tabledata"><?php echo $fetchData['prob_desc'];?></td>
      <td class="tabledata"><?php echo $s-> GetFieldValue('technicians',"id='".$fetchData['technician']."'",'technician');?></td>
      <td class="tabledata"><?php if($fetchData['status']==1){echo 'Open';}
	  							  if($fetchData['status']==2){echo 'In process';}
								  if($fetchData['status']==3){echo 'Close';}?></td>
    </tr>
    <?php $i++;
		} } else {?>
		
		<tr>
		<td colspan="10" style="color:#FF0000;">No Record Found</td>
		</tr>
		
		<?php } ?>
  </table>
</div>
<br />
<?php }else{?>
<script>document.getElementById("getperiod").style.display="none";</script>
<?php }?>
<?php if($_REQUEST['SearchParty']){?>
<script>document.getElementById("getparty").style.display="block";</script>
<div id="pty">
  <table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
    <tr>
      <td colspan="9" class="tabledata"><strong>Showing Job Card Details For <?php echo $s->GetFieldValue('clientmaster',"id='".$_REQUEST['client']."'",'c_name'); ?>&nbsp;&nbsp;From <?php echo $_REQUEST['fDate']; ?> To <?php echo $_REQUEST['tDate']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $s->GetFieldValue('locations',"loccode='".$_REQUEST['site']."'",'locationname'); ?></strong></td>
    </tr>
    <tr>
      <td class="tabledata"><strong>S. No. </strong></td>
      <td class="tabledata"><strong>JC No</strong></td>
      <td class="tabledata"><strong>JC Date</strong></td>
      <td class="tabledata"><strong>TT NO</strong></td>
      <td class="tabledata"><strong>Product Name</strong></td>
      <td class="tabledata"><strong>Serial No.</strong></td>
      <td class="tabledata"><strong>Fault Desc</strong></td>
      <td class="tabledata"><strong>Technician</strong></td>
      <td class="tabledata"><strong>Current Status</strong></td>
    </tr>
    <?php 
	if(DB_num_rows($GetParty)>0){
	$i=1;
			  while($fetchParty = DB_fetch_array($GetParty)){
		?>
    <tr>
      <td class="tabledata"><?php echo $i;?></td>
      <td class="tabledata"><?php echo $fetchParty['job_card_number']?></td>
      <td class="tabledata"><?php echo ConvertSQLDate($fetchParty['job_card_date']);?></td>
      <td class="tabledata"><?php echo $s->GetFieldValue('trouble_ticket_creation', 'id="'.$fetchParty['ticket_number'].'"','ticket_number');?></td>
      <td class="tabledata"><?php echo $s->GetFieldValue('item_master', 'id="'.$fetchParty['product_name'].'"','item_name');?></td>
      <td class="tabledata"><?php echo $fetchParty['serial_number'];?></td>
      <td class="tabledata"><?php echo $fetchParty['prob_desc'];?></td>
      <td class="tabledata"><?php echo $s-> GetFieldValue('technicians',"id='".$fetchParty['technician']."'",'technician'); ?> </td>
      <td class="tabledata"><?php if($fetchParty['status']==1){echo 'Open';}
	  							  if($fetchParty['status']==2){echo 'In process';}
								  if($fetchParty['status']==3){echo 'Close';}?></td>
    </tr>
    <?php $i++;
		} }else {?>
		
		<tr>
			<td colspan="9" style="color:#FF0000;">No Record Found</td>
		</tr>
		
		<?php } ?>
  </table>
</div>
<br />
<?php }else{?>
<script>document.getElementById("getparty").style.display="none";</script>
<?php }?>
<?php if($_REQUEST['SearchTech']){?>
<script>document.getElementById("gettech").style.display="block";</script>
<div id="tec">
  <table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
    <tr>
      <td colspan="9" class="tabledata"><strong>Showing Job Card Register of Technician&nbsp;&nbsp;<?php echo $s-> GetFieldValue('technicians',"id='".$_REQUEST['technician']."'",'technician'); ?>&nbsp;&nbsp;From <?php echo $_REQUEST['fromDate']; ?> To <?php echo $_REQUEST['toDate']; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $s->GetFieldValue('locations',"loccode='".$_REQUEST['site']."'",'locationname'); ?></strong></td>
    </tr>
    <tr>
       <td class="tabledata"><strong>S. No. </strong></td>
       <td class="tabledata"><strong>JC No</strong></td>
      <td class="tabledata"><strong>JC Date</strong></td>
      <td class="tabledata"><strong>TT NO</strong></td>
      <td class="tabledata"><strong>Product Name</strong></td>
      <td class="tabledata"><strong>Serial No.</strong></td>
      <td class="tabledata"><strong>Fault Desc</strong></td>
      <td class="tabledata"><strong>Technician</strong></td>
      <td class="tabledata"><strong>Current Status</strong></td>
    </tr>
    <?php if(DB_num_rows($GetTechData)>0){
			$i = 1;
			while($GetTech = DB_fetch_array($GetTechData)){?>
    <tr>
        <td class="tabledata"><?php echo $i;?></td>
      <td class="tabledata"><?php echo $GetTech['job_card_number']?></td>
      <td class="tabledata"><?php echo ConvertSQLDate($GetTech['job_card_date']);?></td>
      <td class="tabledata"><?php echo $s->GetFieldValue('trouble_ticket_creation', 'id="'.$GetTech['ticket_number'].'"','ticket_number');?></td>
      <td class="tabledata"><?php echo $s->GetFieldValue('item_master', 'id="'.$GetTech['product_name'].'"','item_name');?></td>
      <td class="tabledata"><?php echo $GetTech['serial_number'];?></td>
      <td class="tabledata"><?php echo $GetTech['prob_desc'];?></td>
      <td class="tabledata"><?php echo $s-> GetFieldValue('technicians',"id='".$GetTech['technician']."'",'technician'); ?> </td>
      <td class="tabledata"><?php if($GetTech['status']==1){echo 'Open';}
	  							  if($GetTech['status']==2){echo 'In process';}
								  if($GetTech['status']==3){echo 'Close';}?></td>
    </tr>
    <?php $i++;} }else {?>
	
	<tr>
		<td colspan="9" style="color:#FF0000;">No Record Found</td>
	</tr>
	
	<?php } ?>
  </table>
</div>
<?php }else{?>
<script>document.getElementById("gettech").style.display="none";</script>
<?php }?>
