<?php
if(basename($_SERVER['PHP_SELF']) == 'deporepo.php') 
  $fn=" class='current'";
include'header.php';
include'connection.php';
$custo=$sso=$condi='';
$conde='';
$p=0;
$dato=$datos=$Date;

// search request by date
if(isset($_POST['search']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$pg=$_POST['pg'];
			$custo=$_POST['custo'];
			$sso=$_POST['sso'];
				$p=1;
		}
		
// Update date
if(isset($_POST['change']))
		{
			$dato=$_POST['dato'];
			$datos=$_POST['datos'];
			$custo=$_POST['custo'];
			$code=$_POST['code'];
			$p=$_POST['p'];
			$dte=$_POST['dte'];
			$sso=$_POST['sso'];

			$so=mysqli_query($conn, "UPDATE `deposit` SET `Date`='$dte' WHERE `Number`='$code' ORDER BY `Number` ASC LIMIT 1");
		}

		if($dato==$datos)
			$mpri="ON $dato";
		else
			$mpri="FROM $dato TO $datos";
?>

<div class="container-fluid main-content">
        <div class="page-title hidden-print">
          <h2 style='margin-top:-20px; margin-bottom: 5px; color:#ffcc33'>
        Bank Operations
          </h2>
                 </div>
     
         <div class="row">
  <div class="col-lg-2 hidden-print">
   
     <ul class="list-group"> 
      
    <li class="list-group-item">
	  <a href="bope.php">
                <p>
                <i class="lnr lnr-briefcase"></i>&nbsp;Bank Operation
                </p>
              </a></li>   

    <li class="list-group-item">
	  <a href="deposit.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Bank Slip Record
                </p>
              </a></li>  

	 <li class="list-group-item active">
	  <a href="deporepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Deposit Report
                </p>
              </a></li>
      
    <li class="list-group-item">
	  <a href="withrepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Withdrwal Report
                </p>
              </a></li> 
      
    <li class="list-group-item">
	  <a href="staterepo.php">
                <p>
                <i class="lnr lnr-menu-circle"></i>&nbsp;Statement Report
                </p>
              </a></li>                     
            </ul>
  </div>
       
        <div class="col-lg-10">
                  <div class="row">
        <form action="" method="post" class="form-horizontal "> 
         
           <div class="col-lg-2"> </div>
         
           <div class="col-lg-2"><select class="form-control" name="sso">
			 <?php
		echo"<option value='' selected='selected'> SELECT SOURCE </option>";
		$doi=mysqli_query($conn, "SELECT `Source` FROM `deposit` WHERE `Status`='0' AND `Source` != '' AND `Operation`='DEPOSIT' GROUP BY `Source` ORDER BY `Source` ASC");
			while($roi=mysqli_fetch_assoc($doi)){
				$so=$roi['Source'];
				if($sso==$so)
					$s="selected";
				else
					$s="";
			echo"<option value='$so' title='$so' $s> $so </option>";
			}
						?>
			   </select>  </div>
          
   <div class="col-lg-7 hidden-print"><div class="col-lg-4"> 					
					  <select class="form-control" name="custo">
			 <?php
				echo"<option value='' selected='selected'> SELECT ACCOUNT </option>";
		$doi=mysqli_query($conn, "SELECT *FROM `baccount` ORDER BY `Number` ASC");
			while($roi=mysqli_fetch_assoc($doi)){
				$nu=$roi['Number'];
				$fna=$roi['Bank'];
				$acco=$roi['Account'];
				if($custo==$nu)
					$s="selected";
				else
					$s="";
			echo"<option value='$nu' title='$purpo' $s> $fna $acco </option>";
			}
						?>
			   </select>  
					   </div>
             <div class="col-lg-3"> 
           <div class="input-group date" data-provide="datepicker">
      <input class="form-control form-center" name="dato" type="text" value="<?php echo $dato ?>" onkeypress='return isNumberKey(event)' required>
	  <span class="input-group-addon"><i class="lnr lnr-calendar-full"></i></span>
			</div></div>


		  <div class="col-lg-3"> 
           <div class="input-group date" data-provide="datepicker">	
      <input class="form-control form-center" name="datos" type="text" value="<?php echo $datos ?>" onkeypress='return isNumberKey(event)' required>
	  <span class="input-group-addon"><i class="lnr lnr-calendar-full"></i></span>
              </div></div>                     
                       
                       <div class="col-lg-2"><?php echo"<input type='hidden' name='pg' value='$pg'>"; ?>
                        <button class="btn  btn-primary btn-block" type="submit" name="search"><i class="lnr lnr-magnifier"></i> Search</button>
                   
					  </div>
                         </div></form>               
            </div>
               <?php
					if($custo){
						$conde="AND `Account`='$custo'";
				$doin=mysqli_query($conn, "SELECT *FROM `baccount` WHERE `Number`='$custo' ORDER BY `Number` ASC");
						$roi=mysqli_fetch_assoc($doin);
							$bank=$roi['Bank'];
							$account=$roi['Account'];
					  }
					  else{
						  $bank=$account='';
					  }
					  
					  if($sso){
					      $condi="AND `Source`='$sso'";
					  }

				if($p)
		$dok=mysqli_query($conn, "SELECT *FROM `deposit` WHERE `Status`='0' AND `Date` BETWEEN '$dato' AND '$datos' AND `Operation`='DEPOSIT' $conde $condi ORDER BY `Number` ASC LIMIT 1000");
				else
		$dok=mysqli_query($conn, "SELECT *FROM (SELECT *FROM `deposit` WHERE `Status`='0' AND `Date` <= '$Date' AND `Operation`='DEPOSIT' $conde $condi ORDER BY `Number` DESC LIMIT 20) SUB ORDER BY `Date` ASC");
				if($fo=mysqli_num_rows($dok)){
				?>
                 
             <div class="divFooter"><center><u><b>DEPOSIT REPORT <?php echo $mpri ?></b></u></center></div>
             <div class="row">
            <div class="col-lg-12">
             <span> &nbsp;&nbsp; Total Records Found : <b><?php echo" $fo " ?></b></span>
			 <span class="pull-right hidden-print"><?php echo"$bank   $account"; ?>&nbsp;&nbsp;
			 <a href="#" onclick="return window.print()" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top'>
			 <i class="lnr lnr-printer"></i></a></span>
            <div class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix">

								<table class="table table-striped table-hover">     
                                      <thead>
                    <tr role="row">
                     <th class="hidden-xs" style='padding:1px;'>&nbsp;&nbsp;&nbsp;No&nbsp;&nbsp;</th>
					 <th width='8%' style='padding:1px;'><div align='center'> Date </th>
                       <th style='padding:1px;'>&nbsp;&nbsp;Source </th><th style='padding:1px;'>&nbsp;&nbsp;&nbsp;&nbsp;Destination </th>
					   <th style='padding:1px;'>&nbsp;&nbsp;&nbsp;&nbsp;Account </th><th style='padding:1px;'>&nbsp;&nbsp;&nbsp;Purpose </th>
					   <th style='padding:1px;'><div align='center'>&nbsp;&nbsp;&nbsp;Description </th>
					   <th style='padding:1px;'><div align='center'>&nbsp;&nbsp;Amount </th></tr></thead>
                                        <tbody>
					<?php
								$i=1;			$tpin=$tpout=0;
						while($rok=mysqli_fetch_assoc($dok)){
				$code=$rok['Number'];
				$cheno=$rok['Refer'];
			$sour=$rok['Customer'];
			$dte=$rok['Date'];
			$dest=$rok['Source'];
			$bna=$rok['Operation'];				
			$pda=$rok['Descri'];				
			$item=$rok['Item'];
			$valide=$rok['Valid'];
			$reco=$rok['Record'];
			$acco=$rok['Account'];
			if($dest=='DIRECT')
				$dest="CASH";

			$doi=mysqli_query($conn, "SELECT *FROM `baccount` WHERE `Number`='$acco' ORDER BY `Number` ASC");
				$roi=mysqli_fetch_assoc($doi);
					$fna=$roi['Bank'];
					$acco=$roi['Account'];
												$pin=$pout=0;
			$amo=$rok['Amount'];								$amoo=number_format($amo, 2);
			$stl="padding:1px; font-size:12px;";

						$pin=$amo;				$pino=number_format($pin, 2);					$pouto=number_format($pout, 2);

				print("<tr><td class='hidden-xs' style='$stl $clr'><div align='right'>$i&nbsp;&nbsp;");
				
				
				// *********************** Change Date ************************************************
			echo"<div class='col-lg-7'><div class='modal fade' id='ratepModal$i' tabindex='-1' role='dialog' aria-labelledby='exampleModalLabel' aria-hidden='true'>
  <div class='modal-dialog' role='document'><div class='modal-content'><div class='modal-header text-left'>
        <h5 class='modal-title' id='exampleModalLabel'> Change Date <span class='pull-right'> <b>Amount:</b> $amoo &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>Date:</b> $dte </span></h5>

      </div><form action='' method='post'>
      <div class='modal-body text-left' style='height:100px;'>
			<div class='row'>
		<div class='col-md-12'>
			<div class='col-md-6 text-right' style='padding-top:30px;'><b> Due Date </b>
            </div>


	<div class='col-md-5'><br><div class='input-group date' data-provide='datepicker'>
	<input name='dte' class='form-control text-center' type='text' onkeyup='format(this);' onkeypress='return isNumberKey(event)' title='Date' data-toggle='tooltip' data-placement='top' value='$dte' required><span class='input-group-addon'><i class='lnr lnr-calendar-full'></i></span>
  </div>

</div>

			</div></div><br><font color='teal'>$pda</font></div><hr>
			<input type='hidden' name='code' value='$code'>
			<input type='hidden' name='custo' value='$custo'>
	  <input type='hidden' name='dato' value='$dato'>
	  <input type='hidden' name='datos' value='$datos'>
	  <input type='hidden' name='p' value='$p'>
	  <input type='hidden' name='custo' value='$custo'>
      <div class='modal-footer' style='margin-top:-10px; height:50px; padding-top:5px; border:0px solid blue;'>
        <button type='button' class='btn btn-sm btn-danger' data-dismiss='modal' style='width:80px;'> CANCEL </button>
        <button type='submit' name='change' class='btn btn-sm btn-success' style='width:80px;'> UPDATE </button>
      </div></form>
    </div>
  </div>
</div>";
	
	if($_SESSION['Cpd']){
	    $dbl="data-placement='top' data-toggle='modal' data-target='#ratepModal$i'";
	}
	else{
	    $dbl='';
	}


print("</td><td style='$stl $clr'><div align='center'>&nbsp;
			<a href='#' $dbl>$dte</a>&nbsp;</td><td style='$stl $clr'>&nbsp; $dest </td>
						<td style='$stl $clr'>&nbsp; $sour </td><td style='$stl $clr'><div align='left'> $acco &nbsp;</td>
						<td style='$stl $clr'><div align='left'>&nbsp; $bna </td><td style='$stl $clr'><div align='left'> $pda </td>
						<td style='$stl $clr'><div align='right'> $pino &nbsp;</td></tr>");
									$i++;					$tpin+=$pin;				$tpout+=$pout;
						}
						$tp=number_format($tpin, 2);		
						$tr=number_format($tpout, 2);		
						$tb=number_format($tb, 2);	
						?>
						
                    </tbody>
					 <thead>
					<tr><th class='hidden-xs'> </th><th colspan='6'><div align='center'> Total Amount </th><th><div align='right'><?php echo $tp ?></th>
								</tr></table> 
								</div></div>
								<span class="pull-right hidden-print">
			 <a href="#" onclick="return window.print()" class="hidden-print" title='Click to print' data-toggle='tooltip' data-placement='top'>
			 <i class="lnr lnr-printer"></i></a></span><br><br><br>

			<?php
				}
				else{
						echo"<div class='row'>
            <div class='col-lg-12' style='margin-top:-20px;'>
             <span> &nbsp;&nbsp; Total Records Found : <b> 0 </b></span>
            <div class='widget-container fluid-height clearfix'>
            <div class='widget-content padded clearfix'>
			<br><br><br><br><br><br>
	<div style='text-align:center; font-size:24px; color:#ff9999'>Report not available on selected date </div><br><br><br><br><br><br>";
					}
			
					?>
                                      
                
              </div>
            </div></div>
                  </div>
   <?php
   include'footer.php';
   ?>