<?php 
include('includes/Class_Client.php');
$date=date('Y-m-d');
$back_date=date('Y-m-d', strtotime('-'.$back_days.' day', strtotime($date)));
 
if($_REQUEST['Delete']){
	$del_id = $_POST['technicianid'];
	$count=count($_REQUEST['technicianid']);
	for($i=0;$i<$count;$i++){
	$del_id1 = $del_id[$i];
	
	$condition1="parant_id='".$del_id1."'";
	$s->DeleteRecord('technician_service_visit',  $condition1);// DELETE FROM SERVICE TABLE
	
	$condition2="parant_id='".$del_id1."'";
	$s->DeleteRecord('technician_visit_entry_details',  $condition2);// DELETE FROM DETAILS TABLE
	
	$condition3="id='".$del_id1."'";
	$s->DeleteRecord('technician_visit_entry',  $condition3);//DELETE FROM PARANT TABLE
	}
}
?>
<script language="javascript" >
function TecnicianData()
{	
	myCheckboxArray = document.myform.elements["technicianid[]"];
	var t=myCheckboxArray.length;
	if(document.getElementById('technicianid').checked==true)
	{	
	if(t==undefined)
	document.getElementById('technicianid_'+1).checked=true;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('technicianid_'+i).checked=true;	
	}	
	}
	else
	{
	if(t==undefined)		
	document.getElementById('technicianid_'+1).checked=false;		
	
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('technicianid_'+i).checked=false;	
	}
	}
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Technician visit entry</h1>
<form action="" method="post" name="myform" >
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
      <tr>
        <td class="tabledata">Branch</td>
	<td>
          <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))
	{
	$sel='';
	if($SiteRow['loccode']==$_REQUEST['site'])
	$sel='selected';?>
         <option value="<?php  echo $SiteRow['loccode'];?>"<?php echo $sel; ?>><?php  echo $SiteRow['locationname'];?></option>
      <?php }?>
          </select></td>
        <td class="tabledata">From</td>
		<td><input name="fromdate" type="text" value="<?php echo $_REQUEST['fromdate'] ?>"  class="datepicker"/></td>
		<td class="tabledata">To</td>
		<td><input name="todate" type="text" value="<?php echo $_REQUEST['todate'] ?>"  class="datepicker"/></td>
		<td><input name="Search" type="submit"  value="Search" /></td>
      </tr>
    </table>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
      <tr>
        <td class="tabledata" style="width:250px;">Actions</td>
        <td colspan="6"><table  border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><a href="<?php echo "index.php?route=service/technician_visit_entry".$rurl.'&action=AddNew'?>">
                <input type="button" name="Create" value="Add technician visit" style="background-color:#d1d4be; color:#006699; font-weight:800; padding-top:3px; padding-bottom:3px;" />
                </a></td>
              <td></td>
              <td><input type="submit" name="Delete" value="Delete" style="background-color:#d1d4be; color:#FF0000; padding-top:3px; padding-bottom:3px;" /></td>
              <?php if($_REQUEST['Search'])
	{ ?>
              <td><a href="TicketExp.php">
                <input type="button" name="Export" value="Export" style="background-color:#d1d4be; color:#006699; font-weight:800; padding-top:3px; padding-bottom:3px;" />
                </a></td>
              <?php }?>
            </tr>
          </table></td>
      </tr>
    </table>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
        <tr>
          <td class="tabledata"><input name="technicianid" type="checkbox"   id="technicianid" onClick="TecnicianData()"    /></td>
          <td class="tabledata">S. No.</td>
		  <td class="tabledata">Branch</td>
          <td class="tabledata">Date</td>
		  <td class="tabledata">Technician Visit No.</td>
          <td class="tabledata">Party Name</td>
          <td class="tabledata">Product Name</td>
		  <td class="tabledata">Scope of service</td>
		  <td class="tabledata">Fault Details</td>
          <td class="tabledata">Status</td>
	</tr>
<?php 
$query = "SELECT * FROM technician_visit_entry";
$query1 = array();
if($_REQUEST['Search'] == 'Search')
{
	$fromdateReq =FormatDateForSQL($_REQUEST['fromdate']);
	$todateReq =FormatDateForSQL($_REQUEST['todate']);
	if($_REQUEST['site'] != '0') {
	$query1[] .= ' branch_name = "'.$_REQUEST['site'].'"';
	}
	if(!empty($_REQUEST['fromdate']) && empty($_REQUEST['fromdate'])) {
	$query1[] .= ' visit_date = "'.$fromdateReq.'"';
	}
	if(!empty($_REQUEST['fromdate']) && !empty($_REQUEST['todate'])) {
	$query1[] .= ' visit_date BETWEEN "'.$fromdateReq.'" AND "'.$todateReq.'"';
	}
}
if(!empty($query1))
{	
$query2= implode(" AND ",$query1);
$query .= " WHERE ".$query2;
}
$query .= " ORDER BY id desc";
$gettt = DB_query($query,$db);
$_SESSION['Ticket']=$query;
$i=0;
while($row_quotes = DB_fetch_array($gettt)){ $i++;?>
		<tr bgcolor="#c1c1c1">
			<td style="white-space:nowrap;" valign="top">
			<?php
			 $SOURL="index.php?route=service/technician_visit_entry_Edit&action=Edit&TVID1=".$row_quotes['id'].$rurl;
			 
			 $SO_VIEW="index.php?route=service/technician_visit_view&action=View&TVID=".$row_quotes['id'].$rurl;
			?>
			   <input name="technicianid[]" type="checkbox" id="technicianid_<?php echo $i; ?>"   value="<?php  echo $row_quotes['id']?>"  />
			 <a href="<?php echo $SOURL ;?>"><img src="images/icon_edit.gif" width="10px"  height="10" /></a>
			 <a href="<?php echo $SO_VIEW?>" ><img src="images/search.gif" width="10px"  height="10" /></a>
		  </td>
		  <td valign="top" ><?php  echo $i; ?></td>
          <td valign="top" ><?php  echo $s->GetFieldValue('locations',"loccode='".$row_quotes['branch_name']."'",'locationname'); ?></td>
          <td valign="top" style="white-space:nowrap"><?php echo ConvertSQLDate($row_quotes['visit_date']);?> </td>
          <td valign="top" style="white-space:nowrap"><?php echo $row_quotes['visit_no']?> </td>
		  <td valign="top" >
		  <?php echo $ClientSQL= $s->GetFieldValue('clientmaster', 'id="'.$row_quotes['party_name'].'"','c_name');?>
								</td>
          <td valign="top">
		  <?php 
			$item = DB_query("SELECT item_name FROM item_master where id='".$row_quotes['product_name']."' ",$db);
			$Item_name = DB_fetch_array($item);
			echo $Item_name['item_name'];?></td>
		  <td valign="top">
		   <?php  
		   if($row_quotes['scope_of_services']=='1'){$ttscope="Complaint";}
			else if($row_quotes['scope_of_services']=='2'){$ttscope="Installation";}
			else if($row_quotes['scope_of_services']=='3'){$ttscope="De-Installation";}
			else if($row_quotes['scope_of_services']=='4'){$ttscope="Re-Installation";}
			else if($row_quotes['scope_of_services']=='5'){$ttscope="Preventive";}
			else if($row_quotes['scope_of_services']=='6'){$ttscope="Service";}
			else if($row_quotes['scope_of_services']=='7'){$ttscope="Site Survey";}
			else {$ttscope="";}
		   echo $ttscope; ?>
		  </td>
		  <td valign="top"><?php  echo $row_quotes['fault_details']; ?></td>
		  <td valign="top"><?php  
		  if($row_quotes['status']=='1'){$ttstatus="Open";}
			else if($row_quotes['status']=='2'){$ttstatus="In process";}
			else if($row_quotes['status']=='3'){$ttstatus="Close";}
			else {$ttstatus="";}
		  echo $ttstatus; ?>
		  </td>
        </tr>
		<?php } ?>
      </table>
</form>
</div></div>
