superedit-ANALIZA_GRUP_KOSZTOW.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <?php
  2. function ANALIZA_GRUP_KOSZTOW() {
  3. $analizaGrupKosztowRouter = new AnalizaGrupKosztowRouter();
  4. $_print = V::get('_print', '', $_GET);
  5. if (!$_print) {
  6. $analizaGrupKosztowRouter->menu();
  7. }
  8. $grupyKosztow = $analizaGrupKosztowRouter->getGrupyKosztow();
  9. $projekty = $analizaGrupKosztowRouter->getProjekty();
  10. $costs = $analizaGrupKosztowRouter->getCosts();
  11. $orderby = V::get('orderby', '', $_GET);
  12. $view_type = V::get('view_type', '', $_GET);
  13. $analizaGrupKosztowRouter->cyfrowe($projekty, $grupyKosztow, $costs, $orderby, $view_type);
  14. }
  15. class AnalizaGrupKosztowRouter {
  16. // TODO: function link()
  17. function menu() {
  18. // TODO: MENU_INIT na FUNCTION_INIT i HEADER NOT INIT
  19. ?>
  20. <div>
  21. </div>
  22. <?php
  23. }
  24. function css() {
  25. ?>
  26. <style type="text/css">
  27. /* Styles for rotateTableCellContent plugin */
  28. #oferta-programowa-cyfrowe div.rotated {
  29. -webkit-transform:rotate(-90deg);
  30. -moz-transform:rotate(-90deg);
  31. -o-transform:rotate(-90deg);
  32. writing-mode:tb-rl;
  33. white-space:nowrap;
  34. }
  35. body{font-family:arial}
  36. .oferta-programowa { border-collapse:collapse; border:1px solid #7EC5FF; }
  37. .oferta-programowa td { border:1px solid #7EC5FF; }
  38. .oferta-programowa .prog-group { color:#7A7A7A; }
  39. .oferta-programowa .cyfrowe-prog-count {}
  40. .oferta-programowa .p2 { padding:0 2px; }
  41. .oferta-programowa .c { text-align:center; }
  42. .oferta-programowa .r { text-align:right; }
  43. .oferta-programowa .cyfrowe-prog-count td { background-color:#fff; }
  44. .oferta-programowa .hd { background-color:#FF5F5F; color:#fff; font-weight:bold; }
  45. .oferta-programowa .nr { color:#7A7A7A; }
  46. .oferta-programowa thead th { border:1px solid #7EC5FF; }
  47. #oferta-programowa-cyfrowe thead { background:none; }
  48. #oferta-programowa-cyfrowe thead th { vertical-align:bottom; border:none; }
  49. #oferta-programowa-cyfrowe .logo { text-align:center; background-color:#fff; border:none; }
  50. #oferta-programowa-cyfrowe .vertical { height:30px; white-space:nowrap; line-height:30px; padding:2px 0; }
  51. #oferta-programowa-cyfrowe .prog-pakiet-24 {background-color:#EBEBEB;} /* Biały */
  52. #oferta-programowa-cyfrowe .prog-pakiet-25 {background-color:#B88019;} /* Brązowy */
  53. #oferta-programowa-cyfrowe .prog-pakiet-26 {background-color:#CACACA;} /* Srebrny */
  54. #oferta-programowa-cyfrowe .prog-pakiet-27 {background-color:#FFE554;} /* Złoty */
  55. #oferta-programowa-cyfrowe .prog-pakiet-28 {background-color:#E7E4E4;} /* Platynowy */
  56. #oferta-programowa-cyfrowe .prog-pakiet-8 {background-color:#94CFFF;} /* CANAL+ */
  57. #oferta-programowa-cyfrowe .prog-pakiet-10 {background-color:#77A3FF;} /* CANAL+ HD */
  58. #oferta-programowa-analogowe { }
  59. /* print table background colors */
  60. table td, table th { -webkit-print-color-adjust:exact; }
  61. table { page-break-after:auto }
  62. tr { page-break-inside:avoid; page-break-after:auto; position:relative; }
  63. td { page-break-inside:avoid; page-break-after:auto; position:relative; }
  64. thead { display:table-header-group }
  65. tfoot { display:table-footer-group }
  66. </style>
  67. <?php
  68. }
  69. function cyfrowe($programy, $grupyKosztow, $costs, $orderby = '', $view_type = '') {
  70. $grupyKosztow_count = array();
  71. foreach ($grupyKosztow as $pakiet) {
  72. $grupyKosztow_count[$pakiet->ID] = 0;
  73. }
  74. $grupyKosztow_count['HD'] = 0;
  75. foreach ($programy as $program) {
  76. foreach ($grupyKosztow as $pakiet) {
  77. if (in_array($pakiet->ID, $program->pakiety)) {
  78. $grupyKosztow_count[$pakiet->ID] += 1;
  79. }
  80. }
  81. if ($program->TV_SIGAL_DELIVERY == 'DVB-HD') {
  82. $grupyKosztow_count['HD'] += 1;
  83. }
  84. }
  85. if ($view_type == 'csv') {
  86. $this->csv_cyfrowe($programy, $grupyKosztow, $costs, $orderby = '');
  87. return;
  88. }
  89. $this->css();
  90. $sumyGrupKosztow = array();
  91. ?>
  92. <script type="text/javascript">
  93. (function($){
  94. $.fn.rotateTableCellContent = function(options){
  95. /*
  96. Version 1.0
  97. 7/2011
  98. Written by David Votrubec (davidjs.com) and
  99. Michal Tehnik (@Mictech) for ST-Software.com
  100. @from https://github.com/ST-Software/Scripts/tree/master/jquery.rotateTableCellContent
  101. modified by Piotr Labudda: set -90deg from 90deg
  102. */
  103. var cssClass = ((options) ? options.className : false) || "vertical";
  104. var cellsToRotate = $('.' + cssClass, this);
  105. var betterCells = [];
  106. cellsToRotate.each(function(){
  107. var cell = $(this)
  108. , newText = cell.text()
  109. , height = cell.height()
  110. , width = cell.width()
  111. , newDiv = $('<div>', { height: width, width: height })
  112. , newInnerDiv = $('<div>', { text: newText, 'class': 'rotated' });
  113. newInnerDiv.css('-webkit-transform-origin', (width / 2) + 'px ' + (width / 2) + 'px');
  114. newInnerDiv.css('-moz-transform-origin', (width / 2) + 'px ' + (width / 2) + 'px');
  115. newDiv.append(newInnerDiv);
  116. betterCells.push(newDiv);
  117. });
  118. cellsToRotate.each(function(i){
  119. $(this).html(betterCells[i]);
  120. });
  121. };
  122. })(jQuery);
  123. jQuery(document).ready(function(){
  124. var n=jQuery('#oferta-programowa-cyfrowe')
  125. n.rotateTableCellContent();
  126. n.find('.logo').append(jQuery('<img src="icon/logo.biall-net.jpg">'));
  127. });
  128. </script>
  129. <div style="float:right;color:#aaa;"><?php echo date("Y-m-d"); ?></div>
  130. <h1>Analiza grup kosztów</h1>
  131. <table cellspacing="0" cellpadding="0" border="0" id="oferta-programowa-cyfrowe" class="oferta-programowa">
  132. <thead>
  133. <tr>
  134. <td colspan="2" class="logo">
  135. </td>
  136. <?php foreach ($grupyKosztow as $pakiet) { ?>
  137. <th class="vertical prog-pakiet-<?php echo $pakiet->ID; ?>"><?php echo $pakiet->WWW_NAZWA; ?></th>
  138. <?php } ?>
  139. </tr>
  140. <tr>
  141. <td colspan="2" style="text-align:right">
  142. Nr grupy kosztów
  143. </td>
  144. <?php foreach ($grupyKosztow as $pakiet) { ?>
  145. <td class="c"><?php echo $pakiet->ID; ?></td>
  146. <?php } ?>
  147. </tr>
  148. </thead>
  149. <tbody class="cyfrowe-prog-count">
  150. <tr>
  151. <td colspan="2" class="p2 r">Liczba projektów</td>
  152. <?php foreach ($grupyKosztow as $pakiet) { ?>
  153. <td class="c"><?php echo $grupyKosztow_count[$pakiet->ID]; ?></td>
  154. <?php } ?>
  155. </tr>
  156. </tbody>
  157. <tbody>
  158. <?php $t = 1; foreach ($programy as $projekt) { ?>
  159. <tr class="row-<?php echo ($t = 1 - $t); ?>">
  160. <td class="p2 r nr"><?php echo $projekt->ID; ?></td>
  161. <td class="p2"><?php echo $projekt->M_DIST_DESC; ?></td>
  162. <?php foreach ($grupyKosztow as $grupaKosztow) { ?>
  163. <?php if (!empty($costs[$projekt->ID][$grupaKosztow->ID])) : ?>
  164. <?php
  165. $vCost = $costs[$projekt->ID][$grupaKosztow->ID];
  166. $sumyGrupKosztow[$vCost['TYPE']][$grupaKosztow->ID] += $vCost['COST'];
  167. ?>
  168. <td class="c prog-pakiet-<?php echo $grupaKosztow->ID; ?>"><?php echo $vCost['COST']; ?>/<?php echo substr($vCost['TYPE'], 0, 1); ?></td>
  169. <?php else : ?>
  170. <td></td>
  171. <?php endif; ?>
  172. <?php } ?>
  173. </tr>
  174. <?php } ?>
  175. </tbody>
  176. <tfoot>
  177. <?php $t = 1; foreach ($sumyGrupKosztow as $typKosztu => $vSumy) { ?>
  178. <tr class="row-<?php echo ($t = 1 - $t); ?>">
  179. <td class="p2 r nr" colspan="2"><?php echo $typKosztu; ?></td>
  180. <?php foreach ($grupyKosztow as $grupaKosztow) { ?>
  181. <?php if (!empty($vSumy[$grupaKosztow->ID])) : ?>
  182. <td class="c"><?php echo $vSumy[$grupaKosztow->ID]; ?></td>
  183. <?php else : ?>
  184. <td></td>
  185. <?php endif; ?>
  186. <?php } ?>
  187. </tr>
  188. <?php } ?>
  189. </tfoot>
  190. </table>
  191. <?php
  192. }
  193. function csv_cyfrowe($projekty, $grupyKosztow, $costs, $orderby = '') {
  194. echo'<pre style="overflow:auto;border:1px solid red;text-align:left;">';
  195. foreach ($projekty as $projekt) {
  196. $csv_line = array();
  197. $csv_line []= '"' . $projekt->ID . '"';
  198. $csv_line []= '"' . $projekt->M_DIST_DESC . '"';
  199. foreach ($grupyKosztow as $pakiet) {
  200. if (in_array($pakiet->ID, $projekt->pakiety)) {
  201. $csv_line []= '"1"';
  202. } else {
  203. $csv_line []= '"0"';
  204. }
  205. }
  206. echo implode(';', $csv_line) . "\n";
  207. }
  208. echo'</pre>';
  209. }
  210. function getGrupyKosztow() {
  211. $grupyKosztow = array();
  212. $db = DB::getDB();
  213. $sql = "select gc.`ID`
  214. , gc.`POKAZ_NA_WWW`
  215. , gc.`S_OTHER_INFO` as `WWW_NAZWA`
  216. , gc.`WWW_P_SERVICE`
  217. -- , if(gc.`WWW_P_SERVICE`='TVC', 1, 2) as order_by_lp
  218. from `USERS2_OFFERS_COSTS_GROUPS` as gc
  219. where
  220. gc.`A_STATUS` in('NORMAL', 'WAITING')
  221. -- and gc.`POKAZ_NA_WWW`='TAK'
  222. -- order by order_by_lp
  223. order by gc.`ID` DESC
  224. ";
  225. $res = $db->query($sql);
  226. while ($r = $db->fetch($res)) {
  227. $grupyKosztow[$r->ID] = $r;
  228. }
  229. return $grupyKosztow;
  230. }
  231. function getProjekty() {
  232. $db = DB::getDB();
  233. $projekty = array();
  234. $sql = "select c.ID as c_ID
  235. , c.`ID_PROJECT` as c_ID_PROJECT
  236. , p.`ID`
  237. , p.`M_DIST_DESC`
  238. , p.`TV_NAZWA_PROGRAMU`
  239. , p.`TV_LANGUAGE`
  240. , p.`TV_SIGAL_DELIVERY`
  241. , p.`TV_PROGRAM_PROFILE`
  242. , p.`TV_DVBC_EPG_CHANNEL_NUMBER`
  243. , p.`M_DIST_INVENTOR`
  244. -- , CAST(p.`TV_DVBC_EPG_CHANNEL_NUMBER` AS SIGNED) as order_by_lp
  245. , '' as order_by_lp
  246. , GROUP_CONCAT(cg.ID) as cost_group_ids
  247. from `USERS2_OFFERS_COSTS_GROUPS` as cg
  248. left join `USERS2_OFFERS_COSTS` as c on(c.`ID_COSTS_GROUPS`=cg.`ID`)
  249. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p on(p.`ID`=c.`ID_PROJECT`
  250. -- and p.`M_DIST_TYPE`='TV__UMOWA ZAKUPU KANALU'
  251. )
  252. where 1=1
  253. -- and p.`M_DIST_TYPE`='TV__UMOWA ZAKUPU KANALU'
  254. -- and c.`S_OFFER_STATUS`='IN_OFFER'
  255. -- and cg.`ID_MAIN_COSTS_GROUP`=47
  256. and p.`ID` is not NULL
  257. -- and cg.`A_STATUS` in('WAITING', 'NORMAL')
  258. and c.`A_STATUS` in('WAITING', 'NORMAL')
  259. and p.`A_STATUS` in('WAITING', 'NORMAL')
  260. -- and p.`TV_SIGAL_DELIVERY` in ('DVB-SD', 'DVB-HD')
  261. -- and cg.`POKAZ_NA_WWW`='TAK'
  262. group by p.ID
  263. -- order by order_by_lp ASC
  264. order by ID DESC
  265. limit 10000
  266. ";
  267. $res = $db->query($sql);
  268. while ($r = $db->fetch($res)) {
  269. $r->pakiety = explode(',', $r->cost_group_ids);
  270. $projekty[] = $r;
  271. }
  272. return $projekty;
  273. }
  274. function getCosts() {
  275. $db = DB::getDB();
  276. $costs = array();
  277. $sql = "select c.ID as c_ID
  278. , c.`ID_PROJECT` as c_ID_PROJECT
  279. , c.`ID_COSTS_GROUPS`
  280. , c.`COST_ACCOUNTED_ON`
  281. , c.`COST_POWER`
  282. , p.`ID`
  283. , p.`M_DIST_DESC`
  284. from `USERS2_OFFERS_COSTS_GROUPS` as cg
  285. left join `USERS2_OFFERS_COSTS` as c on(c.`ID_COSTS_GROUPS`=cg.`ID`)
  286. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p on(p.`ID`=c.`ID_PROJECT`)
  287. where 1=1
  288. and p.`ID` is not NULL
  289. and c.`A_STATUS` in('WAITING', 'NORMAL')
  290. and p.`A_STATUS` in('WAITING', 'NORMAL')
  291. order by p.`ID` DESC
  292. limit 10000
  293. ";
  294. $res = $db->query($sql);
  295. while ($r = $db->fetch($res)) {
  296. $costs[$r->ID][$r->ID_COSTS_GROUPS] = array('COST'=>$r->COST_POWER, 'TYPE'=>$r->COST_ACCOUNTED_ON);
  297. }
  298. return $costs;
  299. }
  300. function getProgramyAnalogowe() {
  301. $db = DB::getDB();
  302. $programy = array();
  303. $sql = "select c.ID as c_ID
  304. , c.ID_PROJECT as c_ID_PROJECT
  305. , p.ID, p.TV_NAZWA_PROGRAMU, p.TV_LANGUAGE, p.TV_SIGAL_DELIVERY
  306. , p.TV_PROGRAM_PROFILE
  307. -- , p.TV_DVBC_EPG_CHANNEL_NUMBER
  308. , p.M_DIST_INVENTOR
  309. , p.TV_ANALOG_FREQUENCY
  310. , CAST(p.`TV_DVBC_EPG_CHANNEL_NUMBER` AS SIGNED) as order_by_lp
  311. , GROUP_CONCAT(cg.ID) as cost_group_ids
  312. from `USERS2_OFFERS_COSTS_GROUPS` as cg
  313. left join `USERS2_OFFERS_COSTS` as c on(c.`ID_COSTS_GROUPS`=cg.`ID`)
  314. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p on(p.`ID`=c.`ID_PROJECT` and p.`M_DIST_TYPE`='TV__UMOWA ZAKUPU KANALU')
  315. where
  316. p.`M_DIST_TYPE`='TV__UMOWA ZAKUPU KANALU'
  317. and c.`S_OFFER_STATUS`='IN_OFFER'
  318. and cg.`ID`=2
  319. and p.`ID` is not NULL
  320. and cg.`A_STATUS` in('WAITING', 'NORMAL')
  321. and c.`A_STATUS` in('WAITING', 'NORMAL')
  322. and p.`A_STATUS` in('WAITING', 'NORMAL')
  323. and p.`TV_SIGAL_DELIVERY` in ('ANALOG')
  324. -- and cg.`POKAZ_NA_WWW`='TAK'
  325. group by p.ID
  326. order by order_by_lp ASC
  327. limit 1000;
  328. ";
  329. $res = $db->query($sql);
  330. while ($r = $db->fetch($res)) {
  331. $r->pakiety = explode(',', $r->cost_group_ids);
  332. $programy []= $r;
  333. }
  334. return $programy;
  335. }
  336. }