<?php session_name('CAKEPHP'); session_start();	
$PageSecurity = 1;
$tabindex=0;
include('includes/DefinePaymentClass.php');
$title = _('Telephonic Order Memo');
include('includes/SQL_CommonFunctions.inc');
include('CRM/functions.php');
$s=new db_query();

if($_REQUEST['save']!='')
{


    
    DB_query("insert into perf_team_master (branch,tdate,purpose,team_name,team_code,team_head,prepared_by,approved_by,created_by,created_date,companyid) values ('".$_REQUEST['branch']."','".FormatDateForSQL($_REQUEST['tdate'])."','".$_REQUEST['purpose']."','".$_REQUEST['teamname']."','".$_REQUEST['teamcode']."','".$_REQUEST['teamhead']."','".$_REQUEST['prepared']."','".$_REQUEST['approved']."','".$_SESSION['UserID']."','".date('y-m-d')."','".$_SESSION['ACGCompanyId']."')",$db);
    $last_id=DB_Last_Insert_ID($db,'perf_team_master','id');
    for($i=0;$i<count($_REQUEST['empid']);$i++)
    {
        if($_REQUEST['empid'][$i]!=''){
   DB_query(" insert into perf_team_master_details (masterid,empid) value('".$last_id."','".$_REQUEST['empid'][$i]."')",$db);
        }
    }    
    $s->pageLocation("index.php?route=TaskMgt/perf_team_master_index".$rurl);
}


?>
<script src="ui/jquery.ui.timepicker.js"></script>
<link rel="stylesheet" href="css/new_mxerp.css">
<style>
#showdata {
	display: block;
	background: url(Default.png) no-repeat;
	top: 0px;
	left: 0px;
	width: 300px;
	min-height: 60px;
	z-index:0;
}
#back {
	display: none;
	top: 0px;
	left: 0px;
	width: 300px;
	min-height: 60px;
	z-index:0;
}
</style>
<div class="body_contain">
<div class="tab_div">
<h1>Team Master</h1>
<div id="PickedItems" style="display:none">
</div>
<form method="post" action="">
   <table width="100%" cellpadding="0" cellspacing="0">
        <tr class="row1">
            <td class="tabledata1"><strong>Branch</strong></td>
            <td><select name="branch" id="branch" style="width:80%;" >
                 <option value="">select</option>
                 <?php $locsql= DB_query("select * from locations where mst_companyid='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."')",$db);
                while($locres=DB_fetch_array($locsql)) {  ?>
                 <option value="<?php echo $locres['loccode']; ?>"><?php echo $locres['locationname']; ?></option> 
                 <?php  } ?>
                </select></td>
                <td class="tabledata1"><strong>Team Code</strong></td>
                <td><input type="text" class="" maxlength="10" style="width:80%;" name="teamcode" value="" id="teamcode"></td>
                <td class="tabledata1"><strong>Date</strong></td>
                <td><input type="text" class="datepicker" style="width:80%;" value="" id="tdate" name="tdate"></td>                
        </tr>
        <tr class="row1">
            <td class="tabledata1"><strong>Purpose</strong></td>
            <td><input type="text" class="" maxlength="30" style="width:80%;" name="purpose" value="" id="purpose"></td>
            <td class="tabledata1"><strong>Team Name</strong></td>
            <td><input type="text" class="" maxlength="30" style="width:80%;" name="teamname" value="" id="teamname"></td>
            <td class="tabledata1"><strong>Team Head</strong></td>
            <td><select  name="teamhead" value="" id="teamhead" style="width:80%;">
                <option value="">Select</option>
                <?php $empsql=DB_query("select* from empmaster where CompanyId='".$_SESSION['ACGCompanyId']."' ",$db); while($empres=DB_fetch_assoc($empsql)) { ?>
                <option value="<?php echo $empres['id'] ?>"><?php echo $empres['emp_name'] ?></option>
                    <?php } ?>
                </select></td>
        </tr>
<tr class="row1" id='pickitem'>
	<td colspan="6">
	<input type="button" name="emp_popup" value="Employee" id="emp_popup" class="search" />
    <input type="button" class="search"   onclick="deleteRowOrder('emp_dataTable')" value="Delete" />       
	</td>
</tr>
        <tr class="row1">
	<td colspan="6" style="font-size:12px;font-weight: bold ">Employee Details</td>
</tr>
   </table> 
       <div style="overflow:auto; width:100%;" id="dir_item_detail">    
<table border="1" cellpadding="3" cellspacing="0" width="100%" style="border:1px solid #333333;">
<tr bgcolor="#d4d4d4">
	 <td class="tabledata"><strong>Select</strong></td>
         <td class="tabledata" style="width:1%"></td>
         <td class="tabledata"><strong>Employee Code</strong></td>
         <td class="tabledata"><strong>Employee Name</strong></td>
         <td class="tabledata"><strong>Department</strong></td>		 
         <td class="tabledata"><strong>Designation</strong></td>
</tr>
<tbody id="emp_dataTable">
<tr >
<td><input name="delitem[]" type="checkbox"  id="delitem" /></td>
<td><input type="hidden" name="empid[]" id="empid"  style="width:100%" readonly/></td>
<td><input type="text" name="empcode[]" id="empcode"  style="width:100%" readonly/></td>
<td><input type="text" name="empname[]" id="empname" style="width:100%" readonly/> </td>
<td><input type="text" name="department[]" id="department" style="width:100%" readonly /></td>
<td><input type="text" name="designation[]" id="designation" style="width:100%" readonly /></td>
</tr>
</tbody>
<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
  <input type="hidden" name="" value="0" id="edit_cnt" />
    <input type="hidden" name="" value="0" id="rowcount1" />
</table>
</div>
    <br>
    <table width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr class="row1">
        <td class="tabledata1"><strong>Prepared By</strong></td>
        <td><input type="text" maxlength="20" name="prepared" value=""></td>
        <td class="tabledata1"><strong>Approved By</strong></td>
        <td><input type="text" maxlength="20" name="approved" value=""></td>
    </tr>
    <br>
        <tr><td colspan="6" style="text-align:center"><button name="save" value="save" type="submit" colspan="6">Save</button> &nbsp;&nbsp;&nbsp;<a href="index.php?route=TaskMgt/perf_appraisal_index<?php echo $rurl?>"><button name="cancel" value="" type="button" >Cancel</button></a></td></tr>
    </table>
</form>
   




>
<SCRIPT language=Javascript>

       function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : event.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       }
  function checkfrmsal(str)
  {
      
      var id=str.id;
      if(str.value==""){
          
            document.getElementById(id).value=0;
      }
      else
          {
              var val=parseFloat(str.value);
       document.getElementById(id).value=val.toFixed(2);       
          }
  }
  
  function checktosal(str)
  {
      var val=parseFloat(str.value);
      var id=str.id;
     var from=document.getElementById("fromsal").value;
     if(from!=""){
      if(str.value=='')
       document.getElementById(id).value=0;
      else
          {
              if(parseFloat(document.getElementById("fromsal").value)>=val)
                {
                  alert("From salary must be less than To Salary");
                    document.getElementById(id).value=0;    
                }  
                else
                {
                     document.getElementById(id).value=val.toFixed(2);
                }
          }
     }
     else
         {
            alert("Please enter From Salary First ");
            document.getElementById(id).value=0;
            document.getElementById("fromsal").focus();
         }
  }
    </SCRIPT>
 <script type="text/javascript" language="javascript">
$.noConflict();
$(document).ready(function(){	
    //var cnt=document.getElementById("count").value;
    $('#emp_popup').click(function(){
    $("#PickedItems").dialog({
                title:'Employee List',
                modal: true,
                resizable: false,
                width:900,
                height:300,
                closeText: 'fechar',
                draggable: true,
                show: 'fade',
                hide: 'fade',
                dialogClass: 'main-dialog-class',
                buttons: {
                        Exit: function()
                        {
                                $(this).dialog("close");
                        }
                }

            });
    Getemployeelist();
    });
});

function Getemployeelist()
{  
  var xmlhttp;
    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)
    {
       // alert(xmlhttp.responseText);
    document.getElementById("PickedItems").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("POST","ajax_employeepopup.php",true);
xmlhttp.send();
}


function move_employee_data(ctr,id,empcode,empname,desig,dept)
{    var dup='empty';
	var empcount=parseInt(document.getElementById('rowcount1').value)+1;
	
	var edit_cnt=document.getElementById('edit_cnt').value;
	//alert(edit_cnt);
	if(edit_cnt=='')
	{
		var counter=1;
	} 
	else if(edit_cnt>empcount)
	{
		var counter=edit_cnt;
		var itemcount=parseFloat(counter)+parseFloat(empcount);
	}
	else
	{
		var counter=edit_cnt;
	}
    if(document.getElementById("row_id_"+ctr).checked==true)
	{
         if(document.getElementById("empid") && document.getElementById('empid').value=='')
             {
               
                if(edit_cnt=='')
			{
				var counter=0;
			}
		
			for(var j=0; j<counter; j++)
			{
				if(document.getElementById('empid_'+j).value==id)
				{
					alert("Duplicate Value"); 
					document.getElementById("row_id_"+ctr).checked=false;
					var dup = "dup";
					break;
				}
			}
                       
                        if(dup=='empty')
			{	
				var data=addRow('emp_dataTable');
				document.getElementById('empid').value = id;
				document.getElementById('empcode').value = empcode;
				document.getElementById('empname').value = empname;	
				document.getElementById('department').value =desig ;		
				document.getElementById('designation').value =dept ;					
				//document.getElementById('instrumentname').value = desc;		
			}
                        }
                        else
		{
		
		
			for(var i=counter; i<=empcount; i++)
			{	
			
			
				if(edit_cnt=='')
				{
					var counter=0;
				}
				for(var j=0; j<counter; j++)
				{}
				if(document.getElementById('empid'))
				{
				if(document.getElementById('empid').value==id)
				{
					alert("Duplicate Value");
					document.getElementById("row_id_"+ctr).checked=false;
					break;
				}
				}
				/*if(document.getElementById('itemid1_'+i))
				{
				if(document.getElementById('itemid_'+i).value==id)
				{
					alert("Duplicate Value"); 
					document.getElementById("row_id_"+ctr).checked=false;
					break;
				}
				}*/
				
				if(dup=='empty')
				{
				if(!document.getElementById('empid_'+i))
				{	
					
				var data= addRow('emp_dataTable');	
				}
					if(document.getElementById('empid_'+i))
					{	
					
					if(document.getElementById('empid_'+i).value=='')
					{	
						document.getElementById('empid_'+i).value = id;
                                                document.getElementById('empcode_'+i).value = empcode;
                                                document.getElementById('empname_'+i).value = empname;	
                                                document.getElementById('department_'+i).value =desig ;	
                                                document.getElementById('designation_'+i).value =dept ;
												
						break;
					}
					}
					else
					{
						continue;
					}
				}
			}
		
			
             }
        }
}


function addRow(tableID) 
{	
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=rowCount;
	var row1=document.getElementById("rowcount1").value;
	var rr=parseInt(row1)+1;
	document.getElementById("rowcount1").value=rr;
	document.getElementById("edit_cnt").value=rr;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {	
	//var newCount=parseInt(rowCount)+parseInt(edit_cnt)-1;
	var newCount=parseInt(rowCount);
	var newcell = row.insertCell(i);
	//newcell.style.background='#e7e7e7';
	newcell.className='tabledata';
	$('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
	newcell.innerHTML = table.rows[0].cells[i].innerHTML;
	switch(newcell.childNodes[0].type) 
	{
	case "text":
	newcell.childNodes[0].value = "";
	//var nod_id = newcell.childNodes[0].id;
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	//newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	
	//newcell.childNodes[0].name = newcell.childNodes[0].name;
	
	break;
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id =nod_id[0]+'_'+rr;
	
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	
	break;
	case "select-one":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id =nod_id[0]+'_'+rr;
	
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}	
}

function deleteRowOrder(tableID) 
{
	try 
	{
	var table = document.getElementById(tableID);
	//alert(table);
	var rowCount = table.rows.length;
	//alert(rowCount);
	for(var i=0; i<rowCount; i++) 
	{
	var row = table.rows[i];
	var chkbox = row.cells[0].childNodes[0];
	if(null != chkbox && true == chkbox.checked) 
	{
	if(rowCount <= 1) 
	{
	alert("Cannot delete all the rows.");
	break;
	}
	table.deleteRow(i);
	rowCount--;
	i--;
	}
	}
	document.getElementById("hiditemcount").value=(rowCount);		}
	catch(e) 
	{
	alert(e);
	}
}
</script>   
    
    