<?php
include_once('../global.php');

class FinanceConsumption extends Page
{
  var $FullTitle = 'Spotřeba energie';
  var $ShortTitle = 'Spotřeba';

  function Show()
  {
    $Finance = $this->System->Modules['Finance'];

    // Seznam segmentů a zařízení
    $Output = 'Spotřeba zařízení jednotlivých segmentů:<div align="center"><table class="WideTable"><tr><th>Jméno segmentu</th><th>Spotřeba [W]</th><th>Cena [Kč/měsíc]</th></tr>';
    $CelkovaSpotreba = 0;
    $DbResult = $this->Database->query("SELECT * FROM network_segments");
    while($Row = $DbResult->fetch_array())
    {
      $DbResult2 = $this->Database->query("SELECT SUM(consumption) FROM network_devices WHERE segment=".$Row['id']." AND used=1");
      $Row2 = $DbResult2->fetch_array();
      $CelkovaSpotreba = $CelkovaSpotreba + $Row2[0];
      $Output .= '<tr><td>'.$Row['name'].'</td><td align="right">'.$Row2[0].'</td><td align="right">'.$this->System->Modules['Finance']->W2Kc($Row2[0]).'</td></tr>';
    }
    $Output .= '<tr style="font-weight: Bold;"><td><strong>Celkem</strong></td><td align="right">'.$CelkovaSpotreba.'</td><td align="right">'.$this->System->Modules['Finance']->W2Kc($CelkovaSpotreba).'</td></tr>';
    $Output .= '</table></div>';
    $Output .= 'Dohodnutá cena za jednu kWh: <strong>'.$Finance->kWh.' Kč</strong><br />';
    return($Output);
  }
}

$System->AddModule(new FinanceConsumption());
$System->Modules['FinanceConsumption']->GetOutput();

?>
