helper.class.php 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992
  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. return $invocesRowidString;
  1352. }
  1353. function giveMeTheDifferenceInString($readyInvoices, $invocesRowidString)
  1354. {
  1355. $string = '';
  1356. if ($readyInvoices != '' && $invocesRowidString != '') {
  1357. $array1 = explode(',', $readyInvoices);
  1358. $array2 = explode(',', $invocesRowidString);
  1359. /* print 'array1: ';
  1360. print_r($array1);
  1361. print '<br>';
  1362. print 'array2: ';
  1363. print_r($array2);
  1364. print '<br>'; */
  1365. $arrayDiff = array_diff($array2, $array1);
  1366. //$arrayDiff = array_diff($array1, $array2);
  1367. /* print 'Diff: ';
  1368. print_r($arrayDiff);
  1369. print '<br>';
  1370. print '<br>';
  1371. print '<br>';
  1372. */
  1373. //$arrayDiff = count($array2) > count($array1) ? array_diff($array2, $array1) : array_diff($array1, $array2);
  1374. $string = implode(',', $arrayDiff);
  1375. return $string;
  1376. }
  1377. return $string;
  1378. }
  1379. function getHtmlForConfirmWindow($commission)
  1380. {
  1381. $userData = [];
  1382. $userObj = new User($this->db);
  1383. foreach ($commission as $value) {
  1384. $itemData = explode('_', $value);
  1385. $userdata = $userObj->fetch($itemData[0]);
  1386. //print_r($userObj);exit;
  1387. $userData[$userObj->id]['name'] = $userObj->lastname . ' ' . $userObj->firstname . ' (' . $userObj->login . ') ' . $userObj->array_options['options_nickname'];
  1388. $summaHUF += $itemData[2];
  1389. }
  1390. $uniformHUF = $summaHUF / count($commission);
  1391. $array[] = $userData;
  1392. $array[] = $uniformHUF;
  1393. return $array;
  1394. }
  1395. function azosszesElemEgyezik($tomb)
  1396. {
  1397. $szamlalo = array_count_values($tomb);
  1398. $kulonbozoErtekekSzama = count($szamlalo);
  1399. return $kulonbozoErtekekSzama === 1;
  1400. }
  1401. function getUsersArray($data)
  1402. {
  1403. foreach ($data as $item) {
  1404. $itemData = explode('_', $item);
  1405. $usersArray[] = $itemData[0];
  1406. }
  1407. return $usersArray;
  1408. }
  1409. function checkUserInvoiceRecordAvailability($user_id)
  1410. {
  1411. $userInvoiceObj = new UserInvoice($this->db);
  1412. $now = dol_now();
  1413. $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'"]);
  1414. return $result;
  1415. }
  1416. function deleteUserFromUsersArrayTMPArray($key, $usersArrayTMP)
  1417. {
  1418. $index = array_search($key, $usersArrayTMP);
  1419. if ($index !== false) {
  1420. unset($usersArrayTMP[$index]);
  1421. }
  1422. return $usersArrayTMP;
  1423. }
  1424. function saveUserInvoiceRecord($usersArrayFilteredUsersFrom, $val, $uniformHUF, $settledInvoices)
  1425. {
  1426. global $user;
  1427. $userinvoice = new UserInvoice($this->db);
  1428. $currency = 0;
  1429. $userinvoice->ref = $this->generateRef(2);
  1430. $userinvoice->label = 'Jutalék/Commission ' . $usersArrayFilteredUsersFrom[$val];
  1431. $userinvoice->description = 'Összeg / Amount: ' . $uniformHUF . 'HUF.';
  1432. $userinvoice->user_id = $val;
  1433. $userinvoice->payment_type = 2;
  1434. $userinvoice->amount = $uniformHUF;
  1435. $userinvoice->currency = $currency;
  1436. $userinvoice->individual = 0;
  1437. $userinvoice->invoices = $settledInvoices;
  1438. $userinvoice->date_creation = strtotime($usersArrayFilteredUsersFrom[$val]);
  1439. $userinvoice->create($user);
  1440. }
  1441. function getAllDifferentDatesASC($from, $to)
  1442. {
  1443. foreach ($from as $fromvalue) {
  1444. foreach ($fromvalue as $value1) {
  1445. $allDates[] = $value1;
  1446. }
  1447. }
  1448. foreach ($to as $tovalue) {
  1449. foreach ($tovalue as $value1) {
  1450. $allDates[] = $value1;
  1451. }
  1452. }
  1453. $allDates = array_unique($allDates);
  1454. return $allDates;
  1455. }
  1456. function getQueryArray($from, $to)
  1457. {
  1458. $allDates = $this->getAllDifferentDatesASC($from, $to);
  1459. uasort($allDates, 'datumOsszehasonlitas');
  1460. $countAllDatesArray = count($allDates);
  1461. $allDates = array_values($allDates);
  1462. for ($i = 0; $i < $countAllDatesArray - 1; $i++) {
  1463. $queryArray[$i]['from'] = $allDates[$i];
  1464. $queryArray[$i]['to'] = $allDates[$i + 1];
  1465. }
  1466. return $queryArray;
  1467. }
  1468. function getAllComissionInvoicesOfUserInTheGroupFromUserInvoiceCreated($usersArray, $from, $to)
  1469. {
  1470. $userInvocesObj = new UserInvoice($this->db);
  1471. $result = $userInvocesObj->fetchAll('ASC', 'rowid', 0, 0, ['customsql' => "user_id IN(" . $usersArray . ") AND date_creation BETWEEN '" . $from . "' AND '" . $to . "'"]);
  1472. $all = [];
  1473. foreach ($result as $key => $value) {
  1474. //print $value->user_id . ' - ';
  1475. //print $value->invoices . "\r\n";
  1476. $arrayTmp = explode(',', $value->invoices);
  1477. $all = array_merge($all, $arrayTmp);
  1478. }
  1479. $all = array_unique($all);
  1480. $all = array_filter($all);
  1481. sort($all);
  1482. return implode(',', $all);
  1483. }
  1484. public function getGroupMemberHistory($user_id, $group_id, $date)
  1485. {
  1486. $groupMemberHistory = [];
  1487. $from = $date . ' 00:00:00';
  1488. $to = $date . ' 23:59:59';
  1489. $UserNaplo = new UserNaplo($this->db);
  1490. $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}'"]);
  1491. foreach ($result as $record) {
  1492. if ($record->status == 1) {
  1493. $groupMemberHistory[]['added'] = date("Y-m-d H:i:s", $record->date_creation);
  1494. } else {
  1495. $groupMemberHistory[]['deleted'] = date("Y-m-d H:i:s", $record->date_creation);
  1496. }
  1497. }
  1498. return $groupMemberHistory;
  1499. }
  1500. function getUsersByIdFromGroupUsers($id)
  1501. {
  1502. global $db;
  1503. $usersOfGroup = [];
  1504. if (isset($id)) {
  1505. $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
  1506. INNER JOIN " . MAIN_DB_PREFIX . "user AS u ON u.rowid = gu.fk_user
  1507. WHERE gu.fk_Settlements_group = {$id}";
  1508. $data = $db->query($sql);
  1509. if (!$data) {
  1510. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1511. setEventMessage('A csoporthoz rendelt felhasználók naplózási lekérdezésébe valami hiba csúszott.', 'errors');
  1512. return $usersOfGroup;
  1513. }
  1514. while ($row = pg_fetch_assoc($data)) {
  1515. $usersOfGroup[] = $row;
  1516. }
  1517. }
  1518. return $usersOfGroup;
  1519. }
  1520. function getDeletedHotelUsers($id)
  1521. {
  1522. global $db;
  1523. $deletedUsersArray = [];
  1524. if (isset($id)) {
  1525. $sql = "SELECT user_id, date_creation as date
  1526. FROM " . MAIN_DB_PREFIX . "settlements_usernaplo
  1527. WHERE group_user_id = {$id}
  1528. AND status = 0 ORDER BY date_creation ASC";
  1529. //print $sql;exit;
  1530. $data = $db->query($sql);
  1531. $dataArray = pg_fetch_all($data);
  1532. if (empty($dataArray)) {
  1533. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1534. return $deletedUsersArray;
  1535. }
  1536. foreach ($dataArray as $row) {
  1537. $deletedUsersArray[$row['user_id']][] = $row['date'];
  1538. }
  1539. }
  1540. return $deletedUsersArray;
  1541. }
  1542. function getUserdataFromNaploByUaserId($user_id, $userGroupId)
  1543. {
  1544. global $db;
  1545. $date = '';
  1546. $sql = "SELECT date_creation as date FROM " . MAIN_DB_PREFIX . "settlements_usernaplo
  1547. WHERE user_id = {$user_id} AND group_user_id = {$userGroupId} AND status = 1
  1548. ORDER BY rowid ASC LIMIT 1";
  1549. //print $sql;
  1550. $data = $db->query($sql);
  1551. $dataArray = pg_fetch_all($data);
  1552. if (empty($dataArray)) {
  1553. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1554. return $date;
  1555. }
  1556. foreach ($dataArray as $row) {
  1557. return $row['date'];
  1558. }
  1559. }
  1560. function createDaterangeString($daterange)
  1561. {
  1562. $array = explode(' - ', $daterange);
  1563. return str_replace('-', '.', $array[0]) . ' - ' . str_replace('-', '.', $array[1]);
  1564. }
  1565. function getUsersOfHotelGroup2($id, $daterange)
  1566. {
  1567. global $db;
  1568. $dates = explode(' - ', $daterange);
  1569. $now = dol_now();
  1570. $to = $dates[1] > date('Y-m-d', $now) ? date('Y-m-d', $now) : $dates[1];
  1571. $sql = "SELECT u.rowid, u.firstname, u. lastname, ue.user_category FROM " . MAIN_DB_PREFIX . "settlements_usernaplo AS un
  1572. INNER JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = un.user_id
  1573. INNER JOIN " . MAIN_DB_PREFIX . "user_extrafields AS ue ON ue.fk_object = u.rowid
  1574. WHERE un.date_creation BETWEEN '{$dates[0]} 00:00:00' AND '{$to} 23:59:59'
  1575. AND un.group_user_id = {$id}
  1576. GROUP BY u.firstname, u.lastname, ue.user_category, u.rowid";
  1577. $data = $db->query($sql);
  1578. $result = pg_fetch_all($data);
  1579. if (empty($result)) {
  1580. return [];
  1581. }
  1582. return $result;
  1583. }
  1584. function getUsersOfHotelGroup($id, $daterange, $entity)
  1585. {
  1586. global $db;
  1587. $array = [];
  1588. $dates = explode(' - ', $daterange);
  1589. $now = dol_now();
  1590. $to = $dates[1] > date('Y-m-d', $now) ? date('Y-m-d', $now) : $dates[1];
  1591. if (isset($id)) {
  1592. $sql = "SELECT u.rowid, u.firstname, u. lastname, ue.user_category FROM " . MAIN_DB_PREFIX . "facture AS f
  1593. INNER JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = f.fk_user_closing
  1594. INNER JOIN " . MAIN_DB_PREFIX . "user_extrafields AS ue ON ue.fk_object = u.rowid
  1595. INNER JOIN " . MAIN_DB_PREFIX . "facture_extrafields as fe ON fe.fk_object = f.rowid
  1596. WHERE f.date_closing BETWEEN '{$dates[0]} 00:00:00' AND '{$to} 23:59:59'
  1597. AND f.entity = {$entity}
  1598. AND fe.react_facture = {$id}
  1599. GROUP BY u.rowid, u.firstname, u. lastname, ue.user_category";
  1600. //print $sql;
  1601. $data = $db->query($sql);
  1602. $array = pg_fetch_all($data);
  1603. if (empty($result)) {
  1604. return $array;
  1605. }
  1606. }
  1607. return $array;
  1608. }
  1609. function getUsersList($id, $daterange, $entity)
  1610. {
  1611. global $db;
  1612. $string = '';
  1613. $result = $this->getUsersOfHotelGroup($id, $daterange, $entity);
  1614. foreach ($result as $row) {
  1615. $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>';
  1616. }
  1617. return $string;
  1618. }
  1619. function getUsersIdList($id, $daterange, $entity)
  1620. {
  1621. global $db;
  1622. $result = $this->getUsersOfHotelGroup($id, $daterange, $entity);
  1623. if (!empty($result)) {
  1624. foreach ($result as $row) {
  1625. $array[] = $row['rowid'];
  1626. }
  1627. return implode(',', $array);
  1628. }
  1629. return '';
  1630. }
  1631. function getAllAmountInPeriod($id, $daterange, $currency, $usersIdList, $entity)
  1632. {
  1633. //$entity = 1;
  1634. global $db;
  1635. $result = 0;
  1636. $dates = explode(' - ', $daterange);
  1637. $now = dol_now();
  1638. $to = $dates[1] > date('Y-m-d', $now) ? date('Y-m-d', $now) : $dates[1];
  1639. if (isset($id)) {
  1640. $sql = "SELECT sum(f.total_ttc) FROM " . MAIN_DB_PREFIX . "facture as f
  1641. INNER JOIN " . MAIN_DB_PREFIX . "facture_extrafields as fe ON fe.fk_object = f.rowid
  1642. WHERE f.paye = 1
  1643. AND f.date_closing BETWEEN '{$dates[0]} 00:00:00' AND '{$to} 23:59:59'";
  1644. if ($usersIdList !== '') {
  1645. $sql .= " AND f.fk_user_closing in($usersIdList)";
  1646. }
  1647. $sql .= " AND f.multicurrency_code = '{$currency}'
  1648. AND f.entity = {$entity}
  1649. AND fe.react_facture = {$id}";
  1650. //print $sql;
  1651. $data = $db->query($sql);
  1652. $result = pg_fetch_all($data);
  1653. return is_null($result[0]['sum']) ? 0 : $result[0]['sum'];
  1654. }
  1655. }
  1656. function getAllCommissionInPeriod($id, $daterange, $currency, $usersIdList, $entity)
  1657. {
  1658. global $db;
  1659. $commissionsArray = [];
  1660. $dates = explode(' - ', $daterange);
  1661. $now = dol_now();
  1662. $to = $dates[1] > date('Y-m-d', $now) ? date('Y-m-d', $now) : $dates[1];
  1663. if (isset($id)) {
  1664. $sql = "SELECT f.total_ttc, fe.commission
  1665. FROM " . MAIN_DB_PREFIX . "facture as f
  1666. INNER JOIN " . MAIN_DB_PREFIX . "facture_extrafields as fe ON fe.fk_object = f.rowid
  1667. WHERE f.paye = 1
  1668. AND f.date_closing BETWEEN '{$dates[0]} 00:00:00' AND '{$to} 23:59:59'";
  1669. if ($usersIdList !== '') {
  1670. $sql .= " AND f.fk_user_closing in($usersIdList)";
  1671. }
  1672. $sql .= " AND f.multicurrency_code = '{$currency}'
  1673. AND f.entity = '{$entity}'
  1674. AND fe.react_facture = {$id}";
  1675. //print $sql;exit;
  1676. $data = $db->query($sql);
  1677. $result = pg_fetch_all($data);
  1678. //print_r($result);
  1679. if (!empty($result)) {
  1680. foreach ($result as $row) {
  1681. $commissionValue = $this->getCommissionData($row['commission'], 0);
  1682. $commissionUnit = $this->getCommissionData($row['commission'], 1);
  1683. if ($commissionUnit == '%') {
  1684. $commissionsArray[] = ($row['total_ttc'] / 100) * $commissionValue;
  1685. } else {
  1686. $commissionsArray[] = $commissionValue;
  1687. }
  1688. }
  1689. }
  1690. return $this->getAmountOfCommissions($commissionsArray);
  1691. }
  1692. return 0;
  1693. }
  1694. private function getCommissionData($commission, $number)
  1695. {
  1696. $array = explode('_', $commission);
  1697. return $array[$number];
  1698. }
  1699. public function getAllHotels()
  1700. {
  1701. global $db;
  1702. $resultArray = [];
  1703. $hotelsObj = new Hotel($db);
  1704. $hotelsArray = $hotelsObj->fetchAll('ASC', 'label', 0, 0);
  1705. if (!empty($hotelsArray)) {
  1706. foreach ($hotelsArray as $hotelRecord) {
  1707. $resultArray[$hotelRecord->id] = $hotelRecord->label;
  1708. }
  1709. }
  1710. return $resultArray;
  1711. }
  1712. public function getGroupRefByID($id)
  1713. {
  1714. if (isset($id)) {
  1715. global $db;
  1716. $sql = "SELECT ref FROM " . MAIN_DB_PREFIX . "settlements_group WHERE rowid = {$id}";
  1717. $data = $db->query($sql);
  1718. if (!$data) {
  1719. dol_syslog("No group found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1720. }
  1721. while ($row = pg_fetch_assoc($data)) {
  1722. return $row['ref'];
  1723. }
  1724. }
  1725. return '';
  1726. }
  1727. public function getGroupEntityId($id)
  1728. {
  1729. if (isset($id)) {
  1730. global $db;
  1731. $sql = "SELECT fk_entity FROM " . MAIN_DB_PREFIX . "settlements_group WHERE rowid = {$id}";
  1732. $data = $db->query($sql);
  1733. if (!$data) {
  1734. dol_syslog("No group found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1735. }
  1736. while ($row = pg_fetch_assoc($data)) {
  1737. return $row['fk_entity'];
  1738. }
  1739. }
  1740. return null;
  1741. }
  1742. public function getGroupLabelById($id)
  1743. {
  1744. global $db;
  1745. $groupObj = new Group($db);
  1746. $groupObj->fetch($id);
  1747. return $groupObj->ref;
  1748. }
  1749. public function getFirstDateFromUserNaplo($id)
  1750. {
  1751. global $db;
  1752. $from = date("Y-m-d") . ' 00:00:00';
  1753. $to = date("Y-m-d H:i:s");
  1754. $sql = "SELECT un.date_creation FROM " . MAIN_DB_PREFIX . "settlements_usernaplo AS un
  1755. WHERE un.group_user_id = {$id} AND un.date_creation BETWEEN '{$from}' AND '{$to}' AND un.status = 1
  1756. ORDER BY un.date_creation ASC LIMIT 1";
  1757. //print $sql;exit;
  1758. $data = $db->query($sql);
  1759. if (!$data) {
  1760. dol_syslog("No group found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  1761. }
  1762. while ($row = pg_fetch_all($data)) {
  1763. return $row[0]['date_creation'];
  1764. }
  1765. return null;
  1766. }
  1767. public function getNamedataFoTheUser($user_id)
  1768. {
  1769. global $db;
  1770. $sql = "SELECT u.firstname, u.lastname, u.login FROM " . MAIN_DB_PREFIX . "user AS u WHERE rowid = {$user_id}";
  1771. //print $sql;exit;
  1772. $data = $db->query($sql);
  1773. foreach (pg_fetch_all($data) as $userData) {
  1774. return $userData['firstname'] . ' ' . $userData['lastname'] . ' (' . $userData['login'] . ')';
  1775. }
  1776. }
  1777. public function checklogoutRecordInUserNaplo($user_id, $from, $id)
  1778. {
  1779. global $db;
  1780. $sql = "SELECT date_creation FROM " . MAIN_DB_PREFIX . "settlements_usernaplo
  1781. WHERE group_user_id = {$id}
  1782. AND user_id = {$user_id}
  1783. AND date_creation > '{$from}'
  1784. AND status = 0
  1785. ORDER BY date_creation ASC LIMIT 1";
  1786. $data = $db->query($sql);
  1787. while ($row = pg_fetch_assoc($data)) {
  1788. return $row['date_creation'];
  1789. }
  1790. }
  1791. public function getGTAndGUArray()
  1792. {
  1793. global $db;
  1794. $sql = "SELECT fk_groupid, fk_group_tools_id FROM " . MAIN_DB_PREFIX . "settlements_usergrouptoolgroup";
  1795. $result = $db->query($sql);
  1796. if (pg_num_rows($result) > 0) {
  1797. while ($row = pg_fetch_assoc($result)) {
  1798. $array[$row['fk_groupid']] = $row['fk_group_tools_id'];
  1799. }
  1800. return $array;
  1801. }
  1802. return [];
  1803. }
  1804. function getAllEntities()
  1805. {
  1806. $entitiesArray = [];
  1807. $sql = "SELECT rowid, label FROM " . MAIN_DB_PREFIX . "entity ORDER BY label ASC";
  1808. $data = $this->db->query($sql);
  1809. while ($row = pg_fetch_assoc($data)) {
  1810. $entitiesArray[$row['rowid']] = $row['label'];
  1811. }
  1812. return $entitiesArray;
  1813. }
  1814. function createPopoupBox($numberOfUsers, $usersArray, $id)
  1815. {
  1816. $popoupBox = '<div style="float:right; padding-bottom: 10px;" title="';
  1817. foreach ($usersArray as $users) {
  1818. $popoupBox .= '<span class=&quot;fas fa-user em080&quot; style=&quot; color: #a69944;&quot; cursor: pointer;></span>
  1819. <u class=&quot;paddingrightonly&quot;>' . $users['lastname'] . ' ' . $users['firstname'] . ' (' . $users['login'] . ')</u><br>';
  1820. }
  1821. $popoupBox .= '" class="classfortooltip"><div onclick="popupboxClick(' . $id . ')" class="groupColumn2ndLine">' . $numberOfUsers . '</div>';
  1822. return $popoupBox;
  1823. }
  1824. }