<style>

.popup-form{
	margin:0px;
	border:2px solid #600;
	padding:5px;
}
.title{
  text-align: center;
  color: #fff;
  background-color: #1443BD;
  padding: 4px;
  border: 1px inset #1443BD;
  box-shadow: 0px 0px 10px #050101;
  border-radius: 5px;
}
.btn-new{
  background-color: #05967A;
  color: #fff;
  border: 2px outset #05967A;
  padding: 4px 15px;
  font-weight: 700;
  border-radius: 5px;
  box-shadow: 0px 2px #352E2E;
}
.btn-delete{
  background-color: #CA1A1A;
  border: 2px outset #CA1A1A;
  box-shadow: 1px 3px #322C2C;
  color: #fff;
  padding: 4px 15px;
  font-weight: 700;
  border-radius: 5px;
}
.select-text{
	padding: 3px;
  border: 2px solid #747171;
  color: #380303; 
  font-weight: 600;
}
.level, .btn-new, .btn-delete{
	margin-left: 10px;
  margin-right: 5px;
}
</style>
<?php

// if($_POST){
// 		$saveAry=array("idno"=>$_GET["id"],
// 						"amount"=>$_POST["amount"],
// 						"type"=>$_POST["name"],
// 						"date"=>$_POST["udate"],
// 						"detail"=>$_POST["detail"],
// 						"session"=>$_SESSION["admin"]["session"],
// 						"school_id"=>$_SESSION["admin"]["school_id"],
// 						"added_by"=>$_SESSION["admin"]["uid"]);
// 		$db->insertAry("extra_amount",$saveAry);
// 		echo "Record Save Successfully<br>".$db->getErMsg();
// }

$aryForm=$db->getRow("SELECT * FROM student WHERE school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
?>
<link rel="stylesheet" href="<?php echo URL_ROOT; ?>js/jquery-ui.css">
<script src="<?php echo URL_ROOT; ?>js/jquery-1.10.2.js"></script>
<script src="<?php echo URL_ROOT; ?>js/jquery-ui.js"></script>
<script>
var add_tr='<tr id="row_1"><td ><input type="text" class="st-forminput" style="width:86%;" name="attr_month[]" /></td><td ><textarea type="text" class="st-forminput" style="width:86%;" name="attr_name[]" ></textarea></td><td><input type="text" class="st-forminput" style="width:90%;" name="attr_value[]" /></td><td><a class="delete" href="javascript:;">X</a></td></tr>';
$(document).ready(function(){
	$("#add").click(function(){
		$("#tbody").append($(add_tr));
	
		$('#tbody td a.delete').on('click',function() { 
			var rowCount = $('#tbody tr').length;
			if(rowCount<=1){
				//alert("This item cannot deleted !!!");
			}else{
				$(this).parent().parent().remove(); 
			}
		});	
	});
});
function fetchDetail(ids){
	var values=$(ids).val();
	 $.getJSON("ajax.php?type=getValByRecepit&id="+values, function(field){
		 //alert(field.month)
		$("#month").val(field.month)
		$("#name").val(field.name)
		$("#value").val(field.value)
    });
}
$(function() {
	$(".datepicker").each(function(index, element) {
        var d = new Date(); // for now
		datetext=d.getHours()+": "+d.getMinutes()+": "+d.getSeconds();
		$( this ).datepicker({
		  changeMonth: true,
		  changeYear: true,
		  showOn: "button",
		  buttonImage: "<?php echo URL_ROOT ?>js/images/calendar.gif",
		  buttonImageOnly: true,
		  buttonText: "Select date",
		  dateFormat: 'yy-mm-dd ',
		  onSelect: function(datetext){
			var d = new Date(); // for now
			datetext=datetext+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
			$(this).val(datetext);
		  }
		});
    });
});
</script>

<h2 class="title">Receipt Detail</h2>
<form method="post" action="" id='printMe'>
<table border="2" style="width:100%"> 

  <tr>
        <th>S.No.</th>
        <th>Receipt No</th>
        <th>Receipt Date</th>     
		<th>Amount</th>
		<!--<th>Month</th>-->
		<th>Payment Mode</th>
		<th>Status</th>
        <th>Print</th>
    </tr>
	<?php  
	
	
	$cheque=$db->getRows("select * from pocket_receipt where  idno='".$_GET[id]."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
	
	$class = $db->getVal("select class from student where idno='".$_GET[id]."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' ");

	$i=0;
foreach($cheque as $chequ){ $i++;
	$id=$chequ['id'];
 
   $rmounth=explode(",",$chequ['Months']);
   $rids=array();$rrmonth=array();
   if(is_array($rmounth) && count($rmounth)>0){
	foreach($rmounth as $rrids){

	$rrmonth[]=$rrids['Months'];

	}
   }


                 $fmonths="";$monthname1="";$monthname=array();
				$fmonths=implode(",",$rrmonth);
					$im=explode(",",$fmonths);
					$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));//."(".($ij+3).")";
								}
								else{
									$newDate=date("Y")."-".($ipi-9)."-1";
									$months.= date("M",strtotime($newDate));//."(".($ij-9).")";
								}
							}
						}
					}   
?>
   <tr>
         <td><?= $i; ?></td>
         <td><?= $chequ['id'];?></td>
         <td><?= date("d/m/Y", strtotime($chequ['udate']));?></td>
         <td><?= $chequ['amount'];?></td>
         <!--<td><?= $months;?></td>-->
         
         <td>
             <?php echo $chequ['payment_mode']; ?>
         </td>
         <td style="margin:0px;padding:0px">
            <select id="status<?php echo $chequ['id'];?>">
                <option value="1" <?php if($chequ['rec_status'] == "1")echo "selected"; ?>>Active</option>
                <option value="0" <?php if($chequ['rec_status'] == "0")echo "selected"; ?>>Cancel</option>
            </select>

            
            <?php 
                $roll = $db->getVal("select roll from users where id='".$_SESSION['admin']['uid']."' ");
                $permission = $db->getVal("select id from tbl_privilages where roll_id=$roll and page_name='DeleteReceipt' and a='1' ");
                if($permission){
                 ?>
                 <button style="background:teal;color:white;width:50px;padding:0px;" onclick="updatereceiptstatus(<?php echo $chequ['id'];?>)">Update</button>
                 <?php
                }
            ?>
        </td>

         <td>
            <?php $detail="";?>
            <a style="float:left" class="fancybox" data-class="recepit" href="?page_id=pocket_recepitNew&idno=<?php echo $_GET[id] ?>&udate=<?php echo $chequ["udate"] ?>&month=<?php echo $chequ["Months"] ?>&rrid=<?php echo 'rrid-'.$chequ["rrid"];?>&amount=<?php echo $chequ["amount"] ?>&type=<?php echo $chequ["type"] ?><?php $allDetail=array();
			$detail=json_decode($chequ["detail"], true);
    			foreach($detail as $dList=>$val){
    				echo "&fee-$dList=$val";
    			}
			?>&detail=pay-fee&class=<?php echo $class; ?>&total=<?php echo $chequ["total"] ?>&install=<?php echo $chequ["install"] ?>&receiptid=<?php echo $chequ["id"] ?>">
            <button type="button" class="btn" style="background:green;color:white;">Print</button></a>
        </td>
    </tr> 
<?php  } ?>

	
</table>
<?php 	echo '<center><input style="background: firebrick;color: white;height: 26px;width: 53px;border: 2px inset snow;border-radius: 10px;" type="button" id="btnduesend" onclick="myFunction()" value="Print"></center>';
 ?>
 <style type="text/css">
@media print {
    #btnduesend {
        display :  none;
    }
}

</style>
</form>
<script>
function myFunction() {
    window.print();
}
</script>
<script type="text/javascript">
	// update_back_dues start--------
function update(id){	
	//alert(id);
	var sta = $('#status'+id).val();
			
$.post( "ajax.php", {type: "cheque_status" ,	
								cheque_s: sta,
								id:id} , function( data ) {
									alert(data);
																		
		});
}

function updatepaymode(id){
    var mode = $('#payment_status'+id).val();

        $.post( "ajax.php", {type: "update_mode" ,	
								mode: mode,
								id:id} , function( data ) {
									alert(data);
		});

}

function updatereceiptstatus(id){

    var status = $('#status'+id).val();

    var r = confirm("Do you really want to delete this receipt?");
        if (r == true) {
            $.post( "<?php echo URL_ROOT ?>print/ajax.php", {
        			type: "deletepocketreceipt",
        			rid: id,
        			idno: "<?php echo $_GET['id'] ?>",
        			status: status
        		} , function( data ) {
                    // alert(data);

        	});
        // 	location.reload();
        location.reload(true);
        }
location.reload();
}

// update_back_dues end
</script>