<?php
ini_set('session.gc_maxlifetime', 30*60*60*60);
session_start();
$_SESSION["brand"]="";
if ($_SESSION["dev"]==""){
echo "Invalid User Session";
exit();
}	
?>
<link rel="stylesheet" href="css/themes/redmond/jquery-ui-1.10.3.custom.css" />

<!-- Main content -->
<section class="content">

    <div class="box box-primary">
        <div class="box-header with-border">
            <h3 class="box-title">Sales Invoice</h3>
        </div>
        <form role="form" name ="form1" class="form-horizontal">
            <div class="box-body">

                <div class="form-group">
                    <a onclick="new_inv();" class="btn btn-default">
                        <span class="fa fa-user-plus"></span> &nbsp; New
                    </a>
                    <a onclick="save_inv();" class="btn btn-primary">
                        <span class="fa fa-save"></span> &nbsp; Save
                    </a>
                    <a onclick="print_inv();" class="btn btn-default">
                        <span class="fa fa-print"></span> &nbsp; Print
                    </a>
                    <a onclick="print_inv_net();" class="btn btn-default">
                        <span class="fa fa-print"></span> &nbsp; Print Net
                    </a>
                    <a onclick="NewWindow('search_inv.php', 'mywin', '800', '700', 'yes', 'center');
                            return false" class="btn btn-default">
                        <span class="fa fa-search"></span> &nbsp; Find
                    </a>
					<?php 
					if ($_SESSION['User_Type']=="1"){ ?>
                    <a onclick="cancel_inv();" class="btn btn-danger">
                        <span class="fa fa-print"></span> &nbsp; Cancel
                    </a>	
					<?php } ?>
                </div>
                <div id="msg_box"  class="span12 text-center"  ></div>

                <input type="hidden" id="tmpno" class="form-control">
                <input type="hidden" id="item_count" class="form-control">
                <input type="hidden" name="c_subcode" id="c_subcode">
                
                
                
                
                <input type="hidden" name="ordno" id="ordno">

                <input type="hidden" name="balance" id="balance">
                
                <input type="hidden" name="creditlimit" id="creditlimit">
                

                <div class="form-group">
                    <label class="col-sm-1 control-label" for="invno">Ref No</label>
                    <div class="col-sm-2">
                        <input type="text" placeholder="Ref No" id="invno" class="form-control input-sm">
                    </div> 
                    <label class="col-sm-1 control-label" for="salesord1">Order/AD No</label>
                    <div class="col-sm-2">
                        <input type="text" name="salesord1" id="salesord1" class="form-control input-sm">  
                    </div>
                    <div class="col-sm-1">
                        <a  onclick="load_ord_lst();" class="btn btn-primary btn-sm">...</a>
                    </div>
                    <label class="col-sm-1 control-label" for="invdate">Date</label>
                    <div class="col-sm-2">
                        <input type="text" value="<?php echo date('Y-m-d'); ?>" name="invdate" id="invdate" class="form-control input-sm">  
                    </div>
					<label class="col-sm-1 control-label" for="Result">Order Status</label>
					<div class="col-sm-1">
                        <input type="text" name="Result" disabled class="form-control input-sm" id="Result">
                    </div>
					
                </div>

                <div class="form-group">
                    <label class="col-sm-1 control-label" for="invno">Customer</label>

                    <div class="col-sm-2">
                        <input type="text"  class="form-control input-sm" disabled="disabled" name="firstname_hidden" id="firstname_hidden">
                    </div>

                    <div class="col-sm-3">
                        <input type="text" class="form-control input-sm" id="firstname" name="firstname" />
                    </div>
                    <div class="col-sm-1">
                        <a href=""  class="btn btn-primary btn-sm" onClick="NewWindow('../serach_customer.php', 'mywin', '800', '700', 'yes', 'center');return false" onFocus="this.blur()">
                            ...
                        </a>
                    </div>
					
					<label class="col-sm-1 control-label" for="over60">Over 60</label>
					<div class="col-sm-1">
                        <input type="text" name="over60" disabled class="form-control input-sm" id="over60">
                    </div>
					<label class="col-sm-1 control-label" for="crebal">Credit Balance</label>
					<div class="col-sm-1">
                        <input type="text" name="crebal" disabled class="form-control input-sm" id="crebal">
                    </div>
					<label class="col-sm-1 control-label" for="crebal">Return Chq</label>
					<div class="col-sm-1">
                        <input type="text" name="txtreturn" disabled class="form-control input-sm" id="txtreturn">
                    </div>
					 
                </div>

                <div class="form-group">
                    <label class="col-sm-1 control-label" for="invno">Address</label>

                    <div class="col-sm-5">
                        <input type="text"  class="form-control input-sm"  name="cus_address" id="cus_address">
                        <input type="hidden"  class="form-control input-sm"  name="cus_address2" id="cus_address2">  
                    </div>
                    <label class="col-sm-1 control-label"   for="invno">Department</label>
                    <div class="col-sm-2">   
                        <select id="department" onclick="calc();" onchange="calc();"  class="form-control" >

                            <?php
                            $sql = "select * from s_stomas order by CODE";
                            $result = mysqli_query($GLOBALS['dbinv'], $sql);
                            while ($row = mysqli_fetch_array($result)) {
                                //echo "<option value='" . $row["barnd_name"] . "'>" . $row["barnd_name"] . "</option>";
                                if ($row["CODE"] == "01") {
                                    echo "<option selected value='" . $row["CODE"] . "'><strong>" . $row["DESCRIPTION"] . "-" . $row["CODE"] . "<strong></option>";
                                } else {
                                    echo "<option value='" . $row["CODE"] . "'>" . $row["DESCRIPTION"] . "-" . $row["CODE"] . "</option>";
                                }
                            }
                            ?>
                        </select> 
                    </div> 

                    <label class="col-sm-1 control-label" for="invno">Brand</label>

                    <div class="col-sm-2">
                        <select id="brand"  class="form-control input-sm" >

                            <?php
                            $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>
                    </div> 

                </div>

                <div class="form-group">
                    <label class="col-sm-1 control-label" for="invno">Vat</label>

                    <div class="col-sm-2">
                        <input type="text"  class="form-control input-sm" name="vat1" id="vat1">
                    </div>

                    <div class="col-sm-2">                    
                        <input type="text"  class="form-control input-sm" name="vat2" id="vat2">    
                    </div>

                    <div class="col-sm-1">                    
                        &nbsp;
                    </div>

                    <div  class="col-sm-1">
                        <input type="radio" name="vatgroup" value="vat" id="vatgroup_0" onclick="calc();">
                        VAT
                    </div>  
                    <div  class="col-sm-1">
                        <input type="radio" name="vatgroup" checked value="vat" id="vatgroup_1" onclick="calc();">
                        Non VAT
                    </div>  
                    <div  class="col-sm-1">
                        <input type="radio" name="vatgroup" value="vat" id="vatgroup_2" onclick="calc();">
                        SVAT
                    </div>                      
                    <div  class="col-sm-1">
                        <input type="radio" name="vatgroup" value="vat" id="vatgroup_3" onclick="calc();">
                        EVAT
                    </div>  

                </div>


                <div class="form-group">
                    <label class="col-sm-1 control-label" for="invno">Sales Ex.</label>

                    <div class="col-sm-2">
                        <select id="salesrep" class="form-control input-sm" >

                            <?php
                            $sql = "select * from s_salrep where cancel='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>";
                            }
                            ?>
                        </select>
                    </div>
                    <label class="col-sm-1 control-label" for="invno">Discount 1</label>
                    <div class="col-sm-2">   
                        <input type="text"  class="form-control input-sm"  onkeyup="calc();" name="discount_org1" id="discount_org1">    
                    </div>
                    <label class="col-sm-1 control-label" for="invno">Discount 2</label>
                    <div class="col-sm-2">   
                        <input type="text"  class="form-control input-sm" onkeyup="calc();" name="discount_org2" id="discount_org2">    
                    </div>
                    <label class="col-sm-1 control-label" for="invno">Discount 3</label>
                    <div class="col-sm-2">   
                        <input type="text"  class="form-control input-sm" onkeyup="calc();" name="discount_org3" id="discount_org3">    
                    </div>

                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label" for="invno">Print WO Discount</label>
                    <div class="col-sm-2">   
                        <input type="checkbox"     name="promotion" id="promotion">    
                    </div>
                </div>    
                    
                <table class="table">
                    <tr>
                        <th style="width: 100px;">Item Code</th>
                        <th style="width: 10px;"></th>
                        <th style="width: 450px;">Description</th>
                        <th style="width: 120px;">Price</th>
                        <th style="width: 120px;">Qty</th>
                        <th style="width: 120px;">%</th>
                        <th style="width: 120px;">SubTotal</th>
                        <th></th>
                    </tr>
                    
                    
                    <tr>
                        <td>
                            <input type="text" class="form-control input-sm" name="itemd_hidden" id="itemd_hidden" onblur="itno_ind();">
                        </td>
                        <td><a href="serach_item.php" onclick="NewWindow(this.href, 'mywin', '800', '700', 'yes', 'center');return false" onfocus="this.blur()">
                                <input type="button" name="searchitem" id="searchitem" value="..." class="btn">
                            </a></td>
                        <td>
                            <input type="text"  class="form-control input-sm" id="itemd" name="itemd" disabled="disabled">
                        </td>  
                        <td>
                            <input type="text" disabled name="rate" id="rate" value="" class="form-control input-sm"  onkeyup="calc();">
                            <input type="hidden" name="part_no" id="part_no"> <input type="hidden" name="actual_selling" id="actual_selling">
                        </td>
                        <td>
                            <input type="text" name="qty" id="qty" value="" onkeyup="calc();" class="form-control input-sm">
                        </td>
                        <td>
                            <input type="text" size="15" name="discountper" id="discountper" value="" disabled="disabled" class="form-control input-sm" onkeypress="keyset('subtotal', event);">
                        </td>
                        <td>
                                <input type="text" size="15" name="subtotal" id="subtotal" value="" class="form-control input-sm" disabled="disabled" onkeypress="keyset('additem_tmp', event);">
                        </td>
                        <td><input type="button" name="additem_tmp" id="additem_tmp" value="Add" onclick="add_tmp('add');" class="btn btn-primary"></td>
                    </tr>

                </table>
                
                
                <div id="itemdetails"></div>
                    
                
                
                <table class="table">
                    <tr>
                        <th style="width: 100px;">Stock Level</th>
                        <th style="width: 60px;"><input type="text"  class="form-control input-sm"   name="stklevel" id="stklevel">   </th>
                        <th style="width: 400px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;"><div class="col-sm-2" id="transp"></div></th>
                        <th style="width: 120px;">Sub Total</th>
                        <th style="width: 120px;"><input type="text"  class="form-control input-sm"   name="subtot" id="subtot"></th>
                        <th></th>
                    </tr>
                    <tr>
                        <th style="width: 100px;">Credit Period</th>
                        <th style="width: 60px;"><input type="text"  class="form-control input-sm"   name="credper" id="credper"></th>
                        <th style="width: 400px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;">Discount</th>
                        <th style="width: 120px;"><input type="text"  class="form-control input-sm"   name="totdiscount" id="totdiscount"></th>
                        <th></th>
                    </tr>                    
                    <tr>
                        <th style="width: 100px;">Net Qty</th>
                        <th style="width: 60px;"><input type="text"  class="form-control input-sm"   name="txtinvt" id="txtinvt">   </th>
                        <th style="width: 400px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;">Tax</th>
                        <th style="width: 120px;"><input type="text"  class="form-control input-sm"   name="tax" id="tax"></th>
                        <th></th>
                    </tr>  
                    <tr>
                        <th style="width: 100px;"></th>
                        <th style="width: 60px;"></th>
                        <th style="width: 400px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;">Invoice Total</th>
                        <th style="width: 120px;"><input type="text"  class="form-control input-sm"   name="invtot" id="invtot"></th>
                        <th></th>
                    </tr>  

            </table>
                <div id="storgrid"></div>
                
            <div  class='space' >
                <br>&nbsp;
                <br>&nbsp;
                <br>&nbsp;
            </div>

        </form>
    </div>

</section>

<script src="js/sales_inv.js"></script>
<script src="js/comman.js"></script>
<script>
        new_inv();

</script>
