TVObciazeniaVOD.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. Lib::loadClass('ProcesHelper');
  4. class Route_UrlAction_TVObciazeniaVOD extends RouteBase {
  5. private $conf = array('ID_LIST_SERVICES' => '12', 'ID_LIST_SES_B_TYPES' => '19', 'TABLE' => 'SES_TV_C');
  6. public function handleAuth() {
  7. if (!User::logged()) {
  8. throw new HttpException('Unauthorized', 401);
  9. }
  10. }
  11. public function addTVObciazenieVODAction($ID_SERVICES, $DESC_TYPE, $DESC, $BRUTTO) {
  12. if ($DESC_TYPE == 'month') {
  13. if (!preg_match("/^[[:digit:]]{4}-[[:digit:]]{2}$/",$DESC)) throw new Exception("Błędna data");
  14. if (strtotime($DESC) > strtotime(date("Y-m"))) throw new Exception("Błędna data");
  15. $DESC = "w miesiącu " . $DESC;
  16. } elseif ($DESC_TYPE == 'desc') {
  17. if ($DESC == '') throw new Exception("Błędny opis");
  18. $DESC = "- " . $DESC;
  19. } else throw new Exception("Błąd formularza");
  20. $DESC = "Opłata za VOD " . $DESC;
  21. if (!preg_match("/^[[:digit:]]+(\.[[:digit:]]{1,2})?$/",$BRUTTO)) throw new Exception("Błędna kwota");
  22. if ($BRUTTO == 0) throw new Exception("Błędna kwota");
  23. if (!($ID_BILLING_USERS = DB::getPDO()->fetchValue("select ID_BILLING_USERS from SES_TV_A where ID_SERVICES='{$ID_SERVICES}'"))) throw new Exception("Błąd danych");
  24. if (!($VAT = DB::getPDO()->fetchValue("select VAT from LIST_SERVICES where ID='{$this->conf['ID_LIST_SERVICES']}'"))) throw new Exception("Błąd danych");
  25. $sqlObj = new stdClass();
  26. $sqlObj->ID_SERVICES = $ID_SERVICES;
  27. $sqlObj->ID_BILLING_USERS = $ID_BILLING_USERS;
  28. $sqlObj->TYPE = $this->conf['ID_LIST_SES_B_TYPES'];
  29. $sqlObj->VALUE1 = $DESC;
  30. $sqlObj->VALUE2 = V::nettoOdBrutto($BRUTTO,$VAT);
  31. $id = DB::getDB()->ADD_NEW_OBJ($this->conf['TABLE'], $sqlObj);
  32. return $id>0;
  33. }
  34. public function delTVObciazenieVODAction($ID_SERVICES, $ID_SES_TV_C) {
  35. $result = DB::getPDO()->fetchValue("select if (ID_BILLING_NUMBERS is null, '0', '1') from {$this->conf['TABLE']} where ID='{$ID_SES_TV_C}' and ID_SERVICES='{$ID_SERVICES}'");
  36. if ($result == '') throw new Exception("błąd danych");
  37. if ($result == 1) throw new Exception("obciążenie zostało już rozliczone");
  38. DB::getPDO()->query("delete from {$this->conf['TABLE']} where ID='{$ID_SES_TV_C}'");
  39. return true;
  40. }
  41. public function defaultAction() {
  42. SE_Layout::gora();
  43. SE_Layout::menu();
  44. try {
  45. if (!($ID_SERVICES = V::get('ID_SERVICES',0,$_GET,'int'))) throw new Exception("Błąd parametru");
  46. $query = "select c.ID as ID_BILLING_USERS, c.P_NAME, c.P_NAME_SECOND, c.P_ADDRESS_STREET, c.P_ADDRESS_HOUSE, c.P_ADDRESS_HOME, c.P_ADDRESS_POST_CODE, c.P_ADDRESS_CITY, stva.S_ADDRESS_STREET from SES_TV_A stva join COMPANIES c on c.ID=stva.ID_BILLING_USERS where stva.ID_SERVICES='{$ID_SERVICES}'";
  47. $result = DB::getPDO()->fetchall($query);
  48. if (!$result) throw new Exception("Błąd danych");
  49. if (V::get('action','',$_POST) == 'add') {
  50. try {
  51. if (($DESC_TYPE = V::get('DESC_TYPE','',$_POST)) == '') throw new Exception("Błąd formularza");
  52. if ($DESC_TYPE == 'month') $DESC = V::get('MIESIAC','',$_POST);
  53. elseif ($DESC_TYPE == 'desc') $DESC = htmlspecialchars(V::get('DESC','',$_POST));
  54. else throw new Exception("Błąd formularza");
  55. if ($this->addTVObciazenieVODAction($ID_SERVICES, $DESC_TYPE, $DESC, V::get('BRUTTO','',$_POST))) SE_Layout::alert('success','Pomyślnie dodano obiążenie za VOD');
  56. else SE_Layout::alert('danger','Nie udało się dodać obciążenia za VOD - nie dodano rekordu do SES_TV_C');
  57. } catch (Exception $e) {
  58. SE_Layout::alert('danger',"Nie udało się dodać obciążenia za VOD - ".$e->getMessage());
  59. }
  60. }
  61. if ($ID_SES_TV_C_to_delete = V::get('delete',0,$_POST,'int')) {
  62. try {
  63. if ($this->delTVObciazenieVODAction($ID_SERVICES, $ID_SES_TV_C_to_delete)) SE_Layout::alert('success','Pomyślnie usunięto obiążenie za VOD');
  64. } catch (Exception $e) {
  65. SE_Layout::alert('danger',"Nie udało się usunąć obciążenia za VOD - ".$e->getMessage());
  66. }
  67. }
  68. $query = "select t1.ID as ID, t1.VALUE1 as MIESIAC, round(t1.VALUE2*(1+t2.VAT/100),2) as BRUTTO, if (t1.ID_BILLING_NUMBERS is null, '0', '1') as ROZLICZONE from {$this->conf['TABLE']} as t1 join LIST_SERVICES t2 on t2.ID='{$this->conf['ID_LIST_SERVICES']}' where t1.ID_SERVICES='{$ID_SERVICES}' and t1.TYPE='{$this->conf['ID_LIST_SES_B_TYPES']}' order by t1.ID";
  69. $obciazenia = DB::getPDO()->fetchall($query);
  70. ?>
  71. <div class="container" style="margin-top:20px">
  72. <form class="form-horizontal" method="post">
  73. <legend>
  74. Obciążenia za VOD
  75. <span class="pull-right">
  76. ID_SERVICES: <?=$ID_SERVICES?>
  77. </span>
  78. </legend>
  79. <div class="form-group">
  80. <div class="col-sm-12">
  81. Klient: ID <?=$result[0]['ID_BILLING_USERS'].", ".$result[0]['P_NAME']." ".$result[0]['P_NAME_SECOND'].", ul. ".$result[0]['P_ADDRESS_STREET']." ".$result[0]['P_ADDRESS_HOUSE'].($result[0]['P_ADDRESS_HOME']?"/".$result[0]['P_ADDRESS_HOME']:"").", ".$result[0]['P_ADDRESS_POST_CODE']." ".$result[0]['P_ADDRESS_CITY']?><br/>
  82. Adres instalacji: <?=$result[0]['S_ADDRESS_STREET']?>
  83. </div>
  84. </div>
  85. <div class="form-group">
  86. <div class="col-sm-12">
  87. <h4>Nowe obciążenie:</h4>
  88. </div>
  89. </div>
  90. <div class="form-group">
  91. <label class="col-sm-offset-3 col-sm-2 control-label">Rok i miesiąc (RRRR-MM)</label>
  92. <div class="col-sm-2">
  93. <div class="input-group">
  94. <input type="text" id="MIESIAC" class="form-control se_type-date" name="MIESIAC" value="<?=date("Y-m")?>" maxlength="7"/>
  95. <span class="input-group-addon">
  96. <span class="glyphicon glyphicon-calendar">
  97. </span>
  98. </span>
  99. </div>
  100. </div>
  101. <div class="col-sm-1">
  102. <div class="radio">
  103. <label>
  104. <input type="radio" name="DESC_TYPE" value="month" checked>
  105. </label>
  106. </div>
  107. </div>
  108. </div>
  109. <div class="form-group">
  110. <label class="col-sm-offset-3 col-sm-2 control-label">Własny opis</label>
  111. <div class="col-sm-2">
  112. <input type="text" id="DESC" class="form-control" name="DESC"/>
  113. </div>
  114. <div class="col-sm-1">
  115. <div class="radio">
  116. <label>
  117. <input type="radio" name="DESC_TYPE" value="desc">
  118. </label>
  119. </div>
  120. </div>
  121. </div>
  122. <div class="form-group">
  123. <label class="col-sm-offset-3 col-sm-2 control-label">Kwota brutto</label>
  124. <div class="col-sm-2">
  125. <input type="text" id="BRUTTO" class="form-control" name="BRUTTO" value="0.00"/>
  126. </div>
  127. <div class="col-sm-1">
  128. <button type="submit" class="btn btn-primary" name="action" value="add">Dodaj</button>
  129. </div>
  130. </div>
  131. <div class="form-group">
  132. <div class="col-sm-offset-3 col-sm-6">
  133. <br/><h4>Dotychczasowe obciążenia za VOD:</h4>
  134. <table class="table table-bordered table-hover table-striped">
  135. <thead>
  136. <tr style="text-align:center; background-color:lightgray"><td width="1">Lp.</td><td>Tytułem</td><td nowrap>Kwota brutto</td><td>Rozliczone</td></tr>
  137. </thead>
  138. <tbody>
  139. <?php
  140. if ($obciazenia) {
  141. $i = 1;
  142. foreach ($obciazenia as $x) {
  143. echo "<tr><td style='text-align:right'>".$i++."</td><td style='text-align:center'>{$x['MIESIAC']}</td><td style='text-align:right'>{$x['BRUTTO']}</td><td style='text-align:center'>";
  144. if ($x['ROZLICZONE']) echo "Tak";
  145. else echo "Nie</td><td width=\"1\"><button class=\"btn btn-default btn-xs\" type=\"submit\" name=\"delete\" value=\"{$x['ID']}\">Usuń</button>";
  146. echo "</td></tr>";
  147. }
  148. } else echo '<tr style="text-align:center"><td colspan="4">Brak obciążeń</td></tr>';
  149. ?>
  150. </tbody>
  151. <table>
  152. </div>
  153. </div>
  154. </form>
  155. </div>
  156. <script>
  157. jQuery(document.getElementById('MIESIAC')).parent().datetimepicker({
  158. format: 'YYYY-MM'
  159. , locale: 'pl'
  160. , showTodayButton: false
  161. , maxDate: '<?=date("Y-m")?>'
  162. });
  163. </script>
  164. <?php
  165. } catch (Exception $e) {
  166. SE_Layout::alert('danger',$e->getMessage());
  167. }
  168. SE_Layout::dol();
  169. }
  170. public function reinstallAction() {
  171. die('OK');
  172. }
  173. }