<?php
	include "db_connection/db_connection.php";
	include "config/config.php";
	
	if($_SESSION['admin_login_id'] == '')
	{
		echo "<script>window.location='index.php';</script>";
	}
	
	$check_acc  = check_access('42');
?>
<!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_add_JS.js"></script>
<script type="text/javascript" src="js/cnt_chkbox_JS.js"></script>

<script type="text/javascript" src="js/toword.js"></script><!--var words = toWords(num);-->

<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.dataTables1.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="">

<!-- Top line begins -->
<?php include "header_footer/header.php"; ?>
<!-- Top line ends -->


<!-- Sidebar begins -->
<?php include "menus/left_menu.php"; ?>
<!-- Sidebar ends -->
 <?php

 ?>   
    
<!-- 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="home.php">Dashboard</a></li>
                <li><a href="javascript:">Collections</a></li>
                    
            </ul>
        </div>
	<?php include "menus/top_left_menu.php"; ?>            
        
    </div>
    
    <!-- Main content -->
    <div class="wrapper">
    <?php if($check_acc==1){?>
        <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="design_add.php" title="Add Design" 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="collection_list.php" title="List Collections" class="tipN"><img src="images/icons/middlenav/stats.png" alt="" /></a></li>
    	</ul>            
  		<?php
		
		
		
		if(isset($_GET['party_id']))
		{
			$party_url = $_GET['party_id'];
			$pa_id	=	base64_decode(base64_decode(base64_decode($_GET['party_id'])));                  
			
			$SLCT_ppo = "SELECT * FROM ac_party_det WHERE total_pending!=0 AND party_det_id = '$pa_id'";
			//echo $SLCT_ppo;
			$QURY_ppo = mysqli_query($connect,$SLCT_ppo);
			
		}
		else
		{
			$party_url = '';
			$pa_id	=	'';
		}
		
		?>

    	<!-- Chart --><!-- 6 + 6 -->
        <form id="validate" name="checklist" class="main" method="post" action="bl/acc_BL.php" onsubmit="checkTheBox();"><!--bl/billing_BL.php-->
         <fieldset>
        <div class="fluid">
		<div class="widget">
		<input type="hidden" id="pa_id" name="pa_id" value="<?php echo $pa_id; ?>"/>		
		<div class="formRow">
            <div class="grid2"><label>Party Code:<span class="req">*</span></label></div>
            <div class="grid4 searchDrop">
                <select data-placeholder="Choose Party Code..." class="select" name="co_cod" id="co_cod" onchange="reload_po_lst()" style="width:350px;" tabindex="2">
                    <option value=""></option>
                    <?php
					
                    $SLCT_E = "SELECT  * FROM party_det ORDER BY party_det_id ASC"; //HERE THE 1 IS REPRESENTS CAD DESIGNER ID 
                    //echo $SLCT;
                    $QURY_E = mysqli_query($connect,$SLCT_E);
                    while($FTCH_E = mysqli_fetch_object($QURY_E))
                    {
						
						$party_id= base64_encode(base64_encode(base64_encode($FTCH_E->party_det_id)));
                    ?>
                    <option <?php if($party_url == $party_id){ ?> selected="selected" <?php } ?> value="<?php echo $party_id ?>"><?php echo $FTCH_E->party_code." / ".$FTCH_E->cmp_name ;?></option>
                    <?php
					
                    }
                    ?>
                        
                </select>
            </div>			
			<?php /*?><input type="hidden" value="<?php echo $FTCH_Ep->cmp_name ?>" name="" id="" disabled="disabled" /><?php */?>
            <div class="clear"></div>
        </div>	
		
        <?php		
		if(isset($_GET['party_id']))
		{
			$party_url = $_GET['party_id'];
			$pa_id	=	base64_decode(base64_decode(base64_decode($_GET['party_id'])));  
			
			$SLCT_Ep = "SELECT * FROM party_det WHERE party_det_id = '$pa_id'"; 
			$QURY_Ep = mysqli_query($connect,$SLCT_Ep);
			$FTCH_Ep = mysqli_fetch_object($QURY_Ep);                
		?>
		
       <?php /*?> <div class="formRow">
            <div class="grid2"><label>Party Name:<span class="req">*</span></label></div>
            <div class="grid6"><input type="text" value="<?php echo $FTCH_Ep->cmp_name ?>" name="" id="" disabled="disabled" /></div><div class="clear"></div>
         </div><?php */?>
		
		 <div class="formRow">
            <div class="grid2"><label>Payment Date:<span class="req">*</span></label></div>
            <div class="grid6"><input type="text" value="" name="pod" id="pod" class="datepicker" /></div><div class="clear"></div>
         </div>
		 
		 <div class="formRow">
            <div class="grid2"><label>Payment Type:<span class="req">*</span></label></div>
            <div class="grid9"><label style="margin-right:30px;">
            <input type="radio" name="pay_tp" id="cash" value="cash" onclick="pay_type_hid(this.value,'<?php echo $_GET['party_id']?>')"/>
            Cash</label>
          
          <label style="margin-right:30px;">
            <input type="radio" name="pay_tp" id="cheque" value="cheque" onclick="pay_type_hid(this.value,'<?php echo $_GET['party_id']?>')"/>
            Cheque</label>
          
          <label style="margin-right:30px;">
            <input type="radio" name="pay_tp" id="neft" value="neft" onclick="pay_type_hid(this.value,'<?php echo $_GET['party_id']?>')"/>
            NEFT</label>
			
			</div><div class="clear"></div>
         </div>
        
		<input type="hidden" value="" name="chk_col_id" id="chk_col_id" />
		<input type="hidden" value="" name="rec" id="rec" />
		<div class="formRow" id="rece_div" style="border:solid 1px #999999; display:none">
            <div class="grid2"><label>Cash Receiver:<span class="req">*</span></label></div>
            <div class="grid4 searchDrop">
                <select data-placeholder="Choose Employee..." class="select" name="e_name" id="e_name" style="width:350px;" tabindex="2" >
                    <option value=""></option>
                    <?php
					$SLCT_Ep = "SELECT  * FROM emp_det WHERE key_person = 'yes' ORDER BY emp_det_id ASC"; 
                    //echo $SLCT;
                    $QURY_Ep = mysqli_query($connect,$SLCT_Ep);
                    while($FTCH_Ep = mysqli_fetch_object($QURY_Ep))
                    {						
                    ?>
                    <option value="<?php echo $FTCH_Ep->emp_det_id ?>"><?php echo $FTCH_Ep->name; ?></option>
                    <?php
					}                    
                    ?>                       
                </select>
            </div>
            <div class="clear"></div>
        </div>
		<?php
			$current_time = date('d-m-Y') ;
			$SLCT_chk_sel = "SELECT * FROM cheque_collection_list WHERE cheque_status = 'pending' AND reminder_status = 'waiting' AND party_det_id = ".$pa_id." AND STR_TO_DATE(collection_date,'%d-%m-%Y') <= STR_TO_DATE('".$current_time."','%d-%m-%Y') ORDER BY cheque_collection_list_id ASC"; 
	        $QURY_chk_sel = mysqli_query($connect,$SLCT_chk_sel);
	        $count_chk_sel = mysqli_num_rows($QURY_chk_sel);
        ?>
        <input type="hidden" value="<?php echo $count_chk_sel ?>" name="count_chk_sel" id="count_chk_sel" /> 
        <div style="border:solid 1px #999999; display:none;" id="cheq_det">		
		 <div class="formRow">
            <div class="grid2"><label>Select Cheque:<span class="req">*</span></label></div>
            <div class="grid4 searchDrop" id="search_emp">
                <select data-placeholder="Choose Cheque..." class="select" name="chk_sel" id="chk_sel" style="width:350px;" tabindex="2" onchange="cheque_select(this.value)" >
                    <option value=""></option>
                    <?php
					while($FTCH_chk_sel = mysqli_fetch_object($QURY_chk_sel))
                    {
                    	/*if($FTCH_Ep->emp_det_id == $chk_rec){
							$sel="selected";
						}else{
							$sel="";
						}*/						
                    ?>
                    <option value="<?php echo $FTCH_chk_sel->cheque_collection_list_id ?>" <?php //echo $sel;?>><?php echo $FTCH_chk_sel->bank_name." - ".$FTCH_chk_sel->cheque_no." - ".$FTCH_chk_sel->cheque_amount  ; ?></option>
                    <?php
					}
					                    
                    ?> 
                </select>
            </div>
			<div class="clear"></div>
		  </div>
		</div>
		<div style="border:solid 1px #999999; display:none;" id="cheq_div">		
		 <div class="formRow">
            			
			<div class="grid2"><label>Cash Receiver:<span class="req">*</span></label></div>
            <div class="grid4 searchDrop" id="search_emp">
                <select data-placeholder="Choose Employee..." class="select" name="chk_rec" id="chk_rec" style="width:350px;" tabindex="2" onchange="choose_emp(this.value)">
                    <option value=""></option>
                    <?php
					$SLCT_Ep = "SELECT  * FROM emp_det WHERE key_person = 'yes' ORDER BY emp_det_id ASC"; 
                    //echo $SLCT;
                    $QURY_Ep = mysqli_query($connect,$SLCT_Ep);
                    $count_chk_rec = mysqli_num_rows($QURY_Ep);
                    while($FTCH_Ep = mysqli_fetch_object($QURY_Ep))
                    {
                    	/*if($FTCH_Ep->emp_det_id == $chk_rec){
							$sel="selected";
						}else{
							$sel="";
						}*/						
                    ?>
                    <option value="<?php echo $FTCH_Ep->emp_det_id ?>" <?php //echo $sel;?>><?php echo $FTCH_Ep->name; ?></option>
                    <?php
					}
					                    
                    ?> 
                    <input type="hidden" value="<?php echo $count_chk_rec ?>" name="count_chk_rec" id="count_chk_rec" />          
                </select>
            </div>
			
			<div class="grid2"><label>Cheque No:<span class="req">*</span></label></div>
            <div class="grid4"><input type="text" value="" name="chq_no" id="chq_no" /></div>			
			<div class="clear"></div>
		</div>
		
		 <div class="formRow" >
            <div class="grid2"><label>Bank Name:<span class="req">*</span></label></div>
            <div class="grid4"><input type="text" value="" name="bn_name" id="bn_name" /></div>
			
			<div class="grid2"><label>Branch Name:<span class="req"></span></label></div>
            <div class="grid4"><input type="text" value="" name="bran_name" id="bran_name" /></div>
			
			<div class="clear"></div>
         </div>
         </div>
         <div class="formRow" id="bank_div" style="border:solid 1px #999999; display:none">
            <div class="grid2"><label>Deposit Type:<span class="req">*</span></label></div>
            <div class="grid4 searchDrop">
            	<select data-placeholder="Choose Deposit Type..." class="select" name="bn_name_ne" id="bn_name_ne" style="width:350px;">
                    <option value=""></option>
                    <option value="Cash">Cash</option>
                    <option value="NEFT">NEFT</option>                       
                </select>
            	<!--<input type="text" value="" name="bn_name_ne" id="bn_name_ne" />-->
         	</div>
            <div class="clear"></div>
         </div>
		 
		 <?php
		 	list($test_bil_amt,$test_re_amt,$test_adv_amt,$test_pen_amt,$test_dis_amt) = total_acc_call($pa_id);
			//echo $test_adv_amt."<br>";
			//echo $test_pen_amt."<br>";
			
		  if($test_adv_amt>=0 && $test_pen_amt==0){  ?>
		 <div class="formRow">
            <div class="grid2"><label>Advance Payment:<span class="req">*</span></label></div>
            <div class="grid6"><input type="text" value="" name="ad_amt" onkeypress="return inputOnlyNumbers(event)" id="ad_amt" onkeyup="amt_calc_clr()" disabled="disabled" style="width:150px;"/></div>
			
			<div class="clear"></div>
         </div>
		 <?php } ?> 
		 
		 <?php $flg_vr = 0; if($test_pen_amt!=0){ $flg_vr = 1;?>
		 
		 <div class="formRow">
            <div class="grid2"><label>Bill Payment:<span class="req">*</span></label></div>
            <div class="grid6"><input type="text" value="" onkeypress="return inputOnlyNumbers(event)" name="amt" id="amt" onkeyup="amt_calc_clr(this.id)" disabled="disabled" style="width:150px;" autocomplete="off"/></div>
			<input type="button" value="Assign" class="buttonM bBlack formSubmit" id="amt_bt" onclick="amt_calc(1);" style="margin-left:20px; display:none"/>
			<div class="clear"></div>
         </div>
		 
		  <div class="formRow" id="dis_div" style="display:none">
            <div class="grid2"><label>Roundoff:<span class="req"></span></label></div>
            <div class="grid6"><input type="text" value="" name="disc_amt" id="disc_amt" onkeypress="return inputOnlyNumbers(event)" onkeyup="amt_calc(2);" style="width:150px;" disabled="disabled"/></div>
			<input type="button" value="Assign" class="buttonM bBlack formSubmit" id="disc_amt_bt" onclick="amt_calc(2);" style="margin-left:20px;display:none"/>
			<div class="clear"></div>
         </div>		 
		
		<?php } ?> 
		<input type="hidden" name="check_fl" id="check_fl" value="<?php echo $flg_vr; ?>" />
		
		<?php
            $loop = 1;		
            $SLCT = "SELECT * FROM acc_rep_temp WHERE party_det_id = '$pa_id' ORDER BY STR_TO_DATE(entry_date,'%d-%m-%Y') ASC";
			//echo $SLCT;
            $QURY = mysqli_query($connect,$SLCT);	
            if(mysqli_num_rows($QURY)>0)
            {
                $open_amt = 0;
                $tot_bil_amt = 0;
                $tot_rec_amt = 0;
                $tot_dis_amt = 0;	
                while($FTCH = mysqli_fetch_object($QURY))
                {
                    if($FTCH->data_type=="billing")
                    {
                        $SLCT_tpb = "SELECT * FROM billing_det WHERE billing_det_id = '$FTCH->billing_det_id'";
                        $QURY_tpb = mysqli_query($connect,$SLCT_tpb);
                        $FTCH_tpb = mysqli_fetch_object($QURY_tpb);

                        $bill_amt	= number_format($FTCH_tpb->bill_amt,2);
                        $received_amt  = '';
                        $dis_amt  = '';
                        $tot_bil_amt = $tot_bil_amt + $FTCH_tpb->bill_amt;
                    }
                    else
                    {
                        $bill_amt	= '';
                        
                        $SLCT_t = "SELECT * FROM ac_received_det WHERE ac_received_det_id = '$FTCH->ac_received_det_id'";
                        $QURY_t = mysqli_query($connect,$SLCT_t);
                        $FTCH_t = mysqli_fetch_object($QURY_t);
                        
                        $re_am = ($FTCH_t->received_amt!=0)?$FTCH_t->received_amt:$FTCH_t->cred_amt;
                        
                        $tot_rec_amt = $tot_rec_amt + $re_am;
                        $tot_dis_amt = $tot_dis_amt + $FTCH_t->dis_amt;
                        
                        $received_amt  = number_format($re_am,2);
                        $dis_amt  = number_format($FTCH_t->dis_amt,2);
                    }
                }
                $tot_re_amt = $tot_rec_amt + $tot_dis_amt; 
                $pen = $tot_bil_amt - $tot_re_amt ; 
				if($pen<0)
                {
        ?>
                    <div class="widget"> <!--style="width:600px; margin-left:150px;"-->
                        <div class="whead"><h6>Advance Amount List</h6><h6 style="float:right;"></h6><div class="clear"></div></div>
                        <div style="max-height:700px; overflow-y:auto;">
                            <table cellpadding="0" cellspacing="0" width="100%" class="tDefault checkAll check">
                                <thead>
                                    <tr>            			
                                        <td width="26">S.No<span class="sorting" style="display: block;"></span></td>
                                        <td width="100">Total Billed Amount</td>
                                        <td width="100">Total Paid Amount</td>
                                        <td width="100">Advance Amount</td>
                                    </tr>
                                </thead>
                                <tbody>
        <?php
                                    if($loop%2 != "0")
                                        $bg = "gradeX";
                                    else
                                        $bg = "class='gradeC'";
        ?>
                                    <tr <?php echo $bg ?>>
                                        <td align="center"><?php echo $loop ?></td>
                                        <td align="center"><?php echo number_format($tot_bil_amt,2); ?></td> 
                                        <td align="center"><?php echo number_format($tot_rec_amt,2); ?></td>                                    
                                        <td align="center"><?php echo trim(number_format($pen,2),"-"); ?></td>                                    
                                    </tr>
                                    <input type="hidden" name="tot_rows" id="tot_rows" value="<?php echo $loop ?>" />
                                </tbody>
                            </table> 			
                        </div>
                    </div>  
        <?php
                }
				else if($pen>=0)
                {
        ?>              
                    <div class="widget"> <!--style="width:600px; margin-left:150px;"-->
                    	<div class="whead"><h6>Bill List</h6><h6 style="float:right;"></h6><div class="clear"></div></div>
                        	<div style="max-height:700px; overflow-y:auto;">
                        		<table cellpadding="0" cellspacing="0" width="100%" class="tDefault checkAll check">
                            		<thead>
                                		<tr>                                
                                    		<th width="26">S.No<span class="sorting" style="display: block;"></span></th>
                                    		<th width="85">Bill No</th>
                                            <th width="124">Bill Date</th>
                                            <th width="100">Bill Amt</th>
                                            <th width="92">Pending Amt</th>
                                            <th width="105">Collection</th>
                                            <th width="129">Bill Status</th>
                                		</tr>
                            		</thead>
                           			<tbody>
                                    <?php
                                        $flgif = 0;
										
                                        $SLCT = "SELECT * FROM ac_bills_det WHERE party_det_id='$pa_id' AND close_status='no' ORDER BY ac_bills_det_id ASC";
                                        //echo $SLCT;
                                        $QURY = mysqli_query($connect,$SLCT);
                                        $loop=1;
                                        $tot_bill_amt = 0;
                                        $tot_pen_amt = 0;
										$bill_tet_id = '';                                                
                                        if(mysqli_num_rows($QURY)>0)
                                        {			
                                            while($FTCH = mysqli_fetch_object($QURY))
                                            {  
												$tot_pen_amt = $tot_pen_amt + $FTCH->pending_amt;
                                                $tot_bill_amt = $tot_bill_amt + $FTCH->bill_amt ;
                                               	$SLCT_bl = "SELECT * FROM billing_det WHERE billing_det_id = '$FTCH->billing_det_id'";
                                                $QURY_bl = mysqli_query($connect,$SLCT_bl);
                                                $FTCH_bl = mysqli_fetch_object($QURY_bl);
												
												$bill_tet_id = $bill_tet_id.$FTCH->billing_det_id.",";
												if($FTCH->close_status == 'no')
                                                { 
                                                    $flgif = 1;
                                                    if($loop%2 != "0")
                                                        $bg = "gradeX";
                                                    else
                                                        $bg = "class='gradeC'";
                                    ?>
                                   
                                                    <tr <?php echo $bg ?>>
                                                        <td align="center"><?php echo $loop ?></td>
                                                        <td align="center"><?php echo $FTCH_bl->bill_no; ?><input type="hidden" name="bill_id[<?php echo $loop ?>]" id="bill_id<?php echo $loop ?>" value="<?php echo $FTCH->billing_det_id ?>" /></td>
                                                        <td align="center"><?php echo $FTCH_bl->bill_date; ?></td>
                                                        <td align="center"><?php echo number_format($FTCH->bill_amt,2); ?><input type="hidden" name="bill_amt[<?php echo $loop ?>]" id="bill_amt<?php echo $loop ?>" value="<?php echo $FTCH->bill_amt ?>" /></td>
                                                        <td align="center"><?php echo number_format($FTCH->pending_amt,2); ?><input type="hidden" name="pen_amt[<?php echo $loop ?>]" id="pen_amt<?php echo $loop ?>" value="<?php echo $FTCH->pending_amt ?>" /></td>
                                                        <td align="center"><span id="col_amt<?php echo $loop ?>">0.00</span><input type="hidden" name="cl_amt_vl[<?php echo $loop ?>]" id="cl_amt_vl<?php echo $loop ?>" value="<?php echo $loop ?>" /></td>
                                                        <td align="center"><span id="col_st<?php echo $loop ?>">Pending</span><input type="hidden" name="pen_sts[<?php echo $loop ?>]" id="pen_sts<?php echo $loop ?>" value="Pending" /></td>
                                                    </tr>
                                    
                                    <?php
                                                    $loop ++;
                                                }
                                            }
                                        }
										$bill_tet_id = rtrim($bill_tet_id,",");
										if($bill_tet_id!='')
										{
											$bii_qur = " AND billing_det_id NOT IN(".$bill_tet_id.")";
										}
										else
										{
											$bii_qur = "";
										}
										$SLCT_nb = "SELECT * FROM billing_det WHERE party_det_id='$pa_id' ".$bii_qur." ORDER BY billing_det_id ASC";
										$QURY_nb = mysqli_query($connect,$SLCT_nb);
										if(mysqli_num_rows($QURY_nb)>0)
										{			
											while($FTCH_nb = mysqli_fetch_object($QURY_nb))
											{	
												$SLCT_bl = "SELECT * FROM ac_bills_det WHERE billing_det_id='$FTCH_nb->billing_det_id'";
												//echo $SLCT_bl;
												$QURY_bl = mysqli_query($connect,$SLCT_bl);
												if(mysqli_num_rows($QURY_bl)>0)
												{}
												else
												{
													$flgif =1;
													$tot_bill_amt = $tot_bill_amt + $FTCH_nb->bill_amt ;
													$tot_pen_amt = $tot_pen_amt + $FTCH_nb->bill_amt;
									
													if($loop%2 != "0")
														$bg = "gradeX";
													else
														$bg = "class='gradeC'";
									?>
											
													<tr <?php echo $bg ?>>
														<td align="center"><?php echo $loop ?></td>
														<td align="center"><?php echo $FTCH_nb->bill_no; ?><input type="hidden" name="bill_id[<?php echo $loop ?>]" id="bill_id<?php echo $loop ?>" value="<?php echo $FTCH_nb->billing_det_id ?>" /></td>
														<td align="center"><?php echo $FTCH_nb->bill_date; ?></td>
														<td align="center"><?php echo number_format($FTCH_nb->bill_amt,2); ?><input type="hidden" name="bill_amt[<?php echo $loop ?>]" id="bill_amt<?php echo $loop ?>" value="<?php echo $FTCH_nb->bill_amt ?>" /></td>
														<td align="center"><?php echo number_format($FTCH_nb->bill_amt,2); ?><input type="hidden" name="pen_amt[<?php echo $loop ?>]" id="pen_amt<?php echo $loop ?>" value="<?php echo $FTCH_nb->bill_amt ?>" /></td>
														<td align="center"><span id="col_amt<?php echo $loop ?>">0.00</span><input type="hidden" name="cl_amt_vl[<?php echo $loop ?>]" id="cl_amt_vl<?php echo $loop ?>" value="" /></td>
														<td align="center"><span id="col_st<?php echo $loop ?>">Pending</span><input type="hidden" name="pen_sts[<?php echo $loop ?>]" id="pen_sts<?php echo $loop ?>" value="Pending" /></td>
													</tr>
								
									<?php
													$loop ++;
												}
											}
										}
										
										if($flgif==1)
										{ 
                            		?>
                                            <tr >
                                                <td align="center">&nbsp;</td>
                                                <td align="center">&nbsp;</td>
                                                <td align="center">&nbsp;</td>
                                                <td align="center">&nbsp;</td>
                                                <td align="center">&nbsp;</td>
                                                <td align="center">&nbsp;</td>
                                                <td align="center">&nbsp;</td>
                                            </tr>			
                                            <tr>
                                                <td colspan="3" align="center"><b>Total : </b></td>
                                                <td align="center"><?php echo number_format($tot_bill_amt,2); ?><input type="hidden" name="tot_bl_amt" id="tot_bl_amt" value="<?php echo $tot_bill_amt; ?>" /></td>
                                                <td align="center"><?php echo number_format($tot_pen_amt,2); ?><input type="hidden" name="tot_pen_amt" id="tot_pen_amt" value="<?php echo $tot_pen_amt; ?>" /></td>
                                                <td align="center"><span id="tot_col_amt">0.00</span><input type="hidden" name="tot_cl_amt" id="tot_cl_amt" value="" /></td>
                                                <td align="left"><strong>Balance Pending: <span id="bal_amt" style="float:right">0.00</span></strong><input type="hidden" name="bl_amt" id="bl_amt" value="" /></td>
                                            </tr>
                           			<?php 
                               			} 
                            		?>
                                        <tr >
                                            <td align="center">&nbsp;</td>
                                            <td align="center">&nbsp;</td>
                                            <td align="center">&nbsp;</td>
                                            <td align="center">&nbsp;</td>
                                            <td align="center">&nbsp;</td>
                                            <td align="center">&nbsp;</td>
                                            <td align="left">
                                                <span id="cred_bl_span" style="display:none"><strong>Advance Amount :</strong><span id="cred_bl" style="float:right">0.00</span></span>
                                                <input type="hidden" name="cre_bl_amt" id="cre_bl_amt" value="" />
                                            </td>
                                        </tr>
                         
								<?php
										if($flgif==0)
										{
                                ?>
                                        <tr>
                                            <td colspan="7" align="center" style="display:table-cell;vertical-align:middle;"><font color="#FF0000"><b>Sorry No Bill for this Party</b></font></td>
                                        </tr>
								<?php 
                                    	} 
                                ?>
                                <input type="hidden" name="tot_rows" id="tot_rows" value="<?php echo $loop ?>" />
									
                            </tbody>
                        </table> 
                    </div>
                    </div>  
                    <?php }?>
					<input type="hidden" name="pend_div" id="pend_div" value="<?php echo $pen ?>" />					
					<?php } ?>
                    <?php if(isset($_GET['party_id'])){ ?>
                    <div class="fluid" id="but_area">
                        <div class="widget">	        
                           <div class="formRow">
                                <input type="button" value="Submit" class="buttonM bBlack formSubmit" onclick="checkTheBox();" style="float: right; margin-left:20px;"/>
                                <input type="button" value="Reset" class="buttonM bRed" style="float: right; margin-left:20px;" onclick="clr_fm();"/>
                                <div class="clear"></div>
                            </div>
                            <div class="clear"></div>
                        </div>
                    </div>
    
       <?php } } ?>  
       
       
        </fieldset>
        </form>
        
        <div class="fluid"><!-- Media table --></div>
<?php } else {  echo ACCESS_MSG;} ?>

    </div>
    <!-- Main content ends -->
    
</div>
<!-- Content ends -->
<?php /*?><?php include "header_footer/footer.php"; ?><?php */?>
</body>
</html>
