Changeset 715 for trunk/Modules/Finance/Finance.php
- Timestamp:
- Jan 1, 2015, 2:18:20 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Finance/Finance.php
r713 r715 2 2 3 3 include_once(dirname(__FILE__).'/Overview.php'); 4 include_once(dirname(__FILE__).'/Consumption.php');5 include_once(dirname(__FILE__).'/Devices.php');6 4 include_once(dirname(__FILE__).'/Bill.php'); 7 5 include_once(dirname(__FILE__).'/Services.php'); … … 34 32 var $SpeedReserve; 35 33 var $BaseSpeedElement; 36 var $TotalConsumption;37 34 var $UserIdNetwork = 46; 38 35 var $BaseTariffPrice; … … 143 140 $this->SpravaUsers = $this->PayingUsers; 144 141 145 $DbResult = $this->Database->query('SELECT SUM(`Consumption`) FROM `NetworkSegment`');146 $TotalConsumption = $DbResult->fetch_array();147 $this->TotalConsumption = $TotalConsumption[0];148 149 142 $DbResult = $this->Database->query('SELECT SUM(`MemberPayment`.`MonthlyInternet`) AS `MonthlyInternet`, '. 150 143 'SUM(`MemberPayment`.`MonthlyTotal`) AS `MonthlyTotal` '. … … 208 201 $ConsumptionPlus = $DbResult2->fetch_row(); 209 202 $ConsumptionPlus = $ConsumptionPlus[0]; 210 211 $NetworkDevice = 0;212 $Consumption = 0;213 $Id = $Member['NetworkSegment'];214 while(($Id != '') and ($Id != 0))215 {216 $DbResult2 = $this->Database->query('SELECT * FROM `NetworkSegment` WHERE `Id`='.$Id);217 $Device = $DbResult2->fetch_assoc();218 if($Device['Users'] > 0) $NetworkDevice += $Device['Price'] / $Device['Users'];219 if($Device['UsersOverheads'] > 0) $Consumption += $Device['Consumption'] / $Device['UsersOverheads'];220 $Id = $Device['Parent'];221 }222 203 223 204 $DbResult2 = $this->Database->query('SELECT SUM(`Service`.`Price`) AS `Price` '. … … 253 234 } 254 235 255 function RecalculateSegmentParameters()256 {257 $Output = 'Aktualizuji parametry segmentů...<br />';258 $this->Database->query('UPDATE `NetworkSegment` SET `Users` = 0, `UsersOverheads` = 0'); // Vynulovat počty uživatelů259 $DbResult = $this->Database->query('SELECT * FROM `NetworkSegment`');260 while($NetworkSegment = $DbResult->fetch_array())261 {262 $DbResult2 = $this->Database->query('SELECT `Users` FROM `NetworkSegment` WHERE `Id`='.$NetworkSegment['Id']);263 $RowP = $DbResult2->fetch_array();264 $DbResult2 = $this->Database->query('SELECT `UsersOverheads` FROM `NetworkSegment` WHERE `Id`='.$NetworkSegment['Id']);265 $RowP2 = $DbResult2->fetch_array();266 267 $DbResult2 = $this->Database->query('SELECT SUM(`Product`.`BuyPrice`) * `StockSerialNumber`.`Amount` AS `Price`, '.268 'SUM(`Product`.`Consumption`) * `StockSerialNumber`.`Amount` AS `Consumption` '.269 'FROM `StockSerialNumber` JOIN `Product` ON `Product`.`Id` = `StockSerialNumber`.`Product` '.270 'WHERE (`StockSerialNumber`.`Segment`='.$NetworkSegment['Id'].') AND (`StockSerialNumber`.`TimeElimination` IS NULL)');271 $Row2 = $DbResult2->fetch_array();272 $DbResult2 = $this->Database->query('SELECT COUNT(*) FROM Member WHERE NetworkSegment='.$NetworkSegment['Id']);273 $Row3 = $DbResult2->fetch_array();274 $ID = $NetworkSegment['Parent'];275 while($ID != 0)276 {277 $DbResult2 = $this->Database->query('SELECT * FROM NetworkSegment WHERE Id='.$ID);278 $Row4 = $DbResult2->fetch_array();279 $this->Database->update('NetworkSegment', 'Id='.$Row4['Id'],280 array('Users' => ($Row4['Users'] + $Row3[0]), 'UsersOverheads' => ($Row4['UsersOverheads'] + $Row3[0])));281 $ID = $Row4['Parent'];282 }283 $this->Database->update('NetworkSegment', 'Id='.$NetworkSegment['Id'],284 array('Price' => $Row2['Price'], 'Users' => ($Row3[0] + $RowP['Users']), 'Consumption' => $Row2['Consumption'], 'UsersOverheads' => ($Row3[0] + $RowP2['UsersOverheads'])));285 }286 287 // Zkorigovat segment Internet288 $DbResult = $this->Database->select('Member', 'COUNT(*)');289 $Row = $DbResult->fetch_array();290 $DbResult = $this->Database->update('NetworkSegment', 'Id='.$this->InternetSegmentId,291 array('Users' => $Row[0], 'UsersOverheads' => $Row[0]));292 $this->System->ModuleManager->Modules['Log']->NewRecord('Finance', 'RecalculateSegmentParameters');293 return($Output);294 }295 296 236 function GetVATByType($TypeId) 297 237 { … … 331 271 332 272 $this->System->RegisterPage('finance', 'PageFinance'); 333 $this->System->RegisterPage(array('finance', 'spotreba'), 'PageFinanceConsumption');334 $this->System->RegisterPage(array('finance', 'zarizeni'), 'PageFinanceDeviceList');335 273 $this->System->RegisterPage(array('finance', 'sluzby'), 'PageFinanceServices'); 336 274 $this->System->RegisterPage(array('finance', 'mesicni-prehledy'), 'PageFinanceMonthlyOverall'); … … 433 371 'Bank' => array('Type' => 'TFinanceBank', 'Caption' => 'Banka', 'Default' => ''), 434 372 'TimeCreate' => array('Type' => 'Date', 'Caption' => 'Čas vytvoření', 'Default' => ''), 435 'TimeEnd' => array('Type' => 'Date', 'Caption' => 'Čas zrušení', 'Default' => '' ),373 'TimeEnd' => array('Type' => 'Date', 'Caption' => 'Čas zrušení', 'Default' => '', 'Null' => true), 436 374 'Currency' => array('Type' => 'TCurrency', 'Caption' => 'Měna', 'Default' => ''), 437 375 'LoginName' => array('Type' => 'String', 'Caption' => 'Přihlašovací jméno / token', 'Default' => ''),
Note:
See TracChangeset
for help on using the changeset viewer.