<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link href="../css/main.css" rel="stylesheet" type="text/css" />
<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/cancel_confirmation.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/upper_case.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/numbers_only_decimal.js"  type="text/javascript"></script>    

<?php
include('../include/session.php');
require_once('../include/tc_calendar.php');

date_default_timezone_set('Africa/Gaborone');
$entry_date = date("Y-m-d H:i:s", time()); 


$today = date("Y-m-d");
$record_date = strtotime($today);
$d = date("d", $record_date ) ;
$m = date("m", $record_date ) ;
$y = date("Y", $record_date ) ;


$table_name = $_SESSION['db_prefix']."_compiled_jobs";
$order_no_query = "SELECT job_card_no, project, cust_id FROM $table_name WHERE captured='yes' AND invoiced IS NULL ORDER BY job_card_no DESC";
	$order_no_result = execsql($order_no_query);
	$order_no_num = mysql_num_rows($order_no_result);
	$w = 0;
	$arrId2 = array ();
	$arrName2 = array ();
	while ($w < $order_no_num) {
		$cust_id = mysql_result($order_no_result, $w, "cust_id");
		$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = mySQL_query($customer_query);
		$customer_num = mysql_num_rows($customer_result);
			
		$a1 = mysql_result($customer_result, 0, "account_type");
			if ($a1=="corporate") { 
				$name = mysql_result($customer_result, 0, "comp_name"); 
			} 
			else {
				$name = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name");
 			}
		$arrId2[$w] = mysql_result($order_no_result, $w, "job_card_no");
		$arrName2[$w] = mysql_result($order_no_result, $w, "job_card_no").' - '.mysql_result($order_no_result, $w, "project").' - '.$name;
		$w++;
	}
?>

<script language="javascript">
function addRow2(dataTable2) {
 
            var table2 = document.getElementById(dataTable2);
 
            var rowCount = table2.rows.length;
            var row = table2.insertRow(rowCount);
			var line_no = rowCount-1;
 
            var cell1 = row.insertCell(0);
            var element21 = document.createElement("input");
            element21.type = "checkbox";
            element21.name="line_checkbox2"+line_no;
			element21.id="line_checkbox2"+line_no;
			/*element21.checked="checked";*/
            cell1.appendChild(element21);
			 
            var cell2 = row.insertCell(1);
            var element22 = document.createElement("input");
            element22.type = "text";
            element22.name = "item_text2"+line_no;
			element22.className = "text300";
			element22.value = "";
			element22.onchange = function(){document.getElementById("line_checkbox2"+line_no).checked = "checked";}
			cell2.appendChild(element22);
			
			var cell3 = row.insertCell(2);
			cell3.align="left";
            			
            var element25 = document.createElement("select");
            element25.name = "order_select2"+line_no;
			element25.id = "order_select2"+line_no;
			element25.className="select160"
			element25.onchange = function(){document.getElementById("line_checkbox2"+line_no).checked = "checked";}
			cell3.appendChild(element25);
			
			var option0 = document.createElement("option");
   				 	option0.text = ".";
    				option0.value = ".";
				element25.add(option0);
				
			
			<?php
    			for ($i = 0; $i < count($arrId2); $i++) { ?>
				
				var option<?php echo $i?> = document.createElement("option");
   				 	option<?php echo $i?>.text = "<?php echo $arrName2[$i]?>";
    				option<?php echo $i?>.value = "<?php echo $arrId2[$i]?>";
				element25.add(option<?php echo $i?>);
			<?php	
			}
			?>
			
			
			
			
			
			
				
 
            var cell4 = row.insertCell(3);
			cell4.align="right";
            var element23 = document.createElement("input");
            element23.type = "text";
            element23.name = "quantity_text2"+line_no;
			element23.className = "text60";
			element23.value = "";
			element23.style = "text-align:right";
			element23.onkeypress = function isNumberKey(evt)
       								{
          							var charCode = (evt.which) ? evt.which : event.keyCode
          							if ( charCode > 31 
            						&& (charCode < 48 || charCode > 57))
             						return false;
 
          							return true;
       								}
									;
			element23.onchange = function(){document.getElementById("line_checkbox"+line_no).checked = "checked";}
			cell4.appendChild(element23);
			
					
			var cell5 = row.insertCell(4);
			cell5.align="right";
			var element26 = document.createElement("input");
            element26.type = "text";
            element26.name = "amount_text2"+line_no;
			element26.className = "text60";
			element26.onkeypress = function isNumberKey(evt)
       								{
          							var charCode = (evt.which) ? evt.which : event.keyCode
          							if (charCode != 46 && charCode > 31 
            						&& (charCode < 48 || charCode > 57))
             						return false;
 
          							return true;
       								}
									;
			element26.onkeyup = function() {this.value = this.value.replace (/(\...).*/, '$1')};
			element26.style = "text-align:right";		

            var element24 = document.createElement("input");
            element24.type = "hidden";
            element24.name = "line_num2";
			element24.value = rowCount;
            						
			cell5.appendChild(element26);
            cell5.appendChild(element24);
			
			var element28 = document.createElement("script");
			element28.setAttribute('type', 'text/javascript');
			element28.innerHTML="var frmvalidator  = new Validator('form2');frmvalidator.EnableMsgsTogether();for (i = 0; i < 10; i++) {frmvalidator.addValidation('item_text2'+i,'req','-  item on line 2-'+(i+1)+'.');frmvalidator.addValidation('order_text2'+i,'req','-  order on line 2-'+(i+1)+'.');frmvalidator.addValidation('quantity_text2'+i,'req','- quantity on line 2-'+(i+1)+'.');frmvalidator.addValidation('amount_text2'+i,'req','- price on line 2-'+(i+1)+'.');}"; 
			document.getElementsByTagName('head').item(0).appendChild(element28);
			
			
			element21.onmouseup = function() {
				 if (document.getElementById('line_checkbox2'+line_no).checked) {
                         element22.style.background = '#F0F0F0';
						 element23.style.background = '#F0F0F0';
						 element25.style.background = '#F0F0F0';
						 element26.style.background = '#F0F0F0';
						 element22.value = '-----';
						 element23.value = '-----';
						 element25.value = '-----';
						 element26.value = '0';
						 element22.disabled = true;
						 element23.disabled = true;
						 element25.disabled = true;
						 element26.disabled = true;
						 
                } else {
                        element22.style.background = '#FFF';
						element23.style.background = '#FFF';
						element25.style.background = '#FFF';
						element26.style.background = '#FFF';
						element22.value = '';
						element23.value = '';
						element25.value = '';
						element26.value = '';
						element22.disabled = false;
						element23.disabled = false;
						element25.disabled = false;
						element26.disabled = false;
						 
                }
				};
			
}

</script>

</head>



<?php
include ("../navigation/header.php");
$page_name = "Stores-special";
include ("../navigation/access.php");
if ($permission_num==1) {
	include ("../navigation/store_sidebar.php");
?>

<body>


<div class="main_frame"  style="height:auto; min-height:570px;">

<div class="page_head_frame">
        <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><label class="label_page_head">Special orders</label></td>
            </tr>
        </table>
      </div>
        <br /><br />
        <div class="page_middle_frame">
          <div class="hidden_frame" id="hidden_frame">
  <form action="special_orders_save.php" method="GET" name="form2" id="form2">
<div class="page_inside_frame"  style="min-height:350px;"><br>
<?php $line2_num=0 ?>
    <table id="dataTable2" width="669" border="1" style="border-collapse:collapse;">
    <?php
	
	   if ($line2_num==0) {
	       
		   $a21='';
		   $a22='';
		   $a23='';
		   $a24='';
	   }
	   else {
		   
		   $a21 = mysql_result($line2_result, 0, "item_name");
		   $a22 = mysql_result($line2_result, 0, "quantity");
		   $a23 = mysql_result($line2_result, 0, "price");
		   $a24 = mysql_result($line2_result, 0, "order_no");
	   }
		?>
    <thead> 
        <tr>
          <td>&nbsp;</td>
          <td>Special orders</td>
          <td>Order no / Customer</td>
          <td>Quantity</td>
          <td>Unit price</td>
        </tr>
        </thead>
        <script>
			 function check_it2() {
				 if (document.getElementById('line_checkbox20').checked) {
                         document.getElementById('item_text20').style.background = '#F0F0F0';
						 document.getElementById('order_text20').style.background = '#F0F0F0';
						 document.getElementById('quantity_text20').style.background = '#F0F0F0';
						 document.getElementById('amount_text20').style.background = '#F0F0F0';
						 document.getElementById('item_text20').value = '.';
						 document.getElementById('order_text20').value = '.';
						 document.getElementById('quantity_text20').value = '.';
						 document.getElementById('amount_text20').value = '.';
						 document.getElementById('item_text20').disabled = true;
						 document.getElementById('order_text20').disabled = true;
						 document.getElementById('quantity_text20').disabled = true;
						 document.getElementById('amount_text20').disabled = true;
						 
                } else {
                        document.getElementById('item_text20').style.background = '#FFF';
						document.getElementById('order_text20').style.background = '#FFF';
						 document.getElementById('quantity_text20').style.background = '#FFF';
						 document.getElementById('amount_text20').style.background = '#FFF';
						 document.getElementById('item_text20').value = '';
						 document.getElementById('order_text20').value = '';
						 document.getElementById('quantity_text20').value = '';
						 document.getElementById('amount_text20').value = '';
						 document.getElementById('item_text20').disabled = false;
						 document.getElementById('order_text20').disabled = false;
						 document.getElementById('quantity_text20').disabled = false;
						 document.getElementById('amount_text20').disabled = false;
                }
				}
		     </script>
        <tr>
            <td width="20"><input type="checkbox" name="line_checkbox20" id="line_checkbox20" onMouseUp="check_it2()"  /></td>
          <td width="302"><input  name="item_text20" type="text" class="text300" id="item_text20" value="" onChange="document.getElementById('line_checkbox20').checked=true;"/></td>
          <td width="169" align="left">
            <select name="order_select20" id="order_select20" class="select160">
              <option value="." selected="selected"> </option>
              <?php 
    	for ($w = 0; $w < count($arrId2); $w++) {
		echo "<option value=\"".$arrId2[$w] . "\"" . ">" . $arrName2[$w] . "</option>";	
	    }
     ?>
            </select>
          </td>
            <td width="64" align="right"><input  name="quantity_text20" type="text" class="text60" id="quantity_text20" value="" style="text-align:right" onKeyPress="return numbersonly(this, event)"/></td>
            <td width="80" align="right"><input  name="amount_text20" type="text" class="text60" id="amount_text20" value="" onKeyPress="return isNumberKey(event)" onKeyUp=" this.value = this.value.replace (/(\...).*/, '$1')" style="text-align:right"/><input type="hidden" name="line_num2" id="line_num2" value="1" >
        
            

        </td>    
            <!--<input name="textfield0" type="text" id="textfield0" size="5" value="1"></td>-->
        </tr>
        <?php
		$i=1;
		while ($i<$line2_num) {
		   $a21 = mysql_result($line2_result, $i, "item_name");
		   $a22 = mysql_result($line2_result, $i, "quantity");
		   $a23 = mysql_result($line2_result, $i, "price");
		   $a24 = mysql_result($line2_result, $i, "order_no");
		?>
        <?php
		$i++;
		}
		?>
        
  </table>
  
    <input type="button" class="imagebutton" onClick="addRow2('dataTable2')" value="Add line" />
    <div align="right">
      <label class="label_small">To delete a line: uncheck line box.</label></div>
  
					
				
  </div>
<div class="page_inside_frame">
  <table width="645" border="0">
    <tr>
      <td width="20"></td>
      <td width="615" align="right"><input name="button2" type="button" class="imagebutton" id="button2" onclick="cancel_confirmation(3, '../store/store_main.php?date=0');" value="Close"/>
        <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> 
<script language="JavaScript" type="text/javascript" xml:space="preserve">
 for (j = 0; j < 20; j++) {
	frmvalidator.addValidation("item_text2"+j,"req","- store item on store line 2-"+(j+1)+".");
	frmvalidator.addValidation("order_text2"+j,"req","- order no on store line 2-"+(j+1)+".");
	frmvalidator.addValidation("quantity_text2"+j,"req","- quantity  on store line2-"+(j+1)+".");
  	frmvalidator.addValidation("amount_text2"+j,"req","- price on store line 2-"+(j+1)+".");
	
}
</script>
</div>     
</div>
</div>

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


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