<?php 
session_start();
$where 					= " WHERE 1=1 ";
$next_page_condition 	= "";
$paging ="";
if($_REQUEST['start']){
	$paging .="&start=".$_REQUEST['start'];
}
$frontEndURL = $config->frontEndURL;
###########################################  STRAT FILTER CONITIONS    #####################################
$category	= isset($_REQUEST['category']) ? $_REQUEST['category'] : "";
if($category) {
    $where	.= " AND product_group_name LIKE '%$category%' ";
    $next_page_condition.="&category=$category";
}

###########################################  	END  FILTER CONITIONS 	#####################################
###########################################  PAGING WITH PER PAGE  #####################################
$file_name		= "index"; // this is file name which is used during paging  , included at the bottom of the page
$table_name		= "product_group";
$paging_table_name	= $table_name;
$paging_query		= $where;
$join_query_for_paging = "SELECT * FROM $table_name  $where ";
$page_header = "Update Bill OF Materials / Part Number";
include("paging/paging_query.inc.php");
############################################ END PAGING WITH PER PAGE  #######################################
$query = "SELECT * FROM $table_name $where ORDER BY id DESC LIMIT $eu, $limit";
$sql=mysqli_query($conn,$query);
$result=mysqli_num_rows($sql);

$total_no_of_counties = mysqli_num_rows(mysqli_query($conn,$join_query_for_paging));
#################################   DELETE    #########################################
// when we click on delete this area of php code will execute
if(isset($_REQUEST['action']) && $_REQUEST['action']=='delete')
{
	$sql=mysqli_query($conn,"DELETE FROM $table_name WHERE id = '".$_REQUEST['id']."' ");
	$sql=mysqli_query($conn,"DELETE FROM product_group_mapping WHERE group_id = '".$_REQUEST['id']."' ");
	$_SESSION['info_message'] = " Part Number  deleted sucessfully";
	header("location: $file_name?page=view".$next_page_condition.$paging);
	exit;
}
#################################  END DELETE    #########################################


if($_POST["update"]){
	
	$id=$_POST["id"];
	$pro_id=$_POST["pro_id"];
	$pro_temp_id=$_POST["pro_temp_id"];
	for($i=0;$i<count($_POST["group_code"]);$i=$i+1){
		$group_code = $_POST["group_code"][$i];
		$group_name = $_POST["group_name"][$i];
		$qty = $_POST["qty"][$i];
		$unit = $_POST["unit"][$i];
		$product_cost = $_POST["product_cost"][$i];
		$product_labour_cost = $_POST["product_labour_cost"][$i];
		$product_labour_hours = $_POST["product_labour_hours"][$i];
		$group_number = $_POST["group_number"][$i];
		$sql="update product_name set group_code='".$group_code."',group_name='".$group_name."',cost='".$product_cost."',labour_cost='".$product_labour_cost."',labour_hours='".$product_labour_hours."',group_number='".$group_number."',qty='".$qty."',unit='".$unit."' where id='".$id."'";
		mysqli_query($conn,$sql);
		if (isset($_POST["chk"]) && is_array($_POST["chk"])) {
		if(count($_POST["chk"])>0){
			$sql="delete from product_link where parent_id='".$id."' and child_id not in (".implode(",",$_POST["chk"]).")";
			//echo "<br/>".$sql;
			mysqli_query($conn,$sql);
			for($j=0;$j<count($_POST["chk"]);$j=$j+1){
				$sql="select * from product_link where parent_id='".$id."' and child_id='".$_POST["chk"][$j]."'";
				//echo "<br/>".$sql;
				$res1=mysqli_query($conn,$sql);
				if(mysqli_num_rows($res1)<=0){
					$sql="insert into product_link set parent_id='".$id."', child_id='".$_POST["chk"][$j]."'";
					//echo "<br/>".$sql;
					mysqli_query($conn,$sql);
				}
			}
		}else{
			$sql="delete from product_link where parent_id='".$id."'";
			//echo "<br/>".$sql;
			mysqli_query($conn,$sql);
		}
		//var_dump($_POST);
		
		
	} else {
			// Handle the case where $_POST["chk"] is not set or is not an array
			// For example, you might display an error message or perform some other action.
			
		}
		}
		$query_string 	=  (isset($_POST['query_string'])) ? $_POST['query_string'] : $_SERVER['QUERY_STRING'];
		if(isset($from) && $from == "view_product"){
			$query_string = str_ireplace("page=edit", "page=view_product_details", $query_string);
		}else {
			$query_string = str_ireplace("page=edit", "page=view_product_details", $query_string);
		}
	$_SESSION['info_message'] = "Part Number Updated Sucessfully";
	//header("Location: index?page=view_product_details&from=view_product&pro_temp_id=" . $pro_temp_id . "&id=" . $pro_id);
	//exit;
}
?>
<style>
.list-group-item>.badge {
    float: none !important; 
    margin-left: 10px;
}
.node-treeview button{
    background: none;
    border: none;
}
.no_background_border{
    background: none;
    border: none;
}
</style>
<div class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-6">
                <h1>
                    <?=$page_header;?>
                </h1>
            </div>
            <div class="col-sm-6">
                <?
			$query_string 	=  (isset($_POST['query_string'])) ? $_POST['query_string'] : $_SERVER['QUERY_STRING'];
			if(isset($from) && $from == "view_item"){
				$query_string = str_ireplace("page=edit", "page=view_item_details", $query_string);
			}else {
				$query_string = str_ireplace("page=edit", "page=view_item_details", $query_string);
			}
				
			?>
                <button type="button" id="back" name="back" value="back"
                    style="float:right;margin-right:5px;margin-bottom:8px;" class="btn btn-success"
                    onclick="window.location.href = 'index?<?=$query_string;?>'">Back</button>
            </div>
        </div>
        <!-- /.row -->
    </div>
    <!-- /.container-fluid -->
</div>
<section class="content">
	<div class="container-fluid">
		<div class="row">
			<div class="col-lg-12">
				<div class="card">
				<!----------------------- Message ------------------------------->
				 <?php if(isset($_SESSION['info_message'])) { ?>
						<script>
							$(document).ready(function(){
								Toastify({
									text: "<?php echo $_SESSION['info_message']; ?>",duration: 3000,close: true,gravity: "top",position: 'right',backgroundColor: "#3498DB",style: {borderBottom: "3px solid white",},
								}).showToast();
								<?php unset($_SESSION['info_message']); ?>
							});
						</script>
					<?}?>
				<!----------------------- End Message ------------------------------->
			<div class="card-body">
								
				<div class="modal fade" id="ShowModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalScrollableTitle" aria-hidden="true">
				  <div class="modal-dialog modal-dialog-scrollable" role="document" style="width:65%; max-width:80%">
					<div class="modal-content">
					  <div class="modal-header">
						<h5 class="modal-title" id="exampleModalScrollableTitle" style="float:left">Group Tree</h5>
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						  <span aria-hidden="true">&times;</span>
						</button>
					  </div>
					  <div class="modal-body">
						<!--<h5 class="modal-title" id="exampleModalScrollableTitle">Q->Quantity, C->Cost, LC->Labour Cost, TC->Total Cost, TLC->Total Labour Cost</h5>-->
						<div id="group_tree" style="">
						</div>
					  </div>
					  <div class="modal-footer">
						<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
						
					  </div>
					</div>
				  </div>
				</div>
				
				<form method="post">
				   <div class="row">
				   <?php
					// Database connection
					// Step 1: Retrieve ID from URL
					$id = isset($_GET['id']) ? intval($_GET['id']) : 0;

					if ($id > 0) {
						// Step 2: Fetch Parent Record
						$query_parent = "SELECT * FROM product_name WHERE pro_id = $id";
						$result_parent = $conn->query($query_parent);
						$parent_row = $result_parent->fetch_assoc();

						if ($parent_row) {
							$id = $parent_row['id']; // Parent pro_id

							/* 
							$query_children = "SELECT child_id FROM product_link WHERE parent_id = $id";
							$result_children = $conn->query($query_children);

							$child_ids = [];
							while ($row = $result_children->fetch_assoc()) {
								$child_ids[] = $row['child_id'];
							}

							// 
							$all_ids = array_merge([$parent_row['id']], $child_ids); // Include parent id
							$id_list = implode(',', $all_ids);
					 */
							$query_dropdown = "SELECT * FROM product_name WHERE id IN ($id)";
							$result_dropdown = $conn->query($query_dropdown);

							// Step 5: Generate Dropdown
							echo '<label class="control-label">Select Part Number</label>';
							echo '<select name="group_code_search" id="group_code_search" class="form-control select2">';
							while ($row = $result_dropdown->fetch_assoc()) {
								echo '<option value="' . $row['id'] . '">' . htmlspecialchars($row['group_name']) . '</option>';
							}
							echo '</select>';
						} else {
							echo 'No parent record found.';
						}
					} else {
						echo 'Invalid ID.';
					}
					?>

					<div class="col-lg-2 col-md-2 "> 
					<label class="control-label text-white">Show</label>
					<div>
					   <input type="submit" id="edit" class="btn btn-primary hide" name="edit" value="Show Details"/>
					</div>
					</div>
					</div>
				</form>
				<form method="post">
					<?php
													
							function calculate_child_cost($id){
								global $conn;
								$total_cost=0;
								$total_labour_cost=0;
								
								$stack=array();
								$stack[]=$id;
								while(count($stack)>0){
									$id=$stack[0];
									array_splice($stack, 0, 1);
									$sql="select * from product_name where id='".$id."'";
									$res=mysqli_query($conn,$sql);
									$row=mysqli_fetch_assoc($res);
									$total_cost=$total_cost + ($row["cost"] * $row["qty"]);
									$total_labour_hours=$total_labour_hours + ($row["labour_hours"]);
									$total_labour_cost=$total_labour_cost + ($row["labour_cost"] * 1);
									$total_final_cost = $total_cost + $total_labour_cost;
									$sql="select * from product_link where parent_id='".$id."'";
									$res=mysqli_query($conn,$sql);
									while($row=mysqli_fetch_assoc($res)){
										$stack[]=$row["child_id"];
									}
									
								}
								
								return array($total_labour_hours,$total_cost,$total_labour_cost,$total_final_cost);
							}
						echo '<input type="hidden" id="id" name="id" value="'.$_REQUEST["group_code_search"].'"/>';
						echo '<input type="hidden" id="pro_temp_id" name="pro_temp_id" value="'.$_REQUEST["pro_temp_id"].'"/>';
						echo '<input type="hidden" id="pro_id" name="pro_id" value="'.$_REQUEST["id"].'"/>';

						if($_POST["edit"]){
							$id=$_REQUEST["group_code_search"];
							$main_id=$_REQUEST["id"];
							$sql="select * from product_name where id='".$id."'";
							$res=mysqli_query($conn,$sql);
							$row=mysqli_fetch_assoc($res);
							$child_cost=calculate_child_cost($row["id"]);
					?>
							<table style="width:100%" id="product_list">
								<tr>
									<td  class="col-lg-1"><label class="control-label" style="font-size:15px;">P Number  </label><br/><input type="text" id="group_number" name="group_number[]" value="<?php echo $row["group_number"];?>" class="form-control" placeholder="P Num.." /></td>
									<td style="text-align:left;padding:5px;width:10%;" class="col-lg-1"><label class="control-label">P Name  </label><br/><input type="text" id="group_name" name="group_name[]" value="<?php echo $row["group_name"];?>" class="form-control" placeholder="P Name" required/></td>
									<td class="col-lg-1"><label class="control-label">G Code </label><br/><input type="text" id="group_code" name="group_code[]" value="<?php echo $row["group_code"];?>"  class="form-control" placeholder="G Code" required/></td>
									
									<td class="col-lg-1"> <label class="control-label">Quantity </label><br/><input type="number" id="qty" name="qty[]" step="0.01" value="<?php echo $row["qty"];?>" class="form-control" placeholder="Qty" required/></td>
									<td class="col-lg-1"> <label class="control-label text-white">unit </label><br/><input type="text" id="unit" name="unit[]"  value="<?php echo $row["unit"];?>" class="form-control" placeholder="em" /></td>
									<td class="col-lg-1"><label class="control-label">Cost : </label> <br/><input type="number" id="product_cost" name="product_cost[]" min="0" value="<?php echo $row["cost"];?>" class="form-control"  placeholder="Cost" required/></td>
									<td class="col-lg-1"> <label class="control-label" style="font-size:15px;">Labour Cost </label><br/><input type="number" id="product_labour_cost" name="product_labour_cost[]" min="0" value="<?php echo $row["labour_cost"];?>" class="form-control" placeholder="Labour Cost" required/></td>
									
									<td class="col-lg-1"> <label class="control-label" style="font-size:15px;">Labour Hrs </label><br/><input type="number" id="product_labour_hours" name="product_labour_hours[]" step="0.01" value="<?php echo $row["labour_hours"];?>" class="form-control" placeholder="Hours" required/></td>
							
									<td class="col-lg-2"><label class="control-label">Total Components Cost </label><br/><input type="number" id="total_product_cost" name="total_product_cost[]" min="0" value="<?php echo $child_cost[1];?>" class="form-control" placeholder="Total Component Cost" readonly="readonly"/></td>
									<td class="col-lg-2"><label class="control-label">Total Labour Cost </label><br/><input type="number" id="total_labour_cost" name="total_labour_cost[]" min="0" value="<?php echo $child_cost[2];?>" class="form-control" placeholder="Total Labour Cost" readonly="readonly"/></td>
								</tr>
							</table>
							<br/>
							<table style="width:100%">
								<tr>
									<td>
										<!--<button type="button" value="Add New Product" onclick="add_new_product_list();" />Add New Product</button>-->
										<button type="submit" name="update" value="updatedetails" class="btn btn-success" onclick="validate_form();" >Update</button>
									</td>
								</tr>
							</table>
							<br/>
							<div class="hide" style="float:right;">
								<a href="" data-toggle="modal" data-target="#myModal"
									class="btn btn-warning add_new_station" alt=""
									data-station_name=""
									style="float:right;margin-right:0px;margin-bottom:5px;">Add New Item</a>
							</div>
							<table id="group_details" class=" hide table table-bordered table-striped">
								<thead> 
									<tr> 
										<th></th>
										<th style="font-size:13px;">P Number</th> 
										<th style="font-size:13px;">P Name</th> 
										<th style="font-size:13px;">G Code</th> 
										<th style="font-size:13px;">QTY</th> 
										<th style="font-size:13px;">Cost</th>
										<th style="font-size:13px;">L Cost</th>
										<th style="font-size:13px;">L Hours</th>
										<th style="font-size:13px;">TotCompCost</th>
										<th style="font-size:13px;">TotLabCost</th>
										<th style="font-size:13px;">Total</th>
									</tr> 
								</thead> 	
							</table>	
					<?php
					    
						}

					?>
				</form>

				</div>
			</div>
		</div>
	</div>
	</div>
</section>

</body>
</html>

<script type="text/javascript">
$(document).ready(function() {
    $('#group_code_search').on("change", function() {
        var currentUrl = window.location.href;
        if (currentUrl.includes('group_code_search=')) {
            var newUrl = currentUrl.replace(/([&?])group_code_search=\d+/g, '');
            if (newUrl.endsWith('?') || newUrl.endsWith('&')) {
                newUrl = newUrl.slice(0, -1);
            }
            window.history.pushState({}, "", newUrl);
            $('#edit').click();
        }
    });
});

 $(document).ready(function(){
  $("#myModal .close_button2").click(function(){
		location.reload();
  });	
  });	
$(".add_new_station").click(function(){	
   $("#myModalLabel").html("Add New Part");
	var hide_top_left = "&hide_top=1&hide_left=1";
	var from = "&from=add_new_item_progress";
	var client_id = 'test';
	$('.modal-dialog').css({"max-width":"60%"});
	$(".modal_iframe").attr("src","<?=$config->frontEndURL?>/admin/item_management/index?page=add&client_id="+client_id+hide_top_left+from);
});
$(document).ready(function() {
      var group_code_id = document.getElementById("group_code_search").value;
      if (group_code_id !== '') {
        $('#group_code_search').trigger('change'); 
      }

      $('#group_code_search').on("change", function() {
        $('#edit').click();
      });
});
function validate_form(){
	return true;
}
$('#ShowModal').on('show.bs.modal', function (e) {
  create_group_tree(e.relatedTarget.attributes.alt.value);
})
function deltblrow(ctrl){
	$(ctrl).closest('tr').remove();
	return false;
}
function update_total_cost(){
	//$('#group_details').DataTable().rows().data().toArray()
	//qty[]
	
	//if(document.getElementById("is_parent").checked){
		var total_product_cost=0;
		var total_labour_cost=0;
		var table = $('#group_details').DataTable();
		var rows = table.rows().nodes();
		
		for(i=0;i<rows.length;i=i+1){
			if(rows[i].childNodes[0].childNodes.length!=0){
				if(rows[i].childNodes[0].childNodes[0].checked){
					total_product_cost=total_product_cost + (rows[i].childNodes[6].innerText * 1);
					total_labour_cost=total_labour_cost + (rows[i].childNodes[7].innerText * 1);
				}
			}
		}
		
		for(i=0;i<$('input[name="total_product_cost[]"]').length;i=i+1){
			if($('input[name="qty[]"]')[i].value.trim()==""){
				$('input[name="qty[]"]')[i].value=0;
			}
			if($('input[name="product_cost[]"]')[i].value.trim()==""){
				$('input[name="product_cost[]"]')[i].value=0;
			}
			if($('input[name="product_labour_cost[]"]')[i].value.trim()==""){
				$('input[name="product_labour_cost[]"]')[i].value=0;
			}
			
			$('input[name="total_product_cost[]"]')[i].value=total_product_cost + ($('input[name="qty[]"]')[i].value * $('input[name="product_cost[]"]')[i].value);
			$('input[name="total_labour_cost[]"]')[i].value=total_labour_cost + ($('input[name="product_labour_cost[]"]')[i].value * 1);
		}
	/*}else{
		for(i=0;i<$('input[name="total_product_cost[]"]').length;i=i+1){
			for(i=0;i<$('input[name="total_product_cost[]"]').length;i=i+1){
				if($('input[name="qty[]"]')[i].value.trim()==""){
					$('input[name="qty[]"]')[i].value=0;
				}
				if($('input[name="product_cost[]"]')[i].value.trim()==""){
					$('input[name="product_cost[]"]')[i].value=0;
				}
				if($('input[name="product_labour_cost[]"]')[i].value.trim()==""){
					$('input[name="product_labour_cost[]"]')[i].value=0;
				}
				
				$('input[name="total_product_cost[]"]')[i].value=($('input[name="qty[]"]')[i].value * $('input[name="product_cost[]"]')[i].value);
				$('input[name="total_labour_cost[]"]')[i].value=($('input[name="product_labour_cost[]"]')[i].value * 1);
			}
			
		}			
	}*/
}
function update_group_type(ctrl){
	if(ctrl==1){
		if(document.getElementById("is_parent").checked){
			document.getElementById("is_child").checked=false;
		}else{
			document.getElementById("is_child").checked=true;
		}
	}else{
		if(document.getElementById("is_child").checked){
			document.getElementById("is_parent").checked=false;
		}else{
			document.getElementById("is_parent").checked=true;
		}
	}
	update_total_cost();
}

$(document).on('change', '.group_checkbox', function() {
    var parent_id=document.getElementById("id").value;
	var child_id=$(this).val();
	var id=document.getElementById("id").value;
	if($(this)[0].checked){
		$.ajax({
			url: site_url+"/modules/item_management/index.php?page=ajax_actions&action=get_cyclic_status&parent_id="+parent_id+"&child_id="+child_id,
			method:"POST",
			success: function(data)  
			{
				var resultObj = jQuery.parseJSON(data);    
				if(resultObj.status=="sucess"){
				   if(resultObj.result=="0"){
						update_total_cost();
				   }else{
						alert("Creating link will create become cyclic");
						$(this)[0].checked=false;
				   }
				}else{
					alert("Unable To Process");
				}
			},
			error :function(jqXHR, textStatus, errorThrown)
			{
				alert("something went wrong");
			}   
		});
	}
	
});
$(document).on('change', 'input[name="qty[]"], input[name="product_cost[]"], input[name="product_labour_cost[]"]', function() {
    //alert($(this).val());
	update_total_cost();
});

function add_new_product_list(){
	tbl=document.getElementById("product_list");
	newrow='<tr>';
	newrow=newrow+'<td style="text-align:left;padding:5px;">Group Code : <br/><input type="text" id="group_code" name="group_code[]" value=""/></td>';
	newrow=newrow+'<td style="text-align:left;padding:5px;">Group Name : <br/><input type="text" id="group_name" name="group_name[]" value=""/></td>';
	newrow=newrow+'<td style="text-align:left;padding:5px;">Quantity : <br/><input type="number" id="qty" name="qty[]" step="0.01" value="" required/></td>';
	newrow=newrow+'<td style="text-align:left;padding:5px;">Cost : <br/><input type="number" id="product_cost" name="product_cost[]" min="0" value="" required/></td>';
	newrow=newrow+'<td style="text-align:left;padding:5px;">Labour Cost : <br/><input type="number" id="product_labour_cost" name="product_labour_cost[]" min="0" value="" required/></td>';
	newrow=newrow+'<td style="text-align:left;padding:5px;">Total Cost : <br/><input type="number" id="total_product_cost" name="total_product_cost[]" min="0" value="" readonly="readonly"/></td>';
	newrow=newrow+'<td style="text-align:left;padding:5px;">Total Labour Cost : <br/><input type="number" id="total_labour_cost" name="total_labour_cost[]" min="0" value="" readonly="readonly"/></td>';
	newrow=newrow+'<td style="text-align:left;padding:5px;"><a href="#" onclick="return deltblrow(this)">Del</a></td>';
	newrow=newrow+'</tr>';
	$(tbl).find('tbody').append(newrow);
}
function create_group_tree(id){
	$.ajax({ 
		url: site_url+"/modules/item_management/index.php?page=ajax_actions&action=get_group_list&id="+id,
		method:"POST",
		dataType: "json",       
		success: function(data)  
		{
			$('#group_tree').treeview({
                data: data,
                levels: 1,
                collapseIcon: "fa fa-angle-down",
                expandIcon: "fa fa-angle-right",
                nodeIcon: "fa fa-share-alt-square",
                backColor: 'white',
                showBorder: false,
                enableLinks: true,
                preventUnselect: true,
                 preventUnselect: true,
                showTags: true,
                color:'black'
			});
        },
		error :function(jqXHR, textStatus, errorThrown)
		{
			alert("something went wrong");
        }   
    });
}
$( document ).ready(function() {
	var id=document.getElementById("id").value;
	
	var page='edit';
	$('#group_code_search').select2();
//	create_group_tree(5);
	//create_product_tree();
/* 	$('#group_details').DataTable({
		'lengthMenu': [
			[500,700, 800,1000],
			[500,700, 800,1000]
		],
	  "paging": true,
	  "lengthChange": true,
	  "searching": true,
	  "ordering": true,
	  "info": true,
	  "autoWidth": false,
	  "processing": true,
	  "serverSide": false,
	  "selectedBackColor": 'none',
	  "language": {
		  "emptyTable": "No Group Created.Try Adding Group"
		},
		
	  "ajax": {
			'type': 'POST',
			url: site_url+"/modules/item_management/index.php?page=ajax_actions&action=get_group_details_edit&page_edit=edit&id="+id,
			
	  },
	  'columnDefs': [
		{
			"targets": 0, 
			"className": "text-center"
		},
		{
			"targets": 1,
			"className": "text-center"
		},
		{
			"targets": 2,
			"className": "text-center"
		},
		{
			"targets": 3,
			"className": "text-center"
		},
		{
			"targets": 4,
			"className": "text-center"
		},
		{
			"targets": 5,
			"className": "text-center"
		},
		{
			"targets": 6,
			"className": "text-center"
		},
		{
			"targets": 7,
			"className": "text-center"
		},
		{
			"targets": 8,
			"className": "text-center"
		},
		{
			"targets": 9,
			"className": "text-center"
		},
		{
			"targets": 10,
			"className": "text-center"
		}
	  ],
	  "columns": [
				{ 
					"data": "Action",
					sortable: false,
					"render": function (data, type, full, meta){
						var chk='<input type="checkbox" class="group_checkbox" name="chk[]" value="'+full.chk_val+'"';
						if(full.checked_status!=0){
							chk=chk+' checked="checked" ';
						}
						if(full.cycle_status==1){
							chk=chk+' disabled="disabled" ';
						}
						chk=chk+'/>';
						return chk;
						if(full.checked_status==0){
							return '<input type="checkbox" class="group_checkbox" name="chk[]" value="'+full.chk_val+'"/>';
						}else{
							return '<input type="checkbox" class="group_checkbox" name="chk[]" value="'+full.chk_val+'" checked="checked"/>';
						}
						/*if(full.chk_val=='<?php echo $id;?>'){
							return '';
						}else{
							if(full.cycle_status==0){
								if(full.checked_status==0){
									return '<input type="checkbox" class="group_checkbox" name="chk[]" value="'+full.chk_val+'"/>';
								}else{
									return '<input type="checkbox" class="group_checkbox" name="chk[]" value="'+full.chk_val+'" checked="checked"/>';
								}
							}else{
								return '<input type="checkbox" class="group_checkbox" name="chk[]" value="'+full.chk_val+'"/>';
							}
						}
					}
				},
				{ "data": "group_number" },
				{ "data": "group_name" },
				{ "data": "group_code" },
				{ "data": "qty" },
				{ "data": "cost" },
				{ "data": "labour_cost" },
				{ "data": "labour_hours" },
				{ "data": "total_cost" },
				{ "data": "total_labour_cost" },
				{ "data": "total_final_cost" },
				
				
			],
			
			"fnDrawCallback": function(oSettings) {
            // Hide pagination if fewer records are displayed
            if (oSettings._iDisplayLength > oSettings.fnRecordsDisplay()) {
                $(oSettings.nTableWrapper).find('#group_details_paginate').hide();
            } else {
               // $(oSettings.nTableWrapper).find('#group_details_paginate').show();
            }

            // Update the URL after data is loaded
            
        },

			//order: [[4, 'desc']],
	  
	});
	 */
});
</script>
