<?php require_once('../Connections/lancrox.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
	
  $logoutGoTo = "index.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $theValue) : ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $theValue) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_Recordset1 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Recordset1 = $_SESSION['MM_Username'];
}
mysqli_select_db( $lancrox, $database_lancrox);
$query_Recordset1 = sprintf("SELECT * FROM admin WHERE username = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysqli_query( $lancrox, $query_Recordset1) or die(mysqli_error($GLOBALS["___mysqli_ston"]));
$row_Recordset1 = mysqli_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysqli_num_rows($Recordset1);

mysqli_select_db( $lancrox, $database_lancrox);
$query_inco = "SELECT SUM(amount*qty)amount,FROM_UNIXTIME(datein,'%Y-%m-%d') AS dated,FROM_UNIXTIME(datein,'%Y-%M-%d') AS dated1 FROM billing  WHERE amount>0 AND datein > 1521227752 GROUP BY  dated ORDER BY dated desc";
$inco = mysqli_query( $lancrox, $query_inco) or die(mysqli_error($GLOBALS["___mysqli_ston"]));
$row_inco = mysqli_fetch_assoc($inco);
$totalRows_inco = mysqli_num_rows($inco);

mysqli_select_db( $lancrox, $database_lancrox);
$query_depo = "SELECT SUM(deposit)deposit,FROM_UNIXTIME(datein,'%Y-%m-%d') AS dated,FROM_UNIXTIME(datein,'%Y-%M-%d') AS dated1 FROM billing  WHERE deposit>0  GROUP BY  dated ORDER BY dated desc";
$depo = mysqli_query( $lancrox, $query_depo) or die(mysqli_error($GLOBALS["___mysqli_ston"]));
$row_depo = mysqli_fetch_assoc($depo);
$totalRows_depo = mysqli_num_rows($depo);

$myamount = "SELECT sum(deposit)deposit, sum(amount*qty)amount from billing";
$rst_myamount=mysqli_query($lancrox, $myamount);
$num_myamount=mysqli_num_rows($rst_myamount); 
$row_myamount = mysqli_fetch_assoc($rst_myamount);
$d=1;
$d1=1;
$d2=1;
$d3=1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome</title>
<link href="../macss.css" rel="stylesheet" type="text/css" />
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
</head>

<body>
<div id="container">
  <div id="header">
    <div id="main">
      <div id="logo"></div>
      
      <? include('nav.php');?>
    </div>
  </div>
  <div id="thebody">
    <div id="mainbody">
      <p>Welcome <?php echo $row_Recordset1['fullname']; ?></p>
      <table width="100%" border="0" align="left" cellpadding="4">
        <tr>
          <td width="399"><strong>Income</strong></td>
          <td width="391"><strong>Deposit</strong></td>
        </tr>
        <tr>
          <td colspan="2"><form id="form1" name="form1" method="post" action="summary1.php">
            <strong>From</strong>
            <label for="day"></label>
            <span id="sprytextfield1">
            <label for="day"></label>
            <input name="day" type="text" id="day" size="10" placeholder="DD" />
            <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span><span class="textfieldMaxValueMsg">The entered value is greater than the maximum allowed.</span><span class="textfieldMinValueMsg">The entered value is less than the minimum required.</span><span class="textfieldMinCharsMsg">Minimum number of characters not met.</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span>
<label for="month"></label>
            <select name="month" id="month">
              <option value="Jan">Jan</option>
              <option value="Feb">Feb</option>
              <option value="Mar">Mar</option>
              <option value="Apr">Apr</option>
              <option value="May">May</option>
              <option value="Jun">Jun</option>
              <option value="Jul">Jul</option>
              <option value="Aug">Aug</option>
              <option value="Sep">Sep</option>
              <option value="Oct">Oct</option>
              <option value="Nov">Nov</option>
              <option value="Dec">Dec</option>
            </select>
            <label for="year"></label>
            <input name="year" type="text" id="year" size="12" placeholder="YYYY"/>
          &nbsp;&nbsp;<strong>TO </strong><span id="sprytextfield2">
          <label for="day2"></label>
          <input name="day2" type="text" id="day2" size="10" placeholder="DD" />
          <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span><span class="textfieldMinCharsMsg">Minimum number of characters not met.</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span><span class="textfieldMinValueMsg">The entered value is less than the minimum required.</span><span class="textfieldMaxValueMsg">The entered value is greater than the maximum allowed.</span></span>
          <select name="month2" id="month2">
            <option value="Jan">Jan</option>
            <option value="Feb">Feb</option>
            <option value="Mar">Mar</option>
            <option value="Apr">Apr</option>
            <option value="May">May</option>
            <option value="Jun">Jun</option>
            <option value="Jul">Jul</option>
            <option value="Aug">Aug</option>
            <option value="Sep">Sep</option>
            <option value="Oct">Oct</option>
            <option value="Nov">Nov</option>
            <option value="Dec">Dec</option>
      </select>
          <input name="year2" type="text" id="year2" size="12" placeholder="YYYY" />
          <label for="station"></label>
          <select name="station" id="station">
            <option value="ALL" selected="selected">ALL</option>
            <option value="HEAD OFFICE">HEAD OFFICE</option>
            <option value="IYABI">Iyabi</option>
            <option value="CAMP 74">CAMP 74</option>
          </select>
          <input type="submit" name="button" id="button" value="Search Deposit and Income" />
          </form></td>
        </tr>
        <tr>
          <td align="left" valign="top"><table width="100%" border="1" align="left" cellpadding="4">
            <tr>
              <td width="9%" bgcolor="#D6D6D6"><strong>SN</strong></td>
              <td width="12%" bgcolor="#D6D6D6"><strong>Date</strong></td>
              <td width="17%" bgcolor="#D6D6D6"><strong>Amount</strong></td>
            </tr><?php do { ?>
            <tr>
              
                <td><? echo $d++;?></td>
                <td><?php echo $row_inco['dated1']; ?></td>
                <td>N<?php echo number_format($row_inco['amount'],2); ?></td>
                <?php } while ($row_inco = mysqli_fetch_assoc($inco)); ?>
            </tr>
        </table></td>
          <td align="left" valign="top"><table width="100%" border="1" cellpadding="4">
            <tr>
              <td width="14%" bgcolor="#D6D6D6"><strong>SN</strong></td>
              <td width="19%" bgcolor="#D6D6D6"><strong>Date</strong></td>
              <td width="20%" bgcolor="#D6D6D6"><strong>Amount</strong></td>
            </tr><?php do { ?>
            <tr>
              
                <td><? echo $d1++;?></td>
                <td><?php echo $row_depo['dated1']; ?></td>
                <td>N<?php echo number_format($row_depo['deposit'],2); ?></td>
                <?php } while ($row_depo = mysqli_fetch_assoc($depo)); ?>
            </tr>
          </table></td>
        </tr>
       
        
      </table>
      <h2>&nbsp;</h2> 
    </div>
  </div>
</div>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "integer", {maxValue:31, minValue:1, minChars:1, maxChars:2, useCharacterMasking:true});
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "integer", {minChars:1, maxChars:2, minValue:1, maxValue:31, useCharacterMasking:true});
</script>
</body>
</html>
<?php
((mysqli_free_result($Recordset1) || (is_object($Recordset1) && (get_class($Recordset1) == "mysqli_result"))) ? true : false);

((mysqli_free_result($inco) || (is_object($inco) && (get_class($inco) == "mysqli_result"))) ? true : false);

((mysqli_free_result($depo) || (is_object($depo) && (get_class($depo) == "mysqli_result"))) ? true : false);
?>
