booking_agenda_helper.class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. require_once DOL_DOCUMENT_ROOT . '/custom/eventwizard/class/eventlocation.class.php';
  3. class BookingAgendaHelper
  4. {
  5. public $db;
  6. public function __construct($db)
  7. {
  8. $this->db = $db;
  9. }
  10. function getEventdayDates($year, $month, $day)
  11. {
  12. $dates = [];
  13. $eventday = $year . '-';
  14. $eventday .= (int) $month < 10 ? '0' : '';
  15. $eventday .= $month . '-';
  16. $eventday .= (int) $day < 10 ? '0' : '';
  17. $eventday .= $day;
  18. $eventday = str_replace("-00", "-0", $eventday);
  19. $dates['eventday'] = $eventday;
  20. $dates['eventdayprint'] = date("Y M d", strtotime($eventday));
  21. $dates['from'] = $eventday . ' 00:00:00';
  22. $dates['to'] = $eventday . ' 23:59:59';
  23. return $dates;
  24. }
  25. /* function getMaxNumFromEVENT($eventarray){
  26. foreach($eventarray as $event){
  27. return $event['max_num'];
  28. }
  29. } */
  30. function getsumReservation($eventsArray, $eventday, $hourText)
  31. {
  32. $count = 0;
  33. $actionCommIds = [];
  34. $from = strtotime($eventday . ' ' . $hourText . ':00:00');
  35. $to = strtotime($eventday . ' ' . $hourText . ':59:59');
  36. foreach ($eventsArray as $event) {
  37. $event_from = strtotime($event['datep']);
  38. $event_to = strtotime($event['datep2']);
  39. if (($from <= $event_from && $to >= $event_from) || $from >= $event_from && $to + 1 <= $event_to) {
  40. $count = $count + (int)$event['participants'];
  41. $actionCommIds[] = (int)$event['actioncomm_id'];
  42. }
  43. }
  44. $array['count'] = $count > 0 ? $count : '-';
  45. $array['ids'] = implode(',', $actionCommIds);
  46. return $array;
  47. }
  48. function getsumOccupied($eventsArray, $eventday, $hourText)
  49. {
  50. $count = 0;
  51. $actionCommIds = [];
  52. $from = strtotime($eventday . ' ' . $hourText . ':00:00');
  53. $to = strtotime($eventday . ' ' . $hourText . ':59:59');
  54. foreach ($eventsArray as $event) {
  55. $event_from = strtotime($event['datep']);
  56. $event_to = strtotime($event['datep2']);
  57. if ($from == $event_to) {
  58. $count = $count + (int)$event['participants'];
  59. $actionCommIds[] = (int)$event['actioncomm_id'];
  60. }
  61. if (($from <= $event_from && $to >= $event_from) || $from >= $event_from && $to + 1 <= $event_to) {
  62. $count = $count + (int)$event['participants'];
  63. $actionCommIds[] = (int)$event['actioncomm_id'];
  64. }
  65. }
  66. $array['count'] = $count > 0 ? $count : '-';
  67. $array['ids'] = implode(',', $actionCommIds);
  68. return $array;
  69. }
  70. function getsumService($eventsArray, $eventday, $hourText)
  71. {
  72. $count = 0;
  73. $actionCommIds = [];
  74. $from = strtotime($eventday . ' ' . $hourText . ':00:00');
  75. foreach ($eventsArray as $event) {
  76. $event_to = strtotime($event['datep2']);
  77. if ($from == $event_to) {
  78. $count = $count + (int)$event['participants'];
  79. $actionCommIds[] = (int)$event['actioncomm_id'];
  80. }
  81. }
  82. $array['count'] = $count > 0 ? $count : '-';
  83. $array['ids'] = implode(',', $actionCommIds);
  84. return $array;
  85. }
  86. function getlocations()
  87. {
  88. $locationArray = [];
  89. $eventwizardLocationsObj = new EventLocation($this->db);
  90. $result = $eventwizardLocationsObj->fetchAll('ASC', 'label', 0, 0);
  91. if (count($result) > 0) {
  92. foreach ($result as $location) {
  93. $locationArray[$location->id] = $location->label;
  94. }
  95. }
  96. return $locationArray;
  97. }
  98. function getLocationLabel($event)
  99. {
  100. foreach ($event as $eventDetail) {
  101. return $eventDetail['fk_elventlocation_departure'];
  102. }
  103. }
  104. function getOneColumnFromTable($sql, $array, $column)
  105. {
  106. $eventData = $this->db->query($sql);
  107. if ($this->db->num_rows($eventData) > 0) {
  108. while ($row = $this->db->fetch_object($eventData)) {
  109. $array[$row->fk_elventlocation_departure][$row->$column] = (array) $row;
  110. }
  111. }
  112. return $array;
  113. }
  114. function getBGColor($rowcolorCounter)
  115. {
  116. return $rowcolorCounter % 2 ? 'white' : 'Gainsboro';
  117. }
  118. function getHourText($hour)
  119. {
  120. return $hour < 10 ? '0' . $hour : $hour;
  121. }
  122. private function getActionCommID($event)
  123. {
  124. return array_key_first($event);
  125. }
  126. function showTable($eventdayDates, $selectedEvent)
  127. {
  128. global $langs, $db;
  129. //$this = new this($db);
  130. $k = 0;
  131. $dailyStartTime = 9;
  132. $dailyEndTime = 21;
  133. $eventsArray = [];
  134. $daysql = "SELECT
  135. ed.rowid as eventdetail_id,
  136. ed.label as eventdetail_label,
  137. ac.id as actioncomm_id,
  138. ac.datep,
  139. ac.datep2,
  140. ac.durationp,
  141. ace.buffer,
  142. ace.max_num,
  143. ace.participants,
  144. ed.fk_elventlocation_departure
  145. FROM llx_eventwizard_eventdetails as ed
  146. INNER JOIN llx_actioncomm as ac ON ac.fk_element = ed.rowid
  147. INNER JOIN llx_actioncomm_extrafields as ace ON ace.fk_object = ac.id
  148. WHERE ed.type IN (3,4)
  149. AND ac.code = 'AC_EVENT'
  150. AND ac.datep BETWEEN '{$eventdayDates['from']}' AND '{$eventdayDates['to']}'
  151. AND ace.participants IS NOT NULL
  152. ORDER BY ac.id DESC";
  153. //print $daysql;
  154. $eventsArray = $this->getOneColumnFromTable($daysql, $eventsArray, 'actioncomm_id');
  155. $locationArray = $this->getlocations();
  156. print '<table style="width:100%">';
  157. print '<tr class="firstcolumn">
  158. <td style="width:15%">' . $langs->trans('Location') . '</td>
  159. <td style="width:7%">' . $langs->trans('Status') . '</td>';
  160. for ($i = 9; $i < 21; $i++) {
  161. $hourText = $i < 10 ? '0' . $i : $i;
  162. print '<td>' . $hourText . '</td>';
  163. $k++;
  164. }
  165. $k = $k + 2;
  166. print '<tr class="elvalaszto"><td colspan="' . $k . '"></td></tr>';
  167. print '</tr>';
  168. foreach ($eventsArray as $event) {
  169. print '<tr class="trheight">
  170. <td class="firstcolumn"></td>
  171. <td class="center">' . $langs->trans('Reserved') . '</td>';
  172. $rowcolorCounter = 0;
  173. print '<br>';
  174. for ($i = $dailyStartTime; $i < $dailyEndTime; $i++) {
  175. $backgroundColor = $this->getBGColor($rowcolorCounter);
  176. $hourText = $this->getHourText($i);
  177. $ReservationArray = $this->getsumReservation($event, $eventdayDates['eventday'], $hourText);
  178. $sumNumber = $ReservationArray['count'];
  179. $cursor = $sumNumber > 0 ? 'pointer' : '';
  180. print '<td class="center" style="background-color: ' . $backgroundColor . '; cursor:' . $cursor . ';" onclick="ShoMeTheEventDeatils(\'' . (string)$ReservationArray['ids'] . '\')">' . $sumNumber . '</td>';
  181. $rowcolorCounter++;
  182. }
  183. print '</tr>';
  184. print '<tr class="trheight foglaltsag">
  185. <td class="location firstcolumn">' . $locationArray[$this->getLocationLabel($event)] . '</td>
  186. <td class="center">' . $langs->trans('InUse') . '</td>';
  187. $rowcolorCounter = 0;
  188. for ($i = $dailyStartTime; $i < $dailyEndTime; $i++) {
  189. $backgroundColor = $this->getBGColor($rowcolorCounter);
  190. $hourText = $this->getHourText($i);
  191. $OccupiedArray = $this->getsumOccupied($event, $eventdayDates['eventday'], $hourText);
  192. $sumNumber = $OccupiedArray['count'];
  193. $cursor = $sumNumber > 0 ? 'pointer' : '';
  194. print '<td class="center" style="background-color: ' . $backgroundColor . '; cursor:' . $cursor . ';" onclick="ShoMeTheEventDeatils(\'' . (string)$OccupiedArray['ids'] . '\')">' . $sumNumber . '</td>';
  195. $rowcolorCounter++;
  196. }
  197. print '</tr>';
  198. print '<tr class="trheight">
  199. <td class="firstcolumn"></td>
  200. <td class="center">' . $langs->trans('InService') . '</td>';
  201. $rowcolorCounter = 0;
  202. for ($i = $dailyStartTime; $i < $dailyEndTime; $i++) {
  203. $backgroundColor = $this->getBGColor($rowcolorCounter);
  204. $hourText = $this->getHourText($i);
  205. $ServiceArray = $this->getsumService($event, $eventdayDates['eventday'], $hourText);
  206. $sumNumber = $ServiceArray['count'];
  207. $cursor = $sumNumber > 0 ? 'pointer' : '';
  208. print '<td class="center" style="background-color: ' . $backgroundColor . '; cursor:' . $cursor . ';" onclick="ShoMeTheEventDeatils(\'' . (string)$ServiceArray['ids'] . '\')">' . $sumNumber . '</td>';
  209. $rowcolorCounter++;
  210. }
  211. print '</tr>';
  212. print '<tr class="elvalaszto"><td colspan="' . $k . '"></td></tr>';
  213. }
  214. print '</table>';
  215. }
  216. public function getSelectedEvents($event)
  217. {
  218. global $db;
  219. $eventsArray = explode(',', $event);
  220. $everything = [];
  221. foreach ($eventsArray as $eventdetail) {
  222. $sql = "SELECT ac.id, ac.datep, ac.datep2, ac.durationp, bh.fk_facture, bh.invoice_number
  223. FROM llx_actioncomm as ac
  224. INNER JOIN llx_booking_bookinghistory as bh ON bh.fk_event = ac.id
  225. WHERE ac.id = {$eventdetail} ORDER BY fk_facture DESC";
  226. //print $sql;
  227. //exit;
  228. $result = $db->query($sql);
  229. if ($db->num_rows($result) > 0) {
  230. print '<table><thead><tr class="firstcolumn">
  231. <th>Facture</th>
  232. <th>Time Range</th>
  233. </tr></thead><tbody>';
  234. $rowcolorCounter = 0;
  235. while ($row = $db->fetch_object($result)) {
  236. print '<tr class="center" style="height:60px; background-color: ' . $this->getBGColor($rowcolorCounter) . ';">
  237. <td class="" style="padding:20px;">' . $row->invoice_number . '</td>
  238. <td style="padding:20px;">' . $row->datep . ' - ' . $row->datep2 . '</td>
  239. </tr>';
  240. $rowcolorCounter++;
  241. }
  242. print '</tbody></table>';
  243. }
  244. }
  245. }
  246. }