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

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

<!-- 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="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">

        <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['acc_re_id']))
		{
			$pa_id = base64_decode(base64_decode(base64_decode($_GET['pa_id'])));
			
			$acc_re_id	=	base64_decode(base64_decode(base64_decode($_GET['acc_re_id'])));

			$SLCT = "SELECT * FROM ac_received_det WHERE ac_received_det_id = '$acc_re_id'";
			$QURY = mysqli_query($connect,$SLCT);
			$FTCH = mysqli_fetch_object($QURY);
			$crd_blns = $FTCH->cred_amt;

			$SLCT1 = "SELECT SUM(received_amt) AS re_amt FROM ac_bills_det WHERE ac_received_det_id = '$acc_re_id'";
			$QURY1 = mysqli_query($connect,$SLCT1);
			$FTCH1 = mysqli_fetch_object($QURY1);

		}
		else
		{
			$party_url = '';
		}
		
		?>

    	<!-- 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">
                <?php
					$SLCT_E = "SELECT * 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;
					}

                	echo $FTCH_E->party_code." - ".$cmp_name;
              	?>
            </div>
            <div class="clear"></div>
        </div>

		 <div class="formRow">
            <div class="grid2"><label>Payment Date:<span class="req">*</span></label></div>
            <div class="grid6"><?php echo str_replace("-", "/",$FTCH->received_date); ?></div><div class="clear"></div>
         </div>

		 <div class="formRow">
            <div class="grid2"><label>Payment Type:<span class="req">*</span></label></div>
            <div class="grid9"><?php if($FTCH->payment_type=='Bill'){ echo "ADVANCE";}else{ echo strtoupper($FTCH->payment_type); }?></div><div class="clear"></div>
         </div>

		<?php if($FTCH->payment_type=='cash'){  ?>

		<div class="formRow" id="rece_div" style="border:solid 1px #999999; ">
            <div class="grid2"><label>Cash Receiver:<span class="req">*</span></label></div>
            <div class="grid4 searchDrop">
                  <?php
					$SLCT_Ep = "SELECT * FROM emp_det WHERE emp_det_id = '$FTCH->emp_det_id'"; 

                    $QURY_Ep = mysqli_query($connect,$SLCT_Ep);
                    $FTCH_Ep = mysqli_fetch_object($QURY_Ep);
                    echo $FTCH_Ep->name;
                    ?>
            </div>
            <div class="clear"></div>
        </div>
		<?php } ?>

		<?php if($FTCH->payment_type=='cheque'){  ?>
		<div style="border:solid 1px #999999; " id="cheq_div">
		 <div class="formRow">

			<div class="grid2"><label>Cash Receiver:<span class="req">*</span></label></div>
            <div class="grid4 searchDrop">
              <?php
					$SLCT_Ep = "SELECT * FROM emp_det WHERE emp_det_id = '$FTCH->emp_det_id'"; 

                    $QURY_Ep = mysqli_query($connect,$SLCT_Ep);
                    $FTCH_Ep = mysqli_fetch_object($QURY_Ep);
                    echo $FTCH_Ep->name;
                    ?>
            </div>

			<div class="grid2"><label>Cheque No:<span class="req">*</span></label></div>
            <div class="grid4"><?php echo $FTCH->cheque_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"><?php echo $FTCH->bank_name;?></div>
			<div class="grid2"><label>Branch Name:<span class="req">*</span></label></div>
            <div class="grid4"><?php echo $FTCH->branch_name;?></div>
			<div class="clear"></div>
         </div>
		 </div>
		<?php } ?>
		<?php if($FTCH->payment_type=='neft'){  ?>
		 <div class="formRow" id="bank_div" style="border:solid 1px #999999; ">
            <div class="grid2"><label>Deposit Type:<span class="req">*</span></label></div>
            <div class="grid4"><?php echo $FTCH->bank_name;?></div><div class="clear"></div>
         </div>
		 <?php } ?>
		 <?php if($FTCH->cred_amt!='0'){  ?>
		 <div class="formRow">
            <div class="grid2"><label>Advance Payment:<span class="req">*</span></label></div>
            <div class="grid6"><?php echo number_format($FTCH->cred_amt,2);?></div>
			
			<div class="clear"></div>
         </div>
		<?php } ?>
		 
		 <div class="formRow">
            <div class="grid2"><label>	<?php if($FTCH1->re_amt > 0) { ?> Bill Payment<?php }else{ ?> Advance Payment <?php } ?>:<span class="req">*</span></label></div>
            <div class="grid6"><?php echo number_format($FTCH->received_amt,2);?></div>
			<div class="clear"></div>
         </div>
		  <?php if($FTCH->dis_amt!='0'){  ?>
		  <div class="formRow" id="dis_div" style="">
            <div class="grid2"><label>Roundoff:<span class="req"></span></label></div>
            <div class="grid6"><input type="text" value="<?php echo $FTCH->dis_amt;?>" 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; ?>" />
		</div>
	
	<?php if($FTCH1->re_amt > 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" align="center">S.No<span class="sorting" style="display: block;"></span></th>
            <th width="85" align="center">Bill No</th>
            <th width="124" align="center">Bill Date</th>
            <th width="100" align="right">Bill Amt</th>
            <th width="92" align="right">To Pay  Amt</th>
            <th width="105" align="right">Paid Amt </th>
			 <th width="92" align="right"> Pending Amt</th>
            <th width="129" align="center">Bill Status</th>

            <!--<th width="78">Image</th>-->
            </tr>
            </thead>
            <tbody>
            <?php

			$SLCT = "SELECT * FROM ac_bills_det WHERE ac_received_det_id = '$acc_re_id'";
			//echo $SLCT;
			$QURY = mysqli_query($connect,$SLCT);
			$loop=1;
			$tot_bill_amt = 0;
			$tot_pen_amt = 0;
			$tot_col_amt = 0;
			$tot_op_pen = 0;
			if(mysqli_num_rows($QURY)>0)
			{			
			while($FTCH = mysqli_fetch_object($QURY))
			{
				
				$tot_bill_amt = $tot_bill_amt + $FTCH->bill_amt ;
				$tot_pen_amt = $tot_pen_amt + $FTCH->pending_amt;
				$tot_col_amt = $tot_col_amt + $FTCH->received_amt;
				$op_pen_am = $FTCH->received_amt + $FTCH->pending_amt;
				$tot_op_pen =  $tot_op_pen + $op_pen_am;
				if($FTCH->pending_amt=='0'){ $stt = 'Closed'; $pen_amt = $FTCH->bill_amt; }else{ $stt = 'Pending'; $pen_amt = $FTCH->bill_amt-$FTCH->pending_amt; }
				//$po_id	=	base64_encode(base64_encode(base64_encode($FTCH->po_entry_id)));
				
				$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);
				
			
				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 str_replace("-", "/",$FTCH_bl->bill_date); ?></td>
            <td align="right"><?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="right"><span id="col_amt<?php echo $loop; ?>"><?php echo number_format($op_pen_am,2); ?></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="right"><?php echo number_format($FTCH->received_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="right"><?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_st<?php echo $loop ?>"><?php echo $stt; ?></span></td>
            </tr>

            <?php
			$loop ++;
			 }
			?>

			 <tr>
			   <td colspan="3" align="center">&nbsp;</td>
			   <td align="center">&nbsp;</td>
			   <td align="center">&nbsp;</td>
			   <td align="center">&nbsp;</td>
			   <td colspan="2" align="center">&nbsp;</td>
		      </tr>
			 <tr>
               <td colspan="3" align="right"><b>Total : </b></td>
               <td align="right"><?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="right"><?php echo number_format($tot_op_pen,2); ?><input type="hidden" name="tot_pen_amt" id="tot_pen_amt" value="<?php echo $tot_pen_amt; ?>" /></td>
               <td align="right"><span id="tot_col_amt"><?php echo number_format($tot_col_amt,2); ?></span><input type="hidden" name="tot_cl_amt" id="tot_cl_amt" value="" /></td>
               <td colspan="2" align="right"><strong>Balance Pending: <span id="bal_amt"> </span></strong><?php echo number_format($tot_pen_amt,2); ?></td>
		      </tr>
			  <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 colspan="2" align="center"><?php if($crd_blns!=0){ ?>
                <span id="cred_bl_span"><strong>Credit Balance :</strong><span id="cred_bl" ><?php echo number_format($crd_blns,2); ?></span></span><?php } ?></td>
              </tr>

			 <?php
			 }
			 else
			 {
			 ?>
			  <tr>
              <td colspan="8" 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 } ?> 

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