Changeset 636


Ignore:
Timestamp:
Jan 21, 2014, 12:02:53 AM (11 years ago)
Author:
chronos
Message:
  • Upraveno: Tabulka měsíčních přehledů přepracována s použitím obecných tříd. Nyní podporuje řazení a stránkování. Celkové součty byly odebrány.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/Global.php

    r635 r636  
    137137}
    138138
    139 class Pageing
     139class Paging
    140140{
    141141        var $TotalCount;
    142142        var $ItemPerPage;
    143143        var $Around;
     144        var $SQLLimit;
     145        var $Page;
    144146       
    145147        function __construct()
     
    147149                global $System;
    148150               
    149                 $this->ItemPerPage = 5; //$System->Config['Web']['ItemsPerPage'];
     151                $this->ItemPerPage = $System->Config['Web']['ItemsPerPage'];
    150152                $this->Around = $System->Config['Web']['VisiblePagingItems'];
    151153        }
  • trunk/Common/Setup/Setup.php

    r635 r636  
    210210    $Pageing = new Pageing();
    211211    $Pageing->TotalCount = count($this->System->ModuleManager->Modules);
    212     $Table = new Table();   
     212    $Table = new VisualTable();
    213213    $Table->SetColumns(array(
    214214      array('Name' => 'Name', 'Title' => 'Jméno'),
     
    235235      } else $Actions .= ' <a href="?action=modules&amp;op=install&amp;name='.$Module->Name.'">Instalovat</a>';
    236236   
    237       $Table->Cells[] = array($Module->Name,
     237      $Table->Table->Cells[] = array($Module->Name,
    238238        $Module->Creator, $Module->Version,
    239239        $Module->License, $YesNo[$Module->Installed],
  • trunk/Common/Table.php

    r635 r636  
    1111}
    1212
     13class Table
     14{
     15        function GetCell($Y, $X)
     16        {
     17                return('');
     18        }
     19
     20        function BeginRead()
     21        {
     22        }
     23       
     24        function EndRead()
     25        {
     26        }
     27       
     28  function RowsCount()
     29  {
     30        return(0);
     31  }
     32}
     33
     34class TableMemory extends Table
     35{
     36        var $Cells;
     37       
     38        function GetCell($Y, $X)
     39        {
     40                return($this->Cells[$Y][$X]);
     41        }
     42
     43  function RowsCount()
     44  {
     45        return(count($this->Cells));
     46  }
     47}
     48
     49class TableSQL extends Table
     50{
     51        var $Query;
     52        var $Database;
     53        var $Cells;     
     54       
     55        function GetCell($Y, $X)
     56        {
     57                return($this->Cells[$Y][$X]);
     58        }
     59       
     60        function BeginRead()
     61        {
     62                $this->Cells = array();
     63                $DbResult = $this->Database->query($this->Query);
     64                while($DbRow = $DbResult->fetch_row())
     65                {
     66                        $this->Cells[] = $DbRow;
     67                }
     68        }
     69       
     70        function EndRead()
     71        {
     72                $this->Cells = array();
     73        }
     74
     75  function RowsCount()
     76  {
     77        return(count($this->Cells));
     78  }
     79}
     80
    1381class TableColumn
    1482{
     
    1785}
    1886
    19 class Table extends Control
     87class VisualTable extends Control
    2088{
    2189  var $Cells;
    2290  var $Columns;
    23   var $OrderDirSQL;
     91  var $OrderSQL;
     92  var $OrderColumn;
     93  var $OrderDirection;
    2494  var $OrderArrowImage;
    2595  var $DefaultColumn;
    2696  var $DefaultOrder;
     97  var $Table;
    2798 
    2899  function __construct()
     
    31102       
    32103        $this->Columns = array();
    33         $this->Cells = array();
     104        $this->Table = new TableMemory();
    34105    $this->OrderDirSQL = array('ASC', 'DESC');
    35106    $this->OrderArrowImage = array($System->Link('/images/sort_asc.png'),
     
    57128          $Output = '<table class="WideTable">';
    58129          $Output .= $this->GetOrderHeader();
    59         foreach($this->Cells as $Row)
     130          $this->Table->BeginRead();
     131        for($Y = 0; $Y < $this->Table->RowsCount(); $Y++)
    60132        {
    61133            $Output .= '<tr>';
    62             foreach($Row as $Cell)
     134           
     135            for($X = 0; $X < count($this->Columns); $X++)
    63136            {
     137                $Cell = $this->Table->GetCell($Y, $X);
    64138                if($Cell == '') $Output .= '<td>&nbsp;</td>';
    65139                    else $Output .= '<td>'.$Cell.'</td>';
    66             }
     140            }       
    67141            $Output .= '</tr>';
    68142          }
     143          $this->Table->EndRead();
    69144          $Output .= '</table>';
    70145    return($Output);
     
    109184        else $Result .= '<th><a href="?'.SetQueryStringArray($QueryItems).'">'.$Column->Title.$ArrowImage.'</a></th>';
    110185    }
    111     $this->SQL = ' ORDER BY `'.$_SESSION['OrderCol'].'` '.$this->OrderDirSQL[$_SESSION['OrderDir']];
    112     $this->Column = $_SESSION['OrderCol'];
    113     $this->Direction = $_SESSION['OrderDir'];
     186    $this->OrderSQL = ' ORDER BY `'.$_SESSION['OrderCol'].'` '.$this->OrderDirSQL[$_SESSION['OrderDir']];
     187    $this->OrderColumn = $_SESSION['OrderCol'];
     188    $this->OrderDirection = $_SESSION['OrderDir'];
    114189 
    115190    return($Result);
  • trunk/Modules/Finance/MonthlyOverall.php

    r548 r636  
    1111    global $MonthNames;
    1212
    13     $Output = '<table class="WideTable"><tr><th>Rok</th><th>Měsíc</th><th>Internet [Kč]</th><th>Účastníků</th><th>Správa [Kč/účastníka]</th><th>Správa [Kč]</th><th>Spotřeba [Kč/kWh]</th><th>Spotřeba [Kč]</th><th>Obrat [Kč]</th><th>Průměrná cena [Kč/účastníka]</th><th align="center">Investice [Kč]</th></tr>';
     13    $Output = '';
     14    $Query = 'SELECT *, YEAR(`Date`) AS `Year`, MONTH(`Date`) AS `Month`, ROUND(`TotalPaid` / `MemberCount`) AS `PaidPerCustomer` FROM `FinanceMonthlyOverall`';
     15    $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$Query.') AS `T`');
     16    $DbRow = $DbResult->fetch_row();
     17    $Paging = new Paging();   
     18    $Paging->TotalCount = $DbRow[0];
     19    $Table = new VisualTable();
     20    $Table->SetColumns(array(
     21      array('Name' => 'Year', 'Title' => 'Rok'),
     22      array('Name' => 'Month', 'Title' => 'Měsíc'),
     23      array('Name' => 'Money', 'Title' => 'Internet [Kč]'),
     24      array('Name' => 'MemberCount', 'Title' => 'Zákazníků'),
     25      array('Name' => 'Administration', 'Title' => 'Správa [Kč/zákazníka]'),
     26      array('Name' => 'AdministrationTotal', 'Title' => 'Správa [Kč]'),
     27      array('Name' => 'kWh', 'Title' => 'Spotřeba [Kč/kWh]'),
     28      array('Name' => 'ConsumptionTotal', 'Title' => 'Spotřeba [Kč]'),
     29      array('Name' => 'TotalPaid', 'Title' => 'Obrat [Kč]'),
     30      array('Name' => 'PaidPerCustomer', 'Title' => 'Průměrná cena [Kč/účastníka]'),
     31      array('Name' => 'Investment', 'Title' => 'Investice [Kč]'),     
     32    ));
     33    $Output .= $Paging->Show();     
     34       
     35          $Table->GetOrderHeader();
     36       
    1437    $Total = array('Money' => 0, 'AdministrationTotal' => 0, 'ConsumptionTotal' => 0, 'TotalPaid' => 0, 'Investment' => 0);
    15     $DbResult = $this->Database->select('FinanceMonthlyOverall', '*', '1 ORDER BY Date DESC');
     38    $DbResult = $this->Database->query($Query.' WHERE 1 '.$Table->OrderSQL.' '.$Paging->SQLLimit);
    1639    while($Month = $DbResult->fetch_array())
    1740    {
    18       $DateParts = explode('-', $Month['Date']);
    19       $Output .= '<tr><td>'.$DateParts[0].'</td><td align="center">'.$MonthNames[$DateParts[1] * 1].'</td><td align="center">'.$Month['Money'].'</td><td align="center">'.$Month['MemberCount'].'</td><td align="center">'.$Month['Administration'].'</td><td align="center">'.$Month['AdministrationTotal'].'</td><td align="center">'.$Month['kWh'].'</td><td align="center">'.$Month['ConsumptionTotal'].'</td><td align="center">'.$Month['TotalPaid'].'</td><td align="center">'.round($Month['TotalPaid'] / $Month['MemberCount']).'</td><td align="center">'.$Month['Investment'].'</td></tr>';
     41      $Table->Table->Cells[] = array($Month['Year'], $MonthNames[$Month['Month']],
     42        $Month['Money'], $Month['MemberCount'], $Month['Administration'],
     43        $Month['AdministrationTotal'], $Month['kWh'], $Month['ConsumptionTotal'],
     44        $Month['TotalPaid'], $Month['PaidPerCustomer'],
     45        $Month['Investment']);
    2046
    2147      $Total['Money'] += $Month['Money'];
     
    2652      //if($DateParts[1] == '01') echo('<tr><td style="font-size: 4;" colspan="10">&nbsp;</td></tr>');
    2753    }
    28     $Output .= '<tr><th colspan="2">Celkem</th><th>'.$Total['Money'].'</th><th>&nbsp;</th><th>&nbsp;</th><th>'.$Total['AdministrationTotal'].'</th><th>&nbsp;</th><th>'.$Total['ConsumptionTotal'].'</th><th>'.$Total['TotalPaid'].'</th><th>&nbsp;</th><th>'.$Total['Investment'].'</th>';
    29     $Output .= '</table>';
     54    //$Table->Table->Cells[] = array('Celkem', '', $Total['Money'], '', '', $Total['AdministrationTotal'],
     55    //  '', $Total['ConsumptionTotal'], $Total['TotalPaid'], '', $Total['Investment']);
     56    $Output .= $Table->Show();
     57    $Output .= $Paging->Show();   
     58   
    3059    return($Output);
    3160  }
Note: See TracChangeset for help on using the changeset viewer.