| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- Lib::loadClass('RouteBase');
- Lib::loadClass('Windykacja_View');
- // Windykacja - oblicz ile odzyskano po kontakcie
- class Route_UrlAction_UserSaldoAfterContact extends RouteBase {
- function defaultAction() { UI::layout([ $this, 'defaultView' ]); }
- function defaultView() {
- $id = V::get('ID', 0, $_GET, 'int');
- if ($id <= 0) throw new Exception("Missing id");
- echo UI::h('h3', [ 'style' => "margin-bottom: 24px; border-bottom: 1px solid #eee" ], "Sprawdź ile idzyskano po kontakcie z klientem");
- $contactInfo = $this->getContactInfo($id);
- if (!$contactInfo) throw new Exception("Rekord o podanym numerze nie istnieje");
- $idUser = $contactInfo['ID_BILLING_USERS'];
- if ($idUser <= 0) throw new Exception("Brak numeru klienta");
- Windykacja_View::viewUserInfo($idUser);
- $postTask = V::get('_postTask', '', $_POST);
- switch ($postTask) {
- case 'saveIleOdzyskano': $this->saveIleOdzyskanoPostTask($id, $contactInfo); break;
- case '': break;
- default: throw new Exception("Not implemented postTask '{$postTask}'");
- }
- $this->viewIleOdzyskanoForm($id);
- echo UI::h('hr');
- Router::getRoute('UrlAction_UserContact')->viewUserPaymentContactsHistory($idUser, [ 'markEventsFromSpotkanieNr' => $id ]);
- }
- function viewIleOdzyskanoForm($id) {
- $contactInfo = $this->getContactInfo($id);
- $idUser = $contactInfo['ID_BILLING_USERS'];
- $listContactAfter = DB::getPDO()->fetchAll("
- select *
- from USERS2_CONTACT
- where ID_BILLING_USERS = :id_user
- and A_RECORD_CREATE_DATE > :contact_date
- and A_STATUS != 'DELETED'
- ", [ ':id_user' => $idUser, ':contact_date' => $contactInfo['A_RECORD_CREATE_DATE'] ]);
- $lastContactId = (!empty($listContactAfter)) ? end($listContactAfter)['ID'] : null;
- $args = [];
- $args['ILE_ODZYSKANO'] = V::get('ILE_ODZYSKANO', $contactInfo['ILE_ODZYSKANO'], $_POST);
- echo UI::h('form', [ 'method' => "POST", 'class' => "form-inline" ], [
- UI::h('input', [ 'type' => "hidden", 'name' => '_postTask', 'value' => "saveIleOdzyskano" ]),
- UI::h('input', [ 'type' => "hidden", 'name' => 'id', 'value' => $id ]),
- UI::h('div', [ 'class' => "row", 'style' => "padding-bottom: 12px" ], [
- UI::h('div', [ 'class' => "col-md-12" ], [
- UI::h('h4', [], "Notatka ze spotkania:"),
- UI::h('div', [ 'style' => "padding-left:32px" ], [
- $this->viewNotatkaRow($contactInfo),
- ]),
- ]),
- ]),
- ($listContactAfter)
- ? UI::h('div', [ 'class' => "row", 'style' => "padding-bottom: 12px" ], [
- UI::h('div', [ 'class' => "col-md-12" ], [
- UI::h('div', [ 'class' => "alert alert-warning" ], [
- "Uwaga: Znaleziono późniejsze notatki z klientem",
- " ",
- UI::h('a', [ 'href' => $this->getLink('', [ 'ID' => $lastContactId ]) ], "przejdź do najnowszego kontaktu"),
- ]),
- UI::h('div', [ 'style' => "padding-left:32px" ], array_map([ $this, 'viewNotatkaRow' ], $listContactAfter)),
- ]),
- ])
- : UI::h('div', [], [
- UI::h('div', [ 'class' => "row", 'style' => "padding-bottom: 12px" ], [
- UI::h('div', [ 'class' => "col-md-12" ], [
- // UI::h('iframe', [
- // 'src' => "https://biuro.biall-net.pl/dev-pl/se-master/index.php?MENU_INIT=USERS2_WINDYKACJA_STATUS&q=&_f=&_user_id={$idUser}",
- // 'style' => "width:100%; height:400px; padding:12px; border:1px solid #ddd; border-radius:8px",
- // ]),
- ]),
- UI::h('div', [ 'class' => "col-md-12" ], [
- UI::h('label', [], "Ile odzyskano:"),
- " ",
- UI::h('input', [ 'class' => "form-control", 'type' => "number", 'min' => "0.00", 'step' => "0.01", 'name' => 'ILE_ODZYSKANO', 'value' => $args['ILE_ODZYSKANO'] ]),
- " ",
- UI::h('button', [ 'class' => "btn btn-primary" ], "Zapisz"),
- ]),
- ]),
- ])
- ,
- ]);
- }
- function viewNotatkaRow($item) {
- return UI::h('div', [ 'style' => "margin-bottom:12px" ], array_merge(
- [
- UI::h('div', [ 'style' => "font-weight:bold" ], "Notatka nr {$item['ID']}"),
- UI::h('div', [ 'style' => "color:#333" ], [
- UI::h('span', [ 'class' => "text-muted" ], "Wykonana przez: "),
- " {$item['L_APPOITMENT_USER']}",
- ]),
- UI::h('div', [ 'style' => "color:#333" ], [
- UI::h('span', [ 'class' => "text-muted" ], "Data: "),
- " {$item['L_APPOITMENT_DATE']}",
- ]),
- UI::h('div', [ 'style' => "color:#333" ], [
- UI::h('span', [ 'class' => "text-muted" ], "Treść: "),
- " {$item['L_APPOITMENT_INFO']}",
- ]),
- ],
- ($item['ILE_ODZYSKANO'] > 0) ? [
- UI::h('div', [ 'style' => "color:#333" ], [
- UI::h('span', [ 'class' => "text-muted" ], "Odzyskano: "),
- " ",
- UI::price($item['ILE_ODZYSKANO']),
- ]),
- ] : []
- ));
- }
- function saveIleOdzyskanoPostTask($id, $contactInfo) {
- $args = [];
- $args['ILE_ODZYSKANO'] = V::get('ILE_ODZYSKANO', 0, $_POST, 'price');
- try {
- if ($contactInfo['ILE_ODZYSKANO'] == $args['ILE_ODZYSKANO']) throw new AlertInfoException("Nie wprowadzono żadnych zmian");
- DB::getPDO()->update('USERS2_CONTACT', 'ID', $id, [
- 'ILE_ODZYSKANO' => $args['ILE_ODZYSKANO'],
- 'A_RECORD_UPDATE_DATE' => "NOW()",
- 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
- ]);
- DB::getPDO()->insert('USERS2_CONTACT_HIST', [
- 'ID_USERS2' => $id,
- 'ILE_ODZYSKANO' => $args['ILE_ODZYSKANO'],
- 'A_RECORD_UPDATE_DATE' => "NOW()",
- 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
- ]);
- } catch (AlertInfoException $e) {
- DBG::log($e);
- UI::alert('info', $e->getMessage());
- return;
- } catch (Exception $e) {
- DBG::log($e);
- UI::alert('danger', $e->getMessage());
- return;
- }
- throw new AlertSuccessException("Wprowadzono zmiany " . UI::h('a', [ 'href' => $this->getLink('', [ 'ID' => $id ]) ], "wróć"));
- }
- function getContactInfo($id) {
- return DB::getPDO()->fetchFirst(" select t.* from USERS2_CONTACT t where t.ID = :id ", [ ':id' => $id ]);
- }
- }
|