helper.class.php.bak 85 KB

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