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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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>');
Note: See TracChangeset for help on using the changeset viewer.