| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <?php
- Lib::loadClass('RouteBase');
- Lib::loadClass('ProcesHelper');
- class Route_UrlAction_TVObciazeniaVOD extends RouteBase {
- private $conf = array('ID_LIST_SERVICES' => '12', 'ID_LIST_SES_B_TYPES' => '19', 'TABLE' => 'SES_TV_C');
- public function handleAuth() {
- if (!User::logged()) {
- throw new HttpException('Unauthorized', 401);
- }
- }
- public function addTVObciazenieVODAction($ID_SERVICES, $DESC_TYPE, $DESC, $BRUTTO) {
- if ($DESC_TYPE == 'month') {
- if (!preg_match("/^[[:digit:]]{4}-[[:digit:]]{2}$/",$DESC)) throw new Exception("Błędna data");
- if (strtotime($DESC) > strtotime(date("Y-m"))) throw new Exception("Błędna data");
- $DESC = "w miesiącu " . $DESC;
- } elseif ($DESC_TYPE == 'desc') {
- if ($DESC == '') throw new Exception("Błędny opis");
- $DESC = "- " . $DESC;
- } else throw new Exception("Błąd formularza");
- $DESC = "Opłata za VOD " . $DESC;
- if (!preg_match("/^[[:digit:]]+(\.[[:digit:]]{1,2})?$/",$BRUTTO)) throw new Exception("Błędna kwota");
- if ($BRUTTO == 0) throw new Exception("Błędna kwota");
-
- 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");
- if (!($VAT = DB::getPDO()->fetchValue("select VAT from LIST_SERVICES where ID='{$this->conf['ID_LIST_SERVICES']}'"))) throw new Exception("Błąd danych");
- $sqlObj = new stdClass();
- $sqlObj->ID_SERVICES = $ID_SERVICES;
- $sqlObj->ID_BILLING_USERS = $ID_BILLING_USERS;
- $sqlObj->TYPE = $this->conf['ID_LIST_SES_B_TYPES'];
- $sqlObj->VALUE1 = $DESC;
- $sqlObj->VALUE2 = V::nettoOdBrutto($BRUTTO,$VAT);
- $id = DB::getDB()->ADD_NEW_OBJ($this->conf['TABLE'], $sqlObj);
- return $id>0;
- }
- public function delTVObciazenieVODAction($ID_SERVICES, $ID_SES_TV_C) {
- $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}'");
- if ($result == '') throw new Exception("błąd danych");
- if ($result == 1) throw new Exception("obciążenie zostało już rozliczone");
- DB::getPDO()->query("delete from {$this->conf['TABLE']} where ID='{$ID_SES_TV_C}'");
- return true;
- }
- public function defaultAction() {
- SE_Layout::gora();
- SE_Layout::menu();
- try {
- if (!($ID_SERVICES = V::get('ID_SERVICES',0,$_GET,'int'))) throw new Exception("Błąd parametru");
- $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}'";
- $result = DB::getPDO()->fetchall($query);
- if (!$result) throw new Exception("Błąd danych");
- if (V::get('action','',$_POST) == 'add') {
- try {
- if (($DESC_TYPE = V::get('DESC_TYPE','',$_POST)) == '') throw new Exception("Błąd formularza");
- if ($DESC_TYPE == 'month') $DESC = V::get('MIESIAC','',$_POST);
- elseif ($DESC_TYPE == 'desc') $DESC = htmlspecialchars(V::get('DESC','',$_POST));
- else throw new Exception("Błąd formularza");
- if ($this->addTVObciazenieVODAction($ID_SERVICES, $DESC_TYPE, $DESC, V::get('BRUTTO','',$_POST))) SE_Layout::alert('success','Pomyślnie dodano obiążenie za VOD');
- else SE_Layout::alert('danger','Nie udało się dodać obciążenia za VOD - nie dodano rekordu do SES_TV_C');
- } catch (Exception $e) {
- SE_Layout::alert('danger',"Nie udało się dodać obciążenia za VOD - ".$e->getMessage());
- }
- }
- if ($ID_SES_TV_C_to_delete = V::get('delete',0,$_POST,'int')) {
- try {
- if ($this->delTVObciazenieVODAction($ID_SERVICES, $ID_SES_TV_C_to_delete)) SE_Layout::alert('success','Pomyślnie usunięto obiążenie za VOD');
- } catch (Exception $e) {
- SE_Layout::alert('danger',"Nie udało się usunąć obciążenia za VOD - ".$e->getMessage());
- }
- }
- $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";
- $obciazenia = DB::getPDO()->fetchall($query);
- ?>
- <div class="container" style="margin-top:20px">
- <form class="form-horizontal" method="post">
- <legend>
- Obciążenia za VOD
- <span class="pull-right">
- ID_SERVICES: <?=$ID_SERVICES?>
- </span>
- </legend>
- <div class="form-group">
- <div class="col-sm-12">
- 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/>
- Adres instalacji: <?=$result[0]['S_ADDRESS_STREET']?>
- </div>
- </div>
- <div class="form-group">
- <div class="col-sm-12">
- <h4>Nowe obciążenie:</h4>
- </div>
- </div>
- <div class="form-group">
- <label class="col-sm-offset-3 col-sm-2 control-label">Rok i miesiąc (RRRR-MM)</label>
- <div class="col-sm-2">
- <div class="input-group">
- <input type="text" id="MIESIAC" class="form-control se_type-date" name="MIESIAC" value="<?=date("Y-m")?>" maxlength="7"/>
- <span class="input-group-addon">
- <span class="glyphicon glyphicon-calendar">
- </span>
- </span>
- </div>
- </div>
- <div class="col-sm-1">
- <div class="radio">
- <label>
- <input type="radio" name="DESC_TYPE" value="month" checked>
- </label>
- </div>
- </div>
- </div>
- <div class="form-group">
- <label class="col-sm-offset-3 col-sm-2 control-label">Własny opis</label>
- <div class="col-sm-2">
- <input type="text" id="DESC" class="form-control" name="DESC"/>
- </div>
- <div class="col-sm-1">
- <div class="radio">
- <label>
- <input type="radio" name="DESC_TYPE" value="desc">
- </label>
- </div>
- </div>
- </div>
- <div class="form-group">
- <label class="col-sm-offset-3 col-sm-2 control-label">Kwota brutto</label>
- <div class="col-sm-2">
- <input type="text" id="BRUTTO" class="form-control" name="BRUTTO" value="0.00"/>
- </div>
- <div class="col-sm-1">
- <button type="submit" class="btn btn-primary" name="action" value="add">Dodaj</button>
- </div>
- </div>
- <div class="form-group">
- <div class="col-sm-offset-3 col-sm-6">
- <br/><h4>Dotychczasowe obciążenia za VOD:</h4>
- <table class="table table-bordered table-hover table-striped">
- <thead>
- <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>
- </thead>
- <tbody>
- <?php
- if ($obciazenia) {
- $i = 1;
- foreach ($obciazenia as $x) {
- 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'>";
- if ($x['ROZLICZONE']) echo "Tak";
- else echo "Nie</td><td width=\"1\"><button class=\"btn btn-default btn-xs\" type=\"submit\" name=\"delete\" value=\"{$x['ID']}\">Usuń</button>";
- echo "</td></tr>";
- }
- } else echo '<tr style="text-align:center"><td colspan="4">Brak obciążeń</td></tr>';
- ?>
- </tbody>
- <table>
- </div>
- </div>
- </form>
- </div>
- <script>
- jQuery(document.getElementById('MIESIAC')).parent().datetimepicker({
- format: 'YYYY-MM'
- , locale: 'pl'
- , showTodayButton: false
- , maxDate: '<?=date("Y-m")?>'
- });
- </script>
- <?php
- } catch (Exception $e) {
- SE_Layout::alert('danger',$e->getMessage());
- }
- SE_Layout::dol();
- }
- public function reinstallAction() {
- die('OK');
- }
- }
|