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

class FinanceUserList extends Page
{
  var $FullTitle = 'Seznam účastníků sítě';
  var $ShortTitle = 'Seznam účastníků';

  function Show()
  {
    $Finance = $this->System->Modules['Finance'];
    $this->System->Modules['Finance']->LoadTariffs(1);
    if(!$this->System->Modules['User']->CheckPermission('Finance', 'SubjectList')) return('Nemáte oprávnění');

  // Seznam členů
    $Output = 'Seznam účastníků:<br>'.
    '<table class="WideTable">'.
    '<tr><th>Zástupce</th><th>Subjekt</th>';
    //<th>Cena za zařízení [Kč]</th>
    $Output .= '<th>Měsíční poplatek [Kč]</th><th>Stav účtu [Kč]</th><th>Běžící tarif</th><th>Příští tarif</th><th>Poznámky</th><th>WWW</th></tr>';
    $TotalDevice = 0;
    $TotalMonth = 0;
    $TotalCash = 0;
    $DbResult = $this->Database->query('SELECT MonthlyTotal, Cash, Subject.Id, Subject.WWW, Subject.Note, Subject.Name, NetworkDevice, InternetTariffCurrentMonth, InternetTariffNextMonth, User.Name AS FullName FROM MemberPayment LEFT JOIN Member ON Member.Id=MemberPayment.Member LEFT JOIN Subject ON Subject.Id=Member.Subject JOIN User ON User.Id=Member.ResponsibleUser ORDER BY FullName');
    while($Row = $DbResult->fetch_assoc())
    {
     //$Row['cash'] = $Row['AdvancesIn'] - $Row['AdvancesOut'] + $Row['Liabilities'] - $Row['Claims'];
      $TotalCash += $Row['Cash'];
      if($Row['Cash'] < 0) $Row['Cash'] = '<span style="color: red;">'.$Row['Cash'].'</span>';
      $Tarif = $Finance->Tariffs[$Row['InternetTariffCurrentMonth']]['Name'];
      $PristiTarif = $Finance->Tariffs[$Row['InternetTariffNextMonth']]['Name'];
      $Output .= '<tr><td>'.$Row['FullName'].'</td><td><a href="user_state.php?Subject='.$Row['Id'].'">'.$Row['Name'].'</a></td>';
      //<td align="right">'.$Row['network_device'].'</td>
      $Output .= '<td align="right">'.$Row['MonthlyTotal'].'</td><td align="right">'.$Row['Cash'].'</td><td align="center">'.$Tarif.'</td><td align="center">'.$PristiTarif.'</td><td>'.$Row['Note'].'</td><td>'.$Row['WWW'].'</td></tr>';
      $TotalDevice += $Row['NetworkDevice'];
      $TotalMonth += ($Row['MonthlyTotal']);
    }
    $Output .= '<tr><td><strong>Celkem</strong></td><td>&nbsp;</td>';
    //<td align="right"><strong>'.$TotalDevice.'</strong></td>
    $Output .= '<td align="right"><strong>'.$TotalMonth.'</strong></td><td align="right"><strong>'.$TotalCash.'</strong></td><td align="right">&nbsp;</td><td align="right">&nbsp;</td></tr>';
    $Output .= '</table>';
    return($Output);
  }
}

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

?>
