<?php  
				 
	require_once("connectioni.php");
	
 
?>	

<?php date_default_timezone_set('Asia/Colombo'); ?>						 
	



<link rel="stylesheet" href="css/table_min.css" type="text/css"/>	
<link rel="stylesheet" type="text/css" media="all" href="css/jsDatePick_ltr.min.css" />
<script type="text/javascript" src="js/jsDatePick.min.1.3.js"></script>


<script language="javascript" type="text/javascript">
<!--
/****************************************************
     Author: Eric King
     Url: http://redrival.com/eak/index.shtml
     This script is free to use as long as this info is left in
     Featured on Dynamic Drive script library (http://www.dynamicdrive.com)
****************************************************/
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);}
// -->
</script>

<script type="text/javascript">
function openWin()
{
myWindow=window.open('serach_inv.php','','width=200,height=100');
myWindow.focus();

}
</script>

<script type="text/javascript">
	window.onload = function(){
		new JsDatePick({
			useMode:2,
			target:"dte_dor",
			dateFormat:"%Y-%m-%d"
			/*selectedDate:{				This is an example of what the full configuration offers.
				day:5,						For full documentation about these settings please see the full version of the code.
				month:9,
				year:2006
			},
			yearsRange:[1978,2020],
			limitToToday:false,
			cellColorScheme:"beige",
			dateFormat:"%m-%d-%Y",
			imgPath:"img/",
			weekStartDay:1*/
		});
	};
</script>
<script type="text/javascript">
function load_calader(tar){
		new JsDatePick({
			useMode:2,
			target:tar,
			dateFormat:"%Y-%m-%d"
			
		});
		
	}

</script>

</label>
          
<fieldset>
                                                	<legend>
  <div class="text_forheader">Proforma Invoice Details</div>
                                               	 </legend>             

<form name="form1" id="form1"> <input type="hidden" name="cmd_new" id="cmd_new" value="1" />
    <input type="hidden" name="cmd_save" id="cmd_save" value="0"/>
    <input type="hidden" name="cmd_cancel" id="cmd_cancel" value="0"/>
    <input type="hidden" name="cmd_print" id="cmd_print" value="0"/>
     
  <table width="100%" border="0"  class=\"form-matrix-table\">
  <tr>
    <td width="10%" bgcolor="#00CCCC"><label>
      <input type="radio" name="paymethod" value="credit" id="paymethod_0" />
      <b style="font-size:12px;">Credit</b></label></td>
    <td width="10%"  bgcolor="#00CCCC"><label>
      <input type="radio" name="paymethod" value="cash" id="paymethod_1" />
      <b style="font-size:12px;">Cash</b></label></td>
    <td width="10%">&nbsp;</td>
    <td width="10%"><input type="text"  class="label_purchase" value="SO No" disabled="disabled"/></td>
    <td width="10%"><input type="text" name="salesord1" disabled id="salesord1" value="" class="text_purchase3" onkeypress="keyset('searchcust',event);"   />     </td>
    <td width="12%">
      <input type="button" name="searchinv" onclick="load_ord_lst();" id="searchinv" value="SEARCH" class="btn_purchase1" />    </td>
    <td width="10%"><input type="text"  class="label_purchase" value="Entry Date" disabled="disabled"/></td>
    <td width="10%"><input type="date" size="20" name="invdate"   id="invdate"   value="<?php echo date("Y-m-d"); ?>"   class="text_purchase3"/></td>
    <td width="10%">&nbsp;</td>
  </tr>
    <tr height="31">
                <td><input id="dte_dor" name="dte_dor" type="hidden"  value="" class="text_purchase3" /></td>
                <td><input type="text"  class="label_purchase" value="Type" disabled/></td>
    <td><select name="type" id="type" onkeypress="keyset('brand',event);" class="text_purchase3" >
       
         <option value='Proforma Invoice'>Proforma Invoice</option> 
         <option value='Duplicate Invoice'>Duplicate Invoice</option> 
        																
 	
        ?>
    </select></td>
                <td><input type="text"  class="label_purchase" value="Duplicate Inv.No" disabled="disabled"/></td>

                <td ><input type="text" name="salesord2"   id="salesord2" value="" class="text_purchase3" onkeypress="keyset('searchcust', event);"   /> </td>
                <!--<td ><input type="button" name="searchinv1" onclick="load_ord_lst1();"  id="searchinv1" value="..." class="btn_purchase1" /> </td>-->
                <td>&nbsp;</td>
                <td><input type="hidden" name="ordno" id="ordno" value="" class="text_purchase3" onkeypress="keyset('searchcust', event);"   /></td>
                <td>&nbsp;</td>
            </tr>
  <tr>
    <td><input id="dte_dor" name="dte_dor" type="hidden"  value="" class="text_purchase3" /></td>
    <td colspan="3"><input type="hidden" name="hiddencount" id="hiddencount" /></td>
    <td><input type="hidden" name="ordno" id="ordno" value="" class="text_purchase3" onkeypress="keyset('searchcust',event);"   /></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  
  <input type="hidden" name="c_subcode" id="c_subcode" />
  
  <tr>
    <td><input type="hidden"  class="label_purchase" value="Invoice No" disabled/></td>
    <td colspan="3"><input type="hidden"  class="text_purchase" name="invno" id="invno"/>
      <a href="serach_inv.php?stname=inv_mast" onClick="NewWindow(this.href,'mywin','800','700','yes','center');return false" onFocus="this.blur()">
      <input type="hidden" name="txtdono" id="txtdono" />
      </a></td>
    <td><input type="hidden" name="over60" id="over60" /></td>
    <td>&nbsp;</td>
    <td><input type="hidden"  class="label_purchase" value="Balance With Tmp Limit" disabled="disabled"/></td>
    <td><input type="hidden" name="crebal" id="crebal" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><input type="text"  class="label_purchase" value="Customer" disabled/></td>
    <td colspan="3"><input type="text"  class="text_purchase1"  disabled name="firstname_hidden" id="firstname_hidden" onblur="custno_ind('');" onkeypress="keyset('department',event);"/>
      <input type="text" class="text_purchase2" id="firstname" disabled name="firstname" />
      <a href="" onClick="NewWindow('serach_customer.php?stname=sales_order','mywin','800','700','yes','center');return false" onFocus="this.blur()">
        <input type="button" name="searchcust" id="searchcust" value="SEARCH&nbsp;&nbsp;&nbsp;&nbsp;"  class="btn_purchase">
      </a></td>
    <td><input type="text"  class="label_purchase" value="Credit Limit" disabled/></td>
    <td><input type="text" size="15" name="creditlimit" id="creditlimit" value="0" onkeypress="keyset('balance',event);" class="text_purchase3" disabled="disabled"/></td>
    <td><input type="text"  class="label_purchase" value="Credit Balance" disabled="disabled"/></td>
    <td><input type="text" size="15" name="balance" id="balance" disabled="disabled" value="0" onkeypress="keyset('department',event);" class="text_purchase3"/></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><input type="text"  class="label_purchase" value="Address" disabled/></td>
    <td colspan="2"><input type="text"  class="text_purchase4"  id="cus_address" name="cus_address" /></td>
    <td>&nbsp;</td>
    <td><input type="text"  class="label_purchase" value="Department" disabled/></td>
    <td><select name="department" id="department" onkeypress="keyset('brand',event);" class="text_purchase3" >
      <?php
		 if ($_SESSION["CURRENT_DEP"] != "") {
           $sql="select * from s_stomas where  act='1' and CODE='".$_SESSION["CURRENT_DEP"] ."' order by CODE";
        }else{
          $sql="select * from s_stomas where  act='1'  order by CODE";
        } 
        $result =mysqli_query($GLOBALS['dbinv'],$sql) ; 
        while($row = mysqli_fetch_array($result)){
        echo "<option value='".$row["CODE"]."'>".$row["DESCRIPTION"]."</option>";
        }																	
 	
        ?>
    </select></td>
    <td><input type="text"  class="label_purchase" value="Brand" disabled="disabled"/></td>
    <td ><select name="brand" id="brand" disabled="disabled" onkeypress="keyset('salesrep',event);" class="text_purchase3"  onblur="setord();">
    		<option value=''></option>
      <?php
        if (($_SESSION["CURRENT_DEP"] != "") and (!is_numeric($_SESSION["CURRENT_DEP"]))) {
            $sql="select * from brand_mas where act ='1' and costcenter='".$_SESSION["CURRENT_DEP"]."' order by barnd_name"; 
        }else{
            $sql="select * from brand_mas where act ='1' order by barnd_name";
        } 
        $result =mysqli_query($GLOBALS['dbinv'],$sql) ; 
        while($row = mysqli_fetch_array($result)){
             echo "<option value='".$row["barnd_name"]."'>".$row["barnd_name"]."</option>";
        }
        ?>
    </select></td>
    <td style="visibility: hidden;"  id="tbrchecklbl" >
       
      <label >
      <input type="checkbox" name="tbrcheck" onClick="tbrsession();" id="tbrcheck" />
      <b>TBR Only</b></label></td>
  </tr>
  <tr >
    <td height="31" ><input type="text"  class="label_purchase" value="VAT No" disabled="disabled"/></td>
    <td><input type="text" size="20" name="vat1" id="vat1" value=""  disabled onkeypress="keyset('vat2',event);" class="text_purchase3"/></td>
    <td><input type="text" size="20" name="vat2" id="vat2" value="" disabled onkeypress="keyset('salesrep',event);" class="text_purchase3"/></td>
    <td>&nbsp;</td>
    <td  height="31"  bgcolor="#00CCCC"><label>
      <input type="radio" name="vatgroup" value="vat" id="vatgroup_0"  onclick="calc1_table_discount1();" />
      <b style="font-size:12px;">VAT Invoice</b></label></td>
    <td bgcolor="#00CCCC"><label>
      <input type="radio" name="vatgroup" value="non" id="vatgroup_1"  onclick="calc1_table_discount1();" />
      <b style="font-size:12px;">Non VAT Invoice</b></label></td>
    <td bgcolor="#00CCCC"><label>
      <input type="radio" name="vatgroup" value="svat" id="vatgroup_2"  onclick="calc1_table_discount1();" />
      <b style="font-size:12px;">SVAT Invoice</b></label></td>
    <td bgcolor="#00CCCC"><label>
      <input type="radio" name="vatgroup" value="evat" id="vatgroup_3"  onclick="calc1_table_discount1();" />
      <b style="font-size:12px;">EVAT Invoice</b></label></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="41"><input type="text"  class="label_purchase" value="Sales Executive" disabled="disabled"/></td>
    <td><select name="salesrep" id="salesrep" onkeypress="keyset('discount_org1',event);" onblur="setord();" class="text_purchase3">
      <?php
      require_once("connectioni.php");

        if (($_SESSION["MANAGER"] !="") &&  ($_SESSION["CURRENT_REP"] !="")){ 			 						
            $sql="select * from s_salrep where pactive='1' and repcode = '" . $_SESSION["CURRENT_REP"] ."' order by REPCODE";
            $result =mysqli_query($GLOBALS['dbinv'],$sql) ; 
            while($row = mysqli_fetch_array($result)){
                echo "<option value='".$row["REPCODE"]."'>".$row["REPCODE"]." ".$row["Name"]."</option>";
            }
         }else if ($_SESSION["MANAGER"]!="") {                  
            $sql="select * from s_salrep where pactive='1' and manager='".$_SESSION["MANAGER"]."'order by REPCODE"; 
            $result =mysqli_query($GLOBALS['dbinv'],$sql) ; 
            while($row = mysqli_fetch_array($result)){
                echo "<option value='".$row["REPCODE"]."'>".$row["REPCODE"]." ".$row["Name"]."</option>";
            }
         }else if ($_SESSION["CURRENT_REP"]=="") { 			 						
            $sql="select * from s_salrep where pactive='1' order by REPCODE";
            $result =mysqli_query($GLOBALS['dbinv'],$sql) ; 
            while($row = mysqli_fetch_array($result)){
                echo "<option value='".$row["REPCODE"]."'>".$row["REPCODE"]." ".$row["Name"]."</option>";
            }
         } else {
             $sql="select * from s_salrep where pactive='1' and repcode = '" . $_SESSION["CURRENT_REP"] ."' order by REPCODE";
             $result =mysqli_query($GLOBALS['dbinv'],$sql) ; 
             while($row = mysqli_fetch_array($result)){
             echo "<option value='".$row["REPCODE"]."'>".$row["REPCODE"]." ".$row["Name"]."</option>";
             }
         }
           
                    ?>
    </select></td>
    <td><input type="text"  class="label_purchase" value="Discount 1" disabled="disabled"/></td>
    <td><input type="text" size="5" name="discount_org1" id="discount_org1" onkeyup="calc1_table_discount1();" onkeydown="calc1_table_discount1();" onkeypress="keyset('discount_org2',event);" onblur="calc1_table_discount1();" class="text_purchase"/></td>
    <td><input type="text"  class="label_purchase" value="Discount 2" disabled="disabled" /></td>
    <td><input type="text" size="5" name="discount_org2" id="discount_org2" disabled onkeyup="calc1_table_discount1();" onkeydown="calc1_table_discount1();" onkeypress="keyset('itemd_hidden',event);" onblur="calc1_table_discount2();" class="text_purchase"/></td>
    <td><input type="hidden"  class="label_purchase" value="Discount 3" disabled="disabled"/></td>
    <td><input type="hidden" size="5" name="discount_org3" id="discount_org3" value="0" onkeypress="keyset('itemd_hidden',event);" onblur="calc1_table_discount1();" class="text_purchase"/></td>
    <td>&nbsp;</td>
  </tr>
  </table>

  
  
<fieldset>               
            
   	<legend><div class="text_forheader">Item Details</div></legend>            
            
    <input type="hidden" name="item_count" id="item_count" value="0" />
  <table width="98%" border="0">
  <tr>
    <td width="14%"><span class="style1">
      <input type="text"  class="label_purchase" style="text-align:center;" value="Item Code" disabled/>
    </span></td>
    <td  width="1%">&nbsp;</td>
    <td  width="25%"><span class="style1" >
      <input type="text"style="text-align:center;"   class="label_purchase" value="Description" disabled/>
    </span></td>
    <td  width="14%"><span class="style1">
      <input type="text" style="text-align:center;"  class="label_purchase" value="List Price" disabled/>
    </span></td>
    <td  width="14%"><span class="style1">
      <input type="text"  style="text-align:center;" class="label_purchase" value="Quantity" disabled/>
    </span></td>
    <td  width="14%"><span class="style1">
      <input type="text" style="text-align:center;"  class="label_purchase" value="Discount (%)" disabled="disabled"/>
    </span></td>
    <td  width="14%"><span class="style1">
      <input type="text" style="text-align:center;"  class="label_purchase" value="Unit Total" disabled="disabled"/>
    </span></td>
    <td  width="14%"><span class="style1">&nbsp;</td>
    </tr>
  <tr>
    <td><font color="#FFFFFF">
    <div id="test"><font color="#FFFFFF">
      <input type="text"  class="text_purchase3" name="itemd_hidden" id="itemd_hidden" size="10" onkeypress="keyset('qty',event);" onblur="itno_ind();"   />
    </font></div>  </font></td>
    <td ><a href="serach_item.php?stname=sales_order" onclick="NewWindow(this.href,'mywin','800','700','yes','center');return false" onfocus="this.blur()">
      <input type="button" name="searchitem" id="searchitem" value="SEARCH" class="btn_purchase2" />
    </a></td>
    <td><font color="#FFFFFF">
      <input type="text"  class="text_purchase3" id="itemd" name="itemd" disabled="disabled" onkeypress="keyset('rate',event);" />
    </font><a href="serach_item.php" onClick="NewWindow(this.href,'mywin','800','700','yes','center');return false" onFocus="this.blur()"></a></td>
    <td><font color="#FFFFFF">
      <input type="text" size="15" name="rate" id="rate" value=""   class="text_purchase3" onkeypress="keyset('qty',event);"/>
      <input type="hidden" name="part_no" id="part_no" /> <input type="hidden" name="actual_selling" id="actual_selling" />
    </font></td>
    <td><font color="#FFFFFF">
      <input type="text" size="15" name="qty" id="qty" value="" onblur="calc1();" class="text_purchase3" onkeypress="keyset('additem_tmp',event);"/>
    </font></td>
    <td><font color="#FFFFFF">
      <input type="text" size="15" name="discountper" id="discountper" value="" disabled="disabled" class="text_purchase3" onkeypress="keyset('subtotal',event);"/><input type="hidden" size="15" name="discount" id="discount" value="" disabled class="txtbox" />
    </font></td>
    <td><font color="#FFFFFF">
      <input type="text" size="15" name="subtotal" id="subtotal" value="" class="text_purchase3" disabled="disabled" onkeypress="keyset('additem_tmp',event);"/>
    </font></td>
    <td  ><input type="button" name="additem_tmp" id="additem_tmp" value="ADD" onClick="add_tmp();" class="btn_purchase2"></td>
    </tr>
  <tr>
	<td colspan="7">
    <div class="CSSTableGenerator" id="itemdetails" >
<table>
                                                        			<tr>
                              											<td width="10%"   background="" ><font color="#FFFFFF">Item Code</font></td>
                              											<td width="40%"  background=""><font color="#FFFFFF">Description</font></td>
                              											<td width="10%"  background=""><font color="#FFFFFF">List Price</font></td>
                              											<td width="10%"  background=""><font color="#FFFFFF">Quantity</font></td>
                                                                        <td width="10%"  background=""><font color="#FFFFFF">Discount (%)</font></td>
                                                                        <td width="10%"  background=""><font color="#FFFFFF">Unit Total</font></td>
                           											</tr>
                   												</table>   </div>                                                 		</td>
                                                		</tr>
  
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><span class="style1">
      <input type="text"  class="label_purchase" value="Available Qty" disabled="disabled"/>
    </span></td>
    <td>&nbsp;</td>
    <td><input type="text" size="5" name="stklevel" id="stklevel" disabled value="" class="text_purchase1"/></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><span class="style1">
      <input type="text"  class="label_purchase" value="Sub Total" disabled="disabled"/>
    </span></td>
    <td><input type="text" size="15" name="subtot" id="subtot" style="text-align:right;" value="0" disabled="disabled" class="text_purchase3"/></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="31"><span class="style1">
      <input type="text"  class="label_purchase" value="Credit Period" disabled="disabled"/>
    </span></td>
    <td>&nbsp;</td>
    <td><input type="text" size="5" name="credper" id="credper" value=""  class="text_purchase1"/></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><span class="style1">
      <input type="text"  class="label_purchase" value="Discount" disabled="disabled"/>
    </span></td>
    <td><input type="text" size="15" name="totdiscount" id="totdiscount" style="text-align:right;"  value="0" disabled="disabled"  class="text_purchase3" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
       <td><input type="text"  class="label_purchase" value="Total Month Qty" disabled="disabled"/></td>
    <td>&nbsp;</td>
    <td><input type="text"  size="15" class="text_purchase1" value="" id="txtinvt" name="txtinvt"/></td>
    <td><input type="hidden" name="OutInvAmt" id="OutInvAmt" />
    	<input type="hidden" name="OutREtAmt" id="OutREtAmt" />
        <input type="hidden" name="OutpDAMT" id="OutpDAMT" /></td>
    <td>&nbsp;</td>
    <td height="31"><span class="style1">
      <input type="text"  class="label_purchase" value="Tax" name="taxname" id="taxname" disabled="disabled"/>
    </span></td>
    <td><input type="text" size="15" name="tax" id="tax" value="0"  style="text-align:right;"  class="text_purchase3"  disabled="disabled" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="31" colspan="3" rowspan="5"><div id="storgrid"></div></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><span class="style1">
      <input type="text"  class="label_purchase" value="Grand Total" disabled="disabled"/>
    </span></td>
    <td><input type="text" size="15" name="invtot"  id="invtot" value="0" style="text-align:right;"  disabled="disabled" class="text_purchase3"/></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  </table>
<table>
  <tr>
   <td colspan='2' rowspan='3'><textarea name="remark" id="remark" cols="60" rows="5" ></textarea></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
</table>
          

</form>        

</fieldset>    
            
    <script>
        
        new_inv();
    </script>    