<?php
$fstatus=true;
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;
$daction=$_REQUEST['daction'];
if($_REQUEST['Save']!='')
{
	if($_REQUEST['site']==0)
	$msgErr[]="Please select Branch Name";

	if($_REQUEST['party']==0)
	$msgErr[]="Required party";

	if($_REQUEST['formNo']=='')
	$msgErr[]="Required FormNo";

  
 if($fstatus && $_REQUEST['action']=='')
 {
	$insert1="Insert into party_form_master set
					 site='".$_REQUEST['site']."',     
					 party='".$_REQUEST['party']."',  
					 formNo='".$_REQUEST['formNo']."',  
					 formDate='".FormatDateForSQL($_REQUEST['formDate'])."',  
					 createdDate='".date('Y-m-d')."',  
					 createdBy='".$_SESSION['UserID']."',
					 CompanyId='".$_SESSION['ACGCompanyId']."'";
					
     	$result1=DB_query($insert1,$db);	
		$s->pageLocation("index.php?route=party_form_receive".$rurl.'&daction=Inserted');
	}
	 
	 if($fstatus && $_REQUEST['action']=='Edit')
	 {
		$data['site']=$_REQUEST['site'];
		$data['party']=$_REQUEST['party'];
		$data['formNo']=$_REQUEST['formNo'];
		$data['formDate']=$_REQUEST['formDate'];
		$cond=" id='".$_REQUEST['id']."'";
		$s->RecordEdit('party_form_master', $data, $cond);
		$s->pageLocation("index.php?route=party_form_receive".$rurl.'&daction=Updated');
	}
}


if($_REQUEST['action']=='Edit')
{
	$query1="select  * from party_form_master where id='".$_REQUEST['id']."'";
    $result1=DB_query($query1,$db);
 	$myrow1=DB_fetch_array($result1) ;
	$site=$myrow1['site'];
	$party=$myrow1['party'];
    $formNo=$myrow1['formNo'];
	$formDate=$myrow1['formDate'];
}





?>
<p>
<h2 align="center">Party Form Receive</h2></p>
<form action="" method="post">
<table width="65%"><tr><td bgcolor="#CCCCCC">
<table width="100%" border="0"><tr><td bgcolor="#FFFFFF">
<table width="100%" border="0" cellspacing="1" cellpadding="0" align="center"> 
   <?php if($daction){?>
   <tr>
   <td colspan="4"><div class='success' ><?php
   echo 'Record '.$daction.' Successfully';
    ?></div></td>
   </tr>
   <?php } ?>
 <?php if(count($msgErr)>0){?>
   <tr>
   <td colspan="4"><div class='error' ><?php
   for($i=0;$i<count($msgErr);$i++)
   {
     echo $msgErr[$i].'<br>';
   }
    ?></div></td>
   </tr>
   <?php } ?>
  <tr>
  	<th width="17%">Branch</th>
  	<td ><select name="site" id="site" style="width: 100%" onchange="getDispatch(this.value)">
  		<option value="0">Select</option>
  		<?php 
  		$site_sql=DB_query("Select loccode, locationname from locations",$db);
		while($site_row=DB_fetch_array($site_sql))
		{?>
		<option value="<?php echo $site_row['loccode']?>"<?php echo($site==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname']?></option>
		<?php 	
		}
  		?>
  	</select></td>
    <th width="21%" nowrap="nowrap" scope="row">Form Date</th>
    <td width="24%" nowrap="nowrap"><input name="formDate" id="formDate" type="text" value="<?php echo   $formDate;?>" class="datepicker" style="width:100%;" /></td>
    
  </tr>
  <tr>
    <th>Party </th>
    <td><select name="party"  style="width:100%;">
      <option value="0">---Select---</option>
      <?php 
	$vendor_sql=DB_query("select id,client_code,c_name from clientmaster",$db);
	while($vendor=DB_fetch_array($vendor_sql))
	{
	?>
      <option value="<?php echo $vendor['id'];?>"<?php echo ($party==$vendor['id']?'selected':'')?>><?php echo $vendor['c_name'];?></option>
      <?php } ?>
    </select></td>
    <th width="26%"><strong>Form/Permit No.</strong></th>
    <td width="29%"><input name="formNo" type="text" value="<?php echo $formNo;?>" size="12" style="width:100%;"/></td>
  </tr>
</table>
</td></tr></table></td></tr></table>


<p align="center"><input type="submit" name="Save" value="Save" /></p>
</form>

<table width="70%" cellpadding="1" cellspacing="1">
	<tr>
		<th>Branch</th>
		<th>Party</th>
		<th>Form No.</th>
		<th>Form Date</th><th>Edit</th><th>Delete</th>
	</tr>
	<?php 
	$sql=DB_query("Select * from party_form_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($myrow=DB_fetch_array($sql))
	{?>
		<tr bgcolor="#FFFFFF">
		<td><?php 
		echo $s->getField('locations','loccode',$myrow['site'],'locationname');?></td>
		<td><?php 
		echo $s->getField('clientmaster','id',$myrow['party'],'c_name');?></td>
		<td><?php echo $myrow['formNo'];?></td>
		<td><?php echo $myrow['formDate'];?></td>
		<td><a href="index.php?route=party_form_receive<?php echo $rurl; ?>&action=Edit&id=<?php echo $myrow['id'] ?>"><img src="images/icon-edit.png" width="15" height="15" /></a></td>
				<td><img src="images/Icon_Delete.png" width="15" height="15"/></td>
		</tr>
	<?php 	
	}
	?>
</table>
