<head>
<?php 
if ($_SESSION['company_name']=='') {
?>
<script language="javascript" type="text/javascript">
          needToConfirm = false;
          window.location="store_no_return.php";
</script>
<?php
}
else {

$table_name = $_SESSION['db_prefix']."_cash_quotation_lines_temp";
$line_query = "SELECT *  FROM $table_name WHERE  user_name =  '".$_SESSION['username']."'";
$line_result = mySQL_query($line_query);
$line_num = mysql_num_rows($line_result);

$table_name = $_SESSION['db_prefix']."_permissions";
$permission_query = "SELECT access_id  FROM  $table_name  WHERE access_id ='". $_SESSION['access_id']."' AND page_name = 'Sales-discount' ";
$permission_result = mySQL_query($permission_query);
$permission_num = mysql_num_rows($permission_result);
if ($permission_num>0) { 
		$discount_limit = 'no'; 
}
else {
	$discount_limit = 'yes'; 
}

	$table_name = $_SESSION['db_prefix']."_customer";
    $customer_query = "SELECT comp_name, bag_box, box_no, postal_place, phone, contact_1, email_1   FROM $table_name WHERE cust_id = '".$_SESSION['id']."' ";
	$customer_result = mySQL_query($customer_query);
	
    $b1 = mysql_result($customer_result, 0, "comp_name");
	$b2 = mysql_result($customer_result, 0, "bag_box");
	$b3 = mysql_result($customer_result, 0, "box_no");
	$b4 = mysql_result($customer_result, 0, "postal_place");
	$b5 = mysql_result($customer_result, 0, "phone");
	$b6 = mysql_result($customer_result, 0, "contact_1");
	$b7 = mysql_result($customer_result, 0, "email_1");
	
	
?>
<script language="JavaScript" src="../jscript/format.min.js"  type="text/javascript"></script>
<script>
function calc_discount1() {

var sub_total_var =	document.getElementById('sub_total').value;
	
var discount_var =	sub_total_var * (document.getElementById('discount').value / 100) ;	

var sub_total2_var = sub_total_var - discount_var; 


var transport_var =	parseFloat(document.getElementById('transport').value) ;	

var sub_total3_var = sub_total2_var + transport_var; 

var vat_var =	sub_total3_var * (document.getElementById('VAT').value / 100) ;

var all_total_var = sub_total3_var + vat_var ;

document.getElementById('sub_total_text').value = format( "##0,##0.00", sub_total_var) ;
document.getElementById('discount_text').value = format( "###,##0.00", discount_var) ;
document.getElementById('sub_total2').value = sub_total2_var ;
document.getElementById('sub_total2_text').value = format( "###,##0.00", sub_total2_var) ;
document.getElementById('transport_text').value = format( "###,##0.00", transport_var) ;
document.getElementById('sub_total3_text').value = format( "###,##0.00", sub_total3_var) ;
document.getElementById('vat_text').value = format( "###,##0.00", vat_var) ;
document.getElementById('all_total_text').value = format( "###,##0.00", all_total_var) ;
}
</script>




</head>
<?php include('../include/wait.php') ?>
<body onLoad="MM_showHideLayers('wait','','hide');  calc_discount1(); " onFocus="MM_showHideLayers('wait','','hide');"  onBlur="MM_showHideLayers('wait','','hide');">
<div class="page_middle_frame">
<form id="form1" method="get" action="newQuoteWiz6.php" >
  <table width=595 border="0" align="center" cellpadding="10" cellspacing="0" bordercolor="#0066FF" border-collapse="collapse">
     <tr>
            <td width="525" >
             Quotation details:
               <table width="670" id="table_details_display">
                <tr>
                  <td width="123">Sales representative:</td>
                  <td width="205"><?php echo $_SESSION['seller'] ?></td>
                  <td width="104">Follow up on:</td>
                  <td width="218"><?php echo date("d-m-Y", strtotime($_SESSION['check_date'])) ?></td>
                 </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
              </table>
            
            <br />


             Quotation for:
            
              <table width="670" id="table_details_display">
                <tr>
                  <td width="123">Name:</td>
                  <td colspan="3"><?php echo  $b1 ?></td>
                </tr>
                <tr>
                  <td>Contact person:</td>
                  <td width="205"><?php echo $_SESSION['comp_contact'] ?></td>
                  <td width="109">Phone/cell:</td>
                  <td width="213"><?php echo $_SESSION['contact_phone'] ?></td>
                </tr><br />


                <tr>
                  <td>Address:</td>
                  <td colspan="3"><?php echo $b2." ".$b3.", ".$b4?></td>
                </tr>
                <tr>
                  <td>Telephone:</td>
                  <td><?php echo $b5 ?></td>
                  <td>e-mail:</td>
                  <td><?php echo $b7 ?></td>
                </tr>
              </table>
            
<br />
               Quotation details:
                <table width="670" id="table_details_display">
                  <tr>
                    <td width="123">Quotation date:</td>
                    <td colspan="3"><strong><?php echo date("d-m-Y", strtotime($_SESSION['quotation_date'])) ?></strong></td>
                  </tr>
                  <tr>
                    <td>Project no:</td>
                    <td width="177"><?php echo $_SESSION['project_no'] ?></td>
                    <td width="58">Place:</td>
                    <td width="292"><?php echo $_SESSION['project_place'] ?></td>
                  </tr>
                  <tr>
                    <td>Project description:</td>
                    <td colspan="3"><?php echo $_SESSION['description'] ?></td>
                  </tr>
                </table>
              
              <br>
              
              
              <table width="670" id="table_details_display" >
                <tr>
                  <td width="144" height="26" align="left" valign="middle">Item</td>
                  <td width="116" align="left" valign="middle">Group</td>
                  <td width="71" align="left" valign="middle">Unit</td>
                  <td width="78" align="left" valign="middle">quantity</td>
                  <td width="89" align="left" valign="middle">price</td>
                  <td width="144" 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"><?php $discount_amount = $a5_total * ($_SESSION['discount']/100) ?><label class="label_std" style="color:#F00;">Set final discount here:</label>&nbsp;<img src="../images/red_arrow.png" width="25" height="12"></td>
                  <td colspan="2" align="left" valign="middle">Discount: 
                    <select name="discount" id="discount" class="select50" onChange="calc_discount1()">
                      <option value="0">0</option>
                      <option value="0.5">0.5</option>
                      <option value="1.0">1.0</option>
                      <option value="1.5">1.5</option>
                      <option value="2.0">2.0</option>
                      <option value="2.5">2.5</option>
                      <option value="3.0">3.0</option>
                      <option value="3.5">3.5</option>
                      <option value="4.0">4.0</option>
                      <option value="4.5">4.5</option>
                      <option value="5.0">5.0</option>
                       <?php if ($discount_limit=='no') { ?>
                      <option value="5.5">5.5</option>
                      <option value="6.0">6.0</option>
                      <option value="6.5">6.5</option>
                      <option value="7.0">7.0</option>
                      <option value="7.5">7.5</option>
                      <?php } ?>
                      <option value="<?php echo $_SESSION['discount'] ?>" selected="selected"><?php echo $_SESSION['discount'] ?></option>
                    </select>
                  %</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="hidden" name="sub_total2" id="sub_total2" value="<?php echo $sub_total ?>">
                  <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"><label class="label_std" style="color:#F00;">Set final transport cost here:</label>
&nbsp;<img src="../images/red_arrow.png" alt="" width="25" height="12"></td>
                  <td colspan="2" align="left" valign="middle">Transport: </td>
                  <td align="right" valign="middle"><input type="hidden" name="transport" id="transport" value="<?php echo $_SESSION['transport'] ?> ">
                  <input type="text" name="transport_text" id="transport_text" class="text60" style="text-align:right"  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()" value=" <?php echo number_format($_SESSION['transport'], 2, '.', ',') ?>" ></td>
                </tr>
                <tr>
                  <td colspan="3" align="left" valign="middle"><?php $sub_total3 = $sub_total + $_SESSION['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 * ($_SESSION['vat']/100) ?></td>
                  <td colspan="2" align="left" valign="middle">VAT @ <?php echo $_SESSION['vat'] ?>%
                  <input type="hidden" name="VAT" id="VAT" value="<?php echo $_SESSION['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 $_SESSION['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($_SESSION['all_total'], 2, '.', ',') ?>" >
				</td> 
                </tr>
              </table>
              
             
<br />

          <label class="label_std" style="color:#F00;">A quote number will be generated on saving the quote. </label>
          <br />
<br />

            <div class="wizard_frame">
              <label class="label_std">If you want to make changes use the 'Prev' button to go back. <br />
              Click 'New' to make a new entry or to finish the wizard click 'Finish'.</label>
           </div>
       </td>
           
    </tr>
    <tr>
    <td>
          
              <table width="675" height="50" align="center" id="table_button_bar">
                <tr>
                  <td width="117" valign="top"><input type="button" name="lastprev_button" class="imagebutton" value="Prev" onClick="needToConfirm = false;MM_showHideLayers('wait','','show');MM_goToURL('parent','newQuoteWizbase.php?s=&amp;p=3');return document.MM_returnValue" /></td>
                  <td width="115" valign="top">
                    <input name="s" type="hidden" id="s" value="5" />
                    <input name="p" type="hidden" id="p" value="5" />
                  </td>
                  <td width="99" valign="top"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; cancel_confirmation(1, '../sales/sales_main.php?date='); " value="Cancel" /></td>
                  <td width="255" align="right" valign="top"><input type="submit" name="new_button" class="imagebutton" id="new_button" value="New" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');" onMouseDown="MM_showHideLayers('wait','','show');"  />
                      <td width="65" align="right" valign="top"><input  name="finish_button" type="submit" class="imagebutton" id="finish_button" value="Finish" onClick="needToConfirm = false;MM_showHideLayers('wait','','show')"  />                                        
              </table></td>
          </tr>
  </table>
 
  
</form>
<?php
}
?>
</div>
</body>

