<!DOCTYPE html>
<html lang="en">
<head>

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Chandrani Pearls Gold Billing</title>
  <link rel="icon" type="image/jpg" href="dist/img/favicon.png?v=2">
  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">

    <!-- -=---- searchable dropdown link css ------ -->
  <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
   <!-- -=---- searchable dropdown link css ------ -->

  
  <!-- DataTables -->
  <link rel="stylesheet" href="plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
  <link rel="stylesheet" href="plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
  <link rel="stylesheet" href="plugins/datatables-buttons/css/buttons.bootstrap4.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/adminlte.min.css">
	<link rel="stylesheet" href="dist/css/custom.css?v=2">
	<style>
	
/* faqs styling */

section.faq .question__faqs {
   padding: 10px 80px 10px 0px;
   
    font-size: .96rem;
    height: auto;
}

section.faq .wrapper_child {
    border-bottom: 0px solid #0A3F6B;
    
}

section.faq .answercont {
    color: #424242;
}

.answer {
    padding: 18px 11px 20px;
    box-sizing: border-box;
    overflow: hidden;
    transition: max-height 0.3s ease;

}

/* faqs styling end */




section.questionsfaq {
    border-top-left-radius: 50px;
    border-top-right-radius: 50px;
    margin-top: -75px;
}

section.questionsfaq .wrapper_child {
    border-bottom: 1px solid white;
}

section.questionsfaq .wrapper_child:first-child {
    border-top: 1px solid white;
}

.question__faqs {
    font-size: 1.2rem;
    font-weight: 600;
    padding: 20px 80px 20px 0px;
    position: relative;
    display: flex;
    align-items: center;
    cursor: pointer;
    color: #0A3F6B;
}

.question__faqs::after {
    content: "\002B";
    font-size: 1.5rem;
    position: absolute;
    right: 20px;
    transition: 0.2s;
}

.question__faqs.active::after {
    transform: rotate(45deg);
}

.answercont {
    max-height: 0;
    overflow: hidden;
    transition: 0.3s;
    color: white;
}

section.questionsfaq .answer {
    padding: 0 0 20px;
}


	
	
	
	
	
.table td, .table th {
    padding: .35rem .0rem;
    
}
	
	
	
	    label {
    display: inline-block;
    margin-bottom: 0rem;
}

.text-primary{
    color:#0a6abb !important;
}

button:focus{

outline: none;

}
table{
margin: auto;
margin-bottom: 20px;
font-size:13px
}
th,td{
padding: 10px;
}

.table-container {
  width: 1800px;
  height: 700px;
  border: 1px solid #ccc;
  overflow-y: auto;
  font-family: Arial, sans-serif;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background-color: #f2f2f2;
  position: sticky;
  top: 0;
  z-index: 1;
}

th, td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid #ddd;
}

tbody tr:hover {
  background-color: #f5f5f5;
}

tbody tr:nth-child(even) {
  background-color: #fafafa;
}

	</style>




	
 <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>	


</head>
	


<body class="hold-transition sidebar-mini" >
	
<div class="wrapper">




  <!-- Navbar -->
    <?php include ("topheader.php"); ?>
  <!-- Main Sidebar Container -->
    <?php include ("sidemenu.php"); ?>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
 
 
 <?php 

$collection_id = base64_decode($_REQUEST['collection_id']); 


$fetch_sql=$Mainclass->dbh->prepare("SELECT collection_name FROM gold_collection_master WHERE SLN=?");
$fetch_sql->bind_param('i',$collection_id);
$fetch_sql->execute();
$fetch_qry=$fetch_sql->get_result();
$data=$fetch_qry->fetch_assoc();
?>

 
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h3>Update Products For <?php echo $data['collection_name'] ?></h3>
                </div>
                <div class="col-sm-6">
                    
                </div>
            </div>
        </div>
    </section>
    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">
            
            <!-- /.card -->
            <div class="card">
            
              
              <!-- /.card-header -->
			  
	
			  
              <div class="card-body">


<div class="row">

<div class="table-container">
  <table>
    <thead>
        
      <tr>
        <th>#</th>
        <th>Category</th>
        <th>Product Id</th>
        <th>Barcode</th>
        <th>Product Name</th>
      </tr>
    </thead>
    <tbody>
        
<?php

$SQL1=$Mainclass->dbh->prepare("SELECT SLN,ProductCategory,Productid,Barcode,ProductName,collection_id FROM gold_products_master WHERE Active='Yes' and (collection_id='' or collection_id=?)  Order by SLN desc");
$SQL1->bind_param("i",$collection_id);
$SQL1->execute();
$QryProcessor=$SQL1->get_result();

$i=1;

while ($processor = $QryProcessor->fetch_assoc())
{
$cat_id=     $processor['ProductCategory'];
    
$fetch_sql=$Mainclass->dbh->prepare("SELECT Category FROM gold_product_category_master WHERE SLN=?");
$fetch_sql->bind_param('i',$cat_id);
$fetch_sql->execute();
$fetch_qry=$fetch_sql->get_result();
$data=$fetch_qry->fetch_assoc();    

if($processor['collection_id']==""){
    
$a = "";    
    
}

else{
    
$a = "checked";    
    
}
    
?>
      <tr>
        <td><input type="checkbox" onclick="update_collection('<?php echo $processor['SLN'] ?>')" id="check_id<?php echo $processor['SLN'] ?>" <?php echo $a ;?>></td>
        <td><?php echo $data['Category'] ?></td>
        <td><?php echo $processor['Productid'] ?></td>
        <td><?php echo $processor['Barcode'] ?></td>
        <td><?php echo $processor['ProductName'] ?></td>
      </tr>
    <?php

$i++;

}

$SQL1->close();

?>
    </tbody>
  </table>
</div>
</div>


<div id="scan_data"></div>
<br><br>

<div class="row">

<div class="col-12">
<div class="form-group d-flex align-items-center justify-content-end" style="gap:30px;">
<input type="button" class="btn btn-primary" value="Save & Complete"  style="width:200px;background-color:#0979d8;border: none;" onclick="save_and_complete()">  
</div>
</div>


</div>
  </div> 




              <!-- /.card-body -->

            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->


    <?php include ("footer.php"); ?>

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->


  </aside>
  <!-- /.control-sidebar -->
</div>




<!-- ./wrapper -->
<!-- jQuery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- DataTables  & Plugins -->
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script src="plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
<script src="plugins/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
<script src="plugins/jszip/jszip.min.js"></script>
<script src="plugins/pdfmake/pdfmake.min.js"></script>
<script src="plugins/pdfmake/vfs_fonts.js"></script>
<script src="plugins/datatables-buttons/js/buttons.html5.min.js"></script>
<script src="plugins/datatables-buttons/js/buttons.print.min.js"></script>
<script src="plugins/datatables-buttons/js/buttons.colVis.min.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="dist/js/demo.js"></script>
<!-- Page specific script -->
<script>
  $(function () {
    $("#example1").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
     // "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');
    $('#example2').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": false,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": true,
    });
  });
</script>

<script>
function success_msg()
	{
		Swal.fire({
              icon: 'success',
              title: '',
              text: 'Product Added To Collection.',  
               showConfirmButton:false,
               timer:2000,
               toast:true,
               animation:true,
               position:'top-center',
        }).then(function() {  

});
	}
function remove_msg()
	{
		Swal.fire({
              icon: 'error',
              title: '',
              text: 'Product Removed From Collection.',  
               showConfirmButton:false,
               timer:2000,
               toast:true,
               animation:true,
               position:'top-center',
        }).then(function() {  

});
	}

function update_collection(per){
    
let collection_id = "<?php echo $collection_id; ?>";
let checkBox = document.getElementById("check_id"+per);
var flag = "";

if (checkBox.checked) {
   var flag = "Add"; 
} 

else {
    var flag = "Delete"; 
}


$.ajax({
url:'ajax-add-product-to-collection.php',
type:'POST',
data:{per:per,flag:flag,collection_id:collection_id},
success:function(f){
 if(flag == "Add")
	{
	success_msg();
	}
  if(flag == "Delete")
	{
	remove_msg();
	}
}
});
    
}



function save_and_complete(){
    
window.location.href="view-collections.php";    
    
    
}


</script>



</body>
</html>