<?php
	include "db_connection/db_connection.php";
	include "config/config.php";
	
	if($_SESSION['admin_login_id'] == '')
	{
		echo "<script>window.location='index.php';</script>";
	}
?>
<!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>

<link href="css/styles.css" rel="stylesheet" type="text/css" />
<!--[if IE]> <link href="css/ie.css" rel="stylesheet" type="text/css"> <![endif]-->

<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>

<!-- 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</a></li>                    
            </ul>
        </div>
	<?php include "menus/top_left_menu.php"; ?>            
        
    </div>
    
    <!-- Main content -->
    <div class="wrapper">
    
       <?php /*?> <ul class="middleNavR">
            <!--<li><a href="#" title="Add an article" class="tipN"><img src="images/icons/middlenav/create.png" alt="" /></a></li>
            <li><a href="#" title="Upload files" class="tipN"><img src="images/icons/middlenav/upload.png" alt="" /></a></li>-->  
          <li><a href="acc_add.php" title="Add Accounts" class="tipN"><img src="images/icons/middlenav/add.png" alt="" /></a></li>
            <!--<li><a href="#" title="Messages" class="tipN"><img src="images/icons/middlenav/dialogs.png" alt="" /></a><strong>8</strong></li>
            <li><a href="#" title="Check statistics" class="tipN"><img src="images/icons/middlenav/stats.png" alt="" /></a></li>-->
    	</ul>      <?php */?>      
    	 <?php
			$pag_id = base64_decode(base64_decode(base64_decode(base64_decode($_GET['page_id'])))); 
		?>
    	<!-- Chart --><!-- 6 + 6 -->

    	<div class="widget"> <!--style="width:600px; margin-left:150px;"-->
        <div class="whead"><h6><?php if($pag_id==1){ echo "Balance"; }else if($pag_id==2){ echo "Advance";}?> List</h6><div class="clear"></div></div>
        <div id="dyn" class="hiddenpars">
        	<a class="tOptions" title="Options"><img src="images/icons/options.png" alt="" /></a>
            <table cellpadding="0" cellspacing="0" border="0" class="dTable" id="dynamic">
            <thead>
            <tr>
            <th width="26">S.No<span class="sorting" style="display: block;"></span></th>
            <th width="85">Party Code</th>
            <th width="258">Party Name</th>
            <th width="108">Total Bill Amount</th>
            <th width="109">Total received Amount</th>
			<th width="107">Total Roundoff </th>
			<th width="140"><?php if($pag_id==1){ echo "Total Pending Amount"; }else if($pag_id==2){ echo "Total Advance Amount";}?></th>
            <th width="51">View</th>
            </tr>
            </thead>
            <tbody>
            <?php
			$page_id= base64_encode(base64_encode(base64_encode(2))); //THIS IS FOR PAGE IDENTIFICATION IN BL FILE for active inactive
			$tot_bill_amt_viw= 0;
			$tot_rec_amt_viw= 0;
			$tot_dis_amt_viw= 0;
			$tot_pen_amt_viw= 0;			
			$tot_cr_amt_viw= 0;	
			$SLCT = "SELECT * FROM ac_party_det WHERE comp_status ='no' ORDER BY party_det_id ASC";
			//echo $SLCT;
			$QURY = mysqli_query($connect,$SLCT);
			$loop=1;
			if(mysqli_num_rows($QURY)>0)
			{			
				while($FTCH = mysqli_fetch_object($QURY))
				{	
					list($tot_bil_amt,$tot_re_amt,$tot_adv_amt,$tot_pen_amt,$tot_dis_amt) = total_acc_call($FTCH->party_det_id);
					
					$pa_id	=	base64_encode(base64_encode(base64_encode($FTCH->party_det_id)));									
					$SLCT_E = "SELECT * FROM party_det WHERE party_det_id = '$FTCH->party_det_id'"; 
					$QURY_E = mysqli_query($connect,$SLCT_E);
					$FTCH_E = mysqli_fetch_object($QURY_E);
					
					$tot_bill_amt_viw = $tot_bill_amt_viw+$tot_bil_amt;
					$tot_rec_amt_viw = $tot_rec_amt_viw+$tot_re_amt;				
					$tot_cr_amt_viw = $tot_cr_amt_viw+$tot_adv_amt;			
					$tot_pen_amt_viw =$tot_pen_amt_viw+$tot_pen_amt;
					$tot_dis_amt_viw =$tot_dis_amt_viw+$tot_dis_amt;	
					
					if($loop%2 != "0")
						$bg = "gradeX";
					else
						$bg = "class='gradeC'";
					if($pag_id==1)
					{
						if($tot_pen_amt!=0)
						{
			?>
                            <tr <?php echo $bg ?>>
                                <td align="center"><?php echo $loop ?></td>
                                <td align="center"><a href="bl/balance_temp_BL.php?party_id=<?php echo $pa_id;?>&bal_amt=<?php echo base64_encode(base64_encode(base64_encode(base64_encode($tot_pen_amt))));?>"><?php echo $FTCH_E->party_code; ?></a></td>
                                <td align="center"><?php echo $FTCH_E->cmp_name; ?></td>
                                <td align="center"><?php echo number_format($tot_bil_amt,2); ?></td>
                                <td align="center"><?php echo number_format($tot_re_amt,2); ?></td>
                                <td align="center"><?php echo number_format($tot_dis_amt,2); ?></td>
                                <td align="center"><a href="bl/balance_BL.php?party_id=<?php echo $pa_id;?>&bal_amt=<?php echo base64_encode(base64_encode(base64_encode(base64_encode($tot_pen_amt))));?>"><?php echo number_format($tot_pen_amt,2); ?></a></td>
                            	<td class="center" align="center"><a href="acc_report.php?pa_id=<?php echo $pa_id ?>" target="_blank" class="an_own">View</a></td>
                            </tr>            
			<?php
							$loop ++;
						}
					}
					else if($pag_id==2)
					{
						if($tot_adv_amt!=0)
						{
			?>
                            <tr <?php echo $bg ?>>
                                <td align="center"><?php echo $loop ?></td>
                                <td align="center"><?php echo $FTCH_E->party_code; ?></td>
                                <td align="center"><?php echo $FTCH_E->cmp_name; ?></td>
                                <td align="center"><?php echo number_format($tot_bil_amt,2); ?></td>
                                <td align="center"><?php echo number_format($tot_re_amt,2); ?></td>
                                <td align="center"><?php echo number_format($tot_dis_amt,2); ?></td>
                                <td align="center"><?php echo number_format($tot_adv_amt,2); ?></td>
                                <td class="center" align="center"><a href="acc_report.php?pa_id=<?php echo $pa_id ?>" target="_blank" class="an_own">View</a></td>
                            </tr>            
			<?php
							$loop ++;
						}
					}
	
				 }
			 ?>
                <tr <?php echo $bg ?>>
                    <td align="center">&nbsp;</td>
                    <td align="center">&nbsp;</td>
                    <td align="center"><strong>Total</strong> </td>
                    <td align="center"><strong><?php echo ""; ?></strong></td>
                    <td align="center"><strong><?php echo ""; ?></strong></td>
                    <td align="center"><strong><?php echo ""; ?></strong></td>
                    <td align="center"><strong><?php if($pag_id==1){ echo number_format($tot_pen_amt_viw,2); } else if($pag_id==2) { echo number_format($tot_cr_amt_viw,2); } ?></strong></td>
                    <td class="center" align="center">&nbsp;</td>
                </tr>
			<?php
            }
            ?>
            </tbody>
            </table> 
        </div>
        </div> 
        <div class="fluid"><!-- Media table --></div>
    </div>
    <!-- Main content ends -->
    
</div>
<!-- Content ends -->
<?php /*?><?php include "header_footer/footer.php"; ?><?php */?>
</body>
</html>
