<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
include('../include/session.php');

$purchase_id=$_GET['purchase_id'];

$table_name = $_SESSION['db_prefix']."_purchase";
$purchase_query = "SELECT *  FROM $table_name WHERE  purchase_id = '".$purchase_id."' ";
$purchase_result = mySQL_query($purchase_query);
$b0 = mysql_result($purchase_result, 0, "purchase_date");
$b1 = mysql_result($purchase_result, 0, "delivery_note");
$b2 = mysql_result($purchase_result, 0, "supplier_id");
$b3 = mysql_result($purchase_result, 0, "value");
$b5 = mysql_result($purchase_result, 0, "purchase_order");
$b6 = mysql_result($purchase_result, 0, "ordered_by");
$b7 = mysql_result($purchase_result, 0, "authorised_by");
$b8 = mysql_result($purchase_result, 0, "authorised");
$b9 = mysql_result($purchase_result, 0, "authorised_date");
$b10 = mysql_result($purchase_result, 0, "company");

require_once ('../include/tc_calendar.php');
$start = strtotime($b0);
$d = date("d", $start );
$m = date("m", $start );
$y = date("Y", $start );


$table_name = $_SESSION['db_prefix']."_purchase";
$check_query = "SELECT purchase_id FROM $table_name WHERE  delivery_note = '".$b1."' AND supplier_id = '".$b2."' ";
$check_result = mySQL_query($check_query);
$check_num = mysql_num_rows($check_result);
	  
	 $table_name = $_SESSION['db_prefix']."_purchase_lines";
	 $line_query = "SELECT *  FROM $table_name WHERE  purchase_id = '".$purchase_id."' AND store_item_id>0";
	 $line_result = mySQL_query($line_query);
	 $line_num = mysql_num_rows($line_result);
	 
	 $table_name = $_SESSION['db_prefix']."_purchase_lines";
	 $line2_query = "SELECT *  FROM $table_name WHERE  purchase_id = '".$purchase_id."' AND store_item_id=0";
	 $line2_result = mySQL_query($line2_query);
	 $line2_num = mysql_num_rows($line2_result);
	 
$table_name = $_SESSION['db_prefix']."_list_names_admin";
    $position_query = "SELECT item_name FROM $table_name ORDER BY item_name ASC";
	$arrId0 = array ();
	$arrName0 = array ();
	$position_result = execsql($position_query);
	if ($position_result!="") {
	$position_num = mysql_num_rows($position_result);
	$b = 0;
	while ($b < $position_num) {
		$arrId0[$b] = mysql_result($position_result, $b, "item_name");
		$arrName0[$b] = mysql_result($position_result, $b, "item_name");
		$b++;
	}
	}		 
	 
	 
$table_name = $_SESSION['db_prefix']."_suppliers";
$suppliersQuery = "SELECT supplier_id, account_name FROM $table_name  ORDER BY account_name ASC";
	$suppliersResult = execsql($suppliersQuery);
	$suppliersNum = mysql_num_rows($suppliersResult);
	$w = 0;
	$arrId1 = array ();
	$arrName1 = array ();
	while ($w < $suppliersNum) {
		$arrId1[$w] = mysql_result($suppliersResult, $w, "supplier_id");
		$arrName1[$w] = mysql_result($suppliersResult, $w, "account_name");
		$w++;
	}
	 
	
$table_name2 = $_SESSION['db_prefix']."_suppliers";
$customer_query = "SELECT * FROM $table_name2 WHERE supplier_id ='".$b2."' ";
$customer_result = mySQL_query($customer_query);
$customer_num = mysql_num_rows($customer_result);	

$a0 = mysql_result($customer_result, 0, "account_name");
$a5 = mysql_result($customer_result, 0, "contact1");
$a6 = mysql_result($customer_result, 0, "credit_cash");
$a7 = mysql_result($customer_result, 0, "post_address");
$a9 = mysql_result($customer_result, 0, "post_place");
$a10 = mysql_result($customer_result, 0, "phys_address");
$a11 = mysql_result($customer_result, 0, "phys_place");
$a12 = mysql_result($customer_result, 0, "web_site");
$a13 = mysql_result($customer_result, 0, "VAT_no");
$a15 = mysql_result($customer_result, 0, "email2");
$a23 = mysql_result($customer_result, 0, "fax");
$a24 = mysql_result($customer_result, 0, "phone");
$a26 = mysql_result($customer_result, 0, "country");
$a29 = mysql_result($customer_result, 0, "email1");
$a30 = mysql_result($customer_result, 0, "cell1");
$a32 = mysql_result($customer_result, 0, "cell2");
$a35 = mysql_result($customer_result, 0, "contact2");
$a36 = mysql_result($customer_result, 0, "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>";   

$page = 'purchase';
include('../include/store_item_select_header.php');
include('../include/special_item_select_header.php');
?>
<!--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/alert_message.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/confirm_exit.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/calendar.js"></script>
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script> 
 



</head>



              
<?php
include ("../navigation/header.php");
$page_name = "Stores-edit purchase";
include ("../navigation/access.php");
echo '<br>*****'.$permission_num;
if ($permission_num==1) {
	include ("../navigation/store_sidebar.php");
?>	
<body onLoad="initCS();" >	

<div class="main_frame">
  <div class="page_head_frame">
          <table width="809" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><label class="label_page_head">Edit purchase order</label>&nbsp;&nbsp;</td>
            </tr>
          </table>
          </div>
          <div class="page_middle_frame">
          <form action="edit_purchase_order_save.php" method="post" name="form1" id="form1">
        <div class="page_inside_frame">
          <table width="632" id="table_display" >
            <tr>
              <td align="left" valign="top">Purchase order for:</td>
              <td align="left" valign="top">
                <select name="company_select" id="company_select">
                  <option value="Manase">Manase</option>
                  <option value="M-works">M-works</option>
                  <option value="<?php echo $b10 ?>" selected="selected"><?php echo $b10?></option>
              </select></td>
            </tr>
            <tr>
              <td width="148" align="left" valign="top">Purchase from:</td>
              <td width="472" align="left" valign="top">
                <select name="supplier_id_select" id="supplier_id_select" class="select200">
                  <option value="<?php echo $b2 ?>" ><selected="selected"><?php echo $a0 ?></option>
                  <?php 
    	for ($w = 0; $w < count($arrId1); $w++) {
		echo "<option value=\"".$arrId1[$w] . "\"" . ">" . $arrName1[$w] . "</option>";	
	    }
     ?>
              </select>
              </td>
            </tr>
            <tr>
              <td height="31" align="left" valign="middle">Purchase order no:</td>
              <td align="left" valign="middle"><?php echo $b5 ?></td>
            </tr>
            <tr>
              <td align="left" valign="top">Date:</td>
              <td align="left" valign="top"><?php

		$myCalendar = new tc_calendar("purchase_date", true);
		$myCalendar->setIcon("../images/iconCalendar.gif");
		$myCalendar->setDate($d, $m, $y);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2010, 2030);
		$myCalendar->writeScript();
?></td>
            </tr>
            <tr>
              <td align="left" valign="top">Ordered by:</td>
              <td align="left" valign="top">
                <select name="ordered_by_select" class="select120"  >
                  <option value="<?php echo $b6 ?>" selected="selected"><?php echo $b6 ?></option>
                  <?php
        	for ($j = 0; $j < count($arrId0); $j++) {
    		echo "<option value=" . "\"" . $arrId0[$j] . "\"" . ">" . $arrName0[$j] . "</option>";
	}
?>
              </select></td>
            </tr>
          </table>
        </div>
        <div class="page_inside_frame">
        <?php
		include ('../include/store_item_select_table.php');
		?>
        </div>
        <div class="page_inside_frame">
          
          <br>
          <br>
          <?php
          include('../include/special_item_select_table.php');
		  ?><br>
<br>
</div>
<div class="page_inside_frame">
  <table width="645" border="0">
    <tr>
      <td width="20">&nbsp;</td>
      <td width="615" align="right"><input type="hidden" name="purchase_id" id="purchase_id" value="<?php echo $purchase_id ?>" />
        <input name="button2" type="button" class="imagebutton" id="button2" onClick="cancel_confirmation(3, '../store/store_main.php');" 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>  

</form>
<!--form validation-->
  <script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
     
  for (i = 0; i < 50; i++) {
	
	frmvalidator.addValidation("store_item_text"+i,"req","- store item on store line "+(i+1)+".");
	frmvalidator.addValidation("quantity_text"+i,"req","- quantity  on store line "+(i+1)+".");
  	frmvalidator.addValidation("amount_text"+i,"req","- price on store line "+(i+1)+".");
  
 
	//frmvalidator.addValidation("item_select2"+j,"req","- store item on store line 2-"+(j+1)+".");
	frmvalidator.addValidation("quantity_text2"+i,"req","- quantity  on special orders line "+(i+1)+".");
  	frmvalidator.addValidation("amount_text2"+i,"req","- price on special orders line "+(i+1)+".");
	
}	
  </script> 

</div> 
</div>
</body>
<?php } else {
$_SESSION['denied_return'] = "store/store_main.php";	
include ("../navigation/store_sidebar.php");?>
	<body onload="needToConfirm = false; accessdenied(); return false">
	</body>
<?php }
?>

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