index.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. <?php
  2. if (cfr('TASKREPORT')) {
  3. $altCfg = $ubillingConfig->getAlter();
  4. if ($altCfg['TASKREPORT_ENABLED']) {
  5. class TasksReport {
  6. /**
  7. * System alter config stored as key=>value
  8. *
  9. * @var array
  10. */
  11. protected $altCfg = array();
  12. /**
  13. * jobtypes IDs for report
  14. *
  15. * @var array
  16. */
  17. protected $reportJobtypes = array();
  18. /**
  19. * Signup tasks jobtype IDs array
  20. *
  21. * @var array
  22. */
  23. protected $signupJobtypeId = array();
  24. /**
  25. * Available jobtypes data as jobtypeid=>data
  26. *
  27. * @var array
  28. */
  29. protected $jobtypes = array();
  30. /**
  31. * Report date from
  32. *
  33. * @var string
  34. */
  35. protected $dateFrom = '';
  36. /**
  37. * Report date to
  38. *
  39. * @var string
  40. */
  41. protected $dateTo = '';
  42. /**
  43. * Contains all tasks with reportJobtypes perfromed between search intervals
  44. *
  45. * @var array
  46. */
  47. protected $allTasks = array();
  48. /**
  49. * System messages helper object placeholder
  50. *
  51. * @var object
  52. */
  53. protected $messages = '';
  54. /**
  55. * Warehouse usage flag
  56. *
  57. * @var bool
  58. */
  59. protected $warehouseFlag = false;
  60. /**
  61. * Salary usage flag
  62. *
  63. * @var bool
  64. */
  65. protected $salaryFlag = false;
  66. /**
  67. * Connection details usage flag
  68. *
  69. * @var bool
  70. */
  71. protected $condetFlag = false;
  72. /**
  73. * Warehouse object placeholder
  74. *
  75. * @var object
  76. */
  77. protected $warehouse = '';
  78. /**
  79. * Salary object placeholder
  80. *
  81. * @var object
  82. */
  83. protected $salary = '';
  84. /**
  85. * Telepathy object placeholder
  86. *
  87. * @var object
  88. */
  89. protected $telepathy = '';
  90. /**
  91. * Available user contracts
  92. *
  93. * @var array
  94. */
  95. protected $userContracts = array();
  96. /**
  97. * Available tariff prices
  98. *
  99. * @var array
  100. */
  101. protected $tariffPrices = array();
  102. /**
  103. * Contains current users tariffs
  104. *
  105. * @var array
  106. */
  107. protected $userTariffs = array();
  108. /**
  109. * Contains all signup payments as login=>summ
  110. *
  111. * @var array
  112. */
  113. protected $signupPayments = array();
  114. /**
  115. * Contains tagids for notes column
  116. *
  117. * @var array
  118. */
  119. protected $notesTagids = array();
  120. /**
  121. * Contains tags assigned for users
  122. *
  123. * @var array
  124. */
  125. protected $userTags = array();
  126. /**
  127. * Contains all available tagtypes as id=>name
  128. *
  129. * @var array
  130. */
  131. protected $tagTypes = array();
  132. /**
  133. * Salary tax rates multiplier
  134. *
  135. * @var float
  136. */
  137. protected $salaryMultiplier = 0;
  138. /**
  139. * System caching object placeholder
  140. *
  141. * @var object
  142. */
  143. protected $cache = '';
  144. /**
  145. * Contains basic URL for task editing
  146. */
  147. const URL_TASK = '?module=taskman&edittask=';
  148. /**
  149. * Contains basic URL for user profile
  150. */
  151. const URL_USER = '?module=userprofile&username=';
  152. /**
  153. * Basic module URL
  154. */
  155. const URL_ME = '?module=tasksreport';
  156. /**
  157. * Printable temp file path
  158. */
  159. const PRINT_PATH = 'exports/taskreportprint.html';
  160. /**
  161. * Creates new TasksReport object instance
  162. *
  163. * @return void
  164. */
  165. public function __construct() {
  166. $this->loadConfigs();
  167. $this->preprocessConfigs();
  168. $this->initMessages();
  169. $this->loadJobtypes();
  170. $this->setDates();
  171. $this->loadTasks();
  172. $this->loadTariffsData();
  173. $this->loadContracts();
  174. $this->loadSignupPayments();
  175. $this->loadTagsData();
  176. $this->initWarehouse();
  177. $this->initSalary();
  178. $this->initTelepathy();
  179. $this->initCache();
  180. }
  181. /**
  182. * Loads main configuration options
  183. *
  184. * @global object $ubillingConfig
  185. *
  186. * @return void
  187. */
  188. protected function loadConfigs() {
  189. global $ubillingConfig;
  190. $this->altCfg = $ubillingConfig->getAlter();
  191. }
  192. /**
  193. * Preprocess config options into protected properties
  194. *
  195. * @return void
  196. */
  197. protected function preprocessConfigs() {
  198. if (!empty($this->altCfg['TASKREPORT_JOBTYPES'])) {
  199. $jobtypesTmp = explode(',', $this->altCfg['TASKREPORT_JOBTYPES']);
  200. $this->reportJobtypes = array_flip($jobtypesTmp);
  201. }
  202. if (!empty($this->altCfg['TASKREPORT_SIGNUPJOBTYPES'])) {
  203. $signupJobtypeIdtmp = explode(',', $this->altCfg['TASKREPORT_SIGNUPJOBTYPES']);
  204. $this->signupJobtypeId = array_flip($signupJobtypeIdtmp);
  205. }
  206. if ($this->altCfg['WAREHOUSE_ENABLED']) {
  207. $this->warehouseFlag = true;
  208. }
  209. if ($this->altCfg['SALARY_ENABLED']) {
  210. $this->salaryFlag = true;
  211. }
  212. if ($this->altCfg['CONDET_ENABLED']) {
  213. $this->condetFlag = true;
  214. }
  215. if ($this->altCfg['TASKREPORT_NOTESTAGIDS']) {
  216. $notesTagidsTmp = explode(',', $this->altCfg['TASKREPORT_NOTESTAGIDS']);
  217. $this->notesTagids = array_flip($notesTagidsTmp);
  218. }
  219. if (isset($this->altCfg['TASKREPORT_SALARY_MULTIPLIER'])) {
  220. $this->salaryMultiplier = $this->altCfg['TASKREPORT_SALARY_MULTIPLIER'];
  221. }
  222. }
  223. /**
  224. * Sets current report dates
  225. *
  226. * @return void
  227. */
  228. protected function setDates() {
  229. if (wf_CheckPost(array('dateto', 'datefrom'))) {
  230. $this->dateFrom = mysql_real_escape_string($_POST['datefrom']);
  231. $this->dateTo = mysql_real_escape_string($_POST['dateto']);
  232. } else {
  233. if (wf_CheckGet(array('dateto', 'datefrom'))) {
  234. $this->dateFrom = mysql_real_escape_string($_GET['datefrom']);
  235. $this->dateTo = mysql_real_escape_string($_GET['dateto']);
  236. } else {
  237. $this->dateFrom = date("Y-m") . '-01';
  238. $this->dateTo = curdate();
  239. }
  240. }
  241. }
  242. /**
  243. * Returns dates from object instance
  244. *
  245. * @return array
  246. */
  247. public function getDates() {
  248. $result = array('from' => $this->dateFrom, 'to' => $this->dateTo);
  249. return ($result);
  250. }
  251. /**
  252. * Loads available jobtypes data
  253. *
  254. * @return void
  255. */
  256. protected function loadJobtypes() {
  257. $query = "SELECT * from `jobtypes`";
  258. $all = simple_queryall($query);
  259. if (!empty($all)) {
  260. foreach ($all as $io => $each) {
  261. $this->jobtypes[$each['id']] = $each;
  262. }
  263. }
  264. }
  265. /**
  266. * Loads available users contracts
  267. *
  268. * @return void
  269. */
  270. protected function loadContracts() {
  271. $this->userContracts = array_flip(zb_UserGetAllContracts());
  272. }
  273. /**
  274. * Inits system cache for further usage
  275. *
  276. * @return void
  277. */
  278. protected function initCache() {
  279. $this->cache = new UbillingCache();
  280. }
  281. /**
  282. * Cleans some cached data
  283. *
  284. * @return void
  285. */
  286. public function cacheCleanup() {
  287. $this->cache->delete('TASKSJOBS');
  288. $this->cache->delete('TASKSOUTS');
  289. }
  290. /**
  291. * Inits system messages object
  292. *
  293. * @return void
  294. */
  295. protected function initMessages() {
  296. $this->messages = new UbillingMessageHelper();
  297. }
  298. /**
  299. * Inits warehouse object instance
  300. *
  301. * @return void
  302. */
  303. protected function initWarehouse() {
  304. if ($this->warehouseFlag) {
  305. $this->warehouse = new Warehouse();
  306. }
  307. }
  308. /**
  309. * Inits salary object instance
  310. *
  311. * @return void
  312. */
  313. protected function initSalary() {
  314. if ($this->salaryFlag) {
  315. $this->salary = new Salary();
  316. }
  317. }
  318. /**
  319. * Inits telepathy object
  320. *
  321. * @return void
  322. */
  323. protected function initTelepathy() {
  324. $this->telepathy = new Telepathy(false, true);
  325. }
  326. /**
  327. * Loads tasks for report in selected time range, into protected property for further usage
  328. *
  329. * @return void
  330. */
  331. protected function loadTasks() {
  332. $query = "SELECT * from `taskman` WHERE `startdate` BETWEEN '" . $this->dateFrom . "' AND '" . $this->dateTo . "'";
  333. $all = simple_queryall($query);
  334. if (!empty($all)) {
  335. foreach ($all as $io => $each) {
  336. if (isset($this->reportJobtypes[$each['jobtype']])) {
  337. $this->allTasks[$each['id']] = $each;
  338. }
  339. }
  340. }
  341. }
  342. /**
  343. * Loads users tariffs and tariffs prices data
  344. *
  345. * @return void
  346. */
  347. protected function loadTariffsData() {
  348. $this->tariffPrices = zb_TariffGetPricesAll();
  349. $this->userTariffs = zb_TariffsGetAllUsers();
  350. }
  351. /**
  352. * Loads all signup payments from database into protected prop
  353. *
  354. * @return void
  355. */
  356. protected function loadSignupPayments() {
  357. $cahtypeId = vf($this->altCfg['TASKREPORT_SIGPAYID'], 3);
  358. if ($cahtypeId) {
  359. //natural payments
  360. $query = "SELECT * from `payments` WHERE `cashtypeid`='" . $cahtypeId . "';";
  361. $all = simple_queryall($query);
  362. if (!empty($all)) {
  363. foreach ($all as $io => $each) {
  364. if (isset($this->signupPayments[$each['login']])) {
  365. $this->signupPayments[$each['login']] += $each['summ'];
  366. } else {
  367. $this->signupPayments[$each['login']] = $each['summ'];
  368. }
  369. }
  370. }
  371. } else {
  372. //payments from condet
  373. if ($this->altCfg['CONDET_ENABLED']) {
  374. $query = "SELECT * from `condet`";
  375. $all = simple_queryall($query);
  376. if (!empty($all)) {
  377. foreach ($all as $io => $each) {
  378. $this->signupPayments[$each['login']] = $each['price'];
  379. }
  380. }
  381. }
  382. }
  383. }
  384. /**
  385. * Loads and do some preprocessing tags and tagtypes data
  386. *
  387. * @return void
  388. */
  389. protected function loadTagsData() {
  390. if (!empty($this->notesTagids)) {
  391. //preprocessing tagtypes
  392. $query = "SELECT * from `tagtypes`";
  393. $all = simple_queryall($query);
  394. if (!empty($all)) {
  395. foreach ($all as $io => $each) {
  396. $this->tagTypes[$each['id']] = $each['tagname'];
  397. }
  398. }
  399. //preprocessing usertags
  400. $query = "SELECT * from `tags`";
  401. $all = simple_queryall($query);
  402. if (!empty($all)) {
  403. foreach ($all as $io => $each) {
  404. if (isset($this->notesTagids[$each['tagid']])) {
  405. if (isset($this->userTags[$each['login']])) {
  406. $this->userTags[$each['login']] .= @$this->tagTypes[$each['tagid']] . ' ';
  407. } else {
  408. $this->userTags[$each['login']] = @$this->tagTypes[$each['tagid']] . ' ';
  409. }
  410. }
  411. }
  412. }
  413. }
  414. }
  415. /**
  416. * Returns user signup price by its login
  417. *
  418. * @param string $login
  419. *
  420. * @return float
  421. */
  422. protected function getSignupPrice($login) {
  423. $result = 0;
  424. if (isset($this->signupPayments[$login])) {
  425. $result = $this->signupPayments[$login];
  426. if (!is_numeric($result)) {
  427. $result = 0;
  428. }
  429. }
  430. return ($result);
  431. }
  432. /**
  433. * Renders default from-to date controls form
  434. *
  435. * @return string
  436. */
  437. public function renderDatesForm() {
  438. $result = '';
  439. $inputs = __('Date') . ' ' . wf_DatePickerPreset('datefrom', $this->dateFrom, true) . ' ' . __('From') . ' ';
  440. $inputs .= wf_DatePickerPreset('dateto', $this->dateTo, true) . ' ' . __('To') . ' ';
  441. $inputs .= wf_Submit(__('Show'));
  442. $result = wf_Form('', 'POST', $inputs, 'glamour');
  443. return ($result);
  444. }
  445. /**
  446. * shows printable report content
  447. *
  448. * @param $title report title
  449. * @param $data report data to printable transform
  450. *
  451. * @return void
  452. */
  453. public function reportPrintable($title, $data) {
  454. $style = file_get_contents(CONFIG_PATH . "ukvprintable.css");
  455. $header = wf_tag('html', false);
  456. $header .= wf_tag('head', false);
  457. $header .= wf_tag('title') . $title . wf_tag('title', true);
  458. $header .= wf_tag('meta', false, '', 'http-equiv="Content-Type" content="text/html; charset=UTF-8" /');
  459. $header .= wf_tag('style', false, '', 'type="text/css"');
  460. $header .= $style;
  461. $header .= wf_tag('style', true);
  462. $header .= wf_tag('script', false, '', 'src="modules/jsc/sorttable.js" language="javascript"') . wf_tag('script', true);
  463. $header .= wf_tag('head', true);
  464. $header .= wf_tag('body', false);
  465. $footer = wf_tag('body', true);
  466. $footer .= wf_tag('html', true);
  467. $title = (!empty($title)) ? wf_tag('h2') . $title . wf_tag('h2', true) : '';
  468. $data = $header . $title . $data . $footer;
  469. die($data);
  470. }
  471. /**
  472. * Renders report by preloaded data
  473. *
  474. * @return string
  475. */
  476. public function renderReport() {
  477. $result = '';
  478. $resultPrintable = '';
  479. $count = 1;
  480. $signupsTotalSpent = 0;
  481. $signupsTotalPayments = 0;
  482. $signupsWarehouseTotalSpent = 0;
  483. $signupsSalaryTotalSpent = 0;
  484. $otherTasksTotalSpent = 0;
  485. $signupsTotalTariffPrices = 0;
  486. $tasksSummary = array();
  487. $warehouseSpent = 0;
  488. $salarySpent = 0;
  489. $signupMaterialsSpent = array();
  490. $nonSignupsMaterialsSpent = array();
  491. if (!empty($this->allTasks)) {
  492. $cells = wf_TableCell('№');
  493. $cells .= wf_TableCell(__('ID'));
  494. $cells .= wf_TableCell(__('Done'));
  495. $cells .= wf_TableCell(__('Contract'));
  496. $cells .= wf_TableCell(__('Address'));
  497. $cells .= wf_TableCell(__('Type'));
  498. if ($this->warehouseFlag OR $this->salaryFlag) {
  499. $cells .= wf_TableCell(__('Spent on task'));
  500. }
  501. $cells .= wf_TableCell(__('Paid by user'));
  502. $cells .= wf_TableCell(__('Tariff fee'));
  503. $cells .= wf_TableCell(__('Notes'));
  504. $rows = wf_TableRow($cells, 'row1');
  505. foreach ($this->allTasks as $io => $each) {
  506. $typeColor = (!empty($this->jobtypes[$each['jobtype']]['jobcolor'])) ? $this->jobtypes[$each['jobtype']]['jobcolor'] : '';
  507. if (!empty($typeColor)) {
  508. $styleStart = wf_tag('font', false, '', 'color="' . $typeColor . '"');
  509. $styleEnd = wf_tag('font', true);
  510. } else {
  511. $styleStart = '';
  512. $styleEnd = '';
  513. }
  514. $userLogin = '';
  515. $userLink = '';
  516. $userTariff = '';
  517. $tariffPrice = 0;
  518. if (!empty($each['login'])) {
  519. $userLogin = $each['login'];
  520. @$userContract = $this->userContracts[$userLogin];
  521. $userLink = wf_Link(self::URL_USER . $userLogin, web_profile_icon() . ' ' . $userContract, false);
  522. } else {
  523. $userLogin = $this->telepathy->getLogin($each['address']);
  524. @$userContract = $this->userContracts[$userLogin];
  525. $guessed = wf_tag('sup') . wf_tag('abbr', false, '', 'title="' . __('telepathically guessed') . '"') . '(?)' . wf_tag('abbr', true) . wf_tag('sup', true);
  526. if (!empty($userLogin)) {
  527. $userLink = wf_Link(self::URL_USER . $userLogin, web_profile_icon() . ' ' . $userContract . $guessed, false);
  528. }
  529. }
  530. if (!empty($userLogin)) {
  531. @$userTariff = $this->userTariffs[$userLogin];
  532. if ((!empty($userTariff)) AND ( $userTariff != '*_NO_TARIFF_*')) {
  533. $tariffPrice = $this->tariffPrices[$userTariff];
  534. }
  535. }
  536. $cells = wf_TableCell($count);
  537. $cells .= wf_TableCell(wf_Link(self::URL_TASK . $each['id'], $each['id'], false));
  538. $cells .= wf_TableCell(web_bool_led($each['status']), '', '', 'sorttable_customkey="' . $each['status'] . '"');
  539. $cells .= wf_TableCell($userLink);
  540. $cells .= wf_TableCell($styleStart . $each['address'] . $styleEnd);
  541. $cells .= wf_TableCell($styleStart . $this->jobtypes[$each['jobtype']]['jobname'] . $styleEnd);
  542. if ($this->warehouseFlag OR $this->salaryFlag) {
  543. if ($this->warehouseFlag) {
  544. $warehouseSpentRaw = $this->warehouse->taskMaterialsSpentPrice($each['id']);
  545. //saving materials spent on signups only
  546. if (isset($this->signupJobtypeId[$each['jobtype']])) {
  547. if (isset($warehouseSpentRaw['items'])) {
  548. $signupMaterialsSpent[] = $warehouseSpentRaw['items'];
  549. }
  550. } else {
  551. if (isset($warehouseSpentRaw['items'])) {
  552. $nonSignupsMaterialsSpent[] = $warehouseSpentRaw['items'];
  553. }
  554. }
  555. $warehouseSpent = $warehouseSpentRaw['sum'];
  556. }
  557. if ($this->salaryFlag) {
  558. if ($this->salaryMultiplier) {
  559. $salarySpent = $this->salary->getTaskPrice($each['id']) * $this->salaryMultiplier;
  560. } else {
  561. $salarySpent = $this->salary->getTaskPrice($each['id']);
  562. }
  563. }
  564. $totalTaskSpent = $warehouseSpent + $salarySpent;
  565. $cells .= wf_TableCell($totalTaskSpent);
  566. }
  567. //detecting signup price and some counters only for signup tasks
  568. if (isset($this->signupJobtypeId[$each['jobtype']])) {
  569. $signupPrice = $this->getSignupPrice($userLogin);
  570. $signupsSalaryTotalSpent += $salarySpent;
  571. $signupsWarehouseTotalSpent += $warehouseSpent;
  572. $signupsTotalSpent += $warehouseSpent + $salarySpent;
  573. $signupsTotalPayments += $signupPrice;
  574. if (!is_numeric($tariffPrice)) {
  575. $tariffPrice = 0; //fix of non detected user tariffs pricing
  576. }
  577. $signupsTotalTariffPrices += $tariffPrice;
  578. } else {
  579. //other task types
  580. $signupPrice = 0;
  581. $otherTasksTotalSpent += $warehouseSpent + $salarySpent;
  582. }
  583. $cells .= wf_TableCell($signupPrice);
  584. $cells .= wf_TableCell($tariffPrice);
  585. $cells .= wf_TableCell(@$this->userTags[$userLogin]);
  586. //row coloring
  587. if (empty($userLogin)) {
  588. $rowColor = 'undone';
  589. } else {
  590. if (@$totalTaskSpent > ($signupPrice + $tariffPrice)) {
  591. $rowColor = 'ukvbankstadup';
  592. } else {
  593. $rowColor = 'row3';
  594. }
  595. }
  596. //back coloring for non signup types
  597. if (!isset($this->signupJobtypeId[$each['jobtype']])) {
  598. $rowColor = 'row3';
  599. }
  600. $rows .= wf_TableRow($cells, $rowColor);
  601. //report summary
  602. if (isset($tasksSummary[$each['jobtype']])) {
  603. $tasksSummary[$each['jobtype']]['count'] ++;
  604. $tasksSummary[$each['jobtype']]['warehouse'] += $warehouseSpent;
  605. $tasksSummary[$each['jobtype']]['salary'] += $salarySpent;
  606. $tasksSummary[$each['jobtype']]['sigprice'] += $signupPrice;
  607. if (isset($this->signupJobtypeId[$each['jobtype']])) {
  608. $tasksSummary[$each['jobtype']]['tariffprice'] += $tariffPrice;
  609. }
  610. } else {
  611. $tasksSummary[$each['jobtype']]['tasktype'] = $this->jobtypes[$each['jobtype']]['jobname'];
  612. $tasksSummary[$each['jobtype']]['count'] = 1;
  613. $tasksSummary[$each['jobtype']]['warehouse'] = $warehouseSpent;
  614. $tasksSummary[$each['jobtype']]['salary'] = $salarySpent;
  615. $tasksSummary[$each['jobtype']]['sigprice'] = $signupPrice;
  616. if (isset($this->signupJobtypeId[$each['jobtype']])) {
  617. $tasksSummary[$each['jobtype']]['tariffprice'] = $tariffPrice;
  618. } else {
  619. $tasksSummary[$each['jobtype']]['tariffprice'] = 0;
  620. }
  621. }
  622. $count++;
  623. }
  624. $result = wf_TableBody($rows, '100%', 0, 'sortable');
  625. $result .= wf_tag('br');
  626. //detailed tasks summary
  627. if (!empty($tasksSummary)) {
  628. $cells = wf_TableCell(__('Job type'));
  629. $cells .= wf_TableCell(__('Count'));
  630. if ($this->warehouseFlag OR $this->salaryFlag) {
  631. if ($this->warehouseFlag) {
  632. $cells .= wf_TableCell(__('Spent materials'));
  633. }
  634. if ($this->salaryFlag) {
  635. $cells .= wf_TableCell(__('Paid staff'));
  636. }
  637. }
  638. $cells .= wf_TableCell(__('Tariff fee'));
  639. $cells .= wf_TableCell(__('Signup payments total'));
  640. $cells .= wf_TableCell(__('Profit'));
  641. $rows = wf_TableRow($cells, 'row1');
  642. foreach ($tasksSummary as $io => $each) {
  643. $cells = wf_TableCell($each['tasktype']);
  644. $cells .= wf_TableCell($each['count']);
  645. if ($this->warehouseFlag OR $this->salaryFlag) {
  646. if ($this->warehouseFlag) {
  647. $cells .= wf_TableCell($each['warehouse']);
  648. }
  649. if ($this->salaryFlag) {
  650. $cells .= wf_TableCell($each['salary']);
  651. }
  652. }
  653. $cells .= wf_TableCell($each['tariffprice']);
  654. $cells .= wf_TableCell($each['sigprice']);
  655. $cells .= wf_TableCell((($each['tariffprice'] + $each['sigprice']) - ($each['warehouse'] + $each['salary'])));
  656. $rows .= wf_TableRow($cells, 'row3');
  657. }
  658. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  659. $result .= wf_tag('br');
  660. //signup warehouse items spent summary stats
  661. if (!empty($signupMaterialsSpent)) {
  662. $warehouseSignupStats = array();
  663. foreach ($signupMaterialsSpent as $io => $flow) {
  664. if (!empty($flow)) {
  665. foreach ($flow as $ia => $each) {
  666. if (isset($warehouseSignupStats[$each['itemtypeid']])) {
  667. $warehouseSignupStats[$each['itemtypeid']]['count'] += $each['count'];
  668. $warehouseSignupStats[$each['itemtypeid']]['price'] += $each['price'] * $each['count'];
  669. } else {
  670. $warehouseSignupStats[$each['itemtypeid']]['count'] = $each['count'];
  671. $warehouseSignupStats[$each['itemtypeid']]['price'] = $each['price'] * $each['count'];
  672. }
  673. }
  674. }
  675. }
  676. $cells = wf_TableCell(__('Category'));
  677. $cells .= wf_TableCell(__('Warehouse item types'));
  678. $cells .= wf_TableCell(__('Count'));
  679. $cells .= wf_TableCell(__('Money'));
  680. $rows = wf_TableRow($cells, 'row1');
  681. foreach ($warehouseSignupStats as $io => $each) {
  682. $cells = wf_TableCell($this->warehouse->itemtypeGetCategory($io));
  683. $cells .= wf_TableCell($this->warehouse->itemtypeGetName($io));
  684. $cells .= wf_TableCell($each['count'] . ' ' . $this->warehouse->itemtypeGetUnit($io));
  685. $cells .= wf_TableCell($each['price']);
  686. $rows .= wf_TableRow($cells, 'row3');
  687. }
  688. $resultPrintable .= wf_tag('b') . __('Total spent materials for signups') . wf_tag('b', true);
  689. $resultPrintable .= wf_TableBody($rows, '100%', 0, 'sortable');
  690. $resultPrintable .= wf_tag('br');
  691. }
  692. //warehouse items spent on non-signup tasks
  693. if (!empty($nonSignupsMaterialsSpent)) {
  694. $warehouseNonSignupStats = array();
  695. foreach ($nonSignupsMaterialsSpent as $io => $flow) {
  696. if (!empty($flow)) {
  697. foreach ($flow as $ia => $each) {
  698. if (isset($warehouseNonSignupStats[$each['itemtypeid']])) {
  699. $warehouseNonSignupStats[$each['itemtypeid']]['count'] += $each['count'];
  700. $warehouseNonSignupStats[$each['itemtypeid']]['price'] += $each['price'] * $each['count'];
  701. } else {
  702. $warehouseNonSignupStats[$each['itemtypeid']]['count'] = $each['count'];
  703. $warehouseNonSignupStats[$each['itemtypeid']]['price'] = $each['price'] * $each['count'];
  704. }
  705. }
  706. }
  707. }
  708. $cells = wf_TableCell(__('Category'));
  709. $cells .= wf_TableCell(__('Warehouse item types'));
  710. $cells .= wf_TableCell(__('Count'));
  711. $cells .= wf_TableCell(__('Money'));
  712. $rows = wf_TableRow($cells, 'row1');
  713. foreach ($warehouseNonSignupStats as $io => $each) {
  714. $cells = wf_TableCell($this->warehouse->itemtypeGetCategory($io));
  715. $cells .= wf_TableCell($this->warehouse->itemtypeGetName($io));
  716. $cells .= wf_TableCell($each['count'] . ' ' . $this->warehouse->itemtypeGetUnit($io));
  717. $cells .= wf_TableCell($each['price']);
  718. $rows .= wf_TableRow($cells, 'row3');
  719. }
  720. $resultPrintable .= wf_tag('b') . __('Total spent for other tasks') . ' (' . __('From warehouse storage') . ')' . wf_tag('b', true);
  721. $resultPrintable .= wf_TableBody($rows, '100%', 0, 'sortable');
  722. $resultPrintable .= wf_tag('br');
  723. $result .= $resultPrintable;
  724. }
  725. //appending totals counters
  726. $cells = wf_TableCell(__('Counter'));
  727. $cells .= wf_TableCell(__('Money'));
  728. $rows = wf_TableRow($cells, 'row1');
  729. $cells = wf_TableCell(__('Total spent on signups'), '', 'row2');
  730. $cells .= wf_TableCell($signupsTotalSpent);
  731. $rows .= wf_TableRow($cells, 'row3');
  732. $cells = wf_TableCell(__('Total spent materials for signups'), '', 'row2');
  733. $cells .= wf_TableCell($signupsWarehouseTotalSpent);
  734. $rows .= wf_TableRow($cells, 'row3');
  735. $cells = wf_TableCell(__('Total spent salary for signups'), '', 'row2');
  736. $cells .= wf_TableCell($signupsSalaryTotalSpent);
  737. $rows .= wf_TableRow($cells, 'row3');
  738. $cells = wf_TableCell(__('Signup payments total'), '', 'row2');
  739. $cells .= wf_TableCell($signupsTotalPayments);
  740. $rows .= wf_TableRow($cells, 'row3');
  741. $cells = wf_TableCell(__('Total spent for other tasks'), '', 'row2');
  742. $cells .= wf_TableCell($otherTasksTotalSpent);
  743. $rows .= wf_TableRow($cells, 'row3');
  744. $signupsProfit = ($signupsTotalTariffPrices + $signupsTotalPayments) - $signupsTotalSpent;
  745. $cells = wf_TableCell(__('Profit from users signups'), '', 'row2');
  746. $cells .= wf_TableCell($signupsProfit);
  747. $rows .= wf_TableRow($cells, 'row3');
  748. $result .= wf_TableBody($rows, '50%', 0, 'sortable');
  749. if ($this->salaryMultiplier) {
  750. $result .= __('Including salary tax rates');
  751. }
  752. }
  753. } else {
  754. $result = $this->messages->getStyledMessage(__('Nothing found'), 'info');
  755. }
  756. //saving printable results
  757. file_put_contents(self::PRINT_PATH, $resultPrintable);
  758. return ($result);
  759. }
  760. }
  761. set_time_limit(0);
  762. $report = new TasksReport();
  763. if (wf_CheckGet(array('cleancache'))) {
  764. $report->cacheCleanup();
  765. rcms_redirect($report::URL_ME);
  766. }
  767. if (wf_CheckGet(array('print'))) {
  768. if (file_exists($report::PRINT_PATH)) {
  769. if (filesize($report::PRINT_PATH) > 0) {
  770. $printableData = file_get_contents($report::PRINT_PATH);
  771. $datesFiltered = $report->getDates();
  772. die($report->reportPrintable(__('Warehouse') . ': ' . $datesFiltered['from'] . '-' . $datesFiltered['to'], $printableData));
  773. }
  774. }
  775. }
  776. $cacheCleanupControl = wf_Link($report::URL_ME . '&cleancache=true', wf_img('skins/icon_cleanup.png', __('Cache cleanup')));
  777. show_window(__('Search') . ' ' . $cacheCleanupControl, $report->renderDatesForm());
  778. show_window(__('Tasks report'), $report->renderReport());
  779. $datesFiltered = $report->getDates();
  780. $printDates = '&datefrom=' . $datesFiltered['from'] . '&dateto=' . $datesFiltered['to'];
  781. $printControl = ((file_exists($report::PRINT_PATH)) AND ( filesize($report::PRINT_PATH) > 0) ) ? wf_Link($report::URL_ME . '&print=true' . $printDates, web_icon_print() . ' ' . __('Print'), false, 'ubButton', 'target="_blank"') : '';
  782. show_window('', $printControl);
  783. } else {
  784. show_error(__('This module disabled'));
  785. }
  786. } else {
  787. show_error(__('Access denied'));
  788. }
  789. ?>