Changeset 157 for www


Ignore:
Timestamp:
Feb 18, 2009, 11:19:12 AM (16 years ago)
Author:
george
Message:
  • Upraveno: Soubor include.php ve financích přepracován na třídy ve finance.php.
Location:
www
Files:
2 deleted
16 edited

Legend:

Unmodified
Added
Removed
  • www/finance/bills.php

    r156 r157  
    120120  }
    121121
    122   function CreateBill($SubjectId, $Items, $TimeFrom, $TimeTo, $BillCode, $Type)
    123   {
    124     $this->Database->insert('FinanceBills', array('TimeCreate' => TimeToMysqlDateTime(time()), 'Subject' => $SubjectId, 'TimeFrom' => TimeToMysqlDateTime($TimeFrom), 'TimeTo' => TimeToMysqlDateTime($TimeTo), 'TimeDue' => TimeToMysqlDateTime($TimeFrom + 15*24*3600), 'BillCode' => $BillCode, 'Type' => 'invoice'));
     122  function CreateBill($SubjectId, $Items, $TimeFrom, $TimeTo, $BillCode = '', $Type = 'invoice')
     123  {
     124    $this->Database->insert('FinanceBills', array('TimeCreate' => TimeToMysqlDateTime(time()), 'Subject' => $SubjectId, 'TimeFrom' => TimeToMysqlDateTime($TimeFrom), 'TimeTo' => TimeToMysqlDateTime($TimeTo), 'TimeDue' => TimeToMysqlDateTime($TimeFrom + 15 * 24 * 3600), 'BillCode' => $BillCode, 'Type' => $Type));
    125125    $BillId = $this->Database->insert_id;
    126126    foreach($Items as $Item)
     
    192192  function HtmlToPdf($HtmlCode)
    193193  {
    194     $Output = shell_exec('echo "'.addslashes(from_utf8($HtmlCode)).'"|htmldoc --no-numbered --webpage --charset 8859-2 -t pdf -');
     194    $Output = shell_exec('echo "'.addslashes(FromUTF8($HtmlCode)).'"|htmldoc --no-numbered --webpage --charset 8859-2 -t pdf -');
    195195    return($Output);
    196196  }
  • www/finance/clenove.php

    r152 r157  
    11<?php
    22include('../global.php');
    3 include('include.php');
    4 RecalculateTariffs(1);
    53
    64class FinanceUserList extends Page
     
    119  function Show()
    1210  {
    13     global $Tarify;
    14 
    15     if($this->System->Modules['User']->CheckPermission('Finance', 'SubjectList'))
     11    $Finance = $this->System->Modules['Finance'];
     12        $this->System->Modules['Finance']->RecalculateTariffs(1);
     13        if($this->System->Modules['User']->CheckPermission('Finance', 'SubjectList'))
    1614    {
    1715      // Seznam členů
     
    4341        $TotalCash += $Row['Cash'];
    4442        if($Row['Cash'] < 0) $Row['Cash'] = '<span style="color: red;">'.$Row['Cash'].'</span>';
    45         $Tarif = $Tarify[$Row['inet_tarif_now']]['name'];
    46         $PristiTarif = $Tarify[$Row['inet_tarif_next']]['name'];
     43        $Tarif = $Finance->Tarify[$Row['inet_tarif_now']]['name'];
     44        $PristiTarif = $Finance->Tarify[$Row['inet_tarif_next']]['name'];
    4745        $Output .= '<tr><td><a href="user_state.php?id='.$Row['id'].'">'.$Row['Fullname'].'</a></td>';
    4846        //<td align="right">'.$Row['network_device'].'</td>
  • www/finance/finance.php

    r152 r157  
    33class Finance extends Module
    44{
     5  var $kWh;
     6  var $Internet;
     7  var $Sprava;
     8  var $DatumOdecteni;
     9  var $InternetUsers;
     10  var $SpravaUsers;
     11  var $InternetSegmentId = 21;
     12  var $MaxSpeed;
     13  var $RealMaxSpeed;
     14  var $SpeedReserve;
     15  var $BaseSpeedElement;
     16  var $TotalConsumption;
     17  var $UserIdNetwork = 46;
     18  var $BaseTariffPrice;
     19  var $TopTariffPrice;
     20  var $TotalPaid;
     21  var $TotalInternetPaid;
     22  var $Tarify;
     23 
     24  function RecalculateTariffs($Period = 1)
     25  {
     26    $ResidualPrice = $this->Internet;
     27    $ResidualSpeed = $this->MaxSpeed;
     28 
     29    $Tarify = array();
     30    $DbResult = $this->Database->select('finance_tariffs', '*', 'period='.$Period.' ORDER BY id,speed_factor');
     31    while($Tariff = $DbResult->fetch_array())
     32    {
     33      $Tarify[$Tariff['id']] = $Tariff;
     34    } 
    535
     36    if($Period == 0) $Column = 'now'; else $Column = 'next';
     37    $TotalUserCount = 0;
     38    $TotalUnits = 0;
     39    $TotalTarifUnits = 0;
     40    $TotalTarifSpeedUnits = 0;
     41    foreach($Tarify as $Index => $Tarif)
     42    {
     43      $DbResult = $this->Database->select('users', 'COUNT(*)', 'inet_tarif_'.$Column.'='.$Index.' AND inet=1 AND role=2');
     44      $Row = $DbResult->fetch_array();
     45      $Tarify[$Index]['user_count'] = $Row[0];   
     46      switch($Tarif['group_id'])
     47      {
     48        case 1:
     49          $TotalUserCount = $TotalUserCount + $Tarify[$Index]['user_count'];
     50          $Tarify[$Index]['total_units'] = $Tarify[$Index]['price_units'] * $Tarify[$Index]['user_count'];
     51          $TotalTarifUnits = $TotalTarifUnits + $Tarify[$Index]['total_units'];
     52   
     53          if($Index == 3) // Zarizeni site v tarifu 3 neplati penize, ale ma internet
     54            $Tarify[$Index]['total_speed_factor'] = $Tarify[$Index]['speed_factor'] * ($Tarify[$Index]['user_count']+1);
     55            else $Tarify[$Index]['total_speed_factor'] = $Tarify[$Index]['speed_factor'] * $Tarify[$Index]['user_count'];
     56          $TotalTarifSpeedUnits = $TotalTarifSpeedUnits + $Tarify[$Index]['total_speed_factor'];
     57          break;
     58        case 2:
     59          $ResidualPrice -= $Tarif['price'] * $Tarify[$Index]['user_count'];
     60          $ResidualSpeed -= $Tarif['min_speed'] * $Tarify[$Index]['user_count'];
     61          $Tarify[$Index]['total_units'] = $Tarify[$Index]['price_units'] * $Tarify[$Index]['user_count'];
     62          break;
     63        case 3:
     64          $Tarify[$Index]['total_units'] = $Tarify[$Index]['price_units'] * $Tarify[$Index]['user_count'];
     65          break;
     66      }
     67    }
     68    //$PricePerUnit = $TopTariffPrice / ;  // $ResidualPrice / $TotalTarifUnits;
     69    $SpeedPerUnit = $ResidualSpeed * 1024 / $TotalTarifSpeedUnits;
     70 
     71    // Recalculate price
     72    foreach($Tarify as $Index => $Tarif)
     73    {
     74      switch($Tarif['group_id'])
     75      {
     76        case 1:
     77          $Tarify[$Index]['price'] = $this->BaseTariffPrice + round($this->TopTariffPrice * $Tarif['price_units'] / 10) * 10;
     78          $Tarify[$Index]['min_speed'] = round($Tarif['speed_factor'] * $SpeedPerUnit);
     79          $Tarify[$Index]['max_speed'] = round($Tarify[$Index]['speed_factor'] * $this->BaseSpeedElement * 1024);
     80          break;
     81        case 2:
     82          $Tarify[$Index]['min_speed'] = $Tarify[$Index]['min_speed'] * 1024;
     83          $Tarify[$Index]['max_speed'] = $Tarify[$Index]['max_speed'] * 1024;
     84          break;
     85        case 3:
     86          $Tarify[$Index]['price'] = $this->BaseTariffPrice + round($this->TopTariffPrice * $Tarif['price_units']);
     87          $Tarify[$Index]['min_speed'] = $Tarify[$Index]['min_speed'] * 1024;
     88          $Tarify[$Index]['max_speed'] = $Tarify[$Index]['max_speed'] * 1024;
     89          break;
     90      }
     91      $Tarify[$Index]['aggregation'] = '1:'.round($Tarify[$Index]['max_speed'] / $Tarify[$Index]['min_speed']);
     92    }
     93        $this->Tarify = $Tarify;
     94  }
     95
     96  function LoadMonthParameters($Period = 1) // 0 - now, 1 - next month
     97  {   
     98    $DbResult = $this->Database->query("SELECT * FROM finance_charge WHERE period=".$Period);
     99    $Row = $DbResult->fetch_array();
     100    $this->kWh = $Row['kWh'];
     101    $this->Internet = $Row['internet'];
     102    $this->Sprava = $Row['administration_per_user'];
     103    $this->RealMaxSpeed = $Row['internet_speed'];
     104    $this->SpeedReserve = $Row['internet_speed_reserve'];
     105    $this->BaseSpeedElement = $Row['base_speed_element'];
     106    $this->MaxSpeed = $this->RealMaxSpeed - $this->SpeedReserve;
     107    $this->TopTariffPrice = $Row['TopTariffPrice'];
     108    $this->BaseTariffPrice = $Row['BaseTariffPrice'];
     109
     110    $DbResult = $this->Database->query("SELECT COUNT(*) FROM users WHERE inet=1 AND role=2");
     111    $Row = $DbResult->fetch_array();
     112    $this->InternetUsers = $Row[0];
     113 
     114    $DbResult = $this->Database->query("SELECT COUNT(*) FROM users WHERE overheads=1 AND role=2");
     115    $SpravaUsers = $DbResult->fetch_array();
     116    $this->SpravaUsers = $SpravaUsers[0];
     117    $DbResult = $this->Database->query("SELECT SUM(consumption) FROM network_segments");
     118    $TotalConsumption = $DbResult->fetch_array();
     119    $this->TotalConsumption = $TotalConsumption[0];
     120
     121    $DbResult = $this->Database->query("SELECT SUM(`monthly`) as `internet`, SUM(`monthly` - `plus`) as `real` FROM users WHERE role=2");
     122    $Row = $DbResult->fetch_array();
     123    $this->TotalInternetPaid = $Row['internet'];
     124    $this->TotalPaid = $Row['real'];
     125 
     126    $this->RecalculateTariffs($Period);
     127  }
     128
     129  function W2Kc($Spotreba)
     130  {
     131    return(round($Spotreba * 0.72 * $this->kWh));
     132  }
     133
     134  function GetNextDocumentLineNumber($Id)
     135  {   
     136    $DbResult = $this->Database->query('SELECT Shortcut, NextNumber FROM DocumentLine WHERE Id='.$Id);
     137    $DbRow = $DbResult->fetch_assoc();
     138    $Result = $DbRow['Shortcut'].$DbRow['NextNumber'];
     139    $this->Database->query('UPDATE DocumentLine SET NextNumber = NextNumber + 1 WHERE Id='.$Id);
     140    return($Result);
     141  }
    6142}
    7143
  • www/finance/index.php

    r156 r157  
    11<?php
    22include_once('../global.php');
    3 include_once('include.php');
    43
    54class FinanceOverview extends Page
     
    109  function Show()
    1110  {
    12     global $Config, $RealMaxSpeed, $Internet, $InternetUsers, $kWh, $TotalInternetPaid, $SpravaUsers, $Sprava, $UserIdNetwork;
    13 
    14     $Output = '<table><tr><td valign="top">';
     11    $Finance = $this->System->Modules['Finance'];
     12        $Output = '<table><tr><td valign="top">';
    1513
    1614    if(GetMemberByIP(GetRemoteAddress()) > 0) $Output .= '<a href="user_state_ip.php">Vaše finanční operace</a> (Tato volba je také přístupná po přihlášení do systému v uživatelském menu).<br /><br /><br />';
     
    2119    if($this->System->Modules['User']->CheckPermission('Finance', 'SubjectList')) $Output .= '<a href="clenove.php">Seznam členů</a><br />';
    2220    $Output .= '<a href="spotreba.php">Spotřeba energie</a><br />';
    23     $Output .= '<a href="'.$Config['Web']['RootFolder'].'/aktuality/index.php?category=9">Investice v síti</a><br />';
     21    $Output .= '<a href="'.$this->System->Config['Web']['RootFolder'].'/aktuality/index.php?category=9">Investice v síti</a><br />';
    2422    //$Output .= '<a href="faktury/">Faktury za internet</a><br />';
    2523    //$Output .= '<a href="inventory.php">Výpis skladových zásob</a><br />';
     
    2927    $DbResult = $this->Database->query("SELECT * FROM finance_monthly_overall ORDER BY date DESC LIMIT 0,1");
    3028    $Row = $DbResult->fetch_array();
    31     $Output .= 'Platba za internetovou linku ('.$RealMaxSpeed.'/'.$RealMaxSpeed.' kbit/s): <strong>'.$Internet.' Kč</strong><br />';
     29    $Output .= 'Platba za internetovou linku ('.$Finance->RealMaxSpeed.'/'.$Finance->RealMaxSpeed.' kbit/s): <strong>'.$Finance->Internet.' Kč</strong><br />';
    3230
    3331    $DbResult = $this->Database->query("SELECT COUNT(*) FROM users WHERE role=2");
     
    4240    $Row4 = $DbResult->fetch_array();
    4341    $Output .= 'Celkem peněz na účtech: <strong>'.$Row4[0].' Kč</strong><br />';
    44     $Output .= 'Stanovená cena jedné kWh: <strong>'.$kWh.' Kč</strong><br />';
     42    $Output .= 'Stanovená cena jedné kWh: <strong>'.$Finance->kWh.' Kč</strong><br />';
    4543    //echo('Komunitou stanovený poplatek za správu sítě pro jednoho uživatele: <strong>'.$Sprava.' Kč</strong><br />');
    4644    $DbResult = $this->Database->query("SELECT SUM(family) FROM users WHERE role=2");
     
    5553    $Output .= '</td><td valign="top">';
    5654
    57     $UsersPayment = $TotalInternetPaid;
    58     $NetworkManagement = $Sprava * $SpravaUsers;
     55    $UsersPayment = $Finance->TotalInternetPaid;
     56    $NetworkManagement = $Finance->Sprava * $Finance->SpravaUsers;
    5957    $TotalGain = 0;
    6058    $TotalExpense = 0;
    6159    $DbResult = $this->Database->query("SELECT SUM(consumption) FROM network_devices WHERE used=1");
    6260    $Row = $DbResult->fetch_array();
    63     $TotalConsumption = W2Kc($Row[0]);
     61    $TotalConsumption = $this->System->Modules['Finance']->W2Kc($Row[0]);
    6462
    6563    $Output .= 'Měsíční vyúčtování:<br />
     
    7068    $TotalGain += $UsersPayment;
    7169    $Output .= '<tr><td><strong>Celkem</strong></td><td align="right"><strong>'.$TotalGain.'</strong></td></tr>';
    72     $Output .= '<tr><th colspan="2">Výdaje</th></tr><tr><td>Internet</td><td align="right">'.$Internet.'</td></tr>';
    73     $TotalExpense += $Internet;
     70    $Output .= '<tr><th colspan="2">Výdaje</th></tr><tr><td>Internet</td><td align="right">'.$Finance->Internet.'</td></tr>';
     71    $TotalExpense += $Finance->Internet;
    7472    $Output .= '<tr><td>Správa sítě</td><td align="right">'.$NetworkManagement.'</td></tr>';
    7573    $TotalExpense += $NetworkManagement;
     
    8179    $Output .= '<tr><td>Převod do dalšího měsíce</td><td align="right">'.($TotalGain - $TotalExpense).'</td></tr>';
    8280    $Output .= '</table><br />';
    83     $DbResult = $this->Database->select('users', 'cash', 'id='.$UserIdNetwork);
     81    $DbResult = $this->Database->select('users', 'cash', 'id='.$Finance->UserIdNetwork);
    8482    $Row = $DbResult->fetch_array();
    8583    $NetworkCash = $Row['cash'];
    86     $Output .= 'Stav účtu sítě: '.$NetworkCash.' Kč<br /><a href="clenove.php?show=user&amp;id='.$UserIdNetwork.'">Výpis účtu</a><br />';
     84    $Output .= 'Stav účtu sítě: '.$NetworkCash.' Kč<br /><a href="clenove.php?show=user&amp;id='.$Finance->UserIdNetwork.'">Výpis účtu</a><br />';
    8785
    8886    $Output .= '</td></tr></table>';
  • www/finance/inventory.php

    r152 r157  
    11<?php
    22include_once('../global.php');
    3 include_once('include.php');
    43
    54class FinanceStoragePage extends Page
  • www/finance/manage.php

    r156 r157  
    11<?php
    22include_once('../global.php');
    3 include_once('include.php');
    43
    54class FinanceManagePage extends Page
     
    109  function Show()
    1110  {
    12     //if(!$this->System->Modules['User']->CheckPermission('Finance', 'Manage')) return('Nemáte oprávnění');
     11    if(!$this->System->Modules['User']->CheckPermission('Finance', 'Manage')) return('Nemáte oprávnění');
    1312
    1413    if(array_key_exists('Operation', $_GET)) $Operation = $_GET['Operation']; else $Operation = '';
     14        //$Operation = 'ImportOldData';
    1515    switch($Operation)
    1616    {
     
    5656        $Output .= '<a href="?Operation=ConvertPDFToFile">Převést data z databáze do souborů</a><br>';
    5757        $Output .= '<a href="?Operation=Bills">Správa dokladů</a><br>';
     58                $Output .= '<a href="prepocet.php">Přepočet financí</a><br>';
    5859    }
    5960    return($Output);
  • www/finance/monthly_overall.php

    r156 r157  
    11<?php
    22include_once('../global.php');
    3 include_once('include.php');
    43
    54class FinanceMonthlyOverallPage extends Page
     
    1211    global $MonthNames;
    1312
    14     $Output = '<table cellspacing="0" cellpadding="2" border="1"><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 = '<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>';
    1514    $Total = array('money' => 0, 'administration_total' => 0, 'consumption_total' => 0, 'total_paid' => 0, 'investment' => 0);
    1615    $DbResult = $this->Database->select('finance_monthly_overall', '*', '1 ORDER BY date DESC');
  • www/finance/prepocet.php

    r153 r157  
    11<?php
    2 include('../style.php');
    3 include('include.php');
    4 include('bills.php');
    5 
    6 ShowHeader('Přepočet financí', 'Přepočet financí');
    7 
    8 function RecalculateUsersFinance()
     2include_once('../global.php');
     3
     4class FinanceRecalculatePage extends Page
    95{
    10   global $InternetSegmentId, $Tarify, $Sprava, $Database, $UserIdNetwork;
    11 
    12   echo("Aktualizuju finance uživatelů...<br>\n");
    13   $DbResult = $Database->query("SELECT * FROM users WHERE role=2 OR id=".$UserIdNetwork);  // Select network members only
    14   while($Row = $DbResult->fetch_array())
    15   {
    16     $DbResult2 = $Database->query("SELECT SUM(money) FROM finance_operations WHERE user=".$Row['id']);  // Account state
    17     $Row3 = $DbResult2->fetch_array();
    18     $DbResult2 = $Database->query("SELECT SUM(consumption) FROM network_devices WHERE user=".$Row['id']." AND used=1");
    19     $Row4 = $DbResult2->fetch_array();
    20 
    21     $Price = 0;
    22     $Consumption = 0;
    23     $ID = $Row['network_segment'];
    24     while($ID != 0)
    25     {
    26       $DbResult2 = $Database->query("SELECT * FROM network_segments WHERE id=".$ID);
     6  var $FullTitle = 'Přepočet financí';
     7  var $ShortTitle = 'Přepočet financí';
     8 
     9  function RecalculateUsersFinance()
     10  {
     11    $Finance = &$this->System->Modules['Finance'];
     12    $Output = 'Aktualizuju finance uživatelů...<br />';
     13    $DbResult = $this->Database->query('SELECT * FROM users WHERE role=2 OR id='.$Finance->UserIdNetwork);  // Select network members only
     14    while($Row = $DbResult->fetch_array())
     15    {
     16      $DbResult2 = $this->Database->query('SELECT SUM(money) FROM finance_operations WHERE user='.$Row['id']);  // Account state
     17      $Row3 = $DbResult2->fetch_array();
     18      $DbResult2 = $this->Database->query('SELECT SUM(consumption) FROM network_devices WHERE user='.$Row['id'].' AND used=1');
     19      $Row4 = $DbResult2->fetch_array();
     20
     21      $Price = 0;
     22      $Consumption = 0;
     23      $ID = $Row['network_segment'];
     24      while($ID != 0)
     25      {
     26        $DbResult2 = $this->Database->query('SELECT * FROM network_segments WHERE id='.$ID);
     27        $Row2 = $DbResult2->fetch_array();
     28        if(!(($Row['inet_hw'] == 0) and ($ID == $Finance->InternetSegmentId)))
     29        {
     30          $Price += $Row2['price'] / $Row2['users'];
     31          $Consumption += $Row2['consumption'] / $Row2['users_overheads'];
     32        }
     33        //echo($ID.' '.$InternetSegment.' '.$InternetSegmentId.' '.$Row['inet_hw'].' '.$Price.'<br>');
     34        $ID = $Row2['parent'];
     35      }
     36      $Monthly = 0;
     37      $MonthlyInet = $Finance->Tarify[$Row['inet_tarif_next']]['price'];
     38      if($Row['inet'] == 1) $Monthly += $MonthlyInet;
     39      //if($Row['overheads'] == 1) $Monthly += $Sprava; // + W2Kc($Consumption);
     40      //echo($Row['fullname'].' '.$Row['inet'].' '.$Monthly.'<br>');
     41      $Monthly = round($Monthly);
     42      //echo($Row['fullname'].' '.$Row['inet'].' '.$Monthly.'<br>');
     43      $this->Database->update('users', 'id='.$Row['id'], array('network_device' => $Price, 'monthly_inet' => $MonthlyInet, 'monthly' => $Monthly, 'consumption' => $this->System->Modules['Finance']->W2Kc($Consumption), 'cash' => $Row3[0], 'plus' => $Finance->W2Kc($Row4[0])));
     44    }
     45        return($Output);
     46  }
     47
     48  function RecalculateSegmentParameters()
     49  {
     50    $Finance = &$this->System->Modules['Finance'];
     51        $Output = 'Aktualizuju parametry segmentů...<br />';
     52    $this->Database->query('UPDATE network_segments SET users = 0, users_overheads = 0');               // Vynulovat počty uživatelů
     53    $DbResult = $this->Database->query('SELECT * FROM network_segments');
     54    while($Row = $DbResult->fetch_array())
     55    {
     56      //echo('Segment '.$Row['name'].'<br>');
     57      $DbResult2 = $this->Database->query('SELECT users FROM network_segments WHERE id='.$Row['id']);
     58      $RowP = $DbResult2->fetch_array();
     59      $DbResult2 = $this->Database->query("SELECT users_overheads FROM network_segments WHERE id=".$Row['id']);
     60      $RowP2 = $DbResult2->fetch_array();
     61
     62      $DbResult2 = $this->Database->query("SELECT SUM(price) as Price, SUM(consumption) as Consumption FROM network_devices WHERE segment=".$Row['id']." AND used=1");
    2763      $Row2 = $DbResult2->fetch_array();
    28       if(!(($Row['inet_hw'] == 0) and ($ID == $InternetSegmentId)))
    29       {
    30         $Price += $Row2['price'] / $Row2['users'];
    31         $Consumption += $Row2['consumption'] / $Row2['users_overheads'];
    32       }
    33       //echo($ID.' '.$InternetSegment.' '.$InternetSegmentId.' '.$Row['inet_hw'].' '.$Price.'<br>');
    34       $ID = $Row2['parent'];
    35     }
    36     $Monthly = 0;
    37     $MonthlyInet = $Tarify[$Row['inet_tarif_next']]['price'];
    38     if($Row['inet'] == 1) $Monthly += $MonthlyInet;
    39     //if($Row['overheads'] == 1) $Monthly += $Sprava; // + W2Kc($Consumption);
    40     //echo($Row['fullname'].' '.$Row['inet'].' '.$Monthly.'<br>');
    41     $Monthly = round($Monthly);
    42     //echo($Row['fullname'].' '.$Row['inet'].' '.$Monthly.'<br>');
    43     $Database->update('users', 'id='.$Row['id'], array('network_device' => $Price, 'monthly_inet' => $MonthlyInet, 'monthly' => $Monthly, 'consumption' => W2Kc($Consumption), 'cash' => $Row3[0], 'plus' => W2Kc($Row4[0])));
     64      $DbResult2 = $this->Database->query("SELECT COUNT(*) FROM users WHERE network_segment=".$Row['id'].' AND hw=1');
     65      $Row3 = $DbResult2->fetch_array();
     66      $DbResult2 = $this->Database->query("SELECT COUNT(*) FROM users WHERE network_segment=".$Row['id'].' AND overheads=1');
     67      $Row5 = $DbResult2->fetch_array();
     68      $ID = $Row['parent'];
     69      while($ID != 0)
     70      {
     71        //echo($ID.', ');
     72        $DbResult2 = $this->Database->query("SELECT * FROM network_segments WHERE id=".$ID);
     73        $Row4 = $DbResult2->fetch_array();
     74        $this->Database->update('network_segments', 'id='.$Row4['id'], array('users' => ($Row4['users'] + $Row3[0]), 'users_overheads' => ($Row4['users_overheads'] + $Row5[0])));
     75        $ID = $Row4['parent'];
     76      }
     77      //echo('Pocet '.$Row3[0].','.$Row['hosts'].'<br>');
     78      $this->Database->update('network_segments', 'id='.$Row['id'], array('price' => $Row2['Price'], 'users' => ($Row3[0] + $RowP['users']), 'consumption' => $Row2['Consumption'], 'users_overheads' => ($Row5[0] + $RowP2['users_overheads'])));
     79    }
     80
     81    // Zkorigovat segment Internet
     82    $DbResult = $this->Database->select('users', 'COUNT(*)', 'inet_hw=1');
     83    $Row = $DbResult->fetch_array();
     84    $DbResult = $this->Database->select('users', 'COUNT(*)', 'inet=1');
     85    $Row2 = $DbResult->fetch_array();
     86    $DbResult = $this->Database->update('network_segments','id='.$Finance->InternetSegmentId, array('users' => $Row[0], 'users_overheads' => $Row2[0]));
     87    return($Output);
     88  }
     89
     90  function CreateMonthlyOverallBill()
     91  {
     92    global $Sprava, $SpravaUsers, $TotalConsumption, $UserIdNetwork, $Internet, $TotalInternetPaid;
     93
     94    $TotalConsumptionPrice = $this->System->Modules['Finance']->W2Kc($TotalConsumption);
     95 
     96    $Output .= "Spotřeba energie: ".-$TotalConsumptionPrice."<br />";
     97    $Output .= "Správa sítě: ".-($Sprava * $SpravaUsers)."<br>";
     98    $Output .= "Internet: ".-$Internet."<br>";
     99    $Output .= "Poplatky učástníků: ".$TotalInternetPaid."<br>";
     100
     101    $this->Database->insert('finance_operations', array('money' => -$TotalConsumptionPrice, 'user' => $UserIdNetwork, 'type' => 2, 'date' => 'NOW()', 'comment' => 'Spotřeba energie', 'group' => 2));
     102    $this->Database->insert('finance_operations', array('money' => -($Sprava * $SpravaUsers), 'user' => $UserIdNetwork, 'type' => 2, 'date' => 'NOW()', 'comment' => 'Správa sítě', 'group' => 2));
     103    $this->Database->insert('finance_operations', array('money' => -$Internet, 'user' => $UserIdNetwork, 'type' => 2, 'date' => 'NOW()', 'comment' => 'Internet', 'group' => 2));
     104    $this->Database->insert('finance_operations', array('money' => $TotalInternetPaid, 'user' => $UserIdNetwork, 'type' => 2, 'date' => 'NOW()', 'comment' => 'Poplatky učástníků', 'group' => 2));
     105        return($Output);
     106  }
     107
     108  function DiscountNetworkDevicePrice()
     109  {
     110        $Output = '';
     111    $DbResult = $this->Database->query("SELECT *,CONCAT(second_name, ' ', first_name) as fullname FROM users WHERE role=2");
     112    while($Row = $DbResult->fetch_array())
     113    {
     114      $Output .= $Row['fullname'].': '.($Row['network_device'])."<br />";
     115      $this->Database->insert('finance_operations', array('money' => (-$Row['network_device']), 'user' => $Row['id'], 'type' => 2, 'date' => 'NOW()', 'comment' => 'Jednorázový poplatek za společné zařízení', 'group' => 1));
     116    //echo($Database->LastQuery."<br>\n");
     117    }
     118        return($Output);
     119  }
     120
     121
     122  function Show()
     123  {
     124    if(!$this->System->Modules['User']->CheckPermission('Finance', 'Manage')) return('Nemáte oprávnění');
     125        $Output = '';
     126
     127    $Finance = &$this->System->Modules['Finance'];
     128       
     129    // Načti poslední měsíční přehled a nastavení
     130    $DbResult = $this->Database->select('finance_monthly_overall', '*', '1 ORDER BY date DESC LIMIT 1');
     131    $Overall = $DbResult->fetch_array();
     132
     133    $Output -= 'Datum: '.date('j.n.Y')."<br />";
     134   
     135    $Datum = explode('-', $Overall['date']);
     136    $Mesic = date("m") + 0;
     137
     138    $Output .= $this->RecalculateSegmentParameters();
     139    $Output .= $Finance->RecalculateTariffs();
     140    //DiscountNetworkDevicePrice();
     141    //$InvoiceGenerator->CustomGenerate();
     142    $Output .= $this->RecalculateUsersFinance();
     143
     144    // Celkovy prehled
     145    $DbResult = $this->Database->query("SELECT SUM(price) FROM network_devices WHERE used=1");
     146    $Row4 = $DbResult->fetch_array();
     147    $Output .= "Celková cena zařízení: Zařízení(".$Row4[0];
     148    $DbResult = $this->Database->query("SELECT SUM(price) FROM network_segments");
     149    $Row = $DbResult->fetch_array();
     150    $Output .= "), Segmenty(".$Row[0];
     151    $DbResult = $this->Database->query("SELECT SUM(network_device) FROM users");
     152    $Row5 = $DbResult->fetch_array();
     153    $Output .= "), Uživatelé(".$Row5[0].")<br>\n";
     154    $DbResult = $this->Database->query("SELECT SUM(cash) FROM users WHERE role=2");
     155    $Row6 = $DbResult->fetch_array();
     156    $Output .= "Stav pokladny: Uživatelé(".$Row6[0].")";
     157    $DbResult = $this->Database->query("SELECT SUM(money) FROM finance_operations WHERE `group`=1"); // Položky uživatelů
     158    $Row2 = $DbResult->fetch_array();
     159    $Output .= ", Operace-Zařízení(".($Row2[0] - $Row4[0]).")<br>\n";
     160    $Output .= "Rozdíl peněz v operacích: ".($Row2[0] - $Row6[0] - $Row4[0])." <br>\n";
     161
     162
     163    $DbResult = $this->Database->query("SELECT SUM(consumption) FROM network_devices WHERE used=1");
     164    $Row = $DbResult->fetch_array();
     165    $CelkemSpotreba = $Finance->W2Kc($Row[0]);
     166
     167    $SpravaCelkem = $Finance->Sprava * $Finance->SpravaUsers;
     168    $Output .= "Kontrola placení (Zaplaceno-Sprava-Internet): ".$Finance->TotalPaid."-".$SpravaCelkem."-".$Finance->Internet."=".($Finance->TotalPaid - $SpravaCelkem - $Finance->Internet)."<br>\n\n";
     169
     170    // Zkontrolovat odečtení měsíčního poplatku
     171    //$Mesic = '1';
     172    $Output .= 'Kontrola odečtení poplatků: Poslední měsíc-'.round($Datum[1]).' Aktuální měsíc-'.$Mesic."<br>\n";
     173    if($Mesic != $Datum[1])
     174    {
     175      $Output .= "Odečítám měsíční poplatek...<br>\n";
     176
     177      $BillingPeriodMonthCount = array('never' => 0, 'monthly' => 1, 'quarterly' => 3, 'half-yearly' => 6, 'yearly' => 12);
     178
     179      // Generuj účetní položky
     180      $DbResult = $this->Database->query("SELECT *, CONCAT(second_name, ' ', first_name) as fullname FROM users WHERE (role = 2)");
     181      while($User = $DbResult->fetch_array())
     182      {
     183        $Output .= $User['fullname'].': ';
     184        $MonthCount = $BillingPeriodMonthCount[$User['BillingPeriod']];
     185        if(($MonthCount > 0) and (((($Mesic - 1) % 12) % $MonthCount) == 0) and ($User['inet_tarif_now'] != 6))
     186        {
     187          //echo($Mesic.'%'.$MonthCount.'='.($Mesic % $MonthCount).' ');
     188          $PayPerMonth = -($User['plus'] - $User['monthly']);
     189          $PayPerPeriod = $PayPerMonth * $MonthCount;
     190          $PeriodFrom = mktime(0, 0, 0, date('n'), 1, date('Y'));
     191          $PeriodTo = mktime(0, 0, 0, date('n') + $MonthCount - 1, date('t', mktime(0, 0, 0, date('n') + $MonthCount - 1, 1, date('Y'))) , date('Y'));
     192          $TimePeriodText = date('j.n.Y', $PeriodFrom).' - '.date('j.n.Y', $PeriodTo);
     193          $Output .= $TimePeriodText.': '.$PayPerMonth." * ".$MonthCount." = ".$PayPerPeriod."<br />\n";
     194          $BillCode = $Finance->GetNextDocumentLineNumber(6); // Faktury vydané
     195          $BillId = $this->System->Modules['Bill']->CreateBill($User['id'], array(array('Description' => 'Připojení k síti', 'Price' => $PayPerPeriod, 'Quantity' => 1)), $PeriodFrom, $PeriodTo, $BillCode);
     196          $this->Database->insert('finance_operations', array('money' => -$PayPerPeriod, 'user' => $User['id'], 'type' => 2, 'date' => 'NOW()', 'comment' => 'Připojení k síti za období '.$TimePeriodText, 'group' => 1, 'bill_id' => $BillId, 'BillCode' => $BillCode));
     197        } else $Output .= ("<br />");
     198      }
     199      $Output .= 'Měním aktuální parametry sítě...<br>\n';
     200
     201      // Update finance charge
     202      $this->Database->delete('finance_charge', 'period=0');
     203      $DbResult = $this->Database->select('finance_charge', '*', 'period=1');
     204      $Charge = $DbResult->fetch_array();
     205      //print_r($Charge);
     206      $DbResult = $this->Database->insert('finance_charge', array('period' => 0, 'internet' => $Charge['internet'], 'internet_speed' => $Charge['internet_speed'], 'internet_speed_reserve' => $Charge['internet_speed_reserve'], 'administration_per_user' => $Charge['administration_per_user'], 'kWh' => $Charge['kWh'], 'base_speed_element' => $Charge['base_speed_element'], 'BaseTariffPrice' => $Charge['BaseTariffPrice'], 'TopTariffPrice' => $Charge['TopTariffPrice']));
     207
     208      $Output .= "Přidávám měsíční přehled...<br>\n";
     209
     210      $this->Database->insert('finance_monthly_overall', array('date' => 'NOW()', 'money' => $Finance->Internet, 'kWh' => $Finance->kWh, 'administration' => $Finance->Sprava, 'administration_total' => $SpravaCelkem, 'consumption_total' => $CelkemSpotreba, 'total_paid' => $Finance->TotalPaid, 'BaseTariffPrice' => $Charge['BaseTariffPrice'], 'TopTariffPrice' => $Charge['TopTariffPrice'], 'member_count' => $Finance->InternetUsers));
     211
     212      $Output .= "Měním aktuální tarify....<br>\n";
     213
     214      // Update tarrifs
     215      $this->Database->delete('finance_tariffs', 'period=0');
     216      $DbResult = $this->Database->select('finance_tariffs', '*', 'period=1');
     217      while($Tariff = $DbResult->fetch_array())
     218      {
     219        $this->Database->insert('finance_tariffs', array('period' => 0, 'name' => $Tariff['name'], 'id' => $Tariff['id'],'speed_factor' => $Tariff['speed_factor'], 'price_units' => $Tariff['price_units'], 'group_id' => $Tariff['group_id'], 'min_speed' => $Tariff['min_speed'], 'max_speed' => $Tariff['max_speed'], 'price' => $Tariff['price']));
     220      }
     221
     222      $Output .= "Měním aktuální tarify uživatelů...<br>\n";
     223
     224      // Update tariff user selection
     225      $DbResult = $this->Database->query("SELECT id,inet_tarif_next FROM users WHERE role=2");
     226      while($User = $DbResult->fetch_array())
     227      {
     228        $this->Database->update('users', 'id='.$User['id'], array('inet_tarif_now' => $User['inet_tarif_next']));
     229      }
     230
     231      $Output .= $this->System->Modules['Finance']->RecalculateTariffs();
     232          $this->RecalculateUsersFinance();
     233      //CreateMonthlyOverallBill();
     234      $this->RecalculateUsersFinance();
     235
     236      // Restart traffic shaping
     237      $this->Database->update('services_restart', 'id=3', array('changed' => 1));
     238    }
     239        return($Output);
    44240  }
    45241}
    46242
    47 function RecalculateSegmentParameters()
    48 {
    49   global $Database, $InternetSegmentId;
    50 
    51   echo("Aktualizuju parametry segmentů...<br>\n");
    52   $Database->query("UPDATE network_segments SET users = 0, users_overheads = 0");               // Vynulovat počty uživatelů
    53   $DbResult = $Database->query("SELECT * FROM network_segments");
    54   while($Row = $DbResult->fetch_array())
    55   {
    56     //echo('Segment '.$Row['name'].'<br>');
    57     $DbResult2 = $Database->query("SELECT users FROM network_segments WHERE id=".$Row['id']);
    58     $RowP = $DbResult2->fetch_array();
    59     $DbResult2 = $Database->query("SELECT users_overheads FROM network_segments WHERE id=".$Row['id']);
    60     $RowP2 = $DbResult2->fetch_array();
    61 
    62     $DbResult2 = $Database->query("SELECT SUM(price) as Price, SUM(consumption) as Consumption FROM network_devices WHERE segment=".$Row['id']." AND used=1");
    63     $Row2 = $DbResult2->fetch_array();
    64     $DbResult2 = $Database->query("SELECT COUNT(*) FROM users WHERE network_segment=".$Row['id'].' AND hw=1');
    65     $Row3 = $DbResult2->fetch_array();
    66     $DbResult2 = $Database->query("SELECT COUNT(*) FROM users WHERE network_segment=".$Row['id'].' AND overheads=1');
    67     $Row5 = $DbResult2->fetch_array();
    68     $ID = $Row['parent'];
    69     while($ID != 0)
    70     {
    71       //echo($ID.', ');
    72       $DbResult2 = $Database->query("SELECT * FROM network_segments WHERE id=".$ID);
    73       $Row4 = $DbResult2->fetch_array();
    74       $Database->update('network_segments', 'id='.$Row4['id'], array('users' => ($Row4['users'] + $Row3[0]), 'users_overheads' => ($Row4['users_overheads'] + $Row5[0])));
    75       $ID = $Row4['parent'];
    76     }
    77     //echo('Pocet '.$Row3[0].','.$Row['hosts'].'<br>');
    78     $Database->update('network_segments', 'id='.$Row['id'], array('price' => $Row2['Price'], 'users' => ($Row3[0] + $RowP['users']), 'consumption' => $Row2['Consumption'], 'users_overheads' => ($Row5[0] + $RowP2['users_overheads'])));
    79   }
    80 
    81   // Zkorigovat segment Internet
    82   $DbResult = $Database->select('users', 'COUNT(*)', 'inet_hw=1');
    83   $Row = $DbResult->fetch_array();
    84   $DbResult = $Database->select('users', 'COUNT(*)', 'inet=1');
    85   $Row2 = $DbResult->fetch_array();
    86   $DbResult = $Database->update('network_segments','id='.$InternetSegmentId, array('users' => $Row[0], 'users_overheads' => $Row2[0]));
    87 }
    88 
    89 function CreateMonthlyOverallBill()
    90 {
    91   global $Database, $Sprava, $SpravaUsers, $TotalConsumption, $UserIdNetwork, $Internet, $TotalInternetPaid;
    92 
    93   $TotalConsumptionPrice = W2Kc($TotalConsumption);
    94  
    95   echo("Spotřeba energie: ".-$TotalConsumptionPrice."<br>\n");
    96   echo("Správa sítě: ".-($Sprava * $SpravaUsers)."<br>\n");
    97   echo("Internet: ".-$Internet."<br>\n");
    98   echo("Poplatky učástníků: ".$TotalInternetPaid."<br>\n");
    99 
    100   $Database->insert('finance_operations', array('money' => -$TotalConsumptionPrice, 'user' => $UserIdNetwork, 'type' => 2, 'date' => 'NOW()', 'comment' => 'Spotřeba energie', 'group' => 2));
    101   $Database->insert('finance_operations', array('money' => -($Sprava * $SpravaUsers), 'user' => $UserIdNetwork, 'type' => 2, 'date' => 'NOW()', 'comment' => 'Správa sítě', 'group' => 2));
    102   $Database->insert('finance_operations', array('money' => -$Internet, 'user' => $UserIdNetwork, 'type' => 2, 'date' => 'NOW()', 'comment' => 'Internet', 'group' => 2));
    103   $Database->insert('finance_operations', array('money' => $TotalInternetPaid, 'user' => $UserIdNetwork, 'type' => 2, 'date' => 'NOW()', 'comment' => 'Poplatky učástníků', 'group' => 2));
    104 }
    105 
    106 function DiscountNetworkDevicePrice()
    107 {
    108   global $Database;
    109   $DbResult = $Database->query("SELECT *,CONCAT(second_name, ' ', first_name) as fullname FROM users WHERE role=2");
    110   while($Row = $DbResult->fetch_array())
    111   {
    112     echo($Row['fullname'].': '.($Row['network_device'])."<br>\n");
    113     $Database->insert('finance_operations', array('money' => (-$Row['network_device']), 'user' => $Row['id'], 'type' => 2, 'date' => 'NOW()', 'comment' => 'Jednorázový poplatek za společné zařízení', 'group' => 1));
    114     //echo($Database->LastQuery."<br>\n");
    115   }
    116 }
    117 
    118 // Načti poslední měsíční přehled a nastavení
    119 $DbResult = $Database->select('finance_monthly_overall', '*', '1 ORDER BY date DESC LIMIT 1');
    120 $Overall = $DbResult->fetch_array();
    121 
    122 echo('Datum: '.date('j.n.Y')."<br>");
    123 $Mesice = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec');
    124 $Datum = explode('-', $Overall['date']);
    125 $Mesic = date("m") + 0;
    126 
    127 RecalculateSegmentParameters();
    128 RecalculateTariffs();
    129 //DiscountNetworkDevicePrice();
    130 //$InvoiceGenerator->CustomGenerate();
    131 RecalculateUsersFinance();
    132 
    133 // Celkovy prehled
    134 $DbResult = $Database->query("SELECT SUM(price) FROM network_devices WHERE used=1");
    135 $Row4 = $DbResult->fetch_array();
    136 echo("Celková cena zařízení: Zařízení(".$Row4[0]);
    137 $DbResult = $Database->query("SELECT SUM(price) FROM network_segments");
    138 $Row = $DbResult->fetch_array();
    139 echo("), Segmenty(".$Row[0]);
    140 $DbResult = $Database->query("SELECT SUM(network_device) FROM users");
    141 $Row5 = $DbResult->fetch_array();
    142 echo("), Uživatelé(".$Row5[0].")<br>\n");
    143 $DbResult = $Database->query("SELECT SUM(cash) FROM users WHERE role=2");
    144 $Row6 = $DbResult->fetch_array();
    145 echo("Stav pokladny: Uživatelé(".$Row6[0].")");
    146 $DbResult = $Database->query("SELECT SUM(money) FROM finance_operations WHERE `group`=1"); // Položky uživatelů
    147 $Row2 = $DbResult->fetch_array();
    148 echo(", Operace-Zařízení(".($Row2[0] - $Row4[0]).")<br>\n");
    149 echo("Rozdíl peněz v operacích: ".($Row2[0] - $Row6[0] - $Row4[0])." <br>\n");
    150 
    151 
    152 $DbResult = $Database->query("SELECT SUM(consumption) FROM network_devices WHERE used=1");
    153 $Row = $DbResult->fetch_array();
    154 $CelkemSpotreba = W2Kc($Row[0]);
    155 
    156 $SpravaCelkem = $Sprava * $SpravaUsers;
    157 echo("Kontrola placení (Zaplaceno-Sprava-Internet): ".$TotalPaid."-".$SpravaCelkem."-".$Internet."=".($TotalPaid - $SpravaCelkem - $Internet)."<br>\n\n");
    158 
    159 // Zkontrolovat odečtení měsíčního poplatku
    160 //$Mesic = '1';
    161 echo('Kontrola odečtení poplatků: Poslední měsíc-'.round($Datum[1]).' Aktuální měsíc-'.$Mesic."<br>\n");
    162 if($Mesic != $Datum[1])
    163 {
    164   echo("Odečítám měsíční poplatek...<br>\n");
    165 
    166   $BillingPeriodMonthCount = array('never' => 0, 'monthly' => 1, 'quarterly' => 3, 'half-yearly' => 6, 'yearly' => 12);
    167 
    168   // Generuj účetní položky
    169   $DbResult = $Database->query("SELECT *, CONCAT(second_name, ' ', first_name) as fullname FROM users WHERE (role = 2)");
    170   while($User = $DbResult->fetch_array())
    171   {
    172     echo($User['fullname'].': ');
    173     $MonthCount = $BillingPeriodMonthCount[$User['BillingPeriod']];
    174     if(($MonthCount > 0) and (((($Mesic - 1) % 12) % $MonthCount) == 0) and ($User['inet_tarif_now'] != 6))
    175     {
    176       //echo($Mesic.'%'.$MonthCount.'='.($Mesic % $MonthCount).' ');
    177       $PayPerMonth = -($User['plus'] - $User['monthly']);
    178       $PayPerPeriod = $PayPerMonth * $MonthCount;
    179       $PeriodFrom = mktime(0, 0, 0, date('n'), 1, date('Y'));
    180       $PeriodTo = mktime(0, 0, 0, date('n') + $MonthCount - 1, date('t', mktime(0, 0, 0, date('n') + $MonthCount - 1, 1, date('Y'))) , date('Y'));
    181       $TimePeriodText = date('j.n.Y', $PeriodFrom).' - '.date('j.n.Y', $PeriodTo);
    182       echo($TimePeriodText.': '.$PayPerMonth." * ".$MonthCount." = ".$PayPerPeriod."\n");
    183       $BillCode = GetNextDocumentLineNumber(6); // Faktury vydané
    184       $BillId = $Bill->CreateBill($User['id'], array(array('description' => 'Připojení k síti', 'price' => $PayPerPeriod, 'quantity' => 1)), $PeriodFrom, $PeriodTo, $BillCode);
    185       $Database->insert('finance_operations', array('money' => -$PayPerPeriod, 'user' => $User['id'], 'type' => 2, 'date' => 'NOW()', 'comment' => 'Připojení k síti za období '.$TimePeriodText, 'group' => 1, 'bill_id' => $BillId, 'BillCode' => $BillCode));
    186     } else echo("\n");
    187   }
    188   echo('Měním aktuální parametry sítě...<br>\n');
    189 
    190   // Update finance charge
    191   $Database->delete('finance_charge', 'period=0');
    192   $DbResult = $Database->select('finance_charge', '*', 'period=1');
    193   $Charge = $DbResult->fetch_array();
    194   //print_r($Charge);
    195   $DbResult = $Database->insert('finance_charge', array('period' => 0, 'internet' => $Charge['internet'],
    196     'internet_speed' => $Charge['internet_speed'], 'internet_speed_reserve' => $Charge['internet_speed_reserve'], 'administration_per_user' => $Charge['administration_per_user'], 'kWh' => $Charge['kWh'], 'base_speed_element' => $Charge['base_speed_element'], 'BaseTariffPrice' => $Charge['BaseTariffPrice'], 'TopTariffPrice' => $Charge['TopTariffPrice']));
    197 
    198   echo("Přidávám měsíční přehled...<br>\n");
    199 
    200   $Database->insert('finance_monthly_overall', array('date' => 'NOW()', 'money' => $Internet, 'kWh' => $kWh, 'administration' => $Sprava, 'administration_total' => $SpravaCelkem, 'consumption_total' => $CelkemSpotreba, 'total_paid' => $TotalPaid, 'BaseTariffPrice' => $Charge['BaseTariffPrice'], 'TopTariffPrice' => $Charge['TopTariffPrice'], 'member_count' => $InternetUsers));
    201 
    202   echo("Měním aktuální tarify....<br>\n");
    203 
    204   // Update tarrifs
    205   $Database->delete('finance_tariffs', 'period=0');
    206   $DbResult = $Database->select('finance_tariffs', '*', 'period=1');
    207   while($Tariff = $DbResult->fetch_array())
    208   {
    209     $Database->insert('finance_tariffs', array('period' => 0, 'name' => $Tariff['name'], 'id' => $Tariff['id'],
    210       'speed_factor' => $Tariff['speed_factor'], 'price_units' => $Tariff['price_units'], 'group_id' => $Tariff['group_id'], 'min_speed' => $Tariff['min_speed'], 'max_speed' => $Tariff['max_speed'], 'price' => $Tariff['price']));
    211   }
    212 
    213   echo("Měním aktuální tarify uživatelů...<br>\n");
    214 
    215   // Update tariff user selection
    216   $DbResult = $Database->query("SELECT id,inet_tarif_next FROM users WHERE role=2");
    217   while($User = $DbResult->fetch_array())
    218   {
    219     $Database->update('users', 'id='.$User['id'], array('inet_tarif_now' => $User['inet_tarif_next']));
    220   }
    221 
    222   RecalculateTariffs();
    223   RecalculateUsersFinance();
    224   //CreateMonthlyOverallBill();
    225   RecalculateUsersFinance();
    226 
    227   // Restart traffic shaping
    228   $Database->update('services_restart', 'id=3', array('changed' => 1));
    229 }
    230 
    231 ShowFooter();
     243$System->AddModule(new FinanceRecalculatePage());
     244$System->Modules['FinanceRecalculatePage']->GetOutput();
    232245
    233246?>
  • www/finance/spotreba.php

    r152 r157  
    11<?php
    22include_once('../global.php');
    3 include_once('include.php');
    43
    54class FinanceConsumption extends Page
     
    2120      $Row2 = $DbResult2->fetch_array();
    2221      $CelkovaSpotreba = $CelkovaSpotreba + $Row2[0];
    23       $Output .= '<tr><td>'.$Row['name'].'</td><td align="right">'.$Row2[0].'</td><td align="right">'.W2Kc($Row2[0]).'</td></tr>';
     22      $Output .= '<tr><td>'.$Row['name'].'</td><td align="right">'.$Row2[0].'</td><td align="right">'.$this->System->Modules['Finance']->W2Kc($Row2[0]).'</td></tr>';
    2423    }
    25     $Output .= '<tr style="font-weight: Bold;"><td><strong>Celkem</strong></td><td align="right">'.$CelkovaSpotreba.'</td><td align="right">'.W2Kc($CelkovaSpotreba).'</td></tr>';
     24    $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>';
    2625    $Output .= '</table><br />';
    2726    $Output .= 'Dohodnutá cena za jednu kWh: <strong>'.$kWh.' Kč</strong><br />';
  • www/finance/tarify.php

    r152 r157  
    11<?php
    22include_once('../global.php');
    3 include_once('include.php');
    43
    54class FinanceTarrifsPage extends Page
     
    109  function TariffTable()
    1110  {
    12     global $Tarify, $Internet, $InternetUsers, $RealMaxSpeed, $SpeedReserve, $MaxSpeed;
    13 
    14     $Output = 'Poplatek za společný internet: <strong>'.$Internet.' Kč</strong><br />';
    15     $Output .= 'Rychlost společné linky: <strong>'.$RealMaxSpeed.' kbit/s</strong><br />';
    16     $Output .= 'Rezerva (nevyužitá kapacita pro zlepšení odezvy sítě): <strong>'.$SpeedReserve.' kbit/s</strong><br />';
    17     $Output .= 'Maximální dostupná kapacita pro použití: <strong>'.$MaxSpeed.' kbit/s</strong><br />';
     11    $Finance = &$this->System->Modules['Finance'];
     12       
     13    $Output = 'Poplatek za společný internet: <strong>'.$Finance->Internet.' Kč</strong><br />';
     14    $Output .= 'Rychlost společné linky: <strong>'.$Finance->RealMaxSpeed.' kbit/s</strong><br />';
     15    $Output .= 'Rezerva (nevyužitá kapacita pro zlepšení odezvy sítě): <strong>'.$Finance->SpeedReserve.' kbit/s</strong><br />';
     16    $Output .= 'Maximální dostupná kapacita pro použití: <strong>'.$Finance->MaxSpeed.' kbit/s</strong><br />';
    1817    $Output .= '<br />';
    1918
     
    2221    $TotalPrice = 0;
    2322    $TotalUnits = 0;
    24     foreach($Tarify as $Index => $Tarif)
     23    foreach($Finance->Tarify as $Index => $Tarif)
    2524    {
    2625      $Output .= '<tr><td style="color: blue;">'.$Tarif['name'].'</td><td align="center">'.round($Tarif['min_speed'] / 1024).'</td><td align="center" style="color: blue;">'.round($Tarif['max_speed'] / 1024).'</td><td align="center">'.$Tarif['aggregation'].'</td><td align="center">'.$Tarif['price_units'].'</td><td align="center">'.$Tarif['user_count'].'</td><td align="center">'.
     
    2928      $TotalUnits = $TotalUnits + $Tarif['total_units'];
    3029    }
    31     $Output .= '<tr><td>Součty</td><td colspan="4">&nbsp;</td><td align="center">'.$InternetUsers.'</td><td align="center">'.$TotalUnits.'</td><td>&nbsp;</td><td align="center">'.$TotalPrice.'</td></tr>';
     30    $Output .= '<tr><td>Součty</td><td colspan="4">&nbsp;</td><td align="center">'.$Finance->InternetUsers.'</td><td align="center">'.$TotalUnits.'</td><td>&nbsp;</td><td align="center">'.$TotalPrice.'</td></tr>';
    3231    $Output .= '</table>';
    3332    return($Output);
     
    3635  function Show()
    3736  {
    38     global $Tarify, $Internet, $InternetUsers, $RealMaxSpeed, $SpeedReserve, $MaxSpeed;
    39     $Output = 'Počet členů s internetovým připojením: <strong>'.$InternetUsers.'</strong><br /><br />';
     37        $Finance = &$this->System->Modules['Finance'];
     38    $Output = 'Počet členů s internetovým připojením: <strong>'.$Finance->InternetUsers.'</strong><br /><br />';
    4039    $Output .= '<table><tr><td valign="top">';
    4140
    42     NactiMesicniParametry(0);
     41    $Finance->LoadMonthParameters(0);
    4342    $Output .= '<strong>Stav pro aktuální měsíc:</strong><br />';
    4443    $Output .= $this->TariffTable();
     
    4645    $Output .= '<br /></td></tr><tr><td valign="top">';
    4746
    48     NactiMesicniParametry(1);
     47    $Finance->LoadMonthParameters(1);
    4948    $Output .= '<strong>Stav pro další měsíc:</strong><br />';
    5049    $Output .= $this->TariffTable();
  • www/finance/user_state.php

    r156 r157  
    22
    33include_once('../global.php');
    4 include_once('include.php');
    5 RecalculateTariffs(1);
    64
    75class FinanceUserState extends Page
     
    1614    if(!$this->System->Modules['User']->CheckPermission('Finance', 'DisplaySubjectState')) return('Nemáte oprávnění');
    1715
     16        $this->System->Modules['Finance']->RecalculateTariffs(1);
    1817    $UserId = $this->System->Modules['User']->User['Id'];
    1918    if(!array_key_exists('show', $_GET)) $_GET['show'] = '';
     
    5655    $DbResult = $this->Database->query('SELECT SUM(consumption) AS Total FROM network_devices WHERE user='.$UserId.' AND used=1');
    5756        $ConsumptionBonus = $DbResult->fetch_assoc();
    58         $ConsumptionBonus = W2Kc($ConsumptionBonus['Total']);
     57        $ConsumptionBonus = $this->System->Modules['Finance']->W2Kc($ConsumptionBonus['Total']);
    5958
    6059        $Total = 0;
     
    7978      while($Row = $DbResult->fetch_assoc())
    8079      {
    81         $Output .= '<tr><td>'.$Row['name'].'</td><td>'.$Row['consumption'].'</td><td>'.W2Kc($Row['consumption']).'</td></tr>';
     80        $Output .= '<tr><td>'.$Row['name'].'</td><td>'.$Row['consumption'].'</td><td>'.$this->System->Modules['Finance']->W2Kc($Row['consumption']).'</td></tr>';
    8281        $TotalW += $Row['consumption'];
    83         $TotalPrice += W2Kc($Row['consumption']);
     82        $TotalPrice += $this->System->Modules['Finance']->W2Kc($Row['consumption']);
    8483      }
    8584      $Output .= '<tr><td><strong>Celkem</strong></td><td><strong>'.$TotalW.'</strong></td><td><strong>'.$TotalPrice.'</strong></td></tr>';
  • www/finance/user_state_ip.php

    r156 r157  
    22
    33include_once('../global.php');
    4 include_once('include.php');
    5 RecalculateTariffs(1);
    64
    75class FinanceUserState extends Page
     
    1412    global $Tarify, $Sprava;
    1513
    16         $UserId = GetMemberByIP(GetRemoteAddress());
     14        $this->System->Modules['Finance']->RecalculateTariffs(1);
     15
     16    $UserId = GetMemberByIP(GetRemoteAddress());
    1717
    1818    if(!array_key_exists('show', $_GET)) $_GET['show'] = '';
     
    5555    $DbResult = $this->Database->query('SELECT SUM(consumption) AS Total FROM network_devices WHERE user='.$UserId.' AND used=1');
    5656        $ConsumptionBonus = $DbResult->fetch_assoc();
    57         $ConsumptionBonus = W2Kc($ConsumptionBonus['Total']);
     57        $ConsumptionBonus = $this->System->Modules['Finance']->W2Kc($ConsumptionBonus['Total']);
    5858
    5959        $Total = 0;
     
    7878      while($Row = $DbResult->fetch_assoc())
    7979      {
    80         $Output .= '<tr><td>'.$Row['name'].'</td><td>'.$Row['consumption'].'</td><td>'.W2Kc($Row['consumption']).'</td></tr>';
     80        $Output .= '<tr><td>'.$Row['name'].'</td><td>'.$Row['consumption'].'</td><td>'.$this->System->Modules['Finance']->W2Kc($Row['consumption']).'</td></tr>';
    8181        $TotalW += $Row['consumption'];
    82         $TotalPrice += W2Kc($Row['consumption']);
     82        $TotalPrice += $this->System->Modules['Finance']->W2Kc($Row['consumption']);
    8383      }
    8484      $Output .= '<tr><td><strong>Celkem</strong></td><td><strong>'.$TotalW.'</strong></td><td><strong>'.$TotalPrice.'</strong></td></tr>';
  • www/finance/zarizeni.php

    r152 r157  
    11<?php
    22include_once('../global.php');
    3 include_once('include.php');
    43
    54class FinanceDeviceListPage extends Page
  • www/finance/zivnost.php

    r152 r157  
    11<?php
    22include_once('../global.php');
    3 include_once('include.php');
    43
    54class FinanceTaxFilingPage extends Page
     
    3130  function Show()
    3231  {
    33     RecalculateTariffs(1);
     32    $this->System->Modules['Finance']->RecalculateTariffs(1);
    3433    //TransformFinance();
    3534
  • www/global.php

    r154 r157  
    5252include_once('finance/finance.php');
    5353$System->AddModule(new Finance());
     54$System->Modules['Finance']->LoadMonthParameters(0);
    5455
    5556$MonthNames = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec');
  • www/module.php

    r148 r157  
    1212  {
    1313  }
    14 
    1514}
    1615
Note: See TracChangeset for help on using the changeset viewer.