<?php
session_start();
include './connection_sql.php';
 
?>

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

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

                <input type="hidden" id="tmpno" class="form-control">

                <input type="hidden" id="item_count" class="form-control">

                <div class="form-group">

                    <a onclick="new_inv();" class="btn btn-default btn-sm">
                        <span class="fa fa-user-plus"></span> &nbsp; New
                    </a>

                    <a onclick="save_inv();" class="btn btn-success btn-sm">
                        <span class="fa fa-save"></span> &nbsp; Save
                    </a>

                    <a onclick="print_inv('');" class="btn btn-default btn-sm">
                        <span class="fa fa-print"></span> &nbsp; Print
                    </a>
                    <a onclick="print_inv1('');" class="btn btn-default btn-sm">
                        <span class="fa fa-print"></span> &nbsp; Print Long
                    </a>
 <?php
											  
											  	if ($_SESSION['User_Type']=="1"){?>
                    <a onclick="cancel_inv();" class="btn btn-danger btn-sm">
                        <span class="fa fa-trash-o"></span> &nbsp; Cancel
                    </a>
 <?php }?>
                </div>

                <div id="msg_box"  class="span12 text-center"  ></div>
                <div class="form-group">
                    <label class="col-sm-1 control-label" for="invno">Invoice No</label>
                    <div class="col-sm-2">
                        <input type="text" placeholder="PO NO" disabled  id="txt_entno" class="form-control  input-sm">
                    </div>
                    <div class="col-sm-1">
                        <a onfocus="this.blur()" onclick="NewWindow('serach_inv.php', 'mywin', '800', '700', 'yes', 'center');
                                return false" href="">
                            <input type="button" class="btn btn-default" value="..." id="searchcust" name="searchcust">
                        </a>
                    </div>
                    <label class="col-sm-2 control-label" for="invdate">Date</label>
                    <div class="col-sm-2">
                        <input type="date"  onchange="getno1();"   placeholder="Date" id="invdate" value="<?php echo date('Y-m-d'); ?>" class="form-control   input-sm">
                    </div>
                    <label class="col-sm-1 control-label" for="invno">DA No</label>
                    <div class="col-sm-2">
                        <input type="text" placeholder="DA NO" id="DANO" class="form-control  input-sm">
                    </div>
                    <div class="col-sm-1">
                        <a onfocus="this.blur()" onclick="NewWindow('serach_inv_do.php', 'mywin', '800', '700', 'yes', 'center');
                                return false" href="">
                            <input type="button" class="btn btn-default" value="..." id="searchcust" name="searchcust">
                        </a>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-1 control-label" for="c_code">Customer</label>
                    <div class="col-sm-2">
                        <input type="text" placeholder="Code" name="c_code" disabled id="c_code" class="form-control  input-sm">
                    </div>
                    <div class="col-sm-3">
                        <input type="text" placeholder="Name" name = "c_name" id="c_name" class="form-control input-sm">
                    </div>
                    <div class="col-sm-1">


                        <a onfocus="this.blur()" onclick="NewWindow('serach_customer.php?stname=inv', 'mywin', '800', '700', 'yes', 'center');
                                return false" href="">
                            <input type="button" class="btn btn-default" value="..." id="searchcust" name="searchcust">
                        </a>
                    </div>
                    
                    <div class="col-sm-5">

                        <label  class="col-sm-4 control-label" ><input type="radio" onclick="del_item('.');"  id="paymethod_0" name="paymethod" value="credit" checked="">&nbsp;Credit</label>

                        <label  class="col-sm-3 control-label" ><input type="radio" onclick="del_item('.');" id="paymethod_1" name="paymethod" value="cash">&nbsp;Cash</label>

                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-1 control-label" for="cus_address">Address</label>
                    <div class="col-sm-5">
                        <input type="text" placeholder="Name" id="cus_address" class="form-control input-sm">
                    </div>
                      <label class="col-sm-1 control-label" for="cus_address">Vat No</label>
                    <div class="col-sm-2">
                        <input type="text" placeholder="Vat No" id="vatno" class="form-control input-sm">
                    </div>
                    <div class="col-sm-3">

                        <label  class="col-sm-4 control-label" ><input type="radio" onclick="del_item('.');"  id="non" name="optradio" value="non" disabled="" checked="">&nbsp;Non Vat</label>

                        <label  class="col-sm-3 control-label" ><input type="radio" onclick="del_item('.');" id="svat"name="optradio" value="svat" disabled="">&nbsp;VAT</label>

                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-1 control-label" for="txt_remarks">Remark</label>
                    <div class="col-sm-5">
                        <input type="text" placeholder="Remarks" id="txt_remarks" class="form-control input-sm">
                    </div>
                    <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 order by REPCODE";
                            foreach ($conn->query($sql) as $row) {
                                echo "<option value='" . $row["REPCODE"] . "'>" . $row["REPCODE"] . " " . $row["Name"] . "</option>";
                            }
                            ?>
                        </select>
                    </div> 
                
                    <label class="col-sm-1 control-label" for="invno">Department</label>

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

                            <?php
                if($_SESSION['department'] !=""){
                    $sql="select * from s_stomas where CODE='".$_SESSION['department']."' order by CODE";
                }else{
                    $sql="select * from s_stomas order by CODE";
                }
               
					foreach ($conn->query($sql) as $row) {
                    echo "<option value='".$row["CODE"]."'>".$row["CODE"]." ".$row["DESCRIPTION"]."</option>";
                    }
                 
                            
                            
                            
                            ?>
                        </select>
                    </div>
                   
                </div>
                <input id='currency' type='hidden' value='LKR'>
                <input id='txt_rate' type='hidden' value='1'>

                
                <table class="table table-striped">
                    <tr class='info'>
                        <th style="width: 120px;">Item</th>
                        <th>Description</th>
                        <th style="width: 10px;"></th>
                        <th style="width: 120px;">Qty</th>
                        <th style="width: 120px;">Rate</th>
                        <th style="width: 100px;"></th>
                    </tr>

                    <tr>
                        <td>
                            <input type="text" placeholder="Item" id="itemCode" value="Z" class="form-control input-sm">
                        </td>
                        <td>
                            <input type="text" placeholder="Description" id="itemDesc" class="form-control input-sm">
                        </td>
                        <td>
                            <a href="" onclick="NewWindow('../serach_item.php?stname=spinv', 'mywin', '800', '700', 'yes', 'center');
                                    return false" onfocus="this.blur()">
                                <input type="button" name="searchcusti" id="searchcusti" value="..." class="btn btn-default btn-sm">
                            </a>
                        </td>
                        <td>
                            <input type="number" placeholder="Qty" id="qty" class="form-control input-sm">
                        </td>
                        <?php
							 if(($_SESSION["CURRENT_USER"]=="Mayomi_r") or($_SESSION["CURRENT_USER"]=="Mayomi_A") or($_SESSION["CURRENT_USER"]=="jesintha") or($_SESSION["CURRENT_USER"]=="Shan_K") or ($_SESSION["CURRENT_USER"]=="dilshan_k") or ($_SESSION["CURRENT_USER"]=="lasantha_k") or ($_SESSION["CURRENT_USER"]=="munatunga") or ($_SESSION["CURRENT_USER"]=="munatungar") or ($_SESSION["CURRENT_USER"]=="ratahava") or ($_SESSION["CURRENT_USER"]=="dilshan_a") or ($_SESSION["CURRENT_USER"]=="dilshan_b") or ($_SESSION["CURRENT_USER"]=="dilshan_c") or ($_SESSION["CURRENT_USER"]=="dilshan_r")){?>
								<td>
                                    <input type="number" placeholder="Rate" id="itemPrice"   class="form-control input-sm">
                                </td>			  	
					   <?php }else{ ?>
                        
                        <td>
                            <input type="number" placeholder="Rate" id="itemPrice"    class="form-control input-sm">
                        </td>
                        <?php } ?>
                        <td><a onclick="add_tmp();" class="btn btn-default btn-sm"> <span class="fa fa-plus"></span> &nbsp; </a></td>
                    </tr>

                </table>

                <div id="itemdetails" >

                </div>

                <table id='subtotal' class="table">
                    <tr>
                        <th class="col-md-1">Stk Lvl</th>
                        <td class="col-md-1"> <input type="number" placeholder="stklevel" id="stklevel"   class="form-control input-sm"></td>
                        <td class="col-md-6">&nbsp;</td> 
                        <th class="col-md-2" style='text-align:left'>Sub Total</th>
                       
                        <td class="col-md-2"><input type="text" disabled placeholder="Sub Total" id="subtot" class="form-control input-sm"></td>
                    </tr>
                    <tr>
                        <td class="col-md-1" ></td>
                        <td class="col-md-1" ></td>
                        <td class="col-md-6">&nbsp;</td>
                        <th class="col-md-2" >NBT</th>                        
                        <td class="col-md-2" ><input type="text" disabled placeholder="NBT" id="nbt" class="form-control input-sm"></td>
                    </tr>
                    <tr>
                        <td class="col-md-1"></td>
                        <td class="col-md-1"></td>
                       <td class="col-md-6">&nbsp;</td>
                        <th class="col-md-2">VAT</th>
                                            
                        <td class="col-md-2"><input type="text" disabled placeholder="SVAT" id="svattot" class="form-control input-sm"></td>
                    </tr>
                    <tr>
                        <td class="col-md-1"></td>
                        <td class="col-md-1"></td>
                        <td class="col-md-6">&nbsp;</td>
                        <th class="col-md-2">Grand Total</th>
                     
                        <td  class="col-md-2" ><input type="text" disabled placeholder="Grand Total" id="gtot" class="form-control input-sm"></td>
                    </tr>
                </table>		

            </div>
        </form>
    </div>
    </div>    </div>
</section>
<script src="js/invoice.js?v1"></script>
<script>
                            new_inv();
</script>
<?php
include 'login.php';
include './cancell.php';
?>
    