<?php
session_name('CAKEPHP'); session_start();
$PageSecurity = 4;
$PageName = 'Add Items';
include('includes/session.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/DefineSuppTransClass.php');
date_default_timezone_set('Asia/Kolkata');
if(isset($_GET['Proceed']))
{
$record=DB_fetch_assoc(DB_query("SELECT * FROM material_slip_against_job_card WHERE id='".$_GET['del_id']."' ",$db));
if($_GET['reason_id']=="0")
	{
		DB_query("insert into reason_master (moduleid,frm_id,reason_type,reason,created_by,created_date,companyID) values ('".$_GET['modid']."','".$_GET['frm']."','3','".$_GET['other_reason']."','".$_SESSION['UserID']."','".date('y-m-d H:i:s')."','".$_SESSION['ACGCompanyId']."') ",$db);
		$lst_id=DB_Last_Insert_ID($db,'reason_master');
	}
	else{
	$lst_id=$_GET['reason_id'];
	}
	DB_query("insert into log_reason (frm_id,doc_id,doc_type,doc_date,doc_created_by,modified_date,modified_by,reason_id,company_id) values('".$_GET['frm']."', '".$_GET['del_id']."','3','".$record['created_date']."','".$record['created_by']."','".date('y-m-d H:i:s')."','".$_SESSION['UserID']."','".$lst_id."','".$_SESSION['ACGCompanyId']."')",$db);
	
DB_query("delete  from	 material_slip_against_job_card where id='".$_GET['del_id']."' ",$db);
DB_query("delete  from	 material_job_item where material_slip_id='".$_GET['del_id']."' ",$db);

echo "<script>parent.window.close();
parent.window.opener.location.href='index.php?route=material_job_cardlist&modid=10&frmid=274'</script>";	
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form method="get" action="" name="frm">
<table align="center" width="100%" border="0" cellspacing="1" cellpadding="2">
	<tr align="center">
		<td><h2>Reason To Delete</h2></td>
	</tr>
	<tr >
		<th class="tabledata" >
		<table width="30%" border="0" align="center" cellpadding="3" cellspacing="0">
  <tr>
    <th width="30%" align="left" valign="top">Reason</th>
    <td align="left" valign="top"><select  name="reason_id" id="reason_id" style="width:50%" onchange="display_reason(this.value)" >
			<option value="">--Select--</option>
			<?php $reason_query=DB_query("SELECT * FROM reason_master WHERE reason_type='3' AND companyID='".$_SESSION['ACGCompanyId']."'  and  frm_id='".$_REQUEST['frm']."'  ",$db);
			while($reason=DB_fetch_assoc($reason_query)) {?>
			<option value="<?php echo $reason['id'];?>"><?php echo $reason['reason'] ?></option>
			<?php } ?>
			<option value="0">Other..</option>
			</select></td>
  </tr>
  
  <tr style="display:none" id="other">
    <th align="left" valign="top">Other</th>
    <td align="left" valign="top"><div ><textarea rows="8" cols="15" name="other_reason" id="other_reason"></textarea></div></td>
  </tr>
  
  
</table>

		</th>
		
	</tr>
	
	<tr>
	<td align="center">
	<input type="hidden" name="modid" value="<?php echo $_GET['modid'];?>"/>
	<input type="hidden" name="del_id" value="<?php echo $_GET['del_id'];?>"/>
	<input type="hidden" name="frm" value="<?php echo $_GET['frm'];?>" />
	<input type="submit" name="Proceed" value="Proceed"  onclick="return validate1()" /></td>
	</tr>
</table>
</form>
</body>
</html>

<script type="text/javascript">
function display_reason(str)
{
	if(str=="")
	{
		alert("please select the reason");
		document.getElementById("other").style.display='none';
		return false;
	}
	else if(str==0)
	{
		document.getElementById("other").style.display='';
	}
	else
	{
		document.getElementById("other").style.display='none';
	}
}

function validate1()
{
var reason=document.getElementById("reason_id").value;
var flag=0;
	if(reason=="")
	{
		alert("Please select the reason to Delete ");
		flag=1;		
	}
	else if(reason=="0")
	{
		if(document.getElementById("other_reason").value=="")
		{
		alert ("Please Enter the Other reason");
		flag=1;
		}
	}
	if(flag==1)
	{
	return false;
	}
	else
	{
		var con=confirm("Are You Sure You Want To Delete?");
		if(con)
		{
		document.frm.submit();
		return true;
		}
		else
		{
		return false;
		}
	}
	
}
</script>
