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

<?php 
include('includes/Class_Client.php');
?>
<script language="javascript" type="text/javascript">
function open_technician(str,bran)
{
	var ttid=str;
	var branid=bran;
	window.open("open_technician.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>&ttaid="+ttid+"&braid="+branid,"itempopup_window","height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}
</script>

<div class="body_contain">
<div class="tab_div">
  <h1>Technician Assignment</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">Party Name</td>
		  <td>
		  	<?php
			$ClientSQL="Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' and  Site in('".$_SESSION['AssignedBranch']."') and Zone in(".$_SESSION['AssignedSites'].")";
			$Client_Name = DB_query($ClientSQL,$db);?>
			<select name="client_id" id="client_id" style="width:150px;">
              <option selected Value="0">Select your option</option>
              <?php while($Client = DB_fetch_array($Client_Name)){?>
              <option Value="<?php echo $Client['id']?>"><?php echo $Client['c_name']?></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><p align="left" style="padding-left:10px; padding:0px; margin:0px;"><input name="Search" type="submit"  value="Search"/></p></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;">Pending Trouble Ticket List</td>
        <td colspan="6"><table  border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
             
            </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">S. No.</td>
          <td class="tabledata">Branch</td>
          <td class="tabledata">TT No.</td>
		  <td class="tabledata">Date</td>
          <td class="tabledata">Party Name</td>
          <td class="tabledata">Product Name</td>
		  <td class="tabledata">Invoice No.</td>
		  <td class="tabledata">Warrantee Expiry Date</td>
		  <td class="tabledata">Expected Closing Date</td>
		  <td class="tabledata">Fault Details</td>
          <td class="tabledata">Assignment</td>

	</tr>
		<?php 
		$query = "SELECT * FROM trouble_ticket_creation WHERE is_assign='0'";
		$query1 = array();
		if($_REQUEST['Search'] == 'Search'){
			
			$fromdateReq = date("Y-m-d", strtotime($_REQUEST['fromdate']));
			$todateReq = date("Y-m-d", strtotime($_REQUEST['todate']));
			if($_REQUEST['site'] != '0') {
				$query1[] .= ' branch = "'.$_REQUEST['site'].'"';
			}
			if($_REQUEST['client_id'] != '0') {
				$query1[] .= ' part_name = "'.$_REQUEST['client_id'].'"';
			}
			if(!empty($_REQUEST['fromdate']) && empty($_REQUEST['fromdate'])) {
				$query1[] .= ' ttDate = "'.$fromdateReq.'"';
			}
			if(!empty($_REQUEST['fromdate']) && !empty($_REQUEST['todate'])) {
				$query1[] .= ' ttDate BETWEEN "'.$fromdateReq.'" AND "'.$todateReq.'"';
			}
		}
		//print_r($query1);
			if(!empty($query1))
			{	$query2= implode(" AND ",$query1);
				$query .= " AND ".$query2;
			}	
			
		$query .= " ORDER BY id desc";	
		$gettt = DB_query($query,$db);
		$sno = 0;
		while($row_quotes = DB_fetch_array($gettt)){
		$sno++;?>
		<tr bgcolor="#c1c1c1">
			<td style="white-space:nowrap;" valign="top">
			<?php  echo $sno; ?>
			 
		  </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['ticket_number']?> </td>
          <td valign="top" style="white-space:nowrap"><?php echo $row_quotes['ttDate']?> </td>
		  <td valign="top"><?php echo $ClientSQL= $s->GetFieldValue('clientmaster', 'id="'.$row_quotes['part_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  echo $row_quotes['invoiceNo']; ?></td>
			<td valign="top"><?php  echo $row_quotes['expire_date'];?></td>
		  <td valign="top"><?php  echo $row_quotes['closer_date'];?></td>
		  <td valign="top"><?php  echo $row_quotes['prob_desc']; ?></td>
          <td valign="top"><input type="button" name="profile_popup" value="Assign" id="profile_popup"  onclick="open_technician(<?php echo $row_quotes['id']; ?>,'<?php echo $row_quotes['branch']; ?>')" class="search" /></td>
        </tr>
		<?php } ?>
        
      </table>
  </form>
<?php 
if($_SESSION['session_msg']) {?>
<script type="text/javascript" >
alert("<?php echo $_SESSION['session_msg']; ?>");
this.form.submit();
</script>
<?php } unset($_SESSION['session_msg']);?>



</div></div>
