helper.class.php 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919
  1. <?php
  2. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  3. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  4. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  5. require_once DOL_DOCUMENT_ROOT . '/includes/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Spreadsheet.php';
  6. require_once DOL_DOCUMENT_ROOT . '/includes/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php';
  7. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/usernaplo.class.php';
  8. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/hotel.class.php';
  9. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/group.class.php';
  10. require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/commissionhandler.class.php';
  11. class HelperUserInvoice
  12. {
  13. public $db;
  14. public function __construct(DoliDB $db)
  15. {
  16. $this->db = $db;
  17. $this->userCategoryArray = [1 => "sales / kereskedő", 2 => "office / irodai dolgozó", 3 => "management / vezetőség", 4 => "maintenance / szerelő", 5 => "host(ess) / buszkísérő", 6 => "accounts / elszámolók", 7 => "hotelsales"];
  18. }
  19. /**
  20. * Output the buttons to submit a creation/edit form
  21. *
  22. * @param string $save_label Alternative label for save button
  23. * @param string $cancel_label Alternative label for cancel button
  24. * @param array $morebuttons Add additional buttons between save and cancel
  25. * @param bool $withoutdiv Option to remove enclosing centered div
  26. * @param string $morecss More CSS
  27. * @param string $dol_openinpopup If the button are shown in a context of a page shown inside a popup, we put here the string name of popup.
  28. * @return string Html code with the buttons
  29. */
  30. public function buttonsSaveCancel($save_label = 'Save', $cancel_label = 'Cancel', $cancelURL = '', $morebuttons = array(), $withoutdiv = 0, $morecss = '', $dol_openinpopup = '')
  31. {
  32. global $langs;
  33. $buttons = array();
  34. $save = array(
  35. 'name' => 'save',
  36. 'label_key' => $save_label,
  37. );
  38. if ($save_label == 'Create' || $save_label == 'Add') {
  39. $save['name'] = 'add';
  40. } elseif ($save_label == 'Modify') {
  41. $save['name'] = 'edit';
  42. }
  43. $cancel = array(
  44. 'name' => 'cancel',
  45. 'label_key' => 'Cancel',
  46. );
  47. !empty($save_label) ? $buttons[] = $save : '';
  48. if (!empty($morebuttons)) {
  49. $buttons[] = $morebuttons;
  50. }
  51. //!empty($cancel_label) ? $buttons[] = $cancel : '';
  52. $retstring = $withoutdiv ? '' : '<div class="center">';
  53. foreach ($buttons as $button) {
  54. $addclass = empty($button['addclass']) ? '' : $button['addclass'];
  55. $retstring .= '<input type="submit" class="button button-' . $button['name'] . ($morecss ? ' ' . $morecss : '') . ' ' . $addclass . '" name="' . $button['name'] . '" value="' . dol_escape_htmltag($langs->trans($button['label_key'])) . '">';
  56. }
  57. if ($cancel_label == "Cancel") {
  58. $retstring .= '<a class="button button-' . $cancel['name'] . '" href="' . dol_buildpath($cancelURL, 1) . /*'?restore_lastsearch_values=1' .*/ (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans($cancel['label_key']) . '</a>';
  59. }
  60. $retstring .= $withoutdiv ? '' : '</div>';
  61. if ($dol_openinpopup) {
  62. $retstring .= '<!-- buttons are shown into a $dol_openinpopup=' . $dol_openinpopup . ' context, so we enable the close of dialog on cancel -->' . "\n";
  63. $retstring .= '<script>';
  64. $retstring .= 'jQuery(".button-cancel").click(function(e) {
  65. e.preventDefault(); console.log(\'We click on cancel in iframe popup ' . $dol_openinpopup . '\');
  66. window.parent.jQuery(\'#idfordialog' . $dol_openinpopup . '\').dialog(\'close\');
  67. });';
  68. $retstring .= '</script>';
  69. }
  70. return $retstring;
  71. }
  72. function getAllSales($userObj)
  73. {
  74. $salesUsers = [];
  75. $sql = "SELECT u.rowid, u.lastname, u.firstname, u.login, ue.nickname FROM " . MAIN_DB_PREFIX . "user AS u LEFT JOIN " . MAIN_DB_PREFIX . "user_extrafields AS ue ON u.rowid = ue.fk_object WHERE ue.user_category = '1' ORDER BY u.lastname";
  76. $result = $this->db->query($sql);
  77. while ($row = pg_fetch_assoc($result)) {
  78. $salesUsers[] = $row;
  79. }
  80. return $salesUsers;
  81. }
  82. function getAllSalesWithSQL($sql)
  83. {
  84. $salesUsers = [];
  85. $result = $this->db->query($sql);
  86. if($this->db->num_rows($result) > 0){
  87. while ($row = pg_fetch_assoc($result)) {
  88. $salesUsers[] = $row;
  89. }
  90. }
  91. return $salesUsers;
  92. }
  93. private function getAllPaymenttype($user_id, $db, $payment_type)
  94. {
  95. $sql = "SELECT 'HUF' AS type,
  96. SUM(amount) AS amount
  97. FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
  98. WHERE payment_type = {$payment_type} AND user_id = {$user_id} AND currency = 0";
  99. if ($payment_type != 1) {
  100. $sql .= " AND payed = 1";
  101. }
  102. /* $sql .= "UNION ALL
  103. SELECT 'EUR' AS type,
  104. SUM(amount) AS amount
  105. FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
  106. WHERE payment_type = {$payment_type} AND user_id = {$user_id} AND currency = 1"; */
  107. if ($payment_type != 1) {
  108. $sql .= " AND payed = 1";
  109. }
  110. $resultUserdata = $db->query($sql);
  111. return pg_fetch_all($resultUserdata);
  112. }
  113. function getAllCommissions($user_id, $db)
  114. {
  115. $sql = "SELECT 'HUF' AS type,
  116. SUM(amount) AS amount
  117. FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
  118. WHERE payment_type = 2 AND user_id = {$user_id} AND currency = 0
  119. UNION ALL
  120. SELECT 'EUR' AS type,
  121. SUM(amount) AS amount
  122. FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
  123. WHERE payment_type = 2 AND user_id = {$user_id} AND currency = 1";
  124. $resultUserdata = $db->query($sql);
  125. return pg_fetch_all($resultUserdata);
  126. }
  127. function getAllUnpaidCommissions($user_id, $db)
  128. {
  129. $sql = "SELECT 'HUF' AS type,
  130. SUM(amount) AS amount
  131. FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
  132. WHERE payment_type = 2 AND user_id = {$user_id} AND currency = 0 AND payed=0
  133. UNION ALL
  134. SELECT 'EUR' AS type,
  135. SUM(amount) AS amount
  136. FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
  137. WHERE payment_type = 2 AND user_id = {$user_id} AND currency = 1 AND payed=0";
  138. $resultUserdata = $db->query($sql);
  139. return pg_fetch_all($resultUserdata);
  140. }
  141. function getAllMinusInvoice($user_id, $db)
  142. {
  143. $sql = "SELECT 'HUF' AS type,
  144. SUM(amount) AS amount
  145. FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
  146. WHERE user_id = {$user_id} AND currency = 0 AND payed=0
  147. UNION ALL
  148. SELECT 'EUR' AS type,
  149. SUM(amount) AS amount
  150. FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
  151. WHERE user_id = {$user_id} AND currency = 1 AND payed=0";
  152. $resultUserdata = $db->query($sql);
  153. return pg_fetch_all($resultUserdata);
  154. }
  155. function createArray($daterange)
  156. {
  157. $dates = explode(" - ", $daterange);
  158. $startDate = new DateTime($dates[0]);
  159. $endDate = new DateTime($dates[1]);
  160. $dateArray = array();
  161. $currentDate = clone $startDate;
  162. while ($currentDate <= $endDate) {
  163. $dateArray[] = $currentDate->format('Y-m-d');
  164. $currentDate->modify('+1 day');
  165. }
  166. return $dateArray;
  167. }
  168. function getMonths()
  169. {
  170. global $langs;
  171. if ($langs->shortlang == 'hu') {
  172. return array(
  173. "01" => "Január",
  174. "02" => "Február",
  175. "03" => "Március",
  176. "04" => "Április",
  177. "05" => "Május",
  178. "06" => "Június",
  179. "07" => "Július",
  180. "08" => "Augusztus",
  181. "09" => "Szeptember",
  182. "10" => "Október",
  183. "11" => "November",
  184. "12" => "December"
  185. );
  186. } else {
  187. return array(
  188. "01" => "January",
  189. "02" => "February",
  190. "03" => "March",
  191. "04" => "April",
  192. "05" => "May",
  193. "06" => "June",
  194. "07" => "July",
  195. "08" => "August",
  196. "09" => "September",
  197. "10" => "Octóber",
  198. "11" => "November",
  199. "12" => "December"
  200. );
  201. }
  202. }
  203. function selectedMonths($year, $months, $honapok)
  204. {
  205. $selectedmonths = $year . ' - ';
  206. $count = count($months);
  207. $i = 1;
  208. foreach ($months as $month) {
  209. $selectedmonths .= $honapok[$month];
  210. if ($i < $count)
  211. $selectedmonths .= ', ';
  212. $i++;
  213. }
  214. return $selectedmonths;
  215. }
  216. private function getDateIntervalForExcel($year, $months)
  217. {
  218. $intervalArray = [];
  219. $from = $year . '-' . $months[0];
  220. $to = $year . '-' . end($months);
  221. }
  222. private function createStartDateForQuery($year, $month)
  223. {
  224. return $year . '-' . $month . '-' . '01 00:00:00';
  225. }
  226. private function createEndDateForQuery($year, $month)
  227. {
  228. $lastDayOfTheMonth = $this->getLastDayOfTheMonth($year, $month);
  229. return $year . '-' . $month . '-' . $lastDayOfTheMonth . ' 23:59:59';
  230. }
  231. private function getLastDayOfTheMonth($year, $month)
  232. {
  233. $lastDay = date("t", strtotime("$year-$month-01"));
  234. return $lastDay;
  235. }
  236. function createExcel($year, $months, $honapok)
  237. {
  238. $spreadsheet = new Spreadsheet();
  239. $felirat = $this->selectedMonths($year, $months, $honapok);
  240. $start_date = $this->createStartDateForQuery($year, min($months));
  241. $end_date = $this->createEndDateForQuery($year, max($months));
  242. //$dateInterval = $this->getDateIntervalForExcel($year, $months);
  243. $sql = "SELECT CONCAT(u.lastname, ' ', u.firstname) AS name, u.login, ue.tax_identification_number,
  244. COALESCE(login_count.record_count, 0) AS ledolgozott_napok_szama,
  245. COALESCE(payment_count_huf.total_amount_huf, 0) AS kifizetett_osszeg_huf
  246. /*COALESCE(payment_count_eur.total_amount_eur, 0) AS kifizetett_osszeg_eur*/
  247. FROM " . MAIN_DB_PREFIX . "user AS u
  248. INNER JOIN " . MAIN_DB_PREFIX . "user_extrafields as ue ON ue.fk_object = u.rowid
  249. LEFT JOIN (
  250. SELECT user_id, COUNT(DISTINCT DATE(date_creation)) AS record_count
  251. FROM " . MAIN_DB_PREFIX . "bbus_userloginnaplo
  252. WHERE date_creation BETWEEN '{$start_date}' AND '{$end_date}'
  253. GROUP By user_id
  254. ) AS login_count ON u.rowid = login_count.user_id
  255. LEFT JOIN (
  256. SELECT user_id, SUM(amount) AS total_amount_huf
  257. FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
  258. WHERE payment_type = 2 AND payed = 1 AND currency = 0 AND paymentdate BETWEEN '{$start_date}' AND '{$end_date}'
  259. GROUP BY user_id
  260. ) AS payment_count_huf ON u.rowid = payment_count_huf.user_id
  261. /*LEFT JOIN (
  262. SELECT user_id, SUM(amount) AS total_amount_eur
  263. FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
  264. WHERE payment_type = 2 AND payed = 1 AND currency = 1 AND paymentdate BETWEEN '{$start_date}' AND '{$end_date}'
  265. GROUP BY user_id
  266. ) AS payment_count_eur ON u.rowid = payment_count_eur.user_id*/
  267. WHERE ue.user_category = '1'
  268. ORDER BY name ASC;
  269. ";
  270. $resultUserdata = $this->db->query($sql);
  271. $allUsers = pg_fetch_all($resultUserdata);
  272. $sheet = $spreadsheet->getActiveSheet();
  273. $sheet->setTitle("{$felirat}");
  274. $sheet->setCellValue("A1", "Felhasználó");
  275. $sheet->setCellValue("B1", "Login");
  276. $sheet->setCellValue("C1", "Adóazonosító jel");
  277. $sheet->setCellValue("D1", "Ledolgozott napok száma");
  278. $sheet->setCellValue("E1", "Kifizetett jutalék HUF");
  279. /*$sheet->setCellValue("F1", "Kifizetett jutalék EUR");*/
  280. $i = 2;
  281. foreach ($allUsers as $user) {
  282. $sheet->setCellValue("A" . $i, $user['name']);
  283. $sheet->setCellValue("B" . $i, $user['login']);
  284. $sheet->setCellValue("C" . $i, $user['tax_identification_number']);
  285. $sheet->setCellValue("D" . $i, $user['ledolgozott_napok_szama']);
  286. $sheet->setCellValue("E" . $i, $user['kifizetett_osszeg_huf'] . ' HUF');
  287. /*$sheet->setCellValue("F" . $i, $user['kifizetett_osszeg_eur'] . ' EUR');*/
  288. $i++;
  289. }
  290. //$sheet->setCellValue("A1", "Hello World!");
  291. //$sheet->setCellValue("A1", "Hello World!");
  292. //$sheet->setCellValue("A2", "Goodbye World!");
  293. // (D) ADD NEW WORKSHEET + YOU CAN ALSO USE FORMULAS!
  294. /* $spreadsheet->createSheet();
  295. $sheet = $spreadsheet->getSheet(1);
  296. $sheet->setTitle("Formula");
  297. $sheet->setCellValue("A1", "5");
  298. $sheet->setCellValue("A2", "6");
  299. $sheet->setCellValue("A3", "=SUM(A1:A2)"); */
  300. $date = date('d-m-y-' . substr((string) microtime(), 1, 8));
  301. $date = str_replace(".", "", $date);
  302. $filename = "export_" . $date . ".xlsx";
  303. try {
  304. $writer = new Xlsx($spreadsheet);
  305. $writer->save($filename);
  306. $content = file_get_contents($filename);
  307. } catch (Exception $e) {
  308. exit($e->getMessage());
  309. }
  310. header("Content-Disposition: attachment; filename=" . $filename);
  311. unlink($filename);
  312. exit($content);
  313. }
  314. function createExcelInterval($daterange)
  315. {
  316. $spreadsheet = new Spreadsheet();
  317. $felirat = $daterange;
  318. $rangeArray = explode(' - ', $daterange);
  319. $start_date = $rangeArray[0] . ' 00:00:00';
  320. $end_date = $rangeArray[1] . ' 23:59:59';
  321. //$dateInterval = $this->getDateIntervalForExcel($year, $months);
  322. $sql = "SELECT CONCAT(u.lastname, ' ', u.firstname) AS name, u.login, ue.tax_identification_number,
  323. COALESCE(login_count.record_count, 0) AS ledolgozott_napok_szama,
  324. COALESCE(payment_count_huf.total_amount_huf, 0) AS kifizetett_osszeg_huf
  325. /*COALESCE(payment_count_eur.total_amount_eur, 0) AS kifizetett_osszeg_eur*/
  326. FROM " . MAIN_DB_PREFIX . "user AS u
  327. INNER JOIN " . MAIN_DB_PREFIX . "user_extrafields as ue ON ue.fk_object = u.rowid
  328. LEFT JOIN (
  329. SELECT user_id, COUNT(DISTINCT DATE(date_creation)) AS record_count
  330. FROM " . MAIN_DB_PREFIX . "bbus_userloginnaplo
  331. WHERE date_creation BETWEEN '{$start_date}' AND '{$end_date}'
  332. GROUP By user_id
  333. ) AS login_count ON u.rowid = login_count.user_id
  334. LEFT JOIN (
  335. SELECT user_id, SUM(amount) AS total_amount_huf
  336. FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
  337. WHERE payment_type = 2 AND payed = 1 AND currency = 0 AND paymentdate BETWEEN '{$start_date}' AND '{$end_date}'
  338. GROUP BY user_id
  339. ) AS payment_count_huf ON u.rowid = payment_count_huf.user_id
  340. /*LEFT JOIN (
  341. SELECT user_id, SUM(amount) AS total_amount_eur
  342. FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
  343. WHERE payment_type = 2 AND payed = 1 AND currency = 1 AND paymentdate BETWEEN '{$start_date}' AND '{$end_date}'
  344. GROUP BY user_id
  345. ) AS payment_count_eur ON u.rowid = payment_count_eur.user_id*/
  346. WHERE ue.user_category = '1'
  347. ORDER BY name ASC;
  348. ";
  349. $resultUserdata = $this->db->query($sql);
  350. $allUsers = pg_fetch_all($resultUserdata);
  351. $sheet = $spreadsheet->getActiveSheet();
  352. $sheet->setTitle("{$felirat}");
  353. $sheet->setCellValue("A1", "Felhasználó");
  354. $sheet->setCellValue("B1", "Login");
  355. $sheet->setCellValue("C1", "Adóazonosító jel");
  356. $sheet->setCellValue("D1", "Ledolgozott napok száma");
  357. $sheet->setCellValue("E1", "Kifizetett jutalék HUF");
  358. //$sheet->setCellValue("F1", "Kifizetett jutalék EUR");
  359. $i = 2;
  360. foreach ($allUsers as $user) {
  361. $sheet->setCellValue("A" . $i, $user['name']);
  362. $sheet->setCellValue("B" . $i, $user['login']);
  363. $sheet->setCellValue("C" . $i, $user['tax_identification_number']);
  364. $sheet->setCellValue("D" . $i, $user['ledolgozott_napok_szama']);
  365. $sheet->setCellValue("E" . $i, $user['kifizetett_osszeg_huf'] . ' HUF');
  366. // $sheet->setCellValue("F" . $i, $user['kifizetett_osszeg_eur'] . ' EUR');
  367. $i++;
  368. }
  369. //$sheet->setCellValue("A1", "Hello World!");
  370. //$sheet->setCellValue("A1", "Hello World!");
  371. //$sheet->setCellValue("A2", "Goodbye World!");
  372. // (D) ADD NEW WORKSHEET + YOU CAN ALSO USE FORMULAS!
  373. /* $spreadsheet->createSheet();
  374. $sheet = $spreadsheet->getSheet(1);
  375. $sheet->setTitle("Formula");
  376. $sheet->setCellValue("A1", "5");
  377. $sheet->setCellValue("A2", "6");
  378. $sheet->setCellValue("A3", "=SUM(A1:A2)"); */
  379. $date = date('d-m-y-' . substr((string) microtime(), 1, 8));
  380. $date = str_replace(".", "", $date);
  381. $filename = "export_" . $date . ".xlsx";
  382. try {
  383. $writer = new Xlsx($spreadsheet);
  384. $writer->save($filename);
  385. $content = file_get_contents($filename);
  386. } catch (Exception $e) {
  387. exit($e->getMessage());
  388. }
  389. header("Content-Disposition: attachment; filename=" . $filename);
  390. unlink($filename);
  391. exit($content);
  392. }
  393. function createExcelHotelReport($daterange, $id, $entity, $groups)
  394. {
  395. $spreadsheet = new Spreadsheet();
  396. $usersList = $this->getUsersOfHotelGroup($id, $daterange, $entity);
  397. $felirat = $daterange;
  398. $usersIdList = $this->getUsersIdList($id, $daterange, $entity);
  399. $amountHUF = $this->getAllAmountInPeriod($id, $daterange, 'HUF', $usersIdList, $entity);
  400. $amountEUR = $this->getAllAmountInPeriod($id, $daterange, 'EUR', $usersIdList, $entity);
  401. $commissionHUF = $this->getAllCommissionInPeriod($id, $daterange, 'HUF', $usersIdList, $entity);
  402. $commissionEUR = $this->getAllCommissionInPeriod($id, $daterange, 'EUR', $usersIdList, $entity);
  403. $hotelsArray = $this->getAllHotels();
  404. $hotelName = $hotelsArray[$groups[$id]['fk_hotel_id']];
  405. $style = [
  406. 'alignment' => [
  407. 'horizontal' => Alignment::HORIZONTAL_CENTER, // Vízszintes középre igazítás
  408. 'vertical' => Alignment::VERTICAL_CENTER, // Függőleges középre igazítás
  409. ],
  410. ];
  411. $styleBold = [
  412. 'font' => [
  413. 'bold' => true,
  414. ],
  415. ];
  416. $sheet = $spreadsheet->getActiveSheet();
  417. $sheet->getStyle('A1')->applyFromArray($styleBold);
  418. $sheet->getStyle('A3:B3')->applyFromArray($styleBold);
  419. $sheet->getStyle('A7')->applyFromArray($styleBold);
  420. $sheet->getStyle('A9:D9')->applyFromArray($styleBold);
  421. $sheet->getStyle('A1:D9')->applyFromArray($style);
  422. $sheet->setTitle("{$felirat}");
  423. $sheet->getColumnDimension('A')->setWidth(25);
  424. $sheet->getColumnDimension('B')->setWidth(25);
  425. $sheet->getColumnDimension('C')->setWidth(25);
  426. $sheet->getColumnDimension('D')->setWidth(25);
  427. $sheet->setCellValue("A1", strtoupper($hotelName));
  428. $sheet->mergeCells("A1:B1");
  429. $sheet->setCellValue("A2", $daterange);
  430. $sheet->mergeCells("A2:B2");
  431. $sheet->setCellValue("A3", "INCOMES");
  432. $sheet->setCellValue("B3", "COMMISSIONS");
  433. $sheet->setCellValue("A4", $this->correctNumber($amountHUF) . ' HUF');
  434. $sheet->setCellValue("B4", $this->correctNumber($commissionHUF) . ' HUF');
  435. $sheet->setCellValue("A5", $this->correctNumber($amountEUR) . ' EUR');
  436. $sheet->setCellValue("B5", $this->correctNumber($commissionEUR) . ' EUR');
  437. $sheet->setCellValue("A6", "");
  438. $sheet->setCellValue("B6", "");
  439. $sheet->setCellValue("A7", strtoupper($hotelName));
  440. $sheet->mergeCells("A7:D7");
  441. $sheet->setCellValue("A8", $daterange);
  442. $sheet->mergeCells("A8:D8");
  443. $sheet->setCellValue("A9", "USER");
  444. $sheet->setCellValue("B9", "GROUP");
  445. $sheet->setCellValue("C9", "AMOUNT OF SALES");
  446. $sheet->setCellValue("D9", "AMOUNT OF SALES");
  447. $i = 10;
  448. foreach ($usersList as $userVal) {
  449. $sheet->setCellValue("A" . $i, $userVal['firstname'] . ' ' . $userVal['lastname']);
  450. $sheet->setCellValue("B" . $i, ' (' . $this->userCategoryArray[$userVal['user_category']] . ')');
  451. $sheet->setCellValue("C" . $i, $this->correctNumber($this->getAllAmountInPeriod($id, $daterange, 'HUF', $userVal['rowid'], $entity)) . ' HUF');
  452. $sheet->setCellValue("D" . $i, $this->correctNumber($this->getAllAmountInPeriod($id, $daterange, 'EUR', $userVal['rowid'], $entity)) . ' EUR');
  453. $i++;
  454. }
  455. $sheet->getStyle('C10:C' . $i)->applyFromArray($style);
  456. $sheet->getStyle('D10:D' . $i)->applyFromArray($style);
  457. //$sheet->setCellValue("A1", "Hello World!");
  458. //$sheet->setCellValue("A1", "Hello World!");
  459. //$sheet->setCellValue("A2", "Goodbye World!");
  460. // (D) ADD NEW WORKSHEET + YOU CAN ALSO USE FORMULAS!
  461. /* $spreadsheet->createSheet();
  462. $sheet = $spreadsheet->getSheet(1);
  463. $sheet->setTitle("Formula");
  464. $sheet->setCellValue("A1", "5");
  465. $sheet->setCellValue("A2", "6");
  466. $sheet->setCellValue("A3", "=SUM(A1:A2)"); */
  467. $date = date('d-m-y-' . substr((string) microtime(), 1, 8));
  468. $date = str_replace(".", "", $date);
  469. $filename = "hotelexport_" . $hotelName . '_' . $date . ".xlsx";
  470. try {
  471. $writer = new Xlsx($spreadsheet);
  472. $writer->save($filename);
  473. $content = file_get_contents($filename);
  474. } catch (Exception $e) {
  475. exit($e->getMessage());
  476. }
  477. header("Content-Disposition: attachment; filename=" . $filename);
  478. unlink($filename);
  479. exit($content);
  480. }
  481. function createExcelMonthlyExport($daterange, $entity, $saledTickets)
  482. {
  483. $spreadsheet = new Spreadsheet();
  484. $felirat = $daterange;
  485. $entities = $this->getAllEntities();
  486. $entityName = str_replace(" ", "_", $entities[$entity]);
  487. $entityName = str_replace(".", "_", $entityName);
  488. $style = [
  489. 'alignment' => [
  490. 'horizontal' => Alignment::HORIZONTAL_CENTER, // Vízszintes középre igazítás
  491. 'vertical' => Alignment::VERTICAL_CENTER, // Függőleges középre igazítás
  492. ],
  493. ];
  494. $styleBold = [
  495. 'font' => [
  496. 'bold' => true,
  497. ],
  498. ];
  499. $sheet = $spreadsheet->getActiveSheet();
  500. $sheet->getStyle('A1')->applyFromArray($styleBold);
  501. $sheet->getStyle('A3:P3')->applyFromArray($styleBold);
  502. //$sheet->getStyle('A7')->applyFromArray($styleBold);
  503. //$sheet->getStyle('A9:D9')->applyFromArray($styleBold);
  504. //$sheet->getStyle('A1:D9')->applyFromArray($style);
  505. $sheet->setTitle("{$felirat}");
  506. $sheet->getColumnDimension('A')->setWidth(20);
  507. $sheet->getColumnDimension('B')->setWidth(20);
  508. $sheet->getColumnDimension('C')->setWidth(20);
  509. $sheet->getColumnDimension('D')->setWidth(20);
  510. $sheet->getColumnDimension('E')->setWidth(20);
  511. $sheet->getColumnDimension('F')->setWidth(20);
  512. $sheet->getColumnDimension('G')->setWidth(15);
  513. $sheet->getColumnDimension('H')->setWidth(15);
  514. $sheet->getColumnDimension('I')->setWidth(15);
  515. $sheet->getColumnDimension('J')->setWidth(15);
  516. $sheet->getColumnDimension('K')->setWidth(15);
  517. $sheet->getColumnDimension('L')->setWidth(15);
  518. $sheet->getColumnDimension('M')->setWidth(10);
  519. $sheet->getColumnDimension('N')->setWidth(15);
  520. $sheet->getColumnDimension('O')->setWidth(10);
  521. $sheet->getColumnDimension('P')->setWidth(10);
  522. $sheet->setCellValue("A1", strtoupper($entities[$entity]));
  523. $sheet->mergeCells("A1:B1");
  524. $sheet->setCellValue("A2", $daterange);
  525. $sheet->mergeCells("A2:B2");
  526. $sheet->setCellValue("A3", "Facture");
  527. $sheet->setCellValue("B3", "Type");
  528. $sheet->setCellValue("C3", "Environment");
  529. $sheet->setCellValue("D3", "VATnumber");
  530. $sheet->setCellValue("E3", "Creation date");
  531. $sheet->setCellValue("F3", "Completion date");
  532. $sheet->setCellValue("G3", "Payment deadline");
  533. $sheet->setCellValue("H3", "Net");
  534. $sheet->setCellValue("I3", "VAT");
  535. $sheet->setCellValue("J3", "Gross");
  536. $sheet->setCellValue("K3", "Net");
  537. $sheet->setCellValue("L3", "VAT");
  538. $sheet->setCellValue("M3", "Gross");
  539. $sheet->setCellValue("N3", "Currency");
  540. $sheet->setCellValue("O3", "PaymentMethod");
  541. $sheet->setCellValue("P3", "VAT %");
  542. $i = 4;
  543. foreach ($saledTickets as $item) {
  544. $mtht = $item->multicurrency_total_ht == $item->total_ht ? '' : number_format($item->multicurrency_total_ht, 4, ',', ' ');
  545. $mttva = $item->multicurrency_total_tva == $item->total_tva ? '' : number_format($item->multicurrency_total_ht, 4, ',', ' ');
  546. $mtttc = $item->multicurrency_total_ttc == $item->total_ttc ? '' : number_format($item->multicurrency_total_ttc, 4, ',', ' ');
  547. $sheet->setCellValue("A" . $i, $item->ref);
  548. $sheet->setCellValue("B" . $i, $this->getFectureType($item->type));
  549. $sheet->setCellValue("C" . $i, $item->label);
  550. $sheet->setCellValue("D" . $i, $item->value);
  551. $sheet->setCellValue("E" . $i, $item->datef);
  552. $sheet->setCellValue("F" . $i, $item->date_lim_reglement);
  553. $sheet->setCellValue("G" . $i, $item->datef);
  554. $sheet->setCellValue("H" . $i, number_format($item->total_ht, 4, ',', ' '));
  555. $sheet->setCellValue("I" . $i, number_format($item->total_tva, 4, ',', ' '));
  556. $sheet->setCellValue("J" . $i, number_format($item->total_ttc, 4, ',', ' '));
  557. $sheet->setCellValue("K" . $i, $mtht);
  558. $sheet->setCellValue("L" . $i, $mttva);
  559. $sheet->setCellValue("M" . $i, $mtttc);
  560. $sheet->setCellValue("N" . $i, $item->multicurrency_code);
  561. $sheet->setCellValue("O" . $i, $item->libelle);
  562. $sheet->setCellValue("P" . $i, number_format($item->tva_tx, 0) . ' %');
  563. $i++;
  564. }
  565. ## file name
  566. $date = date('d-m-y-' . substr((string) microtime(), 1, 8));
  567. $date = str_replace(".", "", $date);
  568. $filename = "monthlyexport_" . $entityName . '_' . $date . ".xlsx";
  569. try {
  570. $writer = new Xlsx($spreadsheet);
  571. $writer->save($filename);
  572. $content = file_get_contents($filename);
  573. } catch (Exception $e) {
  574. exit($e->getMessage());
  575. }
  576. header("Content-Disposition: attachment; filename=" . $filename);
  577. unlink($filename);
  578. exit($content);
  579. }
  580. function getTypeOfPayment($payment_type)
  581. {
  582. switch ($payment_type) {
  583. case '0':
  584. return 'prepay';
  585. case '1':
  586. return 'withhold';
  587. case '2':
  588. return 'commission';
  589. default:
  590. return 'prepay';
  591. }
  592. }
  593. function getFectureType($type)
  594. {
  595. global $langs;
  596. switch ($type) {
  597. case '0':
  598. return $langs->trans("Invoice");
  599. case '2':
  600. return $langs->trans("CreditNote");
  601. case '7':
  602. return $langs->trans("Receipt");
  603. case '8':
  604. return $langs->trans("ReceiptCreditNote");
  605. }
  606. }
  607. function getTitle($payment_type)
  608. {
  609. global $langs;
  610. switch ($payment_type) {
  611. case '0':
  612. return $langs->trans("UserInvoices");
  613. case '1':
  614. return $langs->trans("Withhold");
  615. case '2':
  616. return $langs->trans("Commissionpaidamount");
  617. default:
  618. return $langs->trans("UserInvoices");
  619. }
  620. }
  621. function getViewTplTitle($payment_type)
  622. {
  623. global $langs;
  624. switch ($payment_type) {
  625. case '0':
  626. return $langs->trans("Deposit");
  627. case '1':
  628. return $langs->trans("WithheldAmount");
  629. case '2':
  630. return $langs->trans("Commissionpaidamount");
  631. default:
  632. return $langs->trans("Deposit");
  633. }
  634. }
  635. function backPageSelector($payment_type)
  636. {
  637. switch ($payment_type) {
  638. case '0':
  639. return 'prepaymentsindex';
  640. case '1':
  641. return 'withholdingindex';
  642. case '2':
  643. return 'commissionindex';
  644. default:
  645. return 'prepaymentsindex';
  646. }
  647. }
  648. function createHTML($id)
  649. {
  650. $currencies = ['0' => 'HUF', '1' => 'EUR'];
  651. $sql = "SELECT user1.lastname as creatorlastname, user1.firstname as creatorfirstname, user1.login as creatorlogin, user2.lastname as lastname, user2.firstname as firstname, user2.login as userlogin, ui.amount, ui.currency, ui.paymentdate FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice as ui
  652. INNER JOIN " . MAIN_DB_PREFIX . "user AS user1 ON user1.rowid = ui.fk_user_creat
  653. INNER JOIN " . MAIN_DB_PREFIX . "user AS user2 ON user2.rowid = ui.user_id
  654. WHERE ui.rowid={$id}";
  655. //print $sql;
  656. $resultUserdata = $this->db->query($sql);
  657. $UserInvoice = pg_fetch_assoc($resultUserdata);
  658. $result = '<table style="width:100%"><tr><td><b>Átadó adatai <br>Donor / Giver user data</b></td><td style="text-align: right;"><b>Átvevő adatai <br>Receiving user data</b></td></tr>';
  659. $result .= '<div>&nbsp;</div>';
  660. $result .= '<tr><td>' . $UserInvoice['creatorlastname'] . ' ' . $UserInvoice['creatorfirstname'] . ' - ' . $UserInvoice['creatorlogin'] . '</td><td style="text-align: right;">' . $UserInvoice['lastname'] . ' ' . $UserInvoice['firstname'] . ' - ' . $UserInvoice['userlogin'] . '</td></tr></table>';
  661. $result .= '<div style="padding-top: 100px;">&nbsp;</div>';
  662. $result .= '<table style="width:100%">';
  663. $result .= '<tr><td style="width:75%">Jutalék összege / Amount of commission: </td><td style="text-align: right; width:20%;">' . number_format($UserInvoice['amount'], 0, '.', ' ') . '</td></tr>';
  664. $result .= '<tr><td style="width:75%">Jutalék pénznem / Amount of currency: </td><td style="text-align: right; width:20%;">' . $currencies[$UserInvoice['currency']] . '</td></tr>';
  665. $result .= '</table>';
  666. $result .= '<div style="padding-top: 100px;">&nbsp;</div>';
  667. $result .= '<div style="width:100%; text-align: left;">Budapest, Bajcsy-Zsilinszky út 17, 1065</div>';
  668. $result .= '<div style="width:100%; text-align: left;">' . $UserInvoice['paymentdate'] . '</div>';
  669. $result .= '<div style="padding-top: 100px;">&nbsp;</div>';
  670. $result .= '<table style="width:100%; text-align:right;">';
  671. $result .= '</table>';
  672. $result .=
  673. '<table style="width:100%">
  674. <tr>
  675. <td>_________________________________</td>
  676. <td>_________________________________</td>
  677. </tr>
  678. <tr>
  679. <td style="text-align: center;">Átadó aláírása <br> (Donor / Giver)</td>
  680. <td style="text-align: center;">Átvevő aláírása <br> (Recipient / Receiver)</td>
  681. </tr>
  682. </table>';
  683. return $result;
  684. }
  685. function createHTMLForSettlement($dataArray)
  686. {
  687. $result = '
  688. <table style="width:100%; text-align: center;">
  689. <tr style="font-weight: bold;">
  690. <td>Jutalék / Commisson</td>
  691. </tr>
  692. <tr><td>&nbsp;</td></tr>
  693. <tr style="background-color:lightgrey; font-weight: bold;">
  694. <td>Name of group</td>
  695. </tr>
  696. <tr>
  697. <td>' . $dataArray['GroupName'] . '</td>
  698. </tr>
  699. <tr><td>&nbsp;</td></tr>
  700. <tr style="background-color:lightgrey; font-weight: bold;">
  701. <td>Interval</td>
  702. </tr>
  703. <tr>
  704. <td>' . $dataArray['Interval'] . '</td>
  705. </tr>
  706. <tr><td>&nbsp;</td></tr>
  707. <tr style="background-color:lightgrey; font-weight: bold;">
  708. <td>Total amount</td>
  709. </tr>
  710. <tr>
  711. <td>' . $dataArray['FullAmount'] . ' HUF</td>
  712. </tr>
  713. <tr><td>&nbsp;</td></tr>
  714. <tr style="background-color:lightgrey; font-weight: bold;">
  715. <td>Data of Users</td>
  716. </tr>
  717. </table>';
  718. $result .= '
  719. <table>';
  720. foreach ($dataArray['UsersData'] as $userdata) {
  721. $result .= '<tr><td style="font-weight: bold;">User: </td><td style="font-style: italic;">' . $userdata['namedata'] . '</td></tr>';
  722. $result .= '<tr><td style="font-weight: bold;">Amount: </td><td style="font-style: italic;">' . $userdata['amount'] . ' HUF</td></tr>';
  723. //$result .= '<tr><td style="font-weight: bold;">Invoices: </td><td style="font-style: italic;">' . $userdata['invoices'] . '</td></tr>';
  724. $result .= '<tr><td>&nbsp;</td><td>&nbsp;</td></tr>';
  725. }
  726. $result .= '</table>';
  727. return $result;
  728. }
  729. function checkinterval($db)
  730. {
  731. $id = GETPOST('id', 'int');
  732. $interval_startyear = GETPOST('interval_startyear', 'int');
  733. $interval_startmonth = GETPOST('interval_startmonth', 'int');
  734. $interval_startday = GETPOST('interval_startday', 'int');
  735. $interval_starthour = GETPOST('interval_starthour', 'int');
  736. $interval_startmin = GETPOST('interval_startmin', 'int');
  737. $interval_startsec = GETPOST('interval_startsec', 'int');
  738. $interval_endyear = GETPOST('interval_endyear', 'int');
  739. $interval_endmonth = GETPOST('interval_endmonth', 'int');
  740. $interval_endday = GETPOST('interval_endday', 'int');
  741. $interval_endhour = GETPOST('interval_endhour', 'int');
  742. $interval_endmin = GETPOST('interval_endmin', 'int');
  743. $startdate = $interval_startyear . '-' . $interval_startmonth . '-' . $interval_startday . ' ' . $interval_starthour . ':' . $interval_startmin . ':' . $interval_startsec;
  744. $enddate = $interval_endyear . '-' . $interval_endmonth . '-' . $interval_endday . ' ' . $interval_endhour . ':' . $interval_endmin . ':59';
  745. if ($id) {
  746. $sql = "SELECT *
  747. FROM " . MAIN_DB_PREFIX . "financialreport_commissioninterval
  748. WHERE rowid <> {$id}
  749. AND '{$startdate}' BETWEEN interval_start AND interval_end
  750. OR rowid <> {$id} AND '{$enddate}' BETWEEN interval_start AND interval_end
  751. ";
  752. $result = $db->query($sql);
  753. return $db->num_rows($result) != 0;
  754. } else {
  755. $sql = "SELECT *
  756. FROM " . MAIN_DB_PREFIX . "financialreport_commissioninterval
  757. WHERE
  758. '{$startdate}' BETWEEN interval_start AND interval_end
  759. OR '{$enddate}' BETWEEN interval_start AND interval_end
  760. ";
  761. $result = $db->query($sql);
  762. if ($result) {
  763. return $db->num_rows($result) != 0;
  764. } else {
  765. return false;
  766. }
  767. }
  768. }
  769. public function getEntities($entitiesArrayIsEmpty = false, $entities, $entitiesArray)
  770. {
  771. if ($entitiesArrayIsEmpty) {
  772. $array = [];
  773. foreach ($entities as $key => $value) {
  774. $array[] = $key;
  775. }
  776. $selectedEntities = implode(', ', $array);
  777. } else {
  778. $array = [];
  779. foreach ($entitiesArray as $entity) {
  780. if ($entity)
  781. $array[] = $entity;
  782. }
  783. $selectedEntities = implode(', ', $array);
  784. }
  785. return $selectedEntities;
  786. }
  787. function getAllGroupsFromGroupClass($selectedEntities)
  788. {
  789. global $db;
  790. $groups = [];
  791. $sql = "SELECT rowid, ref FROM " . MAIN_DB_PREFIX . "settlements_group WHERE hotelgroup IS NULL ";
  792. if ($selectedEntities != '') {
  793. $sql .= " AND fk_entity IN ({$selectedEntities})";
  794. }
  795. $sql .= "ORDER BY ref ASC";
  796. $data = $db->query($sql);
  797. if (!$data) {
  798. dol_syslog("No group found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  799. setEventMessage('A csoport tábla lekérdezése sikertelen volt.', 'errors');
  800. return $groups;
  801. }
  802. while ($row = pg_fetch_assoc($data)) {
  803. $groups[$row['rowid']] = $row['ref'];
  804. }
  805. return $groups;
  806. }
  807. function getAllHotelGroupsFromGroupClass($db)
  808. {
  809. $groups = [];
  810. $sql = "SELECT g.rowid, g.ref, g.fk_entity, gh.fk_hotel_id
  811. FROM " . MAIN_DB_PREFIX . "settlements_group AS g
  812. INNER JOIN " . MAIN_DB_PREFIX . "settlements_grouphotels as gh ON gh.fk_group_id = g.rowid
  813. WHERE g.hotelgroup IS NOT NULL ORDER BY ref ASC";
  814. //$sql = "SELECT rowid, ref, fk_entity FROM " . MAIN_DB_PREFIX . "settlements_group WHERE hotelgroup IS NOT NULL ORDER BY ref ASC";
  815. //print $sql;exit;
  816. $data = $db->query($sql);
  817. if (!$data) {
  818. dol_syslog("No group found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  819. setEventMessage('A csoport tábla lekérdezése sikertelen volt.', 'errors');
  820. return $groups;
  821. }
  822. while ($row = pg_fetch_assoc($data)) {
  823. $groups[$row['rowid']] = ["ref" => $row['ref'], "entity" => $row['fk_entity'], "fk_hotel_id" => $row['fk_hotel_id']];
  824. }
  825. return $groups;
  826. }
  827. function getGroupHotels()
  828. {
  829. global $db;
  830. $groupHotels = [];
  831. $sql = "SELECT gh.fk_group_id, gh.fk_hotel_id, g.ref as groulabel, h.label as hotellabel FROM " . MAIN_DB_PREFIX . "settlements_grouphotels AS gh
  832. INNER JOIN " . MAIN_DB_PREFIX . "settlements_group AS g ON g.rowid = gh.fk_group_id
  833. INNER JOIN " . MAIN_DB_PREFIX . "settlements_hotel AS h ON h.rowid = gh.fk_hotel_id
  834. ORDER BY h.label ASC";
  835. $data = $db->query($sql);
  836. while ($row = pg_fetch_assoc($data)) {
  837. $groupHotels[] = $row;
  838. }
  839. return $groupHotels;
  840. }
  841. function getUsersByIdWithDateCol2($db, $id, $date)
  842. {
  843. $usersOfGroup = [];
  844. $date = date('Y-m-d', strtotime("-20 day", strtotime($date)));
  845. $dateNow = date('Y-m-d H:i:s', dol_now());
  846. if (isset($id)) {
  847. $sql = "SELECT un.user_id, u.firstname as firstname, u.lastname as lastname, u.login as login FROM " . MAIN_DB_PREFIX . "settlements_usernaplo AS un
  848. INNER JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = un.user_id
  849. WHERE un.group_user_id = {$id} AND un.date_creation BETWEEN '{$date} 00:00:00' AND '{$dateNow}' AND un.status = 1
  850. GROUP BY un.user_id, u.firstname, u.lastname, u.login ORDER BY u.lastname";
  851. $data = $db->query($sql);
  852. if (!$data) {
  853. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  854. setEventMessage('A csoporthoz rendelt felhasználók naplózási lekérdezésébe valami hiba csúszott.', 'errors');
  855. return $usersOfGroup;
  856. }
  857. while ($row = pg_fetch_assoc($data)) {
  858. $usersOfGroup[] = $row;
  859. }
  860. }
  861. return $usersOfGroup;
  862. }
  863. /**
  864. * @param int $id Group ID
  865. */
  866. function getUsersByIdWithDate($db, $id, $date)
  867. {
  868. $usersOfGroup = [];
  869. $date = date('Y-m-d', strtotime("-20 day", strtotime($date)));
  870. $dateNow = date('Y-m-d H:i:s', dol_now());
  871. if (isset($id)) {
  872. $sql = "SELECT un.user_id, u.firstname as firstname, u.lastname as lastname, u.login as login, un.date_creation FROM " . MAIN_DB_PREFIX . "settlements_usernaplo AS un
  873. INNER JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = un.user_id
  874. WHERE un.group_user_id = {$id} AND un.date_creation BETWEEN '{$date} 00:00:00' AND '{$dateNow}' AND un.status = 1
  875. GROUP BY un.user_id, u.firstname, u.lastname, u.login, un.date_creation ORDER BY u.lastname";
  876. //print $sql.'<br>';
  877. $data = $db->query($sql);
  878. if (!$data) {
  879. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  880. setEventMessage('A csoporthoz rendelt felhasználók naplózási lekérdezésébe valami hiba csúszott.', 'errors');
  881. return $usersOfGroup;
  882. }
  883. while ($row = pg_fetch_assoc($data)) {
  884. $usersOfGroup[] = $row;
  885. }
  886. }
  887. return $usersOfGroup;
  888. }
  889. function getDeletedUsers($db, $id, $date)
  890. {
  891. $deletedUsersArray = [];
  892. $date = date('Y-m-d', strtotime("-1 day", strtotime($date)));
  893. $dateNow = date('Y-m-d H:i:s', dol_now());
  894. //print $id;
  895. //$sql = "SELECT user_id, MAX(date_creation) as date FROM " . MAIN_DB_PREFIX . "settlements_usernaplo WHERE group_user_id = {$id} and date_creation BETWEEN '{$date} 00:00:00' AND '{$date} 23:59:59' AND status = 0 GROUP BY user_id ";
  896. $sql = "SELECT user_id, date_creation as date
  897. FROM " . MAIN_DB_PREFIX . "settlements_usernaplo
  898. WHERE group_user_id = {$id}
  899. AND date_creation BETWEEN '{$date} 00:00:00' AND '{$dateNow}'
  900. AND status = 0 ORDER BY date_creation ASC";
  901. //print $sql;
  902. //print '<br>';
  903. $data = $db->query($sql);
  904. $dataArray = pg_fetch_all($data);
  905. if (empty($dataArray)) {
  906. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  907. return $deletedUsersArray;
  908. }
  909. foreach ($dataArray as $row) {
  910. $deletedUsersArray[$row['user_id']][] = $row['date'];
  911. }
  912. return $deletedUsersArray;
  913. }
  914. function getSum($db, $currency, $id, $users, $date = null)
  915. {
  916. $sum = [];
  917. foreach ($users as $user) {
  918. $usersArray[] = $user['user_id'];
  919. }
  920. $usersString = implode(',', $usersArray);
  921. $sql = "SELECT SUM(total_ht) as total_ht, SUM(total_tva) as total_tva, SUM(total_ttc) as total_ttc
  922. FROM " . MAIN_DB_PREFIX . "facture
  923. WHERE fk_user_closing IN({$usersString})
  924. AND fk_statut = 2
  925. AND multicurrency_code = '{$currency}'
  926. AND date_closing BETWEEN '{$date} 00:00:00' AND '{$date} 23:59:59'";
  927. //print $sql;
  928. $data = $db->query($sql);
  929. if (!$data) {
  930. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  931. setEventMessage('A számlák összesítésének számításába valami hiba csúszott.', 'errors');
  932. return $sum;
  933. }
  934. $dataArray = pg_fetch_all($data);
  935. foreach ($dataArray as $row) {
  936. $sum[] = $row;
  937. }
  938. return $sum;
  939. }
  940. function correctNumber($number)
  941. {
  942. $integerPart = floor($number);
  943. $formattedNumber = number_format($integerPart, 0, '.', ' ');
  944. return $formattedNumber;
  945. }
  946. function getFullBalance($user_id, $db)
  947. {
  948. $sql = "SELECT
  949. currency,
  950. SUM(CASE WHEN payed = 0 AND payment_type = 2 THEN amount ELSE 0 END) -
  951. SUM(CASE WHEN payed = 1 AND payment_type = 0 THEN amount ELSE 0 END) -
  952. SUM(CASE WHEN payment_type = 1 THEN amount ELSE 0 END) AS amount
  953. FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
  954. WHERE user_id = {$user_id}
  955. GROUP BY currency;";
  956. //print $sql;exit;
  957. $resultUserdata = $db->query($sql);
  958. return pg_fetch_all($resultUserdata);
  959. }
  960. private function isWarning($amount)
  961. {
  962. return $amount < 0 ? '<font style="color: red;"> <span class="fa fa-exclamation pictofixedwidth"></span> </font>' : '';
  963. }
  964. private function getBgColor($amount)
  965. {
  966. return $amount < 0 ? 'red' : 'green';
  967. }
  968. function tableDrawer($allSalesUsers, $db, $idmenu, $payment_type)
  969. {
  970. $rownum = 0;
  971. foreach ($allSalesUsers as $user) {
  972. $url = '/custom/financialreport/userinvoice_list.php?user_id=' . $user['rowid'] . '&idmenu=' . $idmenu . '&payment_type=' . $payment_type . '&mainmenu=financialreport&leftmenu=';
  973. $bgcolor = $this->setRowColor($rownum);
  974. print '<tr style="height:30px; background-color: ' . $bgcolor . '">
  975. <td><a style="display: block; width: 100%; height: 100%;" href="' . $url . '">' . $user['lastname'] . ' ' . $user['firstname'] . '</a></td>';
  976. print '<td style="text-align: center;">' . $user['nickname'] . '</td>';
  977. print '<td style="text-align: center;">' . $user['login'] . '</td>';
  978. $this->drawCurrentBalance($user['rowid']);
  979. $this->drawPayedRows($user['rowid'], $payment_type);
  980. print '</tr>';
  981. $rownum++;
  982. }
  983. }
  984. function tableDrawerForBasicCommission($allSalesUsers, $db, $idmenu, $year, $month)
  985. {
  986. global $langs;
  987. $rownum = 0;
  988. $percentage = 0;
  989. $commmissionhandler = new CommissionHandler();
  990. foreach ($allSalesUsers as $user) {
  991. $amountHUF = $commmissionhandler->getCommisonByUserIdForAMonth($user['rowid'], $year, $month);
  992. $amount = $amountHUF;
  993. $userCommissionMinimumAmount = $commmissionhandler->getUserMinimumCommission($user['rowid']);
  994. $suplement = $userCommissionMinimumAmount - $amount < 0 ? 0 : $userCommissionMinimumAmount - $amount;
  995. $bgcolor = $this->setRowColor($rownum);
  996. $percentage = $this->getPercentage($userCommissionMinimumAmount, $amount);
  997. $amountcolor = $amount < $userCommissionMinimumAmount ? 'red' : 'lightgreen';
  998. $fontcolor = $percentage < 4 || $amount >= $userCommissionMinimumAmount ? 'black' : 'white';
  999. $makeUpToValue = $user['rowid'] . '|' . $suplement . '|' . $year . '|' . $month . '|' . $user['lastname'] . ' ' . $user['firstname'];
  1000. $buttondisplay = $suplement > 0 ? 'style="display:block;"' : 'style="display:none;"';
  1001. $makeUpToButton = strtotime($year . '-' . $month) < strtotime(date('Y-m')) ? '<td style="padding-left: 10px; padding-right: 10px;">
  1002. <button ' . $buttondisplay . ' id="confirmmakeupto" name="confirmmakeupto" type="submit" value="' . $makeUpToValue . '">' . $langs->trans('MakeUpTo') . '</button>
  1003. </td>' : '<td>&nbsp;</td>';
  1004. //$url = '/custom/financialreport/userinvoicebasiccommission_list.php?user_id=' . $user['rowid'] . '&idmenu=' . $idmenu . '&mainmenu=financialreport&leftmenu=';
  1005. print '<tr style="height:30px; background-color: ' . $bgcolor . '">';
  1006. print '<td style="width: 15%;"><a href="/custom/financialreport/userinvoice_list.php?user_id=' . $user['rowid'] . '&idmenu=1618&payment_type=2&mainmenu=financialreport&leftmenu=">' . $user['lastname'] . ' ' . $user['firstname'] . '</td>';
  1007. print '<td style="width: 10%; text-align: center;">' . $user['nickname'] . '</td>';
  1008. print '<td style="width: 10%; text-align: center;">' . $this->correctNumber($userCommissionMinimumAmount) . ' HUF</td>';
  1009. print '<td style="width: 10%; text-align: center; color:red;">' . $this->correctNumber($suplement) . ' HUF</td>';
  1010. print '<td style="text-align: center; width:60%;"><div style="display:block; width:' . $percentage . '%; background-color: ' . $amountcolor . '; color:' . $fontcolor . '; white-space: nowrap;"> ' . $this->correctNumber($amount) . ' HUF </div></td>';
  1011. print $makeUpToButton;
  1012. print '</tr>';
  1013. $rownum++;
  1014. }
  1015. }
  1016. function getPercentage($minAmount, $amount)
  1017. {
  1018. if ($minAmount != 0) {
  1019. $percentage = ($amount / $minAmount) * 100;
  1020. if ($percentage > 100) {
  1021. $percentage = 100;
  1022. }
  1023. } else {
  1024. $percentage = $amount == 0 ? 0 : 100;
  1025. }
  1026. return $percentage;
  1027. }
  1028. private function drawCurrentBalanceForTpls($amount, $currency)
  1029. {
  1030. global $langs;
  1031. $color = $this->getBgColor($amount);
  1032. print '<div style="flex: 1; text-align: center;">
  1033. <h3>' . $langs->trans("CurrentBalance") . ' ' . $currency . '</h3>
  1034. <p style="background-color:' . $color . '; color:white;">' . number_format($amount, 0, '.', ' ') . ' ' . $currency . '</p>
  1035. </div>';
  1036. }
  1037. private function drawMinimumCommissionForTpls($amount, $currency)
  1038. {
  1039. global $langs;
  1040. $color = $this->getBgColor($amount);
  1041. print '<div style="flex: 1; text-align: center;">
  1042. <h3>' . $langs->trans("MinimumCommission") . ' ' . $currency . '</h3>
  1043. <p style="background-color:' . $color . '; color:white;">' . number_format($amount, 0, '.', ' ') . ' ' . $currency . '</p>
  1044. </div>';
  1045. }
  1046. function tableDrawerForViewTpls($user_id, $db, $userData, $payment_type)
  1047. {
  1048. global $langs;
  1049. print '<div style="width: 100%; height: 40px;padding: 5px; background-color:lightgrey; text-align:center;"><b>' . $userData->firstname . ' ' . $userData->lastname . '</b> <br> ( ' . $userData->login . ' )</div>';
  1050. print '<div></div>';
  1051. $balance = $this->getFullBalance($user_id, $db);
  1052. $earlierCommissionHUF = $balance[0]['amount'] == null ? 0 : $balance[0]['amount'];
  1053. print '<div style="display: flex; width: 100%;">';
  1054. $this->drawCurrentBalanceForTpls($earlierCommissionHUF, 'HUF');
  1055. $amounts = $this->getAllPaymenttype($user_id, $db, $payment_type);
  1056. foreach ($amounts as $amount) {
  1057. print '<div style="flex: 1; text-align: center;">
  1058. <h3>' . $this->getViewTplTitle($payment_type) . ' ' . $amount['type'] . '</h3>
  1059. <p>' . number_format($amount['amount'], 0, '.', ' ') . ' ' . $amount['type'] . '</p>
  1060. </div>';
  1061. }
  1062. print '</div>';
  1063. if ($payment_type == 2) {
  1064. print '<div></div>';
  1065. $minimumCommission = $this->getminimumCommissionGorUser($user_id);
  1066. print '<div style="display: flex; width: 100%;">';
  1067. $this->drawMinimumCommissionForTpls($minimumCommission, 'HUF');
  1068. print '</div>';
  1069. }
  1070. }
  1071. private function getminimumCommissionGorUser($user_id)
  1072. {
  1073. global $langs, $db;
  1074. $userObj = new User($this->db);
  1075. $sql = "SELECT * FROM llx_user as u INNER JOIN llx_user_extrafields as ue ON ue.fk_object = u.rowid WHERE u.rowid = {$user_id}";
  1076. $result = $db->query($sql);
  1077. while($row = $db->fetch_object($result)){
  1078. $minimum_monthly_commission = $row->minimum_monthly_commission;
  1079. }
  1080. if (!$result) {
  1081. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1082. setEventMessage($langs->trans('noUserForMinimumCommission'), 'errors');
  1083. }
  1084. return $minimum_monthly_commission;
  1085. }
  1086. private function setRowColor($rownum)
  1087. {
  1088. return $rownum % 2 == 0 ? '#b0c4de' : 'white';
  1089. }
  1090. private function drawCurrentBalance($user_id)
  1091. {
  1092. $balance = $this->getFullBalance($user_id, $this->db);
  1093. if (isset($ammount[0])) {
  1094. $earlierCommissionHUF = $balance[0]['amount'] == null ? 0 : $balance[0]['amount'];
  1095. } else {
  1096. $earlierCommissionHUF = 0;
  1097. }
  1098. $earlierCommissionHUF = $balance[0]['amount'] == null ? 0 : $balance[0]['amount'];
  1099. //$earlierCommissionEUR = $balance[1]['amount'] == null ? 0 : $balance[1]['amount'];
  1100. $warning = $this->isWarning($earlierCommissionHUF);
  1101. print '<td style="text-align:center;">' . number_format($earlierCommissionHUF, 0, '.', ' ') . ' HUF ' . $warning . '</td>';
  1102. /* $warning = $this->isWarning($earlierCommissionEUR);
  1103. print '<td style="text-align:center;">' . number_format($earlierCommissionEUR, 0, '.', ' ') . ' EUR ' . $warning . '</td>'; */
  1104. }
  1105. private function drawPayedRows($user_id, $payment_type)
  1106. {
  1107. $amounts = $this->getAllPaymenttype($user_id, $this->db, $payment_type);
  1108. foreach ($amounts as $amount) {
  1109. print '<td style="text-align:center;">' . number_format($amount['amount'], 0, '.', ' ') . ' ' . $amount['type'] . ' </td>';
  1110. }
  1111. }
  1112. function tableDrawerForHistory($allSalesUsers, $idmenu)
  1113. {
  1114. $rownum = 0;
  1115. foreach ($allSalesUsers as $user) {
  1116. $url = '/custom/financialreport/commissionhistory_list.php?user_id=' . $user['rowid'] . '&idmenu=' . $idmenu . '&payment_type=2&mainmenu=financialreport&leftmenu=';
  1117. $bgcolor = $this->setRowColor($rownum);
  1118. print '<tr style="height:30px; background-color: ' . $bgcolor . '">
  1119. <td><a style="display: block; width: 100%; height: 100%;" href="' . $url . '">' . $user['lastname'] . ' ' . $user['firstname'] . '</a></td>';
  1120. print '<td style="text-align: center;">' . $user['nickname'] . '</td>';
  1121. print '<td style="text-align: center;">' . $user['login'] . '</td>';
  1122. // Itt azt kell megejelníteni, ami a még ki nem fizetett jutalékokból és a kifizetett előlegek és visszatartsások összegének különbségéből áll össze.
  1123. $this->drawCurrentBalance($user['rowid']);
  1124. $this->drawPayedRows($user['rowid'], 2);
  1125. $this->drawPayedRows($user['rowid'], 0);
  1126. print '</tr>';
  1127. $rownum++;
  1128. }
  1129. }
  1130. function tableDrawerForDailyClosing($allSalesUsers, $idmenu)
  1131. {
  1132. $rownum = 0;
  1133. foreach ($allSalesUsers as $user) {
  1134. $url = '/custom/settlements/dailyclosing_card.php?user_id=' . $user['rowid'] . '&idmenu=' . $idmenu . '&mainmenu=settlements&leftmenu=';
  1135. $bgcolor = $this->setRowColor($rownum);
  1136. print '<tr style="height:30px; background-color: ' . $bgcolor . '">
  1137. <td><a style="display: block; width: 100%; height: 100%;" href="' . $url . '">' . $user['lastname'] . ' ' . $user['firstname'] . '</a></td>';
  1138. print '<td style="text-align: center;">' . $user['nickname'] . '</td>';
  1139. print '<td style="text-align: center;">' . $user['login'] . '</td>';
  1140. // Itt azt kell megejelníteni, ami a még ki nem fizetett jutalékokból és a kifizetett előlegek és visszatartsások összegének különbségéből áll össze.
  1141. $this->drawCurrentBalance($user['rowid']);
  1142. $this->drawPayedRows($user['rowid'], 2);
  1143. $this->drawPayedRows($user['rowid'], 0);
  1144. print '</tr>';
  1145. $rownum++;
  1146. }
  1147. }
  1148. function generateRef($payment_type)
  1149. {
  1150. return $this->getTypeOfPayment($payment_type) . '_' . dol_now() . '_' . rand(1000000, 9999999);
  1151. }
  1152. /* function checkBalance($user_id, $date)
  1153. {
  1154. $sql = "SELECT invoices FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
  1155. WHERE user_id = {$user_id}
  1156. AND date_creation BETWEEN '{$date} 00:00:00' AND '{$date} 23:59:59'
  1157. AND payment_type = 2
  1158. ";
  1159. $resultBalanceData = $this->db->query($sql);
  1160. $result = pg_fetch_all($resultBalanceData);
  1161. return is_array($result);
  1162. } */
  1163. function getOccassionOfThisPeriodByDateAndUserId($user_id, $from, $to)
  1164. {
  1165. return rand(100, 1000);
  1166. }
  1167. function createDataArrayForLoginLogotOccassionTable($results)
  1168. {
  1169. $array = [];
  1170. $i = 0;
  1171. foreach ($results as $record) {
  1172. if ($record->login_logout_status == 0) {
  1173. $array[$i]['login'] = date('Y-m-d H:i:s', $record->date_creation);
  1174. } else {
  1175. if (isset($record->date_creation)) {
  1176. $array[$i]['logout'] = date('Y-m-d H:i:s', $record->date_creation);
  1177. }
  1178. }
  1179. $i++;
  1180. }
  1181. return $array;
  1182. }
  1183. function createUserDataArray($array, $userOfGroups)
  1184. {
  1185. $userDataArray = [];
  1186. $count = count($array);
  1187. for ($k = 0; $k < $count; $k++) {
  1188. if (isset($array[$k]['login'])) {
  1189. if (!isset($userDataArray[$k - 1]['logout']) && $k != 0) {
  1190. $userDataArray[$k - 1]['logout'] = $array[$k]['login'] . '*';
  1191. }
  1192. $userDataArray[$k]['login'] = $array[$k]['login'];
  1193. }
  1194. if (isset($array[$k]['logout'])) {
  1195. $userDataArray[$k - 1]['logout'] = $array[$k]['logout'];
  1196. }
  1197. if ($k == $count - 1 && isset($deletedUsersArray[$userOfGroups['user_id']])) {
  1198. $userDataArray[$k]['logout'] = $array[$userOfGroups['user_id']];
  1199. }
  1200. }
  1201. return $userDataArray;
  1202. }
  1203. function updateUserDataArray($userDataArray, $deletedUsersArray, $userOfGroups, $commmissionhandler)
  1204. {
  1205. foreach ($userDataArray as $key => $period) {
  1206. $from = $period['login'];
  1207. $to = isset($period['logout']) ? $period['logout'] : (isset($deletedUsersArray[$userOfGroups['user_id']]) ? $deletedUsersArray[$userOfGroups['user_id']] : date('Y-m-d', dol_now()) . ' 23:59:59');
  1208. print $from . ' - ' . $to . '<br>';
  1209. if (isset($from)) {
  1210. $commission_HUF = $commmissionhandler->getOccassionOfThisPeriodByDateAndUserId_HUF($userOfGroups['user_id'], $from, $to);
  1211. $commission_EURToHUF = $commmissionhandler->getOccassionOfThisPeriodByDateAndUserId_EURToHUF($userOfGroups['user_id'], $from, $to);
  1212. $userDataArray[$key]['commission'] = $commission_HUF + $commission_EURToHUF;
  1213. }
  1214. }
  1215. return $userDataArray;
  1216. }
  1217. function getAmountOfCommissions($userDataArray)
  1218. {
  1219. $amount = 0;
  1220. foreach ($userDataArray as $record) {
  1221. $amount += intval($record);
  1222. }
  1223. return $amount;
  1224. }
  1225. function getInvoicesRowidFromFacture($user_id, $from, $to)
  1226. {
  1227. $invocesRowidArray = [];
  1228. $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "facture AS f WHERE fk_user_closing = {$user_id}
  1229. AND EXISTS (SELECT * FROM " . MAIN_DB_PREFIX . "bbus_bbticketinvoiceprinting as bbip WHERE bbip.fk_facture = f.rowid ORDER BY bbip.rowid DESC LIMIT 1)
  1230. AND date_closing BETWEEN '{$from}' AND '{$to}'";
  1231. //print $sql;
  1232. //exit;
  1233. $resultInvoicesData = $this->db->query($sql);
  1234. if ($this->db->num_rows($resultInvoicesData) != 0) {
  1235. $result = pg_fetch_all($resultInvoicesData);
  1236. foreach ($result as $value) {
  1237. $invocesRowidArray[] = $value['rowid'];
  1238. }
  1239. $invocesRowidString = implode(',', $invocesRowidArray);
  1240. }
  1241. $readyInvoices = $this->getAllComissionInvoicesOfUserInTheGroupFromUserInvoice($user_id, $from, $to);
  1242. //print $readyInvoices . '<br>';
  1243. //print $invocesRowidString . '<br>';
  1244. if (!empty($readyInvoices)) {
  1245. $invocesRowidString = $this->giveMeTheDifferenceInString($readyInvoices, $invocesRowidString);
  1246. }
  1247. //print $invocesRowidString . '<br>';
  1248. return $invocesRowidString;
  1249. }
  1250. function getInvoicesRowidFromFactureInAnIntervalByEveryUser($users, $from, $to, $exception)
  1251. {
  1252. $invocesRowidArray = [];
  1253. $sql = "SELECT f.rowid FROM " . MAIN_DB_PREFIX . "facture as f WHERE fk_user_closing IN({$users})";
  1254. if ($exception != '') {
  1255. $sql .= " AND rowid NOT IN({$exception})";
  1256. }
  1257. $sql .= " AND EXISTS (SELECT * FROM " . MAIN_DB_PREFIX . "bbus_bbticketinvoiceprinting as bbip WHERE bbip.fk_facture = f.rowid ORDER BY bbip.rowid DESC LIMIT 1)
  1258. AND date_closing BETWEEN '{$from}' AND '{$to}'";
  1259. //print $sql . "\r\n";
  1260. $resultInvoicesData = $this->db->query($sql);
  1261. if ($this->db->num_rows($resultInvoicesData) != 0) {
  1262. $result = pg_fetch_all($resultInvoicesData);
  1263. foreach ($result as $value) {
  1264. $invocesRowidArray[] = $value['rowid'];
  1265. }
  1266. $invocesRowidString = implode(',', $invocesRowidArray);
  1267. }
  1268. return $invocesRowidString;
  1269. }
  1270. function getAllComissionInvoicesOfUserInTheGroupFromUserInvoice($user_id, $from, $to)
  1271. {
  1272. $arraytmp = [];
  1273. $invocesRowidString = '';
  1274. $userInvocesObj = new UserInvoice($this->db);
  1275. $result = $userInvocesObj->fetchAll('ASC', 'rowid', 0, 0, ['customsql' => "user_id = " . $user_id . " AND date_creation BETWEEN '" . $from . "' AND '" . $to . "'"]);
  1276. foreach ($result as $data) {
  1277. if (!empty($data->invoices) || $data->invoices != '') {
  1278. $array1 = explode(',', $data->invoices);
  1279. $arraytmp = array_merge($arraytmp, $array1);
  1280. }
  1281. }
  1282. $invocesRowidString = implode(',', $arraytmp);
  1283. return $invocesRowidString;
  1284. }
  1285. function giveMeTheDifferenceInString($readyInvoices, $invocesRowidString)
  1286. {
  1287. $string = '';
  1288. if ($readyInvoices != '' && $invocesRowidString != '') {
  1289. $array1 = explode(',', $readyInvoices);
  1290. $array2 = explode(',', $invocesRowidString);
  1291. /* print 'array1: ';
  1292. print_r($array1);
  1293. print '<br>';
  1294. print 'array2: ';
  1295. print_r($array2);
  1296. print '<br>'; */
  1297. $arrayDiff = array_diff($array2, $array1);
  1298. //$arrayDiff = array_diff($array1, $array2);
  1299. /* print 'Diff: ';
  1300. print_r($arrayDiff);
  1301. print '<br>';
  1302. print '<br>';
  1303. print '<br>';
  1304. */
  1305. //$arrayDiff = count($array2) > count($array1) ? array_diff($array2, $array1) : array_diff($array1, $array2);
  1306. $string = implode(',', $arrayDiff);
  1307. return $string;
  1308. }
  1309. return $string;
  1310. }
  1311. function getHtmlForConfirmWindow($commission)
  1312. {
  1313. $userData = [];
  1314. $userObj = new User($this->db);
  1315. foreach ($commission as $value) {
  1316. $itemData = explode('_', $value);
  1317. $userdata = $userObj->fetch($itemData[0]);
  1318. //print_r($userObj);exit;
  1319. $userData[$userObj->id]['name'] = $userObj->lastname . ' ' . $userObj->firstname . ' (' . $userObj->login . ') ' . $userObj->array_options['options_nickname'];
  1320. $summaHUF += $itemData[2];
  1321. }
  1322. $uniformHUF = $summaHUF / count($commission);
  1323. $array[] = $userData;
  1324. $array[] = $uniformHUF;
  1325. return $array;
  1326. }
  1327. function azosszesElemEgyezik($tomb)
  1328. {
  1329. $szamlalo = array_count_values($tomb);
  1330. $kulonbozoErtekekSzama = count($szamlalo);
  1331. return $kulonbozoErtekekSzama === 1;
  1332. }
  1333. function getUsersArray($data)
  1334. {
  1335. foreach ($data as $item) {
  1336. $itemData = explode('_', $item);
  1337. $usersArray[] = $itemData[0];
  1338. }
  1339. return $usersArray;
  1340. }
  1341. function checkUserInvoiceRecordAvailability($user_id)
  1342. {
  1343. $userInvoiceObj = new UserInvoice($this->db);
  1344. $now = dol_now();
  1345. $result = $userInvoiceObj->fetchAll('DESC', 'date_creation', 1, 0, ['customsql' => "user_id = " . $user_id . " AND date_creation BETWEEN '" . date('Y-m-d', $now) . " 00:00:00' AND '" . date('Y-m-d', $now) . " 23:59:59'"]);
  1346. return $result;
  1347. }
  1348. function deleteUserFromUsersArrayTMPArray($key, $usersArrayTMP)
  1349. {
  1350. $index = array_search($key, $usersArrayTMP);
  1351. if ($index !== false) {
  1352. unset($usersArrayTMP[$index]);
  1353. }
  1354. return $usersArrayTMP;
  1355. }
  1356. function saveUserInvoiceRecord($usersArrayFilteredUsersFrom, $val, $uniformHUF, $settledInvoices)
  1357. {
  1358. global $user;
  1359. $userinvoice = new UserInvoice($this->db);
  1360. $currency = 0;
  1361. $userinvoice->ref = $this->generateRef(2);
  1362. $userinvoice->label = 'Jutalék/Commission ' . $usersArrayFilteredUsersFrom[$val];
  1363. $userinvoice->description = 'Összeg / Amount: ' . $uniformHUF . 'HUF.';
  1364. $userinvoice->user_id = $val;
  1365. $userinvoice->payment_type = 2;
  1366. $userinvoice->amount = $uniformHUF;
  1367. $userinvoice->currency = $currency;
  1368. $userinvoice->individual = 0;
  1369. $userinvoice->invoices = $settledInvoices;
  1370. $userinvoice->date_creation = strtotime($usersArrayFilteredUsersFrom[$val]);
  1371. $userinvoice->create($user);
  1372. }
  1373. function getAllDifferentDatesASC($from, $to)
  1374. {
  1375. foreach ($from as $fromvalue) {
  1376. foreach ($fromvalue as $value1) {
  1377. $allDates[] = $value1;
  1378. }
  1379. }
  1380. foreach ($to as $tovalue) {
  1381. foreach ($tovalue as $value1) {
  1382. $allDates[] = $value1;
  1383. }
  1384. }
  1385. $allDates = array_unique($allDates);
  1386. return $allDates;
  1387. }
  1388. function getQueryArray($from, $to)
  1389. {
  1390. $allDates = $this->getAllDifferentDatesASC($from, $to);
  1391. uasort($allDates, 'datumOsszehasonlitas');
  1392. $countAllDatesArray = count($allDates);
  1393. $allDates = array_values($allDates);
  1394. for ($i = 0; $i < $countAllDatesArray - 1; $i++) {
  1395. $queryArray[$i]['from'] = $allDates[$i];
  1396. $queryArray[$i]['to'] = $allDates[$i + 1];
  1397. }
  1398. return $queryArray;
  1399. }
  1400. function getAllComissionInvoicesOfUserInTheGroupFromUserInvoiceCreated($usersArray, $from, $to)
  1401. {
  1402. $userInvocesObj = new UserInvoice($this->db);
  1403. $result = $userInvocesObj->fetchAll('ASC', 'rowid', 0, 0, ['customsql' => "user_id IN(" . $usersArray . ") AND date_creation BETWEEN '" . $from . "' AND '" . $to . "'"]);
  1404. $all = [];
  1405. foreach ($result as $key => $value) {
  1406. //print $value->user_id . ' - ';
  1407. //print $value->invoices . "\r\n";
  1408. $arrayTmp = explode(',', $value->invoices);
  1409. $all = array_merge($all, $arrayTmp);
  1410. }
  1411. $all = array_unique($all);
  1412. $all = array_filter($all);
  1413. sort($all);
  1414. return implode(',', $all);
  1415. }
  1416. public function getGroupMemberHistory($user_id, $group_id, $date)
  1417. {
  1418. $groupMemberHistory = [];
  1419. $from = $date . ' 00:00:00';
  1420. $to = $date . ' 23:59:59';
  1421. $UserNaplo = new UserNaplo($this->db);
  1422. $result = $UserNaplo->fetchAll('ASC', 'rowid', 0, 0, ['customsql' => "user_id = {$user_id} AND group_user_id = {$group_id} AND date_creation BETWEEN '{$from}' AND '{$to}'"]);
  1423. foreach ($result as $record) {
  1424. if ($record->status == 1) {
  1425. $groupMemberHistory[]['added'] = date("Y-m-d H:i:s", $record->date_creation);
  1426. } else {
  1427. $groupMemberHistory[]['deleted'] = date("Y-m-d H:i:s", $record->date_creation);
  1428. }
  1429. }
  1430. return $groupMemberHistory;
  1431. }
  1432. function getUsersByIdFromGroupUsers($id)
  1433. {
  1434. global $db;
  1435. $usersOfGroup = [];
  1436. if (isset($id)) {
  1437. $sql = "SELECT gu.fk_user AS user_id, gu.date_creation, u.firstname as firstname, u.lastname as lastname, u.login as login FROM " . MAIN_DB_PREFIX . "settlements_groupusers as gu
  1438. INNER JOIN " . MAIN_DB_PREFIX . "user AS u ON u.rowid = gu.fk_user
  1439. WHERE gu.fk_Settlements_group = {$id}";
  1440. $data = $db->query($sql);
  1441. if (!$data) {
  1442. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1443. setEventMessage('A csoporthoz rendelt felhasználók naplózási lekérdezésébe valami hiba csúszott.', 'errors');
  1444. return $usersOfGroup;
  1445. }
  1446. while ($row = pg_fetch_assoc($data)) {
  1447. $usersOfGroup[] = $row;
  1448. }
  1449. }
  1450. return $usersOfGroup;
  1451. }
  1452. function getDeletedHotelUsers($id)
  1453. {
  1454. global $db;
  1455. $deletedUsersArray = [];
  1456. if (isset($id)) {
  1457. $sql = "SELECT user_id, date_creation as date
  1458. FROM " . MAIN_DB_PREFIX . "settlements_usernaplo
  1459. WHERE group_user_id = {$id}
  1460. AND status = 0 ORDER BY date_creation ASC";
  1461. //print $sql;exit;
  1462. $data = $db->query($sql);
  1463. $dataArray = pg_fetch_all($data);
  1464. if (empty($dataArray)) {
  1465. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1466. return $deletedUsersArray;
  1467. }
  1468. foreach ($dataArray as $row) {
  1469. $deletedUsersArray[$row['user_id']][] = $row['date'];
  1470. }
  1471. }
  1472. return $deletedUsersArray;
  1473. }
  1474. function getUserdataFromNaploByUaserId($user_id, $userGroupId)
  1475. {
  1476. global $db;
  1477. $date = '';
  1478. $sql = "SELECT date_creation as date FROM " . MAIN_DB_PREFIX . "settlements_usernaplo
  1479. WHERE user_id = {$user_id} AND group_user_id = {$userGroupId} AND status = 1
  1480. ORDER BY rowid ASC LIMIT 1";
  1481. //print $sql;
  1482. $data = $db->query($sql);
  1483. $dataArray = pg_fetch_all($data);
  1484. if (empty($dataArray)) {
  1485. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1486. return $date;
  1487. }
  1488. foreach ($dataArray as $row) {
  1489. return $row['date'];
  1490. }
  1491. }
  1492. function createDaterangeString($daterange)
  1493. {
  1494. $array = explode(' - ', $daterange);
  1495. return str_replace('-', '.', $array[0]) . ' - ' . str_replace('-', '.', $array[1]);
  1496. }
  1497. function getUsersOfHotelGroup2($id, $daterange)
  1498. {
  1499. global $db;
  1500. $dates = explode(' - ', $daterange);
  1501. $now = dol_now();
  1502. $to = $dates[1] > date('Y-m-d', $now) ? date('Y-m-d', $now) : $dates[1];
  1503. $sql = "SELECT u.rowid, u.firstname, u. lastname, ue.user_category FROM " . MAIN_DB_PREFIX . "settlements_usernaplo AS un
  1504. INNER JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = un.user_id
  1505. INNER JOIN " . MAIN_DB_PREFIX . "user_extrafields AS ue ON ue.fk_object = u.rowid
  1506. WHERE un.date_creation BETWEEN '{$dates[0]} 00:00:00' AND '{$to} 23:59:59'
  1507. AND un.group_user_id = {$id}
  1508. GROUP BY u.firstname, u.lastname, ue.user_category, u.rowid";
  1509. $data = $db->query($sql);
  1510. $result = pg_fetch_all($data);
  1511. if (empty($result)) {
  1512. return [];
  1513. }
  1514. return $result;
  1515. }
  1516. function getUsersOfHotelGroup($id, $daterange, $entity)
  1517. {
  1518. global $db;
  1519. $array = [];
  1520. $dates = explode(' - ', $daterange);
  1521. $now = dol_now();
  1522. $to = $dates[1] > date('Y-m-d', $now) ? date('Y-m-d', $now) : $dates[1];
  1523. if (isset($id)) {
  1524. $sql = "SELECT u.rowid, u.firstname, u. lastname, ue.user_category FROM " . MAIN_DB_PREFIX . "facture AS f
  1525. INNER JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = f.fk_user_closing
  1526. INNER JOIN " . MAIN_DB_PREFIX . "user_extrafields AS ue ON ue.fk_object = u.rowid
  1527. INNER JOIN " . MAIN_DB_PREFIX . "facture_extrafields as fe ON fe.fk_object = f.rowid
  1528. WHERE f.date_closing BETWEEN '{$dates[0]} 00:00:00' AND '{$to} 23:59:59'
  1529. AND f.entity = {$entity}
  1530. AND fe.react_facture = {$id}
  1531. GROUP BY u.rowid, u.firstname, u. lastname, ue.user_category";
  1532. //print $sql;
  1533. $data = $db->query($sql);
  1534. $array = pg_fetch_all($data);
  1535. if (empty($result)) {
  1536. return $array;
  1537. }
  1538. }
  1539. return $array;
  1540. }
  1541. function getUsersList($id, $daterange, $entity)
  1542. {
  1543. global $db;
  1544. $string = '';
  1545. $result = $this->getUsersOfHotelGroup($id, $daterange, $entity);
  1546. foreach ($result as $row) {
  1547. $string .= '<tr class="smallredcolor"><td><b>' . $row['firstname'] . ' ' . $row['lastname'] . '</b></td><td>(' . $this->userCategoryArray[$row['user_category']] . ')</td><td>' . $this->correctNumber($this->getAllAmountInPeriod($id, $daterange, 'HUF', $row['rowid'], $entity)) . ' HUF</td><td>' . $this->correctNumber($this->getAllAmountInPeriod($id, $daterange, 'EUR', $row['rowid'], $entity)) . ' EUR</td></tr>';
  1548. }
  1549. return $string;
  1550. }
  1551. function getUsersIdList($id, $daterange, $entity)
  1552. {
  1553. global $db;
  1554. $result = $this->getUsersOfHotelGroup($id, $daterange, $entity);
  1555. if (!empty($result)) {
  1556. foreach ($result as $row) {
  1557. $array[] = $row['rowid'];
  1558. }
  1559. return implode(',', $array);
  1560. }
  1561. return '';
  1562. }
  1563. function getAllAmountInPeriod($id, $daterange, $currency, $usersIdList, $entity)
  1564. {
  1565. //$entity = 1;
  1566. global $db;
  1567. $result = 0;
  1568. $dates = explode(' - ', $daterange);
  1569. $now = dol_now();
  1570. $to = $dates[1] > date('Y-m-d', $now) ? date('Y-m-d', $now) : $dates[1];
  1571. if (isset($id)) {
  1572. $sql = "SELECT sum(f.total_ttc) FROM " . MAIN_DB_PREFIX . "facture as f
  1573. INNER JOIN " . MAIN_DB_PREFIX . "facture_extrafields as fe ON fe.fk_object = f.rowid
  1574. WHERE f.paye = 1
  1575. AND f.date_closing BETWEEN '{$dates[0]} 00:00:00' AND '{$to} 23:59:59'";
  1576. if ($usersIdList !== '') {
  1577. $sql .= " AND f.fk_user_closing in($usersIdList)";
  1578. }
  1579. $sql .= " AND f.multicurrency_code = '{$currency}'
  1580. AND f.entity = {$entity}
  1581. AND fe.react_facture = {$id}";
  1582. //print $sql;
  1583. $data = $db->query($sql);
  1584. $result = pg_fetch_all($data);
  1585. return is_null($result[0]['sum']) ? 0 : $result[0]['sum'];
  1586. }
  1587. }
  1588. function getAllCommissionInPeriod($id, $daterange, $currency, $usersIdList, $entity)
  1589. {
  1590. global $db;
  1591. $commissionsArray = [];
  1592. $dates = explode(' - ', $daterange);
  1593. $now = dol_now();
  1594. $to = $dates[1] > date('Y-m-d', $now) ? date('Y-m-d', $now) : $dates[1];
  1595. if (isset($id)) {
  1596. $sql = "SELECT f.total_ttc, fe.commission
  1597. FROM " . MAIN_DB_PREFIX . "facture as f
  1598. INNER JOIN " . MAIN_DB_PREFIX . "facture_extrafields as fe ON fe.fk_object = f.rowid
  1599. WHERE f.paye = 1
  1600. AND f.date_closing BETWEEN '{$dates[0]} 00:00:00' AND '{$to} 23:59:59'";
  1601. if ($usersIdList !== '') {
  1602. $sql .= " AND f.fk_user_closing in($usersIdList)";
  1603. }
  1604. $sql .= " AND f.multicurrency_code = '{$currency}'
  1605. AND f.entity = '{$entity}'
  1606. AND fe.react_facture = {$id}";
  1607. //print $sql;exit;
  1608. $data = $db->query($sql);
  1609. $result = pg_fetch_all($data);
  1610. //print_r($result);
  1611. if (!empty($result)) {
  1612. foreach ($result as $row) {
  1613. $commissionValue = $this->getCommissionData($row['commission'], 0);
  1614. $commissionUnit = $this->getCommissionData($row['commission'], 1);
  1615. if ($commissionUnit == '%') {
  1616. $commissionsArray[] = ($row['total_ttc'] / 100) * $commissionValue;
  1617. } else {
  1618. $commissionsArray[] = $commissionValue;
  1619. }
  1620. }
  1621. }
  1622. return $this->getAmountOfCommissions($commissionsArray);
  1623. }
  1624. return 0;
  1625. }
  1626. private function getCommissionData($commission, $number)
  1627. {
  1628. $array = explode('_', $commission);
  1629. return $array[$number];
  1630. }
  1631. public function getAllHotels()
  1632. {
  1633. global $db;
  1634. $resultArray = [];
  1635. $hotelsObj = new Hotel($db);
  1636. $hotelsArray = $hotelsObj->fetchAll('ASC', 'label', 0, 0);
  1637. if (!empty($hotelsArray)) {
  1638. foreach ($hotelsArray as $hotelRecord) {
  1639. $resultArray[$hotelRecord->id] = $hotelRecord->label;
  1640. }
  1641. }
  1642. return $resultArray;
  1643. }
  1644. public function getGroupRefByID($id)
  1645. {
  1646. if (isset($id)) {
  1647. global $db;
  1648. $sql = "SELECT ref FROM " . MAIN_DB_PREFIX . "settlements_group WHERE rowid = {$id}";
  1649. $data = $db->query($sql);
  1650. if (!$data) {
  1651. dol_syslog("No group found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1652. }
  1653. while ($row = pg_fetch_assoc($data)) {
  1654. return $row['ref'];
  1655. }
  1656. }
  1657. return '';
  1658. }
  1659. public function getGroupEntityId($id)
  1660. {
  1661. if (isset($id)) {
  1662. global $db;
  1663. $sql = "SELECT fk_entity FROM " . MAIN_DB_PREFIX . "settlements_group WHERE rowid = {$id}";
  1664. $data = $db->query($sql);
  1665. if (!$data) {
  1666. dol_syslog("No group found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1667. }
  1668. while ($row = pg_fetch_assoc($data)) {
  1669. return $row['fk_entity'];
  1670. }
  1671. }
  1672. return null;
  1673. }
  1674. public function getGroupLabelById($id)
  1675. {
  1676. global $db;
  1677. $groupObj = new Group($db);
  1678. $groupObj->fetch($id);
  1679. return $groupObj->ref;
  1680. }
  1681. public function getFirstDateFromUserNaplo($id)
  1682. {
  1683. global $db;
  1684. $from = date("Y-m-d") . ' 00:00:00';
  1685. $to = date("Y-m-d H:i:s");
  1686. $sql = "SELECT un.date_creation FROM " . MAIN_DB_PREFIX . "settlements_usernaplo AS un
  1687. WHERE un.group_user_id = {$id} AND un.date_creation BETWEEN '{$from}' AND '{$to}' AND un.status = 1
  1688. ORDER BY un.date_creation ASC LIMIT 1";
  1689. //print $sql;exit;
  1690. $data = $db->query($sql);
  1691. if (!$data) {
  1692. dol_syslog("No group found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1693. }
  1694. while ($row = pg_fetch_all($data)) {
  1695. return $row[0]['date_creation'];
  1696. }
  1697. return null;
  1698. }
  1699. public function getNamedataFoTheUser($user_id)
  1700. {
  1701. global $db;
  1702. $sql = "SELECT u.firstname, u.lastname, u.login FROM " . MAIN_DB_PREFIX . "user AS u WHERE rowid = {$user_id}";
  1703. //print $sql;exit;
  1704. $data = $db->query($sql);
  1705. foreach (pg_fetch_all($data) as $userData) {
  1706. return $userData['firstname'] . ' ' . $userData['lastname'] . ' (' . $userData['login'] . ')';
  1707. }
  1708. }
  1709. public function checklogoutRecordInUserNaplo($user_id, $from, $id)
  1710. {
  1711. global $db;
  1712. $sql = "SELECT date_creation FROM " . MAIN_DB_PREFIX . "settlements_usernaplo
  1713. WHERE group_user_id = {$id}
  1714. AND user_id = {$user_id}
  1715. AND date_creation > '{$from}'
  1716. AND status = 0
  1717. ORDER BY date_creation ASC LIMIT 1";
  1718. $data = $db->query($sql);
  1719. while ($row = pg_fetch_assoc($data)) {
  1720. return $row['date_creation'];
  1721. }
  1722. }
  1723. public function getGTAndGUArray()
  1724. {
  1725. global $db;
  1726. $sql = "SELECT fk_groupid, fk_group_tools_id FROM " . MAIN_DB_PREFIX . "settlements_usergrouptoolgroup";
  1727. $result = $db->query($sql);
  1728. if (pg_num_rows($result) > 0) {
  1729. while ($row = pg_fetch_assoc($result)) {
  1730. $array[$row['fk_groupid']] = $row['fk_group_tools_id'];
  1731. }
  1732. return $array;
  1733. }
  1734. return [];
  1735. }
  1736. function getAllEntities()
  1737. {
  1738. $entitiesArray = [];
  1739. $sql = "SELECT rowid, label FROM " . MAIN_DB_PREFIX . "entity ORDER BY label ASC";
  1740. $data = $this->db->query($sql);
  1741. while ($row = pg_fetch_assoc($data)) {
  1742. $entitiesArray[$row['rowid']] = $row['label'];
  1743. }
  1744. return $entitiesArray;
  1745. }
  1746. function createPopoupBox($numberOfUsers, $usersArray, $id)
  1747. {
  1748. $popoupBox = '<div style="float:right; padding-bottom: 10px;" title="';
  1749. foreach ($usersArray as $users) {
  1750. $popoupBox .= '<span class=&quot;fas fa-user em080&quot; style=&quot; color: #a69944;&quot; cursor: pointer;></span>
  1751. <u class=&quot;paddingrightonly&quot;>' . $users['lastname'] . ' ' . $users['firstname'] . ' (' . $users['login'] . ')</u><br>';
  1752. }
  1753. $popoupBox .= '" class="classfortooltip"><div onclick="popupboxClick(' . $id . ')" class="groupColumn2ndLine">' . $numberOfUsers . '</div>';
  1754. return $popoupBox;
  1755. }
  1756. }