<?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('43');
?>
<!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 -->
 <?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:">Accounts</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="acc_list.php" title="List Accounts" 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 billing_det WHERE party_det_id = '$pa_id'";
			$QURY_ppo = mysqli_query($connect,$SLCT_ppo);
			
		}
		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">
                <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 ?></option>
                    <?php
					
                    }
                    ?>
                </select>
            </div>
            <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'])));                  
		?>
        
		 <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)"/>
            Cash</label>
          
          <label style="margin-right:30px;">
            <input type="radio" name="pay_tp" id="cheque" value="cheque" onclick="pay_type_hid(this.value)"/>
            Cheque</label>
          
          <label style="margin-right:30px;">
            <input type="radio" name="pay_tp" id="neft" value="neft" onclick="pay_type_hid(this.value)"/>
            NEFT</label>
			</div><div class="clear"></div>
         </div>
        
		
		<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>
		
		<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">
                <select data-placeholder="Choose Employee..." class="select" name="chk_rec" id="chk_rec" 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="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>Bank Name:<span class="req">*</span></label></div>
            <div class="grid4"><input type="text" value="" name="bn_name_ne" id="bn_name_ne" /></div><div class="clear"></div>
         </div>
		 
		 <?php if(mysqli_num_rows($QURY_ppo) < 1){  ?>
		 <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(mysqli_num_rows($QURY_ppo) > 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; ?>" />
		</div>
	
        <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>
            
            <!--<th width="78">Image</th>-->
            </tr>
            </thead>
            <tbody>
            <?php
					
			$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;
			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;
				//$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($FTCH->close_status == 'no')
				{ 
			
				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="center"><?php echo number_format($FTCH->bill_amt); ?><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); ?><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></td>
            </tr>
            
            <?php
			$loop ++;
			}
			 }
			 }
			?>
			
			 <?php
					
			$SLCT_nb = "SELECT * FROM billing_det WHERE party_det_id='$pa_id' ORDER BY billing_det_id ASC";
			//echo $SLCT_nb;
			$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;
				$QURY_bl = mysqli_query($connect,$SLCT_bl);
				if(mysqli_num_rows($QURY_bl)<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 str_replace("-", "/", $FTCH_nb->bill_date); ?></td>
            <td align="center"><?php echo number_format($FTCH_nb->bill_amt); ?><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); ?><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></td>
            </tr>
            
            <?php
			$loop ++;
			 }
			 }
			 ?>
			 <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 $tot_bill_amt; ?><input type="hidden" name="tot_bl_amt" id="tot_bl_amt" value="<?php echo $tot_bill_amt; ?>" /></td>
               <td align="center"><?php echo $tot_pen_amt; ?><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="center"><strong>Balance Pending: <span id="bal_amt"> </span></strong><input type="hidden" name="bl_amt" id="bl_amt" value="" />			   </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 align="center"><span id="cred_bl_span" style="display:none"><strong>Credit Balance :</strong><span id="cred_bl" >0.00</span></span>
			   <input type="hidden" name="cre_bl_amt" id="cre_bl_amt" value="" /></td>
             </tr>
			 
			 <?php
			 }
			 else
			 {
			 ?>
			  <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 } ?>
		
		
        <?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>
