<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['salesid'];
	$count=count($_REQUEST['salesid']);
	
	for($i=0;$i<$count;$i++){
		$del_id = $del_id[$i];
		$sql = "DELETE FROM trouble_ticket_jobcard WHERE id='".$del_id."'";
		$result = DB_query($sql,$db);
		
		$tt_sql = "DELETE FROM trouble_ticket_jobcard_details WHERE jc_id='".$del_id."'";
		$tt_result = DB_query($tt_sql,$db);
	}
}
?>
<script language="javascript" type="text/javascript">
function open_jobcard(str)
{
	var jcid=str;
	location.href="index.php?route=service/job_card_closing&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>&jcid="+jcid;
	
}


function LeadData()
{	

	myCheckboxArray = document.myform.elements["salesid[]"];
	var t=myCheckboxArray.length;
	
	
	if(document.getElementById('salesid').checked==true)
	{	
	
		if(t==undefined)
	
		document.getElementById('salesid_'+1).checked=true;		
			for (var i = 1; i <= t; i++)
	{
	document.getElementById('salesid_'+i).checked=true;	
	}	
	}
	else
	{
	if(t==undefined)		
		document.getElementById('salesid_'+1).checked=false;		
			
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('salesid_'+i).checked=false;	
	}
	}
	

	
}
</script>

<div class="body_contain">
<div class="tab_div">
  <h1>Pending Job Cards for closing</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;">&nbsp;</td>
        <td colspan="6"><table  border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td>&nbsp;</td>
              <td></td>
              <td>&nbsp;</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">S. No.</td>
		  <td class="tabledata">Branch</td>
		  <td class="tabledata">Job Card No.</td>
          <td class="tabledata">Date</td>
		  <td class="tabledata">Party Name</td>
          <td class="tabledata">Product Name</td>
		  <td class="tabledata">Expected Closing Date</td>
		  <td class="tabledata">Technician</td>
          <td class="tabledata">&nbsp;</td>

	</tr>
		<?php 
		
	//	$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 = "SELECT * FROM trouble_ticket_jobcard WHERE status != 3 and $query2";
			}else{
				$query = "SELECT * FROM trouble_ticket_jobcard WHERE status != 3";
			}
		$gettt = DB_query($query,$db);
		$_SESSION['Ticket']=$query;
		$i=0;
		while($row_quotes = DB_fetch_array($gettt)){ $i++;?>
		<tr bgcolor="#c1c1c1">
			
		  <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_number']?> </td>
          <td valign="top" style="white-space:nowrap"><?php echo $row_quotes['job_card_date']?> </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  echo $row_quotes['closing_date']; ?>
		  
		  </td>
		  <td valign="top"><?php  echo $tech = $s->GetFieldValue('technicians', 'id="'.$row_quotes['technician'].'"', 'technician'); ?></td>
		  
		  <td valign="top"><input type="button" name="profile_popup" value="Close" id="profile_popup"  onclick="open_jobcard(<?php echo $row_quotes['id']; ?>)" class="search" />
		  
		  </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>
