<?php 
$pgMod="faculty_inventory_dcr";
$pgAct="view";
?>
<style>.top-bar-minimize{display:none;}
thead, tfoot {display: table-header-group;}
.top-bar+.well,.accordion .accordion-heading+.accordion-body{display: inline-block !important;width: 100% !important;overflow: inherit !important;} 
.dynamic{display:none} 
table td {
padding: 6px !important;
}
legend{line-height: 16px;font-weight:100;}
</style> 


<script>
$(document).ready(function(){
var rows = $('table.table tr');
var Cash = rows.filter('.Cash');
var Cheque = rows.filter('.Cheque');
var NEFT = rows.filter('.NEFT');
var empty = rows.filter('.empty');

$('#Cash').click(function() {
    Cheque.hide();
    NEFT.hide();
    empty.hide();
    Cash.show();
});

$('#Cheque').click(function() {
    Cash.hide();
    NEFT.hide();
    empty.hide();
    Cheque.show();	
});
$('#NEFT').click(function() {
    Cash.hide();
    Cheque.hide();
    empty.hide();
    NEFT.show();
});
$('#showAll').click(function() {
    Cash.show();
    Cheque.show();
    empty.show();
	 NEFT.show();
	
});
});
</script>
<form method="get" action="">
    <input type="hidden" name="src" value="Account" />
    <input type="hidden" name="page_id" value="<?php echo $pgMod; ?>" />
	<div class="row-fluid">
        <div class="span12">
            <div class="well no-padding">
                <div class="controls controls-row">
                    <div class="control-group span4">
                        <label class="control-label" for="class">From Date</label>
                        <div class="controls" style=" margin-left: 81px;  !important;" >
                                  <select class="span3" name="fdate"  id="date" style="width: 65px !important;">
                                    <option value="">Date</option>
                                    <?php
									$ndate=date("d");
									$mdate=date("m");
									$ydate=date("Y");
                                    for($m = 01;$m <= 31; $m++){ 
                                        $selected="";
										if($_GET["fdate"]==$m)
										{
											$selected=" selected ";
										}
										if($ndate==$m)
										{
											$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                                <select class="span5" name="fmonth" id="fmonth" style="width: 90px !important;">
                                    <option value="">Month</option>
                                 <?php
                                    for($m = 1;$m <= 12; $m++){ 
                                        $newDate=date("Y")."-".$m."-1";
                                        $month =  date("F",strtotime($newDate));//."(".($ij+3).")";
                                        //$month =  date("F", mktime(0, 0, 0, $m)); 
                                        $selected="";
                                        if($_GET["fmonth"]==$m)
										{
											$selected=" selected ";
										}
										
										if($mdate==$m)
										{
											$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$month</option>";
                                    }
                                 ?> 
                                </select>
                                <select class="span4" name="fyear" id="fyear" style="width: 73px !important;">
                                    <option value="">Year</option>
                                    <?php
                                    for($m = 2013;$m <= 2050; $m++){  
                                        $selected="";
                                        if($_GET["fyear"]==$m)
										{	
										$selected=" selected ";
										}										
										if($ydate==$m)
										{	
										$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                            </div>
                    </div>
                    <div class="control-group span4">
                        <label class="control-label" for="medium">To date</label>
                        <div class="controls" style=" margin-left: 81px;  !important;">
                                 <select class="span3" name="tdate" id="tdate" style="width: 65px !important;">
                                    <option value="">Date</option>
                                    <?php
                                    for($m = 01;$m <= 31; $m++){ 
                                         $selected="";
										 if($_GET["tdate"]==$m)
										 {
											 $selected=" selected ";
										 }
										 if($ndate+1==$m)
										{
											$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                                <select class="span5" name="tmonth" id="tmonth" style="width: 90px !important;">
                                    <option value="">Month</option>
                                 <?php
                                    for($m = 1;$m <= 12; $m++){ 
                                        $newDate=date("Y")."-".$m."-1";
                                        $month =  date("F",strtotime($newDate));//."(".($ij+3).")";
                                        //$month =  date("F", mktime(0, 0, 0, $m)); 
                                        $selected="";if($_GET["tmonth"]==$m)
										{
										$selected=" selected ";
										}
										if($mdate==$m)
										{
											$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$month</option>";
                                    }
                                 ?> 
                                </select>
                                <select class="span4" name="tyear" id="tyear" style="width: 73px !important;">
                                    <option value="">Year</option>
                                    <?php
                                    for($m = 2013;$m <= 2050; $m++){  
                                         $selected="";if($_GET["tyear"]==$m)
										 {	 
										 $selected=" selected ";
										 }
										 if($ydate==$m)
										{
											$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                            </div>
                    </div>
                    <div class="control-group span2">
                    	<select class="span6" name="location" id="location">
                            <option value="">All</option>
                           <?php 
                                $location=$db->getRows("select * from location where school_id='".$_SESSION["admin"]["school_id"]."'");
                                if(is_array($location) && count($location)>0){
                                    foreach($location as $loc){
                                        ?>
                                        <option <?php if($loc["id"]==$_GET["location"])echo 'selected';?> value="<?php echo $loc["id"] ?>">
                                            <?php echo $loc["name"] ?>
                                        </option>
                                        <?php
                                    }
                                }
                            ?>
                        </select>
                    </div>
					
					<!--<div class="control-group span2">
                    	<select class="span9" name="user" id="user">
                            <option value="">All User</option>
                            <?php 
                                $user=$db->getRows("select * from users where school_id='".$_SESSION["admin"]["school_id"]."'");
                                if(is_array($user) && count($user)>0){
                                    foreach($user as $usr){
                                        ?>
                                        <option <?php if($usr["id"]==$_GET["user"])echo 'selected';?> value="<?php echo $usr["id"] ?>">
                                            <?php echo $usr["name"] ?>
                                        </option>
                                        <?php
                                    }
                                }
                            ?>
                        </select>
                    </div>-->
					
					<div class="control-group span2">
					<?php 
                                $user=$db->getRows("select * from users where school_id='".$_SESSION["admin"]["school_id"]."'");
                                if(is_array($user) && count($user)>0){
                                    foreach($user as $usr){
                                        ?>
					<input type="checkbox" name="user1[]" value="<?php echo $usr["id"] ?>"><?php echo $usr["name"] ?>
					<br>
					<?php
                                    }
                                }
                            ?>
					 </div>
					
                    <div class="control-group span10" style="margin-top:-22px; margin-left:2px">


                  <button type="submit" name="inventory" class="btn-classic margin">Inventory DCR</button>
                  
                   <button class="btn btn-danger" onclick="exportTableToExcel('tblData', 'Collection Sheet')" style="float:right;margin-top:10px;">Excel</button>
                   
                   <button type="button" onclick="printDiv('printDiv')" class="btn btn-danger" style="float:right;margin:0px 10px 0px 10px;margin-top:10px;">Print</button>
			   
                   <button onclick="SMSComplete('completeFeeShw','DCRSMS')" style="float:right;margin-top:10px;" type="button" class="btn btn-primary">SMS</button>

                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<div id="printDiv">
<?php

if(isset($_GET["fyear"]) && trim($_GET["fyear"])!="" && isset($_GET["fmonth"]) && trim($_GET["fmonth"])!="" && isset($_GET["fdate"]) && trim($_GET["fdate"])!="" && isset($_GET["tyear"]) && trim($_GET["tyear"])!="" && isset($_GET["tmonth"]) && trim($_GET["tmonth"])!="" && isset($_GET["tdate"]) && trim($_GET["tdate"])!=""){
	$fdate=$_GET["fyear"]."/".$_GET["fmonth"]."/".$_GET["fdate"];
	$tdate=$_GET["tyear"]."/".$_GET["tmonth"]."/".$_GET["tdate"];
	if($_GET["fdate"]==7&&$_GET["fmonth"]==14){
		echo "No records available";
	}else{
		
		if(isset($_REQUEST["delete_receipt"])){
		/*	
		$whereLocation="";
		if(isset($_GET["location"]) && $_GET["location"]!=""){
			$whereLocation=" and location='".$_GET["location"]."' ";
		}*/
		//$aryFeeType=$db->getRows("select distinct(type) from extrafee_type where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 order by type");
		$aryStudentList=$db->getRows("select name,fname,admissionno,idno,class,location from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 $whereLocation and issue_TC=0");
		
		
	    $f=date("Y-m-d",strtotime($fdate));
		$t= date("Y-m-d",strtotime($tdate));
		
		  $del_rec=$db->getRows("select * from receipt_delete where school_id='".$_SESSION["admin"]["school_id"]."' and udate between '$f' and '$t'  ");
				
		//print_r($del_rec);
		
		//echo $db->getErMsg().$db->getLastQuery();
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			$tndate = date('Y/m/d', strtotime('-1 days',strtotime($tdate)));
			//echo $tndate." ".$fdate
			?>
            <center><h5><p style="float:right">Collection Date: 
			<?php if(strtotime($tndate)==strtotime($fdate)){
			echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
			else echo date("d-M-Y",strtotime($fdate)) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> <p>Daily Collection Report</p>	</h5></center>
			<table class="table" cellspacing="0" cellpadding="0" border="1" id="tblData">
				<thead>
				<tr style="cursor:pointer">
                	<td>S.No</td>
					<!--<th>idno </th>-->
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Admission no</th>
					<td>Class</th>
				
                    <td>Receipt No</td>
                    <!--<th>udate</th>
                    <th>detail</th> -->
					<td>amount</th>
					
					
				</tr>
				</thead>
				<tbody>
					<?php
						//echo $db->getErMsg();
						foreach($del_rec as $del_data){ $s++;
						
						$student_details=$db->getRow("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and idno='$del_data[idno]' and session='".$_SESSION["admin"]["session"]."'  ");
						//print_r($student_details);
						
						//echo  "select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and idno='$del_data[idno]' and session='".$_SESSION["admin"]["session"]."'  ";
						?>
						<tr>
                        	<td><?php echo $s; ?></td>
							<!--<td><?php //echo $del_data[idno] ?></td>-->
							<td><?php echo $student_details[name] ?></td>
							<td><?php echo $student_details[fname] ?></td>
							<td><?php echo $student_details[admissionno] ?></td>
							<td><?php echo $student_details['class'] ?></td>
							<td><?php echo $del_data[id] ?></td>
                           <!-- <td><?php echo $del_data[udate] ?></td>
                            <td><?php echo $del_data[detail]  ?></td> -->
							<td><?php  echo $del_data[amount] ?></td>
							
						</tr>
						<?php } ?>

				</tbody>

			</table>  
            Print Date : <?php echo date('d-M-Y'); ?>
			<?php
		}else{
			echo "No record found<br />".$db->getErMsg();
		}
	}
	

elseif(isset($_REQUEST["inventory"])){

	$pmode  = array();
	$ptotal = array();
	$pusers = array();
    $temp   = array();
    $tempuser = array();

		$overAllTotal=0;

		$inventoryReceipt = $db->getRows("SELECT *, r.id as rid, r.rid as rrid, i.name as item FROM faculty_inventory_receipt r left join inventory i on r.inventory_id=i.id WHERE r.school_id='".$_SESSION["admin"]["school_id"]."' and issue_date between '$fdate' and '$tdate' GROUP BY r.rid");
// 		echo $db->getErMsg().$db->getLastQuery();
		if(is_array($inventoryReceipt) && count($inventoryReceipt)>0){
			$tndate = date('Y/m/d', strtotime('-1 days',strtotime($tdate)));

			?>
            <center><h5><p style="float:right">Collection Date: 
			<?php if(strtotime($tndate)==strtotime($fdate)){
			echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
			else echo date("d-M-Y",strtotime($fdate)) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> <p>Inventory Collection Report</p>	</h5></center>

            <a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=collection_sheet&fdate=$_GET[fdate]&fmonth=$_GET[fmonth]&fyear=$_GET[fyear]&tdate=$_GET[tdate]&tmonth=$_GET[tmonth]&tyear=$_GET[tyear]&location=$_GET[location]&inventory=&head_name=$_GET[head_name]&class=$_GET[class]&head_type=$_GET[head_type]"; ?>" target="_blank" >Full Screen</a>

            <style>
                @media print {
            
                    #myPrntbtn {
                        display :  none;
                    }
            
                }
            </style>



			<table class="table" cellspacing="0" cellpadding="0" border="1" id="tblData">
				<thead>
				<tr style="cursor:pointer">
                	<th>S.No</th>
					<th>Name</th>
                    <th>Father Name</th>
                    <th>Department</th>
					<th>Mobile</th>
					<th>Receipt No.</th>
					<th>payment Mode</th>
					<th>Item</th>
					<th>Quantity</th>
                    <th>Amount</th>
                    <th>Issue Date</th>
				</tr>
				</thead>
				<tbody>
					<?php $s=1;
						foreach($inventoryReceipt as $inv){
							$student=$db->getRow("select * from staff where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$inv[idno]."' ");
                            $total = $db->getVal("select sum(total_amount) from faculty_inventory_receipt where rid='".$inv["rrid"]."' ");
                            
                            $usr1 = $db->getVal("select name from users where id='$inv[added_by]'"); 
                            array_push($pusers, $usr1);
                            if(in_array($usr1, $tempuser)){
                                 
                                } else { 
                                    array_push($tempuser,$usr1);  
                                }
                            if(count($student)>1){
                            ?>
						<tr>
                        	<td><?php echo $s; ?></td>
							<td><?php echo $student["name"] ?></td>
                            <td><?php echo $student["fname"] ?></td>
                            <td><?php echo $student["department"] ?></td>
							<td><?php echo $student["mobile"] ?></td>
							<td><?php echo $inv["rrid"] ?></td>
							<td><?php $m = $inv["payment_mode"];
							    echo $m;
							    $pm = $m;
       							 array_push($pmode, $inv["payment_mode"]);
           							 
   		                         if(in_array($pm, $temp)){
    
                                } else {
                                    array_push($temp,$pm);
                                }
							?></td>
                            <td><?php echo $inv["item"] ?></td>
                            <td><?php echo $inv["num_item"]; ?></td>
                            <td><?php echo $total; 
                            array_push($ptotal, $total);
                            $overAllTotal+=$total; ?></td>
							<td><?php echo date("d-m-Y",strtotime($inv['issue_date'])); ?></td>
						</tr>
						<?php
						$s++;
                            }
						}
					?>
				</tbody>
				
				<tfoot>
					<tr>
					    <td colspan="9">Total</td>
					    <td><? echo $overAllTotal; ?></td>
					    <td></td>
					</tr>
				</tfoot>
			</table>  
			
			<br><br>
			
	    <h5>Counterwise Fees Collection Details</h5>
		<table class="table" style="text-align:center;" border="1">
            <thead>
		    <tr>
		        <th></th>
		        <th>Collected By</th>
		        <?php
		            foreach($temp as $pm1){
		                echo "<th>$pm1</th>";
		            }
		        ?>
		        <th>Total</th>
		    </tr>
		    </thead>
		    <tbody>
		    <?php $totalfeescollected = 0; $registrationtotal = 0;
            $j = 0;
            $valary = array(); 
            $feetotal = 0;

		    foreach($tempuser as $row){ ?> 
		    <tr>
		        <td></td>
		        <td>
		            <?php echo $row; $j++; ?>
		        </td>

		        <?php   $m = 0;
        		        $value = array();
                        $rowtotal = 0; 

    		            foreach($pmode as $pt){

                            if($row == $pusers[$m]){
    		                $j = array_search($pt, $temp);
                                $value[$j] += $ptotal[$m];
                                $valary[$j] += $ptotal[$m];
    		                }
    		                $m++;
    		            }

                        $n = 0;
    		            foreach($temp as $vs1){
    		                
    		                if($value[$n]){
    		                echo "<td>$value[$n]</td>";
    		                $rowtotal += $value[$n];
    		                } else echo "<td>0</td>";
    		                $n++;
    		            }
		        ?>
		        <td><?php echo $rowtotal; ?></td>
		    </tr>
		    <?php } ?>
		    </tbody>
		    
		    <tfoot>
		        <tr>
		            <td>Total</td>
		            <td></td>
                    <?php $nm = 0;
		            foreach($temp as $vs1){
		                echo "<td>$valary[$nm]</td>";
		                $feetotal += $valary[$nm];
		                $nm++;
		            }	?>
		            <td><?php echo $feetotal; ?></td>
		        </tr>
		    </tfoot>
		</table>
			
            Print Date : <?php echo date('d-M-Y'); ?>
            
            
            
            
			<?php
		}else{
			echo "No record found<br />".$db->getErMsg();
		}
}


	}
}else{
	echo "Please select date First";
}

?>
</div>
<script type="text/javascript">
	$(document).ready(function(e) {
		var oTable = $('.table').dataTable( {
			"bPaginate": false,
			"bLengthChange": true,
			"bFilter": true,
			"bSort": true,
			"bInfo": true,
			"fnRowCallback" : function(nRow, aData, iDisplayIndex){
                $("td:first", nRow).html(iDisplayIndex +1);
               return nRow;
            },
			"bAutoWidth": false
		});
	});
	
	function SMSComplete(valueid,act){
	$(this).hide();
	var Fee=$("#"+valueid).html();
	var fdate='<?php if($_GET["fdate"]!="")echo $_GET["fdate"];else echo "0" ?>';
	var fmonth='<?php if($_GET["fmonth"]!="")echo $_GET["fmonth"];else echo "0" ?>';
	var fyear='<?php if($_GET["fyear"]!="")echo $_GET["fyear"];else echo "0" ?>';
	var tdate='<?php if($_GET["tdate"]!="")echo $_GET["tdate"];else echo "0" ?>';
	var tmonth='<?php if($_GET["tmonth"]!="")echo $_GET["tmonth"];else echo "0" ?>';
	var tyear='<?php if($_GET["tyear"]!="")echo $_GET["tyear"];else echo "0" ?>';
	var cls='<?php if($_GET["class"]!="")echo $_GET["class"];else echo "0" ?>';
	$.post( "ajax.php", { type: act ,fee: Fee, fdate:fdate, fmonth:fmonth, fyear:fyear, tdate:tdate, tmonth:tmonth, tyear:tyear,class: cls  } , function( data ) {
	  	//$("#ins").html(data);getTotal();
		alert(data);
		$(this).show();
	});
    }
	</script>
    <style>
    tfoot{display: table-footer-group !important;}
    </style>
    
    
    
    
    <script>
    function exportTableToExcel(tableID, filename = '',e){
    
    var tableType = document.getElementById('tblData').getAttribute("data-tblname");

    var downloadLink;
    var dataType = 'application/vnd.ms-excel';
    var tableSelect = document.getElementById(tableID);
    var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');

    // Specify file name
    filename = filename?filename+'.xls':'excel_data.xls';
    
    // Create download link element
    downloadLink = document.createElement("a");
    
    document.body.appendChild(downloadLink);
    
    if(navigator.msSaveOrOpenBlob){
        var blob = new Blob(['\ufeff', tableHTML], {
            type: dataType
        });
        navigator.msSaveOrOpenBlob( blob, filename);
    }else{
        // Create a link to the file
        downloadLink.href = 'data:' + dataType + ', ' + tableHTML;
    
        // Setting the file name
        downloadLink.download = filename;
        
        //triggering the function
        downloadLink.click();
    }
    e.preventDefault();
}
</script>

<style>
     #myPrntbtn {
                margin-top:-80px;
        }
</style>
 

