<?php
session_start();
if(!isset($_SESSION['linkarisecrm']))
	{
		header('Location: index.php');
		return;
	}
	include("connect.php");	header("Access-Control-Allow-Origin: *");
		
		$cmpmid=$_SESSION['linkarisecmpmid'];
			$umid = $_SESSION['linkariseumid'];

date_default_timezone_set("Asia/Singapore");
	$mdate= date('Y/m/d');
	$mdate1= date('d-m-y h:i:sa');				
	$mdate2= date('d-m-Y');
	$mdate3= date('d-m-Y');
if (isset($_POST['startdate']) && isset($_POST['enddate'])){
	
    // Retrieve the date range string submitted via POST
    $p1 = $_POST['startdate'];
	$p2 = $_POST['enddate'];
    // Extract the individual components of the start date
		$dd1 = substr($p1, 8, 2);
		$mm1 = substr($p1, 5, 2);
		$yy1 = substr($p1, 0, 4);

		// Extract the individual components of the end date
		$dd2 = substr($p2,8,2);
		$mm2 = substr($p2,5,2);
		$yy2 = substr($p2,0,4);	
		
		// Convert the start and end date components into "YYYY-MM-DD" format
		$lower = "$yy1-$mm1-$dd1";
		$upper = "$yy2-$mm2-$dd2";
	
    // Store the original date range and the converted lower and upper dates in session variables
    // $_SESSION['daterange'] = $_POST['daterange'];
    $_SESSION['lowerdate'] = $lower;
    $_SESSION['upperdate'] = $upper;
	
	}else
	{
		$lower =  date('Y-m-d', strtotime('-1 months'));
		$upper =  date('Y-m-d',strtotime(date('Y-m-d')));
		$startdate =  date('d-m-Y', strtotime('-1 months'));
		$enddate =  date('d-m-Y',strtotime(date('Y-m-d')));
		//$lower =  $_SESSION['lowerdate'];
		//$upper =  $_SESSION['upperdate'];
		
		//$_SESSION['cstatus']="All";
		// $status='Pending';
		// $_SESSION['cstatus']="All";
	  $_SESSION['lowerdate']=$lower;
	  $_SESSION['upperdate']=$upper; 
	 
	}
	

if(isset($_POST['spotmid']))
	{
		$_SESSION['spotmid']=$_POST['spotmid'];
	}else
	{
		$_SESSION['spotmid']='All';
	}
	//  Status
	if(isset($_POST['jobworkstatus']))
	{
		$_SESSION['jobworkstatus']=$_POST['jobworkstatus'];
	}else
	{
		$_SESSION['jobworkstatus']='All';
	}	
	// Transaction type
	if(isset($_POST['challantype']))
	{
		$_SESSION['challantype']=$_POST['challantype'];
	}else
	{
		$_SESSION['challantype']='All';
	}
	// Company
	if(isset($_POST['comp']))
	{
		$_SESSION['comp']=$_POST['comp'];
	}else
	{
		$_SESSION['comp']='All';
	}
	
	// Truck
	if(isset($_POST['truckn']))
	{
		$_SESSION['truckn']=$_POST['truckn'];
	}else
	{
		$_SESSION['truckn']='All';
	}
	// Ticket
	if(isset($_POST['ticketn']))
	{
		$_SESSION['ticketn']=$_POST['ticketn'];
	}else
	{
		$_SESSION['ticketn']='All';
	} 
	// itemname
	if(isset($_POST['itemname11']))
	{
		$_SESSION['itemname11']=$_POST['itemname11'];
	}else
	{
		$_SESSION['itemname11']='All';
	} 
	// challanweighttype type
	if(isset($_POST['weightyp']))
	{
		$_SESSION['weightyp']=$_POST['weightyp'];
	}else
	{
		$_SESSION['weightyp']='All';
	}

	// Driver (res_driver_master)
	if(isset($_POST['driverid']))
	{
		$_SESSION['driverid']=$_POST['driverid'];
	}else
	{
		$_SESSION['driverid']='All';
	}

	// Master Field 1 (res_masterfield1_master)
	if(isset($_POST['mf1']))
	{
		$_SESSION['mf1']=$_POST['mf1'];
	}else
	{
		$_SESSION['mf1']='All';
	}

	// Master Field 2 (res_masterfield2_master)
	if(isset($_POST['mf2']))
	{
		$_SESSION['mf2']=$_POST['mf2'];
	}else
	{
		$_SESSION['mf2']='All';
	}
	$eve = "SELECT * FROM res_fieldsetting_master where fieldname= 'Job' ";
	  
	$re = mysqli_query($conn, $eve);
	
		while($rt = mysqli_fetch_assoc($re))
		{
			
					$job11 = $rt['fieldlable'];
			 
		}
		
		
	$eve = "SELECT * FROM res_fieldsetting_master ";
	  
	$re = mysqli_query($conn, $eve);
	
		while($rt = mysqli_fetch_assoc($re))
		{
			
						$fieldname=$rt['fieldname'];
			
			if($fieldname == 'Job Report Pdf View') 
			{
					
					$fshide1=$rt['fshide'];
				} 
			
			if($fieldname == 'Job Report Image View') 
			{
					
				$fshide4=$rt['fshide'];
			}
			if($fieldname == 'Job Report Image')
			{
				$fshide5=$rt['fshide'];
			}
			if($fieldname == 'Job Report Print') 
			{
					
				$fshide6=$rt['fshide'];
			}
			if($fieldname == 'Job Report Export')
			{
				$fshide7=$rt['fshide'];
			}
			if($fieldname == 'Job Report Filter')
			{
				$fshide8=$rt['fshide'];
			}
			
			
		}	
	?>
<!DOCTYPE html>
<!--
Author: Keenthemes
Product Name: Metronic - Bootstrap 5 HTML, VueJS, React, Angular. Laravel, Asp.Net Core, Ruby on Rails, Spring Boot, Blazor, Django, Express Node.js & Flask Admin Dashboard Theme
Purchase: https://1.envato.market/EA4JP
Website: http://www.keenthemes.com
Contact: support@keenthemes.com
Follow: www.twitter.com/keenthemes
Dribbble: www.dribbble.com/keenthemes
Like: www.facebook.com/keenthemes
License: For each use you must have a valid license purchased only from above link in order to legally use the theme for your project.
-->
<html lang="en">
	<!--begin::Head-->
	<head>
		<title><?php echo $job11; ?> Report</title>
		<meta charset="utf-8" />
		<meta name="description" content="The most advanced Bootstrap Admin Theme on Themeforest trusted by 100,000 beginners and professionals. Multi-demo, Dark Mode, RTL support and complete React, Angular, Vue, Asp.Net Core, Rails, Spring, Blazor, Django, Flask & Laravel versions. Grab your copy now and get life-time updates for free." />
		<meta name="keywords" content="metronic, bootstrap, bootstrap 5, angular, VueJs, React, Asp.Net Core, Rails, Spring, Blazor, Django, Flask & Laravel starter kits, admin themes, web design, figma, web development, free templates, free admin themes, bootstrap theme, bootstrap template, bootstrap dashboard, bootstrap dak mode, bootstrap button, bootstrap datepicker, bootstrap timepicker, fullcalendar, datatables, flaticon" />
		<meta name="viewport" content="width=device-width, initial-scale=1" />
		<meta property="og:locale" content="en_US" />
		<meta property="og:type" content="article" />
		<meta property="og:title" content="Metronic - Bootstrap Admin Template, HTML, VueJS, React, Angular. Laravel, Asp.Net Core, Ruby on Rails, Spring Boot, Blazor, Django, Express.js, Node.js, Flask Admin Dashboard Theme & Template" />
		<meta property="og:url" content="https://keenthemes.com/metronic" />
		<meta property="og:site_name" content="Keenthemes | Metronic" />
		<link rel="canonical" href="https://preview.keenthemes.com/metronic8" />
		<link rel="shortcut icon" href="assets/media/logos/favicon.ico" />
		<!--begin::Fonts(mandatory for all pages)-->
		<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inter:300,400,500,600,700" />
		<!--end::Fonts-->
		<!--begin::Vendor Stylesheets(used for this page only)-->
		<link href="assets/plugins/custom/datatables/datatables.bundle.css" rel="stylesheet" type="text/css" />
		<!--end::Vendor Stylesheets-->
		<!--begin::Global Stylesheets Bundle(mandatory for all pages)-->
		<link href="assets/plugins/global/plugins.bundle.css" rel="stylesheet" type="text/css" />
		<link href="assets/css/style.bundle.css" rel="stylesheet" type="text/css" />
		<!--end::Global Stylesheets Bundle-->
		<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
	<!-- Include moment.js -->
	<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
		<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker@3.1.0/daterangepicker.css" />
	<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker@3.1.0/daterangepicker.min.js"></script>
	
    <style>
    /* Popup Overlay */
    .popup-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent black */
        z-index: 1001; /* Ensure it's above other content */
    }

    /* Popup Content */
    .popup-content {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background-color: white;
        padding: 20px;
        border-radius: 5px;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
        max-width: 90%; /* Set maximum width */
        width: auto; /* Adjust width automatically */
        z-index: 1002; /* Ensure it's above other content */
    }

    /* Optional: Adjustments for smaller screens */
    @media (max-width: 768px) {
        .popup-content {
            max-width: 80%;
        }
    }

    /* Optional: Adjustments for even smaller screens */
    @media (max-width: 576px) {
        .popup-content {
            max-width: 95%;
        }
    }




       .table-responsive::-webkit-scrollbar {
    width: 12px; 
	color: darkgrey;
}

.table-responsive::-webkit-scrollbar-thumb {
    background-color: darkgrey; 
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background-color: black; 
}

.form-control.form-control-solid,.form-select.form-select-solid{				
		border-color: #979595;			
		}	
	
		.form-control.form-control-solid.active,.form-select.form-select-solid.active{				
		border-color: #979595;			
		}		
    </style>
	</head>
	<!--end::Head-->
	<!--begin::Body-->
	<body id="kt_body" data-kt-app-layout="dark-sidebar" data-kt-app-header-fixed="true" data-kt-app-sidebar-enabled="true"  data-kt-app-sidebar-hoverable="true" data-kt-app-sidebar-push-header="true" data-kt-app-sidebar-push-toolbar="true" data-kt-app-sidebar-push-footer="true" data-kt-app-toolbar-enabled="true"  class="app-default">
		<!--begin::Theme mode setup on page load-->
		<script>var defaultThemeMode = "light"; var themeMode; if ( document.documentElement ) { if ( document.documentElement.hasAttribute("data-theme-mode")) { themeMode = document.documentElement.getAttribute("data-theme-mode"); } else { if ( localStorage.getItem("data-theme") !== null ) { themeMode = localStorage.getItem("data-theme"); } else { themeMode = defaultThemeMode; } } if (themeMode === "system") { themeMode = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"; } document.documentElement.setAttribute("data-theme", themeMode); }</script>
		
		<!--end::Theme mode setup on page load-->
		<!--begin::Main-->
		<!--begin::Root-->
		<div class="d-flex flex-column flex-root">
			<!--begin::Page-->
			<div class="page d-flex flex-row flex-column-fluid">
				<!--begin::Aside-->
				<?php include('sidebar2.php'); ?>
				<!--end::Aside-->
				<!--begin::Wrapper-->
				<div class="wrapper d-flex flex-column flex-row-fluid" id="kt_wrapper">
					<!--begin::Header-->
					<div id="kt_header" style="" class="header align-items-stretch">
						<!--begin::Container-->
						<div class="container-fluid d-flex align-items-stretch justify-content-between">
							<!--begin::Aside mobile toggle-->
							<div class="d-flex align-items-center d-lg-none ms-n3 me-1" title="Show aside menu">
								<div class="btn btn-icon btn-active-color-primary w-40px h-40px" id="kt_app_sidebar_mobile_toggle">
									<!--begin::Svg Icon | path: icons/duotune/abstract/abs015.svg-->
									<span class="svg-icon svg-icon-1 hide">
										<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
											<path d="M21 7H3C2.4 7 2 6.6 2 6V4C2 3.4 2.4 3 3 3H21C21.6 3 22 3.4 22 4V6C22 6.6 21.6 7 21 7Z" fill="currentColor" />
											<path opacity="0.3" d="M21 14H3C2.4 14 2 13.6 2 13V11C2 10.4 2.4 10 3 10H21C21.6 10 22 10.4 22 11V13C22 13.6 21.6 14 21 14ZM22 20V18C22 17.4 21.6 17 21 17H3C2.4 17 2 17.4 2 18V20C2 20.6 2.4 21 3 21H21C21.6 21 22 20.6 22 20Z" fill="currentColor" />
										</svg>
									</span>
									<!--end::Svg Icon-->
								</div>
							</div>
							<!--end::Aside mobile toggle-->
							<!--begin::Mobile logo-->
							<div class="d-flex align-items-center flex-grow-1 flex-lg-grow-0">
								<a href="dashboard.php" class="d-lg-none">
									<img alt="Logo" src="assets/media/logos/demo4-mobile.svg" class="h-25px hide" />
								</a>
							</div>
							<!--end::Mobile logo-->
							<div class="d-flex align-items-center" id="kt_header_wrapper">
								<!--begin::Page title-->
								<div class="page-title d-flex flex-column align-items-start justify-content-center flex-wrap me-lg-20 pb-5 pb-lg-0" data-kt-swapper="true" data-kt-swapper-mode="prepend" data-kt-swapper-parent="{default: '#kt_content_container', lg: '#kt_header_wrapper'}">
									<!--begin::Heading-->
									<h1 class="text-dark fw-bold my-1 fs-3 lh-1 hide">
                                  <?php echo $job11; ?> Report</h1>
									<!--end::Heading-->
									<!--begin::Breadcrumb-->
									<ul class="breadcrumb fw-semibold fs-8 my-1 hide">
										<li class="breadcrumb-item text-muted">
											<a href="dashboard.php" class="text-muted">Home</a>
										</li>
										<li class="breadcrumb-item text-muted">Reports</li>
										
										<li class="breadcrumb-item text-muted"><?php echo $job11; ?> Report</li>
									</ul>
									<!--end::Breadcrumb-->
								</div>
								<!--end::Page title=-->
							</div>
							<!--begin::Wrapper-->
							<?php include('header.php'); ?>
							<!--end::Wrapper-->
						</div>
						<!--end::Container-->
					</div>
					<!--end::Header-->
					<!--begin::Content-->
					<div class="content d-flex flex-column flex-column-fluid" id="kt_content">
						<!--begin::Container-->
						<div class="container-xxl" id="kt_content_container">
							<!--begin::Card-->
							<div class="card">
								<!--begin::Card header-->
								<div class="card-header border-0 pt-6">
									<!--begin::Card title-->
									<div class="card-title">
										<!--begin::Search-->
									
										<!--end::Search-->
									</div>
									<!--begin::Card title-->
									<!--begin::Card toolbar-->
									<div class="card-toolbar flex-row-fluid justify-content-end gap-5">
										<!--begin::Toolbar-->
										
										<style>
    @media print {
        
		
		/* Hide elements with the class "print-hide" */
        .control-label {
            display: none;
        }
		.form-control {
            display: none;
        }
		.form-select {
            display: none;
        }
		.hide {
            display: none;
        }
		
		
    }
</style>
 <label class="control-label">Results shows for date range:</label>
 <div class="d-flex justify-content-end">
                    <div class="col-md-12">
                       
                        <input class="form-control form-control-solid" placeholder="Pick date range" name="d" value="<?php echo date('d-m-Y', strtotime($_SESSION['lowerdate']))." - ".date('d-m-Y', strtotime($_SESSION['upperdate']));?>" readonly/>
                    </div>
                </div>
										<div class="d-flex justify-content-end" data-kt-user-table-toolbar="base">
											<!--begin::Export-->
											<?php if($fshide6=="1"){ ?>
										<a href="javascript:;" onClick="window.print();" class="btn btn-light-danger me-3 hide">
    <i class="fa fa-print"></i> Print
</a>
											<?php } ?>

											<!--end::Export-->
											<!--begin::Add user-->
											
									
											<!--end::Add user-->
										</div>
								
										<div class="d-flex justify-content-end" data-kt-user-table-toolbar="base">
    <!--begin::Export-->
	<?php if($fshide7=="1"){ ?>
    <a href="javascript:;" onClick="exportTableToExcel('sample_5', 'Job_Report')" class="btn btn-light-primary me-3">
        <i class="fa fa-file-excel-o"></i> Export Excel
    </a>

    <a href="javascript:;" onClick="exportTableToCSV('sample_5', 'Job_Report')" class="btn btn-light-primary me-3">
        <i class="fa fa-file-text-o"></i> Export CSV
    </a>

	<?php } if($fshide8=="1"){ ?>
	<button class="btn btn-light-primary me-3 hide" type="button" id="popupBtn">
            Filter
        </button>
    <!--end::Export-->
    <!--begin::Add user-->
	<?php } ?>
    <!--end::Add user-->
</div>

										<!--end::Toolbar-->
										<!--begin::Group actions-->
									
										<!--end::Group actions-->
										<!--begin::Modal - Adjust Balance-->
								
									<!--end::Card toolbar-->
									
								</div>
								
								</div>
								 
											<?php
									

											
	$eve = "SELECT * FROM res_fieldsetting_master";
	  
	$re = mysqli_query($conn, $eve);
	
		while($rt = mysqli_fetch_assoc($re))
		{
			
			$fieldname=$rt['fieldname'];
			
			 if($fieldname == 'Date&Time') 
			{
					$datetime = $rt['fieldlable'];
					$fshidedatetime=$rt['fshide'];
				} 
				
			if($fieldname == 'Ticket No') 
			{
					$ticketno = $rt['fieldlable'];
					$fshideticketno=$rt['fshide'];
				} 
			if($fieldname == 'Customer Name') 
			{
					$customername = $rt['fieldlable'];
					$fshidecustomername=$rt['fshide'];
				} 
			if($fieldname == 'Customer UEN') 
			{
					$customeruen = $rt['fieldlable'];
					$fshidecustomeruen=$rt['fshide'];
				} 
			if($fieldname == 'Customer Contact No.') 
			{
					$customercontactno = $rt['fieldlable'];
					$fshidecustomercontactno=$rt['fshide'];
				} 
			if($fieldname == 'Vehicle No.') 
			{
					$vehicleno = $rt['fieldlable'];
					$fshidevehicleno=$rt['fshide'];
				} 
			if($fieldname == 'Driver Name') 
			{
					$drivername = $rt['fieldlable'];
					$fshidedrivername=$rt['fshide'];
				} 
			if($fieldname == 'Driver NRIC No.') 
			{
					$drivernricno = $rt['fieldlable'];
					$fshidedrivernricno=$rt['fshide'];
				} 
			if($fieldname == 'Driver Contact No.') 
			{
					$drivercontactno = $rt['fieldlable'];
					$fshidedrivercontactno=$rt['fshide'];
				} 
			if($fieldname == 'Transaction Mode') 
			{
					$transactionmode = $rt['fieldlable'];
					$fshidetransactionmode=$rt['fshide'];
				} 
			if($fieldname == 'Transaction Type') 
			{
					$transactiontype = $rt['fieldlable'];
					$fshidetransactiontype=$rt['fshide'];
				} 
			if($fieldname == 'Initial Wt (Kg)') 
			{
					$initialwt = $rt['fieldlable'];
					$fshideinitialwt=$rt['fshide'];
				} 
			if($fieldname == 'Final Wt(Kg)') 
			{
					$finalwt = $rt['fieldlable'];
					$fshidefinalwt=$rt['fshide'];
				} 
			if($fieldname == 'Overall Net-Wt (Kg)') 
			{
					$overallnetwt = $rt['fieldlable'];
					$fshideoverallnetwt=$rt['fshide'];
				} 
			if($fieldname == 'SubTotal($)') 
			{
					$subtotal = $rt['fieldlable'];
					$fshidesubtotal=$rt['fshide'];
				} 
			if($fieldname == 'GST(9%) ($)') 
			{
					$gst = $rt['fieldlable'];
					$fshidegst=$rt['fshide'];
				} 
			if($fieldname == 'Grand Total($)') 
			{
					$grandtotal = $rt['fieldlable'];
					$fshidegrandtotal=$rt['fshide'];
				} 
			if($fieldname == 'Image') 
			{
					$image = $rt['fieldlable'];
					$fshideimage=$rt['fshide'];
				} 
			if($fieldname == 'Remarks') 
			{
					$remarks = $rt['fieldlable'];
					$fshideremarks=$rt['fshide'];
				} 
			if($fieldname == 'Sr No.') 
			{
					$srno2 = $rt['fieldlable'];
					$fshidesrno2=$rt['fshide'];
				} 
			if($fieldname == 'Item Name') 
			{
					$itemname20 = $rt['fieldlable'];
					$fshideitemname=$rt['fshide'];
				} 
			if($fieldname == 'Date&Time2') 
			{
					$datetime2 = $rt['fieldlable'];
					$fshidedatetime2=$rt['fshide'];
				} 
			if($fieldname == 'In-Wt (Kg)') 
			{
					$inwt2 = $rt['fieldlable'];
					$fshideinwt2=$rt['fshide'];
				} 
			if($fieldname == 'Out-Wt (Kg)') 
			{
					$outwt = $rt['fieldlable'];
					$fshideoutwt=$rt['fshide'];
				} 
			if($fieldname == 'Net-Wt (Kg)') 
			{
					$netwt = $rt['fieldlable'];
					$fshidenetwt=$rt['fshide'];
				} 
			if($fieldname == 'Item Price($/kg)') 
			{
					$itemprice = $rt['fieldlable'];
					$fshideitemprice=$rt['fshide'];
				} 
			if($fieldname == 'Original Item Price($)') 
			{
					$orgitemprice = $rt['fieldlable'];
					$fshideorgitemprice=$rt['fshide'];
				} 
			if($fieldname == 'Deduction By Wt(Kg)') 
			{
					$deductbywt = $rt['fieldlable'];
					$fshidedeductbywt=$rt['fshide'];
				} 
			if($fieldname == 'Deduction by Percentage (%)') 
			{
					$deductbyper = $rt['fieldlable'];
					$fshidedeductbyper=$rt['fshide'];
				} 
			if($fieldname == 'Deduction by Payment ($)') 
			{
					$deductbypayment = $rt['fieldlable'];
					$fshidedeductbypayment=$rt['fshide'];
				} 
			if($fieldname == 'Item Price (Before deduction) ($)') 
			{
					$itempricebeforededuct = $rt['fieldlable'];
					$fshideitempricebeforededuct=$rt['fshide'];
				} 
			if($fieldname == 'Item Price (After Deduction) ($)') 
			{
					$itempriceafterdeduct = $rt['fieldlable'];
					$fshideitempriceafterdeduct=$rt['fshide'];
				} 
			if($fieldname == 'MASTER FIELD 1') 
			{
					$masterfield1 = $rt['fieldlable'];
					$fshidemasterfield1=$rt['fshide'];
				} 
			if($fieldname == 'MASTER FIELD 2') 
			{
					$masterfield2 = $rt['fieldlable'];
					$fshidemasterfield2=$rt['fshide'];
				} 
			if($fieldname == 'Text Field 3') 
			{
					$textfield3 = $rt['fieldlable'];
					$fshidetextfield3=$rt['fshide'];
				} 
			if($fieldname == 'Text Field 4') 
			{
					$textfield4 = $rt['fieldlable'];
					$fshidetextfield4=$rt['fshide'];
				} 
			if($fieldname == 'Operator Signature') 
			{
					$opesign = $rt['fieldlable'];
					$fshideopesign=$rt['fshide'];
				} 
			if($fieldname == 'Driver Signature') 
			{
					$drisign = $rt['fieldlable'];
					$fshidedrisign=$rt['fshide'];
				} 	
				

			
			
		
		}							
											?>
								 
						<div class="popup-overlay" id="popupOverlay">
    <div class="popup-content  popup-lg">
        <div class="card-header align-items-center py-5 gap-2 gap-md-5">
            <form method="post" class="form-control" style="border: none;">

                <!-- Date Range Selection -->
               
				<div class="row mb-3">
                    <div class="col-md-6">
                         <label for="startdate">Start Date:</label>
        <input type="date" id="startdate" name="startdate" value="<?php if(isset($_POST['startdate'])){ echo $_POST['startdate'];} else { echo $startdate;} ?>" required>
                    </div>
					<div class="col-md-6">
                         <label for="enddate">End Date:</label>
        <input type="date" id="enddate" name="enddate" value="<?php if(isset($_POST['enddate'])){ echo $_POST['enddate'];} else { echo $enddate;} ?>" required>
                    </div>
                </div>

                <!-- Left Side Selections -->
                <div class="row mb-3">
                    <div class="col-md-4">
                        <label class="control-label">Status</label>
                        <select class="form-select form-select" data-control="select2" data-hide-search="true" name="jobworkstatus">
                            <option value="All" >All</option>
                            <option value="Completed"  <?php if ($_SESSION['jobworkstatus']=='Completed'){echo 'selected';}?>>Completed</option>
                            <option value="In-process"  <?php if ($_SESSION['jobworkstatus']=='In-process'){echo 'selected';}?>>In-process</option>
                        </select>
                    </div>
                    <div class="col-md-4">
                        <label class="control-label"><?php echo $transactiontype; ?></label>
                        <select class="form-select form-select" data-control="select2" data-hide-search="true" name="challantype">
                            <option value="All" >All</option>
                            <option value="Sale"  <?php if ($_SESSION['challantype']=='Sale'){echo 'selected';}?>>Sale</option>
                            <option value="Purchase"  <?php if ($_SESSION['challantype']=='Purchase'){echo 'selected';}?>>Purchase</option>
                        </select>
                    </div>
                    <div class="col-md-4">
                        <label class="control-label"><?php echo $customername; ?></label>
                      <!-- <label class="control-label">Company</label> -->
                        <select class="form-select" data-control="select2" name="comp">
                            <option value="All" >All</option>
                            <?php
                            $eve_main2 = "select * from res_party_master";
                            $re_main2 = mysqli_query($conn, $eve_main2);
                            while($rt_main2 = mysqli_fetch_assoc($re_main2))
                            {
                                $partymid=$rt_main2['partymid'];
                                $partyname=$rt_main2['partyname'];
                                if(isset($_SESSION['comp']) && $_SESSION['comp']==$partymid)
                                {
                                    echo "<option value='$partymid' selected>$partyname</option>";
                                }
                                else
                                {
                                    echo "<option value='$partymid'>$partyname</option>";
                                }
                            }
                            ?>
                        </select>
                    </div>
                </div>

                <!-- Right Side Selections -->
                <div class="row mb-3">
                    <div class="col-md-4">
                        <label class="control-label"><?php echo $vehicleno; ?></label>
                       <!-- <label class="control-label">Truck No</label>-->
                        <select class="form-select form-select" data-control="select2"  name="truckn">
                            <option value="All" >All</option>
                            <?php
                            $eve_main3 = "select * from res_vehicle_master";
                            $re_main3 = mysqli_query($conn, $eve_main3);
                            while($rt_main3 = mysqli_fetch_assoc($re_main3))
                            {
                                $vehiclemid=$rt_main3['vehiclemid'];
                                $vehiclenumber=$rt_main3['vehiclenumber'];
                                if(isset($_SESSION['truckn']) && $_SESSION['truckn']==$vehiclemid)
                                {
                                    echo "<option value='$vehiclemid' selected>$vehiclenumber</option>";
                                }
                                else
                                {
                                    echo "<option value='$vehiclemid'>$vehiclenumber</option>";
                                }
                            }
                            ?>
                        </select>
                    </div>
                    <div class="col-md-4">
                        <label class="control-label"><?php echo $ticketno; ?></label>
                        <select class="form-select form-select" data-control="select2"  name="ticketn">
                            <option value="All" >All</option>
                            <?php
                            $eve_main4 = "select * from res_challan_master where challanstatus != 'Cancelled'";
                            $re_main4 = mysqli_query($conn, $eve_main4);
                            while($rt_main4 = mysqli_fetch_assoc($re_main4))
                            {
                                $challanmid2=$rt_main4['challanmid'];
                                $challannofordisplay=$rt_main4['challannofordisplay'];
                                if(isset($_SESSION['ticketn']) && $_SESSION['ticketn']==$challanmid2)
                                {
                                    echo "<option value='$challanmid2' selected>$challannofordisplay</option>";
                                }
                                else
                                {
                                    echo "<option value='$challanmid2'>$challannofordisplay</option>";
                                }
                            }
                            ?>
                        </select>
                    </div>
                    <div class="col-md-4">
                        <label class="control-label"><?php echo $transactionmode; ?></label>
                     <!--   <label class="control-label">Weighing type</label>-->
                        <select class="form-select form-select" data-control="select2" data-hide-search="true" name="weightyp">
                            <option value="All" >All</option>
                            <option value="Multiple Weight"  <?php if ($_SESSION['weightyp']=='Multiple Weight'){echo 'selected';}?>>Multiple Weight</option>
                            <option value="Single Weight"  <?php if ($_SESSION['weightyp']=='Single Weight'){echo 'selected';}?>>Single Weight</option>
                        </select>
                    </div>
                </div>

                <!-- Driver / Master Field Filters -->
                <div class="row mb-3">
                    <?php if($fshidedrivername=="1"){ ?>
                    <div class="col-md-4">
                        <label class="control-label"><?php echo $drivername; ?></label>
                        <select class="form-select form-select" data-control="select2" name="driverid">
                            <option value="All" >All</option>
                            <?php
                            $eve_drv = "select * from res_driver_master order by dname";
                            $re_drv = mysqli_query($conn, $eve_drv);
                            while($rt_drv = mysqli_fetch_assoc($re_drv))
                            {
                                $driverid2=$rt_drv['driverid'];
                                $dname2=$rt_drv['dname'];
                                if(isset($_SESSION['driverid']) && $_SESSION['driverid']==$driverid2)
                                {
                                    echo "<option value='$driverid2' selected>$dname2</option>";
                                }
                                else
                                {
                                    echo "<option value='$driverid2'>$dname2</option>";
                                }
                            }
                            ?>
                        </select>
                    </div>
                    <?php } ?>

                    <?php if($fshidemasterfield1=="1"){ ?>
                    <div class="col-md-4">
                        <label class="control-label"><?php echo $masterfield1; ?></label>
                        <select class="form-select form-select" data-control="select2" name="mf1">
                            <option value="All" >All</option>
                            <?php
                            $eve_mf1 = "select * from res_masterfield1_master order by mfname";
                            $re_mf1 = mysqli_query($conn, $eve_mf1);
                            while($rt_mf1 = mysqli_fetch_assoc($re_mf1))
                            {
                                $mfmid=$rt_mf1['mfmid'];
                                $mfname2=$rt_mf1['mfname'];
                                if(isset($_SESSION['mf1']) && $_SESSION['mf1']==$mfmid)
                                {
                                    echo "<option value='$mfmid' selected>$mfname2</option>";
                                }
                                else
                                {
                                    echo "<option value='$mfmid'>$mfname2</option>";
                                }
                            }
                            ?>
                        </select>
                    </div>
                    <?php } ?>

                    <?php if($fshidemasterfield2=="1"){ ?>
                    <div class="col-md-4">
                        <label class="control-label"><?php echo $masterfield2; ?></label>
                        <select class="form-select form-select" data-control="select2" name="mf2">
                            <option value="All" >All</option>
                            <?php
                            $eve_mf2 = "select * from res_masterfield2_master order by mf2name";
                            $re_mf2 = mysqli_query($conn, $eve_mf2);
                            while($rt_mf2 = mysqli_fetch_assoc($re_mf2))
                            {
                                $mf2mid=$rt_mf2['mf2mid'];
                                $mf2name2=$rt_mf2['mf2name'];
                                if(isset($_SESSION['mf2']) && $_SESSION['mf2']==$mf2mid)
                                {
                                    echo "<option value='$mf2mid' selected>$mf2name2</option>";
                                }
                                else
                                {
                                    echo "<option value='$mf2mid'>$mf2name2</option>";
                                }
                            }
                            ?>
                        </select>
                    </div>
                    <?php } ?>
                </div>

                <!-- Submit and Close Buttons -->
                <div class="row">
                    <div class="col-md-4">
                        <label class="control-label"><?php echo $itemname20; ?></label>
                        <select class="form-select form-select" data-control="select2"  name="itemname11">
                            <option value="All" >All</option>
                            <?php
                            $eve_main4 = "select * from res_item_master";
                            $re_main4 = mysqli_query($conn, $eve_main4);
                            while($rt_main4 = mysqli_fetch_assoc($re_main4))
                            {
                                $itemmid=$rt_main4['itemmid'];
                                $itemname=$rt_main4['itemname'];
                                if(isset($_SESSION['itemname11']) && $_SESSION['itemname11']==$itemmid)
                                {
                                    echo "<option value='$itemmid' selected>$itemname</option>";
                                }
                                else
                                {
                                    echo "<option value='$itemmid'>$itemname</option>";
                                }
                            }
                            ?>
                        </select>
                    </div>
                    <div class="col-md-2">
                        
                    </div>
                    <div class="col-md-6">
                        
                        <button type="submit" name="btnsubmit" class="btn btn-light-danger me-3">
                            <i class="fa fa-check"></i> Submit</button>
                            <button onclick="closePopup()" class="btn btn-light-danger">Close</button>
                    </div>
                </div>

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


								<!--end::Card header-->
								
<style>
.table-responsive {
 overflow-y: auto;
 height: 800px;

}
.table-responsive thead tr {
 position: sticky;
 top: 0;
  background-color: skyblue;
}
table {
 border-collapse: collapse;
 width: 100%;
}
th,
td {
 padding: 8px 15px;
 border: 2px solid #black;
}
th {
 background: #abdd93;
}
</style>
								<!--begin::Card body-->
								<div class="card-body py-4">
						<div class="table-responsive" id ="firstDiv">									<!--begin::Table-->
									<table class="table table-hover table-sm align-top border-bottom table-striped table-bordered
order-column border-gray gy-3 gs-5" id="sample_5">
									<thead>
									   
											<tr class="hidden-header">
												<th class="sorting" style="display:none;"> </th>
                                                <th>Sr. No.</th>
					  <?php if($fshidedatetime=="1"){ 
					  ?>						
												<th style="width: 200px !important;"><?php echo $datetime; ?></th>
					  <?php }
					  if($fshideticketno=="1"){?>							
					  <th><?php echo $ticketno; ?></th>
					  <?php }?>
					  <th>Location</th>
					  <?php
					  if($fshidecustomername=="1"){?>	
												<th><?php echo $customername; ?></th>
												<?php }
					  if($fshidecustomeruen=="1"){?>	
												<th><?php echo $customeruen; ?></th>
												<?php }
					  if($fshidecustomercontactno=="1"){?>	
												<th><?php echo $customercontactno; ?></th>
												<?php }
					  if($fshidevehicleno=="1"){?>	
												<th><?php echo $vehicleno; ?></th>
												<?php }
					  if($fshidedrivername=="1"){?>	
												<th><?php echo $drivername; ?></th>
												<?php }
					  if($fshidedrivernricno=="1"){?>	
												<th><?php echo $drivernricno; ?></th>
												<?php }
					  if($fshidedrivercontactno=="1"){?>	
												<th><?php echo $drivercontactno; ?></th>
												<?php }
					  if($fshidetransactionmode=="1"){?>	
												<th><?php echo $transactionmode; ?></th>
												<?php }
					  if($fshidetransactiontype=="1"){?>	
												<th><?php echo $transactiontype; ?></th>
												<?php }
					  if($fshidemasterfield1=="1"){?>	
												
												
												 <th><?php echo $masterfield1; ?></th>
												<?php }
					  if($fshidemasterfield2=="1"){?>	
												
												
												 <th><?php echo $masterfield2; ?></th>
												<?php }
					  if($fshidetextfield3=="1"){?>	
												
												
												 <th><?php echo $textfield3; ?></th>
												<?php }
					  if($fshidetextfield4=="1"){?>	
												
												
												 <th><?php echo $textfield4; ?></th>
												<?php }
					  if($fshideopesign=="1"){?>	
												
												
												 <th><?php echo $opesign; ?></th>
												<?php }
					  if($fshidedrisign=="1"){?>	
												
												
												 <th><?php echo $drisign; ?></th>
												<?php }
					  if($fshideinitialwt=="1"){?>	
												
												
												 <!--<th><?php echo $initialwt; ?></th>-->
												<?php }
					  if($fshidefinalwt=="1"){?>	
												<!--<th><?php echo $finalwt; ?></th>-->
<?php }
					  if($fshideoverallnetwt=="1"){?>	
												 <!--<th><?php echo $overallnetwt; ?></th>-->
<?php }
					  if($fshidesubtotal=="1"){?>	
												 <th><?php echo $subtotal; ?></th>
<?php }
					  if($fshidegst=="1"){?>	
											
												 <th><?php echo $gst; ?></th>
<?php }
					  if($fshidegrandtotal=="1"){?>	
												 <th><?php echo $grandtotal; ?></th>
<?php }
					  if($fshideimage=="1"){?>	
												 <th><?php echo $image; ?></th>
<?php }
					  if($fshideremarks=="1"){?>	
												 <th><?php echo $remarks; ?></th>
<?php }
					  if($fshidesrno2=="1"){?>	
												 
												 
												 <th><?php echo $srno2; ?></th>
<?php }
					  if($fshideitemname=="1"){?>	
												 <th><?php echo $itemname20; ?></th>
<?php }
					  if($fshidedatetime2=="1"){?>	
												 <th><?php echo $datetime2; ?></th>
<?php }
					  if($fshideinwt2=="1"){?>	
												 <th><?php echo $inwt2; ?></th>
<?php }
					  if($fshideoutwt=="1"){?>	
												 <th><?php echo $outwt; ?></th>
<?php }
					  if($fshidenetwt=="1"){?>	
												 <th><?php echo $netwt; ?></th>
<?php }
					  if($fshideitemprice=="1"){?>	
												 <th><?php echo $itemprice; ?></th>
<?php }
					  if($fshideorgitemprice=="1"){?>	
												 <th><?php echo $orgitemprice; ?></th>
<?php }
					  if($fshidedeductbywt=="1"){?>	
												 <th><?php echo $deductbywt; ?></th>
<?php }
					  if($fshidedeductbyper=="1"){?>	
												 <th><?php echo $deductbyper; ?></th>
<?php }
					  if($fshidedeductbypayment=="1"){?>	
												 <th><?php echo $deductbypayment; ?></th>
<?php }
					  if($fshideitempricebeforededuct=="1"){?>	
												 <th><?php echo $itempricebeforededuct; ?></th>
<?php }
					  if($fshideitempriceafterdeduct=="1"){?>	
												 <th><?php echo $itempriceafterdeduct; ?></th>

											<?php } ?>	
												 
											
                                        </tr>
                                    </thead>
									 <tbody>
	 <?php
	 if(isset($_SESSION['lowerdate']))
	 {
		 $lowerdate = $_SESSION['lowerdate'];
		 $upperdate = $_SESSION['upperdate'];
		$aa = "and Date(challandate) between '$lowerdate' and '$upperdate'";		
	 }else
	 {
		$aa = ""; 
	 }
	if(isset($_SESSION['jobworkstatus']))
	{
		 $jobworkstatus = $_SESSION['jobworkstatus'];
		if($jobworkstatus == 'All')
		{
			$cc = "and challanstatus NOT IN ('Cancelled')";
		}else{
			$cc = "and challanstatus='$jobworkstatus'";
		}			
	}else
	{
		$dd = ""; 
	}
	 if(isset($_SESSION['challantype']))
	 {
		 $challantype = $_SESSION['challantype'];
		if($challantype == 'All')
		{
			$dd = "";
			
		}else{
			$dd = "and challantype='$challantype'";
		}			
	 }else
	 {
		$dd = ""; 
	 }
	 
	 if(isset($_SESSION['comp']))
	 {
		 $company2 = $_SESSION['comp'];
		if($company2 == 'All')
		{
			$ee = "";
			
		}else{
			$ee = "and partymid='$company2'";
		}			
	 }else
	 {
		$ee = ""; 
	 }
	 
	 if(isset($_SESSION['truckn']))
	 {
		 $truck2 = $_SESSION['truckn'];
		if($truck2 == 'All')
		{
			$ff = "";
			
		}else{
			$ff = "and vehiclemid='$truck2'";
		}			
	 }else
	 {
		$ff = ""; 
	 } 
	 
	 if(isset($_SESSION['ticketn']))
	 {
		 $ticket2 = $_SESSION['ticketn'];
		if($ticket2 == 'All')
		{
			$gg = "";
			
		}else{
			$gg = "and challanmid='$ticket2'";
		}			
	 }else
	 {
		$gg = ""; 
	 }
	 
	 if(isset($_SESSION['itemname11']))
	 {
		 $itemname11 = $_SESSION['itemname11'];
		if($itemname11 == 'All')
		{
			$gi = "";
			
		}else{
			 $gi = "and challanmid in(select challanmid from res_challan_detail where itemmid='$itemname11')";
		}			
	 }else
	 {
		$gi = ""; 
	 }
	 
	 if(isset($_SESSION['weightyp']))
	 {
		 $weightyp2 = $_SESSION['weightyp'];
		if($weightyp2 == 'All')
		{
			$hh = "";
			
		}else{
			$hh = "and challanweighttype='$weightyp2'";
		}			
	 }else
	 {
		$hh = ""; 
	 }
	 
	 

	 $sumtprice=0;
	 $sumtitem=0;
	 $sumtotalweight=0;
	 $sumdeadonduck=0;

	// Additional filters
	if(isset($_SESSION['driverid']))
	{
		$driverid_f = $_SESSION['driverid'];
		if($driverid_f == 'All')
		{
			$dj = "";
		}else{
			$dj = "and driverid='$driverid_f'";
		}
	}else{
		$dj = "";
	}

	if(isset($_SESSION['mf1']))
	{
		$mf1_f = $_SESSION['mf1'];
		if($mf1_f == 'All')
		{
			$mf1c = "";
		}else{
			$mf1c = "and masterfield1='$mf1_f'";
		}
	}else{
		$mf1c = "";
	}

	if(isset($_SESSION['mf2']))
	{
		$mf2_f = $_SESSION['mf2'];
		if($mf2_f == 'All')
		{
			$mf2c = "";
		}else{
			$mf2c = "and masterfield2='$mf2_f'";
		}
	}else{
		$mf2c = "";
	}

	// Totals
	$sumDetailNetWeight = 0;
	$sumOverallNetWeight = 0;

	$seenOverall = array();

	  $eve = "select * from res_challan_master where 1  $aa $dd $cc $ee $ff $gg $hh $gi $dj $mf1c $mf2c Order By challanmid Desc";

	$re = mysqli_query($conn, $eve);


	$response = array();
	$posts = array();

	$result="0";

	if(mysqli_num_rows($re) > 0)
	{
		$i=1;
		while($rt = mysqli_fetch_assoc($re))
		{
			 	$challanmid=$rt['challanmid'];
			 	$challannumber=$rt['challannumber'];
			 	$challandispatchedby=$rt['addedby'];
				$challantime=date("d-m-y H:i",strtotime($rt['addedon']));
				$addedond=date("d-m-y",strtotime($rt['addedon']));
				$challanouttime=date("H:i",strtotime($rt['challanreceivedon']));
			 	$challandate=date("d-m-Y",strtotime($rt['challandate']));
				$challanstatus=$rt['challanstatus'];
				$jobno=$rt['challannofordisplay'];
				$challantype=$rt['challantype'];
				$vehiclemid=$rt['vehiclemid'];
				$challanweighttype=$rt['challanweighttype'];
				$firstweight=$rt['firstweight'];
				$finalweight=$rt['finalweight'];
				$deadonduck=$rt['deadonduck'];
				$jobremarks=$rt['jobremarks'];
				$gst=$rt['gst_rate'];
				
				$view="<a href='generatepdf/pdfchallan.php?id=".$rt['challanmid']."' data-toggle='tooltip' data-placement='top' title='View Pdf' class='fa fa-file fa-lg' target='_blank'>  </a>";
			

			$dw2="select * from res_vehicle_master where vehiclemid=$vehiclemid";
				$wd = mysqli_query($conn, $dw2);
				if(mysqli_num_rows($wd) > 0)
				{
		
		while($dwd = mysqli_fetch_assoc($wd))
		{
			$vehicleno=$dwd['vehicleqrcode'];
			$vehicledetails=$dwd['vehicledetail'];
			
		}
				}

				

				$partymid=$rt['partymid'];
				$driverid=$rt['driverid'];
				
				$challannofordisplay=$rt['challannofordisplay'];
				 $fw = $rt['firstweight'];
				 $fnw =$rt['finalweight']; 
				$nw = abs($fw - $fnw);
				$partyname="";
$cpname="";
$partyprefix="";
				$eve71="select * from res_party_master where partymid=$partymid";
					$re71 = mysqli_query($conn, $eve71);
					while($rt71 = mysqli_fetch_assoc($re71))
					{
						$partyname=$rt71['partyname'];
						$cpname=$rt71['partycontactperson'];
						$partyprefix=$rt71['partyprefix'];
						$partycontectno=$rt71['partycontectno'];
						
					}
					
					$eve71="select * from res_driver_master where driverid=$driverid";
					$re71 = mysqli_query($conn, $eve71);
					while($rt71 = mysqli_fetch_assoc($re71))
					{
						$dname=$rt71['dname'];
						$dnric=$rt71['dnric'];
						$dmobile=$rt71['dmobile'];
						
						
					}

					
					
					
				$correctionweight="";
				$eve721="select SUM(vehiclereceivedgrossweight) as cc from res_challan_detail where challanmid=$challanmid and vehiclereceived=1";
					$re721 = mysqli_query($conn, $eve721);
					while($rt721 = mysqli_fetch_assoc($re721))
					{
						$correctionweight=number_format($rt721['cc'],2,'.','');
						
					}
				$totaltareweight="";
				$eve722="select SUM(vehicletareweight) as cc from res_challan_detail where challanmid=$challanmid and vehiclereceived=1";
					$re722 = mysqli_query($conn, $eve722);
					while($rt722 = mysqli_fetch_assoc($re722))
					{
						$totaltareweight=number_format($rt722['cc'],2,'.','');
						
					}
					
					$verifiedweight=$correctionweight-$totaltareweight;
					$verifiedweight=number_format($verifiedweight,2,'.','');
					
					//$difference=$totalweight-$verifiedweight;
					//$difference=number_format($difference,2,'.','');
							
					/* --for Completed & In-process-- */
					if($_SESSION['linkarisecmptype']=='Company'){
				if($challanstatus=="Completed")
				{
					
					$challanstatus1="<div class='badge badge-light-primary fw-bold'>Completed</div>";
				}
				else if($challanstatus=="In-process")
				{
					
					$challanstatus1="<div class='badge bg-danger text-light'>In-process</div>";
				}
					}
					else{
						if($challanstatus=="Completed")
				{
					
					$challanstatus1="<div class='badge badge-light-primary fw-bold'>Completed</div>";
				}
				else if($challanstatus=="In-process")
				{
					
					$challanstatus1="<div class='badge bg-danger text-light'>In-process</div>";
				}
					}
					
					
					
					
					/* --for sales & purchase-- */
				
					
					
				$challandispatchedbyname="";
				$eve72="select * from res_user_master where usermid=$challandispatchedby";
					$re72 = mysqli_query($conn, $eve72);
					while($rt72 = mysqli_fetch_assoc($re72))
					{
						//$challandispatchedbyname=$cmpprefix."-".$rt72['username'];
						$cpmobile=$rt72['usermobile'];
						
					}
				
				
			
		
		        	$totalitprice="0";
					$eve72="select SUM(totalitemprice) as cc from res_challan_detail where challanmid=$challanmid";
					$re72 = mysqli_query($conn, $eve72);
					while($rt72 = mysqli_fetch_assoc($re72))
					{
						$totalitprice=number_format($rt72['cc'],2,'.','');
						$totaliprice11 = $totalitprice*($gst/100);
						$totaliprice11=number_format($totaliprice11,2,'.','');
						$finaltotal= $totaliprice11 + $totalitprice;
						$finaltotal=number_format($finaltotal,2,'.','');
					}
		
		
		
		
				

				
				$query11 = "select count(challandid) as cc from res_challan_detail where challanmid=$challanmid";
															$stmt11=mysqli_query($conn,$query11);
															
															
															$totalitem="";
															
															if(mysqli_num_rows($stmt11) > 0)
															{
																while($rt11 = mysqli_fetch_assoc($stmt11))
																{
																	$totalitem=$rt11['cc'];
																	

																}
															}
															$flag=1;
																						$n=1;
																						$detailItemFilter = "";
																						if(isset($_SESSION['itemname11']) && $_SESSION['itemname11']!='All'){
																							$detailItemFilter = " and itemmid='".mysqli_real_escape_string($conn, $_SESSION['itemname11'])."'";
																						}
																						$eve22 = "select * from res_challan_detail where challanmid=$challanmid $detailItemFilter";
																						$re22= mysqli_query($conn, $eve22);
														$itemname="";
														$itemqty="";
														
														while($rt22 = mysqli_fetch_assoc($re22))
														{
														    $challandid = $rt22['challandid'];
															$itemmid = $rt22['itemmid'];
															$reductiontype2 = $rt22['deductiontype'];
															$itemdeduction2=$rt22['itemdeduction'];
															$netweight2=$rt22['vehiclenetweight'];
								$sumDetailNetWeight += (float)$netweight2;
															
																						// Sum Current/Overall Net-Wt only once per challan that is actually displayed
																						if(!isset($seenOverall[$challanmid])) {
																							$sumOverallNetWeight += (float)$nw;
																							$seenOverall[$challanmid] = true;
																						}
$totalitemprice2=$rt22['totalitemprice'];
																$addedon20=date("d-m-y H:i",strtotime($rt22['addedon']));
																
															$totalitemprice11=number_format($totalitemprice2,2,'.',',');
															$itprice=$rt22['itemPrice'];
															
															
														// item name
														$eve26 = "select * from res_item_master where itemmid=$itemmid";
														$re26= mysqli_query($conn, $eve26);
														
															while($rt26 = mysqli_fetch_assoc($re26))
															{
																
																
																	$itemname = $rt26['itemname'];
																		//$itemprice11 = $rt26['itemprice'];
																	
																	
																	
																
															}
														$weightRed2 = "0";
						$weightRedPer2 = "0";
						$weightRedPay2 = "0";
						
						if($reductiontype2 == 'Payment')
						{
							$weightRedPay2 = $itemdeduction2;
							//$totalitemprice2 = $totalitemprice + $itemdeduction2;
						}
						else if($reductiontype2 == 'Percentage')
						{
							$weight2 = $netweight2 + ($netweight2 * $itemdeduction2);
							$weight2 =  number_format($weight2,2,'.','');
							$weightRedPer2 = $itemdeduction2;
						}
						else
						{
							
							$weightRed2 = $itemdeduction2;
							$weight2 = $netweight2 + $itemdeduction2;
							$weight2 =  number_format($weight2,2,'.','');
						}
														//$totalitprice2=number_format($totalitemprice2,2,'.','');
						$netweight21= $rt22['vehicletareweight'] - $rt22['vehiclegrossweight'];
						$finaltotal2= abs($netweight21) * $itprice;
						$finaltotal2=number_format($finaltotal2,2,'.',',');
						
						
														if($flag==1)
					{
										
?>

									 <tr class="odd gradeX">
										<td style="display:none;">  </td>
										<td> <?php echo $i++; ?> </td>
										<!-- from this table data -->
															  <?php if($fshidedatetime=="1"){ 
					  ?>
										<td style="width: 200px !important;"> <?php echo $challantime; ?></td>
										 <?php }
					  if($fshideticketno=="1"){?>
									<?php if($fshide1=="1"){ ?>
									<td> <?php
										echo $challannofordisplay."".$view; ?></td>
									<?php }else{?>	
										<td> <?php
										echo $challannofordisplay; ?></td>
									<?php }?>
								 <?php } ?>
								 
								 <?php 
								 	$location="";
                    				$eve723="select * from res_challan_detail where challanmid=$challanmid limit 0,1";
                    					$re723 = mysqli_query($conn, $eve723);
                    					while($rt723 = mysqli_fetch_assoc($re723))
                    					{
                    						$locationid=$rt723['locationid'];
                    						
                        						$eve7230="select * from company_location_master where clmid=$locationid limit 0,1";
                            					$re7230 = mysqli_query($conn, $eve7230);
                            					while($rt7230 = mysqli_fetch_assoc($re7230))
                            					{
                            						$location=$rt7230['locationprefix'];
                            						
                            						
                            					}
                    				
                    						
                    					}
								 ?>
								 
								 <td><?php echo $location; ?></td>
								 <?php
					  if($fshidecustomername=="1"){?>		
										<td> <?php echo $partyname; ?></td>
														<?php }
					  if($fshidecustomeruen=="1"){?>		
										<td> <?php echo $cpname; ?></td>
																	<?php }
					  if($fshidecustomercontactno=="1"){?>	
										<td> <?php echo $partycontectno; ?></td>
																	<?php }
					  if($fshidevehicleno=="1"){?>	
										<td> <?php echo $vehicleno; ?></td>
																	<?php }
					  if($fshidedrivername=="1"){?>	
										<td> <?php echo $dname; ?></td>
																	<?php }
					  if($fshidedrivernricno=="1"){?>	
										<td> <?php echo '*****'.substr($dnric,-4); ?></td>
																<?php }
					  if($fshidedrivercontactno=="1"){?>	
										<td> <?php echo $dmobile; ?></td>
																<?php }
					  if($fshidetransactionmode=="1"){?>	
										<td> <?php $cwt=$rt['challanweighttype'];
										if($cwt=="Single Weight (without bin)"){
										$cwt2="Single Wt (without bin)";
										}else if($cwt=="Multiple Weight (with bin)"){
										$cwt2="Multi Wt (with bin)";
										}else
										{
										$cwt2=$cwt;
										}echo $cwt2; ?></td>
																<?php }
					  if($fshidetransactiontype=="1"){?>	
										<td> <?php echo $rt['challantype']; ?></td>
																<?php }
					 
					  if($fshidemasterfield1=="1"){?>	
														
										<td> <?php  
										$mf1 = $rt['masterfield1']; 
										$mfname="";
											$eve7232="select * from res_masterfield1_master where mfmid=$mf1 limit 0,1";
                    					$re7232 = mysqli_query($conn, $eve7232);
                    					while($rt7232 = mysqli_fetch_assoc($re7232))
                    					{
                    						$mfname=$rt7232['mfname'];
                    					}
										echo $mfname;
										?></td>
										<?php }
					  if($fshidemasterfield2=="1"){?>	
														
										<td> <?php
										$mf2 = $rt['masterfield2']; 
										$mf2name="";
											$eve7232="select * from res_masterfield2_master where mf2mid=$mf2 limit 0,1";
                    					$re7232 = mysqli_query($conn, $eve7232);
                    					while($rt7232 = mysqli_fetch_assoc($re7232))
                    					{
                    						$mf2name=$rt7232['mf2name'];
                    					}
										echo $mf2name;
										?></td>
										<?php }
					  if($fshidetextfield3=="1"){?>	
														
										<td> <?php echo $rt['emptyfield1']; ?></td>
										<?php }
					  if($fshidetextfield4=="1"){?>	
														
										<td> <?php echo $rt['emptyfield2']; ?></td>
										<?php }
					  if($fshideopesign=="1"){?>	
												<td> 
										<?php
											$eve11 = "select * from res_user_master where usermid=".$rt['addedby'];
			$re11 = mysqli_query($conn, $eve11);
			while($rt11 = mysqli_fetch_assoc($re11))
			{
			
				$operatorsign=$rt11['operatorsign'];
				
				 $eve77 = "SELECT signimagename FROM res_challan_sign_image_detail WHERE challanmid=$challanmid and signimagename IS NOT NULL AND signimagename <> '' LIMIT 1"; 
        $re77 = @mysqli_query($conn, $eve77);
        if ($re77 && mysqli_num_rows($re77) > 0) {
            $rt77 = mysqli_fetch_assoc($re77);
            if (!empty($rt77['signimagename'])) {
                $operatorsign = $rt77['signimagename'];
            }
           
        }
			
			}
										echo $challanimagename = "<img width='80' height='80' src='./images/" . $operatorsign . "'>";
										?>
										</td>			
									
										<?php }
					  if($fshidedrisign=="1"){?>	
										<td> 
										<?php
										
			
			
				 $eve779 = "SELECT signimagename2 FROM res_challan_sign_image_detail WHERE challanmid=$challanmid and signimagename2 IS NOT NULL AND signimagename2 <> '' LIMIT 1"; 
        $re779 = @mysqli_query($conn, $eve779);
        if ($re779 && mysqli_num_rows($re779) > 0) {
            $rt779 = mysqli_fetch_assoc($re779);
            if (!empty($rt779['signimagename2'])) {
                $driversign = $rt779['signimagename2'];
            }
           
        }
			
			
										echo $challanimagename = "<img width='80' height='80' src='./images/" . $driversign . "'>";
										?>
										</td>					
									
										<?php }
										
					 if($fshideinitialwt=="1"){?>	
														
										<!--<td> <?php echo number_format($rt['firstweight'])."kg"; ?></td>-->
										<?php }					
					  if($fshidefinalwt=="1"){?>
										<!--<td> <?php echo number_format($rt['finalweight'])."kg"; ?></td>-->
									<?php }
					  if($fshideoverallnetwt=="1"){?>	
										
										<!--<td> <?php echo number_format($nw)."kg";; ?></td>-->
									<?php }
					  if($fshidesubtotal=="1"){?>	
										<td> <?php echo $totalitprice; ?></td>
									<?php }
					  if($fshidegst=="1"){?>
										<td> <?php echo $totaliprice11; ?></td>
									<?php }
					  if($fshidegrandtotal=="1"){?>	
										<td> <?php echo $finaltotal; ?></td>
									<?php }
					  if($fshideimage=="1"){?>	
										<td> <?php 	$eve7="select challanimagename from res_challanimage_detail where challanmid=$challanmid";
					$re7 = mysqli_query($conn, $eve7);
					$challanimagename=" ";
					if(mysqli_num_rows($re7) > 0)
					{
					 
					
					while($rt7 = mysqli_fetch_assoc($re7))
					{
						if($fshide4=="1"){
					$imageview="<a href='images/".$rt7['challanimagename']."' data-toggle='tooltip' data-placement='top' title='View Image' class='fa fa-file fa-lg' target='_blank'> </a>";  
					}else{
						$imageview="";
					}					
					if($fshide5=="1"){
					echo $challanimagename = "<img width='80' height='80' src='./images/" . $rt7['challanimagename'] . "'>&nbsp" .  $imageview;
					}else{
						echo $challanimagename = $imageview;
					}
				// 	echo '<a href="http://aiwm.isv.com.sg/weighbridgenew/'.$challanimagename.'.html">Click here</a>';
				// 	echo $challanimagename = "<img width='80' height='80' src='./images/" . $rt7['challanimagename'] . "'>&nbsp";
				// $view="<a href='generatepdf/pdfchallan_report.php?id=".$rt['challanmid']."' data-toggle='tooltip' data-placement='top' title='Print Pdf' class='fa fa-file fa-lg'>  </a>";
				// <link rel="canonical" href="https://preview.keenthemes.com/metronic8" />

						
					}
					}?></td>
								<?php }
					  if($fshideremarks=="1"){?>		
										<td> <?php echo $jobremarks; ?></td>
									<?php }
					  if($fshidesrno2=="1"){?>	
										
										
										<td> <?php echo $n++; ?></td>
									<?php }
					  if($fshideitemname=="1"){?>	
										<td> <?php echo $itemname; ?></td>
									<?php }
					  if($fshidedatetime2=="1"){?>	
										<td> <?php echo $addedon20; ?></td>
									<?php }
					  if($fshideinwt2=="1"){?>	
									
										
										<td> <?php echo number_format($rt22['vehicletareweight'])."kg"; ?></td>
									<?php }
					  if($fshideoutwt=="1"){?>		
										<td> <?php echo number_format($rt22['vehiclegrossweight'])."kg"; ?></td>
									<?php }
					  if($fshidenetwt=="1"){?>	
										<td> <?php echo number_format($rt22['vehiclenetweight'])."kg"; ?></td>
									<?php }
					  if($fshideitemprice=="1"){?>	
										<?php
										 $ed11 = "select * from res_item_master where itemmid in (select itemmid from res_challan_detail where challandid=$challandid)";
										$red2 = mysqli_query($conn,$ed11);
										while($rd2 = mysqli_fetch_assoc($red2))
				                    	{
    										if($challantype == 'Sale'){
    										$itemdecidedrate= $rd2['salesrate'];
    										}else{
    										$itemdecidedrate= $rd2['purchaserate'];
    									    }
										}
										$colour = "black";
										$itemdecidedrate2="Same as Item Price";
										if($rt22['itemPrice'] != $itemdecidedrate)
										{
										   $colour = "red";
										    $itemdecidedrate2 = number_format($itemdecidedrate,2,'.','');
										}
									
										?>
										
										<td style="color : <?php echo $colour; ?>;"> <?php echo number_format($rt22['itemPrice'],2,'.',''); ?></td>
									<?php }
					  if($fshideorgitemprice=="1"){?>		
										<td> <?php echo $itemdecidedrate2; ?></td>
										<?php }
					  if($fshidedeductbywt=="1"){?>	
							
										<td> <?php if($weightRed2!=0){
											echo "-";} echo number_format($weightRed2)."kg"; ?></td>
<?php }
					  if($fshidedeductbyper=="1"){?>
										<td> <?php if($weightRedPer2!=0){
											echo "-";} echo $weightRedPer2; ?></td>
<?php }
					  if($fshidedeductbypayment=="1"){?>	
										<td> <?php if($weightRedPay2!=0){
											echo "-";} echo $weightRedPay2; ?></td>
<?php }
					  if($fshideitempricebeforededuct=="1"){?>	
										<td> <?php echo $finaltotal2; ?></td>
<?php }
					  if($fshideitempriceafterdeduct=="1"){?>
										<td> <?php echo $totalitemprice11; ?></td>
									<?php } ?>		
										
										<!-- till this table data -->
										
										</tr>
										
										
										
										
										
										<?php
										$flag=0; }
										else {
									?>
									 <tr class="odd gradeX">
										<td style="display:none;">  </td>
										<td> </td>
										
										<!-- From this table data -->
										<?php if($fshidedatetime=="1"){ 
					  ?>
										<td style="width: 200px !important;"> </td>
										<?php }
					  if($fshideticketno=="1"){?>
										<td></td>
									 <?php }
									 ?>
									 <!-- for location -->
									 	<td> </td>
									 <?php
					  if($fshidecustomername=="1"){?>	
										<td> </td>
									<?php }
					  if($fshidecustomeruen=="1"){?>	
										<td></td>
									<?php }
					  if($fshidecustomercontactno=="1"){?>	
										<td> </td>
									<?php }
					  if($fshidevehicleno=="1"){?>	
									
										<td> </td>
											
										
										
										
									<?php }?>
									
									<?php
					  if($fshidedrivername=="1"){?>	
										<td> </td>
									<?php }
					  if($fshidedrivernricno=="1"){?>	
										<td> </td>
									<?php }
					  if($fshidedrivercontactno=="1"){?>	
										<td></td>
									<?php }
					  if($fshidetransactionmode=="1"){?>	
										<td> </td>
									<?php }
					  if($fshidetransactiontype=="1"){?>	
										<td></td>
									<?php }
									
					  if($fshidemasterfield1=="1"){?>	
														
										<td></td>
										<?php }
					  if($fshidemasterfield2=="1"){?>	
											<td></td>
										<?php }
					  if($fshidetextfield3=="1"){?>	
										<td></td>
										<?php }
					  if($fshidetextfield4=="1"){?>	
										<td></td>
										<?php }
					  if($fshideopesign=="1"){?>	
										<td></td>
										<?php }
					  if($fshidedrisign=="1"){?>	
														
										<td></td>
										
										<?php }
					  if($fshideinitialwt=="1"){?>		
										<td> </td>
										
									<?php }
					  if($fshidefinalwt=="1"){?>
										<td></td>
											
										
										
	<?php }
					  if($fshideoverallnetwt=="1"){?>									
											<td></td>
										<?php }
					  if($fshidesubtotal=="1"){?>
										<td></td>

										<?php }
					  if($fshidegst=="1"){?>	<td></td>
<?php }
					  if($fshidegrandtotal=="1"){?>	
											<td></td>

																			<?php }
					  if($fshideimage=="1"){?>	<td></td>

				<?php }
					  if($fshideremarks=="1"){?>							<td></td>

										<?php }
					  if($fshidesrno2=="1"){?>	
										<td> <?php echo $n++; ?></td>
	<?php }
					  if($fshideitemname=="1"){?>
										<td> <?php echo $itemname; ?></td>
<?php }
					  if($fshidedatetime2=="1"){?>
										<td> <?php echo $addedon20; ?></td>
	<?php }
					  if($fshideinwt2=="1"){?>
										<td> <?php echo number_format($rt22['vehicletareweight'])."kg"; ?></td>
								<?php }
					  if($fshideoutwt=="1"){?>		
										<td> <?php echo number_format($rt22['vehiclegrossweight'])."kg"; ?></td>
									<?php }
					  if($fshidenetwt=="1"){?>	
										<td> <?php echo number_format($rt22['vehiclenetweight'])."kg"; ?></td>
									<?php }
					  if($fshideitemprice=="1"){?>	
									
										<td style="color : <?php echo $colour; ?>;"> <?php echo number_format($rt22['itemPrice'],2,'.',''); ?></td>
									<?php }
					  if($fshideorgitemprice=="1"){?>			
										<td> <?php echo $itemdecidedrate2; ?></td>
								<?php }
					  if($fshidedeductbywt=="1"){?>	
										<td> <?php  if($weightRed2!=0){
											echo "-";}echo number_format($weightRed2)."kg"; ?></td>
										<?php }
					  if($fshidedeductbyper=="1"){?>	
										<td> <?php if($weightRedPer2!=0){
											echo "-";} echo $weightRedPer2; ?></td>
									<?php }
					  if($fshidedeductbypayment=="1"){?>

										<td> <?php if($weightRedPay2!=0){
											echo "-";} echo $weightRedPay2; ?></td>
										<?php }
					  if($fshideitempricebeforededuct=="1"){?>	
										<td> <?php echo $finaltotal2; ?></td>
										<?php }
					  if($fshideitempriceafterdeduct=="1"){?>
										<td> <?php echo $totalitemprice11; ?></td>
										<?php } ?>
										
											<!-- till this table data -->
											
											
										
		
				
									</tr>
										
										
										
										
										
										 
										
	<?php }}}} ?>								
									<?php
									// Calculate column count for the TOTAL row (to match visible columns)
									$colCount = 2; // hidden column + Sr. No.
									if($fshidedatetime=="1") $colCount++;
									if($fshideticketno=="1") $colCount++;
									$colCount++; // Location (always)
									if($fshidecustomername=="1") $colCount++;
									if($fshidecustomeruen=="1") $colCount++;
									if($fshidecustomercontactno=="1") $colCount++;
									if($fshidevehicleno=="1") $colCount++;
									if($fshidedrivername=="1") $colCount++;
									if($fshidedrivernricno=="1") $colCount++;
									if($fshidedrivercontactno=="1") $colCount++;
									if($fshidetransactionmode=="1") $colCount++;
									if($fshidetransactiontype=="1") $colCount++;
									if($fshidemasterfield1=="1") $colCount++;
									if($fshidemasterfield2=="1") $colCount++;
									if($fshidetextfield3=="1") $colCount++;
									if($fshidetextfield4=="1") $colCount++;
									if($fshideopesign=="1") $colCount++;
									if($fshidedrisign=="1") $colCount++;
									if($fshideinitialwt=="1") $colCount++;
									if($fshidefinalwt=="1") $colCount++;
									if($fshideoverallnetwt=="1") $colCount++;
									if($fshidesubtotal=="1") $colCount++;
									if($fshidegst=="1") $colCount++;
									if($fshidegrandtotal=="1") $colCount++;
									if($fshideimage=="1") $colCount++;
									if($fshideremarks=="1") $colCount++;
									if($fshidesrno2=="1") $colCount++;
									if($fshideitemname=="1") $colCount++;
									if($fshidedatetime2=="1") $colCount++;
									if($fshideinwt2=="1") $colCount++;
									if($fshideoutwt=="1") $colCount++;
									if($fshidenetwt=="1") $colCount++;
									if($fshideitemprice=="1") $colCount++;
									if($fshideorgitemprice=="1") $colCount++;
									if($fshidedeductbywt=="1") $colCount++;
									if($fshidedeductbyper=="1") $colCount++;
									if($fshidedeductbypayment=="1") $colCount++;
									if($fshideitempricebeforededuct=="1") $colCount++;
									if($fshideitempriceafterdeduct=="1") $colCount++;

									$netWtLabel = (isset($netwt) && $netwt!="") ? $netwt : "Net-Wt (Kg)";
									?>
<?php
    $overallNetWtLabel = (isset($overallnetwt) && $overallnetwt!="") ? $overallnetwt : "Overall Net-Wt (Kg)";
    $netWtLabel = (isset($netwt) && $netwt!="") ? $netwt : "Net-Wt (Kg)";

    // Labels (value will be in the next cell)
    // $overallLabelText = "Overall Total ".$overallNetWtLabel.":";
    $netLabelText = "Overall Total ".$netWtLabel.":";

    // Raw numeric totals (no commas, no kg)
    // $overallValueRaw = (float)$sumOverallNetWeight;
    $netValueRaw = (float)$sumDetailNetWeight;

    // Display (UI)
    // $overallValueDisp = number_format($overallValueRaw, 0, '.', ',')."kg";
    $netValueDisp = number_format($netValueRaw, 0, '.', ',')."kg";
?>

<!--<tr class="fw-bold">-->
 <?php
    // TOTAL (Current/Overall Net-Wt): label merged in previous column(s), value in Overall Net-Wt column
    // echo '<td style="display:none;"></td>'; // hidden column
    // echo '<td></td>'; // Sr. No.
    // if($fshidedatetime=="1") echo '<td></td>';
    // if($fshideticketno=="1") echo '<td></td>';
    // echo '<td></td>'; // Location (always)
    // if($fshidecustomername=="1") echo '<td></td>';
    // if($fshidecustomeruen=="1") echo '<td></td>';
    // if($fshidecustomercontactno=="1") echo '<td></td>';
    // if($fshidevehicleno=="1") echo '<td></td>';
    // if($fshidedrivername=="1") echo '<td></td>';
    // if($fshidedrivernricno=="1") echo '<td></td>';
    // if($fshidedrivercontactno=="1") echo '<td></td>';
    // if($fshidetransactionmode=="1") echo '<td></td>';
    // if($fshidetransactiontype=="1") echo '<td></td>';
    // if($fshidemasterfield1=="1") echo '<td></td>';
    // if($fshidemasterfield2=="1") echo '<td></td>';
    // if($fshidetextfield3=="1") echo '<td></td>';
    // if($fshidetextfield4=="1") echo '<td></td>';
    // if($fshideopesign=="1") echo '<td></td>';
    // if($fshidedrisign=="1") echo '<td></td>';

    // // Put label across Initial+Final (if both visible), and numeric in Overall Net-Wt column
    // if($fshideinitialwt=="1" && $fshidefinalwt=="1" && $fshideoverallnetwt=="1") {
    //     // echo '<td class="text-end" colspan="2" style="white-space:nowrap;">'.htmlspecialchars($overallLabelText).'</td>';
    //     // echo '<td class="text-end" style="white-space:nowrap;" data-export="'.htmlspecialchars($overallValueRaw).'">'.htmlspecialchars($overallValueDisp).'</td>';
    // } else if($fshidefinalwt=="1" && $fshideoverallnetwt=="1") {
    //     if($fshideinitialwt=="1") echo '<td></td>';
    //     // echo '<td class="text-end" style="white-space:nowrap;">'.htmlspecialchars($overallLabelText).'</td>';
    //     // echo '<td class="text-end" st/yle="white-space:nowrap;" data-export="'.htmlspecialchars($overallValueRaw).'">'.htmlspecialchars($overallValueDisp).'</td>';
    // } else {
    //     // Fallback: keep structure
    //     if($fshideinitialwt=="1") echo '<td></td>';
    //     // if($fshidefinalwt=="1") echo '<td class="text-end" style="white-space:nowrap;">'.htmlspecialchars($overallLabelText).'</td>';
    //     // if($fshideoverallnetwt=="1") echo '<td class="text-end" style="white-space:nowrap;" data-export="'.htmlspecialchars($overallValueRaw).'">'.htmlspecialchars($overallValueDisp).'</td>';
    // }

    // if($fshidesubtotal=="1") echo '<td></td>';
    // if($fshidegst=="1") echo '<td></td>';
    // if($fshidegrandtotal=="1") echo '<td></td>';
    // if($fshideimage=="1") echo '<td></td>';
    // if($fshideremarks=="1") echo '<td></td>';
    // if($fshidesrno2=="1") echo '<td></td>';
    // if($fshideitemname=="1") echo '<td></td>';
    // if($fshidedatetime2=="1") echo '<td></td>';
    // if($fshideinwt2=="1") echo '<td></td>';
    // if($fshideoutwt=="1") echo '<td></td>';
    // if($fshidenetwt=="1") echo '<td></td>';
    // if($fshideitemprice=="1") echo '<td></td>';
    // if($fshideorgitemprice=="1") echo '<td></td>';
    // if($fshidedeductbywt=="1") echo '<td></td>';
    // if($fshidedeductbyper=="1") echo '<td></td>';
    // if($fshidedeductbypayment=="1") echo '<td></td>';
    // if($fshideitempricebeforededuct=="1") echo '<td></td>';
    // if($fshideitempriceafterdeduct=="1") echo '<td></td>';
?>
<!--</tr>-->

<tr class="fw-bold">
<?php
    // TOTAL (Item Net-Wt): label merged in previous column(s), value in Net-Wt column
    echo '<td style="display:none;"></td>'; // hidden column
    echo '<td></td>'; // Sr. No.
    if($fshidedatetime=="1") echo '<td></td>';
    if($fshideticketno=="1") echo '<td></td>';
    echo '<td></td>'; // Location (always)
    if($fshidecustomername=="1") echo '<td></td>';
    if($fshidecustomeruen=="1") echo '<td></td>';
    if($fshidecustomercontactno=="1") echo '<td></td>';
    if($fshidevehicleno=="1") echo '<td></td>';
    if($fshidedrivername=="1") echo '<td></td>';
    if($fshidedrivernricno=="1") echo '<td></td>';
    if($fshidedrivercontactno=="1") echo '<td></td>';
    if($fshidetransactionmode=="1") echo '<td></td>';
    if($fshidetransactiontype=="1") echo '<td></td>';
    if($fshidemasterfield1=="1") echo '<td></td>';
    if($fshidemasterfield2=="1") echo '<td></td>';
    if($fshidetextfield3=="1") echo '<td></td>';
    if($fshidetextfield4=="1") echo '<td></td>';
    if($fshideopesign=="1") echo '<td></td>';
    if($fshidedrisign=="1") echo '<td></td>';
    // if($fshideinitialwt=="1") echo '<td></td>';
    // if($fshidefinalwt=="1") echo '<td></td>';
    // if($fshideoverallnetwt=="1") echo '<td></td>';
    if($fshidesubtotal=="1") echo '<td></td>';
    if($fshidegst=="1") echo '<td></td>';
    if($fshidegrandtotal=="1") echo '<td></td>';
    if($fshideimage=="1") echo '<td></td>';
    if($fshideremarks=="1") echo '<td></td>';
    if($fshidesrno2=="1") echo '<td></td>';
    if($fshideitemname=="1") echo '<td></td>';
    if($fshidedatetime2=="1") echo '<td></td>';

    // Put label across In+Out (if both visible), and numeric in Net-Wt column
        if($fshideinwt2=="1" && $fshideoutwt=="1" && $fshidenetwt=="1") {
        echo '<td class="text-end" colspan="2" style="white-space:nowrap;">'.htmlspecialchars($netLabelText).'</td>';
        echo '<td class="text-end" style="white-space:nowrap;" data-export="'.htmlspecialchars($netValueRaw).'">'.htmlspecialchars($netValueDisp).'</td>';
    } else if($fshideoutwt=="1" && $fshidenetwt=="1") {
        if($fshideinwt2=="1") echo '<td></td>';
        echo '<td class="text-end" style="white-space:nowrap;">'.htmlspecialchars($netLabelText).'</td>';
        echo '<td class="text-end" style="white-space:nowrap;" data-export="'.htmlspecialchars($netValueRaw).'">'.htmlspecialchars($netValueDisp).'</td>';
    } else {
        if($fshideinwt2=="1") echo '<td></td>';
        if($fshideoutwt=="1") echo '<td class="text-end" style="white-space:nowrap;">'.htmlspecialchars($netLabelText).'</td>';
        if($fshidenetwt=="1") echo '<td class="text-end" style="white-space:nowrap;" data-export="'.htmlspecialchars($netValueRaw).'">'.htmlspecialchars($netValueDisp).'</td>';
    }


    if($fshideitemprice=="1") echo '<td></td>';
    if($fshideorgitemprice=="1") echo '<td></td>';
    if($fshidedeductbywt=="1") echo '<td></td>';
    if($fshidedeductbyper=="1") echo '<td></td>';
    if($fshidedeductbypayment=="1") echo '<td></td>';
    if($fshideitempricebeforededuct=="1") echo '<td></td>';
    if($fshideitempriceafterdeduct=="1") echo '<td></td>';
?>
</tr>
</tbody>

								</table>
								
									<!--end::Table-->
									</div>
								</div>
								<!--end::Card body-->
							</div>
							<!--end::Card-->
						</div>
						<!--end::Container-->
					</div>
					<!--end::Content-->
					<!--begin::Footer-->
					<?php include('footer.php'); ?>
					<!--end::Footer-->
				</div>
				<!--end::Wrapper-->
			</div>
			<!--end::Page-->
		</div>
		
<script>
    // Function to open the popup
    function openPopup() {
        document.getElementById("popupOverlay").style.display = "block";
    }

    // Function to close the popup
    function closePopup() {
        document.getElementById("popupOverlay").style.display = "none";
    }

    // Add event listener to the button inside the document ready function
    $(document).ready(function() {
        // Initially hide the popup
        closePopup();

        // Add event listener to the button
        $("#popupBtn").click(openPopup);
    });
</script>



		<!--end::Root-->
		<!--end::Modals-->
		<!--begin::Javascript-->
		

		<script>var hostUrl = "assets/";</script>
		<!--begin::Global Javascript Bundle(mandatory for all pages)-->
		<script src="assets/plugins/global/plugins.bundle.js"></script>
		<script src="assets/js/scripts.bundle.js"></script>
		<!--end::Global Javascript Bundle-->
		<!--begin::Vendors Javascript(used for this page only)-->
		<script src="assets/plugins/custom/datatables/datatables.bundle.js"></script>
		<!--end::Vendors Javascript-->
		<!--begin::Custom Javascript(used for this page only)-->
		<script src="assets/js/custom/apps/user-management/users/list/table.js"></script>
		<script src="assets/js/custom/apps/user-management/users/list/export-users.js"></script>
		<script src="assets/js/custom/apps/user-management/users/list/add.js"></script>
		<script src="assets/js/custom/apps/ecommerce/reports/views/views.js"></script>
		<script src="assets/js/widgets.bundle.js"></script>
		<script src="assets/js/custom/widgets.js"></script>
		<script src="assets/js/custom/apps/chat/chat.js"></script>
		<script src="assets/js/custom/utilities/modals/upgrade-plan.js"></script>
		<script src="assets/js/custom/utilities/modals/users-search.js"></script>
		<script type="text/javascript" src="myjs/64/jquery.base64.js"/></script>
		<script type="text/javascript" src="myjs/tableexport.js"/></script>
		<script type="text/javascript" src="js/notification.js"/></script>
		<script src="assets/js/custom/utilities/modals/upgrade-plan.js"></script>
<script src="assets/js/custom/utilities/modals/create-app.js"></script>
<script src="assets/js/custom/utilities/modals/users-search.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
<script>
function normalizeNumberText(s){
    if(s === null || s === undefined) return null;
    let t = String(s).replace(/\u00A0/g, ' ').trim();
    if(t === "") return null;

    const hadKg = /kg/i.test(t);
    t = t.replace(/kg/ig, '').trim();

    const hadComma = t.indexOf(',') !== -1;
    const hadDot = t.indexOf('.') !== -1;

    // Only convert to number if it's clearly a numeric measurement/value
    const looksNumeric = /^-?\d[\d,]*\.?\d*$/.test(t);
    if(!looksNumeric) return null;
    if(!(hadKg || hadComma || hadDot)) return null;

    const num = parseFloat(t.replace(/,/g, ''));
    if(Number.isNaN(num)) return null;
    return num;
}

function sanitizeWorksheet(ws){
    Object.keys(ws).forEach(function(addr){
        if(addr[0] === '!') return;
        const cell = ws[addr];
        if(!cell) return;

        if(cell.t === 's' || typeof cell.v === 'string'){
            const raw = cell.v;
            const num = normalizeNumberText(raw);
            if(num !== null){
                cell.t = 'n';
                cell.v = num;        // numeric value (no 'kg', no commas)
                delete cell.w;
            } else if (typeof raw === 'string') {
                cell.v = raw.replace(/\u00A0/g, ' ').trim();
            }
        }
    });
}

function buildSanitizedSheet(tableID){
    const table = document.getElementById(tableID);
    const ws = XLSX.utils.table_to_sheet(table, { raw: true });
    sanitizeWorksheet(ws);
    return ws;
}

function exportTableToExcel(tableID, filename = ''){
    const ws = buildSanitizedSheet(tableID);
    const wb = XLSX.utils.book_new();
    XLSX.utils.book_append_sheet(wb, ws, "Job_Report");
    XLSX.writeFile(wb, (filename ? filename : 'exported_table') + '.xlsx');
}

function exportTableToCSV(tableID, filename = ''){
    const ws = buildSanitizedSheet(tableID);
    const csv = XLSX.utils.sheet_to_csv(ws);

    const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
    const link = document.createElement('a');
    link.href = URL.createObjectURL(blob);
    link.download = (filename ? filename : 'exported_table') + '.csv';

    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
}
</script>


<?php

if(isset($_SESSION['msg']))
{
	$tt = $_SESSION['msg'];
	echo "<input type=\"hidden\" id=\"mymsg\" value=\"$tt\"/>";
	unset($_SESSION['msg']);
	
	
?>	
			
 <script>
  function hideElement() {
    var element = document.getElementById("elementToHide");
    element.classList.add("hidden");
  }
</script>
			
		<script lang="javascript">

var a = [
    function () {
	

		var mymsg = document.getElementById("mymsg").value;
		toastr.success(mymsg, "Operation Completed")
		
    },
    function () {
        $('span').show();
    },
    function () {
        $('p').fadeIn(100);
    }
];		
					

a[0]();
</script>


		
	
<?php
}

if(isset($_SESSION['msg1']))
{
	$tt1 = $_SESSION['msg1'];
	echo "<input type=\"hidden\" id=\"mymsg1\" value=\"$tt1\"/>";
	unset($_SESSION['msg1']);
	
	
	?>	
								
		<script lang="javascript">

var a = [
    function () {
	

		var mymsg = document.getElementById("mymsg1").value;
		toastr.warning(mymsg, "Error")
		
    },
    function () {
        $('span').show();
    },
    function () {
        $('p').fadeIn(100);
    }
];		
					

a[0]();
</script>
	
<?php

}
?>								
		<!--end::Custom Javascript-->
		<!--end::Javascript-->
		
		

<!-- Initialize Flatpickr date range picker -->
  <script>
  document.addEventListener("DOMContentLoaded", function() {
    var firstDiv = document.getElementById("firstDiv");

    // For Firefox
    firstDiv.style.scrollbarColor = "#000000 #D7DCE2";
    firstDiv.style.scrollbarWidth = "thin";

    // For WebKit (Chrome, Safari)
    firstDiv.style.overflow = "auto";  // Ensure overflow property is set
    firstDiv.style.scrollbarWidth = "thick";
    firstDiv.style.scrollbarColor = "#000000 #D7DCE2";
  });
</script>
	</body>
	<!--end::Body-->
</html>