<?php 
if($_REQUEST['save']){
	$SQLMax=DB_query("SELECT comlaint_no FROM dbl_coplaint order by id DESC limit 0,1",$db);
	$MaxQut=DB_fetch_array($SQLMax);
	$num=DB_num_rows($SQLMax);
	if($num>0)
	{
	$explode=explode("/",$MaxQut['comlaint_no']);
	$FinMx=$explode[1]+1;
	$FinalCode="COMP"."/".str_pad($FinMx,5,0,STR_PAD_LEFT);
	}
	else
	{
	$FinalCode="COMP"."/".'00001';
	}	
	$data['comlaint_no']=$FinalCode;
	$data['comlaint_date']=FormatDateFORSQL($_REQUEST['comlaint_date']);
	$data['complaint_category']=$_REQUEST['complaint_category'];
	$data['customer']=$_REQUEST['customer'];
	$data['product']=$_REQUEST['product'];
	$data['pick_list_no']=$_REQUEST['pick_list_no'];
	$data['pick_list_date']=FormatDateFORSQL($_REQUEST['pick_list_date']);
	$data['warranty_expiry_date']=FormatDateFORSQL($_REQUEST['warranty_expiry_date']);
	$data['expected_closing_date']=FormatDateFORSQL($_REQUEST['expected_closing_date']);
	$data['nature_of_complaint']=$_REQUEST['nature_of_complaint'];
	$data['complaint_type']=$_REQUEST['complaint_type'];
	$data['part_category']=$_REQUEST['part_category'];
	$data['part_sub_category']=$_REQUEST['part_sub_category'];
	$data['attended_by']=$_REQUEST['attended_by'];
	$data['attended_date']=FormatDateFORSQL($_REQUEST['attended_date']);
	$data['description_of_complaint']=$_REQUEST['description_of_complaint'];
	$data['corrective_action_taken']=$_REQUEST['corrective_action_taken'];
	$data['root_cause_analysis']=$_REQUEST['root_cause_analysis'];
	$data['preventive_action_taken']=$_REQUEST['preventive_action_taken'];
	$data['remarks']=$_REQUEST['remarks'];
	$data['action_required_by']=$_REQUEST['action_required_by'];
	$data['preventive_action_date']=FormatDateFORSQL($_REQUEST['preventive_action_date']);
	$data['action_date']=FormatDateFORSQL($_REQUEST['action_date']);
	$data['complaint_date']=FormatDateFORSQL($_REQUEST['complaint_date']);
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
	$data['created_by']=$_SESSION['UserID'];
	$data['created_date']=date('Y-m-d');
	//echo "<pre>";
//	print_r($data);
//	exit;
	$s->RecordInsert('dbl_coplaint', $data);
	$s->pageLocation("index.php?route=DealerDistrbutions/Transaction/complaint_form_index".$rurl);
}	

?>
<script type="text/javascript" language="javascript">
function GetProduct(val)
{
	if (window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	
	document.getElementById("product").innerHTML=xmlhttp.responseText;
	}
	}
	
	xmlhttp.open("GET","GetProducts.php?custID="+val,true);
	xmlhttp.send();

}


function GetUniquePicklist(val)
{
	if (window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("pick_list_no").innerHTML=data[0];
	document.getElementById("partca").innerHTML=data[1];
	document.getElementById("partSubca").innerHTML=data[2];
	}
	}
	xmlhttp.open("GET","GetUniquePickLis.php?itemid="+val,true);
	xmlhttp.send();

}


function picklistdetails(val)
{
	if (window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest();
	}
	else
	{
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data=xmlhttp.responseText.split("__");
	document.getElementById("pick_list_date").innerHTML=data[0];
	document.getElementById("wrrid").innerHTML=data[1];
	}
	}
	var itemid=document.getElementById("product").value;
	xmlhttp.open("GET","GetProducts.php?picklistid="+val+"&mstitemid="+itemid,true);
	xmlhttp.send();

}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Complaint Creation Form</h1>
<form name="form1" action="" method="post" >
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
    <td class="tabledata1"><strong>Complaint No</strong></td>
	<td><input type="text" name="comlaint_no" id="comlaint_no" value="Auto Generated" readonly style="width:150px;"></td>
	<td class="tabledata1"><strong>Comlaint Date </strong></td>
	<td><input type="text" name="comlaint_date" id="comlaint_date" class="datepicker" style="width:150px;"></td>
	<td class="tabledata1"><strong>Complaint Category</strong></td>
	<td><select name="complaint_category" id="complaint_category" style="width:150px;">
			<option value="">Select</option>
			<?php $SQLCC=DB_query("SELECT * FROM dbl_complaint_category where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
			while($GetCC=DB_fetch_array($SQLCC)) {?>
			<option value="<?php echo $GetCC['id']; ?>"><?php echo $GetCC['category_name']; ?></option>
			<?php }?>
		</select>	</td>
</tr>
<tr class="row1">
    <td class="tabledata1"><strong>Customer</strong></td>
	<td><select name="customer" id="customer" style="width:150px;" onChange="GetProduct(this.value)">
			<option value="">Select</option>
			<?php $SQLC=DB_query("SELECT * FROM clientmaster where dealer='".$_SESSION['dealerid']."'",$db);?>
			<?php while($Customer=DB_fetch_array($SQLC)){?>
			<option value="<?php echo $Customer['id']; ?>"><?php echo $Customer['c_name']; ?></option>
			<?php } ?>
		</select></td>
	<td class="tabledata1"><strong>Product</strong></td>
	<td><select name="product" id="product" style="width:150px;" onChange="GetUniquePicklist(this.value)">
			<option value="">Select</option>
		</select></td>
	<td class="tabledata1"><strong>Pick List No.</strong></td>
	<td><select name="pick_list_no" id="pick_list_no" style="width:150px;" onChange="picklistdetails(this.value)">
			<option value="">Select</option>
		</select></td>
</tr>
<tr class="row1">
    <td class="tabledata1"><strong>Pick List date</strong></td>
	<td id="pick_list_date"><input type="text" name="pick_list_date" id="pick_list_date" class="datepicker" style="width:150px;"></td>
	<td class="tabledata1"><strong>Warranty Expiry Date</strong></td>
	<td id="wrrid"><input type="text" name="warranty_expiry_date" id="warranty_expiry_date" class="datepicker" style="width:150px;"></td>
	<td class="tabledata1"><strong>Expected  Closing date</strong></td>
	<td><input type="text" name="expected_closing_date" id="expected_closing_date" class="datepicker" style="width:150px;"></td>
</tr>
<tr class="row1">
    <td class="tabledata1"><strong>Nature  of  Complaint</strong></td>
	<td><select name="nature_of_complaint" id="nature_of_complaint" style="width:150px;">
			<option value="">Select</option>
			<?php $SQLCC=DB_query("SELECT * FROM dbl_nature_of_complaint where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
			while($GetCC=DB_fetch_array($SQLCC)) {?>
			<option value="<?php echo $GetCC['id']; ?>"><?php echo $GetCC['nature_of_complaints']; ?></option>
			<?php }?>
		</select></td>
	<td class="tabledata1"><strong>Complaint Type</strong></td>
	<td><select name="complaint_type" id="complaint_type" style="width:150px;">
			<option value="">Select</option>
			<?php $SQLCC=DB_query("SELECT * FROM dbl_complaints_type_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
			while($GetCC=DB_fetch_array($SQLCC)) {?>
			<option value="<?php echo $GetCC['id']; ?>"><?php echo $GetCC['complaints_type']; ?></option>
			<?php }?>
		</select></td>
	<td class="tabledata1"><strong>Part category</strong></td>
	<td id="partca"><input type="text" name="part_category" id="part_category" style="width:150px;"></td>
</tr>
<tr class="row1">
    <td class="tabledata1"><strong>Part Sub Category</strong></td>
	<td id="partSubca"><input type="text" name="part_sub_category" id="part_sub_category" style="width:150px;"></td>
	<td class="tabledata1"><strong>Attended By</strong></td>
	<td><input type="text" name="attended_by" id="attended_by" style="width:150px;" /></td>
	<td class="tabledata1"><strong>Attended date</strong></td>
	<td><input type="text" name="attended_date" id="attended_date" class="datepicker" style="width:150px;" /></td>
</tr>

<tr class="row1">
    <td class="tabledata1"><strong>Description of Complaint</strong></td>
	<td colspan="2"><textarea name="description_of_complaint" id="description_of_complaint" style="width:321px;"></textarea></td>
	<td class="tabledata1"><strong>Corrective Action Taken</strong></td>
	<td colspan="2"><textarea name="corrective_action_taken" id="corrective_action_taken" style="width:321px;"></textarea></td>
</tr>
<tr class="row1">
    <td class="tabledata1"><strong>Root Cause Analysis</strong></td>
	<td colspan="2"><textarea name="root_cause_analysis" id="root_cause_analysis" style="width:321px;"></textarea></td>
	<td class="tabledata1"><strong>Preventive Action Taken</strong></td>
	<td colspan="2"><textarea name="preventive_action_taken" id="preventive_action_taken" style="width:321px;"></textarea></td>
</tr>
<tr class="row1">
    <td class="tabledata1"><strong>Remarks</strong></td>
	<td colspan="5"><textarea name="remarks" id="remarks" style="width:807px;"></textarea></td>
</tr>
<tr class="row1">
    <td class="tabledata1"><strong>Action Required By</strong></td>
	<td><input type="text" name="action_required_by" id="action_required_by" style="width:150px;"></td>
	<td class="tabledata1"><strong>Preventive Action date</strong></td>
	<td><input type="text" name="preventive_action_date" id="preventive_action_date" class="datepicker" style="width:150px;"></td>
	<td class="tabledata1"><strong>Action Date</strong></td>
	<td><input type="text" name="action_date" id="action_date" class="datepicker" style="width:150px;"></td>
</tr>
<tr class="row1">
    <td class="tabledata1"><strong>Completion Date</strong></td>
	<td colspan="5"><input type="text" name="complaint_date" id="complaint_date" class="datepicker" style="width:150px;"></td>
</tr>
<tr class="row1">
    <td class="tabledata1" style="text-align:center;" colspan="6"><input type="submit" name="save" value="Save" class="search"></td>
</table>
</form>
</div>
</div>