| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993 |
- <?php
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
- use PhpOffice\PhpSpreadsheet\Style\Alignment;
- require_once DOL_DOCUMENT_ROOT . '/includes/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Spreadsheet.php';
- require_once DOL_DOCUMENT_ROOT . '/includes/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php';
- require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/usernaplo.class.php';
- require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/hotel.class.php';
- require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/group.class.php';
- require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/commissionhandler.class.php';
- require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/api_curl.class.php';
- class HelperUserInvoice
- {
- use CurlApi;
- public $db;
- public function __construct(DoliDB $db)
- {
- $this->db = $db;
- $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"];
- }
- /**
- * Output the buttons to submit a creation/edit form
- *
- * @param string $save_label Alternative label for save button
- * @param string $cancel_label Alternative label for cancel button
- * @param array $morebuttons Add additional buttons between save and cancel
- * @param bool $withoutdiv Option to remove enclosing centered div
- * @param string $morecss More CSS
- * @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.
- * @return string Html code with the buttons
- */
- public function buttonsSaveCancel($save_label = 'Save', $cancel_label = 'Cancel', $cancelURL = '', $morebuttons = array(), $withoutdiv = 0, $morecss = '', $dol_openinpopup = '')
- {
- global $langs;
- $buttons = array();
- $save = array(
- 'name' => 'save',
- 'label_key' => $save_label,
- );
- if ($save_label == 'Create' || $save_label == 'Add') {
- $save['name'] = 'add';
- } elseif ($save_label == 'Modify') {
- $save['name'] = 'edit';
- }
- $cancel = array(
- 'name' => 'cancel',
- 'label_key' => 'Cancel',
- );
- !empty($save_label) ? $buttons[] = $save : '';
- if (!empty($morebuttons)) {
- $buttons[] = $morebuttons;
- }
- //!empty($cancel_label) ? $buttons[] = $cancel : '';
- $retstring = $withoutdiv ? '' : '<div class="center">';
- foreach ($buttons as $button) {
- $addclass = empty($button['addclass']) ? '' : $button['addclass'];
- $retstring .= '<input type="submit" class="button button-' . $button['name'] . ($morecss ? ' ' . $morecss : '') . ' ' . $addclass . '" name="' . $button['name'] . '" value="' . dol_escape_htmltag($langs->trans($button['label_key'])) . '">';
- }
- if ($cancel_label == "Cancel") {
- $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>';
- }
- $retstring .= $withoutdiv ? '' : '</div>';
- if ($dol_openinpopup) {
- $retstring .= '<!-- buttons are shown into a $dol_openinpopup=' . $dol_openinpopup . ' context, so we enable the close of dialog on cancel -->' . "\n";
- $retstring .= '<script>';
- $retstring .= 'jQuery(".button-cancel").click(function(e) {
- e.preventDefault(); console.log(\'We click on cancel in iframe popup ' . $dol_openinpopup . '\');
- window.parent.jQuery(\'#idfordialog' . $dol_openinpopup . '\').dialog(\'close\');
- });';
- $retstring .= '</script>';
- }
- return $retstring;
- }
- function getAllSales($userObj)
- {
- $salesUsers = [];
- $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";
- $result = $this->db->query($sql);
- while ($row = pg_fetch_assoc($result)) {
- $salesUsers[] = $row;
- }
- return $salesUsers;
- }
- function getAllSalesWithSQL($sql)
- {
- $salesUsers = [];
- $result = $this->db->query($sql);
- if ($this->db->num_rows($result) > 0) {
- while ($row = pg_fetch_assoc($result)) {
- $salesUsers[] = $row;
- }
- }
- return $salesUsers;
- }
- private function getAllPaymenttype($user_id, $db, $payment_type)
- {
- $sql = "SELECT 'HUF' AS type,
- SUM(amount) AS amount
- FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
- WHERE payment_type = {$payment_type} AND user_id = {$user_id} AND currency = 0";
- if ($payment_type != 1) {
- $sql .= " AND payed = 1";
- }
- /* $sql .= "UNION ALL
- SELECT 'EUR' AS type,
- SUM(amount) AS amount
- FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
- WHERE payment_type = {$payment_type} AND user_id = {$user_id} AND currency = 1"; */
- if ($payment_type != 1) {
- $sql .= " AND payed = 1";
- }
- $resultUserdata = $db->query($sql);
- return pg_fetch_all($resultUserdata);
- }
- function getAllCommissions($user_id, $db)
- {
- $sql = "SELECT 'HUF' AS type,
- SUM(amount) AS amount
- FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
- WHERE payment_type = 2 AND user_id = {$user_id} AND currency = 0
- UNION ALL
- SELECT 'EUR' AS type,
- SUM(amount) AS amount
- FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
- WHERE payment_type = 2 AND user_id = {$user_id} AND currency = 1";
- $resultUserdata = $db->query($sql);
- return pg_fetch_all($resultUserdata);
- }
- function getAllUnpaidCommissions($user_id, $db)
- {
- $sql = "SELECT 'HUF' AS type,
- SUM(amount) AS amount
- FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
- WHERE payment_type = 2 AND user_id = {$user_id} AND currency = 0 AND payed=0
- UNION ALL
- SELECT 'EUR' AS type,
- SUM(amount) AS amount
- FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
- WHERE payment_type = 2 AND user_id = {$user_id} AND currency = 1 AND payed=0";
- $resultUserdata = $db->query($sql);
- return pg_fetch_all($resultUserdata);
- }
- function getAllMinusInvoice($user_id, $db)
- {
- $sql = "SELECT 'HUF' AS type,
- SUM(amount) AS amount
- FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
- WHERE user_id = {$user_id} AND currency = 0 AND payed=0
- UNION ALL
- SELECT 'EUR' AS type,
- SUM(amount) AS amount
- FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
- WHERE user_id = {$user_id} AND currency = 1 AND payed=0";
- $resultUserdata = $db->query($sql);
- return pg_fetch_all($resultUserdata);
- }
- function createArray($daterange)
- {
- $dates = explode(" - ", $daterange);
- $startDate = new DateTime($dates[0]);
- $endDate = new DateTime($dates[1]);
- $dateArray = array();
- $currentDate = clone $startDate;
- while ($currentDate <= $endDate) {
- $dateArray[] = $currentDate->format('Y-m-d');
- $currentDate->modify('+1 day');
- }
- return $dateArray;
- }
- function getMonths()
- {
- global $langs;
- if ($langs->shortlang == 'hu') {
- return array(
- "01" => "Január",
- "02" => "Február",
- "03" => "Március",
- "04" => "Április",
- "05" => "Május",
- "06" => "Június",
- "07" => "Július",
- "08" => "Augusztus",
- "09" => "Szeptember",
- "10" => "Október",
- "11" => "November",
- "12" => "December"
- );
- } else {
- return array(
- "01" => "January",
- "02" => "February",
- "03" => "March",
- "04" => "April",
- "05" => "May",
- "06" => "June",
- "07" => "July",
- "08" => "August",
- "09" => "September",
- "10" => "Octóber",
- "11" => "November",
- "12" => "December"
- );
- }
- }
- function selectedMonths($year, $months, $honapok)
- {
- $selectedmonths = $year . ' - ';
- $count = count($months);
- $i = 1;
- foreach ($months as $month) {
- $selectedmonths .= $honapok[$month];
- if ($i < $count)
- $selectedmonths .= ', ';
- $i++;
- }
- return $selectedmonths;
- }
- private function getDateIntervalForExcel($year, $months)
- {
- $intervalArray = [];
- $from = $year . '-' . $months[0];
- $to = $year . '-' . end($months);
- }
- private function createStartDateForQuery($year, $month)
- {
- return $year . '-' . $month . '-' . '01 00:00:00';
- }
- private function createEndDateForQuery($year, $month)
- {
- $lastDayOfTheMonth = $this->getLastDayOfTheMonth($year, $month);
- return $year . '-' . $month . '-' . $lastDayOfTheMonth . ' 23:59:59';
- }
- private function getLastDayOfTheMonth($year, $month)
- {
- $lastDay = date("t", strtotime("$year-$month-01"));
- return $lastDay;
- }
- function createExcel($year, $months, $honapok)
- {
- $spreadsheet = new Spreadsheet();
- $felirat = $this->selectedMonths($year, $months, $honapok);
- $start_date = $this->createStartDateForQuery($year, min($months));
- $end_date = $this->createEndDateForQuery($year, max($months));
- //$dateInterval = $this->getDateIntervalForExcel($year, $months);
- $sql = "SELECT CONCAT(u.lastname, ' ', u.firstname) AS name, u.login, ue.tax_identification_number,
- COALESCE(login_count.record_count, 0) AS ledolgozott_napok_szama,
- COALESCE(payment_count_huf.total_amount_huf, 0) AS kifizetett_osszeg_huf
- /*COALESCE(payment_count_eur.total_amount_eur, 0) AS kifizetett_osszeg_eur*/
- FROM " . MAIN_DB_PREFIX . "user AS u
- INNER JOIN " . MAIN_DB_PREFIX . "user_extrafields as ue ON ue.fk_object = u.rowid
- LEFT JOIN (
- SELECT user_id, COUNT(DISTINCT DATE(date_creation)) AS record_count
- FROM " . MAIN_DB_PREFIX . "bbus_userloginnaplo
- WHERE date_creation BETWEEN '{$start_date}' AND '{$end_date}'
- GROUP By user_id
- ) AS login_count ON u.rowid = login_count.user_id
- LEFT JOIN (
- SELECT user_id, SUM(amount) AS total_amount_huf
- FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
- WHERE payment_type = 2 AND payed = 1 AND currency = 0 AND paymentdate BETWEEN '{$start_date}' AND '{$end_date}'
- GROUP BY user_id
- ) AS payment_count_huf ON u.rowid = payment_count_huf.user_id
- /*LEFT JOIN (
- SELECT user_id, SUM(amount) AS total_amount_eur
- FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
- WHERE payment_type = 2 AND payed = 1 AND currency = 1 AND paymentdate BETWEEN '{$start_date}' AND '{$end_date}'
- GROUP BY user_id
- ) AS payment_count_eur ON u.rowid = payment_count_eur.user_id*/
- WHERE ue.user_category = '1'
- ORDER BY name ASC;
- ";
- $resultUserdata = $this->db->query($sql);
- $allUsers = pg_fetch_all($resultUserdata);
- $sheet = $spreadsheet->getActiveSheet();
- $sheet->setTitle("{$felirat}");
- $sheet->setCellValue("A1", "Felhasználó");
- $sheet->setCellValue("B1", "Login");
- $sheet->setCellValue("C1", "Adóazonosító jel");
- $sheet->setCellValue("D1", "Ledolgozott napok száma");
- $sheet->setCellValue("E1", "Kifizetett jutalék HUF");
- /*$sheet->setCellValue("F1", "Kifizetett jutalék EUR");*/
- $i = 2;
- foreach ($allUsers as $user) {
- $sheet->setCellValue("A" . $i, $user['name']);
- $sheet->setCellValue("B" . $i, $user['login']);
- $sheet->setCellValue("C" . $i, $user['tax_identification_number']);
- $sheet->setCellValue("D" . $i, $user['ledolgozott_napok_szama']);
- $sheet->setCellValue("E" . $i, $user['kifizetett_osszeg_huf'] . ' HUF');
- /*$sheet->setCellValue("F" . $i, $user['kifizetett_osszeg_eur'] . ' EUR');*/
- $i++;
- }
- //$sheet->setCellValue("A1", "Hello World!");
- //$sheet->setCellValue("A1", "Hello World!");
- //$sheet->setCellValue("A2", "Goodbye World!");
- // (D) ADD NEW WORKSHEET + YOU CAN ALSO USE FORMULAS!
- /* $spreadsheet->createSheet();
- $sheet = $spreadsheet->getSheet(1);
- $sheet->setTitle("Formula");
- $sheet->setCellValue("A1", "5");
- $sheet->setCellValue("A2", "6");
- $sheet->setCellValue("A3", "=SUM(A1:A2)"); */
- $date = date('d-m-y-' . substr((string) microtime(), 1, 8));
- $date = str_replace(".", "", $date);
- $filename = "export_" . $date . ".xlsx";
- try {
- $writer = new Xlsx($spreadsheet);
- $writer->save($filename);
- $content = file_get_contents($filename);
- } catch (Exception $e) {
- exit($e->getMessage());
- }
- header("Content-Disposition: attachment; filename=" . $filename);
- unlink($filename);
- exit($content);
- }
- function createExcelInterval($daterange)
- {
- $spreadsheet = new Spreadsheet();
- $felirat = $daterange;
- $rangeArray = explode(' - ', $daterange);
- $start_date = $rangeArray[0] . ' 00:00:00';
- $end_date = $rangeArray[1] . ' 23:59:59';
- //$dateInterval = $this->getDateIntervalForExcel($year, $months);
- $sql = "SELECT CONCAT(u.lastname, ' ', u.firstname) AS name, u.login, ue.tax_identification_number,
- COALESCE(login_count.record_count, 0) AS ledolgozott_napok_szama,
- COALESCE(payment_count_huf.total_amount_huf, 0) AS kifizetett_osszeg_huf
- /*COALESCE(payment_count_eur.total_amount_eur, 0) AS kifizetett_osszeg_eur*/
- FROM " . MAIN_DB_PREFIX . "user AS u
- INNER JOIN " . MAIN_DB_PREFIX . "user_extrafields as ue ON ue.fk_object = u.rowid
- LEFT JOIN (
- SELECT user_id, COUNT(DISTINCT DATE(date_creation)) AS record_count
- FROM " . MAIN_DB_PREFIX . "bbus_userloginnaplo
- WHERE date_creation BETWEEN '{$start_date}' AND '{$end_date}'
- GROUP By user_id
- ) AS login_count ON u.rowid = login_count.user_id
- LEFT JOIN (
- SELECT user_id, SUM(amount) AS total_amount_huf
- FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
- WHERE payment_type = 2 AND payed = 1 AND currency = 0 AND paymentdate BETWEEN '{$start_date}' AND '{$end_date}'
- GROUP BY user_id
- ) AS payment_count_huf ON u.rowid = payment_count_huf.user_id
- /*LEFT JOIN (
- SELECT user_id, SUM(amount) AS total_amount_eur
- FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
- WHERE payment_type = 2 AND payed = 1 AND currency = 1 AND paymentdate BETWEEN '{$start_date}' AND '{$end_date}'
- GROUP BY user_id
- ) AS payment_count_eur ON u.rowid = payment_count_eur.user_id*/
- WHERE ue.user_category = '1'
- ORDER BY name ASC;
- ";
- $resultUserdata = $this->db->query($sql);
- $allUsers = pg_fetch_all($resultUserdata);
- $sheet = $spreadsheet->getActiveSheet();
- $sheet->setTitle("{$felirat}");
- $sheet->setCellValue("A1", "Felhasználó");
- $sheet->setCellValue("B1", "Login");
- $sheet->setCellValue("C1", "Adóazonosító jel");
- $sheet->setCellValue("D1", "Ledolgozott napok száma");
- $sheet->setCellValue("E1", "Kifizetett jutalék HUF");
- //$sheet->setCellValue("F1", "Kifizetett jutalék EUR");
- $i = 2;
- foreach ($allUsers as $user) {
- $sheet->setCellValue("A" . $i, $user['name']);
- $sheet->setCellValue("B" . $i, $user['login']);
- $sheet->setCellValue("C" . $i, $user['tax_identification_number']);
- $sheet->setCellValue("D" . $i, $user['ledolgozott_napok_szama']);
- $sheet->setCellValue("E" . $i, $user['kifizetett_osszeg_huf'] . ' HUF');
- // $sheet->setCellValue("F" . $i, $user['kifizetett_osszeg_eur'] . ' EUR');
- $i++;
- }
- //$sheet->setCellValue("A1", "Hello World!");
- //$sheet->setCellValue("A1", "Hello World!");
- //$sheet->setCellValue("A2", "Goodbye World!");
- // (D) ADD NEW WORKSHEET + YOU CAN ALSO USE FORMULAS!
- /* $spreadsheet->createSheet();
- $sheet = $spreadsheet->getSheet(1);
- $sheet->setTitle("Formula");
- $sheet->setCellValue("A1", "5");
- $sheet->setCellValue("A2", "6");
- $sheet->setCellValue("A3", "=SUM(A1:A2)"); */
- $date = date('d-m-y-' . substr((string) microtime(), 1, 8));
- $date = str_replace(".", "", $date);
- $filename = "export_" . $date . ".xlsx";
- try {
- $writer = new Xlsx($spreadsheet);
- $writer->save($filename);
- $content = file_get_contents($filename);
- } catch (Exception $e) {
- exit($e->getMessage());
- }
- header("Content-Disposition: attachment; filename=" . $filename);
- unlink($filename);
- exit($content);
- }
- function createExcelHotelReport($daterange, $id, $entity, $groups)
- {
- $spreadsheet = new Spreadsheet();
- $usersList = $this->getUsersOfHotelGroup($id, $daterange, $entity);
- $felirat = $daterange;
- $usersIdList = $this->getUsersIdList($id, $daterange, $entity);
- $amountHUF = $this->getAllAmountInPeriod($id, $daterange, 'HUF', $usersIdList, $entity);
- $amountEUR = $this->getAllAmountInPeriod($id, $daterange, 'EUR', $usersIdList, $entity);
- $commissionHUF = $this->getAllCommissionInPeriod($id, $daterange, 'HUF', $usersIdList, $entity);
- $commissionEUR = $this->getAllCommissionInPeriod($id, $daterange, 'EUR', $usersIdList, $entity);
- $hotelsArray = $this->getAllHotels();
- $hotelName = $hotelsArray[$groups[$id]['fk_hotel_id']];
- $style = [
- 'alignment' => [
- 'horizontal' => Alignment::HORIZONTAL_CENTER, // Vízszintes középre igazítás
- 'vertical' => Alignment::VERTICAL_CENTER, // Függőleges középre igazítás
- ],
- ];
- $styleBold = [
- 'font' => [
- 'bold' => true,
- ],
- ];
- $sheet = $spreadsheet->getActiveSheet();
- $sheet->getStyle('A1')->applyFromArray($styleBold);
- $sheet->getStyle('A3:B3')->applyFromArray($styleBold);
- $sheet->getStyle('A7')->applyFromArray($styleBold);
- $sheet->getStyle('A9:D9')->applyFromArray($styleBold);
- $sheet->getStyle('A1:D9')->applyFromArray($style);
- $sheet->setTitle("{$felirat}");
- $sheet->getColumnDimension('A')->setWidth(25);
- $sheet->getColumnDimension('B')->setWidth(25);
- $sheet->getColumnDimension('C')->setWidth(25);
- $sheet->getColumnDimension('D')->setWidth(25);
- $sheet->setCellValue("A1", strtoupper($hotelName));
- $sheet->mergeCells("A1:B1");
- $sheet->setCellValue("A2", $daterange);
- $sheet->mergeCells("A2:B2");
- $sheet->setCellValue("A3", "INCOMES");
- $sheet->setCellValue("B3", "COMMISSIONS");
- $sheet->setCellValue("A4", $this->correctNumber($amountHUF) . ' HUF');
- $sheet->setCellValue("B4", $this->correctNumber($commissionHUF) . ' HUF');
- $sheet->setCellValue("A5", $this->correctNumber($amountEUR) . ' EUR');
- $sheet->setCellValue("B5", $this->correctNumber($commissionEUR) . ' EUR');
- $sheet->setCellValue("A6", "");
- $sheet->setCellValue("B6", "");
- $sheet->setCellValue("A7", strtoupper($hotelName));
- $sheet->mergeCells("A7:D7");
- $sheet->setCellValue("A8", $daterange);
- $sheet->mergeCells("A8:D8");
- $sheet->setCellValue("A9", "USER");
- $sheet->setCellValue("B9", "GROUP");
- $sheet->setCellValue("C9", "AMOUNT OF SALES");
- $sheet->setCellValue("D9", "AMOUNT OF SALES");
- $i = 10;
- foreach ($usersList as $userVal) {
- $sheet->setCellValue("A" . $i, $userVal['firstname'] . ' ' . $userVal['lastname']);
- $sheet->setCellValue("B" . $i, ' (' . $this->userCategoryArray[$userVal['user_category']] . ')');
- $sheet->setCellValue("C" . $i, $this->correctNumber($this->getAllAmountInPeriod($id, $daterange, 'HUF', $userVal['rowid'], $entity)) . ' HUF');
- $sheet->setCellValue("D" . $i, $this->correctNumber($this->getAllAmountInPeriod($id, $daterange, 'EUR', $userVal['rowid'], $entity)) . ' EUR');
- $i++;
- }
- $sheet->getStyle('C10:C' . $i)->applyFromArray($style);
- $sheet->getStyle('D10:D' . $i)->applyFromArray($style);
- //$sheet->setCellValue("A1", "Hello World!");
- //$sheet->setCellValue("A1", "Hello World!");
- //$sheet->setCellValue("A2", "Goodbye World!");
- // (D) ADD NEW WORKSHEET + YOU CAN ALSO USE FORMULAS!
- /* $spreadsheet->createSheet();
- $sheet = $spreadsheet->getSheet(1);
- $sheet->setTitle("Formula");
- $sheet->setCellValue("A1", "5");
- $sheet->setCellValue("A2", "6");
- $sheet->setCellValue("A3", "=SUM(A1:A2)"); */
- $date = date('d-m-y-' . substr((string) microtime(), 1, 8));
- $date = str_replace(".", "", $date);
- $filename = "hotelexport_" . $hotelName . '_' . $date . ".xlsx";
- try {
- $writer = new Xlsx($spreadsheet);
- $writer->save($filename);
- $content = file_get_contents($filename);
- } catch (Exception $e) {
- exit($e->getMessage());
- }
- header("Content-Disposition: attachment; filename=" . $filename);
- unlink($filename);
- exit($content);
- }
- function createExcelMonthlyExport($daterange, $entity, $saledTickets)
- {
- $spreadsheet = new Spreadsheet();
- $felirat = $daterange;
- $entities = $this->getAllEntities();
- $entityName = str_replace(" ", "_", $entities[$entity]);
- $entityName = str_replace(".", "_", $entityName);
- $style = [
- 'alignment' => [
- 'horizontal' => Alignment::HORIZONTAL_CENTER, // Vízszintes középre igazítás
- 'vertical' => Alignment::VERTICAL_CENTER, // Függőleges középre igazítás
- ],
- ];
- $styleBold = [
- 'font' => [
- 'bold' => true,
- ],
- ];
- $sheet = $spreadsheet->getActiveSheet();
- $sheet->getStyle('A1')->applyFromArray($styleBold);
- $sheet->getStyle('A3:P3')->applyFromArray($styleBold);
- //$sheet->getStyle('A7')->applyFromArray($styleBold);
- //$sheet->getStyle('A9:D9')->applyFromArray($styleBold);
- //$sheet->getStyle('A1:D9')->applyFromArray($style);
- $sheet->setTitle("{$felirat}");
- $sheet->getColumnDimension('A')->setWidth(20);
- $sheet->getColumnDimension('B')->setWidth(20);
- $sheet->getColumnDimension('C')->setWidth(20);
- $sheet->getColumnDimension('D')->setWidth(20);
- $sheet->getColumnDimension('E')->setWidth(20);
- $sheet->getColumnDimension('F')->setWidth(20);
- $sheet->getColumnDimension('G')->setWidth(15);
- $sheet->getColumnDimension('H')->setWidth(15);
- $sheet->getColumnDimension('I')->setWidth(15);
- $sheet->getColumnDimension('J')->setWidth(15);
- $sheet->getColumnDimension('K')->setWidth(15);
- $sheet->getColumnDimension('L')->setWidth(15);
- $sheet->getColumnDimension('M')->setWidth(10);
- $sheet->getColumnDimension('N')->setWidth(15);
- $sheet->getColumnDimension('O')->setWidth(10);
- $sheet->getColumnDimension('P')->setWidth(10);
- $sheet->setCellValue("A1", strtoupper($entities[$entity]));
- $sheet->mergeCells("A1:B1");
- $sheet->setCellValue("A2", $daterange);
- $sheet->mergeCells("A2:B2");
- $sheet->setCellValue("A3", "Facture");
- $sheet->setCellValue("B3", "Type");
- $sheet->setCellValue("C3", "Environment");
- $sheet->setCellValue("D3", "VATnumber");
- $sheet->setCellValue("E3", "Creation date");
- $sheet->setCellValue("F3", "Completion date");
- $sheet->setCellValue("G3", "Payment deadline");
- $sheet->setCellValue("H3", "Net");
- $sheet->setCellValue("I3", "VAT");
- $sheet->setCellValue("J3", "Gross");
- $sheet->setCellValue("K3", "Net");
- $sheet->setCellValue("L3", "VAT");
- $sheet->setCellValue("M3", "Gross");
- $sheet->setCellValue("N3", "Currency");
- $sheet->setCellValue("O3", "PaymentMethod");
- $sheet->setCellValue("P3", "VAT %");
- $i = 4;
- foreach ($saledTickets as $item) {
- $mtht = $item->multicurrency_total_ht == $item->total_ht ? '' : number_format($item->multicurrency_total_ht, 4, ',', ' ');
- $mttva = $item->multicurrency_total_tva == $item->total_tva ? '' : number_format($item->multicurrency_total_ht, 4, ',', ' ');
- $mtttc = $item->multicurrency_total_ttc == $item->total_ttc ? '' : number_format($item->multicurrency_total_ttc, 4, ',', ' ');
- $sheet->setCellValue("A" . $i, $item->ref);
- $sheet->setCellValue("B" . $i, $this->getFectureType($item->type));
- $sheet->setCellValue("C" . $i, $item->label);
- $sheet->setCellValue("D" . $i, $item->value);
- $sheet->setCellValue("E" . $i, $item->datef);
- $sheet->setCellValue("F" . $i, $item->date_lim_reglement);
- $sheet->setCellValue("G" . $i, $item->datef);
- $sheet->setCellValue("H" . $i, number_format($item->total_ht, 4, ',', ' '));
- $sheet->setCellValue("I" . $i, number_format($item->total_tva, 4, ',', ' '));
- $sheet->setCellValue("J" . $i, number_format($item->total_ttc, 4, ',', ' '));
- $sheet->setCellValue("K" . $i, $mtht);
- $sheet->setCellValue("L" . $i, $mttva);
- $sheet->setCellValue("M" . $i, $mtttc);
- $sheet->setCellValue("N" . $i, $item->multicurrency_code);
- $sheet->setCellValue("O" . $i, $item->libelle);
- $sheet->setCellValue("P" . $i, number_format($item->tva_tx, 0) . ' %');
- $i++;
- }
- ## file name
- $date = date('d-m-y-' . substr((string) microtime(), 1, 8));
- $date = str_replace(".", "", $date);
- $filename = "monthlyexport_" . $entityName . '_' . $date . ".xlsx";
- try {
- $writer = new Xlsx($spreadsheet);
- $writer->save($filename);
- $content = file_get_contents($filename);
- } catch (Exception $e) {
- exit($e->getMessage());
- }
- header("Content-Disposition: attachment; filename=" . $filename);
- unlink($filename);
- exit($content);
- }
- function getTypeOfPayment($payment_type)
- {
- switch ($payment_type) {
- case '0':
- return 'prepay';
- case '1':
- return 'withhold';
- case '2':
- return 'commission';
- default:
- return 'prepay';
- }
- }
- function getFectureType($type)
- {
- global $langs;
- switch ($type) {
- case '0':
- return $langs->trans("Invoice");
- case '2':
- return $langs->trans("CreditNote");
- case '7':
- return $langs->trans("Receipt");
- case '8':
- return $langs->trans("ReceiptCreditNote");
- }
- }
- function getTitle($payment_type)
- {
- global $langs;
- switch ($payment_type) {
- case '0':
- return $langs->trans("UserInvoices");
- case '1':
- return $langs->trans("Withhold");
- case '2':
- return $langs->trans("Commissionpaidamount");
- default:
- return $langs->trans("UserInvoices");
- }
- }
- function getViewTplTitle($payment_type)
- {
- global $langs;
- switch ($payment_type) {
- case '0':
- return $langs->trans("Deposit");
- case '1':
- return $langs->trans("WithheldAmount");
- case '2':
- return $langs->trans("Commissionpaidamount");
- default:
- return $langs->trans("Deposit");
- }
- }
- function backPageSelector($payment_type)
- {
- switch ($payment_type) {
- case '0':
- return 'prepaymentsindex';
- case '1':
- return 'withholdingindex';
- case '2':
- return 'commissionindex';
- default:
- return 'prepaymentsindex';
- }
- }
- function createHTML($id)
- {
- $currencies = ['0' => 'HUF', '1' => 'EUR'];
- $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
- INNER JOIN " . MAIN_DB_PREFIX . "user AS user1 ON user1.rowid = ui.fk_user_creat
- INNER JOIN " . MAIN_DB_PREFIX . "user AS user2 ON user2.rowid = ui.user_id
- WHERE ui.rowid={$id}";
- //print $sql;
- $resultUserdata = $this->db->query($sql);
- $UserInvoice = pg_fetch_assoc($resultUserdata);
- $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>';
- $result .= '<div> </div>';
- $result .= '<tr><td>' . $UserInvoice['creatorlastname'] . ' ' . $UserInvoice['creatorfirstname'] . ' - ' . $UserInvoice['creatorlogin'] . '</td><td style="text-align: right;">' . $UserInvoice['lastname'] . ' ' . $UserInvoice['firstname'] . ' - ' . $UserInvoice['userlogin'] . '</td></tr></table>';
- $result .= '<div style="padding-top: 100px;"> </div>';
- $result .= '<table style="width:100%">';
- $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>';
- $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>';
- $result .= '</table>';
- $result .= '<div style="padding-top: 100px;"> </div>';
- $result .= '<div style="width:100%; text-align: left;">Budapest, Bajcsy-Zsilinszky út 17, 1065</div>';
- $result .= '<div style="width:100%; text-align: left;">' . $UserInvoice['paymentdate'] . '</div>';
- $result .= '<div style="padding-top: 100px;"> </div>';
- $result .= '<table style="width:100%; text-align:right;">';
- $result .= '</table>';
- $result .=
- '<table style="width:100%">
- <tr>
- <td>_________________________________</td>
- <td>_________________________________</td>
- </tr>
- <tr>
- <td style="text-align: center;">Átadó aláírása <br> (Donor / Giver)</td>
- <td style="text-align: center;">Átvevő aláírása <br> (Recipient / Receiver)</td>
- </tr>
- </table>';
- return $result;
- }
- function createHTMLForSettlement($dataArray)
- {
- $result = '
- <table style="width:100%; text-align: center;">
- <tr style="font-weight: bold;">
- <td>Jutalék / Commisson</td>
- </tr>
- <tr><td> </td></tr>
- <tr style="background-color:lightgrey; font-weight: bold;">
- <td>Name of group</td>
- </tr>
- <tr>
- <td>' . $dataArray['GroupName'] . '</td>
- </tr>
- <tr><td> </td></tr>
- <tr style="background-color:lightgrey; font-weight: bold;">
- <td>Interval</td>
- </tr>
- <tr>
- <td>' . $dataArray['Interval'] . '</td>
- </tr>
- <tr><td> </td></tr>
- <tr style="background-color:lightgrey; font-weight: bold;">
- <td>Total amount</td>
- </tr>
- <tr>
- <td>' . $dataArray['FullAmount'] . ' HUF</td>
- </tr>
- <tr><td> </td></tr>
- <tr style="background-color:lightgrey; font-weight: bold;">
- <td>Data of Users</td>
- </tr>
- </table>';
- $result .= '
- <table>';
- foreach ($dataArray['UsersData'] as $userdata) {
- $result .= '<tr><td style="font-weight: bold;">User: </td><td style="font-style: italic;">' . $userdata['namedata'] . '</td></tr>';
- $result .= '<tr><td style="font-weight: bold;">Amount: </td><td style="font-style: italic;">' . $userdata['amount'] . ' HUF</td></tr>';
- //$result .= '<tr><td style="font-weight: bold;">Invoices: </td><td style="font-style: italic;">' . $userdata['invoices'] . '</td></tr>';
- $result .= '<tr><td> </td><td> </td></tr>';
- }
- $result .= '</table>';
- return $result;
- }
- function checkinterval($db)
- {
- $id = GETPOST('id', 'int');
- $interval_startyear = GETPOST('interval_startyear', 'int');
- $interval_startmonth = GETPOST('interval_startmonth', 'int');
- $interval_startday = GETPOST('interval_startday', 'int');
- $interval_starthour = GETPOST('interval_starthour', 'int');
- $interval_startmin = GETPOST('interval_startmin', 'int');
- $interval_startsec = GETPOST('interval_startsec', 'int');
- $interval_endyear = GETPOST('interval_endyear', 'int');
- $interval_endmonth = GETPOST('interval_endmonth', 'int');
- $interval_endday = GETPOST('interval_endday', 'int');
- $interval_endhour = GETPOST('interval_endhour', 'int');
- $interval_endmin = GETPOST('interval_endmin', 'int');
- $startdate = $interval_startyear . '-' . $interval_startmonth . '-' . $interval_startday . ' ' . $interval_starthour . ':' . $interval_startmin . ':' . $interval_startsec;
- $enddate = $interval_endyear . '-' . $interval_endmonth . '-' . $interval_endday . ' ' . $interval_endhour . ':' . $interval_endmin . ':59';
- if ($id) {
- $sql = "SELECT *
- FROM " . MAIN_DB_PREFIX . "financialreport_commissioninterval
- WHERE rowid <> {$id}
- AND '{$startdate}' BETWEEN interval_start AND interval_end
- OR rowid <> {$id} AND '{$enddate}' BETWEEN interval_start AND interval_end
- ";
- $result = $db->query($sql);
- return $db->num_rows($result) != 0;
- } else {
- $sql = "SELECT *
- FROM " . MAIN_DB_PREFIX . "financialreport_commissioninterval
- WHERE
- '{$startdate}' BETWEEN interval_start AND interval_end
- OR '{$enddate}' BETWEEN interval_start AND interval_end
- ";
- $result = $db->query($sql);
- if ($result) {
- return $db->num_rows($result) != 0;
- } else {
- return false;
- }
- }
- }
- public function getEntities($entitiesArrayIsEmpty = false, $entities, $entitiesArray)
- {
- if ($entitiesArrayIsEmpty) {
- $array = [];
- foreach ($entities as $key => $value) {
- $array[] = $key;
- }
- $selectedEntities = implode(', ', $array);
- } else {
- $array = [];
- foreach ($entitiesArray as $entity) {
- if ($entity)
- $array[] = $entity;
- }
- $selectedEntities = implode(', ', $array);
- }
- return $selectedEntities;
- }
- function getAllGroupsFromGroupClass($selectedEntities)
- {
- global $db;
- $groups = [];
- $sql = "SELECT rowid, ref FROM " . MAIN_DB_PREFIX . "settlements_group WHERE hotelgroup IS NULL ";
- if ($selectedEntities != '') {
- $sql .= " AND fk_entity IN ({$selectedEntities})";
- }
- $sql .= "ORDER BY ref ASC";
- $data = $db->query($sql);
- if (!$data) {
- dol_syslog("No group found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
- setEventMessage('A csoport tábla lekérdezése sikertelen volt.', 'errors');
- return $groups;
- }
- while ($row = pg_fetch_assoc($data)) {
- $groups[$row['rowid']] = $row['ref'];
- }
- return $groups;
- }
- function getAllHotelGroupsFromGroupClass($db)
- {
- $groups = [];
- $sql = "SELECT g.rowid, g.ref, g.fk_entity, gh.fk_hotel_id
- FROM " . MAIN_DB_PREFIX . "settlements_group AS g
- INNER JOIN " . MAIN_DB_PREFIX . "settlements_grouphotels as gh ON gh.fk_group_id = g.rowid
- WHERE g.hotelgroup IS NOT NULL ORDER BY ref ASC";
- //$sql = "SELECT rowid, ref, fk_entity FROM " . MAIN_DB_PREFIX . "settlements_group WHERE hotelgroup IS NOT NULL ORDER BY ref ASC";
- //print $sql;exit;
- $data = $db->query($sql);
- if (!$data) {
- dol_syslog("No group found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
- setEventMessage('A csoport tábla lekérdezése sikertelen volt.', 'errors');
- return $groups;
- }
- while ($row = pg_fetch_assoc($data)) {
- $groups[$row['rowid']] = ["ref" => $row['ref'], "entity" => $row['fk_entity'], "fk_hotel_id" => $row['fk_hotel_id']];
- }
- return $groups;
- }
- function getGroupHotels()
- {
- global $db;
- $groupHotels = [];
- $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
- INNER JOIN " . MAIN_DB_PREFIX . "settlements_group AS g ON g.rowid = gh.fk_group_id
- INNER JOIN " . MAIN_DB_PREFIX . "settlements_hotel AS h ON h.rowid = gh.fk_hotel_id
- ORDER BY h.label ASC";
- $data = $db->query($sql);
- while ($row = pg_fetch_assoc($data)) {
- $groupHotels[] = $row;
- }
- return $groupHotels;
- }
- function getUsersByIdWithDateCol2($db, $id, $date)
- {
- $usersOfGroup = [];
- $date = date('Y-m-d', strtotime("-20 day", strtotime($date)));
- /* $sqlLastLogin = "SELECT date_creation FROM llx_settlements_usernaplo WHERE status = 1 AND user_id = $id ORDER BY date_creation DESC LIMIT 1";
- $result = $db->query($sqlLastLogin);
- if($db->num_rows($result) > 0){
- while($row = $db->fetch_object($result)){
- $date = $row->date_creation;
- }
- }else{
- $date = date('Y-m-d', strtotime("-20 day", dol_now()));
- $date = $date . ' 00:00:00';
- } */
- $dateNow = date('Y-m-d H:i:s', dol_now());
- if (isset($id)) {
- $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
- INNER JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = un.user_id
- WHERE un.group_user_id = {$id} AND un.date_creation BETWEEN '{$date} 00:00:00' AND '{$dateNow}' AND un.status = 1
- GROUP BY un.user_id, u.firstname, u.lastname, u.login ORDER BY u.lastname";
- $data = $db->query($sql);
- if (!$data) {
- dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
- setEventMessage('A csoporthoz rendelt felhasználók naplózási lekérdezésébe valami hiba csúszott.', 'errors');
- return $usersOfGroup;
- }
- while ($row = pg_fetch_assoc($data)) {
- $usersOfGroup[] = $row;
- }
- }
- return $usersOfGroup;
- }
- /**
- * @param int $id Group ID
- */
- function getUsersByIdWithDate($db, $id, $date)
- {
- $usersOfGroup = [];
- $date = date('Y-m-d', strtotime("-20 day", strtotime($date)));
- $dateNow = date('Y-m-d H:i:s', dol_now());
- if (isset($id)) {
- $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
- INNER JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = un.user_id
- WHERE un.group_user_id = {$id} AND un.date_creation BETWEEN '{$date} 00:00:00' AND '{$dateNow}' AND un.status = 1
- GROUP BY un.user_id, u.firstname, u.lastname, u.login, un.date_creation ORDER BY u.lastname";
- //print $sql.'<br>';
- $data = $db->query($sql);
- if (!$data) {
- dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
- setEventMessage('A csoporthoz rendelt felhasználók naplózási lekérdezésébe valami hiba csúszott.', 'errors');
- return $usersOfGroup;
- }
- while ($row = pg_fetch_assoc($data)) {
- $usersOfGroup[] = $row;
- }
- }
- return $usersOfGroup;
- }
- function getDeletedUsers($db, $id, $date)
- {
- $deletedUsersArray = [];
- $date = date('Y-m-d', strtotime("-1 day", strtotime($date)));
- $dateNow = date('Y-m-d H:i:s', dol_now());
- //print $id;
- //$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 ";
- $sql = "SELECT user_id, date_creation as date
- FROM " . MAIN_DB_PREFIX . "settlements_usernaplo
- WHERE group_user_id = {$id}
- AND date_creation BETWEEN '{$date} 00:00:00' AND '{$dateNow}'
- AND status = 0 ORDER BY date_creation ASC";
- //print $sql;
- //print '<br>';
- $data = $db->query($sql);
- $dataArray = pg_fetch_all($data);
- if (empty($dataArray)) {
- dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
- return $deletedUsersArray;
- }
- foreach ($dataArray as $row) {
- $deletedUsersArray[$row['user_id']][] = $row['date'];
- }
- return $deletedUsersArray;
- }
- function getSum($db, $currency, $id, $users, $date = null)
- {
- $sum = [];
- foreach ($users as $user) {
- $usersArray[] = $user['user_id'];
- }
- $usersString = implode(',', $usersArray);
- $sql = "SELECT SUM(total_ht) as total_ht, SUM(total_tva) as total_tva, SUM(total_ttc) as total_ttc
- FROM " . MAIN_DB_PREFIX . "facture
- WHERE fk_user_closing IN({$usersString})
- AND fk_statut = 2
- AND multicurrency_code = '{$currency}'
- AND date_closing BETWEEN '{$date} 00:00:00' AND '{$date} 23:59:59'";
- //print $sql;
- $data = $db->query($sql);
- if (!$data) {
- dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
- setEventMessage('A számlák összesítésének számításába valami hiba csúszott.', 'errors');
- return $sum;
- }
- $dataArray = pg_fetch_all($data);
- foreach ($dataArray as $row) {
- $sum[] = $row;
- }
- return $sum;
- }
- function correctNumber($number)
- {
- $integerPart = floor($number);
- $formattedNumber = number_format($integerPart, 0, '.', ' ');
- return $formattedNumber;
- }
- function getFullBalance($user_id, $db)
- {
- $sql = "SELECT
- currency,
- SUM(CASE WHEN payed = 0 AND payment_type = 2 THEN amount ELSE 0 END) -
- SUM(CASE WHEN payed = 1 AND payment_type = 0 THEN amount ELSE 0 END) -
- SUM(CASE WHEN payment_type = 1 THEN amount ELSE 0 END) AS amount
- FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
- WHERE user_id = {$user_id}
- GROUP BY currency;";
- //print $sql;exit;
- $resultUserdata = $db->query($sql);
- return pg_fetch_all($resultUserdata);
- }
- private function isWarning($amount)
- {
- return $amount < 0 ? '<font style="color: red;"> <span class="fa fa-exclamation pictofixedwidth"></span> </font>' : '';
- }
- private function getBgColor($amount)
- {
- return $amount < 0 ? 'red' : 'green';
- }
- function tableDrawer($allSalesUsers, $db, $idmenu, $payment_type)
- {
- $rownum = 0;
- foreach ($allSalesUsers as $user) {
- $url = '/custom/financialreport/userinvoice_list.php?user_id=' . $user['rowid'] . '&idmenu=' . $idmenu . '&payment_type=' . $payment_type . '&mainmenu=financialreport&leftmenu=';
- $bgcolor = $this->setRowColor($rownum);
- print '<tr style="height:30px; background-color: ' . $bgcolor . '">
- <td><a style="display: block; width: 100%; height: 100%;" href="' . $url . '">' . $user['lastname'] . ' ' . $user['firstname'] . '</a></td>';
- print '<td style="text-align: center;">' . $user['nickname'] . '</td>';
- print '<td style="text-align: center;">' . $user['login'] . '</td>';
- $this->drawCurrentBalance($user['rowid']);
- $this->drawPayedRows($user['rowid'], $payment_type);
- print '</tr>';
- $rownum++;
- }
- }
- function tableDrawerForBasicCommission($allSalesUsers, $db, $idmenu, $year, $month)
- {
- global $langs;
- $rownum = 0;
- $percentage = 0;
- $commmissionhandler = new CommissionHandler();
- foreach ($allSalesUsers as $user) {
- $amountHUF = $commmissionhandler->getCommisonByUserIdForAMonth($user['rowid'], $year, $month);
- $amount = $amountHUF;
- $userCommissionMinimumAmount = $commmissionhandler->getUserMinimumCommission($user['rowid']);
- $suplement = $userCommissionMinimumAmount - $amount < 0 ? 0 : $userCommissionMinimumAmount - $amount;
- $bgcolor = $this->setRowColor($rownum);
- $percentage = $this->getPercentage($userCommissionMinimumAmount, $amount);
- $amountcolor = $amount < $userCommissionMinimumAmount ? 'red' : 'lightgreen';
- $fontcolor = $percentage < 4 || $amount >= $userCommissionMinimumAmount ? 'black' : 'white';
- $makeUpToValue = $user['rowid'] . '|' . $suplement . '|' . $year . '|' . $month . '|' . $user['lastname'] . ' ' . $user['firstname'];
- $buttondisplay = $suplement > 0 ? 'style="display:block;"' : 'style="display:none;"';
- $makeUpToButton = strtotime($year . '-' . $month) < strtotime(date('Y-m')) ? '<td style="padding-left: 10px; padding-right: 10px;">
- <button ' . $buttondisplay . ' id="confirmmakeupto" name="confirmmakeupto" type="submit" value="' . $makeUpToValue . '">' . $langs->trans('MakeUpTo') . '</button>
- </td>' : '<td> </td>';
- //$url = '/custom/financialreport/userinvoicebasiccommission_list.php?user_id=' . $user['rowid'] . '&idmenu=' . $idmenu . '&mainmenu=financialreport&leftmenu=';
- print '<tr style="height:30px; background-color: ' . $bgcolor . '">';
- 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>';
- print '<td style="width: 10%; text-align: center;">' . $user['nickname'] . '</td>';
- print '<td style="width: 10%; text-align: center;">' . $this->correctNumber($userCommissionMinimumAmount) . ' HUF</td>';
- print '<td style="width: 10%; text-align: center; color:red;">' . $this->correctNumber($suplement) . ' HUF</td>';
- 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>';
- print $makeUpToButton;
- print '</tr>';
- $rownum++;
- }
- }
- function getPercentage($minAmount, $amount)
- {
- if ($minAmount != 0) {
- $percentage = ($amount / $minAmount) * 100;
- if ($percentage > 100) {
- $percentage = 100;
- }
- } else {
- $percentage = $amount == 0 ? 0 : 100;
- }
- return $percentage;
- }
- private function drawCurrentBalanceForTpls($amount, $currency)
- {
- global $langs;
- $color = $this->getBgColor($amount);
- print '<div style="flex: 1; text-align: center;">
- <h3>' . $langs->trans("CurrentBalance") . ' ' . $currency . '</h3>
- <p style="background-color:' . $color . '; color:white;">' . number_format($amount, 0, '.', ' ') . ' ' . $currency . '</p>
- </div>';
- }
- private function drawMinimumCommissionForTpls($amount, $currency)
- {
- global $langs;
- $color = $this->getBgColor($amount);
- print '<div style="flex: 1; text-align: center;">
- <h3>' . $langs->trans("MinimumCommission") . ' ' . $currency . '</h3>
- <p style="background-color:' . $color . '; color:white;">' . number_format($amount, 0, '.', ' ') . ' ' . $currency . '</p>
- </div>';
- }
- function tableDrawerForViewTpls($user_id, $db, $userData, $payment_type)
- {
- global $langs;
- 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>';
- print '<div></div>';
- $balance = $this->getFullBalance($user_id, $db);
- $earlierCommissionHUF = $balance[0]['amount'] == null ? 0 : $balance[0]['amount'];
- print '<div style="display: flex; width: 100%;">';
- $this->drawCurrentBalanceForTpls($earlierCommissionHUF, 'HUF');
- $amounts = $this->getAllPaymenttype($user_id, $db, $payment_type);
- foreach ($amounts as $amount) {
- print '<div style="flex: 1; text-align: center;">
- <h3>' . $this->getViewTplTitle($payment_type) . ' ' . $amount['type'] . '</h3>
- <p>' . number_format($amount['amount'], 0, '.', ' ') . ' ' . $amount['type'] . '</p>
- </div>';
- }
- print '</div>';
- if ($payment_type == 2) {
- print '<div></div>';
- $minimumCommission = $this->getminimumCommissionGorUser($user_id);
- print '<div style="display: flex; width: 100%;">';
- $this->drawMinimumCommissionForTpls($minimumCommission, 'HUF');
- print '</div>';
- }
- }
- private function getminimumCommissionGorUser($user_id)
- {
- global $langs, $db;
- $userObj = new User($this->db);
- $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}";
- $result = $db->query($sql);
- while ($row = $db->fetch_object($result)) {
- $minimum_monthly_commission = $row->minimum_monthly_commission;
- }
- if (!$result) {
- dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
- setEventMessage($langs->trans('noUserForMinimumCommission'), 'errors');
- }
- return $minimum_monthly_commission;
- }
- private function setRowColor($rownum)
- {
- return $rownum % 2 == 0 ? '#b0c4de' : 'white';
- }
- private function drawCurrentBalance($user_id)
- {
- $balance = $this->getFullBalance($user_id, $this->db);
- if (isset($ammount[0])) {
- $earlierCommissionHUF = $balance[0]['amount'] == null ? 0 : $balance[0]['amount'];
- } else {
- $earlierCommissionHUF = 0;
- }
- $earlierCommissionHUF = $balance[0]['amount'] == null ? 0 : $balance[0]['amount'];
- //$earlierCommissionEUR = $balance[1]['amount'] == null ? 0 : $balance[1]['amount'];
- $warning = $this->isWarning($earlierCommissionHUF);
- print '<td style="text-align:center;">' . number_format($earlierCommissionHUF, 0, '.', ' ') . ' HUF ' . $warning . '</td>';
- /* $warning = $this->isWarning($earlierCommissionEUR);
- print '<td style="text-align:center;">' . number_format($earlierCommissionEUR, 0, '.', ' ') . ' EUR ' . $warning . '</td>'; */
- }
- private function drawPayedRows($user_id, $payment_type)
- {
- $amounts = $this->getAllPaymenttype($user_id, $this->db, $payment_type);
- foreach ($amounts as $amount) {
- print '<td style="text-align:center;">' . number_format($amount['amount'], 0, '.', ' ') . ' ' . $amount['type'] . ' </td>';
- }
- }
- function tableDrawerForHistory($allSalesUsers, $idmenu)
- {
- $rownum = 0;
- foreach ($allSalesUsers as $user) {
- $url = '/custom/financialreport/commissionhistory_list.php?user_id=' . $user['rowid'] . '&idmenu=' . $idmenu . '&payment_type=2&mainmenu=financialreport&leftmenu=';
- $bgcolor = $this->setRowColor($rownum);
- print '<tr style="height:30px; background-color: ' . $bgcolor . '">
- <td><a style="display: block; width: 100%; height: 100%;" href="' . $url . '">' . $user['lastname'] . ' ' . $user['firstname'] . '</a></td>';
- print '<td style="text-align: center;">' . $user['nickname'] . '</td>';
- print '<td style="text-align: center;">' . $user['login'] . '</td>';
- // 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.
- $this->drawCurrentBalance($user['rowid']);
- $this->drawPayedRows($user['rowid'], 2);
- $this->drawPayedRows($user['rowid'], 0);
- print '</tr>';
- $rownum++;
- }
- }
- function tableDrawerForDailyClosing($allSalesUsers, $idmenu)
- {
- $rownum = 0;
- foreach ($allSalesUsers as $user) {
- $url = '/custom/settlements/dailyclosing_card.php?user_id=' . $user['rowid'] . '&idmenu=' . $idmenu . '&mainmenu=settlements&leftmenu=';
- $bgcolor = $this->setRowColor($rownum);
- print '<tr style="height:30px; background-color: ' . $bgcolor . '">
- <td><a style="display: block; width: 100%; height: 100%;" href="' . $url . '">' . $user['lastname'] . ' ' . $user['firstname'] . '</a></td>';
- print '<td style="text-align: center;">' . $user['nickname'] . '</td>';
- print '<td style="text-align: center;">' . $user['login'] . '</td>';
- // 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.
- $this->drawCurrentBalance($user['rowid']);
- $this->drawPayedRows($user['rowid'], 2);
- $this->drawPayedRows($user['rowid'], 0);
- print '</tr>';
- $rownum++;
- }
- }
- function generateRef($payment_type)
- {
- return $this->getTypeOfPayment($payment_type) . '_' . dol_now() . '_' . rand(1000000, 9999999);
- }
- /* function checkBalance($user_id, $date)
- {
- $sql = "SELECT invoices FROM " . MAIN_DB_PREFIX . "financialreport_userinvoice
- WHERE user_id = {$user_id}
- AND date_creation BETWEEN '{$date} 00:00:00' AND '{$date} 23:59:59'
- AND payment_type = 2
- ";
- $resultBalanceData = $this->db->query($sql);
- $result = pg_fetch_all($resultBalanceData);
- return is_array($result);
- } */
- function getOccassionOfThisPeriodByDateAndUserId($user_id, $from, $to)
- {
- return rand(100, 1000);
- }
- function createDataArrayForLoginLogotOccassionTable($results)
- {
- $array = [];
- $i = 0;
- foreach ($results as $record) {
- if ($record->login_logout_status == 0) {
- $array[$i]['login'] = date('Y-m-d H:i:s', $record->date_creation);
- } else {
- if (isset($record->date_creation)) {
- $array[$i]['logout'] = date('Y-m-d H:i:s', $record->date_creation);
- }
- }
- $i++;
- }
- return $array;
- }
- function createUserDataArray($array, $userOfGroups)
- {
- $userDataArray = [];
- $count = count($array);
- for ($k = 0; $k < $count; $k++) {
- if (isset($array[$k]['login'])) {
- if (!isset($userDataArray[$k - 1]['logout']) && $k != 0) {
- $userDataArray[$k - 1]['logout'] = $array[$k]['login'] . '*';
- }
- $userDataArray[$k]['login'] = $array[$k]['login'];
- }
- if (isset($array[$k]['logout'])) {
- $userDataArray[$k - 1]['logout'] = $array[$k]['logout'];
- }
- if ($k == $count - 1 && isset($deletedUsersArray[$userOfGroups['user_id']])) {
- $userDataArray[$k]['logout'] = $array[$userOfGroups['user_id']];
- }
- }
- return $userDataArray;
- }
- function updateUserDataArray($userDataArray, $deletedUsersArray, $userOfGroups, $commmissionhandler)
- {
- foreach ($userDataArray as $key => $period) {
- $from = $period['login'];
- $to = isset($period['logout']) ? $period['logout'] : (isset($deletedUsersArray[$userOfGroups['user_id']]) ? $deletedUsersArray[$userOfGroups['user_id']] : date('Y-m-d', dol_now()) . ' 23:59:59');
- //print $from . ' - ' . $to . '<br>';
- if (isset($from)) {
- $commission_HUF = $commmissionhandler->getOccassionOfThisPeriodByDateAndUserId_HUF($userOfGroups['user_id'], $from, $to);
- $commission_EURToHUF = $commmissionhandler->getOccassionOfThisPeriodByDateAndUserId_EURToHUF($userOfGroups['user_id'], $from, $to);
- $userDataArray[$key]['commission'] = $commission_HUF + $commission_EURToHUF;
- }
- }
- return $userDataArray;
- }
- function getAmountOfCommissions($userDataArray)
- {
- $amount = 0;
- foreach ($userDataArray as $record) {
- $amount += intval($record);
- }
- return $amount;
- }
- function getAllFacturesOfThisUser($user_id, $from, $to)
- {
- $crossShoppingFacturesString = '';
- $sql = "SELECT ref
- FROM llx_facture AS f
- WHERE fk_user_closing = {$user_id}
- AND date_closing BETWEEN '{$from}' AND '{$to}'";
- $result = $this->db->query($sql);
- if ($this->db->num_rows($result) > 0) {
- while ($row = $this->db->fetch_object($result)) {
- if ($crossShoppingFacturesString == "") {
- $crossShoppingFacturesString .= "'" . $row->ref . "'";
- } else {
- $crossShoppingFacturesString .= ",'" . $row->ref . "'";
- }
- }
- }
- return $crossShoppingFacturesString;
- }
- function getInvoicesRowidFromFacture($user_id, $from, $to)
- {
- $invocesRowidArray = [];
- $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "facture AS f WHERE fk_user_closing = {$user_id}
- AND EXISTS (SELECT * FROM " . MAIN_DB_PREFIX . "bbus_bbticketinvoiceprinting as bbip WHERE bbip.fk_facture = f.rowid ORDER BY bbip.rowid DESC LIMIT 1)
- AND date_closing BETWEEN '{$from}' AND '{$to}'";
- $resultInvoicesData = $this->db->query($sql);
- if ($this->db->num_rows($resultInvoicesData) != 0) {
- $result = pg_fetch_all($resultInvoicesData);
- foreach ($result as $value) {
- $invocesRowidArray[] = $value['rowid'];
- }
- $invocesRowidString = implode(',', $invocesRowidArray);
- }
- $readyInvoices = $this->getAllComissionInvoicesOfUserInTheGroupFromUserInvoice($user_id, $from, $to);
- if (!empty($readyInvoices)) {
- $invocesRowidString = $this->giveMeTheDifferenceInString($readyInvoices, $invocesRowidString);
- }
- return $invocesRowidString;
- }
- function getCrossShoppingInvoicesRowidFromFacture($allFactures, $from, $to)
- {
- $facturesRowids = '';
- $params = ["from" => $from, "to" => $to, "factures" => $allFactures];
- $postFields = json_encode($params);
- $crossShoppingFactures = $this->curlRunner('bookingapi/getPrintedFacturesRefs', $postFields, 'POST', true);
- if ($crossShoppingFactures !== '') {
- $sql = "SELECT rowid FROM llx_facture WHERE ref IN ($crossShoppingFactures)";
- $result = $this->db->query($sql);
- if ($this->db->num_rows($result) > 0) {
- while ($row = $this->db->fetch_object($result)) {
- if ($facturesRowids == "") {
- $facturesRowids .= $row->rowid;
- } else {
- $facturesRowids .= "," . $row->rowid;
- }
- }
- }
- }
- return $facturesRowids;
- }
- function getInvoicesRowidFromFactureInAnIntervalByEveryUser($users, $from, $to, $exception)
- {
- $invocesRowidArray = [];
- $sql = "SELECT f.rowid FROM " . MAIN_DB_PREFIX . "facture as f WHERE fk_user_closing IN({$users})";
- if ($exception != '') {
- $sql .= " AND rowid NOT IN({$exception})";
- }
- $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)
- AND date_closing BETWEEN '{$from}' AND '{$to}'";
- //print $sql . "\r\n";
- $resultInvoicesData = $this->db->query($sql);
- if ($this->db->num_rows($resultInvoicesData) != 0) {
- $result = pg_fetch_all($resultInvoicesData);
- foreach ($result as $value) {
- $invocesRowidArray[] = $value['rowid'];
- }
- $invocesRowidString = implode(',', $invocesRowidArray);
- }
- return $invocesRowidString;
- }
- function getInvoicesRowidFromFactureInAnIntervalByEveryUserWithoutInvoicePrinting($users, $from, $to, $exception)
- {
- $crossShoppingFacturesString = '';
- $sql = "SELECT f.ref FROM " . MAIN_DB_PREFIX . "facture as f WHERE fk_user_closing IN({$users})";
- if ($exception != '') {
- $sql .= " AND rowid NOT IN({$exception})";
- }
- $sql .= " AND date_closing BETWEEN '{$from}' AND '{$to}'";
- //print $sql . "\r\n";
- $resultInvoicesData = $this->db->query($sql);
- if ($this->db->num_rows($resultInvoicesData) > 0) {
- while ($row = $this->db->fetch_object($resultInvoicesData)) {
- if ($crossShoppingFacturesString == "") {
- $crossShoppingFacturesString .= "'" . $row->ref . "'";
- } else {
- $crossShoppingFacturesString .= ",'" . $row->ref . "'";
- }
- }
- }
- return $crossShoppingFacturesString;
- }
- function getAllComissionInvoicesOfUserInTheGroupFromUserInvoice($user_id, $from, $to)
- {
- $arraytmp = [];
- $invocesRowidString = '';
- $userInvocesObj = new UserInvoice($this->db);
- $result = $userInvocesObj->fetchAll('ASC', 'rowid', 0, 0, ['customsql' => "user_id = " . $user_id . " AND date_creation BETWEEN '" . $from . "' AND '" . $to . "'"]);
- foreach ($result as $data) {
- if (!empty($data->invoices) || $data->invoices != '') {
- $array1 = explode(',', $data->invoices);
- $arraytmp = array_merge($arraytmp, $array1);
- }
- }
- $invocesRowidString = implode(',', $arraytmp);
- //print $invocesRowidString;
- return $invocesRowidString;
- }
- function giveMeTheDifferenceInString($readyInvoices, $invocesRowidString)
- {
- $string = '';
- if ($readyInvoices != '' && $invocesRowidString != '') {
- $array1 = explode(',', $readyInvoices);
- $array2 = explode(',', $invocesRowidString);
- /* print 'array1: ';
- print_r($array1);
- print '<br>';
- print 'array2: ';
- print_r($array2);
- print '<br>'; */
- $arrayDiff = array_diff($array2, $array1);
- //$arrayDiff = array_diff($array1, $array2);
- /* print 'Diff: ';
- print_r($arrayDiff);
- print '<br>';
- print '<br>';
- print '<br>';
- */
- //$arrayDiff = count($array2) > count($array1) ? array_diff($array2, $array1) : array_diff($array1, $array2);
- $string = implode(',', $arrayDiff);
- return $string;
- }
- return $string;
- }
- function getHtmlForConfirmWindow($commission)
- {
- $userData = [];
- $userObj = new User($this->db);
- foreach ($commission as $value) {
- $itemData = explode('_', $value);
- $userdata = $userObj->fetch($itemData[0]);
- //print_r($userObj);exit;
- $userData[$userObj->id]['name'] = $userObj->lastname . ' ' . $userObj->firstname . ' (' . $userObj->login . ') ' . $userObj->array_options['options_nickname'];
- $summaHUF += $itemData[2];
- }
- $uniformHUF = $summaHUF / count($commission);
- $array[] = $userData;
- $array[] = $uniformHUF;
- return $array;
- }
- function azosszesElemEgyezik($tomb)
- {
- $szamlalo = array_count_values($tomb);
- $kulonbozoErtekekSzama = count($szamlalo);
- return $kulonbozoErtekekSzama === 1;
- }
- function getUsersArray($data)
- {
- foreach ($data as $item) {
- $itemData = explode('_', $item);
- $usersArray[] = $itemData[0];
- }
- return $usersArray;
- }
- function checkUserInvoiceRecordAvailability($user_id)
- {
- $userInvoiceObj = new UserInvoice($this->db);
- $now = dol_now();
- $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'"]);
- return $result;
- }
- function deleteUserFromUsersArrayTMPArray($key, $usersArrayTMP)
- {
- $index = array_search($key, $usersArrayTMP);
- if ($index !== false) {
- unset($usersArrayTMP[$index]);
- }
- return $usersArrayTMP;
- }
- function saveUserInvoiceRecord($usersArrayFilteredUsersFrom, $val, $uniformHUF, $settledInvoices)
- {
- global $user;
- $userinvoice = new UserInvoice($this->db);
- $currency = 0;
- $userinvoice->ref = $this->generateRef(2);
- $userinvoice->label = 'Jutalék/Commission ' . $usersArrayFilteredUsersFrom[$val];
- $userinvoice->description = 'Összeg / Amount: ' . $uniformHUF . 'HUF.';
- $userinvoice->user_id = $val;
- $userinvoice->payment_type = 2;
- $userinvoice->amount = $uniformHUF;
- $userinvoice->currency = $currency;
- $userinvoice->individual = 0;
- $userinvoice->invoices = $settledInvoices;
- $userinvoice->date_creation = strtotime($usersArrayFilteredUsersFrom[$val]);
- $userinvoice->create($user);
- }
- function getAllDifferentDatesASC($from, $to)
- {
- foreach ($from as $fromvalue) {
- foreach ($fromvalue as $value1) {
- $allDates[] = $value1;
- }
- }
- foreach ($to as $tovalue) {
- foreach ($tovalue as $value1) {
- $allDates[] = $value1;
- }
- }
- $allDates = array_unique($allDates);
- return $allDates;
- }
- function getQueryArray($from, $to)
- {
- $allDates = $this->getAllDifferentDatesASC($from, $to);
- uasort($allDates, 'datumOsszehasonlitas');
- $countAllDatesArray = count($allDates);
- $allDates = array_values($allDates);
- for ($i = 0; $i < $countAllDatesArray - 1; $i++) {
- $queryArray[$i]['from'] = $allDates[$i];
- $queryArray[$i]['to'] = $allDates[$i + 1];
- }
- return $queryArray;
- }
- function getAllComissionInvoicesOfUserInTheGroupFromUserInvoiceCreated($usersArray, $from, $to)
- {
- $userInvocesObj = new UserInvoice($this->db);
- $result = $userInvocesObj->fetchAll('ASC', 'rowid', 0, 0, ['customsql' => "user_id IN(" . $usersArray . ") AND date_creation BETWEEN '" . $from . "' AND '" . $to . "'"]);
- $all = [];
- foreach ($result as $key => $value) {
- //print $value->user_id . ' - ';
- //print $value->invoices . "\r\n";
- $arrayTmp = explode(',', $value->invoices);
- $all = array_merge($all, $arrayTmp);
- }
- $all = array_unique($all);
- $all = array_filter($all);
- sort($all);
- return implode(',', $all);
- }
- public function getGroupMemberHistory($user_id, $group_id, $date)
- {
- $groupMemberHistory = [];
- $from = $date . ' 00:00:00';
- $to = $date . ' 23:59:59';
- $UserNaplo = new UserNaplo($this->db);
- $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}'"]);
- foreach ($result as $record) {
- if ($record->status == 1) {
- $groupMemberHistory[]['added'] = date("Y-m-d H:i:s", $record->date_creation);
- } else {
- $groupMemberHistory[]['deleted'] = date("Y-m-d H:i:s", $record->date_creation);
- }
- }
- return $groupMemberHistory;
- }
- function getUsersByIdFromGroupUsers($id)
- {
- global $db;
- $usersOfGroup = [];
- if (isset($id)) {
- $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
- INNER JOIN " . MAIN_DB_PREFIX . "user AS u ON u.rowid = gu.fk_user
- WHERE gu.fk_Settlements_group = {$id}";
- $data = $db->query($sql);
- if (!$data) {
- dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
- setEventMessage('A csoporthoz rendelt felhasználók naplózási lekérdezésébe valami hiba csúszott.', 'errors');
- return $usersOfGroup;
- }
- while ($row = pg_fetch_assoc($data)) {
- $usersOfGroup[] = $row;
- }
- }
- return $usersOfGroup;
- }
- function getDeletedHotelUsers($id)
- {
- global $db;
- $deletedUsersArray = [];
- if (isset($id)) {
- $sql = "SELECT user_id, date_creation as date
- FROM " . MAIN_DB_PREFIX . "settlements_usernaplo
- WHERE group_user_id = {$id}
- AND status = 0 ORDER BY date_creation ASC";
- //print $sql;exit;
- $data = $db->query($sql);
- $dataArray = pg_fetch_all($data);
- if (empty($dataArray)) {
- dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
- return $deletedUsersArray;
- }
- foreach ($dataArray as $row) {
- $deletedUsersArray[$row['user_id']][] = $row['date'];
- }
- }
- return $deletedUsersArray;
- }
- function getUserdataFromNaploByUaserId($user_id, $userGroupId)
- {
- global $db;
- $date = '';
- $sql = "SELECT date_creation as date FROM " . MAIN_DB_PREFIX . "settlements_usernaplo
- WHERE user_id = {$user_id} AND group_user_id = {$userGroupId} AND status = 1
- ORDER BY rowid ASC LIMIT 1";
- //print $sql;
- $data = $db->query($sql);
- $dataArray = pg_fetch_all($data);
- if (empty($dataArray)) {
- dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
- return $date;
- }
- foreach ($dataArray as $row) {
- return $row['date'];
- }
- }
- function createDaterangeString($daterange)
- {
- $array = explode(' - ', $daterange);
- return str_replace('-', '.', $array[0]) . ' - ' . str_replace('-', '.', $array[1]);
- }
- function getUsersOfHotelGroup2($id, $daterange)
- {
- global $db;
- $dates = explode(' - ', $daterange);
- $now = dol_now();
- $to = $dates[1] > date('Y-m-d', $now) ? date('Y-m-d', $now) : $dates[1];
- $sql = "SELECT u.rowid, u.firstname, u. lastname, ue.user_category FROM " . MAIN_DB_PREFIX . "settlements_usernaplo AS un
- INNER JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = un.user_id
- INNER JOIN " . MAIN_DB_PREFIX . "user_extrafields AS ue ON ue.fk_object = u.rowid
- WHERE un.date_creation BETWEEN '{$dates[0]} 00:00:00' AND '{$to} 23:59:59'
- AND un.group_user_id = {$id}
- GROUP BY u.firstname, u.lastname, ue.user_category, u.rowid";
- $data = $db->query($sql);
- $result = pg_fetch_all($data);
- if (empty($result)) {
- return [];
- }
- return $result;
- }
- function getUsersOfHotelGroup($id, $daterange, $entity)
- {
- global $db;
- $array = [];
- $dates = explode(' - ', $daterange);
- $now = dol_now();
- $to = $dates[1] > date('Y-m-d', $now) ? date('Y-m-d', $now) : $dates[1];
- if (isset($id)) {
- $sql = "SELECT u.rowid, u.firstname, u. lastname, ue.user_category FROM " . MAIN_DB_PREFIX . "facture AS f
- INNER JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = f.fk_user_closing
- INNER JOIN " . MAIN_DB_PREFIX . "user_extrafields AS ue ON ue.fk_object = u.rowid
- INNER JOIN " . MAIN_DB_PREFIX . "facture_extrafields as fe ON fe.fk_object = f.rowid
- WHERE f.date_closing BETWEEN '{$dates[0]} 00:00:00' AND '{$to} 23:59:59'
- AND f.entity = {$entity}
- AND fe.react_facture = {$id}
- GROUP BY u.rowid, u.firstname, u. lastname, ue.user_category";
- //print $sql;
- $data = $db->query($sql);
- $array = pg_fetch_all($data);
- if (empty($result)) {
- return $array;
- }
- }
- return $array;
- }
- function getUsersList($id, $daterange, $entity)
- {
- global $db;
- $string = '';
- $result = $this->getUsersOfHotelGroup($id, $daterange, $entity);
- foreach ($result as $row) {
- $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>';
- }
- return $string;
- }
- function getUsersIdList($id, $daterange, $entity)
- {
- global $db;
- $result = $this->getUsersOfHotelGroup($id, $daterange, $entity);
- if (!empty($result)) {
- foreach ($result as $row) {
- $array[] = $row['rowid'];
- }
- return implode(',', $array);
- }
- return '';
- }
- function getAllAmountInPeriod($id, $daterange, $currency, $usersIdList, $entity)
- {
- //$entity = 1;
- global $db;
- $result = 0;
- $dates = explode(' - ', $daterange);
- $now = dol_now();
- $to = $dates[1] > date('Y-m-d', $now) ? date('Y-m-d', $now) : $dates[1];
- if (isset($id)) {
- $sql = "SELECT sum(f.total_ttc) FROM " . MAIN_DB_PREFIX . "facture as f
- INNER JOIN " . MAIN_DB_PREFIX . "facture_extrafields as fe ON fe.fk_object = f.rowid
- WHERE f.paye = 1
- AND f.date_closing BETWEEN '{$dates[0]} 00:00:00' AND '{$to} 23:59:59'";
- if ($usersIdList !== '') {
- $sql .= " AND f.fk_user_closing in($usersIdList)";
- }
- $sql .= " AND f.multicurrency_code = '{$currency}'
- AND f.entity = {$entity}
- AND fe.react_facture = {$id}";
- //print $sql;
- $data = $db->query($sql);
- $result = pg_fetch_all($data);
- return is_null($result[0]['sum']) ? 0 : $result[0]['sum'];
- }
- }
- function getAllCommissionInPeriod($id, $daterange, $currency, $usersIdList, $entity)
- {
- global $db;
- $commissionsArray = [];
- $dates = explode(' - ', $daterange);
- $now = dol_now();
- $to = $dates[1] > date('Y-m-d', $now) ? date('Y-m-d', $now) : $dates[1];
- if (isset($id)) {
- $sql = "SELECT f.total_ttc, fe.commission
- FROM " . MAIN_DB_PREFIX . "facture as f
- INNER JOIN " . MAIN_DB_PREFIX . "facture_extrafields as fe ON fe.fk_object = f.rowid
- WHERE f.paye = 1
- AND f.date_closing BETWEEN '{$dates[0]} 00:00:00' AND '{$to} 23:59:59'";
- if ($usersIdList !== '') {
- $sql .= " AND f.fk_user_closing in($usersIdList)";
- }
- $sql .= " AND f.multicurrency_code = '{$currency}'
- AND f.entity = '{$entity}'
- AND fe.react_facture = {$id}";
- //print $sql;exit;
- $data = $db->query($sql);
- $result = pg_fetch_all($data);
- //print_r($result);
- if (!empty($result)) {
- foreach ($result as $row) {
- $commissionValue = $this->getCommissionData($row['commission'], 0);
- $commissionUnit = $this->getCommissionData($row['commission'], 1);
- if ($commissionUnit == '%') {
- $commissionsArray[] = ($row['total_ttc'] / 100) * $commissionValue;
- } else {
- $commissionsArray[] = $commissionValue;
- }
- }
- }
- return $this->getAmountOfCommissions($commissionsArray);
- }
- return 0;
- }
- private function getCommissionData($commission, $number)
- {
- $array = explode('_', $commission);
- return $array[$number];
- }
- public function getAllHotels()
- {
- global $db;
- $resultArray = [];
- $hotelsObj = new Hotel($db);
- $hotelsArray = $hotelsObj->fetchAll('ASC', 'label', 0, 0);
- if (!empty($hotelsArray)) {
- foreach ($hotelsArray as $hotelRecord) {
- $resultArray[$hotelRecord->id] = $hotelRecord->label;
- }
- }
- return $resultArray;
- }
- public function getGroupRefByID($id)
- {
- if (isset($id)) {
- global $db;
- $sql = "SELECT ref FROM " . MAIN_DB_PREFIX . "settlements_group WHERE rowid = {$id}";
- $data = $db->query($sql);
- if (!$data) {
- dol_syslog("No group found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
- }
- while ($row = pg_fetch_assoc($data)) {
- return $row['ref'];
- }
- }
- return '';
- }
- public function getGroupEntityId($id)
- {
- if (isset($id)) {
- global $db;
- $sql = "SELECT fk_entity FROM " . MAIN_DB_PREFIX . "settlements_group WHERE rowid = {$id}";
- $data = $db->query($sql);
- if (!$data) {
- dol_syslog("No group found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
- }
- while ($row = pg_fetch_assoc($data)) {
- return $row['fk_entity'];
- }
- }
- return null;
- }
- public function getGroupLabelById($id)
- {
- global $db;
- $groupObj = new Group($db);
- $groupObj->fetch($id);
- return $groupObj->ref;
- }
- public function getFirstDateFromUserNaplo($id)
- {
- global $db;
- $from = date("Y-m-d") . ' 00:00:00';
- $to = date("Y-m-d H:i:s");
- $sql = "SELECT un.date_creation FROM " . MAIN_DB_PREFIX . "settlements_usernaplo AS un
- WHERE un.group_user_id = {$id} AND un.date_creation BETWEEN '{$from}' AND '{$to}' AND un.status = 1
- ORDER BY un.date_creation ASC LIMIT 1";
- //print $sql;exit;
- $data = $db->query($sql);
- if (!$data) {
- dol_syslog("No group found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
- }
- while ($row = pg_fetch_all($data)) {
- return $row[0]['date_creation'];
- }
- return null;
- }
- public function getNamedataFoTheUser($user_id)
- {
- global $db;
- $sql = "SELECT u.firstname, u.lastname, u.login FROM " . MAIN_DB_PREFIX . "user AS u WHERE rowid = {$user_id}";
- //print $sql;exit;
- $data = $db->query($sql);
- foreach (pg_fetch_all($data) as $userData) {
- return $userData['firstname'] . ' ' . $userData['lastname'] . ' (' . $userData['login'] . ')';
- }
- }
- public function checklogoutRecordInUserNaplo($user_id, $from, $id)
- {
- global $db;
- $sql = "SELECT date_creation FROM " . MAIN_DB_PREFIX . "settlements_usernaplo
- WHERE group_user_id = {$id}
- AND user_id = {$user_id}
- AND date_creation > '{$from}'
- AND status = 0
- ORDER BY date_creation ASC LIMIT 1";
- $data = $db->query($sql);
- while ($row = pg_fetch_assoc($data)) {
- return $row['date_creation'];
- }
- }
- public function getGTAndGUArray()
- {
- global $db;
- $sql = "SELECT fk_groupid, fk_group_tools_id FROM " . MAIN_DB_PREFIX . "settlements_usergrouptoolgroup";
- $result = $db->query($sql);
- if (pg_num_rows($result) > 0) {
- while ($row = pg_fetch_assoc($result)) {
- $array[$row['fk_groupid']] = $row['fk_group_tools_id'];
- }
- return $array;
- }
- return [];
- }
- function getAllEntities()
- {
- $entitiesArray = [];
- $sql = "SELECT rowid, label FROM " . MAIN_DB_PREFIX . "entity ORDER BY label ASC";
- $data = $this->db->query($sql);
- while ($row = pg_fetch_assoc($data)) {
- $entitiesArray[$row['rowid']] = $row['label'];
- }
- return $entitiesArray;
- }
- function createPopoupBox($numberOfUsers, $usersArray, $id)
- {
- $popoupBox = '<div style="float:right; padding-bottom: 10px;" title="';
- foreach ($usersArray as $users) {
- $popoupBox .= '<span class="fas fa-user em080" style=" color: #a69944;" cursor: pointer;></span>
- <u class="paddingrightonly">' . $users['lastname'] . ' ' . $users['firstname'] . ' (' . $users['login'] . ')</u><br>';
- }
- $popoupBox .= '" class="classfortooltip"><div onclick="popupboxClick(' . $id . ')" class="groupColumn2ndLine">' . $numberOfUsers . '</div>';
- return $popoupBox;
- }
- }
|