UserSaldoAfterContact.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. Lib::loadClass('Windykacja_View');
  4. // Windykacja - oblicz ile odzyskano po kontakcie
  5. class Route_UrlAction_UserSaldoAfterContact extends RouteBase {
  6. function defaultAction() { UI::layout([ $this, 'defaultView' ]); }
  7. function defaultView() {
  8. $id = V::get('ID', 0, $_GET, 'int');
  9. if ($id <= 0) throw new Exception("Missing id");
  10. echo UI::h('h3', [ 'style' => "margin-bottom: 24px; border-bottom: 1px solid #eee" ], "Sprawdź ile idzyskano po kontakcie z klientem");
  11. $contactInfo = $this->getContactInfo($id);
  12. if (!$contactInfo) throw new Exception("Rekord o podanym numerze nie istnieje");
  13. $idUser = $contactInfo['ID_BILLING_USERS'];
  14. if ($idUser <= 0) throw new Exception("Brak numeru klienta");
  15. Windykacja_View::viewUserInfo($idUser);
  16. $postTask = V::get('_postTask', '', $_POST);
  17. switch ($postTask) {
  18. case 'saveIleOdzyskano': $this->saveIleOdzyskanoPostTask($id, $contactInfo); break;
  19. case '': break;
  20. default: throw new Exception("Not implemented postTask '{$postTask}'");
  21. }
  22. $this->viewIleOdzyskanoForm($id);
  23. echo UI::h('hr');
  24. Router::getRoute('UrlAction_UserContact')->viewUserPaymentContactsHistory($idUser, [ 'markEventsFromSpotkanieNr' => $id ]);
  25. }
  26. function viewIleOdzyskanoForm($id) {
  27. $contactInfo = $this->getContactInfo($id);
  28. $idUser = $contactInfo['ID_BILLING_USERS'];
  29. $listContactAfter = DB::getPDO()->fetchAll("
  30. select *
  31. from USERS2_CONTACT
  32. where ID_BILLING_USERS = :id_user
  33. and A_RECORD_CREATE_DATE > :contact_date
  34. and A_STATUS != 'DELETED'
  35. ", [ ':id_user' => $idUser, ':contact_date' => $contactInfo['A_RECORD_CREATE_DATE'] ]);
  36. $lastContactId = (!empty($listContactAfter)) ? end($listContactAfter)['ID'] : null;
  37. $args = [];
  38. $args['ILE_ODZYSKANO'] = V::get('ILE_ODZYSKANO', $contactInfo['ILE_ODZYSKANO'], $_POST);
  39. echo UI::h('form', [ 'method' => "POST", 'class' => "form-inline" ], [
  40. UI::h('input', [ 'type' => "hidden", 'name' => '_postTask', 'value' => "saveIleOdzyskano" ]),
  41. UI::h('input', [ 'type' => "hidden", 'name' => 'id', 'value' => $id ]),
  42. UI::h('div', [ 'class' => "row", 'style' => "padding-bottom: 12px" ], [
  43. UI::h('div', [ 'class' => "col-md-12" ], [
  44. UI::h('h4', [], "Notatka ze spotkania:"),
  45. UI::h('div', [ 'style' => "padding-left:32px" ], [
  46. $this->viewNotatkaRow($contactInfo),
  47. ]),
  48. ]),
  49. ]),
  50. ($listContactAfter)
  51. ? UI::h('div', [ 'class' => "row", 'style' => "padding-bottom: 12px" ], [
  52. UI::h('div', [ 'class' => "col-md-12" ], [
  53. UI::h('div', [ 'class' => "alert alert-warning" ], [
  54. "Uwaga: Znaleziono późniejsze notatki z klientem",
  55. " ",
  56. UI::h('a', [ 'href' => $this->getLink('', [ 'ID' => $lastContactId ]) ], "przejdź do najnowszego kontaktu"),
  57. ]),
  58. UI::h('div', [ 'style' => "padding-left:32px" ], array_map([ $this, 'viewNotatkaRow' ], $listContactAfter)),
  59. ]),
  60. ])
  61. : UI::h('div', [], [
  62. UI::h('div', [ 'class' => "row", 'style' => "padding-bottom: 12px" ], [
  63. UI::h('div', [ 'class' => "col-md-12" ], [
  64. // UI::h('iframe', [
  65. // 'src' => "https://biuro.biall-net.pl/dev-pl/se-master/index.php?MENU_INIT=USERS2_WINDYKACJA_STATUS&q=&_f=&_user_id={$idUser}",
  66. // 'style' => "width:100%; height:400px; padding:12px; border:1px solid #ddd; border-radius:8px",
  67. // ]),
  68. ]),
  69. UI::h('div', [ 'class' => "col-md-12" ], [
  70. UI::h('label', [], "Ile odzyskano:"),
  71. " ",
  72. UI::h('input', [ 'class' => "form-control", 'type' => "number", 'min' => "0.00", 'step' => "0.01", 'name' => 'ILE_ODZYSKANO', 'value' => $args['ILE_ODZYSKANO'] ]),
  73. " ",
  74. UI::h('button', [ 'class' => "btn btn-primary" ], "Zapisz"),
  75. ]),
  76. ]),
  77. ])
  78. ,
  79. ]);
  80. }
  81. function viewNotatkaRow($item) {
  82. return UI::h('div', [ 'style' => "margin-bottom:12px" ], array_merge(
  83. [
  84. UI::h('div', [ 'style' => "font-weight:bold" ], "Notatka nr {$item['ID']}"),
  85. UI::h('div', [ 'style' => "color:#333" ], [
  86. UI::h('span', [ 'class' => "text-muted" ], "Wykonana przez: "),
  87. " {$item['L_APPOITMENT_USER']}",
  88. ]),
  89. UI::h('div', [ 'style' => "color:#333" ], [
  90. UI::h('span', [ 'class' => "text-muted" ], "Data: "),
  91. " {$item['L_APPOITMENT_DATE']}",
  92. ]),
  93. UI::h('div', [ 'style' => "color:#333" ], [
  94. UI::h('span', [ 'class' => "text-muted" ], "Treść: "),
  95. " {$item['L_APPOITMENT_INFO']}",
  96. ]),
  97. ],
  98. ($item['ILE_ODZYSKANO'] > 0) ? [
  99. UI::h('div', [ 'style' => "color:#333" ], [
  100. UI::h('span', [ 'class' => "text-muted" ], "Odzyskano: "),
  101. " ",
  102. UI::price($item['ILE_ODZYSKANO']),
  103. ]),
  104. ] : []
  105. ));
  106. }
  107. function saveIleOdzyskanoPostTask($id, $contactInfo) {
  108. $args = [];
  109. $args['ILE_ODZYSKANO'] = V::get('ILE_ODZYSKANO', 0, $_POST, 'price');
  110. try {
  111. if ($contactInfo['ILE_ODZYSKANO'] == $args['ILE_ODZYSKANO']) throw new AlertInfoException("Nie wprowadzono żadnych zmian");
  112. DB::getPDO()->update('USERS2_CONTACT', 'ID', $id, [
  113. 'ILE_ODZYSKANO' => $args['ILE_ODZYSKANO'],
  114. 'A_RECORD_UPDATE_DATE' => "NOW()",
  115. 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
  116. ]);
  117. DB::getPDO()->insert('USERS2_CONTACT_HIST', [
  118. 'ID_USERS2' => $id,
  119. 'ILE_ODZYSKANO' => $args['ILE_ODZYSKANO'],
  120. 'A_RECORD_UPDATE_DATE' => "NOW()",
  121. 'A_RECORD_UPDATE_AUTHOR' => User::getLogin(),
  122. ]);
  123. } catch (AlertInfoException $e) {
  124. DBG::log($e);
  125. UI::alert('info', $e->getMessage());
  126. return;
  127. } catch (Exception $e) {
  128. DBG::log($e);
  129. UI::alert('danger', $e->getMessage());
  130. return;
  131. }
  132. throw new AlertSuccessException("Wprowadzono zmiany " . UI::h('a', [ 'href' => $this->getLink('', [ 'ID' => $id ]) ], "wróć"));
  133. }
  134. function getContactInfo($id) {
  135. return DB::getPDO()->fetchFirst(" select t.* from USERS2_CONTACT t where t.ID = :id ", [ ':id' => $id ]);
  136. }
  137. }