Changeset 204 for trunk/finance/finance.php
- Timestamp:
- May 1, 2009, 12:13:50 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/finance/finance.php
r195 r204 20 20 var $TotalPaid; 21 21 var $TotalInternetPaid; 22 var $Tarif y;22 var $Tariffs; 23 23 var $ExternalSubject = 96; 24 24 var $MainSubject = 71; 25 25 var $BillingPeriods; 26 26 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 27 39 function RecalculateTariffs($Period = 1) 28 40 { 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); 47 51 $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']) 50 57 { 51 58 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']; 60 61 break; 61 62 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']; 65 64 break; 66 65 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 />'); 73 71 74 72 // 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']) 78 76 { 79 77 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); 83 79 break; 84 80 case 2: 85 $Tarify[$Index]['min_speed'] = $Tarify[$Index]['min_speed'] * 1024;86 $Tarify[$Index]['max_speed'] = $Tarify[$Index]['max_speed'] * 1024;87 81 break; 88 82 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); 97 89 } 98 90 … … 130 122 131 123 $this->RecalculateTariffs($Period); 124 $this->LoadTariffs($Period); 132 125 } 133 126 … … 175 168 176 169 $Monthly = 0; 177 $MonthlyInet = $this->Tarif y[$Member['InternetTariffNextMonth']]['price'];170 $MonthlyInet = $this->Tariffs[$Member['InternetTariffNextMonth']]['Price']; 178 171 //if($Row['inet'] == 1) 179 172 $Monthly += $MonthlyInet; 180 173 $Monthly -= $this->W2Kc($ConsumptionPlus); 174 $Monthly -= $Member['Hire']; 181 175 //if($Row['overheads'] == 1) $Monthly += $Sprava; // + W2Kc($Consumption); 182 176 //echo($Row['fullname'].' '.$Row['inet'].' '.$Monthly.'<br>');
Note:
See TracChangeset
for help on using the changeset viewer.