<?php session_start();?>
<?php require_once('open_connection.php');?>
<link href="css/gridtable.css" rel="stylesheet" type="text/css" />
<link href="css/imagetable.css" rel="stylesheet" type="text/css" />
<!--link href='blue/style.css' rel='stylesheet' type='text/css' /-->
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script>
	$(function() {
		$("#quotation_date_from").datepicker({ dateFormat: 'yy-mm-dd' });
		$( "#format" ).change(function() {
		 var minValue = $(this).val();
		  minValue = $.datepicker.parseDate("yy-mm-dd", minValue);
            minValue.setDate(minValue.getDate()+1);
			$( "#invoice_date").datepicker( "option", "dateFormat", $( this ).val() );
		});
		$("#quotation_date_to").datepicker({ dateFormat: 'yy-mm-dd' });
		$( "#format" ).change(function() {
		 var maxValue = $(this).val();
		  maxValue = $.datepicker.parseDate("yy-mm-dd", maxValue);
            maxValue.setDate(maxValue.getDate()+1);
			$( "#invoice_date").datepicker( "option", "dateFormat", $( this ).val() );
		});
	});
	</script>  					
<!DOCTYPE html>
<html>
<head>
      <title>PICCSB e-Directory System</title>

</head>
<body bgcolor="#333333"> 
<table width="100%" border="0" align="center">
<tr>
<td width="15%" bgcolor="#333333">&nbsp;</td>
<td width="70%" align="center" bgcolor="#FFFFFF" > 

<table width="100%" border="0" align="center">

<!-- row for header picc 1 -->
<tr>  
     <th width="100%" colspan="4"><img src="images/header-cox.jpg" width="100%" height="auto"></th>
</tr>

<!-- row for header picc 2 -->
<tr>
     <th width="100%" colspan="4"><img src="images/eoffice-cox.jpg" width="100%" height="auto"></th>
</tr>
<!-- calling frame -->	
<tr>
    <td colspan="1" width="10%" align="center"><!--?php include("header.php");?--></td>
	
</tr>
<tr>

<td colspan="3" width="90%" align="center" >
<tr><td align="left">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<?php
$username=$_SESSION['username'];
echo 'Welcome: '.$username;
?>
 <?php
                    $userid=mysql_query("select * from tbl_dir_user where user_name='$username'")or die(mysql_errno());
                    $row2=mysql_fetch_array($userid);
                    $user_id=$row2['user_id'];
					
                ?>
							<a href="cust_FnB_Login.php"><img src="images/logout3.gif" align="right"></a>
							<!--a href="cust_FnB.php"><img src="images/back-button.png" align="right" width="50" height="30"></a-->
							</td>
</tr>
<tr><td>
<h2 align="center">FOOD AND BEVERAGE QUOTATION</h2>

<form method="post" onSubmit="return validateForm(this);">
		<?php
$quotation_id=$_GET['quotation_id'];
//echo $quotation_id;
?>
<?php
       $quotation= "SELECT * FROM tbl_dir_fnb_customer LEFT JOIN tbl_dir_fnb_rquotation ON tbl_dir_fnb_customer.cust_id=tbl_dir_fnb_rquotation.cust_id 
	                WHERE tbl_dir_fnb_rquotation.quotation_id='$quotation_id'";											
				$result1 = mysql_query($quotation);		
				    $row1=mysql_fetch_array($result1);
			    $quotation_id=$row1['quotation_id'];
			         $cust_id=$row1['cust_id'];
	     $quotation_date_from=$row1['quotation_date_from'];
		   $quotation_date_to=$row1['quotation_date_to'];	
		   $quotation_remarks=$row1['quotation_remarks'];
		?>
		
		<script type="text/javascript">
function validateForm(oForm)
{
	var reitem_qty = /\d+/gi;
	//var reitem_unit_price = /\d+/gi;
	if(!reitem_qty.test(oForm.item_qty.value))
	{
		alert("Please key in number in the quantity");
		return false;
	}
	
	/*if(!reitem_unit_price.test(oForm.item_unit_price.value))
	{
		alert("Please key in number in the price per unit");
		return false;
	}*/
		
	return true;
}

</script>

<table align=center class="gridtable" >
			<tr>
            <th width="13%" scope="col">Customer Name </th>
            <th width="11%" scope="col">Quotation ID </th>
			<th width="20%" scope="col">Date</th>
			<!--th width="21%" scope="col">Quotation No: </th-->
            <th width="20%" scope="col">Remarks</th>
          </tr>
		  
          <tr>
            <td><div align="center"><?php echo $row1['cust_name']?></div></td>
            <td>
			 <label class="control-label" for="input01"></label><label for="to">
			 <div align="center">
			   <?php echo $quotation_id ?>		      </div>
			 </label></td>
			<td align="center"><?php echo $quotation_date_from; ?> <strong>to</strong> <?php echo $quotation_date_to; ?> </td>
			<!--td>Cafe@picc <input type="text" size="5" maxlength="5" name="quotation_id"></td-->
            <td align="center"><label><!--input type="text" size="5" maxlength="5" name="cust_id" value="<!--?php echo $row['cust_id']?>"-->
                <?php echo $quotation_remarks; ?></label></td>
          </tr> 
		   <tr >
              <td width="80%" colspan="2"><div align="center"><strong>Description</strong></div></td>
              <td width="20%"><div align="center"><strong>Quantity</strong></div></td>
              <td width="20%"><div align="center"><strong>Unit Price</strong></div></td>
            </tr>
             <tr>
              <td colspan="2"><div align="center">
                <input type="text" size="50"  name="item_description"required>
						

              </div></td>
              <td><div align="center">
                <input type="text" size="5" maxlength="10" name="item_qty">
			
              </div></td>
              <td><div align="center">
                <input type="text" size="10" maxlength="10" name="item_unit_price">
			
              </div></td>
            </tr>
			<tr><td colspan="4" align="center">
			<div align="center"><button name="save" class="mybutton">Save</button> &nbsp;
			<a href="quotation_chooseDate_Ramadhan.php?cust_id=<?php echo $cust_id?>" class="mybutton">Back </a>
		</div>
		  </td></tr>
</table>

</form>
<br>

<!--hr /-->
<div align="right">
<?php

            if (isset($_POST['save'])){
			
			
			            
			                  $quotation_id=$row1['quotation_id'];
			                       $user_id=$row2['user_id'];
				          $item_description=trim($_POST['item_description']);
				                  $item_qty=trim($_POST['item_qty']); 
				          $item_unit_price=trim($_POST['item_unit_price']);
				               $item_total=$item_qty*$item_unit_price;
						
            $item="insert into tbl_dir_fnb_ritem
	    		 (item_id,quotation_id,user_id,item_description,item_qty,item_unit_price,item_total) 
                  values ('$item_id','$quotation_id','$user_id','$item_description','$item_qty','$item_unit_price','$item_total')";
				  
		  $total="update tbl_dir_fnb_ritem SET tbl_dir_fnb_ritem.item_total=(SELECT SUM(item_total) )
					             WHERE  tbl_dir_fnb_ritem.quotation_id='$quotation_id'";

  /*$update_total="update tbl_dir_fnb_item SET tbl_dir_fnb_item.item_total_value=(SELECT SUM(item_total) )
 				 WHERE  tbl_dir_fnb_item.quotation_id='$quotation_id'";*/
		
			$result2= mysql_query($item);
			$result3= mysql_query($total);
			//$result= mysql_query($update_total);
		 
		 if ($result2 && $result3 ){
		 		echo "<script language='javascript'>window.location='quotation_addOrder_Ramadhan.php?quotation_id=$quotation_id'</script>";}
			else{
				echo 'Unsuccessful, please try again';}
    }  
	
?>
<?php

			$rowsPerPage =10; 
				$pageNum = $_REQUEST['page']; 
				if(empty($pageNum))
						{
					$offset =0;
					$pageNum=1;
						}
				else
						{
					$offset = ($pageNum - 1) * $rowsPerPage;
						}	
					$result3=mysql_query("SELECT * from tbl_dir_fnb_ritem WHERE quotation_id='$quotation_id' ORDER BY item_id DESC  LIMIT $offset, $rowsPerPage"); 
		                  $i=$offset;
					echo "<center><table border=1 width=56% align=center class=gridtable >";
					echo"<tr><th  width=100>No</th><th  width=500>Desciption</th><th  width=200>Quantity</th><th width=200>Unit Price</th>
						<th  width=300>Total</th><th  width=400>ACTION</th></tr>";
					$item_total_value=0;
					while(@$row=mysql_fetch_array($result3))
						{
				          $item_id = $row['item_id']; 
		 	     $item_description = $row['item_description'];
		                 $item_qty = $row['item_qty'];
		          $item_unit_price = $row['item_unit_price'];
			           $item_total = $row['item_total'];
		       
			 	   $sum += $item_total;
				   //$gst=0.06*$sum;
				    $rgst=number_format((float)$sum, 2, '.', ''); 
				   //$gtotal=$sum+$rgst;
				   //$rgtotal= round($gtotal,2);
				   
				   $rgtotal=number_format((float)$rgst, 2, '.', '');  
			$i++;
					echo"<tr>";
					echo "<td align= center >".$i."</td>";
					echo "<td align=center width=500>".$row['item_description']."</td>";
					echo "<td align=center width=100>".$row['item_qty']."</td>";
					echo "<td align=center width=100>"."RM ".$row['item_unit_price']."</td>";
					echo "<td align=left width=100>"."RM ".$row['item_total']."</td>";
					echo"<td align=center width=200> <a href='cust_edit_item_Ramadhan.php?item_id=".$row['item_id']."'>EDIT</a>
						 <a href='cust_del_item_Ramadhan.php?quotation_id=".$row['quotation_id']."'>DELETE</a></td>";
					echo "<tr>";	
				}	
				/*echo"<tr>";
				    echo "<td colspan=4 align= right>"."Goods & Services Tax (GST 6%) "."</td>";
					echo "<td colspan=2 align=left>"."RM ".$rgst."</td>";
		     		echo"</tr>";*/
					echo"<tr>";
				    echo "<td colspan=4 align= right>"."Total "."</td>";
					echo "<td colspan=2 align=left>"."RM ".$rgtotal."</td>";
		     		echo"</tr>";
					echo "</table>";
					
					
 ?>
	<br /><br /><a href="cust_FnB_print_Ramadhan.php<?php echo '?quotation_id='.$quotation_id; ?>" class="btn btn-large"><i class="icon-file icon-large"></i>&nbsp;Display Current Quotation</a>   
 
</body>

  </td></tr>
  
  </div>
  </td></tr>
<!-- row for footer -->	
<tr>
	<th align="center" colspan="4">
<?php include ('footer.php'); ?>
		
	</th>
</tr>

<!--- end for ruang kerja 80% -->
</table> 

</td>

<td width="15%" bgcolor="#333333">&nbsp;</td>

</tr>

<!--- end for ruang kerja 100% -->
</table>

</body>
</html>
