<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--reference to main.css removed-->
<?php
include ("../navigation/header.php");
$page_name = "Stores-receive edit";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/store_sidebar.php");
require_once('../include/tc_calendar.php');
include('../include/receive_item_select_header.php');



$receive_id=$_GET['receive_id'];
$error = $_GET['e'];

$table_name = $_SESSION['db_prefix']."_receive_store";
$receive_query = "SELECT *  FROM $table_name WHERE  receive_id = '".$receive_id."' ";
$receive_result = $con->query($receive_query);
$row = mysqli_fetch_assoc($receive_result);
$b0 = $row["receive_date"];
$b2 = $row["supplier_id"];
$b3 = $row["receive_id"];

$receive = strtotime($b0);
$d = date("d", $receive );
$m = date("m", $receive );
$y = date("Y", $receive );

$table_name = $_SESSION['db_prefix']."_receive_store_lines";
$line_query = "SELECT *  FROM $table_name WHERE  receive_id = '".$receive_id."' ";
$line_result = $con->query($line_query);
$line_num = mysqli_num_rows($line_result);

	
$table_name2 = $_SESSION['db_prefix']."_suppliers";
$customer_query = "SELECT * FROM $table_name2 WHERE supplier_id ='".$b2."' ";
$customer_result = $con->query($customer_query);
$row = mysqli_fetch_assoc($customer_result);
$a0 = $row["account_name"];
$a5 = $row["contact1"];
$a6 = $row["credit_cash"];
$a7 = $row["post_address"];
$a9 = $row["post_place"];
$a10 = $row["phys_address"];
$a11 = $row["phys_place"];
$a12 = $row["web_site"];
$a13 = $row["VAT_no"];
$a15 = $row["email2"];
$a23 = $row["fax"];
$a24 = $row["phone"];
$a26 = $row["country"];
$a29 = $row["email1"];
$a30 = $row["cell1"];
$a32 = $row["cell2"];
$a35 = $row["contact2"];
$a36 = $row["notes"];

$supplierTT =
		   "<table id=table_tool_tip width=250 ><tr><td  width=75>Name:</td><td width=175>".$a0."</td></tr><tr><td>Address:</td><td>".$a7."</td></tr><tr><td></td><td>".$a9."</td></tr><tr><td>Contact:</td><td>".$a5."</td></tr><tr><td>Phone:</td><td>".$a24."</td></tr><tr><td>Cell:</td><td>".$a30."</td></tr></table><br><b>Click for details</b>";   




?>
<!--style sheets-->

<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />

<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/numbers_only_decimal.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script> 
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script> 
<script language="javascript" src="../jscript/calendar.js"></script>  


</head> 

<body  onLoad="initCS(); <?php if ($error==1) { ?> alertMessage(1, '', 'This product is already in the list. Edit the quantity and/or unit price.'); <?php } ?>">
<div class="main_frame" style=" height:auto; min-height:560px;">
<div class="page_head_frame">
          <table width="809" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><label class="label_page_head">Edit received:</label>
                &nbsp;&nbsp;&nbsp;
                <label class="label_page_head_2"> <?php echo $a0 ?></label></td>
            </tr>
          </table>
        </div>
<form name="form1"  id="form1" action="edit_receive_save.php" method="get">                   
        <div class="page_middle_frame">
          <table width="592" id="table_display" >
            <tr>
              <td width="114" align="left" valign="top">Received from:</td>
              <td width="155" align="left" valign="top"><a href="displaySupplier.php?supplier_id=<?php echo $b2 ?>" onMouseover="ddrivetip('<?php echo $supplierTT ?>', 200)"; onMouseout="hideddrivetip()"><?php echo $a0?></a></td>
              <td width="51" align="left" valign="top">Date:</td>
              <td width="252" align="left" valign="top"><?php

		$myCalendar = new tc_calendar("receive_date", true);
		$myCalendar->setIcon("../images/iconCalendar.gif");
		$myCalendar->setDate($d, $m, $y);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2010, 2030);
		//$myCalendar->dateAllow('2009-02-20', "", false);
		$myCalendar->writeScript();
?></td>
            </tr>
            <tr>
              <td align="left" valign="top">Receive no:</td>
              <td align="left" valign="top"><a href="displaySupplier.php?supplier_id=<?php echo $b2 ?>" onMouseover="ddrivetip('<?php echo $supplierTT ?>', 200)"; onMouseout="hideddrivetip()"><?php echo $b3?></a></td>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
            </tr>
            <tr>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="top">&nbsp;</td>
            </tr>
            <tr>
              <td colspan="4" align="left" valign="top">&nbsp;</td>
            </tr>
          </table>
      </div>
     
<div class="page_middle_frame"> 
   
<table width="642" id="table_display" >
            <tr>
                  <td width="328" height="26" align="left" valign="top">Item</td>
                  <td width="136" align="left" valign="top">Group</td>
                  <td width="136" align="left" valign="top">Received</td>
                  <td width="136" align="left" valign="top">Unit price</td>
                </tr>
                <?php
				$i=0;
				while($row = $line_result->fetch_assoc()) {
						$a0 = $row["receive_line_id"];
						$a1 = $row["store_item_id"];
						$a2 =$row["quantity"];
					 	$a3 = $row["purchase_price"];
					 
					 $table_name = $_SESSION['db_prefix']."_store_items";
						$item_query = "SELECT item_name, unit, subCategory FROM $table_name WHERE store_item_id = '".$a1."' ";
						$item_result =$con->query($item_query);
						$row = mysqli_fetch_assoc($item_result);
							$a1a = $row['item_name'];
							$a3a = $row['unit'];
							$a4a = $row['subCategory'];
						
					 
					 
					 
								 
				 ?>
                <tr>
                  <td colspan="2" valign="middle">
                    <?php echo $a1a ?><input name="store_item_id<?php echo $i ?>" type="hidden" value="<?php echo $a1 ?>"></td>
                  <td valign="middle"><input name="quantity_text<?php echo $i ?>" id="quantity_text<?php echo $i ?>" type="text" value="<?php echo number_format($a2, 0, '.', '') ?>" class="text50" width="50px" onfocus = "this.select();" autocomplete="off"  onchange="document.getElementById('edit_monitor').value='yes'; " style="text-align:right" onKeyPress="return isNumberKey(event);" onkeyup=" this.value = this.value.replace (/(\...).*/, '$1')"> </td>
                  <td valign="middle">
                  <input type="text" name="price_text<?php echo $i ?>" id="price_text<?php echo $i ?>" class="text50" width="50px" value="<?php echo $a3; ?>" style="text-align:right" onKeyPress="return isNumberKey(event);" onkeyup=" this.value = this.value.replace (/(\...).*/, '$1')" onfocus = "this.select();" autocomplete="off"/></td>
                </tr>
                <?php 
			   $i++;
				 }
				 ?>
             <!--   <tr>
                  <td colspan="2">
                 <a href="" onmouseover="ddrivetip('Click to add a new line.', 150)"; onmouseout="hideddrivetip()" onclick= " 
                 if (document.getElementById('edit_monitor').value=='no') {
		  editwindow=dhtmlmodal.open('editBox', 'iframe', '../edit_windows/receive_edit_add_line.php?receive_id=<?php echo $receive_id ?>', 'Select product', 'width=450px,height=75px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false;
	}
	else {
		alertMessage(1, 'quotation_edit.php', 'Before adding a line, you need to save the changes you made. Click the Save button and try again.'); return false;
	}

                  "><img src="../images//line_edit.png" width="16" height="12" /><font color='#0047D4'> New line</font></a>
                   <input type="hidden" name="edit_monitor" id="edit_monitor" value="no" />
                  </td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>-->
              </table>

<div class="page_inside_frame">
      <table width="600" border="0">
    <tr>
      <td width="189">&nbsp;</td>
      <td width="401" align="right"><input type="hidden" name="receive_id" id="receive_id" value="<?php echo $receive_id ?>" />
        <input name="button2" type="button" class="imagebutton" id="button2" onClick="cancel_confirmation(3, '../store/store_main.php?date=0');" value="Close"/>
        <input name="save_button"  id="save_button" type="submit" class="imagebutton" value="Save" onClick="needToConfirm = false; confirmRefresh();" />
        <input name="save_close_button"  id="save_close_button" type="submit" class="imagebutton" value="Save &amp; Close" onClick="needToConfirm = false; confirmRefresh();"  />
	 </td>
    </tr>
  </table>
</div>
</div>
</form> 
<!--form validation-->
  <script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
     
  for (i = 0; i < 25; i++) {
	frmvalidator.addValidation("quantity_text"+i,"req","- quantity  on line "+(i+1)+".");
  	frmvalidator.addValidation("price_text"+i,"req","- price on line "+(i+1)+".");

}	
  </script>
</div>  

<?php include ('../navigation/side_bar.php'); ?>

</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
$_SESSION['denied_return'] = "sales/sales_main.php";	
include ("../navigation/sales_sidebar.php");?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>
</html>