Changeset 157 for www/finance
- Timestamp:
- Feb 18, 2009, 11:19:12 AM (16 years ago)
- Location:
- www/finance
- Files:
-
- 2 deleted
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
www/finance/bills.php
r156 r157 120 120 } 121 121 122 function CreateBill($SubjectId, $Items, $TimeFrom, $TimeTo, $BillCode , $Type)123 { 124 $this->Database->insert('FinanceBills', array('TimeCreate' => TimeToMysqlDateTime(time()), 'Subject' => $SubjectId, 'TimeFrom' => TimeToMysqlDateTime($TimeFrom), 'TimeTo' => TimeToMysqlDateTime($TimeTo), 'TimeDue' => TimeToMysqlDateTime($TimeFrom + 15 *24*3600), 'BillCode' => $BillCode, 'Type' => 'invoice'));122 function CreateBill($SubjectId, $Items, $TimeFrom, $TimeTo, $BillCode = '', $Type = 'invoice') 123 { 124 $this->Database->insert('FinanceBills', array('TimeCreate' => TimeToMysqlDateTime(time()), 'Subject' => $SubjectId, 'TimeFrom' => TimeToMysqlDateTime($TimeFrom), 'TimeTo' => TimeToMysqlDateTime($TimeTo), 'TimeDue' => TimeToMysqlDateTime($TimeFrom + 15 * 24 * 3600), 'BillCode' => $BillCode, 'Type' => $Type)); 125 125 $BillId = $this->Database->insert_id; 126 126 foreach($Items as $Item) … … 192 192 function HtmlToPdf($HtmlCode) 193 193 { 194 $Output = shell_exec('echo "'.addslashes( from_utf8($HtmlCode)).'"|htmldoc --no-numbered --webpage --charset 8859-2 -t pdf -');194 $Output = shell_exec('echo "'.addslashes(FromUTF8($HtmlCode)).'"|htmldoc --no-numbered --webpage --charset 8859-2 -t pdf -'); 195 195 return($Output); 196 196 } -
www/finance/clenove.php
r152 r157 1 1 <?php 2 2 include('../global.php'); 3 include('include.php');4 RecalculateTariffs(1);5 3 6 4 class FinanceUserList extends Page … … 11 9 function Show() 12 10 { 13 global $Tarify;14 15 11 $Finance = $this->System->Modules['Finance']; 12 $this->System->Modules['Finance']->RecalculateTariffs(1); 13 if($this->System->Modules['User']->CheckPermission('Finance', 'SubjectList')) 16 14 { 17 15 // Seznam členů … … 43 41 $TotalCash += $Row['Cash']; 44 42 if($Row['Cash'] < 0) $Row['Cash'] = '<span style="color: red;">'.$Row['Cash'].'</span>'; 45 $Tarif = $ Tarify[$Row['inet_tarif_now']]['name'];46 $PristiTarif = $ Tarify[$Row['inet_tarif_next']]['name'];43 $Tarif = $Finance->Tarify[$Row['inet_tarif_now']]['name']; 44 $PristiTarif = $Finance->Tarify[$Row['inet_tarif_next']]['name']; 47 45 $Output .= '<tr><td><a href="user_state.php?id='.$Row['id'].'">'.$Row['Fullname'].'</a></td>'; 48 46 //<td align="right">'.$Row['network_device'].'</td> -
www/finance/finance.php
r152 r157 3 3 class Finance extends Module 4 4 { 5 var $kWh; 6 var $Internet; 7 var $Sprava; 8 var $DatumOdecteni; 9 var $InternetUsers; 10 var $SpravaUsers; 11 var $InternetSegmentId = 21; 12 var $MaxSpeed; 13 var $RealMaxSpeed; 14 var $SpeedReserve; 15 var $BaseSpeedElement; 16 var $TotalConsumption; 17 var $UserIdNetwork = 46; 18 var $BaseTariffPrice; 19 var $TopTariffPrice; 20 var $TotalPaid; 21 var $TotalInternetPaid; 22 var $Tarify; 23 24 function RecalculateTariffs($Period = 1) 25 { 26 $ResidualPrice = $this->Internet; 27 $ResidualSpeed = $this->MaxSpeed; 28 29 $Tarify = array(); 30 $DbResult = $this->Database->select('finance_tariffs', '*', 'period='.$Period.' ORDER BY id,speed_factor'); 31 while($Tariff = $DbResult->fetch_array()) 32 { 33 $Tarify[$Tariff['id']] = $Tariff; 34 } 5 35 36 if($Period == 0) $Column = 'now'; else $Column = 'next'; 37 $TotalUserCount = 0; 38 $TotalUnits = 0; 39 $TotalTarifUnits = 0; 40 $TotalTarifSpeedUnits = 0; 41 foreach($Tarify as $Index => $Tarif) 42 { 43 $DbResult = $this->Database->select('users', 'COUNT(*)', 'inet_tarif_'.$Column.'='.$Index.' AND inet=1 AND role=2'); 44 $Row = $DbResult->fetch_array(); 45 $Tarify[$Index]['user_count'] = $Row[0]; 46 switch($Tarif['group_id']) 47 { 48 case 1: 49 $TotalUserCount = $TotalUserCount + $Tarify[$Index]['user_count']; 50 $Tarify[$Index]['total_units'] = $Tarify[$Index]['price_units'] * $Tarify[$Index]['user_count']; 51 $TotalTarifUnits = $TotalTarifUnits + $Tarify[$Index]['total_units']; 52 53 if($Index == 3) // Zarizeni site v tarifu 3 neplati penize, ale ma internet 54 $Tarify[$Index]['total_speed_factor'] = $Tarify[$Index]['speed_factor'] * ($Tarify[$Index]['user_count']+1); 55 else $Tarify[$Index]['total_speed_factor'] = $Tarify[$Index]['speed_factor'] * $Tarify[$Index]['user_count']; 56 $TotalTarifSpeedUnits = $TotalTarifSpeedUnits + $Tarify[$Index]['total_speed_factor']; 57 break; 58 case 2: 59 $ResidualPrice -= $Tarif['price'] * $Tarify[$Index]['user_count']; 60 $ResidualSpeed -= $Tarif['min_speed'] * $Tarify[$Index]['user_count']; 61 $Tarify[$Index]['total_units'] = $Tarify[$Index]['price_units'] * $Tarify[$Index]['user_count']; 62 break; 63 case 3: 64 $Tarify[$Index]['total_units'] = $Tarify[$Index]['price_units'] * $Tarify[$Index]['user_count']; 65 break; 66 } 67 } 68 //$PricePerUnit = $TopTariffPrice / ; // $ResidualPrice / $TotalTarifUnits; 69 $SpeedPerUnit = $ResidualSpeed * 1024 / $TotalTarifSpeedUnits; 70 71 // Recalculate price 72 foreach($Tarify as $Index => $Tarif) 73 { 74 switch($Tarif['group_id']) 75 { 76 case 1: 77 $Tarify[$Index]['price'] = $this->BaseTariffPrice + round($this->TopTariffPrice * $Tarif['price_units'] / 10) * 10; 78 $Tarify[$Index]['min_speed'] = round($Tarif['speed_factor'] * $SpeedPerUnit); 79 $Tarify[$Index]['max_speed'] = round($Tarify[$Index]['speed_factor'] * $this->BaseSpeedElement * 1024); 80 break; 81 case 2: 82 $Tarify[$Index]['min_speed'] = $Tarify[$Index]['min_speed'] * 1024; 83 $Tarify[$Index]['max_speed'] = $Tarify[$Index]['max_speed'] * 1024; 84 break; 85 case 3: 86 $Tarify[$Index]['price'] = $this->BaseTariffPrice + round($this->TopTariffPrice * $Tarif['price_units']); 87 $Tarify[$Index]['min_speed'] = $Tarify[$Index]['min_speed'] * 1024; 88 $Tarify[$Index]['max_speed'] = $Tarify[$Index]['max_speed'] * 1024; 89 break; 90 } 91 $Tarify[$Index]['aggregation'] = '1:'.round($Tarify[$Index]['max_speed'] / $Tarify[$Index]['min_speed']); 92 } 93 $this->Tarify = $Tarify; 94 } 95 96 function LoadMonthParameters($Period = 1) // 0 - now, 1 - next month 97 { 98 $DbResult = $this->Database->query("SELECT * FROM finance_charge WHERE period=".$Period); 99 $Row = $DbResult->fetch_array(); 100 $this->kWh = $Row['kWh']; 101 $this->Internet = $Row['internet']; 102 $this->Sprava = $Row['administration_per_user']; 103 $this->RealMaxSpeed = $Row['internet_speed']; 104 $this->SpeedReserve = $Row['internet_speed_reserve']; 105 $this->BaseSpeedElement = $Row['base_speed_element']; 106 $this->MaxSpeed = $this->RealMaxSpeed - $this->SpeedReserve; 107 $this->TopTariffPrice = $Row['TopTariffPrice']; 108 $this->BaseTariffPrice = $Row['BaseTariffPrice']; 109 110 $DbResult = $this->Database->query("SELECT COUNT(*) FROM users WHERE inet=1 AND role=2"); 111 $Row = $DbResult->fetch_array(); 112 $this->InternetUsers = $Row[0]; 113 114 $DbResult = $this->Database->query("SELECT COUNT(*) FROM users WHERE overheads=1 AND role=2"); 115 $SpravaUsers = $DbResult->fetch_array(); 116 $this->SpravaUsers = $SpravaUsers[0]; 117 $DbResult = $this->Database->query("SELECT SUM(consumption) FROM network_segments"); 118 $TotalConsumption = $DbResult->fetch_array(); 119 $this->TotalConsumption = $TotalConsumption[0]; 120 121 $DbResult = $this->Database->query("SELECT SUM(`monthly`) as `internet`, SUM(`monthly` - `plus`) as `real` FROM users WHERE role=2"); 122 $Row = $DbResult->fetch_array(); 123 $this->TotalInternetPaid = $Row['internet']; 124 $this->TotalPaid = $Row['real']; 125 126 $this->RecalculateTariffs($Period); 127 } 128 129 function W2Kc($Spotreba) 130 { 131 return(round($Spotreba * 0.72 * $this->kWh)); 132 } 133 134 function GetNextDocumentLineNumber($Id) 135 { 136 $DbResult = $this->Database->query('SELECT Shortcut, NextNumber FROM DocumentLine WHERE Id='.$Id); 137 $DbRow = $DbResult->fetch_assoc(); 138 $Result = $DbRow['Shortcut'].$DbRow['NextNumber']; 139 $this->Database->query('UPDATE DocumentLine SET NextNumber = NextNumber + 1 WHERE Id='.$Id); 140 return($Result); 141 } 6 142 } 7 143 -
www/finance/index.php
r156 r157 1 1 <?php 2 2 include_once('../global.php'); 3 include_once('include.php');4 3 5 4 class FinanceOverview extends Page … … 10 9 function Show() 11 10 { 12 global $Config, $RealMaxSpeed, $Internet, $InternetUsers, $kWh, $TotalInternetPaid, $SpravaUsers, $Sprava, $UserIdNetwork; 13 14 $Output = '<table><tr><td valign="top">'; 11 $Finance = $this->System->Modules['Finance']; 12 $Output = '<table><tr><td valign="top">'; 15 13 16 14 if(GetMemberByIP(GetRemoteAddress()) > 0) $Output .= '<a href="user_state_ip.php">Vaše finanční operace</a> (Tato volba je také přístupná po přihlášení do systému v uživatelském menu).<br /><br /><br />'; … … 21 19 if($this->System->Modules['User']->CheckPermission('Finance', 'SubjectList')) $Output .= '<a href="clenove.php">Seznam členů</a><br />'; 22 20 $Output .= '<a href="spotreba.php">Spotřeba energie</a><br />'; 23 $Output .= '<a href="'.$ Config['Web']['RootFolder'].'/aktuality/index.php?category=9">Investice v síti</a><br />';21 $Output .= '<a href="'.$this->System->Config['Web']['RootFolder'].'/aktuality/index.php?category=9">Investice v síti</a><br />'; 24 22 //$Output .= '<a href="faktury/">Faktury za internet</a><br />'; 25 23 //$Output .= '<a href="inventory.php">Výpis skladových zásob</a><br />'; … … 29 27 $DbResult = $this->Database->query("SELECT * FROM finance_monthly_overall ORDER BY date DESC LIMIT 0,1"); 30 28 $Row = $DbResult->fetch_array(); 31 $Output .= 'Platba za internetovou linku ('.$ RealMaxSpeed.'/'.$RealMaxSpeed.' kbit/s): <strong>'.$Internet.' Kč</strong><br />';29 $Output .= 'Platba za internetovou linku ('.$Finance->RealMaxSpeed.'/'.$Finance->RealMaxSpeed.' kbit/s): <strong>'.$Finance->Internet.' Kč</strong><br />'; 32 30 33 31 $DbResult = $this->Database->query("SELECT COUNT(*) FROM users WHERE role=2"); … … 42 40 $Row4 = $DbResult->fetch_array(); 43 41 $Output .= 'Celkem peněz na účtech: <strong>'.$Row4[0].' Kč</strong><br />'; 44 $Output .= 'Stanovená cena jedné kWh: <strong>'.$ kWh.' Kč</strong><br />';42 $Output .= 'Stanovená cena jedné kWh: <strong>'.$Finance->kWh.' Kč</strong><br />'; 45 43 //echo('Komunitou stanovený poplatek za správu sítě pro jednoho uživatele: <strong>'.$Sprava.' Kč</strong><br />'); 46 44 $DbResult = $this->Database->query("SELECT SUM(family) FROM users WHERE role=2"); … … 55 53 $Output .= '</td><td valign="top">'; 56 54 57 $UsersPayment = $ TotalInternetPaid;58 $NetworkManagement = $ Sprava * $SpravaUsers;55 $UsersPayment = $Finance->TotalInternetPaid; 56 $NetworkManagement = $Finance->Sprava * $Finance->SpravaUsers; 59 57 $TotalGain = 0; 60 58 $TotalExpense = 0; 61 59 $DbResult = $this->Database->query("SELECT SUM(consumption) FROM network_devices WHERE used=1"); 62 60 $Row = $DbResult->fetch_array(); 63 $TotalConsumption = W2Kc($Row[0]);61 $TotalConsumption = $this->System->Modules['Finance']->W2Kc($Row[0]); 64 62 65 63 $Output .= 'Měsíční vyúčtování:<br /> … … 70 68 $TotalGain += $UsersPayment; 71 69 $Output .= '<tr><td><strong>Celkem</strong></td><td align="right"><strong>'.$TotalGain.'</strong></td></tr>'; 72 $Output .= '<tr><th colspan="2">Výdaje</th></tr><tr><td>Internet</td><td align="right">'.$ Internet.'</td></tr>';73 $TotalExpense += $ Internet;70 $Output .= '<tr><th colspan="2">Výdaje</th></tr><tr><td>Internet</td><td align="right">'.$Finance->Internet.'</td></tr>'; 71 $TotalExpense += $Finance->Internet; 74 72 $Output .= '<tr><td>Správa sítě</td><td align="right">'.$NetworkManagement.'</td></tr>'; 75 73 $TotalExpense += $NetworkManagement; … … 81 79 $Output .= '<tr><td>Převod do dalšího měsíce</td><td align="right">'.($TotalGain - $TotalExpense).'</td></tr>'; 82 80 $Output .= '</table><br />'; 83 $DbResult = $this->Database->select('users', 'cash', 'id='.$ UserIdNetwork);81 $DbResult = $this->Database->select('users', 'cash', 'id='.$Finance->UserIdNetwork); 84 82 $Row = $DbResult->fetch_array(); 85 83 $NetworkCash = $Row['cash']; 86 $Output .= 'Stav účtu sítě: '.$NetworkCash.' Kč<br /><a href="clenove.php?show=user&id='.$ UserIdNetwork.'">Výpis účtu</a><br />';84 $Output .= 'Stav účtu sítě: '.$NetworkCash.' Kč<br /><a href="clenove.php?show=user&id='.$Finance->UserIdNetwork.'">Výpis účtu</a><br />'; 87 85 88 86 $Output .= '</td></tr></table>'; -
www/finance/inventory.php
r152 r157 1 1 <?php 2 2 include_once('../global.php'); 3 include_once('include.php');4 3 5 4 class FinanceStoragePage extends Page -
www/finance/manage.php
r156 r157 1 1 <?php 2 2 include_once('../global.php'); 3 include_once('include.php');4 3 5 4 class FinanceManagePage extends Page … … 10 9 function Show() 11 10 { 12 //if(!$this->System->Modules['User']->CheckPermission('Finance', 'Manage')) return('Nemáte oprávnění');11 if(!$this->System->Modules['User']->CheckPermission('Finance', 'Manage')) return('Nemáte oprávnění'); 13 12 14 13 if(array_key_exists('Operation', $_GET)) $Operation = $_GET['Operation']; else $Operation = ''; 14 //$Operation = 'ImportOldData'; 15 15 switch($Operation) 16 16 { … … 56 56 $Output .= '<a href="?Operation=ConvertPDFToFile">Převést data z databáze do souborů</a><br>'; 57 57 $Output .= '<a href="?Operation=Bills">Správa dokladů</a><br>'; 58 $Output .= '<a href="prepocet.php">Přepočet financí</a><br>'; 58 59 } 59 60 return($Output); -
www/finance/monthly_overall.php
r156 r157 1 1 <?php 2 2 include_once('../global.php'); 3 include_once('include.php');4 3 5 4 class FinanceMonthlyOverallPage extends Page … … 12 11 global $MonthNames; 13 12 14 $Output = '<table c ellspacing="0" cellpadding="2" border="1"><tr><th>Rok</th><th>Měsíc</th><th>Internet [Kč]</th><th>Účastníků</th><th>Správa [Kč/účastníka]</th><th>Správa [Kč]</th><th>Spotřeba [Kč/kWh]</th><th>Spotřeba [Kč]</th><th>Obrat [Kč]</th><th>Průměrná cena [Kč/účastníka]</th><th align="center">Investice [Kč]</th></tr>';13 $Output = '<table class="WideTable"><tr><th>Rok</th><th>Měsíc</th><th>Internet [Kč]</th><th>Účastníků</th><th>Správa [Kč/účastníka]</th><th>Správa [Kč]</th><th>Spotřeba [Kč/kWh]</th><th>Spotřeba [Kč]</th><th>Obrat [Kč]</th><th>Průměrná cena [Kč/účastníka]</th><th align="center">Investice [Kč]</th></tr>'; 15 14 $Total = array('money' => 0, 'administration_total' => 0, 'consumption_total' => 0, 'total_paid' => 0, 'investment' => 0); 16 15 $DbResult = $this->Database->select('finance_monthly_overall', '*', '1 ORDER BY date DESC'); -
www/finance/prepocet.php
r153 r157 1 1 <?php 2 include('../style.php'); 3 include('include.php'); 4 include('bills.php'); 5 6 ShowHeader('Přepočet financí', 'Přepočet financí'); 7 8 function RecalculateUsersFinance() 2 include_once('../global.php'); 3 4 class FinanceRecalculatePage extends Page 9 5 { 10 global $InternetSegmentId, $Tarify, $Sprava, $Database, $UserIdNetwork; 11 12 echo("Aktualizuju finance uživatelů...<br>\n"); 13 $DbResult = $Database->query("SELECT * FROM users WHERE role=2 OR id=".$UserIdNetwork); // Select network members only 14 while($Row = $DbResult->fetch_array()) 15 { 16 $DbResult2 = $Database->query("SELECT SUM(money) FROM finance_operations WHERE user=".$Row['id']); // Account state 17 $Row3 = $DbResult2->fetch_array(); 18 $DbResult2 = $Database->query("SELECT SUM(consumption) FROM network_devices WHERE user=".$Row['id']." AND used=1"); 19 $Row4 = $DbResult2->fetch_array(); 20 21 $Price = 0; 22 $Consumption = 0; 23 $ID = $Row['network_segment']; 24 while($ID != 0) 25 { 26 $DbResult2 = $Database->query("SELECT * FROM network_segments WHERE id=".$ID); 6 var $FullTitle = 'Přepočet financí'; 7 var $ShortTitle = 'Přepočet financí'; 8 9 function RecalculateUsersFinance() 10 { 11 $Finance = &$this->System->Modules['Finance']; 12 $Output = 'Aktualizuju finance uživatelů...<br />'; 13 $DbResult = $this->Database->query('SELECT * FROM users WHERE role=2 OR id='.$Finance->UserIdNetwork); // Select network members only 14 while($Row = $DbResult->fetch_array()) 15 { 16 $DbResult2 = $this->Database->query('SELECT SUM(money) FROM finance_operations WHERE user='.$Row['id']); // Account state 17 $Row3 = $DbResult2->fetch_array(); 18 $DbResult2 = $this->Database->query('SELECT SUM(consumption) FROM network_devices WHERE user='.$Row['id'].' AND used=1'); 19 $Row4 = $DbResult2->fetch_array(); 20 21 $Price = 0; 22 $Consumption = 0; 23 $ID = $Row['network_segment']; 24 while($ID != 0) 25 { 26 $DbResult2 = $this->Database->query('SELECT * FROM network_segments WHERE id='.$ID); 27 $Row2 = $DbResult2->fetch_array(); 28 if(!(($Row['inet_hw'] == 0) and ($ID == $Finance->InternetSegmentId))) 29 { 30 $Price += $Row2['price'] / $Row2['users']; 31 $Consumption += $Row2['consumption'] / $Row2['users_overheads']; 32 } 33 //echo($ID.' '.$InternetSegment.' '.$InternetSegmentId.' '.$Row['inet_hw'].' '.$Price.'<br>'); 34 $ID = $Row2['parent']; 35 } 36 $Monthly = 0; 37 $MonthlyInet = $Finance->Tarify[$Row['inet_tarif_next']]['price']; 38 if($Row['inet'] == 1) $Monthly += $MonthlyInet; 39 //if($Row['overheads'] == 1) $Monthly += $Sprava; // + W2Kc($Consumption); 40 //echo($Row['fullname'].' '.$Row['inet'].' '.$Monthly.'<br>'); 41 $Monthly = round($Monthly); 42 //echo($Row['fullname'].' '.$Row['inet'].' '.$Monthly.'<br>'); 43 $this->Database->update('users', 'id='.$Row['id'], array('network_device' => $Price, 'monthly_inet' => $MonthlyInet, 'monthly' => $Monthly, 'consumption' => $this->System->Modules['Finance']->W2Kc($Consumption), 'cash' => $Row3[0], 'plus' => $Finance->W2Kc($Row4[0]))); 44 } 45 return($Output); 46 } 47 48 function RecalculateSegmentParameters() 49 { 50 $Finance = &$this->System->Modules['Finance']; 51 $Output = 'Aktualizuju parametry segmentů...<br />'; 52 $this->Database->query('UPDATE network_segments SET users = 0, users_overheads = 0'); // Vynulovat počty uživatelů 53 $DbResult = $this->Database->query('SELECT * FROM network_segments'); 54 while($Row = $DbResult->fetch_array()) 55 { 56 //echo('Segment '.$Row['name'].'<br>'); 57 $DbResult2 = $this->Database->query('SELECT users FROM network_segments WHERE id='.$Row['id']); 58 $RowP = $DbResult2->fetch_array(); 59 $DbResult2 = $this->Database->query("SELECT users_overheads FROM network_segments WHERE id=".$Row['id']); 60 $RowP2 = $DbResult2->fetch_array(); 61 62 $DbResult2 = $this->Database->query("SELECT SUM(price) as Price, SUM(consumption) as Consumption FROM network_devices WHERE segment=".$Row['id']." AND used=1"); 27 63 $Row2 = $DbResult2->fetch_array(); 28 if(!(($Row['inet_hw'] == 0) and ($ID == $InternetSegmentId))) 29 { 30 $Price += $Row2['price'] / $Row2['users']; 31 $Consumption += $Row2['consumption'] / $Row2['users_overheads']; 32 } 33 //echo($ID.' '.$InternetSegment.' '.$InternetSegmentId.' '.$Row['inet_hw'].' '.$Price.'<br>'); 34 $ID = $Row2['parent']; 35 } 36 $Monthly = 0; 37 $MonthlyInet = $Tarify[$Row['inet_tarif_next']]['price']; 38 if($Row['inet'] == 1) $Monthly += $MonthlyInet; 39 //if($Row['overheads'] == 1) $Monthly += $Sprava; // + W2Kc($Consumption); 40 //echo($Row['fullname'].' '.$Row['inet'].' '.$Monthly.'<br>'); 41 $Monthly = round($Monthly); 42 //echo($Row['fullname'].' '.$Row['inet'].' '.$Monthly.'<br>'); 43 $Database->update('users', 'id='.$Row['id'], array('network_device' => $Price, 'monthly_inet' => $MonthlyInet, 'monthly' => $Monthly, 'consumption' => W2Kc($Consumption), 'cash' => $Row3[0], 'plus' => W2Kc($Row4[0]))); 64 $DbResult2 = $this->Database->query("SELECT COUNT(*) FROM users WHERE network_segment=".$Row['id'].' AND hw=1'); 65 $Row3 = $DbResult2->fetch_array(); 66 $DbResult2 = $this->Database->query("SELECT COUNT(*) FROM users WHERE network_segment=".$Row['id'].' AND overheads=1'); 67 $Row5 = $DbResult2->fetch_array(); 68 $ID = $Row['parent']; 69 while($ID != 0) 70 { 71 //echo($ID.', '); 72 $DbResult2 = $this->Database->query("SELECT * FROM network_segments WHERE id=".$ID); 73 $Row4 = $DbResult2->fetch_array(); 74 $this->Database->update('network_segments', 'id='.$Row4['id'], array('users' => ($Row4['users'] + $Row3[0]), 'users_overheads' => ($Row4['users_overheads'] + $Row5[0]))); 75 $ID = $Row4['parent']; 76 } 77 //echo('Pocet '.$Row3[0].','.$Row['hosts'].'<br>'); 78 $this->Database->update('network_segments', 'id='.$Row['id'], array('price' => $Row2['Price'], 'users' => ($Row3[0] + $RowP['users']), 'consumption' => $Row2['Consumption'], 'users_overheads' => ($Row5[0] + $RowP2['users_overheads']))); 79 } 80 81 // Zkorigovat segment Internet 82 $DbResult = $this->Database->select('users', 'COUNT(*)', 'inet_hw=1'); 83 $Row = $DbResult->fetch_array(); 84 $DbResult = $this->Database->select('users', 'COUNT(*)', 'inet=1'); 85 $Row2 = $DbResult->fetch_array(); 86 $DbResult = $this->Database->update('network_segments','id='.$Finance->InternetSegmentId, array('users' => $Row[0], 'users_overheads' => $Row2[0])); 87 return($Output); 88 } 89 90 function CreateMonthlyOverallBill() 91 { 92 global $Sprava, $SpravaUsers, $TotalConsumption, $UserIdNetwork, $Internet, $TotalInternetPaid; 93 94 $TotalConsumptionPrice = $this->System->Modules['Finance']->W2Kc($TotalConsumption); 95 96 $Output .= "Spotřeba energie: ".-$TotalConsumptionPrice."<br />"; 97 $Output .= "Správa sítě: ".-($Sprava * $SpravaUsers)."<br>"; 98 $Output .= "Internet: ".-$Internet."<br>"; 99 $Output .= "Poplatky učástníků: ".$TotalInternetPaid."<br>"; 100 101 $this->Database->insert('finance_operations', array('money' => -$TotalConsumptionPrice, 'user' => $UserIdNetwork, 'type' => 2, 'date' => 'NOW()', 'comment' => 'Spotřeba energie', 'group' => 2)); 102 $this->Database->insert('finance_operations', array('money' => -($Sprava * $SpravaUsers), 'user' => $UserIdNetwork, 'type' => 2, 'date' => 'NOW()', 'comment' => 'Správa sítě', 'group' => 2)); 103 $this->Database->insert('finance_operations', array('money' => -$Internet, 'user' => $UserIdNetwork, 'type' => 2, 'date' => 'NOW()', 'comment' => 'Internet', 'group' => 2)); 104 $this->Database->insert('finance_operations', array('money' => $TotalInternetPaid, 'user' => $UserIdNetwork, 'type' => 2, 'date' => 'NOW()', 'comment' => 'Poplatky učástníků', 'group' => 2)); 105 return($Output); 106 } 107 108 function DiscountNetworkDevicePrice() 109 { 110 $Output = ''; 111 $DbResult = $this->Database->query("SELECT *,CONCAT(second_name, ' ', first_name) as fullname FROM users WHERE role=2"); 112 while($Row = $DbResult->fetch_array()) 113 { 114 $Output .= $Row['fullname'].': '.($Row['network_device'])."<br />"; 115 $this->Database->insert('finance_operations', array('money' => (-$Row['network_device']), 'user' => $Row['id'], 'type' => 2, 'date' => 'NOW()', 'comment' => 'Jednorázový poplatek za společné zařízení', 'group' => 1)); 116 //echo($Database->LastQuery."<br>\n"); 117 } 118 return($Output); 119 } 120 121 122 function Show() 123 { 124 if(!$this->System->Modules['User']->CheckPermission('Finance', 'Manage')) return('Nemáte oprávnění'); 125 $Output = ''; 126 127 $Finance = &$this->System->Modules['Finance']; 128 129 // Načti poslední měsíční přehled a nastavení 130 $DbResult = $this->Database->select('finance_monthly_overall', '*', '1 ORDER BY date DESC LIMIT 1'); 131 $Overall = $DbResult->fetch_array(); 132 133 $Output -= 'Datum: '.date('j.n.Y')."<br />"; 134 135 $Datum = explode('-', $Overall['date']); 136 $Mesic = date("m") + 0; 137 138 $Output .= $this->RecalculateSegmentParameters(); 139 $Output .= $Finance->RecalculateTariffs(); 140 //DiscountNetworkDevicePrice(); 141 //$InvoiceGenerator->CustomGenerate(); 142 $Output .= $this->RecalculateUsersFinance(); 143 144 // Celkovy prehled 145 $DbResult = $this->Database->query("SELECT SUM(price) FROM network_devices WHERE used=1"); 146 $Row4 = $DbResult->fetch_array(); 147 $Output .= "Celková cena zařízení: Zařízení(".$Row4[0]; 148 $DbResult = $this->Database->query("SELECT SUM(price) FROM network_segments"); 149 $Row = $DbResult->fetch_array(); 150 $Output .= "), Segmenty(".$Row[0]; 151 $DbResult = $this->Database->query("SELECT SUM(network_device) FROM users"); 152 $Row5 = $DbResult->fetch_array(); 153 $Output .= "), Uživatelé(".$Row5[0].")<br>\n"; 154 $DbResult = $this->Database->query("SELECT SUM(cash) FROM users WHERE role=2"); 155 $Row6 = $DbResult->fetch_array(); 156 $Output .= "Stav pokladny: Uživatelé(".$Row6[0].")"; 157 $DbResult = $this->Database->query("SELECT SUM(money) FROM finance_operations WHERE `group`=1"); // Položky uživatelů 158 $Row2 = $DbResult->fetch_array(); 159 $Output .= ", Operace-Zařízení(".($Row2[0] - $Row4[0]).")<br>\n"; 160 $Output .= "Rozdíl peněz v operacích: ".($Row2[0] - $Row6[0] - $Row4[0])." <br>\n"; 161 162 163 $DbResult = $this->Database->query("SELECT SUM(consumption) FROM network_devices WHERE used=1"); 164 $Row = $DbResult->fetch_array(); 165 $CelkemSpotreba = $Finance->W2Kc($Row[0]); 166 167 $SpravaCelkem = $Finance->Sprava * $Finance->SpravaUsers; 168 $Output .= "Kontrola placení (Zaplaceno-Sprava-Internet): ".$Finance->TotalPaid."-".$SpravaCelkem."-".$Finance->Internet."=".($Finance->TotalPaid - $SpravaCelkem - $Finance->Internet)."<br>\n\n"; 169 170 // Zkontrolovat odečtení měsíčního poplatku 171 //$Mesic = '1'; 172 $Output .= 'Kontrola odečtení poplatků: Poslední měsíc-'.round($Datum[1]).' Aktuální měsíc-'.$Mesic."<br>\n"; 173 if($Mesic != $Datum[1]) 174 { 175 $Output .= "Odečítám měsíční poplatek...<br>\n"; 176 177 $BillingPeriodMonthCount = array('never' => 0, 'monthly' => 1, 'quarterly' => 3, 'half-yearly' => 6, 'yearly' => 12); 178 179 // Generuj účetní položky 180 $DbResult = $this->Database->query("SELECT *, CONCAT(second_name, ' ', first_name) as fullname FROM users WHERE (role = 2)"); 181 while($User = $DbResult->fetch_array()) 182 { 183 $Output .= $User['fullname'].': '; 184 $MonthCount = $BillingPeriodMonthCount[$User['BillingPeriod']]; 185 if(($MonthCount > 0) and (((($Mesic - 1) % 12) % $MonthCount) == 0) and ($User['inet_tarif_now'] != 6)) 186 { 187 //echo($Mesic.'%'.$MonthCount.'='.($Mesic % $MonthCount).' '); 188 $PayPerMonth = -($User['plus'] - $User['monthly']); 189 $PayPerPeriod = $PayPerMonth * $MonthCount; 190 $PeriodFrom = mktime(0, 0, 0, date('n'), 1, date('Y')); 191 $PeriodTo = mktime(0, 0, 0, date('n') + $MonthCount - 1, date('t', mktime(0, 0, 0, date('n') + $MonthCount - 1, 1, date('Y'))) , date('Y')); 192 $TimePeriodText = date('j.n.Y', $PeriodFrom).' - '.date('j.n.Y', $PeriodTo); 193 $Output .= $TimePeriodText.': '.$PayPerMonth." * ".$MonthCount." = ".$PayPerPeriod."<br />\n"; 194 $BillCode = $Finance->GetNextDocumentLineNumber(6); // Faktury vydané 195 $BillId = $this->System->Modules['Bill']->CreateBill($User['id'], array(array('Description' => 'Připojení k síti', 'Price' => $PayPerPeriod, 'Quantity' => 1)), $PeriodFrom, $PeriodTo, $BillCode); 196 $this->Database->insert('finance_operations', array('money' => -$PayPerPeriod, 'user' => $User['id'], 'type' => 2, 'date' => 'NOW()', 'comment' => 'Připojení k síti za období '.$TimePeriodText, 'group' => 1, 'bill_id' => $BillId, 'BillCode' => $BillCode)); 197 } else $Output .= ("<br />"); 198 } 199 $Output .= 'Měním aktuální parametry sítě...<br>\n'; 200 201 // Update finance charge 202 $this->Database->delete('finance_charge', 'period=0'); 203 $DbResult = $this->Database->select('finance_charge', '*', 'period=1'); 204 $Charge = $DbResult->fetch_array(); 205 //print_r($Charge); 206 $DbResult = $this->Database->insert('finance_charge', array('period' => 0, 'internet' => $Charge['internet'], 'internet_speed' => $Charge['internet_speed'], 'internet_speed_reserve' => $Charge['internet_speed_reserve'], 'administration_per_user' => $Charge['administration_per_user'], 'kWh' => $Charge['kWh'], 'base_speed_element' => $Charge['base_speed_element'], 'BaseTariffPrice' => $Charge['BaseTariffPrice'], 'TopTariffPrice' => $Charge['TopTariffPrice'])); 207 208 $Output .= "Přidávám měsíční přehled...<br>\n"; 209 210 $this->Database->insert('finance_monthly_overall', array('date' => 'NOW()', 'money' => $Finance->Internet, 'kWh' => $Finance->kWh, 'administration' => $Finance->Sprava, 'administration_total' => $SpravaCelkem, 'consumption_total' => $CelkemSpotreba, 'total_paid' => $Finance->TotalPaid, 'BaseTariffPrice' => $Charge['BaseTariffPrice'], 'TopTariffPrice' => $Charge['TopTariffPrice'], 'member_count' => $Finance->InternetUsers)); 211 212 $Output .= "Měním aktuální tarify....<br>\n"; 213 214 // Update tarrifs 215 $this->Database->delete('finance_tariffs', 'period=0'); 216 $DbResult = $this->Database->select('finance_tariffs', '*', 'period=1'); 217 while($Tariff = $DbResult->fetch_array()) 218 { 219 $this->Database->insert('finance_tariffs', array('period' => 0, 'name' => $Tariff['name'], 'id' => $Tariff['id'],'speed_factor' => $Tariff['speed_factor'], 'price_units' => $Tariff['price_units'], 'group_id' => $Tariff['group_id'], 'min_speed' => $Tariff['min_speed'], 'max_speed' => $Tariff['max_speed'], 'price' => $Tariff['price'])); 220 } 221 222 $Output .= "Měním aktuální tarify uživatelů...<br>\n"; 223 224 // Update tariff user selection 225 $DbResult = $this->Database->query("SELECT id,inet_tarif_next FROM users WHERE role=2"); 226 while($User = $DbResult->fetch_array()) 227 { 228 $this->Database->update('users', 'id='.$User['id'], array('inet_tarif_now' => $User['inet_tarif_next'])); 229 } 230 231 $Output .= $this->System->Modules['Finance']->RecalculateTariffs(); 232 $this->RecalculateUsersFinance(); 233 //CreateMonthlyOverallBill(); 234 $this->RecalculateUsersFinance(); 235 236 // Restart traffic shaping 237 $this->Database->update('services_restart', 'id=3', array('changed' => 1)); 238 } 239 return($Output); 44 240 } 45 241 } 46 242 47 function RecalculateSegmentParameters() 48 { 49 global $Database, $InternetSegmentId; 50 51 echo("Aktualizuju parametry segmentů...<br>\n"); 52 $Database->query("UPDATE network_segments SET users = 0, users_overheads = 0"); // Vynulovat počty uživatelů 53 $DbResult = $Database->query("SELECT * FROM network_segments"); 54 while($Row = $DbResult->fetch_array()) 55 { 56 //echo('Segment '.$Row['name'].'<br>'); 57 $DbResult2 = $Database->query("SELECT users FROM network_segments WHERE id=".$Row['id']); 58 $RowP = $DbResult2->fetch_array(); 59 $DbResult2 = $Database->query("SELECT users_overheads FROM network_segments WHERE id=".$Row['id']); 60 $RowP2 = $DbResult2->fetch_array(); 61 62 $DbResult2 = $Database->query("SELECT SUM(price) as Price, SUM(consumption) as Consumption FROM network_devices WHERE segment=".$Row['id']." AND used=1"); 63 $Row2 = $DbResult2->fetch_array(); 64 $DbResult2 = $Database->query("SELECT COUNT(*) FROM users WHERE network_segment=".$Row['id'].' AND hw=1'); 65 $Row3 = $DbResult2->fetch_array(); 66 $DbResult2 = $Database->query("SELECT COUNT(*) FROM users WHERE network_segment=".$Row['id'].' AND overheads=1'); 67 $Row5 = $DbResult2->fetch_array(); 68 $ID = $Row['parent']; 69 while($ID != 0) 70 { 71 //echo($ID.', '); 72 $DbResult2 = $Database->query("SELECT * FROM network_segments WHERE id=".$ID); 73 $Row4 = $DbResult2->fetch_array(); 74 $Database->update('network_segments', 'id='.$Row4['id'], array('users' => ($Row4['users'] + $Row3[0]), 'users_overheads' => ($Row4['users_overheads'] + $Row5[0]))); 75 $ID = $Row4['parent']; 76 } 77 //echo('Pocet '.$Row3[0].','.$Row['hosts'].'<br>'); 78 $Database->update('network_segments', 'id='.$Row['id'], array('price' => $Row2['Price'], 'users' => ($Row3[0] + $RowP['users']), 'consumption' => $Row2['Consumption'], 'users_overheads' => ($Row5[0] + $RowP2['users_overheads']))); 79 } 80 81 // Zkorigovat segment Internet 82 $DbResult = $Database->select('users', 'COUNT(*)', 'inet_hw=1'); 83 $Row = $DbResult->fetch_array(); 84 $DbResult = $Database->select('users', 'COUNT(*)', 'inet=1'); 85 $Row2 = $DbResult->fetch_array(); 86 $DbResult = $Database->update('network_segments','id='.$InternetSegmentId, array('users' => $Row[0], 'users_overheads' => $Row2[0])); 87 } 88 89 function CreateMonthlyOverallBill() 90 { 91 global $Database, $Sprava, $SpravaUsers, $TotalConsumption, $UserIdNetwork, $Internet, $TotalInternetPaid; 92 93 $TotalConsumptionPrice = W2Kc($TotalConsumption); 94 95 echo("Spotřeba energie: ".-$TotalConsumptionPrice."<br>\n"); 96 echo("Správa sítě: ".-($Sprava * $SpravaUsers)."<br>\n"); 97 echo("Internet: ".-$Internet."<br>\n"); 98 echo("Poplatky učástníků: ".$TotalInternetPaid."<br>\n"); 99 100 $Database->insert('finance_operations', array('money' => -$TotalConsumptionPrice, 'user' => $UserIdNetwork, 'type' => 2, 'date' => 'NOW()', 'comment' => 'Spotřeba energie', 'group' => 2)); 101 $Database->insert('finance_operations', array('money' => -($Sprava * $SpravaUsers), 'user' => $UserIdNetwork, 'type' => 2, 'date' => 'NOW()', 'comment' => 'Správa sítě', 'group' => 2)); 102 $Database->insert('finance_operations', array('money' => -$Internet, 'user' => $UserIdNetwork, 'type' => 2, 'date' => 'NOW()', 'comment' => 'Internet', 'group' => 2)); 103 $Database->insert('finance_operations', array('money' => $TotalInternetPaid, 'user' => $UserIdNetwork, 'type' => 2, 'date' => 'NOW()', 'comment' => 'Poplatky učástníků', 'group' => 2)); 104 } 105 106 function DiscountNetworkDevicePrice() 107 { 108 global $Database; 109 $DbResult = $Database->query("SELECT *,CONCAT(second_name, ' ', first_name) as fullname FROM users WHERE role=2"); 110 while($Row = $DbResult->fetch_array()) 111 { 112 echo($Row['fullname'].': '.($Row['network_device'])."<br>\n"); 113 $Database->insert('finance_operations', array('money' => (-$Row['network_device']), 'user' => $Row['id'], 'type' => 2, 'date' => 'NOW()', 'comment' => 'Jednorázový poplatek za společné zařízení', 'group' => 1)); 114 //echo($Database->LastQuery."<br>\n"); 115 } 116 } 117 118 // Načti poslední měsíční přehled a nastavení 119 $DbResult = $Database->select('finance_monthly_overall', '*', '1 ORDER BY date DESC LIMIT 1'); 120 $Overall = $DbResult->fetch_array(); 121 122 echo('Datum: '.date('j.n.Y')."<br>"); 123 $Mesice = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec'); 124 $Datum = explode('-', $Overall['date']); 125 $Mesic = date("m") + 0; 126 127 RecalculateSegmentParameters(); 128 RecalculateTariffs(); 129 //DiscountNetworkDevicePrice(); 130 //$InvoiceGenerator->CustomGenerate(); 131 RecalculateUsersFinance(); 132 133 // Celkovy prehled 134 $DbResult = $Database->query("SELECT SUM(price) FROM network_devices WHERE used=1"); 135 $Row4 = $DbResult->fetch_array(); 136 echo("Celková cena zařízení: Zařízení(".$Row4[0]); 137 $DbResult = $Database->query("SELECT SUM(price) FROM network_segments"); 138 $Row = $DbResult->fetch_array(); 139 echo("), Segmenty(".$Row[0]); 140 $DbResult = $Database->query("SELECT SUM(network_device) FROM users"); 141 $Row5 = $DbResult->fetch_array(); 142 echo("), Uživatelé(".$Row5[0].")<br>\n"); 143 $DbResult = $Database->query("SELECT SUM(cash) FROM users WHERE role=2"); 144 $Row6 = $DbResult->fetch_array(); 145 echo("Stav pokladny: Uživatelé(".$Row6[0].")"); 146 $DbResult = $Database->query("SELECT SUM(money) FROM finance_operations WHERE `group`=1"); // Položky uživatelů 147 $Row2 = $DbResult->fetch_array(); 148 echo(", Operace-Zařízení(".($Row2[0] - $Row4[0]).")<br>\n"); 149 echo("Rozdíl peněz v operacích: ".($Row2[0] - $Row6[0] - $Row4[0])." <br>\n"); 150 151 152 $DbResult = $Database->query("SELECT SUM(consumption) FROM network_devices WHERE used=1"); 153 $Row = $DbResult->fetch_array(); 154 $CelkemSpotreba = W2Kc($Row[0]); 155 156 $SpravaCelkem = $Sprava * $SpravaUsers; 157 echo("Kontrola placení (Zaplaceno-Sprava-Internet): ".$TotalPaid."-".$SpravaCelkem."-".$Internet."=".($TotalPaid - $SpravaCelkem - $Internet)."<br>\n\n"); 158 159 // Zkontrolovat odečtení měsíčního poplatku 160 //$Mesic = '1'; 161 echo('Kontrola odečtení poplatků: Poslední měsíc-'.round($Datum[1]).' Aktuální měsíc-'.$Mesic."<br>\n"); 162 if($Mesic != $Datum[1]) 163 { 164 echo("Odečítám měsíční poplatek...<br>\n"); 165 166 $BillingPeriodMonthCount = array('never' => 0, 'monthly' => 1, 'quarterly' => 3, 'half-yearly' => 6, 'yearly' => 12); 167 168 // Generuj účetní položky 169 $DbResult = $Database->query("SELECT *, CONCAT(second_name, ' ', first_name) as fullname FROM users WHERE (role = 2)"); 170 while($User = $DbResult->fetch_array()) 171 { 172 echo($User['fullname'].': '); 173 $MonthCount = $BillingPeriodMonthCount[$User['BillingPeriod']]; 174 if(($MonthCount > 0) and (((($Mesic - 1) % 12) % $MonthCount) == 0) and ($User['inet_tarif_now'] != 6)) 175 { 176 //echo($Mesic.'%'.$MonthCount.'='.($Mesic % $MonthCount).' '); 177 $PayPerMonth = -($User['plus'] - $User['monthly']); 178 $PayPerPeriod = $PayPerMonth * $MonthCount; 179 $PeriodFrom = mktime(0, 0, 0, date('n'), 1, date('Y')); 180 $PeriodTo = mktime(0, 0, 0, date('n') + $MonthCount - 1, date('t', mktime(0, 0, 0, date('n') + $MonthCount - 1, 1, date('Y'))) , date('Y')); 181 $TimePeriodText = date('j.n.Y', $PeriodFrom).' - '.date('j.n.Y', $PeriodTo); 182 echo($TimePeriodText.': '.$PayPerMonth." * ".$MonthCount." = ".$PayPerPeriod."\n"); 183 $BillCode = GetNextDocumentLineNumber(6); // Faktury vydané 184 $BillId = $Bill->CreateBill($User['id'], array(array('description' => 'Připojení k síti', 'price' => $PayPerPeriod, 'quantity' => 1)), $PeriodFrom, $PeriodTo, $BillCode); 185 $Database->insert('finance_operations', array('money' => -$PayPerPeriod, 'user' => $User['id'], 'type' => 2, 'date' => 'NOW()', 'comment' => 'Připojení k síti za období '.$TimePeriodText, 'group' => 1, 'bill_id' => $BillId, 'BillCode' => $BillCode)); 186 } else echo("\n"); 187 } 188 echo('Měním aktuální parametry sítě...<br>\n'); 189 190 // Update finance charge 191 $Database->delete('finance_charge', 'period=0'); 192 $DbResult = $Database->select('finance_charge', '*', 'period=1'); 193 $Charge = $DbResult->fetch_array(); 194 //print_r($Charge); 195 $DbResult = $Database->insert('finance_charge', array('period' => 0, 'internet' => $Charge['internet'], 196 'internet_speed' => $Charge['internet_speed'], 'internet_speed_reserve' => $Charge['internet_speed_reserve'], 'administration_per_user' => $Charge['administration_per_user'], 'kWh' => $Charge['kWh'], 'base_speed_element' => $Charge['base_speed_element'], 'BaseTariffPrice' => $Charge['BaseTariffPrice'], 'TopTariffPrice' => $Charge['TopTariffPrice'])); 197 198 echo("Přidávám měsíční přehled...<br>\n"); 199 200 $Database->insert('finance_monthly_overall', array('date' => 'NOW()', 'money' => $Internet, 'kWh' => $kWh, 'administration' => $Sprava, 'administration_total' => $SpravaCelkem, 'consumption_total' => $CelkemSpotreba, 'total_paid' => $TotalPaid, 'BaseTariffPrice' => $Charge['BaseTariffPrice'], 'TopTariffPrice' => $Charge['TopTariffPrice'], 'member_count' => $InternetUsers)); 201 202 echo("Měním aktuální tarify....<br>\n"); 203 204 // Update tarrifs 205 $Database->delete('finance_tariffs', 'period=0'); 206 $DbResult = $Database->select('finance_tariffs', '*', 'period=1'); 207 while($Tariff = $DbResult->fetch_array()) 208 { 209 $Database->insert('finance_tariffs', array('period' => 0, 'name' => $Tariff['name'], 'id' => $Tariff['id'], 210 'speed_factor' => $Tariff['speed_factor'], 'price_units' => $Tariff['price_units'], 'group_id' => $Tariff['group_id'], 'min_speed' => $Tariff['min_speed'], 'max_speed' => $Tariff['max_speed'], 'price' => $Tariff['price'])); 211 } 212 213 echo("Měním aktuální tarify uživatelů...<br>\n"); 214 215 // Update tariff user selection 216 $DbResult = $Database->query("SELECT id,inet_tarif_next FROM users WHERE role=2"); 217 while($User = $DbResult->fetch_array()) 218 { 219 $Database->update('users', 'id='.$User['id'], array('inet_tarif_now' => $User['inet_tarif_next'])); 220 } 221 222 RecalculateTariffs(); 223 RecalculateUsersFinance(); 224 //CreateMonthlyOverallBill(); 225 RecalculateUsersFinance(); 226 227 // Restart traffic shaping 228 $Database->update('services_restart', 'id=3', array('changed' => 1)); 229 } 230 231 ShowFooter(); 243 $System->AddModule(new FinanceRecalculatePage()); 244 $System->Modules['FinanceRecalculatePage']->GetOutput(); 232 245 233 246 ?> -
www/finance/spotreba.php
r152 r157 1 1 <?php 2 2 include_once('../global.php'); 3 include_once('include.php');4 3 5 4 class FinanceConsumption extends Page … … 21 20 $Row2 = $DbResult2->fetch_array(); 22 21 $CelkovaSpotreba = $CelkovaSpotreba + $Row2[0]; 23 $Output .= '<tr><td>'.$Row['name'].'</td><td align="right">'.$Row2[0].'</td><td align="right">'. W2Kc($Row2[0]).'</td></tr>';22 $Output .= '<tr><td>'.$Row['name'].'</td><td align="right">'.$Row2[0].'</td><td align="right">'.$this->System->Modules['Finance']->W2Kc($Row2[0]).'</td></tr>'; 24 23 } 25 $Output .= '<tr style="font-weight: Bold;"><td><strong>Celkem</strong></td><td align="right">'.$CelkovaSpotreba.'</td><td align="right">'. W2Kc($CelkovaSpotreba).'</td></tr>';24 $Output .= '<tr style="font-weight: Bold;"><td><strong>Celkem</strong></td><td align="right">'.$CelkovaSpotreba.'</td><td align="right">'.$this->System->Modules['Finance']->W2Kc($CelkovaSpotreba).'</td></tr>'; 26 25 $Output .= '</table><br />'; 27 26 $Output .= 'Dohodnutá cena za jednu kWh: <strong>'.$kWh.' Kč</strong><br />'; -
www/finance/tarify.php
r152 r157 1 1 <?php 2 2 include_once('../global.php'); 3 include_once('include.php');4 3 5 4 class FinanceTarrifsPage extends Page … … 10 9 function TariffTable() 11 10 { 12 global $Tarify, $Internet, $InternetUsers, $RealMaxSpeed, $SpeedReserve, $MaxSpeed;13 14 $Output = 'Poplatek za společný internet: <strong>'.$ Internet.' Kč</strong><br />';15 $Output .= 'Rychlost společné linky: <strong>'.$ RealMaxSpeed.' kbit/s</strong><br />';16 $Output .= 'Rezerva (nevyužitá kapacita pro zlepšení odezvy sítě): <strong>'.$ SpeedReserve.' kbit/s</strong><br />';17 $Output .= 'Maximální dostupná kapacita pro použití: <strong>'.$ MaxSpeed.' kbit/s</strong><br />';11 $Finance = &$this->System->Modules['Finance']; 12 13 $Output = 'Poplatek za společný internet: <strong>'.$Finance->Internet.' Kč</strong><br />'; 14 $Output .= 'Rychlost společné linky: <strong>'.$Finance->RealMaxSpeed.' kbit/s</strong><br />'; 15 $Output .= 'Rezerva (nevyužitá kapacita pro zlepšení odezvy sítě): <strong>'.$Finance->SpeedReserve.' kbit/s</strong><br />'; 16 $Output .= 'Maximální dostupná kapacita pro použití: <strong>'.$Finance->MaxSpeed.' kbit/s</strong><br />'; 18 17 $Output .= '<br />'; 19 18 … … 22 21 $TotalPrice = 0; 23 22 $TotalUnits = 0; 24 foreach($ Tarify as $Index => $Tarif)23 foreach($Finance->Tarify as $Index => $Tarif) 25 24 { 26 25 $Output .= '<tr><td style="color: blue;">'.$Tarif['name'].'</td><td align="center">'.round($Tarif['min_speed'] / 1024).'</td><td align="center" style="color: blue;">'.round($Tarif['max_speed'] / 1024).'</td><td align="center">'.$Tarif['aggregation'].'</td><td align="center">'.$Tarif['price_units'].'</td><td align="center">'.$Tarif['user_count'].'</td><td align="center">'. … … 29 28 $TotalUnits = $TotalUnits + $Tarif['total_units']; 30 29 } 31 $Output .= '<tr><td>Součty</td><td colspan="4"> </td><td align="center">'.$ InternetUsers.'</td><td align="center">'.$TotalUnits.'</td><td> </td><td align="center">'.$TotalPrice.'</td></tr>';30 $Output .= '<tr><td>Součty</td><td colspan="4"> </td><td align="center">'.$Finance->InternetUsers.'</td><td align="center">'.$TotalUnits.'</td><td> </td><td align="center">'.$TotalPrice.'</td></tr>'; 32 31 $Output .= '</table>'; 33 32 return($Output); … … 36 35 function Show() 37 36 { 38 global $Tarify, $Internet, $InternetUsers, $RealMaxSpeed, $SpeedReserve, $MaxSpeed;39 $Output = 'Počet členů s internetovým připojením: <strong>'.$ InternetUsers.'</strong><br /><br />';37 $Finance = &$this->System->Modules['Finance']; 38 $Output = 'Počet členů s internetovým připojením: <strong>'.$Finance->InternetUsers.'</strong><br /><br />'; 40 39 $Output .= '<table><tr><td valign="top">'; 41 40 42 NactiMesicniParametry(0);41 $Finance->LoadMonthParameters(0); 43 42 $Output .= '<strong>Stav pro aktuální měsíc:</strong><br />'; 44 43 $Output .= $this->TariffTable(); … … 46 45 $Output .= '<br /></td></tr><tr><td valign="top">'; 47 46 48 NactiMesicniParametry(1);47 $Finance->LoadMonthParameters(1); 49 48 $Output .= '<strong>Stav pro další měsíc:</strong><br />'; 50 49 $Output .= $this->TariffTable(); -
www/finance/user_state.php
r156 r157 2 2 3 3 include_once('../global.php'); 4 include_once('include.php');5 RecalculateTariffs(1);6 4 7 5 class FinanceUserState extends Page … … 16 14 if(!$this->System->Modules['User']->CheckPermission('Finance', 'DisplaySubjectState')) return('Nemáte oprávnění'); 17 15 16 $this->System->Modules['Finance']->RecalculateTariffs(1); 18 17 $UserId = $this->System->Modules['User']->User['Id']; 19 18 if(!array_key_exists('show', $_GET)) $_GET['show'] = ''; … … 56 55 $DbResult = $this->Database->query('SELECT SUM(consumption) AS Total FROM network_devices WHERE user='.$UserId.' AND used=1'); 57 56 $ConsumptionBonus = $DbResult->fetch_assoc(); 58 $ConsumptionBonus = W2Kc($ConsumptionBonus['Total']);57 $ConsumptionBonus = $this->System->Modules['Finance']->W2Kc($ConsumptionBonus['Total']); 59 58 60 59 $Total = 0; … … 79 78 while($Row = $DbResult->fetch_assoc()) 80 79 { 81 $Output .= '<tr><td>'.$Row['name'].'</td><td>'.$Row['consumption'].'</td><td>'. W2Kc($Row['consumption']).'</td></tr>';80 $Output .= '<tr><td>'.$Row['name'].'</td><td>'.$Row['consumption'].'</td><td>'.$this->System->Modules['Finance']->W2Kc($Row['consumption']).'</td></tr>'; 82 81 $TotalW += $Row['consumption']; 83 $TotalPrice += W2Kc($Row['consumption']);82 $TotalPrice += $this->System->Modules['Finance']->W2Kc($Row['consumption']); 84 83 } 85 84 $Output .= '<tr><td><strong>Celkem</strong></td><td><strong>'.$TotalW.'</strong></td><td><strong>'.$TotalPrice.'</strong></td></tr>'; -
www/finance/user_state_ip.php
r156 r157 2 2 3 3 include_once('../global.php'); 4 include_once('include.php');5 RecalculateTariffs(1);6 4 7 5 class FinanceUserState extends Page … … 14 12 global $Tarify, $Sprava; 15 13 16 $UserId = GetMemberByIP(GetRemoteAddress()); 14 $this->System->Modules['Finance']->RecalculateTariffs(1); 15 16 $UserId = GetMemberByIP(GetRemoteAddress()); 17 17 18 18 if(!array_key_exists('show', $_GET)) $_GET['show'] = ''; … … 55 55 $DbResult = $this->Database->query('SELECT SUM(consumption) AS Total FROM network_devices WHERE user='.$UserId.' AND used=1'); 56 56 $ConsumptionBonus = $DbResult->fetch_assoc(); 57 $ConsumptionBonus = W2Kc($ConsumptionBonus['Total']);57 $ConsumptionBonus = $this->System->Modules['Finance']->W2Kc($ConsumptionBonus['Total']); 58 58 59 59 $Total = 0; … … 78 78 while($Row = $DbResult->fetch_assoc()) 79 79 { 80 $Output .= '<tr><td>'.$Row['name'].'</td><td>'.$Row['consumption'].'</td><td>'. W2Kc($Row['consumption']).'</td></tr>';80 $Output .= '<tr><td>'.$Row['name'].'</td><td>'.$Row['consumption'].'</td><td>'.$this->System->Modules['Finance']->W2Kc($Row['consumption']).'</td></tr>'; 81 81 $TotalW += $Row['consumption']; 82 $TotalPrice += W2Kc($Row['consumption']);82 $TotalPrice += $this->System->Modules['Finance']->W2Kc($Row['consumption']); 83 83 } 84 84 $Output .= '<tr><td><strong>Celkem</strong></td><td><strong>'.$TotalW.'</strong></td><td><strong>'.$TotalPrice.'</strong></td></tr>'; -
www/finance/zarizeni.php
r152 r157 1 1 <?php 2 2 include_once('../global.php'); 3 include_once('include.php');4 3 5 4 class FinanceDeviceListPage extends Page -
www/finance/zivnost.php
r152 r157 1 1 <?php 2 2 include_once('../global.php'); 3 include_once('include.php');4 3 5 4 class FinanceTaxFilingPage extends Page … … 31 30 function Show() 32 31 { 33 RecalculateTariffs(1);32 $this->System->Modules['Finance']->RecalculateTariffs(1); 34 33 //TransformFinance(); 35 34
Note:
See TracChangeset
for help on using the changeset viewer.