<?php
ini_set('session.gc_maxlifetime', 30 * 60 * 60 * 60);
session_start();
$_SESSION["brand"] = "";
if ($_SESSION["CURRENT_USER"] == "") {
    echo "Please Loging Again !!!";
    exit();
}
?>
 
  
<style>

    .talign{
        text-align: left !important; 

    }
    .text{
        font-weight: 600; 
        color: black;
    }
    .form-horizontal .form-group{
        margin-top:-10px !important;
   }
</style>
<script language="JavaScript" src="js/grn.js?v4"></script>

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

    <div class="box box-primary">
        <div class="box-header with-border">
            <h3 class="box-title">DIRECT ARN</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 btn-sm">
                        <span class="fa fa-user-plus"></span> &nbsp; New
                    </a>

                    <?php  if($row_userp['doc_feed']==1){?>
                   
                    <?php }?>
 

                    <?php  if($row_userp['doc_view']==1){?>
                    
                    <?php }?>

                    <?php  if($row_userp['doc_print']==1){?>
                    
                    <?php }?>

                     <?php  if($row_userp['doc_cancel']==1){?>
                       
                    <?php } ?>
                     <a onclick="save_inv();" class="btn btn-success btn-sm">
                        <span class="fa fa-save"></span> &nbsp; Save
                        </a>
                        <a onclick="NewWindow('grn_search.php?stname=Grn', 'mywin', '800', '700', 'yes', 'center');
                                return false" class="btn btn-info active btn-sm">
                            <span class="fa fa-search"></span> &nbsp; Search
                        </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">
                            <span class="fa fa-trash"></span> &nbsp; Cancel
                        </a>    
                </div>

          <!-- Hidden Items -->
<div hidden>
    <input type="text" name="count" id="count">
    <td style='visibility:hidden'><select name="costcenter" id="costcenter"  class="text_purchase3 "  >
      <option value=''> --Select-- </option> 
    </select>
</div>
    
           
                <div id="msg_box"  class="span12 text-center"  ></div>
                <div class="col-sm-3">
                    <input type="text" placeholder="Uniq"  id="uniq" class="form-control hidden input-sm">
                </div>   

                <div class="form-group"></div>

                <div class="form-group">
                        <label class="col-sm-1 control-label" for="invno">GRN No</label>
                    <div  class="col-sm-2">
                        <input type="text" name="invno" id="invno" disabled class="form-control   input-sm">  
                    </div>
                        <label class="col-sm-1 control-label" for="invno">Entry Date</label>
                    <div class="col-sm-2">
                        <input type="date"  name="invdate" id="invdate" disabled value="<?php echo date("Y-m-d"); ?>" class="form-control   input-sm">  
                    </div>
                    
                    <label class="col-sm-1 control-label" for="invno">PO No</label>
                    <div class="col-sm-2">
                        <input type="text" name="orderno1" id="orderno1"  class="form-control   input-sm">  
                    </div>
                    <div  class="col-sm-1">
                        <a onclick="NewWindow('grn_po_search.php?stname=grn', 'mywin', '800', '700', 'yes', 'center');
                            return false" class="btn btn-info active btn-sm">
                        <span class="fa fa-search"></span> &nbsp;
                        </a>  
                    </div>
                </div>

                <div class="form-group">
                     <label class="col-sm-1 control-label" for="invno">Supplier</label>
                    <div class="col-sm-1">
                        <input type="text" name="supplier_code" disabled id="supplier_code" class="form-control   input-sm">  
                    </div>
                    <div class="col-sm-3"> 
                        <input type="text"  id="supplier_name" disabled name="supplier_name"  class="form-control   input-sm">  
                    </div>
                    <div  class="col-sm-1">
                        <a onclick="NewWindow('grn_supp_search.php', 'mywin', '800', '700', 'yes', 'center');
                            return false" class="btn btn-info active btn-sm">
                        <span class="fa fa-search"></span> &nbsp;
                        </a>  
                    </div>
                    <label class="col-sm-1 control-label" for="invno">PO Date</label>
                    <div class="col-sm-2">
                        <input type="date"  id="dte_dor" name="dte_dor" value="<?php echo date("Y-m-d"); ?>" class="form-control   input-sm">  
                    </div>
                    <label class="col-sm-1 control-label" for="invno">Department</label>
                    <div class="col-sm-2">
                        <select name="department" id="department"  class="form-control   input-sm">
                            <?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";
                                } 
                            foreach ($conn->query($sql) as $row) {
                                 echo "<option value='".$row["CODE"]."'>".$row["DESCRIPTION"]."</option>";                                 
                            }
                              ?> 
                        </select>  
                    </div>
                    
                </div>
 
                <div class="form-group">
                     <label class="col-sm-1 control-label" for="invno">CI No</label>
                    <div class="col-sm-2">
                        <input id="invno1" name="invno1" type="text" class="form-control   input-sm" >
                    </div>
                        <label class="col-sm-1 control-label" for="invno">BL No</label>
                    <div class="col-sm-2">
                        <input id="blno" name="blno" type="text"  class="form-control   input-sm"> 
                    </div>
                    <label class="col-sm-1 control-label" for="invno">Brand</label>
                    <div class="col-sm-2">
                        <select name="brand" id="brand"  class="form-control   input-sm" onchange="brand_session();" onclick="brand_session();">
                            <?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";
                            } foreach ($conn->query($sql) as $row) {
                                echo "<option value='".$row["barnd_name"]."'>".$row["barnd_name"]."</option>";
                                }
                            ?>          
                        </select>    
                    </div> 
                    <label class="col-sm-1 control-label" for="invno">GRN Status</label>
                    <div class="col-sm-2">
                        <select name="arpend" id="arpend" class="form-control   input-sm">
                            <option value='0'>Received</option> 
                            <option value='1'>Pending</option>
                        </select>
                    </div>
                    
                </div>

                <div class="form-group">
                    <label class="col-sm-1 control-label" for="invno">LC/TT No</label>
                    <div class="col-sm-2">
                        <input type="text" id="lc_no" class="form-control  input-sm">  
                    </div>
                        <label class="col-sm-1 control-label" for="invno">PI No</label>
                    <div class="col-sm-2">
                        <input type="text"  id="pi_no" name="pi_no" class="form-control   input-sm">
                    </div>
                    
                    <label class="col-sm-1 control-label" for="invno">Order By</label>
                    <div class="col-sm-2">
                        <select name="salesrep" id="salesrep"   class="form-control   input-sm">
                            <?php
                            if ($_SESSION["MANAGER"]!="") {
                               $sql="select * from s_salrep where pactive='1' and manager='".$_SESSION["MANAGER"]."'order by REPCODE";
                               foreach ($conn->query($sql) as $row) {
                                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";
                              foreach ($conn->query($sql) as $row) {
                                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"; 
                            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">Purchase Type</label>
                    <div class="col-sm-2">
                        <select name="purtype" id="purtype" class="form-control   input-sm">
                            <option value='Import'>Import</option>
                            <option value='Local'>Local</option>
                          </select>
                    </div>
                </div>
  

                <div class="form-group">
                    <label class="col-sm-1 control-label" for="invno">Container Size</label>
                    <div class="col-sm-2">
                        <input type="text" name="contsize" id="contsize" class="form-control   input-sm">  
                    </div>
                   
                    
                    <label class="col-sm-1 control-label" for="invno">Invoice Date</label>
                    <div class="col-sm-2"> 
                        <input type="date"  name="indate" id="indate" value="<?php echo date("Y-m-d"); ?>" class="form-control input-sm">
                    </div>
                    <label class="col-sm-1 control-label" for="invno">Country</label>
                    <div class="col-sm-2">
                        <select id="country" name="country"  class="form-control   input-sm">
                            <?php 
                            $sql="select * from country ";
                            foreach ($conn->query($sql) as $row) {
                                echo "<option value='".$row["name"]."'>".$row["name"]." </option>";
                            }
                              ?> 
                        </select>
                    </div>
                    <div class="col-sm-3">
                        <label style="background-color: #00CCCC">
                            &nbsp;&nbsp;
                          <input type="radio" name="vatgroup" value="non" id="vatgroup_0"  onclick="calc1_table_discount1();">
                          &nbsp;&nbsp;Non VAT&nbsp;&nbsp;
                        </label>
                         <label style="background-color: #00CCCC">
                            &nbsp;&nbsp;
                          <input type="radio" name="vatgroup" value="vat" id="vatgroup_1"  onclick="calc1_table_discount1();">
                          &nbsp;&nbsp;VAT&nbsp;&nbsp;
                        </label>
                        <label style="background-color: #00CCCC">
                            &nbsp;&nbsp;
                            <input type="radio" name="vatgroup" value="svat" id="vatgroup_2"  onclick="calc1_table_discount1();">
                            &nbsp;&nbsp;SVAT&nbsp;&nbsp;
                        </label>
                    </div> 
                </div>

                <div class="form-group">
                        <label class="col-sm-1 control-label" for="invno">Remark</label>
                    <div class="col-sm-5">
                        <textarea name="textarea" id="textarea"crows="2" class="form-control   input-sm"></textarea>
                    </div>
                    <label class="col-sm-1 control-label" for="invno">Pending Debit Note Amount</label>
                    <div class="col-sm-2">
                        <input type="number" name="pdebitnote" id="pdebitnote" class="form-control   input-sm">  
                    </div>
                                                   
                </div> 
 <h3 style="font-size: 18px;" class="box-title">Item Details</h3>  

                <table class="table table-bordered"> 
                    <tr class="info">
                        <td width="10%">Item Code</td>
                        <td width="15%">Description</td>
                        <th width="2%"></th>
                        <td width="5%">Ord Qty</td>
                        <td width="5%">Rec Qty</td>
                        <td width="5%">Com Cost</td>
                        <td width="5%">Dis 1</td>
                        <td width="5%">Dis 2</td>
                        <td width="5%">Dis 3</td>
                        <td width="5%">Actual Cost</td>
                        <td width="5%">Tax</td>
                        <td width="5%">List Price</td>
                        <td width="5%">Cash Price</td>
                        <td width="5%">Credit Price</td>
                        <td width="5%">Margin (%)</td>
                        <td width="5%">Unit Total</td>
                        <th width="2%"></th>
                    </tr>

                    <tr>
                        <td style="padding: 5px 1px 1px 1px;">
                            <input type="text"  class="form-control input-sm" name="itemcode" id="itemcode" onblur="itno_ind();" disabled="disabled">
                        </td>
                        <td style="padding: 5px 1px 1px 1px;">
                            <input type="text"  class="form-control input-sm" id="itemname" name="itemname" disabled="disabled">
                        </td>
                        <td style="padding: 5px 1px 1px 1px;">
                            <a onclick="NewWindow('grn_item_search.php', 'mywin', '800', '700', 'yes', 'center');
                            return false" class="btn btn-info active btn-sm">
                                <span class="fa fa-search"></span>
                            </a>
                        </td>
                        <td style="padding: 5px 1px 1px 1px;">
                            <input type="text"  class="form-control input-sm" name="ord_qty" id="ord_qty" disabled>
                        </td>
                        <td style="padding: 5px 1px 1px 1px;">
                            <input type="number" type="number"  name="qty" id="qty"  class="form-control input-sm" onchange="cal_subtot2();" onkeyup="cal_subtot2();">
                        </td>
                        <td style="padding: 5px 1px 1px 1px;">
                            <input type="number"  class="form-control input-sm" name="reccost" id="reccost" onchange="cal_subtot2();" onkeyup="cal_subtot2();" >
                        </td>
                        <td style="padding: 5px 1px 1px 1px;">
                            <input type="number"  class="form-control input-sm"  name="dis1" id="dis1" onchange="cal_subtot2();" onkeyup="cal_subtot2();">
                        </td>
                        <td style="padding: 5px 1px 1px 1px;">
                            <input type="number"  name="dis2" id="dis2"  class="form-control   input-sm input-sm" onchange="cal_subtot2();" onkeyup="cal_subtot2();" class="form-control   input-sm">
                        </td>
                        <td style="padding: 5px 1px 1px 1px;">
                            <input type="number"  class="form-control input-sm"  name="dis3" id="dis3" onchange="cal_subtot2();" onkeyup="cal_subtot2();">
                        </td>
                        <td style="padding: 5px 1px 1px 1px;">
                            <input type="number"  name="cost" id="cost"  class="form-control   input-sm input-sm" onchange="cal_subtot2();" onkeyup="cal_subtot2();" class="form-control   input-sm" disabled>
                        </td>
                        <td style="padding: 5px 1px 1px 1px;">
                            <input type="number"  name="tax" id="tax" disabled  class="form-control   input-sm">
                        </td>
                        <td style="padding: 5px 1px 1px 1px;">
                            <input type="number"  name="selling" id="selling" onkeyup="cal_margine2();"  class="form-control   input-sm"/>
                        </td>
                        <td style="padding: 5px 1px 1px 1px;">
                            <input type="number"  name="cash" id="cash"  class="form-control   input-sm"/>
                        </td>
                        <td style="padding: 5px 1px 1px 1px;">
                            <input type="number"  name="credit" id="credit"  class="form-control   input-sm"/>
                        </td>
                        <td style="padding: 5px 1px 1px 1px;">
                            <input type="number"  name="margin" id="margin" class="form-control   input-sm" disabled>
                        </td>
                        <td style="padding: 5px 1px 1px 1px;">
                            <input type="number"  name="subtotal" id="subtotal" class="form-control   input-sm" disabled>
                        </td>
                        <td style="padding: 5px 1px 1px 1px;">
                            <input type="button" name="additem_tmp" id="additem_tmp" value="ADD" onClick="add_tmp();" class="btn btn-primary">
                        </td>
                    </tr>
                </table>

                <div class="form-group"></div>
                <div class="form-group"></div>
                <div class="form-group"></div>

                <div id="itemdetails"> 
                </div>

                <div class="form-group"></div>                

                <div class="form-group">
                    <div class="col-sm-8"></div>
                        <label class="col-sm-2 control-label" for="invno">Sub GRN Value</label>
                    <div class="col-sm-2">
                        <input type="number" style="text-align: right;" name="sub_val" id="sub_val" disabled class="form-control input-sm">
                    </div>                      
                </div> 

                <div class="form-group">
                    <div class="col-sm-8"></div>
                        <label class="col-sm-2 control-label" for="invno">Total Discount</label>
                    <div class="col-sm-2"> 
                        <input type="number" style="text-align: right;" name="total_dis" id="total_dis" disabled class="form-control input-sm">
                    </div>                    
                </div>

                <div class="form-group">
                    <div class="col-sm-8"></div>
                        <label class="col-sm-2 control-label" for="invno">Total Vat Value</label>
                    <div class="col-sm-2"> 
                        <input type="number" style="text-align: right;" name="total_vat_value" id="total_vat_value" disabled class="form-control input-sm">
                    </div>                         
                </div>
                <div class="form-group">
                    <div class="col-sm-8"></div>
                        <label class="col-sm-2 control-label" for="invno">Total GRN Value</label>
                    <div class="col-sm-2"> 
                        <input type="number" style="text-align: right;" name="total_value" id="total_value" disabled class="form-control input-sm">
                    </div>                         
                </div>

                <div class="form-group">
                    <div class="col-sm-8"></div>
                        <label class="col-sm-2 control-label" for="invno">Total Received Qty</label>
                    <div class="col-sm-2"> 
                        <input type="number" style="text-align: right;" name="total_r_value" id="total_r_value" disabled class="form-control input-sm">
                    </div>                            
                </div>

                <div class="form-group">
                    <div class="col-sm-8"></div>  
                    <label class="col-sm-2 control-label" for="invno">Total Order Qty</label>
                    <div class="col-sm-2"> 
                        <input type="number" style="text-align: right;" name="total_o_value" id="total_o_value" disabled class="form-control input-sm">
                    </div>                         
                </div>

        </form>
    </div></div> </div>
</section>
<script>new_inv();</script>