<?php
	include "db_connection/db_connection.php";
	include "config/config.php";
	
	if($_SESSION['admin_login_id'] == '')
	{
		echo "<script>window.location='index.php';</script>";
	}
	else // THIS IS FOR GETTING PARTY DET ID ROM LOAGIN DET AND PARTY DET TABLE
	{
		$admin_id = $_SESSION['admin_login_id'];
		$SLCT_log = "SELECT * FROM login_details,ac_party_det WHERE ac_party_det.party_det_id = login_details.party_det_id AND login_details.admin_id = '$admin_id'";
		$QURY_log = mysqli_query($connect,$SLCT_log);
		$FTCH_log = mysqli_fetch_object($QURY_log);
		$party_id = '$FTCH_log->party_det_id';
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
		<title><?php echo $PROJECT_TITLE ?></title>
		<script type="text/javascript" src="js/acc_analize_JS.js"></script>
		<link href="css/styles.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
		<script type="text/javascript" src="js/plugins/forms/ui.spinner.js"></script>
		<script type="text/javascript" src="js/plugins/forms/jquery.mousewheel.js"></script> 
		<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
		<script type="text/javascript" src="js/plugins/charts/excanvas.min.js"></script>
		<script type="text/javascript" src="js/plugins/charts/jquery.flot.js"></script>
		<script type="text/javascript" src="js/plugins/charts/jquery.flot.orderBars.js"></script>
		<script type="text/javascript" src="js/plugins/charts/jquery.flot.pie.js"></script>
		<script type="text/javascript" src="js/plugins/charts/jquery.flot.resize.js"></script>
		<script type="text/javascript" src="js/plugins/charts/jquery.sparkline.min.js"></script>
		<script type="text/javascript" src="js/plugins/tables/jquery.dataTables.js"></script>
		<script type="text/javascript" src="js/plugins/tables/jquery.sortable.js"></script>
		<script type="text/javascript" src="js/plugins/tables/jquery.resizable.js"></script>
		<script type="text/javascript" src="js/plugins/forms/autogrowtextarea.js"></script>
		<script type="text/javascript" src="js/plugins/forms/jquery.uniform.js"></script>
		<script type="text/javascript" src="js/plugins/forms/jquery.inputlimiter.min.js"></script>
		<script type="text/javascript" src="js/plugins/forms/jquery.tagsinput.min.js"></script>
		<script type="text/javascript" src="js/plugins/forms/jquery.maskedinput.min.js"></script>
		<script type="text/javascript" src="js/plugins/forms/jquery.autotab.js"></script>
		<script type="text/javascript" src="js/plugins/forms/jquery.chosen.min.js"></script>
		<script type="text/javascript" src="js/plugins/forms/jquery.dualListBox.js"></script>
		<script type="text/javascript" src="js/plugins/forms/jquery.cleditor.js"></script>
		<script type="text/javascript" src="js/plugins/forms/jquery.ibutton.js"></script>
		<script type="text/javascript" src="js/plugins/forms/jquery.validationEngine-en.js"></script>
		<script type="text/javascript" src="js/plugins/forms/jquery.validationEngine.js"></script>
		<script type="text/javascript" src="js/plugins/uploader/plupload.js"></script>
		<script type="text/javascript" src="js/plugins/uploader/plupload.html4.js"></script>
		<script type="text/javascript" src="js/plugins/uploader/plupload.html5.js"></script>
		<script type="text/javascript" src="js/plugins/uploader/jquery.plupload.queue.js"></script>
		<script type="text/javascript" src="js/plugins/wizards/jquery.form.wizard.js"></script>
		<script type="text/javascript" src="js/plugins/wizards/jquery.validate.js"></script>
		<script type="text/javascript" src="js/plugins/wizards/jquery.form.js"></script>
		<script type="text/javascript" src="js/plugins/ui/jquery.collapsible.min.js"></script>
		<script type="text/javascript" src="js/plugins/ui/jquery.breadcrumbs.js"></script>
		<script type="text/javascript" src="js/plugins/ui/jquery.tipsy.js"></script>
		<script type="text/javascript" src="js/plugins/ui/jquery.progress.js"></script>
		<script type="text/javascript" src="js/plugins/ui/jquery.timeentry.min.js"></script>
		<script type="text/javascript" src="js/plugins/ui/jquery.colorpicker.js"></script>
		<script type="text/javascript" src="js/plugins/ui/jquery.jgrowl.js"></script>
		<script type="text/javascript" src="js/plugins/ui/jquery.fancybox.js"></script>
		<script type="text/javascript" src="js/plugins/ui/jquery.fileTree.js"></script>
		<script type="text/javascript" src="js/plugins/ui/jquery.sourcerer.js"></script>
		<script type="text/javascript" src="js/plugins/others/jquery.fullcalendar.js"></script>
		<script type="text/javascript" src="js/plugins/others/jquery.elfinder.js"></script>
		<script type="text/javascript" src="js/plugins/ui/jquery.easytabs.min.js"></script>
		<script type="text/javascript" src="js/files/bootstrap.js"></script>
		<script type="text/javascript" src="js/files/functions.js"></script>
		<script type="text/javascript" src="js/charts/chart.js"></script>
		<script type="text/javascript" src="js/charts/hBar_side.js"></script>
		<!-- Shared on MafiaShare.net  --><!-- Shared on MafiaShare.net  -->
		
	</head>
	<body onload="tot_count()">
		<!-- Top line begins -->
		<?php include "header_footer/header.php"; ?>
		<!-- Top line ends -->
		<!-- Sidebar begins -->
		<?php include "menus/left_menu.php"; ?>
		<!-- Sidebar ends -->
		<!-- Content begins -->
		<div id="content">    
			<?php include "menus/top_menu.php"; ?>    
    		<!-- Breadcrumbs line -->
    		<div class="breadLine">
		        <div class="bc">
		            <ul id="breadcrumbs" class="breadcrumbs">
		                <li><a href="#">Dashboard</a></li>
		                <li><a href="javascript:">Accounts Analyze</a></li>
		                    
		            </ul>
		        </div>
				<?php include "menus/top_left_menu.php"; ?>    
    		</div>
    		<!-- Main content -->
    		<div class="wrapper">    
			<?php
			   	$flag = 0;
			   	$sta_iden = '0';
			   	// THIS IS FOR CHECKING THE STAGE NAME
				if(isset($_GET['sta_name']) && $_GET['sta_name']!='' ) 
				{
					$mas_stage_id 	= 	$_GET['sta_name'];
					$mas_stage_id1	=	base64_decode(base64_decode(base64_decode(base64_decode($_GET['sta_name'])))); // this is for getting the value from url				
				}
				else
				{
					$mas_stage_id = '';
					$mas_stage_id1 = '';
				}
				if(isset($_GET['mnthyr']) && $_GET['mnthyr']!='')
				{ 				
					$mnthyr = explode("-",base64_decode(base64_decode(base64_decode(base64_decode($_GET['mnthyr'])))));
					$mn_no = $mnthyr[0];
					$mn_nm = $mnthyr[1];
					$yr_nm = $mnthyr[2];
					$dat_rslt = "01-".$mn_no."-".$yr_nm; 
				}
				else
				{
					$mn_no = '';
					$mn_nm = '';
					$yr_nm = '';
					$dat_rslt = '';
				}
				if(isset($_GET['fdate']) && $_GET['fdate']!='' ){ $fdate = $_GET['fdate'];	}else{ $fdate = ''; }
				if(isset($_GET['todate']) && $_GET['todate']!='' ){ $todate = $_GET['todate'];	}else{ $todate = ''; }				
				if(isset($_GET['yea_r']) && $_GET['yea_r']!='' ){ $yea_r = 'checked="checked"'; $y_r = $_GET['yea_r'];}else{ $yea_r = ''; $y_r = '';}
				if(isset($_GET['mont_h']) && $_GET['mont_h']!='' ){ $mont_h = 'checked="checked"'; $m_h = $_GET['mont_h'];}else{ $mont_h = ''; $m_h = ''; }
				if(isset($_GET['da_y']) && $_GET['da_y']!='' ){ $da_y = 'checked="checked"'; $d_y = $_GET['da_y'];}else{ $da_y = ''; $d_y = ''; }				
			?>    
	        	<ul class="middleNavR"></ul>            
	    		<form id="acc_dat" name="acc_dat" class="main" method="post" action="acc_report.php" target="_blank">		
	            	<fieldset>
	    				<div class="widget">
                			<div class="formRow" >
				                <table width="100%">
				                    <tr>
				                        <td width="25%" style="display:table-cell; vertical-align:top;">Select Stage:</td>
				                        <td width="75%">
				                            <div class="searchDrop">
				                             <select  data-placeholder="" class="select" name="sta_name" id="sta_name" style="width:350px;" onchange="reload_page()" onfocus="foc(this.id)" onblur="stnon(this.id)" disabled="">
				                                 <option selected="selected" value="">Choose a Stage...</option>
				                                 <option <?php if($mas_stage_id1 == '1'){ ?> selected="selected" <?php }?> value="<?php echo base64_encode(base64_encode(base64_encode(base64_encode('1')))); ?>">Billing</option>
				                                 <option <?php if($mas_stage_id1 == '2'){ ?> selected="selected" <?php }?> value="<?php echo base64_encode(base64_encode(base64_encode(base64_encode('2')))); ?>">Collection</option>
				                            </select>
				                            </div> 
				                        </td>
				                    </tr>
				                </table>
				          	</div>
				          	<div class="formRow" >
								<table width="100%">
									<tr>
										<td width="25%" style="display:table-cell; vertical-align:top;">Report For:</td>
				                        <td width="65%"><?php echo $mn_nm." - ".$yr_nm; ?></td>
				                        <td width="15%"><a class="buttonM bRed" href="acc_analize.php?sta_name=<?php echo $mas_stage_id; ?>&fdate=<?php echo $_GET['fdate'] ?>&todate=<?php echo $_GET['todate'] ?>&yea_r=<?php echo $_GET['yea_r'] ?>&mont_h=<?php echo $_GET['mont_h'] ?>&da_y=<?php echo $_GET['da_y'] ?>">Back</a></td>
						  			</tr>
								</table>
							</div>
                        	<div class="clear"></div>
                    	</div> 
                    	<?php if(isset($_GET['fdate']) && $_GET['fdate']!='' || isset($_GET['todate']) && $_GET['todate']!=''){ ?>	
	                    	<input type="hidden" value="<?php echo $_GET['fdate']; ?>" name="std" id="std" />
							<input type="hidden" value="<?php echo $_GET['todate']; ?>" name="edd" id="edd" />
							<input type="hidden" value="<?php echo $_GET['yea_r']; ?>" name="yr" id="yr" />
							<input type="hidden" value="<?php echo $_GET['mont_h']; ?>" name="mnt" id="mnt" />
							<input type="hidden" value="<?php echo $_GET['da_y']; ?>" name="dty" id="dty" />
							<input type="hidden" value="<?php echo $_GET['todate']; ?>" name="edd" id="edd" />
							<input type="hidden" value="" name="par_id" id="par_id" />
							<?php
								$billing_date = "billing_det.bill_date"; 
								$collect_date = "AC.received_date"; 
								$dat_str_bill = ''; //THIS IS FOR QUERY STRING
								$dat_str_coll = '';	//THIS IS FOR QUERY STRING	
								$dat_str_bill = "WHERE DATE_FORMAT(STR_TO_DATE(".$billing_date.",'%d-%m-%Y'),'%m-%Y') = DATE_FORMAT(STR_TO_DATE('$dat_rslt','%d-%m-%Y'),'%m-%Y')";  
								$dat_str_coll = "WHERE DATE_FORMAT(STR_TO_DATE(".$collect_date.",'%d-%m-%Y'),'%m-%Y') = DATE_FORMAT(STR_TO_DATE('$dat_rslt','%d-%m-%Y'),'%m-%Y')";  

								/*if($fdate!='' && $todate!='')
								{
									$dat_str_bill = "WHERE STR_TO_DATE(".$billing_date.",'%d-%m-%Y') BETWEEN STR_TO_DATE('$fdate','%d/%m/%Y') AND STR_TO_DATE('$todate','%d/%m/%Y')"; 
									$dat_str_coll = "WHERE STR_TO_DATE(".$collect_date.",'%d-%m-%Y') BETWEEN STR_TO_DATE('$fdate','%d/%m/%Y') AND STR_TO_DATE('$todate','%d/%m/%Y')"; 
									$flgg=1;				
								}
								else if($fdate=='' && $todate!='')
								{
									if($yea_r!='' && $mont_h!='' && $da_y!='')
									{ 
										$dat_str_bill = "WHERE STR_TO_DATE(".$billing_date.",'%d-%m-%Y') = STR_TO_DATE('$todate','%d/%m/%Y')"; 
										$dat_str_coll = "WHERE STR_TO_DATE(".$collect_date.",'%d-%m-%Y') = STR_TO_DATE('$todate','%d/%m/%Y')";
										$flgg = 1;				
									}									
									else if($yea_r!='' && $mont_h!='' && $da_y=='')
									{
										$vl = explode("/",$todate);
										$todat_vl = $vl[2]."-".$vl[1]."-".$vl[0];
									 	$dat_str_bill = "WHERE DATE_FORMAT(STR_TO_DATE(".$billing_date.",'%d-%m-%Y'),'%m-%Y') = DATE_FORMAT(STR_TO_DATE('$todate','%d/%m/%Y'),'%m-%Y')";  
										$dat_str_coll = "WHERE DATE_FORMAT(STR_TO_DATE(".$collect_date.",'%d-%m-%Y'),'%m-%Y') = DATE_FORMAT(STR_TO_DATE('$todate','%d/%m/%Y'),'%m-%Y')";  
										$flgg = 1;					
									}									
									else if($yea_r!='' && $mont_h=='' && $da_y=='')
									{ 
										$vl = explode("/",$todate);
										$todat_vl = ($vl[2]-1)."-12-31";
										$dat_str_bill = "WHERE YEAR(STR_TO_DATE(".$billing_date.",'%d-%m-%Y')) = YEAR(STR_TO_DATE('$todate','%d/%m/%Y'))"; 				
										$dat_str_coll = "WHERE YEAR(STR_TO_DATE(".$collect_date.",'%d-%m-%Y')) = YEAR(STR_TO_DATE('$todate','%d/%m/%Y'))"; 				
										$flgg = 1;
									}									
									else if($yea_r=='' && $mont_h=='' && $da_y=='')
									{ 
										$dat_str_bill = "WHERE STR_TO_DATE(".$billing_date.",'%d-%m-%Y') <= STR_TO_DATE('$todate','%d/%m/%Y')"; 				
										$dat_str_coll = "WHERE STR_TO_DATE(".$collect_date.",'%d-%m-%Y') <= STR_TO_DATE('$todate','%d/%m/%Y')";
										
										$flgg = 0;
									}									
									else if($yea_r=='' && $mont_h!='' && $da_y=='')
									{ 
										$vl = explode("/",$todate);
										$todat_vl = $vl[2]."-".$vl[1]."-".$vl[0];
										$dat_str_bill = "WHERE DATE_FORMAT(STR_TO_DATE(".$billing_date.",'%d-%m-%Y'),'%m-%Y') = DATE_FORMAT(STR_TO_DATE('$todate','%d/%m/%Y'),'%m-%Y')";  
										$dat_str_coll = "WHERE DATE_FORMAT(STR_TO_DATE(".$collect_date.",'%d-%m-%Y'),'%m-%Y') = DATE_FORMAT(STR_TO_DATE('$todate','%d/%m/%Y'),'%m-%Y')";  
										$flgg = 1;
									}									
									else if($yea_r=='' && $mont_h=='' && $da_y!='')
									{ 
										$dat_str_bill = "WHERE STR_TO_DATE(".$billing_date.",'%d-%m-%Y') = STR_TO_DATE('$todate','%d/%m/%Y')"; 
										$dat_str_coll = "WHERE STR_TO_DATE(".$collect_date.",'%d-%m-%Y') = STR_TO_DATE('$todate','%d/%m/%Y')"; 				
										$flgg = 1;
									}									
									else if($yea_r!='' && $mont_h=='' && $da_y!='')
									{ 
										$dat_str_bill = "WHERE STR_TO_DATE(".$billing_date.",'%d-%m-%Y') = STR_TO_DATE('$todate','%d/%m/%Y')"; 
										$dat_str_coll = "WHERE STR_TO_DATE(".$collect_date.",'%d-%m-%Y') = STR_TO_DATE('$todate','%d/%m/%Y')"; 					
										$flgg = 1;
									}									
									else if($yea_r=='' && $mont_h!='' && $da_y!='')
									{ 
										$dat_str_bill = "WHERE STR_TO_DATE(".$billing_date.",'%d-%m-%Y') = STR_TO_DATE('$todate','%d/%m/%Y')"; 				
										$dat_str_coll = "WHERE STR_TO_DATE(".$collect_date.",'%d-%m-%Y') = STR_TO_DATE('$todate','%d/%m/%Y')"; 					
										$flgg = 1;
									}
								}*/			
							?>		
							<?php 
								if($mas_stage_id1 == '1') // THIS IS FOR BILLING CONDITION
								{ 
									$bil_tit1 = 'Total Net Amt';
									$bil_tit2 = 'Total Tax Amt';
									$bil_tit3 = 'Total Courier Amt';
									$bil_tit4 = 'Total Round Off';
									$bil_tit5 = 'Total Bill Amt';
									$prnt_flg = 2; // THIS IS PRINT SCREEN FLAGG VALUE FOR BILLING MONTH VIEW 
								}
								else if($mas_stage_id1 == '2') // THIS IS FOR COLLECTION CONDITION
								{ 
									$bil_tit1 = 'Total Advance Amt';
									$bil_tit2 = 'Total Cash Amt';
									$bil_tit3 = 'Total Cheque Amt';
									$bil_tit4 = 'Total NEFT Amt';
									$bil_tit5 = 'Total Colletion';
									$prnt_flg = 2; // THIS IS PRINT SCREEN FLAGG VALUE FOR COLLECTION MONTH VIEW
								}
							?>
	    					<div class="widget" style="display: block">
	        					<div class="whead">
	        						<ul class="titleToolbar">
							            <li><h6 style=" margin-right:0px; text-align:center;"><?php echo $bil_tit1; ?> <br /><input class="dataNumGrey" type="text" id="stot_bl" name="tot_bl" value="" readonly="readonly" disabled="disabled" style="width:80px; font-size:12px; text-align:right" /></h6></li>
							            <li><h6 style=" margin-right:0px; text-align:center;"><?php echo $bil_tit2; ?> <br /><input class="dataNumGrey" type="text" id="stot_rec" name="stot_rec" value="" readonly="readonly" disabled="disabled" style="width:80px; font-size:12px; text-align:right" /></h6></li>
							            <li><h6 style=" margin-right:0px; text-align:center;"><?php echo $bil_tit3; ?> <br /><input class="dataNumGrey" type="text" id="stot_dis" name="stot_dis" value="" readonly="readonly" disabled="disabled" style="width:80px; font-size:12px; text-align:right" /></h6></li>
							            <li><h6 style=" margin-right:0px; text-align:center;"><?php echo $bil_tit4; ?> <br /><input class="dataNumGrey" type="text" id="stot_pe" name="stot_pe" value="" readonly="readonly" disabled="disabled" style="width:80px; font-size:12px; text-align:right" /></h6></li>
							            <li><h6 style=" margin-right:0px; text-align:center;"><?php echo $bil_tit5; ?> <br /><input class="dataNumGrey" type="text" id="stot_adv" name="stot_adv" value="" readonly="readonly" disabled="disabled" style="width:80px; font-size:12px; text-align:right" /></h6></li>
							            <li><h6 style=" margin-right:0px; text-align:center;"><a href="export_sales_report.php?fdate=<?php echo $_GET['fdate'] ?>&todate=<?php echo $_GET['todate'] ?>&yea_r=<?php echo $_GET['yea_r'] ?>&mont_h=<?php echo $_GET['mont_h'] ?>&da_y=<?php echo $_GET['da_y'] ?>" >Export</a></h6></li>
							            <li><h6 style=" margin-right:42px; text-align:center;"><a href="acc_analize_print.php?sta_name=<?php echo $mas_stage_id; ?>&fdate=<?php echo $_GET['fdate'] ?>&todate=<?php echo $_GET['todate'] ?>&yea_r=<?php echo $_GET['yea_r'] ?>&mont_h=<?php echo $_GET['mont_h'] ?>&da_y=<?php echo $_GET['da_y'] ?>&mnthyr=<?php echo $_GET['mnthyr']; ?>&flg=<?php echo base64_encode(base64_encode(base64_encode(base64_encode($prnt_flg)))); ?>" target="_blank">Print</a></h6></li>
							        </ul>
									<div class="clear"></div>
								</div>
	        					<div id="dyn" class="hiddenpars">
	        						<a href="javascript:0" id="searchlink" onfocus="foc(this.id)" onblur="stnon(this.id)" class="tOptions" title="Options"><img src="images/icons/options.png" alt="" /></a>
	            					<table width="677" border="0" cellpadding="0" cellspacing="0" class="dTable" id="dynamic">
	            						<thead>
	            							<tr>
	<?php 
		if($mas_stage_id1 == '1') // THIS IS FOR BILLING CONDITION
		{ 
	?>
		<th width="6%">S.No<span class="sorting" style="display: block;"></span></th>
		<th width="24%" style="text-align:left;">Party Code/ Name</th>
		<th width="13%">Bill No</th> 
		<th width="9%">Bill Date</th>
		<th width="12%" style="text-align:right;">Bill Amt</th>
		<th width="8%">Tax Amt</th>
		<th width="8%">Courier</th>
		<th width="7%">Round off</th>
		<th width="12%" style="text-align:right;">Total Amt</th>
		<?php 
			} 
			else if($mas_stage_id1 == '2') // THIS IS FOR COLLECTION CONDITION
			{ 
		?>
			<th width="10%">S.No<span class="sorting" style="display: block;"></span></th>
			<th width="30%" style="text-align:left;">Party Code/Name</th>
			<th width="10%">Payment Dt</th>
			<th width="10%">Advance</th> 
			<th width="10%">Cash</th>
			<th width="10%">Cheque</th>
			<th width="10%">NEFT</th>
			<th width="10%" style="text-align:right;">Total Amt</th>
			<?php } ?>
											</tr>
	            						</thead>
	            						<tbody>  
										<?php 
											$tot_net_amt = 0;
											$tot_tax_amt = 0;
											$tot_cor_amt = 0;
											$tot_rnd_amt = 0;
											$tot_bil_amt = 0;
											if($mas_stage_id1 == '1') // THIS IS FOR BILLING CONDITION
											{ 	
													$SLCT = "SELECT bill_no,bill_type,party_det_id,bill_date,bill_amt,bill_tot_tax_amt,round_off,courier_amt FROM `billing_det` ".$dat_str_bill." ORDER BY STR_TO_DATE(bill_date,'%d-%m-%Y') ASC,bill_no ASC,`party_det_id` ASC ";
													$QURY = mysqli_query($connect,$SLCT);
													$loop=1;
													if(mysqli_num_rows($QURY)>0)
													{			
														while($FTCH = mysqli_fetch_object($QURY))
														{
															$pa_id = $FTCH->party_det_id;
															
															$SLCT_PT = "SELECT party_code, cmp_name FROM party_det WHERE party_det_id = '$pa_id'";
															$QURY_PT = mysqli_query($connect,$SLCT_PT);
																		$FTCH_PT = mysqli_fetch_object($QURY_PT);

		$SLCT_part = "SELECT cmp_name FROM party_det_log WHERE party_det_id = '$pa_id' AND STR_TO_DATE(REPLACE('$FTCH->bill_date','/','-'),'%d-%m-%Y') BETWEEN STR_TO_DATE(`active_date`,'%Y-%m-%d') AND STR_TO_DATE(`inactive_date`,'%Y-%m-%d')";
			$QURY_part = mysqli_query($connect,$SLCT_part);
			if(mysqli_num_rows($QURY_part)>0){
				$FTCH_part = mysqli_fetch_object($QURY_part);
				$cmp_name  = $FTCH_part->cmp_name;
			} else {
				$cmp_name  = $FTCH_PT->cmp_name;
			}
				$rnd_off = str_replace(array( '(', ')' ), '', $FTCH->round_off);
//echo $rnd_off;
				if($rnd_off!='')
				{
					$bl_amt = $FTCH->bill_amt-($FTCH->bill_tot_tax_amt+$rnd_off)-$FTCH->courier_amt;
					$rnd_lbl = $FTCH->round_off;
				}
					else if($rnd_off=='')
															{
																$bl_amt = $FTCH->bill_amt - $FTCH->bill_tot_tax_amt - $FTCH->courier_amt;
																$rnd_lbl = "0.00";				
															}
											?>
		<tr>
			<td align="left" style="display:table-cell;vertical-align:middle"><?php echo $loop; ?></td> 
			<td align="left" style="display:table-cell;vertical-align:middle"><?php 
			//echo $FTCH_PT->party_code." / ".$cmp_name; 
			
				$name_count = strlen($cmp_name);
				$name='';
				if($name_count>14){
					$name = substr($cmp_name,0,14)."...";
				} else {
					$name = $cmp_name;
				} ?>
			<?php if($name_count>14){?>
			<div class="tooltip1">
			<?php echo $FTCH_PT->party_code." / ".$name;?>
				<span class="tooltiptext1"><?php echo $cmp_name;?></span>
			</div>
			<?php } else { ?>
			<?php echo $FTCH_PT->party_code." / ".$cmp_name;?>
			<?php } ?>
			</td> 
			<td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH->bill_no; ?></td> 
			<td align="left" style="display:table-cell;vertical-align:middle"><?php echo str_replace("-", "/", $FTCH->bill_date); ?></td> 
			<td align="right" style="display:table-cell;vertical-align:middle"><?php echo number_format($bl_amt,2); ?></td> 
			<td align="right" style="display:table-cell;vertical-align:middle"><?php echo number_format($FTCH->bill_tot_tax_amt,2); ?></td>
			<td align="right" style="display:table-cell;vertical-align:middle"><?php echo number_format($FTCH->courier_amt,2); ?></td> 
			<td align="right" style="display:table-cell;vertical-align:middle"><?php echo $rnd_lbl; ?></td> 
			<td align="right" style="display:table-cell;vertical-align:middle"><?php echo number_format($FTCH->bill_amt,2); ?></td>  
		</tr>
											<?php 
															$tot_net_amt = $tot_net_amt + $bl_amt;
															$tot_tax_amt = $tot_tax_amt + $FTCH->bill_tot_tax_amt;
															$tot_cor_amt = $tot_cor_amt + $FTCH->courier_amt;
															$tot_rnd_amt = $tot_rnd_amt + $rnd_off;
															$tot_bil_amt = $tot_bil_amt + $FTCH->bill_amt;
															$loop++;
														}
													}
												} 
else if($mas_stage_id1 == '2') // THIS IS FOR COLLECTION CONDITION
{ 
$SLCT = "SELECT AC.`ac_party_det_id`, AC.`received_date`, IFNULL(AC1.`received_amt`,'0') AS advance, IFNULL(AC2.`received_amt`,'0') AS cash, IFNULL(AC3.`received_amt`,'0') AS cheque, IFNULL(AC4.`received_amt`,'0') AS neft,(IFNULL(AC1.`received_amt`,'0')+IFNULL(AC2.`received_amt`,'0')+IFNULL(AC3.`received_amt`,'0')+IFNULL(AC4.`received_amt`,'0')) AS tot_amt
	FROM `ac_received_det` AS AC
	LEFT JOIN ac_received_det AC1 ON AC.ac_received_det_id=AC1.ac_received_det_id AND AC1.`payment_type`='Bill'
	LEFT JOIN ac_received_det AC2 ON AC.ac_received_det_id=AC2.ac_received_det_id AND AC2.`payment_type`='cash'
	LEFT JOIN ac_received_det AC3 ON AC.ac_received_det_id=AC3.ac_received_det_id AND AC3.`payment_type`='cheque'
LEFT JOIN ac_received_det AC4 ON AC.ac_received_det_id=AC4.ac_received_det_id AND AC4.`payment_type`='neft' ".$dat_str_coll." ORDER BY STR_TO_DATE(AC.`received_date`,'%d-%m-%Y') ASC";
													$QURY = mysqli_query($connect,$SLCT);
													$loop=1;
													if(mysqli_num_rows($QURY)>0)
													{			
														while($FTCH = mysqli_fetch_object($QURY))
														{				
															$SLCT_E = "SELECT party_det.party_det_id,party_det.party_code,party_det.cmp_name FROM ac_party_det,party_det WHERE party_det.party_det_id = ac_party_det.party_det_id AND ac_party_det.ac_party_det_id = '$FTCH->ac_party_det_id'"; 
															$QURY_E = mysqli_query($connect,$SLCT_E);
															$FTCH_E = mysqli_fetch_object($QURY_E);

															$SLCT_part = "SELECT cmp_name FROM party_det_log WHERE party_det_id = '$FTCH_E->party_det_id' AND STR_TO_DATE(REPLACE('$FTCH->received_date','/','-'),'%d-%m-%Y') BETWEEN STR_TO_DATE(`active_date`,'%Y-%m-%d') AND STR_TO_DATE(`inactive_date`,'%Y-%m-%d')";
															$QURY_part = mysqli_query($connect,$SLCT_part);
															if(mysqli_num_rows($QURY_part)>0)
															{
																$FTCH_part = mysqli_fetch_object($QURY_part);
																$cmp_name  = $FTCH_part->cmp_name;
															}
															else
															{
																$cmp_name  = $FTCH_E->cmp_name;
															}
											?>
															<tr>
																<td align="center" style="display:table-cell;vertical-align:middle"><?php echo $loop; ?></td> 
																<td align="left" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_E->party_code." / ".$cmp_name; ?></td>  
																<td align="center" style="display:table-cell;vertical-align:middle"><?php echo str_replace("-", "/", $FTCH->received_date); ?></td> 
																<td align="center" style="display:table-cell;vertical-align:middle"><?php echo number_format($FTCH->advance,2); ?></td> 
																<td align="center" style="display:table-cell;vertical-align:middle"><?php echo number_format($FTCH->cash,2); ?></td> 
																<td align="center" style="display:table-cell;vertical-align:middle"><?php echo number_format($FTCH->cheque,2); ?></td> 
																<td align="center" style="display:table-cell;vertical-align:middle"><?php echo number_format($FTCH->neft,2); ?></td> 
																<td align="center" style="display:table-cell;vertical-align:middle"><?php echo number_format($FTCH->tot_amt,2); ?></td> 
															</tr>
											<?php 
															$tot_net_amt = $tot_net_amt + $FTCH->advance;
															$tot_tax_amt = $tot_tax_amt + $FTCH->cash;
															$tot_cor_amt = $tot_cor_amt + $FTCH->cheque;
															$tot_rnd_amt = $tot_rnd_amt + $FTCH->neft;
															$tot_bil_amt = $tot_bil_amt + $FTCH->tot_amt;
															$loop++;
														}
													}
												} 
											?>        
	            						</tbody>    
	            					</table> 
	        					</div>
	        				</div>
	        			<?php } ?>
	        			<input name="tot_net_amt" id="tot_net_amt" type="hidden" value="<?php echo number_format($tot_net_amt,2); ?>" />
						<input name="tot_tax_amt" id="tot_tax_amt" type="hidden" value="<?php echo number_format($tot_tax_amt,2); ?>" />	 
						<input name="tot_cor_amt" id="tot_cor_amt" type="hidden" value="<?php echo number_format($tot_cor_amt,2); ?>" />	 
						<input name="tot_rnd_amt" id="tot_rnd_amt" type="hidden" value="<?php echo number_format($tot_rnd_amt,2); ?>" />	
						<input name="tot_bil_amt" id="tot_bil_amt" type="hidden" value="<?php echo number_format($tot_bil_amt,2); ?>" /> 	 
        			</fieldset>
     			</form>
        		<div class="fluid"><!-- Media table --></div>       
    		</div>
    		<!-- Main content ends -->    
		</div>
		<!-- Content ends -->
	</body>
</html>
