Umowy.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. Lib::loadClass('ColumnDealsStatus');
  4. class Route_Test_Umowy extends RouteBase {
  5. function allAction() {
  6. UI::layout( [ $this, 'allView' ], [ 'showMenu' => false ] );
  7. }
  8. function allView() {
  9. ColumnDealsStatus::reinstall();
  10. ColumnDealsStatus::run_update($force = true);
  11. DBG::nicePrint($msgs, '$msgs');
  12. $items = DB::getPDO()->fetchAll("
  13. select d.ID, d.A_STATUS, t.SERVICES_STATUS
  14. , d.*, t.*
  15. from `temp_DEALS_STATUS` t
  16. left join DEALS_TABLE d on ( d.ID = t.ID_DEALS )
  17. ");
  18. }
  19. function defaultAction() {
  20. UI::layout( [ $this, 'defaultView' ], [ 'showMenu' => false ] );
  21. }
  22. function defaultView() {
  23. $id = V::get('id', 0, $_GET, 'int');
  24. if ($id <= 0) throw new Exception("Missing id company");
  25. echo UI::h('div', [], [
  26. "Klient {$id}: ",
  27. UI::h('a', [
  28. 'href' => "index.php?MENU_INIT=USERS2_WINDYKACJA_STATUS&q={$id}&_f=&_oby=ID&_odir=DESC&_user_id={$id}",
  29. 'target' => "_blank",
  30. ], "Windykacja"),
  31. " | ",
  32. UI::h('a', [
  33. 'href' => "index.php?MENU_INIT=POKAZ_OFERTY_AKTUALNE_FUNC&task=klient_umowy&id_user={$id}",
  34. 'target' => "_blank",
  35. ], "Umowy"),
  36. " | ",
  37. UI::h('a', [
  38. 'href' => "index.php?FUNCTION_INIT=bm_make_faktura&ARG1_VAL={$id}",
  39. 'target' => "_blank",
  40. ], "Faktury"),
  41. ]);
  42. $totalDeals = DB::getPDO()->fetchValue(" select count(*) from DEALS_TABLE ");
  43. $totalActivatedDeals = DB::getPDO()->fetchValue(" select count(*) from DEALS_TABLE where A_STATUS = 'NORMAL' ");
  44. $itemDealsTable = DB::getPDO()->fetchAll(" select * from DEALS_TABLE where ID_BILLING_USERS = :id ", [ ':id' => $id ]);
  45. UI::table([ 'rows' => $itemDealsTable, 'caption' => "`DEALS_TABLE`: itemDealsTable, Client = {$id}, total rows = {$totalDeals} (activated: {$totalActivatedDeals})" ]);
  46. UI::table([ 'rows' => array_map(function ($item) {
  47. return array_merge([
  48. 'ID' => '',
  49. 'A_STATUS' => '',
  50. 'P_DEALDATE' => '',
  51. 'P_DEALDATE_TERM' => '',
  52. 'USTALONA_DATA_PODLACZENIA' => '',
  53. 'DATA_WYK_PODLACZENIA' => '',
  54. 'TODO__DATA_WYK_PODLACZENIA' => DB::getPDO()->fetchValue("
  55. (
  56. select T_WHEN_CONNECTED, a.ID, s.ID_DEALS_TABLE
  57. from SES_USERS2_A a
  58. join SERVICES s on ( s.ID = a.ID_SERVICES )
  59. where a.ID_BILLING_USERS = :id_client
  60. and s.ID_DEALS_TABLE = :id_deal
  61. )
  62. union
  63. (
  64. select T_WHEN_CONNECTED, a.ID, s.ID_DEALS_TABLE
  65. from SES_TV_A a
  66. join SERVICES s on ( s.ID = a.ID_SERVICES )
  67. where a.ID_BILLING_USERS = :id_client
  68. and s.ID_DEALS_TABLE = :id_deal
  69. )
  70. union
  71. (
  72. select T_WHEN_CONNECTED, a.ID, s.ID_DEALS_TABLE
  73. from SES_VOIP_A a
  74. join SERVICES s on ( s.ID = a.ID_SERVICES )
  75. where a.ID_BILLING_USERS = :id_client
  76. and s.ID_DEALS_TABLE = :id_deal
  77. )
  78. order by T_WHEN_CONNECTED asc
  79. ", [
  80. ':id_client' => $item['ID_BILLING_USERS'],
  81. ':id_deal' => $item['ID'],
  82. ]),
  83. 'DEALDESC' => '',
  84. ], $item);
  85. }, $itemDealsTable), 'caption' => "`DEALS_TABLE`: itemDealsTable, Client = {$id}, total rows = {$totalDeals} (activated: {$totalActivatedDeals})" ]);
  86. $itemServices = DB::getPDO()->fetchAll(" select * from SERVICES where ID_BILLING_USERS = :id ", [ ':id' => $id ]);
  87. UI::table([ 'rows' => $itemServices, 'caption' => "`SERVICES`: itemServices, Client = {$id}" ]);
  88. $itemSesNET = DB::getPDO()->fetchAll("
  89. select *
  90. , '***' as P_SERVICE_QUOTA_PROFILE
  91. , '***' as N_AVG_TRAFFIC
  92. from SES_USERS2_A
  93. where ID_BILLING_USERS = :id
  94. ", [ ':id' => $id ]);
  95. UI::table([ 'rows' => $itemSesNET, 'caption' => "`SES_USERS2_A`: itemSesNET, Client = {$id}" ]);
  96. $itemSesTV = DB::getPDO()->fetchAll(" select * from SES_TV_A where ID_BILLING_USERS = :id ", [ ':id' => $id ]);
  97. UI::table([ 'rows' => $itemSesTV, 'caption' => "`SES_TV_A`: itemSesTV, Client = {$id}" ]);
  98. $itemSesVOIP = DB::getPDO()->fetchAll(" select * from SES_VOIP_A where ID_BILLING_USERS = :id ", [ ':id' => $id ]);
  99. UI::table([ 'rows' => $itemSesVOIP, 'caption' => "`SES_VOIP_A`: itemSesVOIP, Client = {$id}" ]);
  100. // `SES_*_A`: `T_WHEN_CONNECTED`, `T_WHO_CONNECTED`
  101. echo UI::h('div', [ 'style' => "padding:3px 12px; background-color:#eee" ], [
  102. UI::h('h3', [], "Daty podłączenia (Aktywacji?):"),
  103. UI::h('div', [ 'style' => "padding: 12px; background-color:#eee" ], [
  104. UI::h('div', [ 'style' => "background-color:#fff" ], [
  105. UI::hTable([ 'rows' => array_map([ $this, 'whenConnectedTableRowView' ], $itemSesNET), 'caption' => "SES_USERS2_A" ]),
  106. UI::hTable([ 'rows' => array_map([ $this, 'whenConnectedTableRowView' ], $itemSesTV), 'caption' => "SES_TV_A" ]),
  107. UI::hTable([ 'rows' => array_map([ $this, 'whenConnectedTableRowView' ], $itemSesVOIP), 'caption' => "SES_VOIP_A" ]),
  108. ]),
  109. ]),
  110. ]);
  111. $itemDbTasks = DB::getPDO()->fetchAll("
  112. select t.*
  113. from DEALS_TABLE d
  114. left join _DB_TASKS t on ( t.TRANSACTION_ID = concat('DEALS_TABLE-', d.ID) )
  115. where d.ID_BILLING_USERS = :id
  116. ", [ ':id' => $id ]);
  117. UI::table([ 'rows' => $itemDbTasks, 'caption' => "`_DB_TASKS`: itemDbTasks, Client = {$id}" ]);
  118. DBG::nicePrint(null, "memory_get_usage: " . round(memory_get_usage() / 1024) . " KB");
  119. die('.EOF');
  120. }
  121. function whenConnectedTableRowView($item) { // ID, T_WHEN_CONNECTED, T_WHO_CONNECTED
  122. return array_merge([
  123. 'ID' => '',
  124. 'ID_DEALS_TABLE' => DB::getPDO()->fetchValue(" select ID_DEALS_TABLE from SERVICES where ID = :id ", [ ':id' => $item['ID_SERVICES'] ]),
  125. 'T_WHEN_CONNECTED' => '',
  126. 'T_WHO_CONNECTED' => '',
  127. ], $item);
  128. }
  129. }
  130. class RelatedFeatureTagReader {
  131. function __construct() {
  132. $this->_parsedTags = [];
  133. }
  134. function findRelatedFeatureRecurse($tag, $parentTagId = 0, $parsedTags = []) {
  135. if (!is_array($tag)) return $parsedTags; // string
  136. DBG::nicePrint([ 'tag' => $tag[0], 'attrs' => $tag[1], '$parsedTags' => $parsedTags ], "findRelatedFeatureRecurse({$tag[0]})");
  137. if (empty($tag)) return [];
  138. if ('RelatedFeature' === $tag[0]) {
  139. $parsedTags[] = [ 'tag' => $tag[0], 'attrs' => $tag[1], 'parentTagId' => $parentTagId ];
  140. $parentTagId = count($parsedTags) - 1;
  141. }
  142. else if (!empty($tag[1]['xpath'])) $parsedTags[] = [ 'tag' => $tag[0], 'attrs' => $tag[1], 'parentTagId' => $parentTagId ];
  143. if (empty($tag[2])) return $parsedTags;
  144. return array_reduce($tag[2], function ($ret, $childTag) use ($parentTagId) {
  145. return $this->findRelatedFeatureRecurse($childTag, $parentTagId, $ret);
  146. }, $parsedTags);
  147. }
  148. }