<?php
include("../config.php");
require_once '../assets/plugins/pdf/tcpdf.php';
$pdf = new PDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
if($_GET['module'] == 'BREGSUM') {
if(isset($_GET['vendor_id']) && !empty($_GET['vendor_id'])) {
		$vendor_id = strtoupper($_GET['vendor_id']);
	}

	if(isset($_GET['bill_no']) && !empty($_GET['bill_no'])) {
		$bill_no = strtoupper($_GET['bill_no']);
	}

	$sd = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_GET['start_date'])));
	$ed = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_GET['end_date'])));

	if(!empty($vendor_id) && !empty($bill_no) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `billing` WHERE vendor_id = '".$vendor_id."' AND DATE(bill_date) >= '".$sd."' AND DATE(bill_date) <= '".$ed."' AND invoice_no = '".$bill_no."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY invoice_no";
	}else if(!empty($vendor_id) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `billing` WHERE vendor_id = '".$vendor_id."' AND DATE(bill_date) >= '".$sd."' AND DATE(bill_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY invoice_no";
	}else if(!empty($vendor_id)){
		$lr = "SELECT * FROM `billing` WHERE vendor_id = '".$vendor_id."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY invoice_no";

	}else if(!empty($bill_no) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `billing` WHERE DATE(bill_date) >= '".$sd."' AND DATE(bill_date) <= '".$ed."' AND invoice_no = '".$bill_no."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY invoice_no";
	}else{
		$lr = "SELECT * FROM `billing` WHERE DATE(bill_date) >= '".$sd."' AND DATE(bill_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY invoice_no";
	}

	$result 		= mysqli_query($conn,$lr);
	$total       	= mysqli_num_rows($result);

	$master_accounts    = combine(getAllRecords('vendor_master'), 'id', 'name');
	$master_company     = combine(getAllRecords('company_mst'), 'id', 'name');

	$output= '';
	$output.= '<html>
	<table style="width: 100%" cellpadding="1">
		<thead>
			<tr style="border: 0.1pt solid black;">
				<td style="text-align:center;font-size:15px;"><strong>'.@$master_company[$_SESSION['company_id']].'</strong></td>
			</tr>
			<tr style="border: 0.1pt solid black;text-align:center;">
				<td style="text-align:center;margin-bottom:10px;">BILLING SUMMERY <strong>START FROM</strong> : '.$_GET['start_date'].' <strong>TO</strong> :  '.$_GET['end_date'].'</td>
			</tr>

		</thead>
		<tbody>
		    <tr style="border: 0.1pt solid black;">
				<td width="5%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>BILL NO</strong></td>
				<td width="10%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>BILL DATE</strong></td>
				<td width="25%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>PARTY</strong></td>
				<td width="15%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>GST</strong></td>
				<td width="12%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>GROSS AMOUNT</strong></td>
				<td width="12%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>TOTAL ADD(+)</strong></td>
				<td width="12%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>TOTAL DED(-)</strong></td>
		      	<td width="12%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>NET AMOUNT</strong></td>
			</tr>
			';
			
			$total_count    = 0;
		    if(count($total) > 0) {
				$total_fright = 0;
				$rate 	= 0;
				$amount = 0;
				$other  = 0;
				$other  = 0;
				$other  = 0;
				$ga    	= 0;
				$na     = 0;
				$total_add = 0;
				$total_sub = 0;
				while ($row = mysqli_fetch_array($result)) {
					$nor     = "SELECT * FROM `vendor_master` WHERE `id` = '".$row['vendor_id']."'";
					$nor_res = mysqli_query($conn,$nor);
					$nor_row = mysqli_fetch_assoc($nor_res);
					
					$add      = "SELECT SUM(amount) AS total_add FROM billing_details WHERE type = 'add' AND bill_no = '".$data['invoice_no']."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY bill_no";
					$add_res  = mysqli_query($conn,$add);
					$add_row  = mysqli_fetch_assoc($add_res);
					
					$sub      = "SELECT SUM(amount) AS total_sub FROM billing_details WHERE type = 'sub' AND bill_no = '".$data['invoice_no']."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY bill_no";
					$sub_res  = mysqli_query($conn,$sub);
					$sub_row  = mysqli_fetch_assoc($sub_res);

					$total_add += $add_row['total_add'];
					$total_sub += $sub_row['total_sub'];
					$ga    	   += $row['gross_amt'];
					$na        += $row['net_amt'];
					$remove_alies = substr($row["invoice_no"], 4);
					$new_bill_no   = ltrim($remove_alies, "0");
				
					$output.='<tr style="border: 0.1pt solid black;">
						<td width="5%" align="center" style="text-align: center;">'.$new_bill_no.'</td>
						<td width="10%" align="center" style="text-align: center;">'.risFormatDate($row["bill_date"]).'</td>
						<td width="25%" style="text-align: center;">'.@$master_accounts[$row['vendor_id']].'</td>
						<td width="15%" style="text-align: center;">'.$nor_row['gstin'].'</td>
						<td width="12%" style="text-align: center;">'.customFormatMoney($row['gross_amt']).'</td>
						<td width="12%" style="text-align: center;">'.customFormatMoney($add_row['total_add']).'</td>
						<td width="12%" style="text-align: center;">'.customFormatMoney($sub_row['total_sub']).'</td>
						<td width="12%" style="text-align: center;">'.customFormatMoney($row['net_amt']).'</td>
			    	</tr>';
				}
			}
		$output.='<tr>
					<td colspan="4" width="55%" align="left" style="text-align: left;border-top:1px solid black;border-bottom:1px solid black"><b>TOTAL</b></td>
					
					<td width="12%" style="border-top: 1px solid black;border-bottom: 1px solid black; text-align: center;"><strong>' . customFormatMoney($ga) . '</strong></td>

				    <td width="12%" style="border-top: 1px solid black;border-bottom: 1px solid black; text-align: center;"><strong>' . customFormatMoney($total_add) . '</strong></td>

				    <td width="12%" style="border-top: 1px solid black;border-bottom: 1px solid black; text-align: center;"><strong>' . customFormatMoney($total_sub) . '</strong></td>

				    <td width="12%" style="border-top: 1px solid black;border-bottom: 1px solid black; text-align: center;"><strong>' . customFormatMoney($na) . '</strong></td>
		</tr>
		</tbody>
	</table>
	</html>';
	$title = 'BILLING SUMMERY';
	$fname = 'billing_summery.pdf';
}elseif ($_GET['module'] == 'BR') {
	if(isset($_GET['vendor_id']) && !empty($_GET['vendor_id'])) {
	$vendor_id = strtoupper($_GET['vendor_id']);
	}

	if(isset($_GET['truck_no']) && !empty($_GET['truck_no'])) {
		$truck_no = strtoupper($_GET['truck_no']);
	}

	if(isset($_GET['broker']) && !empty($_GET['broker'])) {
		$broker = strtoupper($_GET['broker']);
	}

	$sd = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_GET['start_date'])));
	$ed = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_GET['end_date'])));

	if(!empty($vendor_id) && !empty($broker) && !empty($truck_no) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `lr_mst` WHERE agent = '".$broker."' AND truck_no = '".$truck_no."' AND (consignor_name = '".$vendor_id."' OR consignee_name = '".$vendor_id."')AND DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lr_no";
	}else if(!empty($vendor_id) && !empty($truck_no) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `lr_mst` WHERE truck_no = '".$truck_no."' AND (consignor_name = '".$vendor_id."' OR consignee_name = '".$vendor_id."')AND DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lr_no";
	}elseif(!empty($vendor_id) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `lr_mst` WHERE (consignor_name = '".$vendor_id."' OR consignee_name = '".$vendor_id."') AND DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lr_no";
	}else if(!empty($vendor_id)){
		$lr = "SELECT * FROM `lr_mst` WHERE consignor_name = '".$vendor_id."' OR consignee_name = '".$vendor_id."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lr_no";

	}else if(!empty($broker) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `lr_mst` WHERE agent = '".$broker."' AND DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lr_no";
	}else if(!empty($truck_no) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `lr_mst` WHERE truck_no = '".$truck_no."' AND DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lr_no";
	}else if(!empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `lr_mst` WHERE DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lr_no";
	}else{
		$lr = "SELECT * FROM `lr_mst` WHERE DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lr_no";
	}


	$result 		= mysqli_query($conn,$lr);
	$total       	= mysqli_num_rows($result);
	
	$master_accounts    = combine(getAllRecords('vendor_master'), 'id', 'name');
	$master_company     = combine(getAllRecords('company_mst'), 'id', 'name');

	$output= '';
	$output.= '<html>
	<table style="width: 100%" cellpadding="1">
		<thead>
			<tr style="border: 0.1pt solid black;">
				<td style="text-align:center;font-size:15px;"><strong>'.@$master_company[$_SESSION['company_id']].'</strong></td>
			</tr>
			<tr style="border: 0.1pt solid black;text-align:center;">
				<td style="text-align:center;margin-bottom:10px;">BOOKING REGISTER <strong>START FROM</strong> : '.$_GET['start_date'].' <strong>TO</strong> :  '.$_GET['end_date'].'</td>
			</tr>

		</thead>
		<tbody>
		    <tr style="border: 0.1pt solid black;">
				<td width="6%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>LR NO.</strong></td>
				<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>DATE</strong></td>
				<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>TRUCK NO</strong></td>
				<td width="10%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>CONSIGNOR</strong></td>
				<td width="10%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>CONSIGNEE</strong></td>
				<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>BILL TO</strong></td>
				<td width="10%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>FROM-TO</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>PCS</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>WEIGHT</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>FREIGHT</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>PAID BY</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>BROKER</strong></td>

		      	
			</tr>
			';
			
					$table       	= '';
					$total_count    = 0;
					if(count($total) > 0) {
						$total_fright = 0;
						while ($row = mysqli_fetch_array($result)) {
							$nor     = "SELECT * FROM `vendor_master` WHERE `id` = '".$row['consignor_name']."'";
							$nor_res = mysqli_query($conn,$nor);
							$nor_row = mysqli_fetch_assoc($nor_res);

							$nee     = "SELECT * FROM `vendor_master` WHERE `id` = '".$row['consignee_name']."'";
							$nee_res = mysqli_query($conn,$nee);
							$nee_row = mysqli_fetch_assoc($nee_res);
							
							if($row['eway_date'] != ''){
					            $edate = risFormatDate($row['eway_date']);
					        }else{
					            $edate = '';
					        }

					        if($row['eway_ex_date'] != ''){
					            $exdate = risFormatDate($row['eway_ex_date']);
					        }else{
					            $exdate = '';
					        }

							$remove_alies = substr($row["lr_no"], 4);
							$new_bill_no   = ltrim($remove_alies, "0");
							$total_fright += $row['freight'];

					$output.='<tr style="border: 0.1pt solid black;">
						<td width="6%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row["lr_no"].'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.risFormatDate($row["l_date"]).'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row["truck_no"].'</td>
						<td width="10%" style="text-align: center;border-bottom:1px solid black">'. @$master_accounts[$row['consignor_name']] . '<br> '.$nor_row['gstin'].'</td>
						<td width="10%" align="center" style="text-align: center;border-bottom:1px solid black">'. @$master_accounts[$row['consignee_name']] . '<br> '.$nee_row['gstin'].'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'. @$master_accounts[$row['billing_to']] .'</td>
						<td width="10%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row['from_place'] . ' - ' . $row['to_place'].'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row['pcs'].'</td>
						<td width="8%" style="text-align: center;border-bottom:1px solid black">'.$row['weight'].'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($row['freight']).'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row['billing_party'].'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row['agent'].'</td>

						
			    	</tr>
			    	
			    	';
				}
				$output.='
			    	<tr>
			    		<td colspan="9" style="border-top:1px solid black;border-bottom:1px solid black"><b>TOTAL FREIGHT</b></td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($total_fright) . '</td>
			    	</tr>';
			}
		$output.='
		</tbody>
	</table>
	</html>';
	$title = 'BOOKING REGISTER';
	$fname = '=booking_register.pdf';
}elseif ($_GET['module'] == 'PLFL') {
	if(isset($_GET['vendor_id']) && !empty($_GET['vendor_id'])) {
	$vendor_id = strtoupper($_GET['vendor_id']);
	}

	if(isset($_GET['truck_no']) && !empty($_GET['truck_no'])) {
		$truck_no = strtoupper($_GET['truck_no']);
	}

	if(isset($_GET['broker']) && !empty($_GET['broker'])) {
		$broker = strtoupper($_GET['broker']);
	}

	$sd = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_GET['start_date'])));
	$ed = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_GET['end_date'])));

	if(!empty($vendor_id) && !empty($broker) && !empty($truck_no) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM lr_mst WHERE truck_no = '".$truck_no."' AND DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND lhc_status = 'N' AND (consignor_name = '".$vendor_id."' OR consignee_name = '".$vendor_id."') AND agent = '".$broker."' AND truck_no = '".$truck_no."' GROUP BY lr_no";
		
	}else if(!empty($vendor_id) && !empty($truck_no) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM lr_mst WHERE truck_no = '".$truck_no."' AND DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND lhc_status = 'N' AND (consignor_name = '".$vendor_id."' OR consignee_name = '".$vendor_id."') AND truck_no = '".$truck_no."' GROUP BY lr_no";

	}else if(!empty($vendor_id) && !empty($truck_no) && !empty($broker) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM lr_mst WHERE truck_no = '".$truck_no."' AND agent = '".$broker."' AND DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND lhc_status = 'N' AND (consignor_name = '".$vendor_id."' OR consignee_name = '".$vendor_id."') AND truck_no = '".$truck_no."' GROUP BY lr_no";

	}else if(!empty($vendor_id) && !empty($broker) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM lr_mst WHERE agent = '".$broker."' AND DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND lhc_status = 'N' AND (consignor_name = '".$vendor_id."' OR consignee_name = '".$vendor_id."') GROUP BY lr_no";

	}else if(!empty($vendor_id) && !empty($sd) && !empty($ed)){
		
		$lr = "SELECT * FROM lr_mst WHERE (consignor_name = '".$vendor_id."' OR consignee_name = '".$vendor_id."') AND DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND lhc_status = 'N' GROUP BY lr_no";

	}else if(!empty($vendor_id)){
		$lr = "SELECT * FROM lr_mst WHERE (consignor_name = '".$vendor_id."' OR consignee_name = '".$vendor_id."') AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND lhc_status = 'N' GROUP BY lr_no";

	}else if(!empty($broker) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM lr_mst WHERE agent = '".$broker."' AND DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND lhc_status = 'N' GROUP BY lr_no";

	}else if(!empty($truck_no) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM lr_mst WHERE truck_no = '".$truck_no."' AND DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND lhc_status = 'N' GROUP BY lr_no";


	}else if(!empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM lr_mst WHERE DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND lhc_status = 'N' GROUP BY lr_no";
	}else{
		$lr = "SELECT * FROM lr_mst WHERE DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND lhc_status = 'N' GROUP BY lr_no";
	}


	$result 		= mysqli_query($conn,$lr);
	$total       	= mysqli_num_rows($result);
	
	$master_accounts    = combine(getAllRecords('vendor_master'), 'id', 'name');
	$master_company     = combine(getAllRecords('company_mst'), 'id', 'name');

	$output= '';
	$output.= '<html>
	<table style="width: 100%" cellpadding="1">
		<thead>
			<tr style="border: 0.1pt solid black;">
				<td style="text-align:center;font-size:15px;"><strong>'.@$master_company[$_SESSION['company_id']].'</strong></td>
			</tr>
			<tr style="border: 0.1pt solid black;text-align:center;">
				<td style="text-align:center;margin-bottom:10px;">PENDING LR FOR LHC <strong>START FROM</strong> : '.$_GET['start_date'].' <strong>TO</strong> :  '.$_GET['end_date'].'</td>
			</tr>

		</thead>
		<tbody>
		    <tr style="border: 0.1pt solid black;">
				<td width="6%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>LR NO.</strong></td>
				<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>DATE</strong></td>
				<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>TRUCK NO</strong></td>
				<td width="10%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>CONSIGNOR</strong></td>
				<td width="10%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>CONSIGNEE</strong></td>
				<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>BILL TO</strong></td>
				<td width="10%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>FROM-TO</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>PCS</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>WEIGHT</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>FREIGHT</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>PAID BY</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>BROKER</strong></td>
			</tr>
			';
			
					$table       	= '';
					$total_count    = 0;
					if(count($total) > 0) {
					$total_fright = 0;
					while ($row = mysqli_fetch_array($result)) {
					$nor     = "SELECT * FROM `vendor_master` WHERE `id` = '".$row['consignor_name']."'";
					$nor_res = mysqli_query($conn,$nor);
					$nor_row = mysqli_fetch_assoc($nor_res);

					$nee     = "SELECT * FROM `vendor_master` WHERE `id` = '".$row['consignee_name']."'";
					$nee_res = mysqli_query($conn,$nee);
					$nee_row = mysqli_fetch_assoc($nee_res);
					$remove_alies = substr($row["lr_no"], 4);
					$new_bill_no   = ltrim($remove_alies, "0");
					$total_fright += $row['freight'];
					$output.='<tr style="border: 0.1pt solid black;">
						<td width="6%" align="center" style="text-align: center;border-bottom:1px solid black">'.$new_bill_no.'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.risFormatDate($row["l_date"]).'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row["truck_no"].'</td>
						<td width="10%" style="text-align: center;border-bottom:1px solid black">'. @$master_accounts[$row['consignor_name']] . '<br> '.$nor_row['gstin'].'</td>
						<td width="10%" align="center" style="text-align: center;border-bottom:1px solid black">'. @$master_accounts[$row['consignee_name']] . '<br> '.$nee_row['gstin'].'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'. @$master_accounts[$row['billing_to']] .'</td>
						<td width="10%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row['from_place'] . ' - ' . $row['to_place'].'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row['pcs'].'</td>
						<td width="8%" style="text-align: center;border-bottom:1px solid black">'.$row['weight'].'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($row['freight']).'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row['billing_party'].'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row['agent'].'</td>
			    	</tr>
			    	
			    	';
				}
				$output.='
			    	<tr>
			    		<td colspan="9" style="border-top:1px solid black;border-bottom:1px solid black"><b>TOTAL FREIGHT</b></td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($total_fright) . '</td>
			    	</tr>';
			}
		$output.='
		</tbody>
	</table>
	</html>';
	$title = 'PENDING LR FOR LHC';
	$fname = '=pending_lr_for_lhc.pdf';
}elseif ($_GET['module'] == 'PLFB') {
	if(isset($_GET['vendor_id']) && !empty($_GET['vendor_id'])) {
	$vendor_id = strtoupper($_GET['vendor_id']);
	}

	if(isset($_GET['truck_no']) && !empty($_GET['truck_no'])) {
		$truck_no = strtoupper($_GET['truck_no']);
	}

	if(isset($_GET['broker']) && !empty($_GET['broker'])) {
		$broker = strtoupper($_GET['broker']);
	}

	$sd = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_GET['start_date'])));
	$ed = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_GET['end_date'])));

	if(!empty($vendor_id) && !empty($broker) && !empty($truck_no) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM lr_mst WHERE billing_to = '".$vendor_id."' AND DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND agent = '".$broker."' AND truck_no = '".$truck_no."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND `billing_status` = 'N' GROUP BY lr_no";
		
	}else if(!empty($vendor_id) && !empty($truck_no) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM lr_mst WHERE billing_to = '".$vendor_id."' AND DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND truck_no = '".$truck_no."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND `billing_status` = 'N' GROUP BY lr_no";
	}else if(!empty($vendor_id) && !empty($broker) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM lr_mst WHERE billing_to = '".$vendor_id."' AND DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND agent = '".$broker."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND `billing_status` = 'N' GROUP BY lr_no";

	}else if(!empty($vendor_id) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM lr_mst WHERE billing_to = '".$vendor_id."' AND DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND `billing_status` = 'N' GROUP BY lr_no";

	}else if(!empty($vendor_id)){
		$lr = "SELECT * FROM lr_mst WHERE billing_to = '".$vendor_id."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND `billing_status` = 'N' GROUP BY lr_no";

	}else if(!empty($broker) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM lr_mst WHERE DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND agent = '".$broker."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND `billing_status` = 'N' GROUP BY lr_no";

	}else if(!empty($truck_no) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM lr_mst WHERE DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND truck_no = '".$truck_no."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND `billing_status` = 'N' GROUP BY lr_no";

	}else if(!empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM lr_mst WHERE DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND `billing_status` = 'N' GROUP BY lr_no";
	}else{
		$lr = "SELECT * FROM lr_mst WHERE DATE(l_date) >= '".$sd."' AND DATE(l_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' AND `billing_status` = 'N' GROUP BY lr_no";
	}


	$result 		= mysqli_query($conn,$lr);
	$total       	= mysqli_num_rows($result);
	
	$master_accounts    = combine(getAllRecords('vendor_master'), 'id', 'name');
	$master_company     = combine(getAllRecords('company_mst'), 'id', 'name');

	$output= '';
	$output.= '<html>
	<table style="width: 100%" cellpadding="1">
		<thead>
			<tr style="border: 0.1pt solid black;">
				<td style="text-align:center;font-size:15px;"><strong>'.@$master_company[$_SESSION['company_id']].'</strong></td>
			</tr>
			<tr style="border: 0.1pt solid black;text-align:center;">
				<td style="text-align:center;margin-bottom:10px;">PENDING LR FOR BILLING <strong>START FROM</strong> : '.$_GET['start_date'].' <strong>TO</strong> :  '.$_GET['end_date'].'</td>
			</tr>

		</thead>
		<tbody>
		    <tr style="border: 0.1pt solid black;">
				<td width="6%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>LR NO.</strong></td>
				<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>DATE</strong></td>
				<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>TRUCK NO</strong></td>
				<td width="10%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>CONSIGNOR</strong></td>
				<td width="10%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>CONSIGNEE</strong></td>
				<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>BILL TO</strong></td>
				<td width="10%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>FROM-TO</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>PCS</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>WEIGHT</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>FREIGHT</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>PAID BY</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>BROKER</strong></td>
			</tr>
			';
			
					$table       	= '';
					$total_count    = 0;
					if(count($total) > 0) {
					$total_fright = 0;
					while ($row = mysqli_fetch_array($result)) {
					$nor     = "SELECT * FROM `vendor_master` WHERE `id` = '".$row['consignor_name']."'";
					$nor_res = mysqli_query($conn,$nor);
					$nor_row = mysqli_fetch_assoc($nor_res);

					$nee     = "SELECT * FROM `vendor_master` WHERE `id` = '".$row['consignee_name']."'";
					$nee_res = mysqli_query($conn,$nee);
					$nee_row = mysqli_fetch_assoc($nee_res);
					$remove_alies = substr($row["lr_no"], 4);
					$new_bill_no   = ltrim($remove_alies, "0");
					$total_fright += $row['freight'];
					$output.='<tr style="border: 0.1pt solid black;">
						<td width="6%" align="center" style="text-align: center;border-bottom:1px solid black">'.$new_bill_no.'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.risFormatDate($row["l_date"]).'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row["truck_no"].'</td>
						<td width="10%" style="text-align: center;border-bottom:1px solid black">'. @$master_accounts[$row['consignor_name']] . '<br> '.$nor_row['gstin'].'</td>
						<td width="10%" align="center" style="text-align: center;border-bottom:1px solid black">'. @$master_accounts[$row['consignee_name']] . '<br> '.$nee_row['gstin'].'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'. @$master_accounts[$row['billing_to']] .'</td>
						<td width="10%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row['from_place'] . ' - ' . $row['to_place'].'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row['pcs'].'</td>
						<td width="8%" style="text-align: center;border-bottom:1px solid black">'.$row['weight'].'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($row['freight']).'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row['billing_party'].'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row['agent'].'</td>
			    	</tr>
			    	
			    	';
				}
				$output.='
			    	<tr>
			    		<td colspan="9" style="border-top:1px solid black;border-bottom:1px solid black"><b>TOTAL FREIGHT</b></td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($total_fright) . '</td>
			    	</tr>';
			}
		$output.='
		</tbody>
	</table>
	</html>';
	$title = 'PENDING LR FOR BILLING';
	$fname = '=pending_lr_for_billing.pdf';
}elseif ($_GET['module'] == 'LHCREG') {
	if(isset($_GET['owner']) && !empty($_GET['owner'])) {
	$owner = strtoupper($_GET['owner']);
	}


	if(isset($_GET['agent']) && !empty($_GET['agent'])) {
		$agent = strtoupper($_GET['agent']);
	}

	if(isset($_GET['lhc_no']) && !empty($_GET['lhc_no'])) {
		$lhc_no = strtoupper($_GET['lhc_no']);
	}


	$sd = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_GET['start_date'])));
	$ed = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_GET['end_date'])));

	if(!empty($owner) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `lhc` WHERE owner_name = '".$owner."' AND DATE(lhc_date) >= '".$sd."' AND DATE(lhc_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";
	}else if(!empty($owner_name)){
		$lr = "SELECT * FROM `lhc` WHERE owner_name = '".$owner."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";

	}else if(!empty($agent) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `lhc` WHERE agent = '".$agent."' AND DATE(lhc_date) >= '".$sd."' AND DATE(lhc_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";

	}else if(!empty($agent)){
		$lr = "SELECT * FROM `lhc` WHERE agent = '".$agent."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";

	}else if(!empty($lhc_no) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `lhc` WHERE lhc_no = '".$lhc_no."' AND DATE(lhc_date) >= '".$sd."' AND DATE(lhc_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";
	}else if(!empty($lhc_no)){
		$lr = "SELECT * FROM `lhc` WHERE lhc_no = '".$lhc_no."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";
	}else if(!empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `lhc` WHERE DATE(lhc_date) >= '".$sd."' AND DATE(lhc_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";
	}else{
		$lr = "SELECT * FROM `lhc` WHERE DATE(lhc_date) >= '".$sd."' AND DATE(lhc_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";
	}

	$result 		= mysqli_query($conn,$lr);
	$total       	= mysqli_num_rows($result);

	$master_accounts       = combine(getAllRecords('vendor_master'), 'id', 'name');
	$master_accounts       = combine(getAllRecords('truck_mst'), 'id', 'o_name');
	$master_company    	   = combine(getAllRecords('company_mst'), 'id', 'name');

	

	$output= '';
	$output.= '<html>
	<table style="width: 100%" cellpadding="1">
		<thead>
			<tr style="border: 0.1pt solid black;">
				<td style="text-align:center;font-size:15px;"><strong>'.@$master_company[$_SESSION['company_id']].'</strong></td>
			</tr>
			<tr style="border: 0.1pt solid black;text-align:center;">
				<td style="text-align:center;margin-bottom:10px;">LHC REGISTER <strong>START FROM</strong> : '.$_GET['start_date'].' <strong>TO</strong> :  '.$_GET['end_date'].'</td>
			</tr>

		</thead>
		<tbody>
		    <tr style="border: 0.1pt solid black;">
				<td width="6%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>LHC NO</strong></td>
				<td width="7%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>LHC DATE</strong></td>
				<td width="7%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>TRUCK NO</strong></td>
				<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>FROM - TO</strong></td>
				<td width="6%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>OWNER</strong></td>
				<td width="6%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>AGENT</strong></td>
				<td width="6%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>LORRY HIRE CHARGES</strong></td>
		      	<td width="6%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>TOTAL ADDITION</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>DISEL</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>TOTAL DEDUCTION</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>ADVANCE</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>PENDING</strong></td>
		      	<td width="6%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>BANK</strong></td>
		      	<td width="5%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>CASH</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>PAYMENT</strong></td>
			</tr>
			';
			
					$table       	= '';
					$total_count    = 0;
					if(count($total) > 0) {
						$total_add 		= 0;
						$total_sub 		= 0;
						$lorry_hire     = 0;
						$disel    		= 0;
						$adv     		= 0;
						$balance     	= 0;
						$bank     		= 0;
						$cash    	   	= 0;
						$total_add 		= 0;
						$total_sub 		= 0;
					while ($row = mysqli_fetch_array($result)) {
							$add      = "SELECT SUM(amount) AS total_add FROM lhc_details WHERE type = 'add' AND lhc_id = '".$row['lhc_no']."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_id";
							$add_res  = mysqli_query($conn,$add);
							$add_row  = mysqli_fetch_assoc($add_res);
							
							$sub      = "SELECT SUM(amount) AS total_sub FROM lhc_details WHERE type = 'sub' AND lhc_id = '".$row['lhc_no']."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_id";
							$sub_res  = mysqli_query($conn,$sub);
							$sub_row  = mysqli_fetch_assoc($sub_res);

							$truck 			= "SELECT * FROM truck_mst WHERE id = '".$row['owner_name']."'";
							$truck_res 		= mysqli_query($conn,$truck);
							$truck_row 		= mysqli_fetch_assoc($truck_res);

							$agent 			= "SELECT * FROM agent WHERE name = '".$row['agent']."'";
							$agent_res 		= mysqli_query($conn,$agent);
							$agent_row 		= mysqli_fetch_assoc($agent_res);

							$total_add 		+= $add_row['total_add'];
							$total_sub 		+= $sub_row['total_sub'];
							$lorry_hire     += $row['lorry_hire'];
							$disel    		+= $row['disel_amnt'];
							$adv     		+= $row['adv_amnt'];
							$balance     	+= $row['balance'];
							$bank     		+= $row['pay_mode_amnt'];
							$cash    	   	+= $row['cash'];
							$remove_alies = substr($row["lhc_no"], 4);
					    	$new_bill_no   = ltrim($remove_alies, "0");
					$output.='<tr style="border: 0.1pt solid black;">
						<td width="6%" align="center" style="text-align: center;border-bottom:1px solid black">'.$new_bill_no.'</td>
						<td width="7%" align="center" style="text-align: center;border-bottom:1px solid black">'.risFormatDate($row["lhc_date"]).'</td>
						<td width="7%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row['truck_no'].'</td>
						<td width="8%" style="text-align: center;border-bottom:1px solid black">'. $row['from_place'] . '-'. $row['to_place'] .'</td>
						<td width="6%" align="center" style="text-align: center;border-bottom:1px solid black"><span style="color:red">'.$truck_row['pan_no'].'</span>&nbsp;'. @$master_accounts[$row['owner_name']] . '</td>
						<td width="6%" align="center" style="text-align: center;border-bottom:1px solid black"><span style="color:red">'.$agent_row['pan_no'].'</span>&nbsp;'. $row['agent'] . '</td>
						<td width="6%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($row['lorry_hire']).'</td>
						<td width="6%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($add_row['total_add']).'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($row['disel_amnt']).'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($sub_row['total_sub']).'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($row['adv_amnt']).'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($row['balance']).'</td>
						<td width="6%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($row['pay_mode_amnt']).'</td>
						<td width="5%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($row['cash']).'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row['payment_to'].'</td>
			    	</tr>
			    	';
			    	
				}
				$output.='
			    	<tr>
			    		<td colspan="6" style="border-top:1px solid black;border-bottom:1px solid black"><b>TOTAL</b></td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($lorry_hire) . '</td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($total_add) . '</td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($disel) . '</td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($total_sub) . '</td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($adv) . '</td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($balance) . '</td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($bank) . '</td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($cash) . '</td>
			    	</tr>';
			}
		$output.='
		</tbody>
	</table>
	</html>';
	$title = 'LHC REGISTER';
	$fname = 'lhc_register.pdf';
}elseif ($_GET['module'] == 'TDSPBL') {
	if(isset($_GET['owner']) && !empty($_GET['owner'])) {
	$owner = strtoupper($_GET['owner']);
	}


	if(isset($_GET['agent']) && !empty($_GET['agent'])) {
		$agent = strtoupper($_GET['agent']);
	}

	if(isset($_GET['lhc_no']) && !empty($_GET['lhc_no'])) {
		$lhc_no = strtoupper($_GET['lhc_no']);
	}


	$sd = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_GET['start_date'])));
	$ed = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_GET['end_date'])));

	if(!empty($owner) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `lhc` WHERE owner_name = '".$owner."' AND DATE(lhc_date) >= '".$sd."' AND DATE(lhc_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";
	}else if(!empty($owner_name)){
		$lr = "SELECT * FROM `lhc` WHERE owner_name = '".$owner."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";

	}else if(!empty($agent) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `lhc` WHERE agent = '".$agent."' AND DATE(lhc_date) >= '".$sd."' AND DATE(lhc_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";

	}else if(!empty($agent)){
		$lr = "SELECT * FROM `lhc` WHERE agent = '".$agent."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";

	}else if(!empty($lhc_no) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `lhc` WHERE lhc_no = '".$lhc_no."' AND DATE(lhc_date) >= '".$sd."' AND DATE(lhc_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";
	}else if(!empty($lhc_no)){
		$lr = "SELECT * FROM `lhc` WHERE lhc_no = '".$lhc_no."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";
	}else if(!empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `lhc` WHERE DATE(lhc_date) >= '".$sd."' AND DATE(lhc_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";
	}else{
		$lr = "SELECT * FROM `lhc` WHERE DATE(lhc_date) >= '".$sd."' AND DATE(lhc_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";
	}

	$result 		= mysqli_query($conn,$lr);
	$total       	= mysqli_num_rows($result);

	$master_accounts       = combine(getAllRecords('vendor_master'), 'id', 'name');
	$master_accounts       = combine(getAllRecords('truck_mst'), 'id', 'o_name');
	$master_company    	   = combine(getAllRecords('company_mst'), 'id', 'name');

	

	$output= '';
	$output.= '<html>
	<table style="width: 100%" cellpadding="1">
		<thead>
			<tr style="border: 0.1pt solid black;">
				<td style="text-align:center;font-size:15px;"><strong>'.@$master_company[$_SESSION['company_id']].'</strong></td>
			</tr>
			<tr style="border: 0.1pt solid black;text-align:center;">
				<td style="text-align:center;margin-bottom:10px;">TDS PAYABLE <strong>START FROM</strong> : '.$_GET['start_date'].' <strong>TO</strong> :  '.$_GET['end_date'].'</td>
			</tr>

		</thead>
		<tbody>
		    <tr style="border: 0.1pt solid black;">
				<td width="10%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>LHC NO</strong></td>
				<td width="10%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>LHC DATE</strong></td>
				<td width="35%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>AGENT</strong></td>
				<td width="15%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>AGENT PANCARD</strong></td>
				<td width="15%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>LORRY HIRE CHARGES</strong></td>
		      	<td width="15%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>TDS AMOUNT</strong></td>
			</tr>
			';
			
					$table       	= '';
					$total_count    = 0;
					if(count($total) > 0) {
						$total_add 		= 0;
						$total_sub 		= 0;
						$lorry_hire     = 0;
						$disel    		= 0;
						$adv     		= 0;
						$balance     	= 0;
						$bank     		= 0;
						$cash    	   	= 0;
						$total_add 		= 0;
						$total_sub 		= 0;
					while ($row = mysqli_fetch_array($result)) {
							$add      = "SELECT SUM(amount) AS total_add FROM lhc_details WHERE type = 'add' AND lhc_id = '".$row['lhc_no']."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_id";
							$add_res  = mysqli_query($conn,$add);
							$add_row  = mysqli_fetch_assoc($add_res);
							
							$sub      = "SELECT SUM(amount) AS total_sub FROM lhc_details WHERE type = 'sub' AND lhc_id = '".$row['lhc_no']."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_id";
							$sub_res  = mysqli_query($conn,$sub);
							$sub_row  = mysqli_fetch_assoc($sub_res);

							$truck 			= "SELECT * FROM truck_mst WHERE id = '".$row['owner_name']."'";
							$truck_res 		= mysqli_query($conn,$truck);
							$truck_row 		= mysqli_fetch_assoc($truck_res);

							$agent 			= "SELECT * FROM agent WHERE name = '".$row['agent']."'";
							$agent_res 		= mysqli_query($conn,$agent);
							$agent_row 		= mysqli_fetch_assoc($agent_res);

							$total_add 		+= $add_row['total_add'];
							$total_sub 		+= $sub_row['total_sub'];
							$lorry_hire     += $row['lorry_hire'];
							$disel    		+= $row['disel_amnt'];
							$adv     		+= $row['adv_amnt'];
							$balance     	+= $row['balance'];
							$bank     		+= $row['pay_mode_amnt'];
							$cash    	   	+= $row['cash'];
							$remove_alies = substr($row["lhc_no"], 4);
					    	$new_bill_no   = ltrim($remove_alies, "0");
					$output.='<tr style="border: 0.1pt solid black;">
						<td width="10%" align="center" style="text-align: center;border-bottom:1px solid black">'.$new_bill_no.'</td>
						<td width="10%" align="center" style="text-align: center;border-bottom:1px solid black">'.risFormatDate($row["lhc_date"]).'</td>
						<td width="35%" align="center" style="text-align: center;border-bottom:1px solid black">'. $row['agent'] . '</td>
						<td width="15%" align="center" style="text-align: center;border-bottom:1px solid black">'.$agent_row['pan_no'].'</td>
						<td width="15%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($row['lorry_hire']).'</td>
						<td width="15%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($sub_row['total_sub']).'</td>
			    	</tr>
			    	';
			    	
				}
				$output.='
			    	<tr>
			    		<td colspan="4" style="border-top:1px solid black;border-bottom:1px solid black"><b>TOTAL</b></td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($lorry_hire) . '</td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($total_sub) . '</td>
			    	</tr>';
			}
		$output.='
		</tbody>
	</table>
	</html>';
	$title = 'LHC REGISTER';
	$fname = 'lhc_register.pdf';
}elseif ($_GET['module'] == 'LHCPENREG') {
	if(isset($_GET['owner']) && !empty($_GET['owner'])) {
	$owner = strtoupper($_GET['owner']);
	}


	if(isset($_GET['agent']) && !empty($_GET['agent'])) {
		$agent = strtoupper($_GET['agent']);
	}

	if(isset($_GET['type']) && !empty($_GET['type'])) {
		$type = strtoupper($_GET['type']);
	}


	$sd = $_GET['start_date'];
	$ed = $_GET['end_date'];

	if($sd =='' || $ed =='' || $_GET['type'] =='' || $_GET['agent'] =='' || $_GET['owner'] ==''){
		$lr = "SELECT * FROM `lhc` WHERE balance > 0 AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";
	}

	if( !empty($sd) && !empty($ed)) {
		$sd = date('Y-m-d', strtotime($sd));
		$ed = date('Y-m-d', strtotime($ed));
		$lr = "SELECT * FROM `lhc` WHERE DATE(lhc_date) >= '".$sd."' AND DATE(lhc_date) <= '".$ed."' AND balance > 0 AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";
	}

	if( !empty($agent) ) {
		$lr = "SELECT * FROM `lhc` WHERE agent = '".$agent."' AND payment_to = 'AGENT' AND balance > 0 AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";
	}

	if( !empty($owner) ) {
		$lr = "SELECT * FROM `lhc` WHERE owner_name = '".$owner."' AND payment_to = 'OWNER' AND balance > 0 AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";
	}

	if( !empty($type) ) {
		$lr = "SELECT * FROM `lhc` WHERE payment_to = '".$type."' AND balance > 0 AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";
	}

	$result 		= mysqli_query($conn,$lr);
	$total       	= mysqli_num_rows($result);

	$master_accounts       = combine(getAllRecords('vendor_master'), 'id', 'name');
	$master_accounts       = combine(getAllRecords('truck_mst'), 'id', 'o_name');
	$master_company    	   = combine(getAllRecords('company_mst'), 'id', 'name');

	

	$output= '';
	$output.= '<html>
	<table style="width: 100%" cellpadding="1">
		<thead>
			<tr style="border: 0.1pt solid black;">
				<td style="text-align:center;font-size:15px;"><strong>'.@$master_company[$_SESSION['company_id']].'</strong></td>
			</tr>
			<tr style="border: 0.1pt solid black;text-align:center;">
				<td style="text-align:center;margin-bottom:10px;">PENDING LHC REGISTER <strong>START FROM</strong> : '.$_GET['start_date'].' <strong>TO</strong> :  '.$_GET['end_date'].'</td>
			</tr>

		</thead>
		<tbody>
		    <tr style="border: 0.1pt solid black;">
				<td width="6%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>LHC NO</strong></td>
				<td width="7%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>LHC DATE</strong></td>
				<td width="7%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>TRUCK NO</strong></td>
				<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>FROM - TO</strong></td>
				<td width="10%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>OWNER</strong></td>
				<td width="6%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>AGENT</strong></td>
				<td width="6%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>LORRY HIRE CHARGES</strong></td>
		      	<td width="6%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>TOTAL ADDITION</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>DISEL</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>TOTAL DEDUCTION</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>ADVANCE</strong></td>
		      	<td width="7%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>BANK</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>CASH</strong></td>
		      	<td width="8%" align="center" style="text-align: center;border-top:1pt solid black;border-bottom:1pt solid black"><strong>BALANCE</strong></td>
			</tr>
			';
			
					$table       	= '';
					$total_count    = 0;
					if(count($total) > 0) {
						$total_add 		= 0;
						$total_sub 		= 0;
						$lorry_hire     = 0;
						$disel    		= 0;
						$adv     		= 0;
						$balance     	= 0;
						$bank     		= 0;
						$cash    	   	= 0;
						$total_add 		= 0;
						$total_sub 		= 0;

						while ($row = mysqli_fetch_array($result)) {
							$add      = "SELECT SUM(amount) AS total_add FROM lhc_details WHERE type = 'add' AND lhc_id = '".$row['lhc_no']."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_id";
							$add_res  = mysqli_query($conn,$add);
							$add_row  = mysqli_fetch_assoc($add_res);
							
							$sub      = "SELECT SUM(amount) AS total_sub FROM lhc_details WHERE type = 'sub' AND lhc_id = '".$row['lhc_no']."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_id";
							$sub_res  = mysqli_query($conn,$sub);
							$sub_row  = mysqli_fetch_assoc($sub_res);

							$hit_lhc 		= "SELECT * FROM lhc WHERE lhc_no = '".$row['lhc_no']."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."'";
							$hit_lhc_res 	= mysqli_query($conn,$hit_lhc);
							$hit_lhc_row 	= mysqli_fetch_assoc($hit_lhc_res);
							

							if($hit_lhc_row['payment_to'] == 'AGENT'){
								$style  = "color:red";
								$button = "<a href='#' id='".$row["agent"]."' onclick='viewData(this);'>STATEMENT</a>";
							}else{
								$style = "";
								$button = '';
							}

							if($hit_lhc_row['payment_to'] == 'OWNER'){
								$styles = "color:green";
								$buttons = "<a href='#' id='".$row["owner_name"]."' onclick='viewDatas(this);'>STATEMENT</a>";
							}else{
								$styles = "";
								$buttons = '';
							}

							$total_add 		+= $add_row['total_add'];
							$total_sub 		+= $sub_row['total_sub'];
							$lorry_hire     += $row['lorry_hire'];
							$disel    		+= $row['disel_amnt'];
							$adv     		+= $row['adv_amnt'];
							$balance     	+= $row['balance'];
							$bank     		+= $row['pay_mode_amnt'];
							$cash    	   	+= $row['cash'];
							$remove_alies = substr($row["lhc_no"], 4);
					    	$new_bill_no   = ltrim($remove_alies, "0");
					$output.='<tr style="border: 0.1pt solid black;">
						<td width="6%" align="center" style="text-align: center;border-bottom:1px solid black">'.$new_bill_no.'</td>
						<td width="7%" align="center" style="text-align: center;border-bottom:1px solid black">'.risFormatDate($row["lhc_date"]).'</td>
						<td width="7%" align="center" style="text-align: center;border-bottom:1px solid black">'.$row['truck_no'].'</td>
						<td width="8%" style="text-align: center;border-bottom:1px solid black">'. $row['from_place'] . '-'. $row['to_place'] .'</td>
						<td width="10%" align="center" style="text-align: center;border-bottom:1px solid black">' . @$master_accounts[$row['owner_name']] . '</td>
						<td width="6%" align="center" style="text-align: center;border-bottom:1px solid black">' . $row['agent'] . '</td>
						<td width="6%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($row['lorry_hire']).'</td>
						<td width="6%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($add_row['total_add']).'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($row['disel_amnt']).'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($sub_row['total_sub']).'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($row['adv_amnt']).'</td>
						<td width="7%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($row['pay_mode_amnt']).'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($row['cash']).'</td>
						<td width="8%" align="center" style="text-align: center;border-bottom:1px solid black">'.customFormatMoney($row['balance']).'</td>
			    	</tr>
			    	';
			    	
				}
				$output.='
			    	<tr>
			    		<td colspan="6" style="border-top:1px solid black;border-bottom:1px solid black"><b>TOTAL</b></td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($lorry_hire) . '</td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($total_add) . '</td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($disel) . '</td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($total_sub) . '</td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($adv) . '</td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($bank) . '</td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($cash) . '</td>
			    		<td style="border-top:1px solid black;border-bottom:1px solid black" align="center">' . customFormatMoney($balance) . '</td>
			    	</tr>';
			}
		$output.='
		</tbody>
	</table>
	</html>';
	$title = 'PENDING LHC REGISTER';
	$fname = 'pending_lhc_register.pdf';
}else if($_GET['module'] == 'PLFBP'){

	$sd = $_GET['start_date'];
	$ed = $_GET['end_date'];
	$p1 = $_GET['p1'];

	if( !empty($sd) && !empty($ed) && $p1 != '') {
		$sd = date('Y-m-d', strtotime($sd));
		$ed = date('Y-m-d', strtotime($ed));
		$lr = "SELECT * FROM `lhc` WHERE DATE(lhc_date) >= '".$sd."' AND DATE(lhc_date) <= '".$ed."' AND balance > 0 AND agent = '".$p1."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";
	}else{
		$sd = date('Y-m-d', strtotime($sd));
		$ed = date('Y-m-d', strtotime($ed));
		$lr = "SELECT * FROM `lhc` WHERE DATE(lhc_date) >= '".$sd."' AND DATE(lhc_date) <= '".$ed."' AND balance > 0 AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_no";
	}

	$result 		= mysqli_query($conn,$lr);
	$total       	= mysqli_num_rows($result);
	$master_vendor  = combine(getAllRecords('vendor_master'), 'id', 'name');
	$output       	= '';
	$master_accounts    = combine(getAllRecords('vendor_master'), 'id', 'name');
	$master_company     = combine(getAllRecords('company_mst'), 'id', 'name');
	$output= '';
	$output.= '<html>
	<table style="width: 100%" cellpadding="1">
		<thead>
			<tr style="border: 0.1pt solid black;">
				<td style="text-align:center;font-size:15px;"><strong>'.@$master_company[$_SESSION['company_id']].'</strong></td>
			</tr>
			<tr style="border: 0.1pt solid black;text-align:center;">
				<td style="text-align:center;border-bottom:1pt solid black;margin-bottom:10px;">PENDING LHC FOR BALANCE <strong>START FROM :</strong> '.$_GET['start_date'].' <strong>TO DATE</strong> :  '.$_GET['end_date'].'</td>
			</tr>

		</thead>
		<tbody>
		    <tr>
				<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;"><strong>LHC NO</strong></td>
				<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;"><strong>DATE</strong></td>
				<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;"><strong>LR NO</strong></td>
				<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;"><strong>TRUCK NO</strong></td>
				<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;"><strong>FROM <br/> TO</strong></td>
				<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;"><strong>CONSIGNOR <br/> CONSIGNEE</strong></td>
				<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;"><strong>TO.AMOUNT</strong></td>
		      	<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;"><strong>ADVANCE</strong></td>
		      	<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;"><strong>ADDITION</strong></td>
		      	<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;"><strong>DEDUCTION</strong></td>
		      	<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;"><strong>P.AMOUNT</strong></td>
			</tr>
			';
			$total_count    = 0;
			if(count($total) > 0) {
				$total_amount  = 0;
				$total_advance = 0;
				$total_balance = 0;
				$total_add = 0;
				$total_sub = 0;

		    	while ($row = mysqli_fetch_array($result)) {
            		$sub      = "SELECT SUM(amount) AS total_sub FROM lhc_details WHERE type = 'sub' AND lhc_id = '".$row['lhc_no']."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_id";
            		$sub_res  = mysqli_query($conn,$sub);
					$sub_row  = mysqli_fetch_assoc($sub_res);

					$add      = "SELECT SUM(amount) AS total_add FROM lhc_details WHERE type = 'add' AND lhc_id = '".$row['lhc_no']."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY lhc_id";
					$add_res  = mysqli_query($conn,$add);
					$add_row  = mysqli_fetch_assoc($add_res);

		    		$remove_lhc_alies = substr($row['lhc_no'], 4);
					$new_lhc_no       = ltrim($remove_lhc_alies, "0"); 
					
					$remove_lr_alies = substr($row['lr_no'], 4);
					$new_lr_no       = ltrim($remove_lr_alies, "0");

					$lr     = mysqli_query($conn,"SELECT * FROM `lr_mst` WHERE `lr_no` = '".$row['lr_no']."'");
					$lr_row = mysqli_fetch_assoc($lr);

					$total_amount  += $row['net_amnt'];
					$total_advance += ($row['adv_amnt']);
					$total_add += $add_row['total_add'];
					$total_sub += $sub_row['total_sub'];
					$total_balance += $row['balance'];

					$output.='<tr>
						<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;">'.$new_lhc_no.'</td>
						<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;">'.risFormatDate($row["lhc_date"]).'</td>
						<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;">' . $new_lr_no . '</td>
						<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;">' . $row['truck_no'] . '</td>
						<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;">' . $row['from_place'] . '<br/>'. $row['to_place'] .'</td>
						<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;">' . @$master_vendor[$lr_row['consignor_name']] . '<br/>'.@$master_vendor[$lr_row['consignee_name']].'<br/> <span style="color:red">'. @$master_vendor[$lr_row['consignor_name']].'</span></td>
						<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;">' . customFormatMoney($row['net_amnt']) . '</td>

				      	<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;">' . customFormatMoney($row['adv_amnt']) . '</td>

				      	<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;">' . customFormatMoney($add_row['total_add']) . '</td>
				      	<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;">' . customFormatMoney($sub_row['total_sub']) . '</td>

				      	<td width="9%" align="center" style="text-align: center;border-bottom:1pt solid black;">' . customFormatMoney($row['balance']) . '</td>
					</tr>';
		    	}

		    	$output.='<tr>
						<td colspan="6" align="left" style="text-align: center;border-bottom:1pt solid black;"><strong>TOTAL</strong></td>

						<td align="center" style="text-align: center;border-bottom:1pt solid black;">' . customFormatMoney($total_amount) . '</td>
				      	<td align="center" style="text-align: center;border-bottom:1pt solid black;">' . customFormatMoney($total_advance) . '</td>
				      	<td align="center" style="text-align: center;border-bottom:1pt solid black;">' . customFormatMoney($total_add) . '</td>
				      	<td align="center" style="text-align: center;border-bottom:1pt solid black;">' . customFormatMoney($total_sub) . '</td>
				      	<td align="center" style="text-align: center;border-bottom:1pt solid black;">' . customFormatMoney($total_balance) . '</td>
				      	
					</tr>';
			}
		$output.='
		</tbody>
	</table>
	</html>';

	$title    = 'PENDING LHC FOR BALANCE';
	$pdf_name = 'PENDING_LHC_FOR_BALANCE.pdf';
}else{
    if(isset($_GET['vendor_id']) && !empty($_GET['vendor_id'])) {
	$vendor_id = strtoupper($_GET['vendor_id']);
	}
	if(isset($_GET['bill_no']) && !empty($_GET['bill_no'])) {
	$bill_no = strtoupper($_GET['bill_no']);
	}
	$sd = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_GET['start_date'])));
	$ed = mysqli_real_escape_string($conn, date('Y-m-d', strtotime($_GET['end_date'])));
	if(!empty($vendor_id) && !empty($bill_no) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `billing` WHERE vendor_id = '".$vendor_id."'  AND invoice_no = '".$bill_no."' AND DATE(bill_date) >= '".$sd."' AND DATE(bill_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY invoice_no";
	}else if(!empty($vendor_id) && !empty($sd) && !empty($ed)){
		$lr = "SELECT * FROM `billing` WHERE vendor_id = '".$vendor_id."' AND DATE(bill_date) >= '".$sd."' AND DATE(bill_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY invoice_no";
	}else if(!empty($vendor_id)){
		$lr = "SELECT * FROM `billing` WHERE vendor_id = '".$vendor_id."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY invoice_no";
	}else if(!empty($sd) && !empty($ed) && !empty($bill_no)){
		$lr = "SELECT * FROM `billing` WHERE DATE(bill_date) >= '".$sd."' AND DATE(bill_date) <= '".$ed."' AND invoice_no = '".$bill_no."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY invoice_no";
	}else{
		$lr = "SELECT * FROM `billing` WHERE DATE(bill_date) >= '".$sd."' AND DATE(bill_date) <= '".$ed."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY invoice_no";
	}
	$result = mysqli_query($conn,$lr);
	$data = array();
	while ($row = mysqli_fetch_array($result)) {
		$data[] = $row;
	}
	$total       	= mysqli_num_rows($result);
	$master_accounts= combine(getAllRecords('vendor_master'), 'id', 'name');
	$table       	= '';
	$total_count    = 0;
	$master_company     = combine(getAllRecords('company_mst'), 'id', 'name');
	$output= '';
	$output.= '
	<html>
	   <table style="width: 100%" cellpadding="1">
	      <thead>
	         <tr style="border: 0.1pt solid black;">
	            <td style="text-align:center;font-size:15px;"><strong>'.@$master_company[$_SESSION['company_id']].'</strong></td>
	         </tr>
	         <tr style="border: 0.1pt solid black;text-align:center;">
	            <td style="text-align:center;border-bottom:1pt solid black;margin-bottom:10px;">BILLING REGISTER <strong>START FROM</strong> : '.$_GET['start_date'].' <strong>TO</strong> :  '.$_GET['end_date'].'</td>
	         </tr>
	      </thead>
	      <tbody>
	         <tr style="border: 0.1pt solid black;">
	            <td width="10%" align="center" style="text-align: center;"><strong>LR NO</strong></td>
	            <td width="8%" align="center" style="text-align: center;"><strong>WEIGHT</strong></td>
	            <td width="8%" align="center" style="text-align: center;"><strong>RATE</strong></td>
	            <td width="10%" align="center" style="text-align: center;"><strong>AMOUNT</strong></td>
	            <td width="10%" align="center" style="text-align: center;"><strong>OTHER CHANRGES</strong></td>
	            <td width="15%" align="center" style="text-align: center;"><strong>GROSS AMOUNT</strong></td>
	            <td width="13%" align="center" style="text-align: center;"><strong>TOTAL ADD(+)</strong></td>
	            <td width="13%" align="center" style="text-align: center;"><strong>TOTAL DEDU(-)</strong></td>
	            <td width="15%" align="center" style="text-align: center;"><strong>NET AMOUNT</strong></td>
	         </tr>
	         ';
	         foreach ($data as $key => $data) {
	         	$add      = "SELECT SUM(amount) AS total_add FROM billing_details WHERE type = 'add' AND bill_no = '".$data['invoice_no']."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY bill_no";
				$add_res  = mysqli_query($conn,$add);
				$add_row  = mysqli_fetch_assoc($add_res);

				$sub      = "SELECT SUM(amount) AS total_sub FROM billing_details WHERE type = 'sub' AND bill_no = '".$data['invoice_no']."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."' GROUP BY bill_no";
				$sub_res  = mysqli_query($conn,$sub);
				$sub_row  = mysqli_fetch_assoc($sub_res);
				

				$total_add = $add_row['total_add'];
				$total_sub = $sub_row['total_sub'];

				$lr_data 	 		= "SELECT * FROM billing WHERE invoice_no = '".$data['invoice_no']."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."'";
				$lr_data_res 		= mysqli_query($conn,$lr_data);
				$lr_data_rowspan 	= mysqli_num_rows($lr_data_res);
				$lr_data 			= array();
				$lr_amnt 			= 0;
				$other   			= 0;
				$ga    	 			= 0;
				while ($lr_data_row = mysqli_fetch_array($lr_data_res)) {
					$lr_data[] = $lr_data_row;
					$lr_amnt   += $lr_data_row['lr_amount'];
					$other     += $lr_data_row['other_charges'];
					$ga    	   = $lr_data_row['gross_amt'];
				}
				
				$output.='<tr>
	            <td width="100%" align="center" style="text-align: center;border-bottom:1pt solid black;border-top:1pt solid black;background-color: #d8d9da;"><b>'.@$master_accounts[$data['vendor_id']].' - '.$data["invoice_no"].' - ('.risFormatDate($data["bill_date"]).')</b></td>
	            </tr>
	            ';

	            $lastColumnPrinted 	= false;
	            foreach ($lr_data as $key => $lr_datas){
	            	$remove_alies = substr($lr_datas['lr_no'], 4);
					$new_bill_no   = ltrim($remove_alies, "0");
	            	$output.='<tr style="border: 0.1pt solid black;">
	            		<td width="10%" align="center" style="text-align: center;border-bottom:1pt solid black;">' .$new_bill_no . '</td>
	            		<td width="8%" align="center" style="text-align: center;border-bottom:1pt solid black;">' . $lr_datas['lr_weight'] . '</td>
	            		<td width="8%" align="center" style="text-align: center;border-bottom:1pt solid black;">' . $lr_datas['lr_rate'] . '</td>
	            		<td width="10%" align="center" style="text-align: center;border-bottom:1pt solid black;">' . $lr_datas['lr_amount'] . '</td>
	            		<td width="10%" align="center" style="text-align: center;border-bottom:1pt solid black;">' . $lr_datas['other_charges'] . '</td>
	            		<td width="13%" align="center" style="text-align: center;border-bottom:1pt solid black;">' . $data['gross_amt'] . '</td>
	            		<td width="13%" align="center" style="text-align: center;border-bottom:1pt solid black;">' .  $add_row['total_add'] . '</td>
	            		<td width="13%" align="center" style="text-align: center;border-bottom:1pt solid black;">' . $sub_row['total_sub'] . '</td>
	            		<td width="15%" align="center" style="text-align: center;border-bottom:1pt solid black;">' . $data['net_amt'] . '</td>
	            	</tr>';
	            }
                }
	         $output.='
	      </tbody>
	   </table>
	</html>';
	$title = 'BILLING REGISTER';
	$fname = 'billing_register.pdf';
}
$pdf->AddPage();
$pdf->setPageOrientation('L');
$pdf->SetAutoPageBreak(TRUE, 0);
$pdf->SetFont('helvetica', '', 8, '', true);
$pdf->writeHTML($output, true, false, false, false, '');
$pdf->SetTitle($title);
$pdf->IncludeJS("print();");
$pdf->Output($fname);
?>