<?php
ini_set('session.gc_maxlifetime', 30 * 60 * 60 * 60);
session_start(); 
if ($_SESSION["UserName"] == "") {
    echo "Please Login..";
    exit();
}
 
include './connection_sql.php';
?>

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

    <div class="box box-primary">
        <div class="box-header with-border">
            <h3 class="box-title">Collection</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">
                <input type="hidden" id="sizeId" class="form-control input-sm">
                <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="cancel_inv();" class="btn btn-danger btn-sm hidden">
                        <span class="fa fa-trash-o"></span> &nbsp; Cancel
                    </a>

                </div>

                <div id="msg_box"  class="span12 text-center"  ></div>
                <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="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="text"  placeholder="Date" id="invdate" value="<?php echo date('Y-m-d'); ?>" class="form-control dt input-sm">
                    </div>
                    <label class="col-sm-1 control-label hidden" for="invno">DA No</label>
                    <div class="col-sm-2 hidden">
                        <input type="text" placeholder="DA NO" id="DANO" class="form-control  input-sm">
                    </div>
                    <div class="col-sm-1 hidden">
                        <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" disabled name="c_code" id="c_code" class="form-control  input-sm">
                    </div>
                    <div class="col-sm-3">
                        <input type="text" placeholder="Name" disabled 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 hidden">

                        <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>
                </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>

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

                        <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>
                <input id='currency' type='hidden' value='LKR'>
                <input id='txt_rate' type='hidden' value='1'>

                <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 order by REPCODE";
                            foreach ($conn->query($sql) as $row) {
                                echo "<option value='" . $row["REPCODE"] . "'>" . $row["REPCODE"] . " " . $row["Name"] . "</option>";
                            }
                            ?>
                        </select>
                    </div> 
                </div>
                <div class="form-group hidden">
                    <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 (!is_numeric($_SESSION["CURRENT_DEP"]))  {                                                  
                    $sql="select * from s_stomas  order by CODE";
                    foreach ($conn->query($sql) as $row) {
                        echo "<option value='".$row["CODE"]."'>".$row["CODE"]." ".$row["DESCRIPTION"]."</option>";
                    }
                } else {
                    $sql="select * from s_stomas  where CODE = '" . $_SESSION["CURRENT_DEP"] ."' order by CODE";
                    foreach ($conn->query($sql) as $row) {
                    echo "<option value='".$row["CODE"]."'>".$row["CODE"]." ".$row["DESCRIPTION"]."</option>";
                    }
                }
                            
                            
                            
                            ?>
                        </select>
                    </div>
                </div>
                <table class="table table-striped">
                    <tr class='info'>
                        <th style="width: 120px;">Item</th>
                        <th>Size</th>
                        <th style="width: 10px;"></th> 
                        <th style="width: 150px;">Brand</th>
                        <th style="width: 150px;">Price</th>
                        <th style="width: 120px;">Serial No</th>
                        <th style="width: 120px;">Required Date</th>
                        <th style="width: 10px;"></th>
                        <th style="width: 10px;"></th> 
                    </tr>

                    <tr>
                        <td>
                            <input type="text" placeholder="Item" id="itemCode" value="1" class="form-control input-sm" disabled="">
                        </td>
                        <td style="width: 400px;">
                            <input type="text" placeholder="Size" id="itemDesc" disabled class="form-control input-sm">
                        </td>
                        <td >
                            <a href="" onclick="NewWindow('../serach_item.php?stname=dagcoll', '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>
                            <select id="brand"  class="form-control input-sm" >
                            <?php
                            $sql = "select * from brand_mas_new where brand_name='DAG' order by brand_name";
                            foreach ($conn->query($sql) as $row) {
                                echo "<option value='" . $row["brand_name"] . "'>" . $row["brand_name"] . "</option>";
                            }
                            ?>                                
                            </select>
                        </td>
                         <td>
                            <input type="number" disabled placeholder="Rate" id="itemPrice" class="form-control input-sm">
                        </td>
                        <td>
                            <input type="text" placeholder="Serial No" id="srlNo" class="form-control input-sm">
                        </td>
                        <td>
                            <input type="text" placeholder="Req. Date" id="reqDate" value="<?php echo date('Y-m-d'); ?>" class="form-control dt input-sm">
                        </td>
                        
                       
                        <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 hidden">
                    <tr>
                        <td></td>
                        <td></td>
                        <th>Sub Total</th>

                        <td></td>                        
                        <td style="width: 150px;"><input type="text" disabled placeholder="Sub Total" id="subtot" class="form-control input-sm"></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <th>NBT</th>
                        <td></td>                        
                        <td style="width: 150px;"><input type="text" disabled placeholder="NBT" id="nbt" class="form-control input-sm"></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <th>VAT</th>
                        <td></td>                        
                        <td style="width: 150px;"><input type="text" disabled placeholder="SVAT" id="svattot" class="form-control input-sm"></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <th>Grand Total</th>

                        <td></td>                        
                        <td style="width: 150px;"><input type="text" disabled placeholder="Grand Total" id="gtot" class="form-control input-sm"></td>
                    </tr>
                </table>        

            </div>
        </form>
    </div>

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