<link rel="stylesheet" href="css/new_mxerp.css">

<?php 
include('includes/Class_Client.php');

$date=date('Y-m-d');
$back_date=date('Y-m-d', strtotime('-'.$back_days.' day', strtotime($date)));

?>
<?php 
if($_REQUEST['Delete'])
{
	$del_id = $_POST['jobcardid'];
	$count=count($_REQUEST['jobcardid']);
	
	for($i=0;$i<$count;$i++){
	$del_id1 = $del_id[$i];
	
	$condition1="jc_id='".$del_id1."'";
	$s->DeleteRecord('add_service_jobcard',  $condition1);// DELETE FROM SERVICE TABLE
	
	
	$condition2="jc_id='".$del_id1."'";
	$s->DeleteRecord('trouble_ticket_jobcard_details',  $condition2);// DELETE FROM DETAILS TABLE
	
	
	$condition3="id='".$del_id1."'";
	$s->DeleteRecord('trouble_ticket_jobcard',  $condition3);// DELETE FROM PARANT TABLE
	}
}
?>
<script language="javascript" >
function JobCardData()
{	
	myCheckboxArray = document.myform.elements["jobcardid[]"];
	var t=myCheckboxArray.length;
	if(document.getElementById('jobcardid').checked==true)
	{	
	if(t==undefined)
	document.getElementById('jobcardid_'+1).checked=true;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('jobcardid_'+i).checked=true;	
	}	
	}
	else
	{
	if(t==undefined)		
	document.getElementById('jobcardid_'+1).checked=false;		
	
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('jobcardid_'+i).checked=false;	
	}
	}
}
</script>

<div class="body_contain">
<div class="tab_div">
  <h1>Job Card Against Trouble Ticket List</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))
	{?>
            <option value="<?php  echo $SiteRow['loccode'];?>" <?php  echo $_REQUEST['site']==$SiteRow['loccode']?'selected':''?> >
            <?php  echo $SiteRow['locationname'];?>
            </option>
            <?php 
	}
	?>
          </select></td>
        <td class="tabledata">From</td>
		<td><input name="fromdate" type="text"  class="datepicker"/></td>
		<td class="tabledata">To</td>
		<td><input name="todate" type="text"  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/job_card".$rurl.'&action=AddNew'?>">
                <input type="button" name="Create" value="Add Job Card" 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="jobcardid" type="checkbox"   id="jobcardid" onclick="JobCardData()"    /></td>
          <td class="tabledata">S. No.</td>
		  <td class="tabledata">Branch</td>
          <td class="tabledata">Date</td>
		  <td class="tabledata">Job Card 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 trouble_ticket_jobcard WHERE status != 3";
		$query = "SELECT * FROM trouble_ticket_jobcard";
		$query1 = array();
		if($_REQUEST['Search'] == 'Search'){
			$fromdateReq = FormatDateForSQL($_REQUEST['fromdate']);
			$todateReq   = FormatDateForSQL($_REQUEST['todate']);
			if($_REQUEST['site'] != '0') {
				$query1[] .= ' branch = "'.$_REQUEST['site'].'"';
			}
			if(!empty($_REQUEST['fromdate']) && empty($_REQUEST['fromdate'])) {
				$query1[] .= ' job_card_date = "'.$fromdateReq.'"';
			}
			if(!empty($_REQUEST['fromdate']) && !empty($_REQUEST['todate'])) {
				$query1[] .= ' job_card_date BETWEEN "'.$fromdateReq.'" AND "'.$todateReq.'"';
			}
		}
			if(!empty($query1))
			{	
				$query2= implode(" AND ",$query1);
				$query .= " WHERE ".$query2;
			}//else{
			//	$query = "SELECT * FROM trouble_ticket_jobcard";
			//}
		$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/jcEdit&action=Edit&jcid=".$row_quotes['id'].$rurl;
			 
			 $SO_VIEW="index.php?route=service/jcView&action=View&jcid=".$row_quotes['id'].$rurl;
			?>
			   <input name="jobcardid[]" type="checkbox" id="jobcardid_<?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']."'",'locationname'); ?></td>
          <td valign="top" style="white-space:nowrap"><?php echo $row_quotes['job_card_date']?> </td>
          <td valign="top" style="white-space:nowrap"><?php echo $row_quotes['job_card_number']?> </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_compaint']=='1'){$ttscope="Complaint";}
			else if($row_quotes['scope_compaint']=='2'){$ttscope="Installation";}
			else if($row_quotes['scope_compaint']=='3'){$ttscope="De-Installation";}
			else if($row_quotes['scope_compaint']=='4'){$ttscope="Re-Installation";}
			else if($row_quotes['scope_compaint']=='5'){$ttscope="Preventive";}
			else if($row_quotes['scope_compaint']=='6'){$ttscope="Service";}
			else if($row_quotes['scope_compaint']=='7'){$ttscope="Site Survey";}
			else {$ttscope="";}
		   echo $ttscope; ?>
		  
		  </td>
		  <td valign="top"><?php  echo $row_quotes['prob_desc']; ?></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>
<?php 
if($_SESSION['session_msg']) {?>
<script type="text/javascript" >
alert("<?php echo $_SESSION['session_msg']; ?>");
</script>
<?php } unset($_SESSION['session_msg']);?>


</div></div>
