<?php
session_start();
// ============
include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class.php");

$obj=new my_class();

extract($_GET);

function getMonthName($i){
    if($i=="1") { return "January";}
    else if($i=="2") { return "February";}
    else if($i=="3") { return "March";}
    else if($i=="4") { return "April";}
    else if($i=="5") { return "May";}
    else if($i=="6") { return "June";}
    else if($i=="7") { return "July";}
    else if($i=="8") { return "August";}
    else if($i=="9") { return "September";}
    else if($i=="10") { return "October";}
    else if($i=="11") { return "November";}
    else if($i=="12") { return "December";}
    else { return "Unknown";}
}

/*function randString($length,$id){
    $charset='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    $str = '';
    $count = strlen($charset);
    while ($length--) {
        $str .= $charset[mt_rand(0, $count-1)];
    }
	return $str.time().$id;
}*/


$table_name="`_fee_master_invoice` a LEFT JOIN `_pf_std_personal_info` b ON a.`_std_id`=b.`_id`";
$column="_invoice_no,_month,_year,_total_amount,_due_amount,_paid_amount,a._status master_status,b.`_full_name`,b.`_contact_mobile`,b.`_gender`,b.`_uniq_id`";
$where_cond="a._id='$id'";
$fee_master_invoice_data=$obj->View_column_details_By_Cond($table_name,$column,$where_cond);
 
$_invoice_no=$fee_master_invoice_data["_invoice_no"];
$_month=$fee_master_invoice_data["_month"];
$_year=$fee_master_invoice_data["_year"];
$_total_amount=$fee_master_invoice_data["_total_amount"];
$_due_amount=$fee_master_invoice_data["_due_amount"];
$_paid_amount=$fee_master_invoice_data["_paid_amount"];
$_status=$fee_master_invoice_data["master_status"];
$_full_name=$fee_master_invoice_data["_full_name"];
$_contact_mobile=$fee_master_invoice_data["_contact_mobile"];
	
$_uniq_id=$fee_master_invoice_data["_uniq_id"];

if($_status=="U"){
    $nstatus_text="Unpaid";
    $nstatus="<button class='btn btn-small btn-success' onclick='fee_pay_confirm($id,$_due_amount)' data-dismiss='modal'>Confirm</button>";
}
else if($_status=="P"){
    $nstatus_text="Paid";
    $nstatus="<div class='alert alert-info center' role='alert'>You have already paid for this month.</div>";
}
else if($_status=="PR"){
    $nstatus_text="Partially Paid";
    $nstatus="<div class='alert alert-warning center' role='alert'>Please try for partial payment</div>";
}
?>


<div class="modal-body">
    <span style="font-size:11px;" class="alert alert-info inline no-margin"><?php echo '<b>Invoice No:</b> '.$_invoice_no;?></span>
    <span style="font-size:11px;" class="alert alert-info inline no-margin"><?php echo '<b>Month:</b> '.getMonthName($_month);?></span>
    <span style="font-size:11px;" class="alert alert-info inline no-margin"><?php echo '<b>Session:</b> '.$_year;?></span>

	<div class="panel panel-info" style="margin-top: 10px;">
        <div class="panel-body">
			<table class="table">
				<tr>
					<td>
						<table class="table table-striped table-bordered">
							<tr>
								<td>Student ID</td>
								<td><b><?php echo $_uniq_id;?></b></td>
							</tr>
							<tr>
								<td>Name</td>
								<td><b><?php echo $_full_name;?></b></td>
							</tr>
							<tr>
								<td>Total</td>
								<td><b><?php echo $_total_amount;?></b></td>
							</tr>
							<tr>
								<td>Due</td>
								<td><b><?php echo $_due_amount;?></b></td>
							</tr>
							<tr>
								<td>Paid</td>
								<td><b><?php echo $_paid_amount;?></b></td>
							</tr>
							<tr>
								<td>Status</td>
								<td><b><?php echo $nstatus_text;?></b></td>
							</tr>
						</table>
					</td>
					<td>
					<?php

						$table_name="_fee_details_invoice";
						$column="*";
						$where_cond="_invoice_no='$_invoice_no'";
					?>
						<table class="table table-striped table-bordered">
					<?php
							foreach ($obj->View_all_data_row_column_By_Cond($table_name,$column,$where_cond) as $value){
								extract($value);
								echo "<tr>
										<td>$_fee_head</td> 
										<td><b>$_amount</b></td>
									</tr>";
							}
					?>
						</table>
						<div class="control-group">
							<table class="table table-striped table-bordered" >
								<tr style="width: 100%;">
									<td style="width: 30%; padding-bottom: 0px;"><b>Payment Date<font color="#FF0000">*</font></b></td>
									<td style="padding:0">
										<input id="monthly_fee_payment_date" name="monthly_fee_payment_date"  style="width: 70%; padding: 5px;" class="date-picker" type="text" data-date-format="dd-mm-yyyy" placeholder="dd-mm-yyyy"  />
									</td>
								</tr>
							</table>
						</div>
						<div id="discount_<?php echo $_uniq_id;?>">
							<button type="button" class="btn btn-mini btn-warning" onclick="opendiscountinputbox(<?php echo $_uniq_id;?>)">Discount</button>
						</div>
						<div id="discount_input_div_<?php echo $_uniq_id;?>" style="display: none; ">
							<table class="table table-striped table-bordered" >
								<tr style="width: 100%;">
									<td style="width: 46% ;padding-bottom: 0px; ">Discount</td>
									<td style="padding:0 " ><input id="discount_input_<?php echo $id;?>" value="0" class="form-control" style="width: 96%; padding: 5px; "></td>
								</tr>
							</table>
						</div>
					</td>
				</tr>
			</table>
		</div>
    </div>
</div>
<div class="modal-footer">
    <?php echo $nstatus;?>
</div>

<script>
$('.date-picker').datepicker().next().on(ace.click_event, function(){
     $(this).prev().focus();
    });
</script>