<?php 
if($_REQUEST['Add'])
{
   
    $data['client_id']=$_REQUEST['c_id'];
    $data['followup_date']=FormatDateForSQL($_REQUEST['followDate']);
    if($_REQUEST['nextfollowDate']!="")
    {
    $data['next_followup_date']=FormatDateForSQL($_REQUEST['nextfollowDate']);
    }
    else
    {
        $data['nxt_follow_reason']=$_REQUEST['reason_text'];
    }
    $data['fillowup_type']=$_REQUEST['FollowType'];
    $data['comments']=$_REQUEST['comments'];
    if($_REQUEST['action']=='Edit')
    {
    $cond="id='".$_REQUEST['id']."'";
    $row= $s->RecordEdit('follow_up', $data,$cond);
    }
    else
    {
        
    $row= $s->RecordInsert('follow_up', $data);
    }
    $s->pageLocation("index.php?route=TaskMgt/FollowUp".$rurl);
}

if($_REQUEST['action']=='delete')
{
	$condition="id='".$_REQUEST['id']."'";
	$s->DeleteRecord('follow_up', $condition);
	$s->pageLocation("index.php?route=TaskMgt/FollowUp".$rurl);
}

if($_REQUEST['action']=='Edit')
{
	$sqlget=DB_query("select * from follow_up where id='".$_REQUEST['id']."'",$db);
	$FetchData=DB_fetch_array($sqlget);
	extract($FetchData);
}	
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Follow Up</h1>
<form action="" method="post" onsubmit="return validation()">
<table  cellpadding="3" cellspacing="0" border="0" width="100%">
<tr class="row1">
    <td class="tabledata1">Client</td>
        <td><input id="c_code" name="partycode" list="browserscode" placeholder="Client Code" onchange="javascript:ajax_get_match_client(this,'code');">
           <?php //  echo "select c_name,id from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."'"; ?>
<datalist id="browserscode">
<?

    $q=DB_query("select client_code,id from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
    while($res=DB_fetch_assoc($q))
    {
        //$x=$res[0];
        echo "<option value='".$res['client_code']."'>";
    }
?>
</datalist></td>
        <?php // echo "select c_name,id from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."'"; ?>
<td><input style="width: 150px" id="c_name" name="party" list="browsers" placeholder="Client Name" onchange="javascript:ajax_get_match_client(this,'name');">
           <?php //  echo "select c_name,id from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."'"; ?>
       <datalist id="browsers">
<?

    $q=DB_query("select c_name,id,client_code from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
    while($res=DB_fetch_assoc($q))
    {
        //$x=$res[0];
        echo "<option value='".$res['c_name'].'   '.$res['client_code']."'>";
    }
?>
</datalist></td>
<input type="hidden" value="0" id="c_id" name="c_id">

	<td class="tabledata1">Follow Up Date</td>
	<td><input type="text" readonly  style="width:100%" name="followDate" value="<?php echo date('d/m/Y'); ?>"  class="datepicker" size="15" /></td>
	<td class="tabledata1">Follow Type</td>
	<td>
	<select  name="FollowType" >
		
		<option value="By Phone"<?php echo($fillowup_type=='By Phone'?'selected':''); ?>>By Phone</option>
		<option value="By Mail"<?php echo($fillowup_type=='By Mail'?'selected':''); ?>>By Mail</option>
	</select>
	</td>
</tr>
<tr class="row1">
    <td class="tabledata1">Next Follow Up Date</td>
	<td><input type="text" id="nextfollowDate" readonly="true" style="width:100%" name="nextfollowDate" value=""  class="datepicker" size="15" /></td>
	<td class="tabledata1">Description</td>
	<td colspan="5"><textarea name="comments" style="width:100%;" rows="5" cols="40"><?php echo $comments ?></textarea></td>
</tr>
<tr class="row1" style="display:none" id="reason_row">
    <td class="tabledata1">Reason</td>
    <td colspan="4"><textarea name="reason_text" id="reason_text" style="width:100%;" rows="5" cols="40"></textarea></td>
    <td colspan="3"></td>
</tr>

<tr class="row1">
	<td style="text-align:center;" class="tabledata1" colspan="8"><input type="submit" name="Add" value="Add" class="search" /> <input type="button"  value="cancel" class="search" /></td>
</tr>
</table>
</form>
<!--<table cellpadding="3" cellspacing="0" width="100%" border="1">
<tr class="row1">
		<td colspan="5"  class="tabledata1"><div align="center"><strong>Follow Up History</strong></div></td>
</tr>
	<tr>
		<th><strong>Party</strong></th>
		<th><strong>Follow Date</strong></th>
		<th><strong>Follow Type</strong></th>
		<th><strong>Comments</strong></th>
		<th>Action</th>
	</tr>
	<?php 
	$follow_sql=DB_query("SELECT * FROM follow_up",$db);
	while($follow_row=DB_fetch_array($follow_sql))
	{?>
	<tr bgcolor="#dfdfdf">
		<td width="15%"><?php echo $s->getField('clientmaster','id',$follow_row['client_id'],'c_name'); ?></td>
		<td width="15%"><?php echo ConvertSQLDate($follow_row['followup_date']);?></td>
		<td width="15%"><?php echo $follow_row['fillowup_type'];?></td>
		<td><?php echo $follow_row['comments'];?></td>
		<td>
		  <a href="index.php?route=TaskMgt/FollowUp&amp;action=Edit&amp;id=<?php echo $follow_row['id'].$rurl;?>">
  <img src="images/icon_edit.gif" width="15px"  height="15" /></a>
		<a href="index.php?route=TaskMgt/FollowUp&amp;id=<?php echo $follow_row['id'];?>&amp;modid=<?php echo $_REQUEST['modid'];?>&amp;frmid=<?php echo $_REQUEST['frmid'];?>&amp;action=delete" onclick="return confirm('This data will be deleted')" ><img src="images/Icon_Delete.png" height="15" width="15"></a></td>
	</tr>
	<?php 
	}
?>
</table>-->

<script>
function ajax_get_match_client(str,type)
{
    
    if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
               
                if(type=='name')
                    { 
                        alert(xmlhttp.responseText);
                       var data1=xmlhttp.responseText.split("**"); 
                   document.getElementById("c_code").value=data1[0]; 
                   document.getElementById("c_id").value=data1[1];
                    }
               if(type=='code')
                  {
                     var data=xmlhttp.responseText.split("**"); 
                   document.getElementById("c_name").value=data[0];
                   document.getElementById("c_id").value=data[1];
                  }
                
            }
        }
        if(type=='name')
        { 
            var data=str.value.split("   ");
         xmlhttp.open("POST","ajax_get_match_client.php?val="+data[1]+"&type="+type,true);
        }
        else if(type=='code')
      { 
      xmlhttp.open("POST","ajax_get_match_client.php?val="+str.value+"&type="+type,true);    
      }
        xmlhttp.send();
}

function validation()
{
    if(document.getElementById("c_id").value=='0')
    {
        alert("Please select the Client");
         return false;
    }
    else
        {
           if(document.getElementById("nextfollowDate").value=="")
            {
                document.getElementById("reason_row").style.display='';
                 if(document.getElementById("reason_text").value=="")
                     {
                         alert("Please Enter the reason");
                         return false;
                     }
                 else
                     {
                      return true;   
                     }
            }
            else
                {
                    document.getElementById("reason_row").style.display='none';
                }
        }
}
</script>
        
