<?php
session_start();
// ============
include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class.php");
include('alert.php');
$obj=new my_class();
// ============
$branchid = $_SESSION['LOGIN_BRANCH'];

extract($_GET);
$invoice = trim($invoice);

$sec = $obj->Details_By_Cond("_fee_master_invoice","_invoice_no='$invoice'");
$std = $obj->Details_By_Cond("_pf_std_personal_info","_id='".$sec['_std_id']."'");

$det_in = $obj->Details_By_Cond("_int_institute_setup_vw","section_id='".$sec['_section_id']."'");
//============================
$lf_dept = $det_in['department_id'];
$last_payment_date = $sec['_last_payment_date'];
if($last_payment_date != '0000-00-00'){
	$last_payment_date = date("d-m-Y",strtotime($sec['_last_payment_date']));
}
else{
	$last_payment_date = '00-00-0000';
}

//include("late_fine_date_compare.php");

//============================
if($sec['_status']=='U' OR $sec['_status']=='PR'){
?>

<script src="module/fees/js/std_collect_fee.js" type="text/javascript"></script>

<div class="row-fluid">
	<div class="span2">
	</div>
	<div class="span8">
		<table id="sample-table-273" class="table table-striped table-bordered table-hover" cellspacing="10px" style="font-size:13px;">
			<thead style="padding: 10px;">
				<tr>
					<td colspan="4" style="text-align: center; background-color:#438eb9; color:#FFFFFF; font-weight:bold; font-size:14px;"><?php echo $std['_full_name']; ?></td>
				</tr>
				<tr>
					<td width="16%" style="font-weight:bold; background-color:#FFFFFF; line-height:10px; text-align:right;">Shift : </td>
                    <td style="font-weight:bold; background-color:#FFFFFF; line-height:10px;">
					<?php echo $det_in['shift']; ?>
					
					</td>
					<td width="16%" style="font-weight:bold; background-color:#FFFFFF; line-height:10px;text-align:right;">Medium : </td>
                    <td style="font-weight:bold; background-color:#FFFFFF; line-height:10px;">
					<?php echo $det_in['medium']; ?>
					
					</td>
				</tr>
                <tr>
					<td style="font-weight:bold; line-height:10px;text-align:right;">Class :</td>
                    <td style="font-weight:bold; line-height:10px;">
					<?php echo $det_in['class']; ?>
					
					</td>
					<td style="font-weight:bold;line-height:10px;text-align:right;">Department </td>
                    <td style="font-weight:bold; line-height:10px;">
					<?php echo $det_in['department']; ?>
					
					</td>								
				</tr>
				<tr>
					<td style="font-weight:bold; background-color:#FFFFFF; line-height:10px;text-align:right;">Student Type : </td>
                    <td style="font-weight:bold; background-color:#FFFFFF; line-height:10px;">
					
					<?php echo $det_in['student_type']; ?>
					</td>	
					<td style="font-weight:bold; background-color:#FFFFFF; line-height:10px;text-align:right;">Section : </td>
                    <td style="font-weight:bold; background-color:#FFFFFF; line-height:10px;">
					<?php echo $det_in['section']; ?>
					</td>				
				</tr>
				<tr>				
					<td style="font-weight:bold; line-height:10px;text-align:right;">Roll : </td>
                    <td style="font-weight:bold; line-height:10px;">
					
					<?php echo $std['_section_roll']; ?>
					</td>
					<td style="font-weight:bold; line-height:10px;text-align:right;">Year : </td>
                    <td style="font-weight:bold; line-height:10px;">
					
					<?php echo $sec['_year']; ?>
					</td>
				</tr>
				<tr>				
					<td style="font-weight:bold; background-color:#FFFFFF; line-height:10px;text-align:right;">Month : </td>
                    <td style="font-weight:bold; background-color:#FFFFFF; line-height:10px;">
					
					<?php echo $obj->Month($sec['_month']); ?>
					</td>
					<td style="font-weight:bold; background-color:#FFFFFF; line-height:10px;text-align:right;">Invoice : </td>
                    <td style="font-weight:bold; background-color:#FFFFFF; line-height:10px;">
					
					<?php echo $sec['_invoice_no']; ?>
					</td>
				</tr>
				
			</thead>
		</table>
	</div>
	<div class="span2"></div>

</div>
<!--<div class="row-fluid">
	<div class="span2"></div>
	<div class="span8">
		<table id="sample-table-273" class="table table-striped table-bordered table-hover" cellspacing="10px" style="font-size:13px;">
			<tr>
				<th>Payment Date<font color="#FF0000">*</font></th>
				<td>
					<div class="control-group" >
						<label class="control-label" for="form-field-1"></label>
						<div class="controls" id="branch_control">
							<input id="payment_date" name="payment_date" class="date-picker" type="text" data-date-format="dd-mm-yyyy" placeholder="dd-mm-yyyy"  />
						</div>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<div class="span2"></div>
</div>--->
<div class="row-fluid">
	<div class="span2">
		<input type="hidden" id="mod_id34" value="<?php echo $mod_id; ?>">
	</div>
	<div class="span8">	
	<table id="sample-table-273" class="table table-striped table-bordered table-hover" style="font-size:16px;">
		<thead>
			<tr>
				<!--<th>Sl</th>-->
				<th>Fee Head</th>
				<th>Req. Amount</th>
				<th>
					<!--<button id="btn1">Add More</button>-->
					<div id="discount_btn" style="text-align:right;">
						<button type="button" id="add_discount_btn" class="btn btn-lg btn-purple btn-sm" onclick="opendiscountinputbox()">Discount</button>
					</div>
				</th>
			</tr>
		</thead>
		
		<tbody class="abc">
			<?php
			$i=0;
			foreach($obj->View_All_By_Cond("_fee_details_invoice","_invoice_no='$invoice' AND _br_id='$branchid'") as $v1){
			$i++;
			?> 			
			<tr>
				<!--<td class="td_pad"><?php //echo $i; ?></td>-->
				<td class="td_pad">
					<?php echo $v1['_fee_head']; ?>
					<input type="hidden" id="adjust_head_<?php echo $i;?>" name="adjust_head[]" value="<?php echo $v1['_fee_head']; ?>" />
                </td>
				<td colspan="2" class="td_pad">
					<?php if($v1['_type']=='C'){ echo $v1['_amount']; }else{echo '-';} ?>
					<input type="hidden" id="cr_<?php echo $i;?>" name="cr[]" value="<?php if($v1['_type']=='C'){ echo $v1['_amount']; }else{echo '-';} ?>" />
                </td>
				<!--<td class="td_pad"><?php if($v1['_type']=='D'){ echo $v1['_amount']; }else{echo '-';} ?></td>-->
			</tr>
			<?php } ?>	
		</tbody>	

		<tfoot>
		<?php
			$c = $obj->View_column_details_By_Cond("_fee_details_invoice","SUM(_amount) AS credit","_invoice_no='$invoice' AND _type='C' AND _br_id='$branchid'");
			$d = $obj->View_column_details_By_Cond("_fee_details_invoice","SUM(_amount) AS debit","_invoice_no='$invoice' AND _type='D' AND _br_id='$branchid'");
		?>
			<tr>
				<th >Total = </th>
				<th colspan="2" id="ttl_amount"><?php if($c['credit']!=''){ echo $c['credit']; }else{echo '-';} ?></th>
				<!--<th><?php if($d['debit']!=''){ echo $d['debit']; }else{echo '-';} ?></th>-->
			</tr>
			<tr>
			<?php $tot = $obj->Details_By_Cond("_fee_master_invoice","_invoice_no='$invoice'");
					$show_rec_for_human = $tot['_paid_amount'];
					if($tot['_discount']!=0){
						$show_rec_for_human = $tot['_paid_amount'].' + <span style="color: red">'.$tot['_discount'].' (Discount)</span>';
					}
			?>
				<th >Received Amount = </th>
				<th colspan="2" id="receive_amnt"><?php echo $show_rec_for_human; ?></th>	
			</tr>
			<tr>
				<th >Net Payable = </th>
				<th colspan="2" id="thh"><?php echo $tot['_due_amount']; ?></th>
			</tr>
			
			<tr>
				<th >Discount</th>
				<th colspan="2">
					<div id="discount_input_div" style="display: none; ">
						<input type="text" name="full_pay_discount" id="full_pay_discount">
					</div>
				</th>
			</tr>
			<tr>
				<th>Payment Date<font color="#FF0000">*</font></th>
				<th>
					<div class="control-group" >
						<label class="control-label" for="form-field-1"></label>
						<div class="controls" id="branch_control">
							<input id="full_payment_date" name="payment_date" class="date-picker" type="text" data-date-format="dd-mm-yyyy" placeholder="dd-mm-yyyy"  />
						</div>
					</div>
				</th>
				<th>
					<div class="span12" style="text-align:right;">
						<button class="btn btn-lg btn-success" id="btn_full_pay_submit" type="button" data-toggle='modal' data-target='#modal_pay_con_msg'>Payment&nbsp;Confirm</button>
					</div>
				</th>
			</tr>
		</tfoot>
	</table>
	
	<input type="hidden" name="npay" value="<?php echo $tot['_due_amount']; ?>" id="npay" >
	<input type="hidden" name="total_amount" value="<?php echo $tot['_total_amount']; ?>" id="total_amount" >
	<input type="hidden" name="tot_amount" value="<?php echo $tot['_due_amount']; ?>" id="tot_amount" >
	
	<input type="hidden" name="inv" value="<?php echo $tot['_invoice_no']; ?>" id="inv">
	<input type="hidden" name="amount" value="<?php echo $tot['_due_amount']; ?>" id="amount">
    <input type="hidden" name="last_payment_date" value="<?php echo $last_payment_date; ?>" id="last_payment_date">
    
    <!--<input type="hidden" name="today" value="<?php echo date('Y-m-d'); ?>" id="today">-->
    
	</div>
</div>
<!--<div class="row-fluid">	
	<div class="span3">
		
				</div>
</div>-->
<!--
<div class="row-fluid">
	<div class="span12" style="text-align:left;">
		<button class="btn btn-lg btn-success" id="submit12" type="button">Payment&nbsp;Confirm</button>
	</div>
</div>
-->


<?php
}
elseif($sec['_status']=='P'){
?>
<div class="row-fluid">This Invoice Already Paid</div>
<?php
}
elseif($sec['_status']=='AD'){
?>
<div class="row-fluid">This Invoice Expired</div>
<?php
}
else{
?>
<div class="row-fluid">Invalid Invoice No or Barcode</div>
<?php
}
?>

<script>
$('.date-picker').datepicker({
		endDate: '+0d',
		startDate: '-1y'
}).on('changeDate', function(ev){
    // $('#sDate1').text($('#datepicker').data('date'));
    $('.date-picker').datepicker('hide');
});

$('.date-picker').datepicker({
			endDate: '+0d',
		startDate: '-1y'
}).next().on(ace.click_event, function(){
					$(this).prev().focus();
				});
/*$('.date-picker').datepicker().next().on(ace.click_event, function(){
     $(this).prev().focus();
    });*/
$(document).ready(function(){
	
var ran = '<?php echo $ran;?>';
var filed=1;
$("#btn1").click(function(){
	var x = <?php echo $i;?>;
	 var xx = x + filed;
	 var inpu_box_id="input_button"+filed;
	 var datastr="id="+ inpu_box_id+"&xx="+xx;
	 
	 $.ajax({
			type:"post",
			url:"module/fees/ins_append_fee_head.php",
			data:datastr ,
			success:function(st){
				//alert(st);
				$(".abc").append(st);
				
				}
			}); 
filed++;
});
});

function opendiscountinputbox() 
{
    //$("#discount_btn").css("display", "none");
    $("#discount_input_div").css("display", "block");
}


 function call_calculation(){
		 var values = $('input[name="fhamount[]"]').map(function(){
					   return this.value;
					 }).get();
		
		var total = 0;
		
		for (var i = 0; i < values.length; i++) {
			total += values[i] << 0;
		}
		var total_amount = <?php echo $tot['_total_amount'];?>;
		//alert(total_amount);
		
		var npay  = $("#npay").val();
		//alert(npay);
		var sum_total = parseInt(total) + parseInt(total_amount);
		
		var sum = parseInt(total) + parseInt(npay);
		//alert(sum);
		 $("#thh").html(sum);
		 $("#ttl_amount").html(sum_total);
		 $("#total_amount").val(sum_total);
		 $("#tot_amount").val(sum);
		 }
	
</script>