api.switchcash.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. <?php
  2. /**
  3. * Switches profitability implementation
  4. */
  5. class SwitchCash {
  6. /**
  7. * Contains system alter config as key=>value
  8. *
  9. * @var array
  10. */
  11. protected $altCfg = array();
  12. /**
  13. * Contains all available switches financial data as switchId=>data
  14. *
  15. * @var array
  16. */
  17. protected $allCashData = array();
  18. /**
  19. * Contains database abstraction layer for financial data
  20. *
  21. * @var object
  22. */
  23. protected $swCashDb = '';
  24. /**
  25. * System message helper object placeholder
  26. *
  27. * @var object
  28. */
  29. protected $messages = '';
  30. /**
  31. * Filestorage instance object placeholder
  32. *
  33. * @var object
  34. */
  35. protected $filestorage = '';
  36. /**
  37. * Excel report placeholder
  38. *
  39. * @var objecr
  40. */
  41. protected $excelReport = '';
  42. /**
  43. * Contains all user data as login=>userdata
  44. *
  45. * @var array
  46. */
  47. protected $allUsersData = array();
  48. /**
  49. *
  50. * Contains all switch assigns as login=>assignData
  51. *
  52. * @var array
  53. */
  54. protected $allSwitchAssigns = array();
  55. /**
  56. * Contains all switches that contains report mark as switchId=>switchData
  57. *
  58. * @var array
  59. */
  60. protected $allReportSwitches = array();
  61. /**
  62. * Contains all available tariff prices as tariffname=>Fee
  63. *
  64. * @var array
  65. */
  66. protected $allTariffPrices = array();
  67. /**
  68. * Contains bad colored switches count
  69. *
  70. * @var int
  71. */
  72. protected $counterBad = 0;
  73. /**
  74. * Contains good colored switches count
  75. *
  76. * @var int
  77. */
  78. protected $counterGood = 0;
  79. /**
  80. * Contains equal colored switches count
  81. *
  82. * @var int
  83. */
  84. protected $counterEqual = 0;
  85. /**
  86. * Some static defines etc
  87. */
  88. const TABLE_FINANCE = 'swcash';
  89. const FILESTORAGE_SCOPE = 'SWCASH';
  90. const REPORT_MASK = 'SWCASH';
  91. const URL_ME = '?module=swcash';
  92. const URL_SWITCHPROFILE = '?module=switches&edit=';
  93. const ROUTE_EDIT = 'switchid';
  94. const ROUTE_REPORT = 'renderreport';
  95. const ROUTE_EXCEL = 'excelexport';
  96. const ROUTE_USERS = 'renderswusers';
  97. const PROUTE_CREATE = 'createswitchid';
  98. const PROUTE_SAVE = 'saveswitchid';
  99. const PROUTE_RECORD = 'swcashrecordid';
  100. const PROUTE_PLACECONTRACT = 'newplacecontract';
  101. const PROUTE_PLACEPRICE = 'newplaceprice';
  102. const PROUTE_POWERCONTRACT = 'newpowercontract';
  103. const PROUTE_POWERPRICE = 'newpoweprice';
  104. const PROUTE_TRANSPORTCONTRACT = 'newtransportcontract';
  105. const PROUTE_TRANSPORTPRICE = 'newtransportprice';
  106. const PROUTE_SWITCHPRICE = 'newswitchprice';
  107. const PROUTE_SWITCHDATE = 'newswitchdate';
  108. const COLOR_BAD = 'bc0000';
  109. const COLOR_GOOD = '007603';
  110. const COLOR_EQUAL = 'f47900';
  111. /**
  112. * ___ ___
  113. * (o o) (o o)
  114. * ( V ) ( V )
  115. * /--m-m- /--m-m-
  116. */
  117. public function __construct() {
  118. $this->loadAlter();
  119. $this->initMessages();
  120. $this->initFilestorage();
  121. $this->initDatabase();
  122. $this->loadAllCashData();
  123. }
  124. /**
  125. * Inits database abstraction layer for further usage
  126. *
  127. * @return void
  128. */
  129. protected function initDatabase() {
  130. $this->swCashDb = new NyanORM(self::TABLE_FINANCE);
  131. }
  132. /**
  133. * Inits system message helper object
  134. *
  135. * @return void
  136. */
  137. protected function initMessages() {
  138. $this->messages = new UbillingMessageHelper();
  139. }
  140. /**
  141. * Inits filestorage instance if enabled
  142. *
  143. * @return void
  144. */
  145. protected function initFilestorage() {
  146. if (@$this->altCfg['FILESTORAGE_ENABLED']) {
  147. $this->filestorage = new FileStorage(self::FILESTORAGE_SCOPE);
  148. }
  149. }
  150. /**
  151. * Loads system alter.ini config into protected prop
  152. *
  153. * @global object $ubillingConfig
  154. *
  155. * @return void
  156. */
  157. protected function loadAlter() {
  158. global $ubillingConfig;
  159. $this->altCfg = $ubillingConfig->getAlter();
  160. }
  161. /**
  162. * Performs loading and preprocessing of available financial data
  163. *
  164. * @return void
  165. */
  166. protected function loadAllCashData() {
  167. $this->allCashData = $this->swCashDb->getAll('switchid');
  168. }
  169. /**
  170. * Loads all data required for basic report.
  171. * Must be called manually to save some resources.
  172. *
  173. * @return void
  174. */
  175. protected function loadReportData() {
  176. $this->loadUserData();
  177. $this->loadTariffPrices();
  178. $this->loadSwitchesData();
  179. $this->loadSwitchPortAssigns();
  180. $this->initExcelLib();
  181. }
  182. /**
  183. * Loads all users data into protected prop
  184. *
  185. * @return void
  186. */
  187. protected function loadUserData() {
  188. $this->allUsersData = zb_UserGetAllDataCache();
  189. }
  190. /**
  191. * Loads all available tariff fees
  192. *
  193. * @return void
  194. */
  195. protected function loadTariffPrices() {
  196. $this->allTariffPrices = zb_TariffGetPricesAll();
  197. }
  198. /**
  199. * Loads switches data into protected property
  200. *
  201. * @return void
  202. */
  203. protected function loadSwitchesData() {
  204. $this->allReportSwitches = zb_SwitchesGetAllMask(self::REPORT_MASK);
  205. }
  206. /**
  207. * Loads all available switchport assigns into protected prop
  208. *
  209. * @return void
  210. */
  211. protected function loadSwitchPortAssigns() {
  212. $this->allSwitchAssigns = zb_SwitchesGetAssignsAll();
  213. }
  214. /**
  215. * Inits excel export library
  216. *
  217. * @return void
  218. */
  219. protected function initExcelLib() {
  220. require_once ('api/vendor/PHPExcel/Classes/PHPExcel.php');
  221. $this->excelReport = new PHPExcel();
  222. }
  223. /**
  224. * Checks have some switch some financial data or not?
  225. *
  226. * @param int $switchId
  227. *
  228. * @return bool
  229. */
  230. public function haveFinancialData($switchId) {
  231. $result = (isset($this->allCashData[$switchId])) ? true : false;
  232. return($result);
  233. }
  234. /**
  235. * Creates new database record on request
  236. *
  237. * @return void/string on error
  238. */
  239. public function catchCreate() {
  240. $result = '';
  241. if (ubRouting::checkPost(self::PROUTE_CREATE)) {
  242. $switchId = ubRouting::post(self::PROUTE_CREATE, 'int');
  243. $placecontract = ubRouting::post(self::PROUTE_PLACECONTRACT, 'mres');
  244. $placeprice = ubRouting::post(self::PROUTE_PLACEPRICE, 'mres');
  245. $powercontract = ubRouting::post(self::PROUTE_POWERCONTRACT, 'mres');
  246. $powerprice = ubRouting::post(self::PROUTE_POWERPRICE, 'mres');
  247. $transportcontract = ubRouting::post(self::PROUTE_TRANSPORTCONTRACT, 'mres');
  248. $transportprice = ubRouting::post(self::PROUTE_TRANSPORTPRICE, 'mres');
  249. $switchprice = ubRouting::post(self::PROUTE_SWITCHPRICE, 'mres');
  250. $switchdate = ubRouting::post(self::PROUTE_SWITCHDATE, 'mres');
  251. if (zb_checkDate($switchdate)) {
  252. $this->swCashDb->data('switchid', $switchId);
  253. $this->swCashDb->data('placecontract', $placecontract);
  254. $this->swCashDb->data('placeprice', $placeprice);
  255. $this->swCashDb->data('powercontract', $powercontract);
  256. $this->swCashDb->data('powerprice', $powerprice);
  257. $this->swCashDb->data('transportcontract', $transportcontract);
  258. $this->swCashDb->data('transportprice', $transportprice);
  259. $this->swCashDb->data('switchprice', $switchprice);
  260. $this->swCashDb->data('switchdate', $switchdate);
  261. $this->swCashDb->create();
  262. log_register('SWCASH CREATE SWID [' . $switchId . ']');
  263. } else {
  264. $result .= __('Wrong date format');
  265. }
  266. }
  267. return($result);
  268. }
  269. /**
  270. * Saves database record on request
  271. *
  272. * @return void/string on error
  273. */
  274. public function catchSave() {
  275. $result = '';
  276. if (ubRouting::checkPost(self::PROUTE_SAVE) AND ubRouting::checkPost(self::PROUTE_RECORD)) {
  277. $switchId = ubRouting::post(self::PROUTE_SAVE, 'int');
  278. $recordId = ubRouting::post(self::PROUTE_RECORD, 'int');
  279. $placecontract = ubRouting::post(self::PROUTE_PLACECONTRACT, 'mres');
  280. $placeprice = ubRouting::post(self::PROUTE_PLACEPRICE, 'mres');
  281. $powercontract = ubRouting::post(self::PROUTE_POWERCONTRACT, 'mres');
  282. $powerprice = ubRouting::post(self::PROUTE_POWERPRICE, 'mres');
  283. $transportcontract = ubRouting::post(self::PROUTE_TRANSPORTCONTRACT, 'mres');
  284. $transportprice = ubRouting::post(self::PROUTE_TRANSPORTPRICE, 'mres');
  285. $switchprice = ubRouting::post(self::PROUTE_SWITCHPRICE, 'mres');
  286. $switchdate = ubRouting::post(self::PROUTE_SWITCHDATE, 'mres');
  287. if (zb_checkDate($switchdate)) {
  288. $this->swCashDb->where('id', '=', $recordId);
  289. $this->swCashDb->data('placecontract', $placecontract);
  290. $this->swCashDb->data('placeprice', $placeprice);
  291. $this->swCashDb->data('powercontract', $powercontract);
  292. $this->swCashDb->data('powerprice', $powerprice);
  293. $this->swCashDb->data('transportcontract', $transportcontract);
  294. $this->swCashDb->data('transportprice', $transportprice);
  295. $this->swCashDb->data('switchprice', $switchprice);
  296. $this->swCashDb->data('switchdate', $switchdate);
  297. $this->swCashDb->save();
  298. log_register('SWCASH EDIT SWID [' . $switchId . ']');
  299. } else {
  300. $result .= __('Wrong date format');
  301. }
  302. }
  303. return($result);
  304. }
  305. /**
  306. * Renders switch financial data creation form
  307. *
  308. * @param int $switchId
  309. *
  310. * @return string
  311. */
  312. public function renderCreateForm($switchId) {
  313. $result = '';
  314. $switchId = ubRouting::filters($switchId, 'int');
  315. //creation flag
  316. $inputs = wf_HiddenInput(self::PROUTE_CREATE, $switchId);
  317. //placement data
  318. $inputs .= wf_TextInput(self::PROUTE_PLACECONTRACT, __('Placement contract'), '', true, 20);
  319. $inputs .= wf_TextInput(self::PROUTE_PLACEPRICE, __('Placement price') . ' / ' . __('month'), '0', true, 5, 'finance');
  320. //power data
  321. $inputs .= wf_TextInput(self::PROUTE_POWERCONTRACT, __('Power contract'), '', true, 20);
  322. $inputs .= wf_TextInput(self::PROUTE_POWERPRICE, __('Power price') . ' / ' . __('month'), '0', true, 5, 'finance');
  323. //transport data
  324. $inputs .= wf_TextInput(self::PROUTE_TRANSPORTCONTRACT, __('Transport contract'), '', true, 20);
  325. $inputs .= wf_TextInput(self::PROUTE_TRANSPORTPRICE, __('Transport price') . ' / ' . __('month'), '0', true, 5, 'finance');
  326. //switch pricing and installation date
  327. $inputs .= wf_TextInput(self::PROUTE_SWITCHPRICE, __('Switch price'), '0', true, 5, 'finance');
  328. $inputs .= wf_DatePickerPreset(self::PROUTE_SWITCHDATE, curdate(), true) . ' ' . __('Switch installation date');
  329. $inputs .= wf_delimiter();
  330. $inputs .= wf_Submit(__('Create'));
  331. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  332. return($result);
  333. }
  334. /**
  335. * Renders switch financial data editing form
  336. *
  337. * @param int $switchId
  338. *
  339. * @return string
  340. */
  341. public function renderEditForm($switchId) {
  342. $result = '';
  343. $switchId = ubRouting::filters($switchId, 'int');
  344. if (isset($this->allCashData[$switchId])) {
  345. $switchData = $this->allCashData[$switchId];
  346. //save flag and record id
  347. $inputs = wf_HiddenInput(self::PROUTE_SAVE, $switchId);
  348. $inputs .= wf_HiddenInput(self::PROUTE_RECORD, $switchData['id']);
  349. //placement data
  350. $inputs .= wf_TextInput(self::PROUTE_PLACECONTRACT, __('Placement contract'), $switchData['placecontract'], true, 20);
  351. $inputs .= wf_TextInput(self::PROUTE_PLACEPRICE, __('Placement price') . ' / ' . __('month'), $switchData['placeprice'], true, 5, 'finance');
  352. if (!empty($this->filestorage)) {
  353. $this->filestorage->setItemid('place' . $switchId);
  354. $inputs .= $this->filestorage->renderFilesPreview(true);
  355. }
  356. //power data
  357. $inputs .= wf_TextInput(self::PROUTE_POWERCONTRACT, __('Power contract'), $switchData['powercontract'], true, 20);
  358. $inputs .= wf_TextInput(self::PROUTE_POWERPRICE, __('Power price') . ' / ' . __('month'), $switchData['powerprice'], true, 5, 'finance');
  359. if (!empty($this->filestorage)) {
  360. $this->filestorage->setItemid('power' . $switchId);
  361. $inputs .= $this->filestorage->renderFilesPreview(true);
  362. }
  363. //transport data
  364. $inputs .= wf_TextInput(self::PROUTE_TRANSPORTCONTRACT, __('Transport contract'), $switchData['transportcontract'], true, 20);
  365. $inputs .= wf_TextInput(self::PROUTE_TRANSPORTPRICE, __('Transport price') . ' / ' . __('month'), $switchData['transportprice'], true, 5, 'finance');
  366. if (!empty($this->filestorage)) {
  367. $this->filestorage->setItemid('transport' . $switchId);
  368. $inputs .= $this->filestorage->renderFilesPreview(true);
  369. }
  370. //switch pricing and installation date
  371. $inputs .= wf_TextInput(self::PROUTE_SWITCHPRICE, __('Switch price'), $switchData['switchprice'], true, 5, 'finance');
  372. $inputs .= wf_DatePickerPreset(self::PROUTE_SWITCHDATE, $switchData['switchdate'], true) . ' ' . __('Switch installation date');
  373. $inputs .= wf_delimiter();
  374. $inputs .= wf_Submit(__('Save'));
  375. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  376. } else {
  377. $result .= $this->messages->getStyledMessage(__('Something went wrong') . ': EX_NO_SWCASHDATA', 'error');
  378. }
  379. return($result);
  380. }
  381. /**
  382. * Returns switch month price for the first year
  383. *
  384. * @param int $switchId
  385. *
  386. * @return float
  387. */
  388. protected function getSwitchPrice($switchId) {
  389. $result = 0;
  390. if (isset($this->allCashData[$switchId])) {
  391. $curDateTimestamp = time();
  392. $switchCashData = $this->allCashData[$switchId];
  393. if ($switchCashData['switchprice'] > 0) {
  394. if (!empty($switchCashData['switchdate'])) {
  395. $switchSetupTimestamp = strtotime($switchCashData['switchdate']);
  396. $timeFromSetup = $curDateTimestamp - $switchSetupTimestamp;
  397. $daysFromSetup = round($timeFromSetup / 86400);
  398. if ($daysFromSetup < 365) { //switch installed less than one year ago
  399. $result = $switchCashData['switchprice'] / 12; //price per month
  400. }
  401. }
  402. }
  403. }
  404. return($result);
  405. }
  406. /**
  407. * Returns total of switch expenses per month
  408. *
  409. * @param int $switchId
  410. *
  411. * @return float
  412. */
  413. protected function getSwitchExpenses($switchId) {
  414. $result = 0;
  415. if (isset($this->allCashData[$switchId])) {
  416. $switchCashData = $this->allCashData[$switchId];
  417. $result += $this->getSwitchPrice($switchId); //switch price for the first year
  418. $result += $switchCashData['placeprice']; //placement price
  419. $result += $switchCashData['powerprice']; //power price
  420. $result += $switchCashData['transportprice']; //transport price
  421. }
  422. return($result);
  423. }
  424. /**
  425. * Returns total switch profit per month
  426. *
  427. * @param int $switchId
  428. *
  429. * @return float
  430. */
  431. protected function getSwitchProfit($switchId) {
  432. $result = 0;
  433. if (!empty($this->allSwitchAssigns)) {
  434. foreach ($this->allSwitchAssigns as $eachLogin => $assignData) {
  435. if ($assignData['switchid'] == $switchId) {
  436. if (isset($this->allUsersData[$eachLogin])) {
  437. $userTariff = $this->allUsersData[$eachLogin]['Tariff'];
  438. if (isset($this->allTariffPrices[$userTariff])) {
  439. $userFee = $this->allTariffPrices[$userTariff];
  440. $result += $userFee;
  441. }
  442. }
  443. }
  444. }
  445. }
  446. return($result);
  447. }
  448. /**
  449. * Colorize switch name based on profit
  450. *
  451. * @param string $switchName
  452. * @param float $expenses
  453. * @param float $profit
  454. *
  455. * @return string
  456. */
  457. protected function colorizeSwitch($switchName, $expenses, $profit) {
  458. $result = $switchName;
  459. $textColor = '';
  460. if ($profit > $expenses) {
  461. $textColor = self::COLOR_GOOD;
  462. $this->counterGood++;
  463. }
  464. if ($profit < $expenses) {
  465. $textColor = self::COLOR_BAD;
  466. $this->counterBad++;
  467. }
  468. if ($profit == $expenses) {
  469. $textColor = self::COLOR_EQUAL;
  470. $this->counterEqual++;
  471. }
  472. if ($textColor) {
  473. $result = wf_tag('font', false, '', 'color="#' . $textColor . '"') . $switchName . wf_tag('font', true);
  474. }
  475. return($result);
  476. }
  477. /**
  478. * Renders chart of switches profitability percents
  479. *
  480. * @return string
  481. */
  482. protected function renderCharts() {
  483. $result = '';
  484. if ($this->counterBad OR $this->counterGood OR $this->counterEqual) {
  485. $chartOpts = "chartArea: { width: '100%', height: '80%' }, legend : {position: 'right', textStyle: {fontSize: 12 }}, pieSliceText: 'value-and-percentage',";
  486. $chartData = array(
  487. __('Good payback') => $this->counterGood,
  488. __('Bad payback') => $this->counterBad,
  489. __('Equal') => $this->counterEqual,
  490. );
  491. $result .= wf_gcharts3DPie($chartData, __('Payback'), '400px', '300px', $chartOpts);
  492. }
  493. return($result);
  494. }
  495. /**
  496. * Performs report exporting in MS Excel format
  497. *
  498. * @return
  499. */
  500. protected function exportBasicReport() {
  501. // Set document properties
  502. $this->excelReport->getProperties()->setCreator("Ubilling")
  503. ->setLastModifiedBy("Ubilling")
  504. ->setTitle('Switches profitability report')
  505. ->setSubject('Switches profitability report')
  506. ->setDescription('Switches profitability report')
  507. ->setKeywords("Ubilling");
  508. // Redirect output to a client’s web browser (Excel5)
  509. header('Content-Type: application/vnd.ms-excel');
  510. header('Content-Disposition: attachment;filename="' . curdatetime() . '_report.xls"');
  511. header('Cache-Control: max-age=0');
  512. // If you're serving to IE 9, then the following may be needed
  513. header('Cache-Control: max-age=1');
  514. // If you're serving to IE over SSL, then the following may be needed
  515. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  516. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
  517. header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  518. header('Pragma: public'); // HTTP/1.0
  519. // Set document properties
  520. $this->excelReport->getProperties()->setCreator("Ubilling")
  521. ->setLastModifiedBy("Ubilling")
  522. ->setTitle('Switches profitability report')
  523. ->setSubject('Switches profitability report')
  524. ->setDescription('Switches profitability report')
  525. ->setKeywords("Ubilling");
  526. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  527. $this->excelReport->setActiveSheetIndex(0);
  528. //setting columns width
  529. $this->excelReport->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
  530. $this->excelReport->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
  531. $this->excelReport->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
  532. $objWriter = PHPExcel_IOFactory::createWriter($this->excelReport, 'Excel5');
  533. $objWriter->save('php://output');
  534. die();
  535. }
  536. /**
  537. * Renders basic report with switches profitability
  538. *
  539. * @return string
  540. */
  541. public function renderBasicReport() {
  542. $result = '';
  543. //loading all data required for this report
  544. $this->loadReportData();
  545. $exportFlag = (ubRouting::checkGet(self::ROUTE_EXCEL)) ? true : false;
  546. if (!empty($this->allReportSwitches)) {
  547. $cells = wf_TableCell(__('Address'));
  548. $cells .= wf_TableCell(__('Monthly expenses'));
  549. $cells .= wf_TableCell(__('Monthly profit'));
  550. $cells .= wf_TableCell(__('Actions'));
  551. $rows = wf_TableRow($cells, 'row1');
  552. $rowCounter = 1; //starts from 1 due excel columns numbering
  553. //appending export headers if required
  554. if ($exportFlag) {
  555. $this->excelReport->setActiveSheetIndex(0)->setCellValue('A' . $rowCounter, __('Address'));
  556. $this->excelReport->setActiveSheetIndex(0)->setCellValue('B' . $rowCounter, __('Monthly expenses'));
  557. $this->excelReport->setActiveSheetIndex(0)->setCellValue('C' . $rowCounter, __('Monthly profit'));
  558. }
  559. foreach ($this->allReportSwitches as $eachSwitchId => $eachSwitchData) {
  560. $rowCounter++;
  561. $switchExpenses = $this->getSwitchExpenses($eachSwitchId);
  562. $switchProfit = $this->getSwitchProfit($eachSwitchId);
  563. $switchName = (!empty($eachSwitchData['location'])) ? $eachSwitchData['location'] : $eachSwitchData['ip'];
  564. $cells = wf_TableCell($this->colorizeSwitch($switchName, $switchExpenses, $switchProfit));
  565. $cells .= wf_TableCell($switchExpenses);
  566. $cells .= wf_TableCell($switchProfit);
  567. $swControls = '';
  568. $swControls .= wf_Link(self::URL_SWITCHPROFILE . $eachSwitchId, web_edit_icon(__('Switch'))) . ' ';
  569. $swControls .= wf_Link(self::URL_ME . '&' . self::ROUTE_EDIT . '=' . $eachSwitchId, wf_img('skins/ukv/dollar.png', __('Financial data'))) . ' ';
  570. $swControls .= wf_Link(self::URL_ME . '&' . self::ROUTE_USERS . '=' . $eachSwitchId, web_profile_icon(__('Users'))) . ' ';
  571. $cells .= wf_TableCell($swControls);
  572. $rows .= wf_TableRow($cells, 'row5');
  573. //appending export data if required
  574. if ($exportFlag) {
  575. $this->excelReport->setActiveSheetIndex(0)->setCellValue('A' . $rowCounter, $switchName);
  576. $this->excelReport->setActiveSheetIndex(0)->setCellValue('B' . $rowCounter, $switchExpenses);
  577. $this->excelReport->setActiveSheetIndex(0)->setCellValue('C' . $rowCounter, $switchProfit);
  578. }
  579. }
  580. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  581. //charts rendering
  582. $result .= $this->renderCharts();
  583. //excel report exporting
  584. if ($exportFlag) {
  585. $this->exportBasicReport();
  586. }
  587. } else {
  588. $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'warning');
  589. }
  590. return($result);
  591. }
  592. /**
  593. * Renders users list assigned for some switch
  594. *
  595. * @param int $switchId
  596. *
  597. * @return string
  598. */
  599. public function renderUsersReport($switchId) {
  600. $result = '';
  601. //loading all data required for this report
  602. $this->loadReportData();
  603. $switchId = ubRouting::filters($switchId, 'int');
  604. $usersTmp = array();
  605. if (!empty($this->allCashData)) {
  606. if (!empty($this->allSwitchAssigns)) {
  607. foreach ($this->allSwitchAssigns as $eachLogin => $eachAssignData) {
  608. if ($eachAssignData['switchid'] == $switchId) {
  609. if (isset($this->allUsersData[$eachLogin])) {
  610. $usersTmp[$eachLogin] = $eachLogin;
  611. }
  612. }
  613. }
  614. }
  615. }
  616. $result .= web_UserCorpsArrayShower($usersTmp, $switchId);
  617. return($result);
  618. }
  619. }