Changeset 4 for www/finance/prepocet.php
- Timestamp:
- Jan 14, 2008, 9:48:39 PM (17 years ago)
- Location:
- www
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
www
-
Property svn:ignore
set to
config.php
php_script_error.log
-
Property svn:ignore
set to
-
www/finance/prepocet.php
r1 r4 1 <? 2 include('../db.php'); 3 include('../is/error.php'); 4 DB_Init('localhost','root','','is'); 5 DB_Query('SET CHARACTER SET latin2'); 1 <?php 2 include('../global.php'); 6 3 include('include.php'); 7 4 … … 10 7 global $InternetSegmentId, $Tarify, $Sprava; 11 8 12 DB_Query("SELECT * FROM users WHERE role=0"); // Select network members only13 while($Row = DB_Row())9 $DbResult = $Database->query("SELECT * FROM users WHERE role=0"); // Select network members only 10 while($Row = $DbResult->fetch_array()) 14 11 { 15 DB_Save(); 16 DB_Query("SELECT SUM(money) FROM finance_operations WHERE user=".$Row['id']); // Account state 17 $Row3 = DB_Row(); 18 DB_Query("SELECT SUM(consumption) FROM network_devices WHERE user=".$Row['id']." AND used=1"); 19 $Row4 = DB_Row(); 12 $DbResult2 = $Database->query("SELECT SUM(money) FROM finance_operations WHERE user=".$Row['id']); // Account state 13 $Row3 = $DbResult2->fetch_array(); 14 $DbResult2 = $Database->query("SELECT SUM(consumption) FROM network_devices WHERE user=".$Row['id']." AND used=1"); 15 $Row4 = $DbResult2->fetch_array(); 20 16 //DB_Update('users','id='.$Row['id'], array()); 21 17 … … 25 21 while($ID != 0) 26 22 { 27 DB_Query("SELECT * FROM network_segments WHERE id=".$ID);28 $Row2 = DB_Row();23 $DbResult2 = $Database->query("SELECT * FROM network_segments WHERE id=".$ID); 24 $Row2 = $DbResult2->fetch_array(); 29 25 if(!(($Row['inet_hw'] == 0) and ($ID == $InternetSegmentId))) 30 26 { … … 42 38 $Monthly = round($Monthly); 43 39 //echo($Row['fullname'].' '.$Row['inet'].' '.$Monthly.'<br>'); 44 DB_Update('users', 'id='.$Row['id'], array('network_device' => $Price, 'monthly_inet' => $MonthlyInet, 'monthly' => $Monthly, 'consumption' => W2Kc($Consumption), 'cash' => ($Row3[0]-$Row['network_device']), 'plus' => W2Kc($Row4[0]))); 45 DB_Load(); 40 $Database->update('users', 'id='.$Row['id'], array('network_device' => $Price, 'monthly_inet' => $MonthlyInet, 'monthly' => $Monthly, 'consumption' => W2Kc($Consumption), 'cash' => ($Row3[0]-$Row['network_device']), 'plus' => W2Kc($Row4[0]))); 46 41 } 47 42 } 48 43 49 44 50 DB_Select('finance_monthly_overall', '*', '1 ORDER BY date DESC LIMIT 1');51 $Overall = DB_Row();45 $DbResult = $Database->select('finance_monthly_overall', '*', '1 ORDER BY date DESC LIMIT 1'); 46 $Overall = $DbResult->fetch_array(); 52 47 53 48 echo('Datum: '.date('j.n.Y')."\n"); 54 $Mesice = array('','Leden','Únor','B øezen','Duben','Kvìten','Èerven','Èervenec','Srpen','Záøí','Øíjen','Listopad','Prosinec');49 $Mesice = array('','Leden','Únor','Březen','Duben','Květen','Červen','Červenec','Srpen','Září','Říjen','Listopad','Prosinec'); 55 50 $Datum = explode('-', $Overall['date']); 56 51 $Mesic = date("m")+0; 57 52 58 // Spo èítat ceny segmentù53 // Spočítat ceny segmentů 59 54 echo("Prepocitavam ceny"); 60 DB_Query("UPDATE network_segments SET users=0"); // Vynulovat poèty poèítaèù 61 DB_Query("UPDATE network_segments SET users_overheads=0"); // Vynulovat poèty poèítaèù 62 DB_Query("SELECT * FROM network_segments");63 while($Row = DB_Row())55 $Database->query("UPDATE network_segments SET users=0"); // Vynulovat počty počítačů 56 $Database->query("UPDATE network_segments SET users_overheads=0"); // Vynulovat počty počítačů 57 $DbResult = $Database->query("SELECT * FROM network_segments"); 58 while($Row = $DbResult->fetch_array()) 64 59 { 65 60 //echo('Segment '.$Row['name'].'<br>'); 66 DB_Save(); 67 DB_Query("SELECT users FROM network_segments WHERE id=".$Row['id']); 68 $RowP = DB_Row(); 69 DB_Query("SELECT users_overheads FROM network_segments WHERE id=".$Row['id']); 70 $RowP2 = DB_Row(); 71 DB_Query("SELECT SUM(price),SUM(consumption) FROM network_devices WHERE segment=".$Row['id']." AND used=1"); 72 $Row2 = DB_Row(); 73 DB_Query("SELECT COUNT(*) FROM users WHERE network_segment=".$Row['id'].' AND hw=1'); 74 $Row3 = DB_Row(); 75 DB_Query("SELECT COUNT(*) FROM users WHERE network_segment=".$Row['id'].' AND overheads=1'); 76 $Row5 = DB_Row(); 61 $DbResult2 = $Database->query("SELECT users FROM network_segments WHERE id=".$Row['id']); 62 $RowP = $DbResult2->fetch_array(); 63 $DbResult2 = $Database->query("SELECT users_overheads FROM network_segments WHERE id=".$Row['id']); 64 $RowP2 = $DbResult2->fetch_array(); 65 $DbResult2 = $Database->query("SELECT SUM(price),SUM(consumption) FROM network_devices WHERE segment=".$Row['id']." AND used=1"); 66 $Row2 = $DbResult2->fetch_array(); 67 $DbResult2 = $Database->query("SELECT COUNT(*) FROM users WHERE network_segment=".$Row['id'].' AND hw=1'); 68 $Row3 = $DbResult2->fetch_array(); 69 $DbResult2 = $Database->query("SELECT COUNT(*) FROM users WHERE network_segment=".$Row['id'].' AND overheads=1'); 70 $Row5 = $DbResult2->fetch_array(); 77 71 $ID = $Row['parent']; 78 while($ID !=0)72 while($ID != 0) 79 73 { 80 74 //echo($ID.', '); 81 DB_Query("SELECT * FROM network_segments WHERE id=".$ID);82 $Row4 = DB_Row();83 DB_Update('network_segments', 'id='.$Row4['id'], array('users' => ($Row4['users']+$Row3[0]), 'users_overheads' => ($Row4['users_overheads']+$Row5[0])));75 $DbResult2 = $Database->query("SELECT * FROM network_segments WHERE id=".$ID); 76 $Row4 = $DbResult2->fetch_array(); 77 $Database->update('network_segments', 'id='.$Row4['id'], array('users' => ($Row4['users']+$Row3[0]), 'users_overheads' => ($Row4['users_overheads']+$Row5[0]))); 84 78 $ID = $Row4['parent']; 85 79 } 86 80 //echo('Pocet '.$Row3[0].','.$Row['hosts'].'<br>'); 87 DB_Update('network_segments','id='.$Row['id'],array('price' => $Row2[0], 'users' => ($Row3[0]+$RowP['users']), 'consumption' => $Row2[1], 'users_overheads' => ($Row5[0]+$RowP2['users_overheads']))); 88 DB_Load(); 81 $Database->update('network_segments','id='.$Row['id'],array('price' => $Row2[0], 'users' => ($Row3[0]+$RowP['users']), 'consumption' => $Row2[1], 'users_overheads' => ($Row5[0]+$RowP2['users_overheads']))); 89 82 } 90 83 91 84 // Zkorigovat segment Internet 92 DB_Select('users', 'COUNT(*)', 'inet_hw=1');93 $Row = DB_Row();94 DB_Select('users', 'COUNT(*)', 'inet=1');95 $Row2 = DB_Row();96 DB_Update('network_segments','id='.$InternetSegmentId, array('users' => $Row[0], 'users_overheads' => $Row2[0]));85 $DbResult = $Database->select('users', 'COUNT(*)', 'inet_hw=1'); 86 $Row = $DbResult->fetch_array(); 87 $DbResult = $Database->select('users', 'COUNT(*)', 'inet=1'); 88 $Row2 = $DbResult->fetch_array(); 89 $DbResult = $Database->update('network_segments','id='.$InternetSegmentId, array('users' => $Row[0], 'users_overheads' => $Row2[0])); 97 90 98 91 RecalculateTariffs(); … … 103 96 104 97 // Celkovy prehled 105 DB_Query("SELECT SUM(price) FROM network_devices WHERE used=1");106 $Row4 = DB_Row();107 echo("Celkova cena za øízení: Zaøízení(".$Row4[0]);108 DB_Query("SELECT SUM(price) FROM network_segments");109 $Row = DB_Row();98 $DbResult = $Database->query("SELECT SUM(price) FROM network_devices WHERE used=1"); 99 $Row4 = $DbResult->fetch_array(); 100 echo("Celkova cena zařízení: Zařízení(".$Row4[0]); 101 $DbResult = $Database->query("SELECT SUM(price) FROM network_segments"); 102 $Row = $DbResult->fetch_array(); 110 103 echo("), Segmenty(".$Row[0]); 111 DB_Query("SELECT SUM(network_device) FROM users");112 $Row5 = DB_Row();113 echo("), U ¾ivatelé(".$Row5[0].")\n");114 DB_Query("SELECT SUM(cash) FROM users WHERE role=0");115 $Row6 = DB_Row();116 echo("Stav pokladny: U ¾ivatelé(".$Row6[0].")");117 DB_Query("SELECT SUM(money) FROM finance_operations");118 $Row = DB_Row();119 DB_Query("SELECT SUM(price) FROM network_devices WHERE used=1");120 $Row2 = DB_Row();121 echo(", Operace-Za øízení(".($Row[0]-$Row2[0]).")<br>\n");104 $DbResult = $Database->query("SELECT SUM(network_device) FROM users"); 105 $Row5 = $DbResult->fetch_array(); 106 echo("), Uľivatelé(".$Row5[0].")\n"); 107 $DbResult = $Database->query("SELECT SUM(cash) FROM users WHERE role=0"); 108 $Row6 = $DbResult->fetch_array(); 109 echo("Stav pokladny: Uľivatelé(".$Row6[0].")"); 110 $DbResult = $Database->query("SELECT SUM(money) FROM finance_operations"); 111 $Row = $DbResult->fetch_array(); 112 $DbResult = $Database->query("SELECT SUM(price) FROM network_devices WHERE used=1"); 113 $Row2 = $DbResult->fetch_array(); 114 echo(", Operace-Zařízení(".($Row[0]-$Row2[0]).")<br>\n"); 122 115 123 DB_Query("SELECT SUM(money) FROM finance_operations");116 $DbResult = $Database->query("SELECT SUM(money) FROM finance_operations"); 124 117 $Row3 = DB_Row(); 125 echo("Rozdíl pen ìz v operacích: ".($Row3[0]-$Row6[0] - $Row4[0])." <br>\n");118 echo("Rozdíl peněz v operacích: ".($Row3[0]-$Row6[0] - $Row4[0])." <br>\n"); 126 119 127 120 128 DB_Query("SELECT SUM(consumption) FROM network_devices WHERE used=1");129 $Row = DB_Row();121 $DbResult = $Database->query("SELECT SUM(consumption) FROM network_devices WHERE used=1"); 122 $Row = $DbResult->fetch_array(); 130 123 $CelkemSpotreba = W2Kc($Row[0]); 131 124 132 DB_Query("SELECT SUM(plus-monthly) FROM users WHERE role=0");133 $Row = DB_Row();125 $DbResult = $Database->query("SELECT SUM(plus-monthly) FROM users WHERE role=0"); 126 $Row = $DbResult->fetch_array(); 134 127 $CelkemZaplaceno = $Row[0]; 135 128 $SpravaCelkem = $Sprava*$SpravaUsers; 136 129 echo("Kontrola placení (Zaplaceno-Sprava-Internet): ".(-$CelkemZaplaceno)."-".$SpravaCelkem."-".$Internet."=".(-$CelkemZaplaceno-$SpravaCelkem-$Internet)."<br>\n\n"); 137 130 138 // Zkontrolovat ode ètení mìsíèního poplatku131 // Zkontrolovat odečtení měsíčního poplatku 139 132 //$Mesic = '1'; 140 echo('Kontrola ode ètení poplatkù: Poslední mìsíc-'.round($Datum[1]).' Aktuální mìsíc-'.$Mesic."<br>\n");133 echo('Kontrola odečtení poplatků: Poslední měsíc-'.round($Datum[1]).' Aktuální měsíc-'.$Mesic."<br>\n"); 141 134 if($Mesic != $Datum[1]) 142 135 { 143 echo("Ode èítám mìsíèní poplatek: ");136 echo("Odečítám měsíční poplatek: "); 144 137 145 DB_Query("SELECT * FROM users WHERE role=0");146 while($Row = DB_Row())138 $DbResult = $Database->query("SELECT * FROM users WHERE role=0"); 139 while($Row = $DbResult->fetch_array()) 147 140 { 148 141 echo($Row['fullname'].': '.($Row['plus']-$Row['monthly']).'<br>'); 149 DB_Save(); 150 DB_Insert('finance_operations',array('money' => $Row['plus']-$Row['monthly'], 'user' => $Row['id'], 'type' => 2, 'date' => 'NOW()', 'comment' => 'Poplatek za mìsíc '.$Mesice[$Mesic])); 151 DB_Load(); 142 $Database->insert('finance_operations',array('money' => $Row['plus']-$Row['monthly'], 'user' => $Row['id'], 'type' => 2, 'date' => 'NOW()', 'comment' => 'Poplatek za měsíc '.$Mesice[$Mesic])); 152 143 } 153 DB_Insert('finance_monthly_overall', array('date' => 'NOW()', 'money' => $Internet, 'kWh' => $kWh, 'administration' => $Sprava, 'administration_total' => $SpravaCelkem, 'consumption_total' => $CelkemSpotreba, 'total_paid' => $CelkemZaplaceno));144 $Database->insert('finance_monthly_overall', array('date' => 'NOW()', 'money' => $Internet, 'kWh' => $kWh, 'administration' => $Sprava, 'administration_total' => $SpravaCelkem, 'consumption_total' => $CelkemSpotreba, 'total_paid' => $CelkemZaplaceno)); 154 145 155 146 echo('Menim aktualni parametry site.'); 156 147 157 148 // Update finance charge 158 DB_Delete('finance_charge', 'period=0');159 DB_Select('finance_charge', '*', 'period=1');160 $Charge = DB_Row();149 $Database->delete('finance_charge', 'period=0'); 150 $DbResult = $Database->select('finance_charge', '*', 'period=1'); 151 $Charge = $DbResult->fetch_array(); 161 152 //print_r($Charge); 162 DB_Insert('finance_charge', array('period' => 0, 'internet' => $Charge['internet'],153 $DbResult = $Database->insert('finance_charge', array('period' => 0, 'internet' => $Charge['internet'], 163 154 'internet_speed' => $Charge['internet_speed'], 'internet_speed_reserve' => $Charge['internet_speed_reserve'], 164 155 'administration_per_user' => $Charge['administration_per_user'], 'kWh' => $Charge['kWh'])); … … 168 159 169 160 // Update tarrifs 170 DB_Delete('finance_tariffs', 'period=0');171 DB_Select('finance_tariffs', '*', 'period=1');172 while($Tariff = DB_Row())161 $Database->delete('finance_tariffs', 'period=0'); 162 $DbResult = $Database->elect('finance_tariffs', '*', 'period=1'); 163 while($Tariff = $DbResult->fetch_array()) 173 164 { 174 DB_Save(); 175 DB_Insert('finance_tariffs', array('period' => 0, 'name' => $Tariff['name'], 'id' => $Tariff['id'], 165 $Database->insert('finance_tariffs', array('period' => 0, 'name' => $Tariff['name'], 'id' => $Tariff['id'], 176 166 'speed_factor' => $Tariff['speed_factor'], 'price_units' => $Tariff['price_units'])); 177 DB_Load();178 167 } 179 168 … … 181 170 182 171 // Update tariff user selection 183 DB_Query("SELECT id,inet_tarif_next FROM users WHERE role=0");184 while($User = DB_Row())172 $DbResult = $Database->query("SELECT id,inet_tarif_next FROM users WHERE role=0"); 173 while($User = $DbResult->fetch_array()) 185 174 { 186 DB_Save(); 187 DB_Update('users', 'id='.$User['id'], array('inet_tarif_now' => $User['inet_tarif_next'])); 188 DB_Load(); 175 $Database->update('users', 'id='.$User['id'], array('inet_tarif_now' => $User['inet_tarif_next'])); 189 176 } 190 177 … … 193 180 194 181 // Restart traffic shaping 195 DB_Update('services_restart', 'id=3', array('changed' => 1));182 $Database->update('services_restart', 'id=3', array('changed' => 1)); 196 183 } 197 184 ?>
Note:
See TracChangeset
for help on using the changeset viewer.