<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
get_pagesecurity('4','views','R');     
$_SESSION['cuPages']='dai_dsrlist.php';   
$cuPage='dai_dsrlist.php';    
$aid=$_SESSION['uid'];
$brid=$_SESSION['abrid'];    
}else{
header('Location:../index.php');
exit;    
}
$mhead='daily';
$menuh='Daily Process';
$phead='barcode';
$page='Barcode';
$dtnow = date("Y-m-d h:i:s", time());
?>
<?php 
if(isset($_POST['delbar'])){
$id=$_POST['delbar'];
$sql1="SELECT * FROM tbl_barcode WHERE id='$id'";
$query1=mysqli_query($con,$sql1)or die(mysqli_error($con));
$row=mysqli_fetch_array($query1);
$name=$row['name'];


$sql="DELETE FROM tbl_barcode WHERE id='$id'";
$query=mysqli_query($con,$sql)or die(mysqli_error($con));

$efid=mysqli_affected_rows($con);    
if($efid>0){    
$act =remove_junk(escape('Product: '.$code));    
write_activity($aid,'BAR','Barcode has been deleted',$act);       
save_msg('s','Barcode Successfully Deleted!!!');
}else{
save_msg('w','Barcode Fail to Delete!!!');   
}
echo "<script>window.location='dai_barcodegen.php'</script>";     
}
?>
<?php
include('../layout/head.php');
include('../layout/header.php');
include('../layout/side_nav.php');
?>
<?php 
?>
<div class="content-wrapper">
    <?php include('../layout/page_head.php'); ?> 
    <!-- Main content -->
        <section class="content">
            
            <div class="row">
                <div class="col-md-8">
                    <div class="box box-solid">
                        <div class="box-header with-border">
                            <h3 class="box-title">Barcode List</h3>
                        </div>
                        <div class="box-body">
                            <?php echo display_msg();?>    
                            <div class="col-md-12 table-responsive">
                                <table class="table table-bordered table-striped" id="datarec">
                                    <thead class="text-uppercase">
                                        <tr>
                                            <th width="30px">SN</th>
                                            <th>Name</th>  
                                            <th>Code</th>
                                            <th>Date</th>    
                                            <th width="40px">Action</th>  
                                        </tr>
                                    </thead>    
                                    <tbody>
                                        <?php
                                        $sql="SELECT * FROM tbl_barcode ORDER BY id ASC";    
                                        $query=mysqli_query($con,$sql)or die(mysqli_error($con));
                                        while ($row=mysqli_fetch_array($query)){

                                        ?>
                                            <tr>
                                                <td width="30px"><?php echo count_id();?></td>
                                                <td><?php echo $row['name'];?></td>       
                                                <td><?php echo $row['code'];?></td>
                                                <td><?php echo $row['date'];?></td>
                                                <td nowrap="">
                                                    <!-- <a class="btn btn-flat bg-purple" href="#" onclick="edit_item('ED_<?php echo $row['code'];?>')" data-toggle="tooltip" title="Edit"><i class="fa fa-edit"></i></a>    -->
                                                    <a class="btn btn-flat bg-purple" href="#" onclick="remove_item('DL_<?php echo $row['id'];?>')" data-toggle="tooltip" title="Delete"><i class="fa fa-trash"></i></a>
                                                    <a class="btn btn-flat bg-purple stiker" href="#" id="ST_<?php echo $row['id'];?>"><i class="fa fa-tag"></i></a>    
                                                    <form action="dai_barcodegen.php" id="DL_<?php echo $row['id'];?>" method="post" >
                                                    <input type="hidden" name="delbar" value="<?php echo $row['id']; ?>" />
                                                    </form>
                                                    <form action="dai_barcodegenedit.php" id="ED_<?php echo $row['id'];?>" method="post" >
                                                    <input type="hidden" name="editbar" value="<?php echo $row['id']; ?>" />
                                                    </form> 
                                                </td>     
                                            </tr> 
                                        <?php }?>     
                                    </tbody>   
                                </table>
                            </div>
                            <div class="clearfix" ></div>  
                            <div class="row"style="margin-top: 15px" >
                                <div class="col-md-12 table-responsive">    
                                    <div class="col-md-8"></div>
                                    <div class="col-md-4 text-right" >
                                        <a href="dai_barcodegencre.php" class="btn btn-flat bg-purple">Add Barcode</a>   
                                    </div>
                                </div>    
                            </div>    
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="box box-solid">
                                <div class="box-header">
                                    <h3 class="box-title">History </h3>
                                </div>

                                <div class="box-body" >
                                <?php if($_SESSION['access']=='1'){echo read_activity($aid,'DSR','A');}else{echo read_activity($aid,'DSR','U');}?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div> 
        
            <?php include('../layout/quick.php');?>   
        </section>
    <!-- /.main content -->  
    <?php include('../layout/print.php'); ?>    
   <?php include('../layout/rsidebarcode.php'); ?>       
</div>

<?php 
include('../layout/footer.php');
?>
<!-- page script -->
<script type="text/javascript">
$(document).ready(function() {
$('#datarec').DataTable({stateSave: true});   
});
function edit_item(id) {
   document.getElementById(id).submit(); 
}
function remove_item(id) {
        bootbox.confirm({
            title: "Confirm",
            message: "Are you sure to delete ?",
            buttons: {
                confirm: {
                    label: 'Yes',
                    className: 'btn-flat bg-purple'
                },
                cancel: {
                    label: 'Cancel',
                    className: 'btn-flat bg-gray'
                }
            },
            callback: function (result) {
                if (result == true) {
                    document.getElementById(id).submit();
                }
            }
        });

    }

$(".details-invoice").click(function (e) {
id_arr = $(this).attr('id');
id = id_arr.split("_");

$.ajax({
url: 'dai_viewdsrlist.php',
method: "POST",
data:{ 
invid: id[1]
},
success: function(data){
$('#listitem').html(data);
pagelist();    
}
});    
    
$.ajax({
url: 'dai_viewdsr.php',
method: "POST",
data:{ 
print: id[1]
},
success: function(data){
$('#invhold').html(data);
sethead();    
}
});
    
$('.right-side').toggle('slide', { direction: 'right' }, 300);    

e.preventDefault();
});

$(document).on('click', '#closepop', function() {
if($('.right-side').is(':visible')) { $('.right-side').toggle('slide', { direction: 'right' }, 300); }   
});    

$('#listitem').on('click','li', function(){
   $(this).addClass('active').siblings().removeClass('active');
});
    
$(document).on('click', '.invdsr', function() {
id_arr = $(this).attr('id');
id = id_arr.split("_");
var ids = id[1];
$.ajax({
url: 'dai_viewdsr.php',
method: "POST",
data:{ 
print: ids
},
beforeSend: function() {
$("#invhold").fadeOut('slow');
},    
success: function(data){    
$('#invhold').html(data);
$("#invhold").fadeIn('slow');    
sethead();    
}
});     
}); 


$(document).on('click','.stiker',function(e) {
id_arr = $(this).attr('id');
id = id_arr.split("_");   
$.ajax({
url: 'dai_barcodegenprint.php',
method: "POST",
data:{ 
stiker: id[1]
},
success: function(data){
$('#addsitem').html(data);    
$('.right-side-add').toggle('slide', { direction: 'right' }, 300);    
}
});    
e.preventDefault();    
});


</script>
<!-- /page script -->
</html>    