<?php
$idno = $_GET['idno'];
$rid = $_GET['rid'];

// print_r($_REQUEST); 
// die();
?>
<script>
    var headPrint='<div class="headPrint"><img src="<?php echo $LinksDetails["logo"] ?>" height="60px"><h1><?php echo ucfirst(trim($LinksDetails["site_name"])) ?></h1></div>';
	var root='<?php echo URL_ROOT ?>';
	</script>
<script type="text/javascript" src="<?php echo URL_ROOT ?>js/jquery-1.9.1.js"></script>
<link href='<?php echo URL_ROOT ?>assets/css/print.css' rel='stylesheet'>
<script type="text/javascript" src="<?php echo URL_ROOT ?>js/custom.js"></script>
<?php
include("../db.php");

$aryForm=$db->getRow("SELECT * FROM student WHERE  school_id='".$_SESSION["admin"]["school_id"]."' and idno='$idno' ");

$rdetail = $db->getRow("select * from receipt where id='$rid' and idno='$idno' and session='".$_SESSION["admin"]["session"]."' and topay!='' ");
?>
<style>
.recept {
font-weight: bold;
font-size: 20px;
color: #FC0D0D;
}
.headprint .logo{
	margin: -5px 10px 0px 0px !important;
}

#pm1 {
    display:none;
}
#txnid {
    display:none;
}
#bankname {
    display:none;
}
#tdate {
    display:none;
}

</style>

<div style="display:flex;">
<div style="width:49%; border: 4px solid black;background: #C1CCD8;display:none;">
<div class="headPrint" style="background: #C1CCD8; border-bottom: 4px solid black;"> 
<table width="100%">
        <tr>
          <td width="10%"><img style="top:3px;position:relative;" src="<?php echo $LinksDetails["logo"] ?>" class="logo" height="50px" width="70px"></td>
           <td  style="text-align:center"><h5 style="margin:0; padding:0;"><?php echo ucfirst($LinksDetails["site_name"]) ?></h5>
            <span style="text-align:center;font-size:13px;"><?php echo ucfirst(nl2br($LinksDetails["contact_content"])); ?></span>
			</td>
        </tr>
      </table>
  </div>
<table width="100%" style='background: #C1CBD8;font-size:12px;'>
    <tr> 
        <td width="20%"><strong>R.No</strong></td><td><span class="recept"><?php echo $rid; ?></span></td>
        <td width="20%"><strong>Date</strong></td><td><?php echo $rdetail["udate"]; ?></td>
    </tr>
    <tr>
        <td><strong>Name</strong></td><td><?php echo $aryForm["name"]; ?></td>
        <?php
			$im=explode(",",$rdetail["Months"]);
			$mn=array_unique($im);$months="";
		 	if(is_array($mn) && count($mn)){
				foreach($mn as $ipi){					
					if($ipi!=""){
						if($months!="")$months.=", ";
				// 		if($ipi<=9){
				// 			$newDate=date("Y")."-".($ipi+3)."-1";
				// 			$months.= date("M",strtotime($newDate));
				// 		}
				// 		else{
				// 			$newDate=date("Y")."-".($ipi-9)."-1";
				// 			$months.= date("M",strtotime($newDate));
				// 		}
				    $months.= $db->getVal("select name from months where month='$ipi'");
					}
				}
			}
		?>
		<td><strong>Month</strong></td><td><?php echo $months;?></td>
    </tr>
    <tr>
        <td><strong>Father's</strong></td><td><?php echo $aryForm["fname"]; ?></td>
        <td><strong>Mode</strong></td>
        <td>
    		<span id='pm1'><?=  $rdetail['payment_mode']?></span>
		     <select id='status' name='payment_mode' onchange='change_pm()'>
		          <option <?php if($rdetail['payment_mode'] == 'Cash') echo "selected";?> >Cash</option>
       	   	      <option <?php if($rdetail['payment_mode'] == 'Cheque') echo "selected";?>>Cheque</option>
       	   	      <option <?php if($rdetail['payment_mode'] == 'NEFT') echo "selected";?>>NEFT</option>
       	   	      <option <?php if($rdetail['payment_mode'] == 'UPI') echo "selected";?>>UPI</option>
       	   	      <option <?php if($rdetail['payment_mode'] == 'Bank Deposit') echo "selected";?>>Bank Deposit</option>
       	   	      <option <?php if($rdetail['payment_mode'] == 'POS') echo "selected";?>>POS</option>
       	   	      <option <?php if($rdetail['payment_mode'] == 'Debit Card') echo "selected";?>>Debit Card</option>
       	   	      <option <?php if($rdetail['payment_mode'] == 'Credit Card') echo "selected";?>>Credit Card</option>
       	   	      <option <?php if($rdetail['payment_mode'] == 'online') echo "selected";?>>online</option>
       	   	      <option <?php if($rdetail['payment_mode'] == 'Mobile Wallet') echo "selected";?>>Mobile Wallet</option>
       	   	      <option <?php if($rdetail['payment_mode'] == 'POS-2') echo "selected";?>>POS-2</option>
			</select>
        </td>
    </tr>
    <tr>
        <td><strong>Class</strong></td><td><?php echo $aryForm["class"]; ?>-<?php echo $aryForm["section"]; ?></td>
        <td><strong>Issued By</strong></td><td><?php echo $db->getVal("select name from users where id=$rdetail[added_by] "); ?></td>
    </tr>
    <tr>
        <td><strong>Adm/No</strong></td><td><?php echo $aryForm["admissionno"]; ?></td>
        <td><strong>Roll No.</strong></td><td><?php echo $aryForm["fincome"]; ?></td>
    </tr>

    <tr>
        <td><strong>Cheque No/Tr. No.</strong></td>
        <td>
            <span id="txnid"><?php echo $rdetail['txnid']; ?></span>
            <input id="txnidtext" type="text" name="txnid" value="<?php echo $rdetail['txnid']; ?>" style="background-color:white !important; height: 23px; width:90px; font-size:15px !important;">
        </td>
        <td><strong>Bank Name</strong></td>
        <td>
            <span id="bankname"><?php echo $rdetail['bankname']; ?></span>
            <input id="banknametext" type="text" name="bankname" value="<?php echo $rdetail['bankname']; ?>" style="background-color:white !important; height: 23px; width:90px; font-size:15px !important;">
        </td>
    </tr>
    <tr>
        <td><strong>Transaction Date</strong></td>
        <td>
            <span id="tdate"><?php echo $rdetail['tdate']; ?></span>
            <input id="tdatetext" type="text" name="tdate" value="<?php echo $rdetail['tdate']; ?>" style="background-color:white !important; height: 25px; width:90px; font-size:15px !important;">
        </td>
        <td><strong>Session</strong></td>
        <td><?php echo $rdetail["session"]; ?></td>
    </tr>

	<tr>
    <td colspan="4">
    
<?php
echo "<table width='100%' border='1'>
<tr>
	<th>Sr. No</th><th>Fee Head</th><th>To Pay</th><th>Paid</th>
</tr>";

if($rdetail){
    $topay = json_decode($rdetail['topay'], true);
    $paid = json_decode($rdetail['detail'], true);

    $j=0;
    foreach($topay as $key => $val){$j++;
    
    if($paid[$key]==""){
        $val1= 0;
    } else {
        $val1 = $paid[$key];
    }
    
        echo "<tr  style='text-align: center;'><td>$j</td><td>";

			if($key=="Bus_Fees")echo "Transport Fee"; 
			elseif($key=="bus")echo "Transport Fee";
			elseif($key=="tution")echo "Tuition Fee";
			elseif($key=="Tution_Fees")echo "Tuition Fee";
			elseif($key=="hostel")echo "Hostel Fee";
			elseif($key=="tuition_fine")echo "Fine";
			else echo $key;
			
			echo "</td><td>$val</td><td>$val1</td></tr>";
    }

	echo "<tr><th></th><th>Total </th><th>".$rdetail['total']."</th><th>".$rdetail["amount"]."</th></tr>";
	echo "<tr><th></th><th>Remaining Amount</th><th></th><th>".$rdetail['remaining']."</th></tr>";
	echo "<tr><th></th><th>Discount</th><th>".($rdetail['discount'])."</th><th></th></tr>";
}

echo "</table><hr/><div class='footerPrint'><span>Signature...............................</span></div>";
echo '<input id="myPrntbtn" style="background: firebrick;color: white;height: 26px;width: 53px;border: 2px inset snow;border-radius: 10px;" type="button"  onclick="window.print()" value="Print">';
?>

<input id="updatebtn" style="background: firebrick;color: white;height: 26px;width: 53px;border: 2px inset snow;border-radius: 10px;" type="button"  onclick="update()" value="Update">

<style type="text/css">
@media print {
    #myPrntbtn {
        display :  none;
    }
    #updatebtn{
        display: none;
    }
    
    #status {
        display:none;
    }
    
    #pm1 {
        display:block;
    }

    #txnidtext {
        display:none;
    }    
    #txnid{
        display:block;
    }
    
    #banknametext {
        display:none;
    }    
    #bankname{
        display:block;
    }

    #tdatetext {
        display:none;
    }    
    #tdate{
        display:block;
    }
    
}

</style>
	</td></tr>
</table>
<span style="color:red;text-align:center;font-size:14px;"><?php echo "[" ?>Note : If any correction,Please consult to fee counter.<?php echo "]" ?></span>
</div>
<!--<br/><br/><br/><div style="border-top:3px dotted black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><br/><br/>-->
<div style="width:100%;float:left;margin-left:10px;border: 4px solid black;background: #C1CCD8;">
<div class="headPrint" style="background: #C1CCD8;border-bottom: 2px solid black;"> <table width="100%">
        <tr>
          <td width="10%"><img style="top:3px;position:relative;" src="<?php echo $LinksDetails["logo"] ?>" class="logo" height="50px" width="70px"></td>
           <td  style="text-align:center"><h5 style="margin:0; padding:0;"><?php echo ucfirst($LinksDetails["site_name"]) ?></h5>
            <span style="text-align:center;font-size:13px;"><?php echo ucfirst(nl2br($LinksDetails["contact_content"])); ?></span>
			</td>
        </tr>
      </table></div>
    <table width="100%" style='background: #C1CBD8;font-size:12px;'>
    <tr>
        <td width="20%"><strong>R.No</strong></td><td><span class="recept"><?php echo $rid; ?></span></td>
        <td width="20%"><strong>Date</strong></td><td><?php echo $rdetail["udate"]; ?></td>
    </tr>
    <tr>
        <td><strong>Name</strong></td><td><?php echo $aryForm["name"]; ?></td>
        <td><strong>Month</strong></td><td><?php echo $months;?></td>
    </tr>
    <tr>
        <td><strong>Father's</strong></td><td><?php echo $aryForm["fname"]; ?></td>
        <td><strong>Mode</strong></td>
        <td>
		<span id='pm' ><?=  $rdetail['payment_mode']?></span>
        </td>
    </tr>
    <tr>
        <td><strong>Class</strong></td><td><?php echo $aryForm["class"]; ?>-<?php echo $aryForm["section"]; ?></td>
        <td><strong>Issued By</strong></td><td><?php echo $db->getVal("select name from users where id=$rdetail[added_by] "); ?></td>
    </tr>
    <tr>
        <td><strong>Adm/No</strong></td><td><?php echo $aryForm["admissionno"]; ?></td>
        <td><strong>Roll No.</strong></td><td><?php echo $aryForm["fincome"]; ?></td>
    </tr>
    
    <tr>
        <td><strong>Cheque No/Tr. No.</strong></td>
        <td><?php echo $rdetail['txnid']; ?></td> 
        <td><strong>Bank Name</strong></td>
        <td><?php echo $rdetail['bankname'] ?></td>
    </tr>
    <tr>
        <td><strong>Transaction Date</strong></td>
        <td><?php echo $rdetail['tdate']; ?></td>
        <td><strong>Session</strong></td>
        <td><?php echo $rdetail["session"]; ?></td>
    </tr>
    
	<tr>
    <td colspan="4">

<?php
echo "<table width='100%' border='1'>
<tr>
	<th>Sr. No</th><th>Fee Head</th><th>To Pay</th><th>Paid</th>
</tr>
";

if($rdetail){
        $j=0;
    foreach($topay as $key => $val){$j++;
    if($paid[$key]==""){
        $val1= 0;
    } else {
        $val1 = $paid[$key];
    }
        echo "<tr  style='text-align: center;'><td>$j</td><td>";

			if($key=="Bus_Fees")echo "Transport Fee"; 
			elseif($key=="bus")echo "Transport Fee";
			
			elseif($key=="tution")echo "Tuition Fee";
			
			elseif($key=="Tution_Fees")echo "Tuition Fee";
			elseif($key=="hostel")echo "Hostel Fee";
			elseif($key=="tuition_fine")echo "Fine";
			else echo $key;
			
			echo "</td><td>$val</td><td>$val1</td></tr>";
    }

	echo "<tr><th></th><th>Total </th><th>".$rdetail["total"]."</th><th>".$rdetail["amount"]."</th></tr>";
	echo "<tr><th></th><th>Remaining Amount</th><th></th><th>".$rdetail['remaining']."</th></tr>";
	echo "<tr><th></th><th>Discount</th><th>".($rdetail['discount'])."</th><th></th></tr>";
}

echo "</table><hr/><div class='footerPrint'><span>Signature...............................</span></div>";
echo '<input id="myPrntbtn" style="background: firebrick;color: white;height: 26px;width: 53px;border: 2px inset snow;border-radius: 10px;" type="button"  onclick="window.print()" value="Print">';
?>
	</td></tr>
</table>
<br/>
<span style="color:red;text-align:center;font-size:14px;"><?php echo "[" ?>Note : If any correction,Please consult to fee counter.<?php echo "]" ?></span>
</div>
</div>

<script>
function checkreceptNo(id){
	$.post( "<?php echo URL_ROOT ?>ajax.php", {
			type: "checkreceptNo" ,
			paytype: '<?php echo $_REQUEST["type"] ?>',
			id: id
		} , function( data ) {
		data=data.trim();
		if(data==""){
			$("#saveprintme").click();
		}
		else{
			alert("receipt id already exit");
		}
	});
}

function change_pm()
{
	var v= $('#status').val();
	$('#pm').text(v);
	$('#pm1').text(v);
}

function update(){

    var mode = $("#status").val();
    var txnid = $("#txnidtext").val();
    var bankname = $("#banknametext").val();
    var tdate = $("#tdatetext").val();

    $.post( "<?php echo URL_ROOT ?>print/ajax.php", {
			type: "updatereceipt",
			rid: "<?php echo $rid; ?>",
			idno: "<?php echo $_GET['idno'] ?>",
			mode: mode,
			txnid: txnid,
			bankname: bankname,
			tdate: tdate,
			rrid: <?php echo json_encode($rridary); ?>
		} , function( data ) {
            // alert(data);
            location.reload();
	});    

}
</script>