<?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/import_po.js?v3"></script>

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

    <div class="box box-primary">
        <div class="box-header with-border">
            <h3 class="box-title">Import Po</h3>

        </div>

        <form role="form" name ="form1" class="form-horizontal">
            <div class="box-body">
                <br>               
                <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 
				$sql_userp="select * from view_userpermission where username='".$_SESSION["UserName"]."' and docname='IMPORT PO' and grp='Data Capture' ";
            	$result_userp = $conn->query($sql_userp);
                if ($row_userp = $result_userp->fetch()) {
            	    
            	    if($row_userp['doc_feed']==1){
            	       echo" <a onclick='save_inv();' class='btn btn-success btn-sm'>
                            <span class='fa fa-save'></span> &nbsp; Save
                        </a> ";
            	    } 
            	    if($row_userp['doc_feed']==1){
            	       echo" <a onclick='update_inv();' class='btn btn-warning  btn-sm'>
                            <span class='fa fa-save'></span> &nbsp; Update
                        </a> ";
            	    } 
            	    if($row_userp['doc_view']==1){
            	       echo" <a onclick=\"NewWindow('import_po_search.php', 'mywin', '800', '700', 'yes', 'center'); return false\" class='btn btn-info btn-sm'>
                            <span class='fa fa-search'></span> &nbsp; Search
                        </a> ";
            	    } 
            	    
            	     if($row_userp['doc_print']==1){
            	       echo" <a onclick='print_inv();' class='btn btn-default btn-sm'>
                            <span class='fa fa-print'></span> &nbsp; Print
                        </a> ";
            	    }
            	    
            	    if($row_userp['doc_cancel']==1){
            	       echo" <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" size="20" name="dte_shedule" id="dte_shedule" value="" class="text_purchase3">
                    <input type="text" placeholder="Uniq"  id="uniq" class="form-control input-sm">
                    <input type="text" placeholder="count"  id="count" class="form-control input-sm">
                    <input type="text" placeholder="countpro"  id="countpro" class="form-control input-sm">
                </div>

                <div id="msg_box"  class="span12 text-center"  ></div>
                 

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

                <div class="form-group">
                        <label class="col-sm-1 control-label" for="invno">PO No</label>
                    <div class="col-sm-2">
                        <input type="text" class="form-control input-sm" disabled="disabled" name="invno" id="invno" onblur="purord_ind('ord');"> 
                    </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"  value="<?php echo date("Y-m-d"); ?>" disabled class="form-control  input-sm">  
                    </div>
                    <label class="col-sm-1 control-label" for="invno">BL No</label>
                    <div class="col-sm-2">
                        <input type="text" name="blno" id="blno" class="form-control   input-sm">
                    </div>
                    <label class="col-sm-1 control-label" for="invno">Country</label>
                    <div class="col-sm-2">
                        <select name="country" id="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>

                <div class="form-group">
                    <label class="col-sm-1 control-label" for="invno">Supplier</label>
                    <div class="col-sm-1">
                        <input type="text" disabled  name="supplier_code" id="supplier_code" class="form-control   input-sm">  
                    </div>
                    <div class="col-sm-3">
                        <input type="text" disabled  id="supplier_name" name="supplier_name" class="form-control   input-sm">  
                    </div>
                    <div class="col-sm-1">
                        <a onclick="NewWindow('import_po_supp_search.php', 'mywin', '800', '700', 'yes', 'center'); return false" class="btn btn-info active btn-sm">
                            <span class="fa fa-search"></span>
                        </a>
                    </div> 
                    <label class="col-sm-1 control-label" for="invno">PI No</label>                     
                    <div class="col-sm-2">
                        <input type="text" name="pi_no" id="pi_no" class="form-control   input-sm" >
                    </div>
                    <label class="col-sm-1 control-label" for="invno">CI No</label>
                    <div class="col-sm-2">
                        <input type="text" name="invno1" id="invno1" class="form-control   input-sm">  
                    </div>
                </div>

                <div class="form-group">
                    <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>
                    <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">LC/TT No</label>
                    <div class="col-sm-2">
                        <input type="text"  name="lc_no" id="lc_no" 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="set_brand();" onclick="set_brand();">
                            <?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> 
                     
                </div>

                <div class="form-group" >
                    <label class="col-sm-1 control-label" for="invno">Remark</label>
                    <div class="col-sm-5">
                        <input type="text"  id="remarks" name="remarks" class="form-control   input-sm">  
                    </div>  
                    <div class="col-sm-3" >
                        <label style="background-color: #00CCCC">
                            &nbsp;&nbsp;
                          <input type="radio" name="vatgroup" value="non" id="vatgroup_0" disabled  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" disabled  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"  disabled onclick="calc1_table_discount1();">
                            &nbsp;&nbsp;SVAT&nbsp;&nbsp;
                        </label>
                         
                    </div>
                     <label class="col-sm-1 control-label" for="invno">Arrival Date</label>
                    <div class="col-sm-2">
                        <input type="date"  name="ardate" id="ardate" class="form-control   input-sm" >
                    </div>
                </div>

                <h3 style="font-size: 18px; font-weight: bold;" class="box-title">Item Details</h3>
                <table class="table table-bordered">
                    <tr class="info">
                        <td class="col-sm-1" >Item Code</td>
                        <td class="col-sm-3">Description</td>
                        <td width="2%"></th>
                        <td class="col-sm-1">Pattern</td>
                        <td class="col-sm-1">Qty</td>
                        <td class="col-sm-1">Rate ($)</td>
                        <td class="col-sm-1">Sub Total</td>
                        <td width="5%">#</td>
                    </tr>
                     
                
                    <tr>
                        <td>
                            <input type="text"  class="form-control input-sm" name="itemd_hidden" id="itemd_hidden" onblur="itno_ind();" disabled="disabled">
                        </td>
                        <td>
                            <input type="text"  class="form-control input-sm" id="itemd" name="itemd" disabled="disabled">
                        </td>
                        <td>
                            <a onclick="NewWindow('import_po_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>
                            <input type="text"  class="form-control input-sm" name="partno" id="partno" disabled="disabled">
                        </td>
                        <td>
                            <input type="number"  class="form-control input-sm" onkeyup="cal_subtotal();"  name="qty" id="qty">
                        </td>
                        <td>
                            <input type="number"  class="form-control input-sm" onkeyup="cal_subtotal();"  name="rate" id="rate">
                        </td>
                        <td>
                            <input type="number"  class="form-control input-sm"  disabled name="subtotal" id="subtotal">
                        </td>
                        <td>
                            <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 id="itemdetails">  </div>
                <div class='row'>
                     <div id="sales_provi" class='col-md-6' > </div>
                     <div class='col-md-6' > 
                         <div class="form-group">
                                <div class="col-sm-3"></div>
                                <label class="col-sm-3 control-label" for="invno">Total</label>
                                <div class="col-sm-4">
                                    <input type="number" name="tot" id="tot"   class="form-control   input-sm">
                                </div>
                            </div>
                             <div class="form-group">
                                <div class="col-sm-3"></div>
                                <label class="col-sm-3 control-label" for="invno">Vat Value</label>
                                <div class="col-sm-4">
                                    <input type="number" name="vatvalue" id="vatvalue" disabled class="form-control   input-sm">
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-3"></div>
                                <label class="col-sm-3 control-label" for="invno">Total Quantity</label>
                                <div class="col-sm-4">
                                    <input type="number" name="totqty" id="totqty"   class="form-control   input-sm">
                                </div>
                            </div>
                     </div>
                </div>
               
               
                <div id="payhistory"></div>
                <div id="edit_log"></div>

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

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

</section>

<script>new_inv();</script>