Changeset 6 for www/finance/include.php
- Timestamp:
- Jan 16, 2008, 8:40:08 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
www/finance/include.php
r4 r6 4 4 function RecalculateTariffs($Period = 1) 5 5 { 6 global $Tarify, $MaxSpeed, $Internet, $SpeedElement, $ Database;6 global $Tarify, $MaxSpeed, $Internet, $SpeedElement, $BaseSpeedElement, $Database; 7 7 8 $ResidualPrice = $Internet; 9 $ResidualSpeed = $MaxSpeed; 10 8 11 $Tarify = array(); 9 12 $DbResult = $Database->select('finance_tariffs', '*', 'period='.$Period.' ORDER BY speed_factor'); … … 23 26 $Row = $DbResult->fetch_array(); 24 27 $Tarify[$Index]['user_count'] = $Row[0]; 25 $TotalUserCount = $TotalUserCount + $Tarify[$Index]['user_count']; 26 $Tarify[$Index]['total_units'] = $Tarify[$Index]['price_units'] * $Tarify[$Index]['user_count']; 27 $TotalTarifUnits = $TotalTarifUnits + $Tarify[$Index]['total_units']; 28 switch($Tarif['group_id']) 29 { 30 case 1: 31 $TotalUserCount = $TotalUserCount + $Tarify[$Index]['user_count']; 32 $Tarify[$Index]['total_units'] = $Tarify[$Index]['price_units'] * $Tarify[$Index]['user_count']; 33 $TotalTarifUnits = $TotalTarifUnits + $Tarify[$Index]['total_units']; 28 34 29 if($Index == 3) // Zarizeni site v tarifu 3 neplati penize, ale ma internet 30 $Tarify[$Index]['total_speed_factor'] = $Tarify[$Index]['speed_factor'] * ($Tarify[$Index]['user_count']+1); 31 else $Tarify[$Index]['total_speed_factor'] = $Tarify[$Index]['speed_factor'] * $Tarify[$Index]['user_count']; 32 $TotalTarifSpeedUnits = $TotalTarifSpeedUnits + $Tarify[$Index]['total_speed_factor']; 35 if($Index == 3) // Zarizeni site v tarifu 3 neplati penize, ale ma internet 36 $Tarify[$Index]['total_speed_factor'] = $Tarify[$Index]['speed_factor'] * ($Tarify[$Index]['user_count']+1); 37 else $Tarify[$Index]['total_speed_factor'] = $Tarify[$Index]['speed_factor'] * $Tarify[$Index]['user_count']; 38 $TotalTarifSpeedUnits = $TotalTarifSpeedUnits + $Tarify[$Index]['total_speed_factor']; 39 break; 40 case 2: 41 $ResidualPrice -= $Tarif['price'] * $Tarify[$Index]['user_count']; 42 $ResidualSpeed -= $Tarif['min_speed'] * $Tarify[$Index]['user_count']; 43 $Tarify[$Index]['total_units'] = $Tarify[$Index]['price_units'] * $Tarify[$Index]['user_count']; 44 break; 45 case 3: 46 $Tarify[$Index]['total_units'] = $Tarify[$Index]['price_units'] * $Tarify[$Index]['user_count']; 47 break; 48 } 33 49 } 34 $PricePerUnit = $Internet / $TotalTarifUnits; 35 $SpeedPerUnit = $MaxSpeed * 1024 / $TotalTarifSpeedUnits; 50 $PricePerUnit = $ResidualPrice / $TotalTarifUnits; 51 $SpeedPerUnit = $ResidualSpeed * 1024 / $TotalTarifSpeedUnits; 52 36 53 // Recalculate price 37 $SpeedElement = 256*1024;38 54 foreach($Tarify as $Index => $Tarif) 39 55 { 40 $Tarify[$Index]['price'] = round($Tarif['price_units'] * $PricePerUnit); 41 $Tarify[$Index]['min_speed'] = round($Tarif['speed_factor'] * $SpeedPerUnit); 42 $Tarify[$Index]['max_speed'] = round($Tarify[$Index]['speed_factor'] * $SpeedElement); 56 switch($Tarif['group_id']) 57 { 58 case 1: 59 $Tarify[$Index]['price'] = round($Tarif['price_units'] * $PricePerUnit); 60 $Tarify[$Index]['min_speed'] = round($Tarif['speed_factor'] * $SpeedPerUnit); 61 $Tarify[$Index]['max_speed'] = round($Tarify[$Index]['speed_factor'] * $BaseSpeedElement * 1024); 62 break; 63 case 2: 64 $Tarify[$Index]['min_speed'] = $Tarify[$Index]['min_speed'] * 1024; 65 $Tarify[$Index]['max_speed'] = $Tarify[$Index]['max_speed'] * 1024; 66 break; 67 case 3: 68 $Tarify[$Index]['min_speed'] = $Tarify[$Index]['min_speed'] * 1024; 69 $Tarify[$Index]['max_speed'] = $Tarify[$Index]['max_speed'] * 1024; 70 break; 71 } 43 72 $Tarify[$Index]['aggregation'] = '1:'.round($Tarify[$Index]['max_speed'] / $Tarify[$Index]['min_speed']); 44 //echo($Tarify[$Index]['price'].'<br>');45 73 } 46 74 } … … 49 77 { 50 78 global $kWh, $Internet, $Sprava, $DatumOdecteni, $InternetUsers, $SpravaUsers, $InternetSegmentId, 51 $MaxSpeed, $RealMaxSpeed, $SpeedReserve, $ Database;79 $MaxSpeed, $RealMaxSpeed, $SpeedReserve, $BaseSpeedElement, $Database; 52 80 53 81 $DbResult = $Database->query("SELECT * FROM finance_charge WHERE period=".$Period); … … 58 86 $RealMaxSpeed = $Row['internet_speed']; 59 87 $SpeedReserve = $Row['internet_speed_reserve']; 88 $BaseSpeedElement = $Row['base_speed_element']; 60 89 $MaxSpeed = $RealMaxSpeed - $SpeedReserve; 61 90
Note:
See TracChangeset
for help on using the changeset viewer.