| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929 |
- <?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';
- class HelperUserInvoice
- {
- 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 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}'";
- //print $sql;
- //exit;
- $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);
- //print $readyInvoices . '<br>';
- //print $invocesRowidString . '<br>';
- if (!empty($readyInvoices)) {
- $invocesRowidString = $this->giveMeTheDifferenceInString($readyInvoices, $invocesRowidString);
- }
- //print $invocesRowidString . '<br>';
- return $invocesRowidString;
- }
- 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 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);
- 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;
- }
- }
|