Changeset 204 for trunk/finance


Ignore:
Timestamp:
May 1, 2009, 12:13:50 PM (16 years ago)
Author:
george
Message:
  • Upraveno: Tabulka finance_tariffs přejmenována na FinanceTariff a přepracována její struktura podle aktuálních potřeb. Do tabulky uloženy průběžné výpočty jako sloupec MemberCount či dynamicky přepočítavaný sloupce SpeedMin. Zrušeno přepočítávání ceny a rychlosti dle cenových jednotek a rychlostních jednotek.
  • Přidáno: Sloupec Hire v tabulce Member sloužící pro záznam placení nájmu členům.
Location:
trunk/finance
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/finance/clenove.php

    r189 r204  
    2828      $TotalCash += $Row['Cash'];
    2929      if($Row['Cash'] < 0) $Row['Cash'] = '<span style="color: red;">'.$Row['Cash'].'</span>';
    30       $Tarif = $Finance->Tarify[$Row['InternetTariffCurrentMonth']]['name'];
    31       $PristiTarif = $Finance->Tarify[$Row['InternetTariffNextMonth']]['name'];
     30      $Tarif = $Finance->Tariffs[$Row['InternetTariffCurrentMonth']]['Name'];
     31      $PristiTarif = $Finance->Tariffs[$Row['InternetTariffNextMonth']]['Name'];
    3232      $Output .= '<tr><td>'.$Row['FullName'].'</td><td><a href="user_state.php?Subject='.$Row['Id'].'">'.$Row['Name'].'</a></td>';
    3333      //<td align="right">'.$Row['network_device'].'</td>
  • trunk/finance/finance.php

    r195 r204  
    2020  var $TotalPaid;
    2121  var $TotalInternetPaid;
    22   var $Tarify;
     22  var $Tariffs;
    2323  var $ExternalSubject = 96;
    2424  var $MainSubject = 71;
    2525        var $BillingPeriods;
    2626 
     27  function LoadTariffs($Period = 1)
     28  {
     29    $this->Tariffs = array();
     30    $DbResult = $this->Database->select('FinanceTariff', '*', 'Period='.$Period.' ORDER BY Tariff, SpeedMax');
     31    while($Tariff = $DbResult->fetch_array())
     32    {
     33      $Tariff['SpeedMin'] = $Tariff['SpeedMin'] * 1024;
     34      $Tariff['SpeedMax'] = $Tariff['SpeedMax'] * 1024;
     35      $this->Tariffs[$Tariff['Tariff']] = $Tariff;
     36    } 
     37  }
     38 
    2739  function RecalculateTariffs($Period = 1)
    2840  {
    29     $ResidualPrice = $this->Internet;
    30     $ResidualSpeed = $this->MaxSpeed;
    31  
    32     $Tarify = array();
    33     $DbResult = $this->Database->select('finance_tariffs', '*', 'period='.$Period.' ORDER BY id,speed_factor');
    34     while($Tariff = $DbResult->fetch_array())
    35     {
    36       $Tarify[$Tariff['id']] = $Tariff;
    37     } 
    38 
    39     if($Period == 0) $Column = 'Current'; else $Column = 'Next';
    40     $TotalUserCount = 0;
    41     $TotalUnits = 0;
    42     $TotalTarifUnits = 0;
    43     $TotalTarifSpeedUnits = 0;
    44     foreach($Tarify as $Index => $Tarif)
    45     {
    46       $DbResult = $this->Database->select('Member', 'COUNT(*)', 'InternetTariff'.$Column.'Month='.$Index);
     41    $ResidualSpeed = $this->MaxSpeed * 1024;
     42 
     43    $this->LoadTariffs($Period);
     44   
     45    $Column = array('Current', 'Next');
     46    $TotalMemberCount = 0;
     47    $TotalMaxSpeed = 0;
     48    foreach($this->Tariffs as $Index => $Tariff)
     49    {
     50      $DbResult = $this->Database->select('Member', 'COUNT(*)', 'InternetTariff'.$Column[$Period].'Month='.$Index);
    4751      $Row = $DbResult->fetch_row();
    48       $Tarify[$Index]['user_count'] = $Row[0];   
    49       switch($Tarif['group_id'])
     52      $this->Tariffs[$Index]['MemberCount'] = $Row[0];
     53      $Tariffs['MemberCount'] = $Row[0];
     54     
     55      //echo($Tariff['Name'].' '.$Tariff['MemberCount'].' '.$Tariff['SpeedMax'] * $Tariff['MemberCount'].' '.$ResidualSpeed.'<br />');
     56      switch($Tariff['Group'])
    5057      {
    5158        case 1:
    52           $TotalUserCount = $TotalUserCount + $Tarify[$Index]['user_count'];
    53           $Tarify[$Index]['total_units'] = $Tarify[$Index]['price_units'] * $Tarify[$Index]['user_count'];
    54           $TotalTarifUnits = $TotalTarifUnits + $Tarify[$Index]['total_units'];
    55    
    56           if($Index == 3) // Zarizeni site v tarifu 3 neplati penize, ale ma internet
    57             $Tarify[$Index]['total_speed_factor'] = $Tarify[$Index]['speed_factor'] * ($Tarify[$Index]['user_count']+1);
    58             else $Tarify[$Index]['total_speed_factor'] = $Tarify[$Index]['speed_factor'] * $Tarify[$Index]['user_count'];
    59           $TotalTarifSpeedUnits = $TotalTarifSpeedUnits + $Tarify[$Index]['total_speed_factor'];
     59          $TotalMemberCount += $Tariff['MemberCount'];
     60          $TotalMaxSpeed += $Tariff['SpeedMax'] * $Tariff['MemberCount'];
    6061          break;
    6162        case 2:
    62           $ResidualPrice -= $Tarif['price'] * $Tarify[$Index]['user_count'];
    63           $ResidualSpeed -= $Tarif['min_speed'] * $Tarify[$Index]['user_count'];
    64           $Tarify[$Index]['total_units'] = $Tarify[$Index]['price_units'] * $Tarify[$Index]['user_count'];
     63          $ResidualSpeed -= $Tariff['SpeedMin'] * $Tariff['MemberCount'];
    6564          break;
    6665        case 3:
    67           $Tarify[$Index]['total_units'] = $Tarify[$Index]['price_units'] * $Tarify[$Index]['user_count'];
    68           break;
    69       }
    70     }
    71     //$PricePerUnit = $TopTariffPrice / ;  // $ResidualPrice / $TotalTarifUnits;
    72     $SpeedPerUnit = $ResidualSpeed * 1024 / $TotalTarifSpeedUnits;
     66          break;
     67      }
     68    }
     69    $Aggregation = $ResidualSpeed / $TotalMaxSpeed;
     70    //echo($TotalMaxSpeed.' '.$Aggregation.'<br />');
    7371 
    7472    // Recalculate price
    75     foreach($Tarify as $Index => $Tarif)
    76     {
    77       switch($Tarif['group_id'])
     73    foreach($this->Tariffs as $Index => $Tariff)
     74    {
     75      switch($Tariff['Group'])
    7876      {
    7977        case 1:
    80           $Tarify[$Index]['price'] = $this->BaseTariffPrice + round($this->TopTariffPrice * $Tarif['price_units'] / 10) * 10;
    81           $Tarify[$Index]['min_speed'] = round($Tarif['speed_factor'] * $SpeedPerUnit);
    82           $Tarify[$Index]['max_speed'] = round($Tarify[$Index]['speed_factor'] * $this->BaseSpeedElement * 1024);
     78          $Tariff['SpeedMin'] = round($Tariff['SpeedMax'] * $Aggregation);
    8379          break;
    8480        case 2:
    85           $Tarify[$Index]['min_speed'] = $Tarify[$Index]['min_speed'] * 1024;
    86           $Tarify[$Index]['max_speed'] = $Tarify[$Index]['max_speed'] * 1024;
    8781          break;
    8882        case 3:
    89           $Tarify[$Index]['price'] = $this->BaseTariffPrice + round($this->TopTariffPrice * $Tarif['price_units']);
    90           $Tarify[$Index]['min_speed'] = $Tarify[$Index]['min_speed'] * 1024;
    91           $Tarify[$Index]['max_speed'] = $Tarify[$Index]['max_speed'] * 1024;
    92           break;
    93       }
    94       $Tarify[$Index]['aggregation'] = '1:'.round($Tarify[$Index]['max_speed'] / $Tarify[$Index]['min_speed']);
    95     }
    96           $this->Tarify = $Tarify;
     83          break;
     84      }
     85      //echo('MinSpeed: '.$Tariff['SpeedMin'].'<br />');
     86      $this->Database->update('FinanceTariff', 'Tariff='.$Tariff['Tariff'], array('SpeedMin' => ($Tariff['SpeedMin'] / 1024), 'MemberCount' => $Tariff['MemberCount']));
     87    }
     88    $this->LoadTariffs($Period);
    9789  }
    9890
     
    130122 
    131123    $this->RecalculateTariffs($Period);
     124    $this->LoadTariffs($Period);
    132125  }
    133126
     
    175168         
    176169      $Monthly = 0;
    177       $MonthlyInet = $this->Tarify[$Member['InternetTariffNextMonth']]['price'];
     170      $MonthlyInet = $this->Tariffs[$Member['InternetTariffNextMonth']]['Price'];
    178171      //if($Row['inet'] == 1)
    179172      $Monthly += $MonthlyInet;
    180173      $Monthly -= $this->W2Kc($ConsumptionPlus);
     174      $Monthly -= $Member['Hire'];
    181175      //if($Row['overheads'] == 1) $Monthly += $Sprava; // + W2Kc($Consumption);
    182176      //echo($Row['fullname'].' '.$Row['inet'].' '.$Monthly.'<br>');
  • trunk/finance/index.php

    r167 r204  
    2424    $Output .= '<br /><strong>Souhrn:</strong><br />';
    2525
    26     $DbResult = $this->Database->query("SELECT * FROM finance_monthly_overall ORDER BY date DESC LIMIT 0,1");
     26    $DbResult = $this->Database->query('SELECT * FROM finance_monthly_overall ORDER BY date DESC LIMIT 0,1');
    2727    $Row = $DbResult->fetch_array();
    2828    $Output .= 'Platba za internetovou linku ('.$Finance->RealMaxSpeed.'/'.$Finance->RealMaxSpeed.' kbit/s): <strong>'.$Finance->Internet.' Kč</strong><br />';
     
    5757    $TotalGain = 0;
    5858    $TotalExpense = 0;
    59     $DbResult = $this->Database->query("SELECT SUM(consumption) FROM network_devices WHERE used=1");
     59    $DbResult = $this->Database->query('SELECT SUM(consumption) FROM network_devices WHERE used=1');
    6060    $Row = $DbResult->fetch_array();
    6161    $TotalConsumption = $this->System->Modules['Finance']->W2Kc($Row[0]);
  • trunk/finance/manage.php

    r186 r204  
    553553      $Output .= 'Měním aktuální tarify....<br>';
    554554      // Update tarrifs
    555       $this->Database->delete('finance_tariffs', 'period=0');
    556       $DbResult = $this->Database->select('finance_tariffs', '*', 'period = 1');
     555      $this->Database->delete('FinanceTariffs', 'Period=0');
     556      $DbResult = $this->Database->select('FinanceTariff', '*', 'Period = 1');
    557557      while($Tariff = $DbResult->fetch_array())
    558558      {
    559         $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']));
     559        $this->Database->insert('FinanceTariff', array('Period' => 0, 'Name' => $Tariff['Name'], 'Tariff' => $Tariff['Tariff'], 'UploadAsymmetry' => $Tariff['UploadAsymmetry'], 'MemberCount' => $Tariff['MemberCount'], 'Group' => $Tariff['Group'], 'SpeedMin' => $Tariff['SpeedMin'], 'SpeedMax' => $Tariff['SpeedMax'], 'Price' => $Tariff['Price']));
    560560      }
    561561
     
    566566
    567567      // Restart traffic shaping
    568       $this->Database->update('services_restart', 'id = 3', array('changed' => 1));
     568      //$this->Database->update('NetworkConfiguration', 'Id = 3', array('Changed' => 1));
    569569    }
    570570    return($Output);
  • trunk/finance/tarify.php

    r179 r204  
    1818
    1919    $Output .= '<table width="50%" class="WideTable" style="font-size: small;">';
    20     $Output .= '<tr><th>Název tarifu</th><th>Min. rychlost [kbit/s]</th><th>Max. rychlost [kbit/s]</th><th>Agregační poměr</th><th>Cenových jednotek</th><th>Počet podílníků</th><th>Celkem cenových jednotek</th><th>Cena [Kč]</th><th>Vybráno celkem [Kč]</th></tr>';
     20    $Output .= '<tr><th>Název tarifu</th><th>Min. rychlost [kbit/s]</th><th>Max. rychlost [kbit/s]</th><th>Agregační poměr</th><th>Počet podílníků</th><th>Cena [Kč]</th><th>Součet ceny [Kč]</th></tr>';
    2121    $TotalPrice = 0;
    22     $TotalUnits = 0;
    23     foreach($Finance->Tarify as $Index => $Tarif)
     22    foreach($Finance->Tariffs as $Index => $Tariff)
    2423    {
    25       $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">'.
    26       $Tarif['total_units'].'</td><td align="center" style="color: blue;">'.$Tarif['price'].'</td><td align="center">'.$Tarif['user_count'] * $Tarif['price'].'</td></tr>';
    27       $TotalPrice = $TotalPrice + $Tarif['price'] * $Tarif['user_count'];
    28       $TotalUnits = $TotalUnits + $Tarif['total_units'];
     24      $Tariff['Aggregation'] = '1:'.round($Tariff['SpeedMax'] / $Tariff['SpeedMin']);
     25      $Output .= '<tr><td style="color: blue;">'.$Tariff['Name'].'</td><td align="center">'.round($Tariff['SpeedMin'] / 1024).'</td><td align="center" style="color: blue;">'.round($Tariff['SpeedMax'] / 1024).'</td><td align="center">'.$Tariff['Aggregation'].'</td><td align="center">'.$Tariff['MemberCount'].'</td><td align="center" style="color: blue;">'.$Tariff['Price'].'</td><td align="center">'.$Tariff['MemberCount'] * $Tariff['Price'].'</td></tr>';
     26      $TotalPrice = $TotalPrice + $Tariff['Price'] * $Tariff['MemberCount'];
    2927    }
    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>';
     28    $Output .= '<tr><td>Součty</td><td colspan="3">&nbsp;</td><td align="center">'.$Finance->InternetUsers.'</td><td>&nbsp;</td><td align="center">'.$TotalPrice.'</td></tr>';
    3129    $Output .= '</table>';
    3230    return($Output);
  • trunk/finance/user_state.php

    r179 r204  
    3838    $DbResult = $this->Database->query('SELECT * FROM Member LEFT JOIN MemberPayment ON MemberPayment.Member=Member.Id WHERE Member.Subject='.$Subject['Id']);
    3939    $Member = $DbResult->fetch_assoc();
    40     $TarifName = $Finance->Tarify[$Member['InternetTariffCurrentMonth']]['name'];
    41           $TarifPrice = $Finance->Tarify[$Member['InternetTariffCurrentMonth']]['price'];
     40    $TarifName = $Finance->Tariffs[$Member['InternetTariffCurrentMonth']]['Name'];
     41          $TarifPrice = $Finance->Tariffs[$Member['InternetTariffCurrentMonth']]['Price'];
    4242    $Output = '<table width="100%" border="0" cellspacing="0" cellpadding="3"><tr><td valign="top">';
    4343
     
    6868    $Output .= 'Variabilní symbol pro platby: <strong>'.$Subject['Id'].'</strong><br><br>';
    6969
    70         $Total = 0;
     70          $Total = 0;
    7171    $Output .= 'Rozpis měsíčního poplatku:<br><table class="WideTable">'.
    7272      '<tr><th>Část</th><th>Cena [Kč]</th></tr>'.
    7373      '<tr><td>Internet - tarif '.$TarifName.'</td><td>'.$TarifPrice.'</td></tr>';
    74         $Total += $TarifPrice;
    75         if($Member['MonthlyPlus'] != 0)
    76       $Output .= '<tr><td>Příjem za spotřebu</td><td>'.(-$Member['MonthlyPlus'])  .'</td></tr>';
    77         $Total += -$Member['MonthlyPlus'];
     74    $Total += $TarifPrice;
     75          if($Member['Hire'] != 0)
     76    {
     77      $Output .= '<tr><td>Nájem</td><td>'.(-$Member['Hire']).'</td></tr>';
     78            $Total -= $Member['Hire'];
     79    }
     80          if($Member['MonthlyPlus'] != 0)
     81    {
     82      $Output .= '<tr><td>Příjem za spotřebu</td><td>'.(-$Member['MonthlyPlus']).'</td></tr>';
     83            $Total -= $Member['MonthlyPlus'];
     84    }
    7885    $Output .= '<tr><td><strong>Celkem</strong></td><td><strong>'.$Total.'</strong></td></tr></table>';
    7986    //echo('Tarif pro příští měsíc: '.$Tarify[$Row2['inet_tarif_next']]['name'].'<br><br>');
     
    8289    if($Member['MonthlyPlus'] != 0)
    8390    {
    84           $Output .= 'Měsíční příjem za spotřebu zařízení umístěných u uživatele:<br>';
     91      $Output .= 'Měsíční příjem za spotřebu zařízení umístěných u uživatele:<br>';
    8592      $Output .= '<table class="WideTable"><tr><th>Název zařízení</th><th>Spotřeba [W]</th><th>Příjem [Kč]</th></tr>';
    8693      $DbResult = $this->Database->query('SELECT * FROM network_devices WHERE user='.$Member['Id'].' AND used=1');
Note: See TracChangeset for help on using the changeset viewer.