helper.class.php 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929
  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. /* $sqlLastLogin = "SELECT date_creation FROM llx_settlements_usernaplo WHERE status = 1 AND user_id = $id ORDER BY date_creation DESC LIMIT 1";
  846. $result = $db->query($sqlLastLogin);
  847. if($db->num_rows($result) > 0){
  848. while($row = $db->fetch_object($result)){
  849. $date = $row->date_creation;
  850. }
  851. }else{
  852. $date = date('Y-m-d', strtotime("-20 day", dol_now()));
  853. $date = $date . ' 00:00:00';
  854. } */
  855. $dateNow = date('Y-m-d H:i:s', dol_now());
  856. if (isset($id)) {
  857. $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
  858. INNER JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = un.user_id
  859. WHERE un.group_user_id = {$id} AND un.date_creation BETWEEN '{$date} 00:00:00' AND '{$dateNow}' AND un.status = 1
  860. GROUP BY un.user_id, u.firstname, u.lastname, u.login ORDER BY u.lastname";
  861. $data = $db->query($sql);
  862. if (!$data) {
  863. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  864. setEventMessage('A csoporthoz rendelt felhasználók naplózási lekérdezésébe valami hiba csúszott.', 'errors');
  865. return $usersOfGroup;
  866. }
  867. while ($row = pg_fetch_assoc($data)) {
  868. $usersOfGroup[] = $row;
  869. }
  870. }
  871. return $usersOfGroup;
  872. }
  873. /**
  874. * @param int $id Group ID
  875. */
  876. function getUsersByIdWithDate($db, $id, $date)
  877. {
  878. $usersOfGroup = [];
  879. $date = date('Y-m-d', strtotime("-20 day", strtotime($date)));
  880. $dateNow = date('Y-m-d H:i:s', dol_now());
  881. if (isset($id)) {
  882. $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
  883. INNER JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = un.user_id
  884. WHERE un.group_user_id = {$id} AND un.date_creation BETWEEN '{$date} 00:00:00' AND '{$dateNow}' AND un.status = 1
  885. GROUP BY un.user_id, u.firstname, u.lastname, u.login, un.date_creation ORDER BY u.lastname";
  886. //print $sql.'<br>';
  887. $data = $db->query($sql);
  888. if (!$data) {
  889. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  890. setEventMessage('A csoporthoz rendelt felhasználók naplózási lekérdezésébe valami hiba csúszott.', 'errors');
  891. return $usersOfGroup;
  892. }
  893. while ($row = pg_fetch_assoc($data)) {
  894. $usersOfGroup[] = $row;
  895. }
  896. }
  897. return $usersOfGroup;
  898. }
  899. function getDeletedUsers($db, $id, $date)
  900. {
  901. $deletedUsersArray = [];
  902. $date = date('Y-m-d', strtotime("-1 day", strtotime($date)));
  903. $dateNow = date('Y-m-d H:i:s', dol_now());
  904. //print $id;
  905. //$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 ";
  906. $sql = "SELECT user_id, date_creation as date
  907. FROM " . MAIN_DB_PREFIX . "settlements_usernaplo
  908. WHERE group_user_id = {$id}
  909. AND date_creation BETWEEN '{$date} 00:00:00' AND '{$dateNow}'
  910. AND status = 0 ORDER BY date_creation ASC";
  911. //print $sql;
  912. //print '<br>';
  913. $data = $db->query($sql);
  914. $dataArray = pg_fetch_all($data);
  915. if (empty($dataArray)) {
  916. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  917. return $deletedUsersArray;
  918. }
  919. foreach ($dataArray as $row) {
  920. $deletedUsersArray[$row['user_id']][] = $row['date'];
  921. }
  922. return $deletedUsersArray;
  923. }
  924. function getSum($db, $currency, $id, $users, $date = null)
  925. {
  926. $sum = [];
  927. foreach ($users as $user) {
  928. $usersArray[] = $user['user_id'];
  929. }
  930. $usersString = implode(',', $usersArray);
  931. $sql = "SELECT SUM(total_ht) as total_ht, SUM(total_tva) as total_tva, SUM(total_ttc) as total_ttc
  932. FROM " . MAIN_DB_PREFIX . "facture
  933. WHERE fk_user_closing IN({$usersString})
  934. AND fk_statut = 2
  935. AND multicurrency_code = '{$currency}'
  936. AND date_closing BETWEEN '{$date} 00:00:00' AND '{$date} 23:59:59'";
  937. //print $sql;
  938. $data = $db->query($sql);
  939. if (!$data) {
  940. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  941. setEventMessage('A számlák összesítésének számításába valami hiba csúszott.', 'errors');
  942. return $sum;
  943. }
  944. $dataArray = pg_fetch_all($data);
  945. foreach ($dataArray as $row) {
  946. $sum[] = $row;
  947. }
  948. return $sum;
  949. }
  950. function correctNumber($number)
  951. {
  952. $integerPart = floor($number);
  953. $formattedNumber = number_format($integerPart, 0, '.', ' ');
  954. return $formattedNumber;
  955. }
  956. function getFullBalance($user_id, $db)
  957. {
  958. $sql = "SELECT
  959. currency,
  960. SUM(CASE WHEN payed = 0 AND payment_type = 2 THEN amount ELSE 0 END) -
  961. SUM(CASE WHEN payed = 1 AND payment_type = 0 THEN amount ELSE 0 END) -
  962. SUM(CASE WHEN payment_type = 1 THEN amount ELSE 0 END) AS amount
  963. FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
  964. WHERE user_id = {$user_id}
  965. GROUP BY currency;";
  966. //print $sql;exit;
  967. $resultUserdata = $db->query($sql);
  968. return pg_fetch_all($resultUserdata);
  969. }
  970. private function isWarning($amount)
  971. {
  972. return $amount < 0 ? '<font style="color: red;"> <span class="fa fa-exclamation pictofixedwidth"></span> </font>' : '';
  973. }
  974. private function getBgColor($amount)
  975. {
  976. return $amount < 0 ? 'red' : 'green';
  977. }
  978. function tableDrawer($allSalesUsers, $db, $idmenu, $payment_type)
  979. {
  980. $rownum = 0;
  981. foreach ($allSalesUsers as $user) {
  982. $url = '/custom/financialreport/userinvoice_list.php?user_id=' . $user['rowid'] . '&idmenu=' . $idmenu . '&payment_type=' . $payment_type . '&mainmenu=financialreport&leftmenu=';
  983. $bgcolor = $this->setRowColor($rownum);
  984. print '<tr style="height:30px; background-color: ' . $bgcolor . '">
  985. <td><a style="display: block; width: 100%; height: 100%;" href="' . $url . '">' . $user['lastname'] . ' ' . $user['firstname'] . '</a></td>';
  986. print '<td style="text-align: center;">' . $user['nickname'] . '</td>';
  987. print '<td style="text-align: center;">' . $user['login'] . '</td>';
  988. $this->drawCurrentBalance($user['rowid']);
  989. $this->drawPayedRows($user['rowid'], $payment_type);
  990. print '</tr>';
  991. $rownum++;
  992. }
  993. }
  994. function tableDrawerForBasicCommission($allSalesUsers, $db, $idmenu, $year, $month)
  995. {
  996. global $langs;
  997. $rownum = 0;
  998. $percentage = 0;
  999. $commmissionhandler = new CommissionHandler();
  1000. foreach ($allSalesUsers as $user) {
  1001. $amountHUF = $commmissionhandler->getCommisonByUserIdForAMonth($user['rowid'], $year, $month);
  1002. $amount = $amountHUF;
  1003. $userCommissionMinimumAmount = $commmissionhandler->getUserMinimumCommission($user['rowid']);
  1004. $suplement = $userCommissionMinimumAmount - $amount < 0 ? 0 : $userCommissionMinimumAmount - $amount;
  1005. $bgcolor = $this->setRowColor($rownum);
  1006. $percentage = $this->getPercentage($userCommissionMinimumAmount, $amount);
  1007. $amountcolor = $amount < $userCommissionMinimumAmount ? 'red' : 'lightgreen';
  1008. $fontcolor = $percentage < 4 || $amount >= $userCommissionMinimumAmount ? 'black' : 'white';
  1009. $makeUpToValue = $user['rowid'] . '|' . $suplement . '|' . $year . '|' . $month . '|' . $user['lastname'] . ' ' . $user['firstname'];
  1010. $buttondisplay = $suplement > 0 ? 'style="display:block;"' : 'style="display:none;"';
  1011. $makeUpToButton = strtotime($year . '-' . $month) < strtotime(date('Y-m')) ? '<td style="padding-left: 10px; padding-right: 10px;">
  1012. <button ' . $buttondisplay . ' id="confirmmakeupto" name="confirmmakeupto" type="submit" value="' . $makeUpToValue . '">' . $langs->trans('MakeUpTo') . '</button>
  1013. </td>' : '<td>&nbsp;</td>';
  1014. //$url = '/custom/financialreport/userinvoicebasiccommission_list.php?user_id=' . $user['rowid'] . '&idmenu=' . $idmenu . '&mainmenu=financialreport&leftmenu=';
  1015. print '<tr style="height:30px; background-color: ' . $bgcolor . '">';
  1016. 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>';
  1017. print '<td style="width: 10%; text-align: center;">' . $user['nickname'] . '</td>';
  1018. print '<td style="width: 10%; text-align: center;">' . $this->correctNumber($userCommissionMinimumAmount) . ' HUF</td>';
  1019. print '<td style="width: 10%; text-align: center; color:red;">' . $this->correctNumber($suplement) . ' HUF</td>';
  1020. 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>';
  1021. print $makeUpToButton;
  1022. print '</tr>';
  1023. $rownum++;
  1024. }
  1025. }
  1026. function getPercentage($minAmount, $amount)
  1027. {
  1028. if ($minAmount != 0) {
  1029. $percentage = ($amount / $minAmount) * 100;
  1030. if ($percentage > 100) {
  1031. $percentage = 100;
  1032. }
  1033. } else {
  1034. $percentage = $amount == 0 ? 0 : 100;
  1035. }
  1036. return $percentage;
  1037. }
  1038. private function drawCurrentBalanceForTpls($amount, $currency)
  1039. {
  1040. global $langs;
  1041. $color = $this->getBgColor($amount);
  1042. print '<div style="flex: 1; text-align: center;">
  1043. <h3>' . $langs->trans("CurrentBalance") . ' ' . $currency . '</h3>
  1044. <p style="background-color:' . $color . '; color:white;">' . number_format($amount, 0, '.', ' ') . ' ' . $currency . '</p>
  1045. </div>';
  1046. }
  1047. private function drawMinimumCommissionForTpls($amount, $currency)
  1048. {
  1049. global $langs;
  1050. $color = $this->getBgColor($amount);
  1051. print '<div style="flex: 1; text-align: center;">
  1052. <h3>' . $langs->trans("MinimumCommission") . ' ' . $currency . '</h3>
  1053. <p style="background-color:' . $color . '; color:white;">' . number_format($amount, 0, '.', ' ') . ' ' . $currency . '</p>
  1054. </div>';
  1055. }
  1056. function tableDrawerForViewTpls($user_id, $db, $userData, $payment_type)
  1057. {
  1058. global $langs;
  1059. 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>';
  1060. print '<div></div>';
  1061. $balance = $this->getFullBalance($user_id, $db);
  1062. $earlierCommissionHUF = $balance[0]['amount'] == null ? 0 : $balance[0]['amount'];
  1063. print '<div style="display: flex; width: 100%;">';
  1064. $this->drawCurrentBalanceForTpls($earlierCommissionHUF, 'HUF');
  1065. $amounts = $this->getAllPaymenttype($user_id, $db, $payment_type);
  1066. foreach ($amounts as $amount) {
  1067. print '<div style="flex: 1; text-align: center;">
  1068. <h3>' . $this->getViewTplTitle($payment_type) . ' ' . $amount['type'] . '</h3>
  1069. <p>' . number_format($amount['amount'], 0, '.', ' ') . ' ' . $amount['type'] . '</p>
  1070. </div>';
  1071. }
  1072. print '</div>';
  1073. if ($payment_type == 2) {
  1074. print '<div></div>';
  1075. $minimumCommission = $this->getminimumCommissionGorUser($user_id);
  1076. print '<div style="display: flex; width: 100%;">';
  1077. $this->drawMinimumCommissionForTpls($minimumCommission, 'HUF');
  1078. print '</div>';
  1079. }
  1080. }
  1081. private function getminimumCommissionGorUser($user_id)
  1082. {
  1083. global $langs, $db;
  1084. $userObj = new User($this->db);
  1085. $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}";
  1086. $result = $db->query($sql);
  1087. while($row = $db->fetch_object($result)){
  1088. $minimum_monthly_commission = $row->minimum_monthly_commission;
  1089. }
  1090. if (!$result) {
  1091. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1092. setEventMessage($langs->trans('noUserForMinimumCommission'), 'errors');
  1093. }
  1094. return $minimum_monthly_commission;
  1095. }
  1096. private function setRowColor($rownum)
  1097. {
  1098. return $rownum % 2 == 0 ? '#b0c4de' : 'white';
  1099. }
  1100. private function drawCurrentBalance($user_id)
  1101. {
  1102. $balance = $this->getFullBalance($user_id, $this->db);
  1103. if (isset($ammount[0])) {
  1104. $earlierCommissionHUF = $balance[0]['amount'] == null ? 0 : $balance[0]['amount'];
  1105. } else {
  1106. $earlierCommissionHUF = 0;
  1107. }
  1108. $earlierCommissionHUF = $balance[0]['amount'] == null ? 0 : $balance[0]['amount'];
  1109. //$earlierCommissionEUR = $balance[1]['amount'] == null ? 0 : $balance[1]['amount'];
  1110. $warning = $this->isWarning($earlierCommissionHUF);
  1111. print '<td style="text-align:center;">' . number_format($earlierCommissionHUF, 0, '.', ' ') . ' HUF ' . $warning . '</td>';
  1112. /* $warning = $this->isWarning($earlierCommissionEUR);
  1113. print '<td style="text-align:center;">' . number_format($earlierCommissionEUR, 0, '.', ' ') . ' EUR ' . $warning . '</td>'; */
  1114. }
  1115. private function drawPayedRows($user_id, $payment_type)
  1116. {
  1117. $amounts = $this->getAllPaymenttype($user_id, $this->db, $payment_type);
  1118. foreach ($amounts as $amount) {
  1119. print '<td style="text-align:center;">' . number_format($amount['amount'], 0, '.', ' ') . ' ' . $amount['type'] . ' </td>';
  1120. }
  1121. }
  1122. function tableDrawerForHistory($allSalesUsers, $idmenu)
  1123. {
  1124. $rownum = 0;
  1125. foreach ($allSalesUsers as $user) {
  1126. $url = '/custom/financialreport/commissionhistory_list.php?user_id=' . $user['rowid'] . '&idmenu=' . $idmenu . '&payment_type=2&mainmenu=financialreport&leftmenu=';
  1127. $bgcolor = $this->setRowColor($rownum);
  1128. print '<tr style="height:30px; background-color: ' . $bgcolor . '">
  1129. <td><a style="display: block; width: 100%; height: 100%;" href="' . $url . '">' . $user['lastname'] . ' ' . $user['firstname'] . '</a></td>';
  1130. print '<td style="text-align: center;">' . $user['nickname'] . '</td>';
  1131. print '<td style="text-align: center;">' . $user['login'] . '</td>';
  1132. // 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.
  1133. $this->drawCurrentBalance($user['rowid']);
  1134. $this->drawPayedRows($user['rowid'], 2);
  1135. $this->drawPayedRows($user['rowid'], 0);
  1136. print '</tr>';
  1137. $rownum++;
  1138. }
  1139. }
  1140. function tableDrawerForDailyClosing($allSalesUsers, $idmenu)
  1141. {
  1142. $rownum = 0;
  1143. foreach ($allSalesUsers as $user) {
  1144. $url = '/custom/settlements/dailyclosing_card.php?user_id=' . $user['rowid'] . '&idmenu=' . $idmenu . '&mainmenu=settlements&leftmenu=';
  1145. $bgcolor = $this->setRowColor($rownum);
  1146. print '<tr style="height:30px; background-color: ' . $bgcolor . '">
  1147. <td><a style="display: block; width: 100%; height: 100%;" href="' . $url . '">' . $user['lastname'] . ' ' . $user['firstname'] . '</a></td>';
  1148. print '<td style="text-align: center;">' . $user['nickname'] . '</td>';
  1149. print '<td style="text-align: center;">' . $user['login'] . '</td>';
  1150. // 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.
  1151. $this->drawCurrentBalance($user['rowid']);
  1152. $this->drawPayedRows($user['rowid'], 2);
  1153. $this->drawPayedRows($user['rowid'], 0);
  1154. print '</tr>';
  1155. $rownum++;
  1156. }
  1157. }
  1158. function generateRef($payment_type)
  1159. {
  1160. return $this->getTypeOfPayment($payment_type) . '_' . dol_now() . '_' . rand(1000000, 9999999);
  1161. }
  1162. /* function checkBalance($user_id, $date)
  1163. {
  1164. $sql = "SELECT invoices FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
  1165. WHERE user_id = {$user_id}
  1166. AND date_creation BETWEEN '{$date} 00:00:00' AND '{$date} 23:59:59'
  1167. AND payment_type = 2
  1168. ";
  1169. $resultBalanceData = $this->db->query($sql);
  1170. $result = pg_fetch_all($resultBalanceData);
  1171. return is_array($result);
  1172. } */
  1173. function getOccassionOfThisPeriodByDateAndUserId($user_id, $from, $to)
  1174. {
  1175. return rand(100, 1000);
  1176. }
  1177. function createDataArrayForLoginLogotOccassionTable($results)
  1178. {
  1179. $array = [];
  1180. $i = 0;
  1181. foreach ($results as $record) {
  1182. if ($record->login_logout_status == 0) {
  1183. $array[$i]['login'] = date('Y-m-d H:i:s', $record->date_creation);
  1184. } else {
  1185. if (isset($record->date_creation)) {
  1186. $array[$i]['logout'] = date('Y-m-d H:i:s', $record->date_creation);
  1187. }
  1188. }
  1189. $i++;
  1190. }
  1191. return $array;
  1192. }
  1193. function createUserDataArray($array, $userOfGroups)
  1194. {
  1195. $userDataArray = [];
  1196. $count = count($array);
  1197. for ($k = 0; $k < $count; $k++) {
  1198. if (isset($array[$k]['login'])) {
  1199. if (!isset($userDataArray[$k - 1]['logout']) && $k != 0) {
  1200. $userDataArray[$k - 1]['logout'] = $array[$k]['login'] . '*';
  1201. }
  1202. $userDataArray[$k]['login'] = $array[$k]['login'];
  1203. }
  1204. if (isset($array[$k]['logout'])) {
  1205. $userDataArray[$k - 1]['logout'] = $array[$k]['logout'];
  1206. }
  1207. if ($k == $count - 1 && isset($deletedUsersArray[$userOfGroups['user_id']])) {
  1208. $userDataArray[$k]['logout'] = $array[$userOfGroups['user_id']];
  1209. }
  1210. }
  1211. return $userDataArray;
  1212. }
  1213. function updateUserDataArray($userDataArray, $deletedUsersArray, $userOfGroups, $commmissionhandler)
  1214. {
  1215. foreach ($userDataArray as $key => $period) {
  1216. $from = $period['login'];
  1217. $to = isset($period['logout']) ? $period['logout'] : (isset($deletedUsersArray[$userOfGroups['user_id']]) ? $deletedUsersArray[$userOfGroups['user_id']] : date('Y-m-d', dol_now()) . ' 23:59:59');
  1218. print $from . ' - ' . $to . '<br>';
  1219. if (isset($from)) {
  1220. $commission_HUF = $commmissionhandler->getOccassionOfThisPeriodByDateAndUserId_HUF($userOfGroups['user_id'], $from, $to);
  1221. $commission_EURToHUF = $commmissionhandler->getOccassionOfThisPeriodByDateAndUserId_EURToHUF($userOfGroups['user_id'], $from, $to);
  1222. $userDataArray[$key]['commission'] = $commission_HUF + $commission_EURToHUF;
  1223. }
  1224. }
  1225. return $userDataArray;
  1226. }
  1227. function getAmountOfCommissions($userDataArray)
  1228. {
  1229. $amount = 0;
  1230. foreach ($userDataArray as $record) {
  1231. $amount += intval($record);
  1232. }
  1233. return $amount;
  1234. }
  1235. function getInvoicesRowidFromFacture($user_id, $from, $to)
  1236. {
  1237. $invocesRowidArray = [];
  1238. $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "facture AS f WHERE fk_user_closing = {$user_id}
  1239. AND EXISTS (SELECT * FROM " . MAIN_DB_PREFIX . "bbus_bbticketinvoiceprinting as bbip WHERE bbip.fk_facture = f.rowid ORDER BY bbip.rowid DESC LIMIT 1)
  1240. AND date_closing BETWEEN '{$from}' AND '{$to}'";
  1241. //print $sql;
  1242. //exit;
  1243. $resultInvoicesData = $this->db->query($sql);
  1244. if ($this->db->num_rows($resultInvoicesData) != 0) {
  1245. $result = pg_fetch_all($resultInvoicesData);
  1246. foreach ($result as $value) {
  1247. $invocesRowidArray[] = $value['rowid'];
  1248. }
  1249. $invocesRowidString = implode(',', $invocesRowidArray);
  1250. }
  1251. $readyInvoices = $this->getAllComissionInvoicesOfUserInTheGroupFromUserInvoice($user_id, $from, $to);
  1252. //print $readyInvoices . '<br>';
  1253. //print $invocesRowidString . '<br>';
  1254. if (!empty($readyInvoices)) {
  1255. $invocesRowidString = $this->giveMeTheDifferenceInString($readyInvoices, $invocesRowidString);
  1256. }
  1257. //print $invocesRowidString . '<br>';
  1258. return $invocesRowidString;
  1259. }
  1260. function getInvoicesRowidFromFactureInAnIntervalByEveryUser($users, $from, $to, $exception)
  1261. {
  1262. $invocesRowidArray = [];
  1263. $sql = "SELECT f.rowid FROM " . MAIN_DB_PREFIX . "facture as f WHERE fk_user_closing IN({$users})";
  1264. if ($exception != '') {
  1265. $sql .= " AND rowid NOT IN({$exception})";
  1266. }
  1267. $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)
  1268. AND date_closing BETWEEN '{$from}' AND '{$to}'";
  1269. //print $sql . "\r\n";
  1270. $resultInvoicesData = $this->db->query($sql);
  1271. if ($this->db->num_rows($resultInvoicesData) != 0) {
  1272. $result = pg_fetch_all($resultInvoicesData);
  1273. foreach ($result as $value) {
  1274. $invocesRowidArray[] = $value['rowid'];
  1275. }
  1276. $invocesRowidString = implode(',', $invocesRowidArray);
  1277. }
  1278. return $invocesRowidString;
  1279. }
  1280. function getAllComissionInvoicesOfUserInTheGroupFromUserInvoice($user_id, $from, $to)
  1281. {
  1282. $arraytmp = [];
  1283. $invocesRowidString = '';
  1284. $userInvocesObj = new UserInvoice($this->db);
  1285. $result = $userInvocesObj->fetchAll('ASC', 'rowid', 0, 0, ['customsql' => "user_id = " . $user_id . " AND date_creation BETWEEN '" . $from . "' AND '" . $to . "'"]);
  1286. foreach ($result as $data) {
  1287. if (!empty($data->invoices) || $data->invoices != '') {
  1288. $array1 = explode(',', $data->invoices);
  1289. $arraytmp = array_merge($arraytmp, $array1);
  1290. }
  1291. }
  1292. $invocesRowidString = implode(',', $arraytmp);
  1293. return $invocesRowidString;
  1294. }
  1295. function giveMeTheDifferenceInString($readyInvoices, $invocesRowidString)
  1296. {
  1297. $string = '';
  1298. if ($readyInvoices != '' && $invocesRowidString != '') {
  1299. $array1 = explode(',', $readyInvoices);
  1300. $array2 = explode(',', $invocesRowidString);
  1301. /* print 'array1: ';
  1302. print_r($array1);
  1303. print '<br>';
  1304. print 'array2: ';
  1305. print_r($array2);
  1306. print '<br>'; */
  1307. $arrayDiff = array_diff($array2, $array1);
  1308. //$arrayDiff = array_diff($array1, $array2);
  1309. /* print 'Diff: ';
  1310. print_r($arrayDiff);
  1311. print '<br>';
  1312. print '<br>';
  1313. print '<br>';
  1314. */
  1315. //$arrayDiff = count($array2) > count($array1) ? array_diff($array2, $array1) : array_diff($array1, $array2);
  1316. $string = implode(',', $arrayDiff);
  1317. return $string;
  1318. }
  1319. return $string;
  1320. }
  1321. function getHtmlForConfirmWindow($commission)
  1322. {
  1323. $userData = [];
  1324. $userObj = new User($this->db);
  1325. foreach ($commission as $value) {
  1326. $itemData = explode('_', $value);
  1327. $userdata = $userObj->fetch($itemData[0]);
  1328. //print_r($userObj);exit;
  1329. $userData[$userObj->id]['name'] = $userObj->lastname . ' ' . $userObj->firstname . ' (' . $userObj->login . ') ' . $userObj->array_options['options_nickname'];
  1330. $summaHUF += $itemData[2];
  1331. }
  1332. $uniformHUF = $summaHUF / count($commission);
  1333. $array[] = $userData;
  1334. $array[] = $uniformHUF;
  1335. return $array;
  1336. }
  1337. function azosszesElemEgyezik($tomb)
  1338. {
  1339. $szamlalo = array_count_values($tomb);
  1340. $kulonbozoErtekekSzama = count($szamlalo);
  1341. return $kulonbozoErtekekSzama === 1;
  1342. }
  1343. function getUsersArray($data)
  1344. {
  1345. foreach ($data as $item) {
  1346. $itemData = explode('_', $item);
  1347. $usersArray[] = $itemData[0];
  1348. }
  1349. return $usersArray;
  1350. }
  1351. function checkUserInvoiceRecordAvailability($user_id)
  1352. {
  1353. $userInvoiceObj = new UserInvoice($this->db);
  1354. $now = dol_now();
  1355. $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'"]);
  1356. return $result;
  1357. }
  1358. function deleteUserFromUsersArrayTMPArray($key, $usersArrayTMP)
  1359. {
  1360. $index = array_search($key, $usersArrayTMP);
  1361. if ($index !== false) {
  1362. unset($usersArrayTMP[$index]);
  1363. }
  1364. return $usersArrayTMP;
  1365. }
  1366. function saveUserInvoiceRecord($usersArrayFilteredUsersFrom, $val, $uniformHUF, $settledInvoices)
  1367. {
  1368. global $user;
  1369. $userinvoice = new UserInvoice($this->db);
  1370. $currency = 0;
  1371. $userinvoice->ref = $this->generateRef(2);
  1372. $userinvoice->label = 'Jutalék/Commission ' . $usersArrayFilteredUsersFrom[$val];
  1373. $userinvoice->description = 'Összeg / Amount: ' . $uniformHUF . 'HUF.';
  1374. $userinvoice->user_id = $val;
  1375. $userinvoice->payment_type = 2;
  1376. $userinvoice->amount = $uniformHUF;
  1377. $userinvoice->currency = $currency;
  1378. $userinvoice->individual = 0;
  1379. $userinvoice->invoices = $settledInvoices;
  1380. $userinvoice->date_creation = strtotime($usersArrayFilteredUsersFrom[$val]);
  1381. $userinvoice->create($user);
  1382. }
  1383. function getAllDifferentDatesASC($from, $to)
  1384. {
  1385. foreach ($from as $fromvalue) {
  1386. foreach ($fromvalue as $value1) {
  1387. $allDates[] = $value1;
  1388. }
  1389. }
  1390. foreach ($to as $tovalue) {
  1391. foreach ($tovalue as $value1) {
  1392. $allDates[] = $value1;
  1393. }
  1394. }
  1395. $allDates = array_unique($allDates);
  1396. return $allDates;
  1397. }
  1398. function getQueryArray($from, $to)
  1399. {
  1400. $allDates = $this->getAllDifferentDatesASC($from, $to);
  1401. uasort($allDates, 'datumOsszehasonlitas');
  1402. $countAllDatesArray = count($allDates);
  1403. $allDates = array_values($allDates);
  1404. for ($i = 0; $i < $countAllDatesArray - 1; $i++) {
  1405. $queryArray[$i]['from'] = $allDates[$i];
  1406. $queryArray[$i]['to'] = $allDates[$i + 1];
  1407. }
  1408. return $queryArray;
  1409. }
  1410. function getAllComissionInvoicesOfUserInTheGroupFromUserInvoiceCreated($usersArray, $from, $to)
  1411. {
  1412. $userInvocesObj = new UserInvoice($this->db);
  1413. $result = $userInvocesObj->fetchAll('ASC', 'rowid', 0, 0, ['customsql' => "user_id IN(" . $usersArray . ") AND date_creation BETWEEN '" . $from . "' AND '" . $to . "'"]);
  1414. $all = [];
  1415. foreach ($result as $key => $value) {
  1416. //print $value->user_id . ' - ';
  1417. //print $value->invoices . "\r\n";
  1418. $arrayTmp = explode(',', $value->invoices);
  1419. $all = array_merge($all, $arrayTmp);
  1420. }
  1421. $all = array_unique($all);
  1422. $all = array_filter($all);
  1423. sort($all);
  1424. return implode(',', $all);
  1425. }
  1426. public function getGroupMemberHistory($user_id, $group_id, $date)
  1427. {
  1428. $groupMemberHistory = [];
  1429. $from = $date . ' 00:00:00';
  1430. $to = $date . ' 23:59:59';
  1431. $UserNaplo = new UserNaplo($this->db);
  1432. $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}'"]);
  1433. foreach ($result as $record) {
  1434. if ($record->status == 1) {
  1435. $groupMemberHistory[]['added'] = date("Y-m-d H:i:s", $record->date_creation);
  1436. } else {
  1437. $groupMemberHistory[]['deleted'] = date("Y-m-d H:i:s", $record->date_creation);
  1438. }
  1439. }
  1440. return $groupMemberHistory;
  1441. }
  1442. function getUsersByIdFromGroupUsers($id)
  1443. {
  1444. global $db;
  1445. $usersOfGroup = [];
  1446. if (isset($id)) {
  1447. $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
  1448. INNER JOIN " . MAIN_DB_PREFIX . "user AS u ON u.rowid = gu.fk_user
  1449. WHERE gu.fk_Settlements_group = {$id}";
  1450. $data = $db->query($sql);
  1451. if (!$data) {
  1452. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1453. setEventMessage('A csoporthoz rendelt felhasználók naplózási lekérdezésébe valami hiba csúszott.', 'errors');
  1454. return $usersOfGroup;
  1455. }
  1456. while ($row = pg_fetch_assoc($data)) {
  1457. $usersOfGroup[] = $row;
  1458. }
  1459. }
  1460. return $usersOfGroup;
  1461. }
  1462. function getDeletedHotelUsers($id)
  1463. {
  1464. global $db;
  1465. $deletedUsersArray = [];
  1466. if (isset($id)) {
  1467. $sql = "SELECT user_id, date_creation as date
  1468. FROM " . MAIN_DB_PREFIX . "settlements_usernaplo
  1469. WHERE group_user_id = {$id}
  1470. AND status = 0 ORDER BY date_creation ASC";
  1471. //print $sql;exit;
  1472. $data = $db->query($sql);
  1473. $dataArray = pg_fetch_all($data);
  1474. if (empty($dataArray)) {
  1475. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1476. return $deletedUsersArray;
  1477. }
  1478. foreach ($dataArray as $row) {
  1479. $deletedUsersArray[$row['user_id']][] = $row['date'];
  1480. }
  1481. }
  1482. return $deletedUsersArray;
  1483. }
  1484. function getUserdataFromNaploByUaserId($user_id, $userGroupId)
  1485. {
  1486. global $db;
  1487. $date = '';
  1488. $sql = "SELECT date_creation as date FROM " . MAIN_DB_PREFIX . "settlements_usernaplo
  1489. WHERE user_id = {$user_id} AND group_user_id = {$userGroupId} AND status = 1
  1490. ORDER BY rowid ASC LIMIT 1";
  1491. //print $sql;
  1492. $data = $db->query($sql);
  1493. $dataArray = pg_fetch_all($data);
  1494. if (empty($dataArray)) {
  1495. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1496. return $date;
  1497. }
  1498. foreach ($dataArray as $row) {
  1499. return $row['date'];
  1500. }
  1501. }
  1502. function createDaterangeString($daterange)
  1503. {
  1504. $array = explode(' - ', $daterange);
  1505. return str_replace('-', '.', $array[0]) . ' - ' . str_replace('-', '.', $array[1]);
  1506. }
  1507. function getUsersOfHotelGroup2($id, $daterange)
  1508. {
  1509. global $db;
  1510. $dates = explode(' - ', $daterange);
  1511. $now = dol_now();
  1512. $to = $dates[1] > date('Y-m-d', $now) ? date('Y-m-d', $now) : $dates[1];
  1513. $sql = "SELECT u.rowid, u.firstname, u. lastname, ue.user_category FROM " . MAIN_DB_PREFIX . "settlements_usernaplo AS un
  1514. INNER JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = un.user_id
  1515. INNER JOIN " . MAIN_DB_PREFIX . "user_extrafields AS ue ON ue.fk_object = u.rowid
  1516. WHERE un.date_creation BETWEEN '{$dates[0]} 00:00:00' AND '{$to} 23:59:59'
  1517. AND un.group_user_id = {$id}
  1518. GROUP BY u.firstname, u.lastname, ue.user_category, u.rowid";
  1519. $data = $db->query($sql);
  1520. $result = pg_fetch_all($data);
  1521. if (empty($result)) {
  1522. return [];
  1523. }
  1524. return $result;
  1525. }
  1526. function getUsersOfHotelGroup($id, $daterange, $entity)
  1527. {
  1528. global $db;
  1529. $array = [];
  1530. $dates = explode(' - ', $daterange);
  1531. $now = dol_now();
  1532. $to = $dates[1] > date('Y-m-d', $now) ? date('Y-m-d', $now) : $dates[1];
  1533. if (isset($id)) {
  1534. $sql = "SELECT u.rowid, u.firstname, u. lastname, ue.user_category FROM " . MAIN_DB_PREFIX . "facture AS f
  1535. INNER JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = f.fk_user_closing
  1536. INNER JOIN " . MAIN_DB_PREFIX . "user_extrafields AS ue ON ue.fk_object = u.rowid
  1537. INNER JOIN " . MAIN_DB_PREFIX . "facture_extrafields as fe ON fe.fk_object = f.rowid
  1538. WHERE f.date_closing BETWEEN '{$dates[0]} 00:00:00' AND '{$to} 23:59:59'
  1539. AND f.entity = {$entity}
  1540. AND fe.react_facture = {$id}
  1541. GROUP BY u.rowid, u.firstname, u. lastname, ue.user_category";
  1542. //print $sql;
  1543. $data = $db->query($sql);
  1544. $array = pg_fetch_all($data);
  1545. if (empty($result)) {
  1546. return $array;
  1547. }
  1548. }
  1549. return $array;
  1550. }
  1551. function getUsersList($id, $daterange, $entity)
  1552. {
  1553. global $db;
  1554. $string = '';
  1555. $result = $this->getUsersOfHotelGroup($id, $daterange, $entity);
  1556. foreach ($result as $row) {
  1557. $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>';
  1558. }
  1559. return $string;
  1560. }
  1561. function getUsersIdList($id, $daterange, $entity)
  1562. {
  1563. global $db;
  1564. $result = $this->getUsersOfHotelGroup($id, $daterange, $entity);
  1565. if (!empty($result)) {
  1566. foreach ($result as $row) {
  1567. $array[] = $row['rowid'];
  1568. }
  1569. return implode(',', $array);
  1570. }
  1571. return '';
  1572. }
  1573. function getAllAmountInPeriod($id, $daterange, $currency, $usersIdList, $entity)
  1574. {
  1575. //$entity = 1;
  1576. global $db;
  1577. $result = 0;
  1578. $dates = explode(' - ', $daterange);
  1579. $now = dol_now();
  1580. $to = $dates[1] > date('Y-m-d', $now) ? date('Y-m-d', $now) : $dates[1];
  1581. if (isset($id)) {
  1582. $sql = "SELECT sum(f.total_ttc) FROM " . MAIN_DB_PREFIX . "facture as f
  1583. INNER JOIN " . MAIN_DB_PREFIX . "facture_extrafields as fe ON fe.fk_object = f.rowid
  1584. WHERE f.paye = 1
  1585. AND f.date_closing BETWEEN '{$dates[0]} 00:00:00' AND '{$to} 23:59:59'";
  1586. if ($usersIdList !== '') {
  1587. $sql .= " AND f.fk_user_closing in($usersIdList)";
  1588. }
  1589. $sql .= " AND f.multicurrency_code = '{$currency}'
  1590. AND f.entity = {$entity}
  1591. AND fe.react_facture = {$id}";
  1592. //print $sql;
  1593. $data = $db->query($sql);
  1594. $result = pg_fetch_all($data);
  1595. return is_null($result[0]['sum']) ? 0 : $result[0]['sum'];
  1596. }
  1597. }
  1598. function getAllCommissionInPeriod($id, $daterange, $currency, $usersIdList, $entity)
  1599. {
  1600. global $db;
  1601. $commissionsArray = [];
  1602. $dates = explode(' - ', $daterange);
  1603. $now = dol_now();
  1604. $to = $dates[1] > date('Y-m-d', $now) ? date('Y-m-d', $now) : $dates[1];
  1605. if (isset($id)) {
  1606. $sql = "SELECT f.total_ttc, fe.commission
  1607. FROM " . MAIN_DB_PREFIX . "facture as f
  1608. INNER JOIN " . MAIN_DB_PREFIX . "facture_extrafields as fe ON fe.fk_object = f.rowid
  1609. WHERE f.paye = 1
  1610. AND f.date_closing BETWEEN '{$dates[0]} 00:00:00' AND '{$to} 23:59:59'";
  1611. if ($usersIdList !== '') {
  1612. $sql .= " AND f.fk_user_closing in($usersIdList)";
  1613. }
  1614. $sql .= " AND f.multicurrency_code = '{$currency}'
  1615. AND f.entity = '{$entity}'
  1616. AND fe.react_facture = {$id}";
  1617. //print $sql;exit;
  1618. $data = $db->query($sql);
  1619. $result = pg_fetch_all($data);
  1620. //print_r($result);
  1621. if (!empty($result)) {
  1622. foreach ($result as $row) {
  1623. $commissionValue = $this->getCommissionData($row['commission'], 0);
  1624. $commissionUnit = $this->getCommissionData($row['commission'], 1);
  1625. if ($commissionUnit == '%') {
  1626. $commissionsArray[] = ($row['total_ttc'] / 100) * $commissionValue;
  1627. } else {
  1628. $commissionsArray[] = $commissionValue;
  1629. }
  1630. }
  1631. }
  1632. return $this->getAmountOfCommissions($commissionsArray);
  1633. }
  1634. return 0;
  1635. }
  1636. private function getCommissionData($commission, $number)
  1637. {
  1638. $array = explode('_', $commission);
  1639. return $array[$number];
  1640. }
  1641. public function getAllHotels()
  1642. {
  1643. global $db;
  1644. $resultArray = [];
  1645. $hotelsObj = new Hotel($db);
  1646. $hotelsArray = $hotelsObj->fetchAll('ASC', 'label', 0, 0);
  1647. if (!empty($hotelsArray)) {
  1648. foreach ($hotelsArray as $hotelRecord) {
  1649. $resultArray[$hotelRecord->id] = $hotelRecord->label;
  1650. }
  1651. }
  1652. return $resultArray;
  1653. }
  1654. public function getGroupRefByID($id)
  1655. {
  1656. if (isset($id)) {
  1657. global $db;
  1658. $sql = "SELECT ref FROM " . MAIN_DB_PREFIX . "settlements_group WHERE rowid = {$id}";
  1659. $data = $db->query($sql);
  1660. if (!$data) {
  1661. dol_syslog("No group found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1662. }
  1663. while ($row = pg_fetch_assoc($data)) {
  1664. return $row['ref'];
  1665. }
  1666. }
  1667. return '';
  1668. }
  1669. public function getGroupEntityId($id)
  1670. {
  1671. if (isset($id)) {
  1672. global $db;
  1673. $sql = "SELECT fk_entity FROM " . MAIN_DB_PREFIX . "settlements_group WHERE rowid = {$id}";
  1674. $data = $db->query($sql);
  1675. if (!$data) {
  1676. dol_syslog("No group found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1677. }
  1678. while ($row = pg_fetch_assoc($data)) {
  1679. return $row['fk_entity'];
  1680. }
  1681. }
  1682. return null;
  1683. }
  1684. public function getGroupLabelById($id)
  1685. {
  1686. global $db;
  1687. $groupObj = new Group($db);
  1688. $groupObj->fetch($id);
  1689. return $groupObj->ref;
  1690. }
  1691. public function getFirstDateFromUserNaplo($id)
  1692. {
  1693. global $db;
  1694. $from = date("Y-m-d") . ' 00:00:00';
  1695. $to = date("Y-m-d H:i:s");
  1696. $sql = "SELECT un.date_creation FROM " . MAIN_DB_PREFIX . "settlements_usernaplo AS un
  1697. WHERE un.group_user_id = {$id} AND un.date_creation BETWEEN '{$from}' AND '{$to}' AND un.status = 1
  1698. ORDER BY un.date_creation ASC LIMIT 1";
  1699. //print $sql;exit;
  1700. $data = $db->query($sql);
  1701. if (!$data) {
  1702. dol_syslog("No group found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1703. }
  1704. while ($row = pg_fetch_all($data)) {
  1705. return $row[0]['date_creation'];
  1706. }
  1707. return null;
  1708. }
  1709. public function getNamedataFoTheUser($user_id)
  1710. {
  1711. global $db;
  1712. $sql = "SELECT u.firstname, u.lastname, u.login FROM " . MAIN_DB_PREFIX . "user AS u WHERE rowid = {$user_id}";
  1713. //print $sql;exit;
  1714. $data = $db->query($sql);
  1715. foreach (pg_fetch_all($data) as $userData) {
  1716. return $userData['firstname'] . ' ' . $userData['lastname'] . ' (' . $userData['login'] . ')';
  1717. }
  1718. }
  1719. public function checklogoutRecordInUserNaplo($user_id, $from, $id)
  1720. {
  1721. global $db;
  1722. $sql = "SELECT date_creation FROM " . MAIN_DB_PREFIX . "settlements_usernaplo
  1723. WHERE group_user_id = {$id}
  1724. AND user_id = {$user_id}
  1725. AND date_creation > '{$from}'
  1726. AND status = 0
  1727. ORDER BY date_creation ASC LIMIT 1";
  1728. $data = $db->query($sql);
  1729. while ($row = pg_fetch_assoc($data)) {
  1730. return $row['date_creation'];
  1731. }
  1732. }
  1733. public function getGTAndGUArray()
  1734. {
  1735. global $db;
  1736. $sql = "SELECT fk_groupid, fk_group_tools_id FROM " . MAIN_DB_PREFIX . "settlements_usergrouptoolgroup";
  1737. $result = $db->query($sql);
  1738. if (pg_num_rows($result) > 0) {
  1739. while ($row = pg_fetch_assoc($result)) {
  1740. $array[$row['fk_groupid']] = $row['fk_group_tools_id'];
  1741. }
  1742. return $array;
  1743. }
  1744. return [];
  1745. }
  1746. function getAllEntities()
  1747. {
  1748. $entitiesArray = [];
  1749. $sql = "SELECT rowid, label FROM " . MAIN_DB_PREFIX . "entity ORDER BY label ASC";
  1750. $data = $this->db->query($sql);
  1751. while ($row = pg_fetch_assoc($data)) {
  1752. $entitiesArray[$row['rowid']] = $row['label'];
  1753. }
  1754. return $entitiesArray;
  1755. }
  1756. function createPopoupBox($numberOfUsers, $usersArray, $id)
  1757. {
  1758. $popoupBox = '<div style="float:right; padding-bottom: 10px;" title="';
  1759. foreach ($usersArray as $users) {
  1760. $popoupBox .= '<span class=&quot;fas fa-user em080&quot; style=&quot; color: #a69944;&quot; cursor: pointer;></span>
  1761. <u class=&quot;paddingrightonly&quot;>' . $users['lastname'] . ' ' . $users['firstname'] . ' (' . $users['login'] . ')</u><br>';
  1762. }
  1763. $popoupBox .= '" class="classfortooltip"><div onclick="popupboxClick(' . $id . ')" class="groupColumn2ndLine">' . $numberOfUsers . '</div>';
  1764. return $popoupBox;
  1765. }
  1766. }