superedit-ANALIZA_GRUP_KOSZTOW.php 12 KB

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