<head>
<?php 
$table_name = $_SESSION['db_prefix']."_list_admin";
$sellers_query = "SELECT item_name FROM $table_name  ORDER BY item_name ASC";
	$sellers_result = execsql($sellers_query);
	$sellers_num = mysql_num_rows($sellers_result);
	$w = 0;
	$arrId2 = array ();
	$arrName2 = array ();
	while ($w < $sellers_num) {
		$arrId2[$w] = mysql_result($sellers_result, $w, "item_name");
		$arrName2[$w] = mysql_result($sellers_result, $w, "item_name");
		$w++;
	}
	
require_once ('../include/tc_calendar.php');	
$start = strtotime($_SESSION['acceptance_date']);
$d = date("d", $start );
$m = date("m", $start );
$y = date("Y", $start );
?>

<!--style sheets-->


<!--jscript-->
<script type="text/javascript" src="../jscript/jquery.1.4.2.js"></script>
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<script language="JavaScript" src="../jscript/upper_case.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/numbers_only_decimal.js"  type="text/javascript"></script> 
<script language="javascript" src="../jscript/calendar.js"></script>
<script type="text/javascript">
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
</script>
</head>
<?php include('../include/wait.php') ?>

<body onLoad="MM_showHideLayers('table_display_wizard2','','hide','table_display_wizard3','','hide','wait','','hide')" onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');  ">

<div class="page_middle_frame">
<form id="form1" method="get" >
     <?php if($_SESSION['quote_type']=='Project') { ?>
    <div class="wizard_frame">
    <?php
    $table_name = $_SESSION['db_prefix']."_quotation_lines";
	$line_query = "SELECT quote_item_text, quote_item_price  FROM $table_name WHERE quote_number = '".$_SESSION['quote_no']."' ";
	$line_result = mySQL_query($line_query);
	$line_num = mysql_num_rows($line_result);
	?>
    <table width="650" id="table_details_display">
            <?php 
	  $i=0;
	  $d3=0;
	  while ($i<$line_num) {
		  $d1 = mysql_result($line_result, $i, "quote_item_text");
		  $d2 = mysql_result($line_result, $i, "quote_item_price");
		  $d3 =$d3+$d2
		  ?>
            <tr>
              <td width="331"><?php echo $d1 ?></td>
              <td width="104"><div align="right"><?php echo number_format($d2, 2, '.', ',') ?></div></td>
            </tr>
            <?php
	  $i++;
	  }
	  ?>
            <tr>
              <td align="right">&nbsp;</td>
              <td align="right">&nbsp;</td>
            </tr>
            <tr>
              <td align="right"><b>Total: (excl VAT)</b></td>
              <td align="right"><b>
                <div align="right"><?php echo number_format($d3, 2, '.', ',') ?></div>
                </b></td>
            </tr>
		  </table>
                <table width="642" id="table_display_wizard">
                <tr>
                    <td valign="top">Installation by Vertex?&nbsp;
                    <label class="star">*</label></td>
                    <td valign="top">
                      <label class="label_std">
                        <input type="radio" name="install_group" value="Yes" id="install_group_0" <?php if ($_SESSION['install']=="Yes") {?>checked="checked" <?php }?>>
                        Yes</label>
                      
                      <label class="label_std">
                        <input type="radio" name="install_group" value="No" id="install_group_1" <?php if ($_SESSION['install']=="No") {?>checked="checked" <?php }?>>
                        No</label>
                                  
                    </td>
                  </tr>
                  <tr>
                    <td width="143" valign="top">Job  value:&nbsp;&nbsp;
                      <label class="star">*</label></td>
                    <td width="487" valign="top">                     
                    <input name="received_text" type="text" autofocus class="text100" id="received_text" style="text-align:right" onChange=" this.value = this.value.replace (/(\...).*/, '$1')" onKeyPress="return isNumberKey(event)" value="<?php echo $_SESSION['received']?>" tabindex="1"/>
                    &nbsp;&nbsp;(excl VAT)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Quotation value:&nbsp;&nbsp;P&nbsp;<?php echo number_format($_SESSION['value'], 2, '.', ',');?> </td>
                  </tr>
                  <tr>
                    <td>Payment terms:&nbsp;&nbsp;<label class="star">*</label></td>
                    <td valign="top"><p>
                      <label>
                        <input name="account_group" type="radio" id="account_group_0" onClick="MM_showHideLayers('table_display_wizard2','','show','table_display_wizard3','','hide'); $('#order_no_text').attr('value', '---'); $('#invoice_no_text').attr('value', '---'); $('#receipt_text').attr('value', '');" value="cash" <?php if ($_SESSION['account']=="cash") {?>checked="checked" <?php }?>/>
                        cash</label>
                      &nbsp;&nbsp;&nbsp;
                      <label>
                        <input name="account_group" type="radio" id="account_group_1" onClick="MM_showHideLayers('table_display_wizard2','','hide','table_display_wizard3','','show'); $('#order_no_text').attr('value', ''); $('#invoice_no_text').attr('value', ''); $('#receipt_text').attr('value', '---');" value="account" <?php if ($_SESSION['account']=="account") {?>checked="checked" <?php }?> />
                        account</label>
                      <br />
                    </p></td>
                  </tr>
                </table>
                </div>
                <?php } ?>
                <?php if($_SESSION['quote_type']=='Cash sale') { ?>
                <div class="wizard_frame">
                <?php 
				$table_name = $_SESSION['db_prefix']."_quotations";
				$quote_query = "SELECT quote_discount, quote_vat, transport  FROM $table_name WHERE quote_no = '".$_SESSION['quote_no']."' ";
				$quote_result = mySQL_query($quote_query);
				$quote_num = mysql_num_rows($quote_result);
				$quote_discount = mysql_result($quote_result, 0, "quote_discount");	
				$quote_vat = mysql_result($quote_result, 0, "quote_vat");	
				$transport = mysql_result($quote_result, 0, "transport");	
	
				$table_name = $_SESSION['db_prefix']."_cash_job_lines";
				$line_query = "SELECT *  FROM $table_name WHERE quote_no = '".$_SESSION['quote_no']."' ";
				$line_result = mySQL_query($line_query);
				$line_num = mysql_num_rows($line_result);				
				?>
                Cash quotation:
                <table width="640" id="table_details_display" >
                <tr>
                  <td width="133" height="26" align="left" valign="middle">Item</td>
                  <td width="109" align="left" valign="middle">Group</td>
                  <td width="94" align="left" valign="middle">Unit</td>
                  <td width="47" align="left" valign="middle">quantity</td>
                  <td width="67" align="left" valign="middle">price</td>
                  <td width="162" align="left" valign="middle">total</td>
                </tr>
                <?php
				$i=0;
				$sub_tot=0;
				$a5_total=0;
				 while ($i<$line_num){
					 $a0 = mysql_result($line_result, $i, "quote_line_id");
					 $a1 = mysql_result($line_result, $i, "store_item_id");
					 $table_name = $_SESSION['db_prefix']."_store_items";
						$item_query = "SELECT item_name, unit, subCategory FROM $table_name WHERE store_item_id = '".$a1."' ";
						$item_result = mySQL_query($item_query);
						$a1a = mysql_result($item_result, 0, "item_name");
						$a3a = mysql_result($item_result, 0, "unit");
						$a4a = mysql_result($item_result, 0, "subCategory");
					 $a2 = mysql_result($line_result, $i, "quantity");
					 $a3 = mysql_result($line_result, $i, "price_2");
					 
					$a5=$a2*$a3;
					$a5_total=$a5_total+$a5;
					
					
					 
				 ?>
                <tr>
                  <td valign="middle"><?php echo $a1a ?></td>
                  <td><?php echo $a4a ?></td>
                  <td valign="middle"><?php echo $a3a ?></td>
                  <td valign="middle"><?php echo $a2 ?></td>
                  <td align="right" valign="middle"><?php echo $a3. "  /" .$a3a ?>&nbsp;</td>
                  <td align="right" valign="middle"><?php echo number_format($a5, 2, '.', ',')?></td>
                </tr>
                <?php 
			   // $a6_total=$a6_total+$a6;
				$i++;
				 }
				 ?>
                <tr>
                  <td colspan="3" align="left" valign="middle">&nbsp;</td>
                  <td colspan="2" align="left" valign="middle">Sub total:</td>
                  <td align="right" valign="middle"><input type="hidden" name="sub_total" id="sub_total" value="<?php echo $a5_total?>">                    <input type="text" name="sub_total_text" id="sub_total_text" class="text80" style="border:hidden; text-align:right" readonly  value="<?php echo number_format($a5_total, 2, '.', ',') ?>">                    </td>
                </tr>
                <tr>
                  <td colspan="3" align="right" valign="middle">&nbsp;<?php $discount_amount = $a5_total * ($quote_discount / 100 ) ?></td>
                  <td colspan="2" align="left" valign="middle">Discount: 
                    <?php echo $quote_discount ?>
                  %</td>
                  <td align="right" valign="middle"><input type="text" name="discount_text" id="discount_text" class="text80" style="border:hidden; text-align:right" readonly  value="<?php echo number_format($discount_amount, 2, '.', ',') ?>">                    </td>
                </tr>
                <tr>
                  <td colspan="3" align="left" valign="middle">&nbsp;<?php $sub_total = $a5_total - $discount_amount ?></td>
                  <td colspan="2" align="left" valign="middle">Sub total:</td>
                  <td align="right" valign="middle"><input type="text" name="sub_total2_text" id="sub_total2_text" class="text80" style="border:hidden; text-align:right" readonly  value=" <?php echo number_format($sub_total, 2, '.', ',') ?>"></td>
                </tr>
                <tr>
                  <td colspan="3" align="right" valign="middle">&nbsp;</td>
                  <td colspan="2" align="left" valign="middle">Transport: </td>
                  <td align="right" valign="middle"><input type="text" name="transport_text" id="transport_text" class="text60"  autocomplete="off" onfocus = "this.select();" onKeyPress="return isNumberKey(event)" onKeyUp=" this.value = this.value.replace (/(\...).*/, '$1'); document.getElementById('transport').value = document.getElementById('transport_text').value; " onBlur="calc_discount1()" style="border:hidden; text-align:right" readonly value=" <?php echo number_format($transport, 2, '.', ',') ?>" ></td>
                </tr>
                <tr>
                  <td colspan="3" align="left" valign="middle"><?php $sub_total3 = $sub_total + $transport ?></td>
                  <td colspan="2" align="left" valign="middle">Sub total:</td>
                  <td align="right" valign="middle">
                  <input type="text" name="sub_total3_text" id="sub_total3_text" class="text80" style="border:hidden; text-align:right" readonly  value="<?php echo number_format($sub_total3, 2, '.', ',') ?>"></td>
                </tr>
                <tr>
                  <td colspan="3" align="left" valign="middle">&nbsp;<?php $vat_amount = $sub_total3 * ($quote_vat/100) ?></td>
                  <td colspan="2" align="left" valign="middle">VAT @ <?php echo $quote_vat ?>%                  </td>
                  <td align="right" valign="middle"><input type="text" name="vat_text" id="vat_text" class="text80" style="border:hidden; text-align:right" readonly  value="<?php echo number_format($vat_amount, 2, '.', ',') ?>">                    </td>
                </tr>
                <tr>
                  <td colspan="3" align="left" valign="middle">&nbsp;<?php $all_total = $sub_total3 + $vat_amount ?></td>
                  <td colspan="2" align="left" valign="middle">Total:</td>
                  <td align="right" valign="middle"><input type="text" name="all_total_text" id="all_total_text" class="text80" style="border:hidden; text-align:right" readonly  value="<?php echo number_format($all_total, 2, '.', ',') ?>" >
				</td> 
                </tr>
              </table><br>
<br>

    <table width="642" id="table_display_wizard">
                  <tr>
                    <td width="143" valign="top">Quotation value:</td>
                    <td width="487" valign="top">&nbsp;&nbsp;P&nbsp;<?php echo number_format($all_total, 2, '.', ',') ?> (incl VAT) 
                    <input type="hidden" name="received_text" id="received_text" value="<?php echo $all_total ?>">
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(Basic quotation value: P <?php echo number_format($sub_total, 2, '.', ',') ?>) <?php $_SESSION['value'] = $sub_total ?> </td>
                  </tr>
                  <tr>
                    <td>Payment terms:&nbsp;&nbsp;<label class="star">*</label></td>
                    <td valign="top"><p>
                      <label>
                        <input name="account_group" type="radio" id="account_group_0" onClick="MM_showHideLayers('table_display_wizard2','','show','table_display_wizard3','','hide'); $('#order_no_text').attr('value', '---'); $('#invoice_no_text').attr('value', '---'); $('#receipt_text').attr('value', '');" value="cash" <?php if ($_SESSION['account']=="cash") {?>checked="checked" <?php }?>/>
                        cash</label>
                      &nbsp;&nbsp;&nbsp;
                      <label>
                        <input name="account_group" type="radio" id="account_group_1" onClick="MM_showHideLayers('table_display_wizard2','','hide','table_display_wizard3','','show'); $('#order_no_text').attr('value', ''); $('#invoice_no_text').attr('value', ''); $('#receipt_text').attr('value', '---');" value="account" <?php if ($_SESSION['account']=="account") {?>checked="checked" <?php }?> />
                        account</label>
                      <br />
                    </p></td>
                  </tr>
                </table>          
              
    </div>
                <?php } ?>
                
    <div class="wizard_frame">
                <table width="582" id="table_display_wizard2">
                  <tr>
                    <td width="131" valign="top"><label class="label_std">Receipt no:</label>&nbsp;&nbsp;<label class="star">*</label> </td>
                    <td width="439" valign="top"><input name="receipt_text" type="text" class="text150" id="receipt_text" onKeyUp="ToUpper(this)"  value="<?php echo $_SESSION['receipt']?>"/></td>
                  </tr>
                </table>
                <table width="309" id="table_display_wizard3">
                  <tr>
                    <td width="140" valign="top"><label class="label_std">Order  no:</label>&nbsp;&nbsp;<label class="star">*</label> </td>
                    <td width="157" valign="top"><input name="order_no_text" type="text" class="text150" id="order_no_text" onKeyUp="ToUpper(this)"  value="<?php echo $_SESSION['order']?>"/></td>
                  </tr>
                </table>
                </div>
                <br />
                <div class="wizard_frame">
                <table width="582" id="table_display_wizard">
                  <tr>
                    <td width="131" valign="top">Accepted by:&nbsp;&nbsp;<label class="star">*</label></td>
                    <td width="439" valign="top"><select name="acceptor_select" id="acceptor_select" class="select160" tabindex="2">
                      <option value="<?php echo $_SESSION['acceptor']?>" selected="selected"><?php echo $_SESSION['acceptor']?></option>
                      <?php 
    	for ($w = 0; $w < count($arrId2); $w++) {
		echo "<option value=\"".$arrId2[$w] . "\"" . ">" . $arrName2[$w] . "</option>";	
	    }
     ?>
                    </select></td>
                  </tr>
                  <tr>
                    <td valign="top">Order date:</td>
                    <td valign="top"><?php 
				  //instantiate class and set properties
		$myCalendar = new tc_calendar("acceptance_date", true);
		$myCalendar->setIcon("../images/iconCalendar.gif");
		$myCalendar->setDate($d, $m, $y);
		$myCalendar->setYearInterval(2014, 2090);
		//output the calendar
		$myCalendar->writeScript();
?></td>
                  </tr>
                </table>
             </div>   
            <br>
<br>
<br>

           <table width="675" height="50" align="center" id="table_button_bar">
                <tr>
                  <td width="117"><input type="button" name="lastprev_button" class="imagebutton" value="Prev" onClick="needToConfirm = false;MM_showHideLayers('wait','','show');MM_goToURL('parent','acceptanceWizbase.php?s=&amp;p=3');return document.MM_returnValue" tabindex="4"/></td>
                  <td width="115">&nbsp;</td>
                  <td width="99"><span class="wizard">
                    <input name="s" type="hidden" id="s" value="4" />
                    <input name="p" type="hidden" id="p" value="4" />
                  </span></td>
                  <td width="125"><input name="cancel_button" type="button" class="imagebutton" id="cancel_button" onClick="editwindow=dhtmlmodal.open('editBox', 'iframe', '../edit_windows/undo_quote.php?quote_no=<?php echo $_SESSION['quote_no'] ?>&status=cancel&p=4', 'Cancel create job', 'width=500px,height=125px,center=1,resize=0,scrolling=0')
needToConfirm = false;
editwindow.onclose=function(){return window}; return false; MM_showHideLayers('wait','','show');" value="Cancel" tabindex="5"/></td>
                  <td width="110" align="left"><input type="submit" name="next_button" class="imagebutton" value="Next" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');" tabindex="3"/></td>
                </tr>
              </table>
</form>
</div>

<!--form validation-->
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("install_group","selone","Please select Vertex to install.");
  frmvalidator.addValidation("received_text","req","Please enter amount.");
  frmvalidator.addValidation("account_group","selone","Please select cash or account.");
  frmvalidator.addValidation("receipt_text","req","Please enter receipt no.");
  frmvalidator.addValidation("order_no_text","req","Please enter order no.");
  frmvalidator.addValidation("acceptor_select","req","Please select accepted by.");
</script>
</body>