source: www/finance/include.php@ 152

Last change on this file since 152 was 152, checked in by george, 16 years ago
  • Upraveno: Další soubory přepracované do nového systému zobrazování.
  • Property svn:executable set to *
File size: 5.2 KB
Line 
1<?php
2NactiMesicniParametry();
3
4function RecalculateTariffs($Period = 1)
5{
6 global $Tarify, $MaxSpeed, $Internet, $SpeedElement, $BaseSpeedElement, $Database, $BaseTariffPrice, $TopTariffPrice;
7
8 $ResidualPrice = $Internet;
9 $ResidualSpeed = $MaxSpeed;
10
11 $Tarify = array();
12 $DbResult = $Database->select('finance_tariffs', '*', 'period='.$Period.' ORDER BY id,speed_factor');
13 while($Tariff = $DbResult->fetch_array())
14 {
15 $Tarify[$Tariff['id']] = $Tariff;
16 }
17
18 if($Period == 0) $Column = 'now'; else $Column = 'next';
19 $TotalUserCount = 0;
20 $TotalUnits = 0;
21 $TotalTarifUnits = 0;
22 $TotalTarifSpeedUnits = 0;
23 foreach($Tarify as $Index => $Tarif)
24 {
25 $DbResult = $Database->select('users', 'COUNT(*)', 'inet_tarif_'.$Column.'='.$Index.' AND inet=1 AND role=2');
26 $Row = $DbResult->fetch_array();
27 $Tarify[$Index]['user_count'] = $Row[0];
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'];
34
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 }
49 }
50 //$PricePerUnit = $TopTariffPrice / ; // $ResidualPrice / $TotalTarifUnits;
51 $SpeedPerUnit = $ResidualSpeed * 1024 / $TotalTarifSpeedUnits;
52
53 // Recalculate price
54 foreach($Tarify as $Index => $Tarif)
55 {
56 switch($Tarif['group_id'])
57 {
58 case 1:
59 $Tarify[$Index]['price'] = $BaseTariffPrice + round($TopTariffPrice * $Tarif['price_units'] / 10) * 10;
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]['price'] = $BaseTariffPrice + round($TopTariffPrice * $Tarif['price_units']);
69 $Tarify[$Index]['min_speed'] = $Tarify[$Index]['min_speed'] * 1024;
70 $Tarify[$Index]['max_speed'] = $Tarify[$Index]['max_speed'] * 1024;
71 break;
72 }
73 $Tarify[$Index]['aggregation'] = '1:'.round($Tarify[$Index]['max_speed'] / $Tarify[$Index]['min_speed']);
74 }
75}
76
77function NactiMesicniParametry($Period = 1) // 0 - now, 1 - next month
78{
79 global $kWh, $Internet, $Sprava, $DatumOdecteni, $InternetUsers, $SpravaUsers, $InternetSegmentId,
80 $MaxSpeed, $RealMaxSpeed, $SpeedReserve, $BaseSpeedElement, $Database, $TotalConsumption, $UserIdNetwork,
81 $BaseTariffPrice, $TopTariffPrice, $TotalPaid, $TotalInternetPaid;
82
83 $DbResult = $Database->query("SELECT * FROM finance_charge WHERE period=".$Period);
84 $Row = $DbResult->fetch_array();
85 $kWh = $Row['kWh'];
86 $Internet = $Row['internet'];
87 $Sprava = $Row['administration_per_user'];
88 $RealMaxSpeed = $Row['internet_speed'];
89 $SpeedReserve = $Row['internet_speed_reserve'];
90 $BaseSpeedElement = $Row['base_speed_element'];
91 $MaxSpeed = $RealMaxSpeed - $SpeedReserve;
92 $TopTariffPrice = $Row['TopTariffPrice'];
93 $BaseTariffPrice = $Row['BaseTariffPrice'];
94
95 $DbResult = $Database->query("SELECT COUNT(*) FROM users WHERE inet=1 AND role=2");
96 $Row = $DbResult->fetch_array();
97 $InternetUsers = $Row[0];
98
99 $DbResult = $Database->query("SELECT COUNT(*) FROM users WHERE overheads=1 AND role=2");
100 $SpravaUsers = $DbResult->fetch_array();
101 $SpravaUsers = $SpravaUsers[0];
102 $InternetSegmentId = 21;
103 $DbResult = $Database->query("SELECT SUM(consumption) FROM network_segments");
104 $TotalConsumption = $DbResult->fetch_array();
105 $TotalConsumption = $TotalConsumption[0];
106 $UserIdNetwork = 46;
107
108 $DbResult = $Database->query("SELECT SUM(`monthly`) as `internet`, SUM(`monthly` - `plus`) as `real` FROM users WHERE role=2");
109 $Row = $DbResult->fetch_array();
110 $TotalInternetPaid = $Row['internet'];
111 $TotalPaid = $Row['real'];
112
113 RecalculateTariffs($Period);
114}
115
116function W2Kc($Spotreba)
117{
118 global $kWh;
119 return(round($Spotreba * 0.72 * $kWh));
120}
121
122function GetNextDocumentLineNumber($Id)
123{
124 global $Database;
125
126 $DbResult = $Database->query('SELECT Shortcut, NextNumber FROM DocumentLine WHERE Id='.$Id);
127 $DbRow = $DbResult->fetch_assoc();
128 $Result = $DbRow['Shortcut'].$DbRow['NextNumber'];
129 $Database->query('UPDATE DocumentLine SET NextNumber = NextNumber + 1 WHERE Id='.$Id);
130 return($Result);
131}
132
133
134?>
Note: See TracBrowser for help on using the repository browser.