* Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2015 Jean-François Ferry * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file settlements/settlementsindex.php * \ingroup settlements * \brief Home page of settlements top menu */ // Load Dolibarr environment $res = 0; // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined) if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) { $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php"; } // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; } if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) { $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php"; } if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) { $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php"; } // Try main.inc.php using relative path if (!$res && file_exists("../main.inc.php")) { $res = @include "../main.inc.php"; } if (!$res && file_exists("../../main.inc.php")) { $res = @include "../../main.inc.php"; } if (!$res && file_exists("../../../main.inc.php")) { $res = @include "../../../main.inc.php"; } if (!$res) { die("Include of main fails"); } require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT . '/user/class/usergroup.class.php'; require_once DOL_DOCUMENT_ROOT . '/custom/financialreport/class/userinvoice.class.php'; require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/groupusers.class.php'; require_once DOL_DOCUMENT_ROOT . '/custom/financialreport/class/helper.class.php'; require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/helper.class.php'; require_once DOL_DOCUMENT_ROOT . '/custom/financialreport/class/commissionsettlements.class.php'; require_once DOL_DOCUMENT_ROOT . '/custom/financialreport/class/financialreportformhelper.class.php'; require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/commissionhandler.class.php'; require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/userloginnaplo.class.php'; require_once DOL_DOCUMENT_ROOT . '/custom/settlements/core/tpl/printPDF_szisz.php'; $helper = new HelperUserInvoice($db); $settlementsHelper = new Helper($db); $formHelper = new FinancialreportFormHelper($db); $commmissionhandler = new CommissionHandler(); $userLoginNaploObj = new UserLoginNaplo($db); // Load translation files required by the page $langs->loadLangs(array("settlements@settlements")); $action = GETPOST('action', 'aZ09'); $cancel = GETPOST('cancel', 'int'); $id = GETPOST('id', 'int'); $idmenu = GETPOST('idmenu', 'int'); $daterange = GETPOST('daterange', 'alpha'); $datepicker = GETPOST('datepicker', 'alpha'); $interval = GETPOST('interval', 'alpha'); $array = GETPOST('array', 'array'); $options = GETPOST('options', 'array'); $commission = GETPOST('commission', 'array'); $commissions = GETPOST('commissions', 'alpha'); $optionsString = GETPOST('optionsString', 'alpha'); $groupEntity = GETPOST('groupEntity', 'int'); $printSummary = GETPOST('printSummary', 'int'); $confirmsettlements = GETPOST('confirmsettlements', 'int'); $confirmpersonalsettlements = GETPOST('confirmpersonalsettlements', 'alpha'); if ($daterange == '' && $datepicker == '') { $now = dol_now(); $daterange = date("Y-m-d", $now) . ' - ' . date("Y-m-d", $now); $isSetDatepicker = true; $datesOfRange = $helper->createArray($daterange); } else { $daterange = $daterange != '' ? $daterange : $datepicker; $datesOfRange = $helper->createArray($daterange); $isSetDatepicker = $datepicker != ''; } $socid = GETPOST('socid', 'int'); if (isset($user->socid) && $user->socid > 0) { $action = ''; $socid = $user->socid; } $form = new Form($db); $formfile = new FormFile($db); $entities = $settlementsHelper->getAllEntities(); $entitiesArray = []; $selectedEntities = ''; foreach ($entities as $key => $value) { $val = GETPOST('entity_' . $key, 'int'); $entitiesArray[$key] = $val; /* if ($val != '') { $entitiesArrayIsEmpty = false; } */ } if (empty(array_filter($entitiesArray))) { $entitiesArray[1] = 1; } $selectedEntities = $helper->getEntities($entitiesArrayIsEmpty, $entities, $entitiesArray); $groups = $helper->getAllGroupsFromGroupClass($selectedEntities); $groupToolsAndGroupUsersArray = $helper->getGTAndGUArray(); if (empty($id)) { $keys = array_keys($groups); $id = $keys[0]; } include DOL_DOCUMENT_ROOT . '/custom/financialreport/core/actions_addupdatedelete.inc.php'; foreach ($datesOfRange as $date) { $usersOfGroups = $helper->getUsersByIdWithDate($db, $id, $date); $usersOfGroupsCol2 = $helper->getUsersByIdWithDateCol2($db, $id, $date); $groupEntityId = $helper->getGroupEntityId($id); } $formconfirm = ''; if ($confirmsettlements == 1) { $string = implode("@", $commission); foreach ($options as $optionkey => $optionValue) { $array[] = $optionkey . '|' . $optionValue; } $optionsString = implode("@", $array); //print $string; //print $optionsString; //exit; $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $id . '&commissions=' . $string . '&optionsString=' . $optionsString . '&groupEntity=' . $groupEntityId, $langs->trans('GroupSettlementsConfirm'), $langs->trans('GroupSettlementsConfirmObject'), 'confirm_settlement', '', 0, 1); } if ($confirmpersonalsettlements) { $commissionArray = []; $successfully = false; $selectedUserArray = explode('_', $confirmpersonalsettlements); $result = explode('_', $commission[$selectedUserArray[1]]); $userObj = new User($db); $commissionArray['user_id'] = $result[0]; $commissionArray['interval'] = $result[1]; $commissionArray['HUF'] = $result[2]; $commissionsForPost = implode('_', $commissionArray); $result = $userObj->fetch($result[0]); $userString = $userObj->firstname . ' ' . $userObj->lastname . ' (' . $userObj->login . ')'; $successfully = true; if (!$successfully) { setEventMessages('Sikertelen művelet.', [], 'errors'); } else { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $id . '&commissions=' . $commissionsForPost, $langs->trans('PersonalSettlementsConfirm'), $langs->trans('PersonalSettlementsConfirmObject', $userString), 'confirm_personal_settlement', '', 0, 1); } } if (isset($excelexport)) { $helper->createExcelHotelReport($daterange, $id, $entity, $groups); } llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs'); if (($confirmsettlements == 1) || $confirmpersonalsettlements) { print $formconfirm; } $url = $_SERVER["PHP_SELF"] . '?idmenu=' . $idmenu . '&mainmenu=financialreport&leftmenu=&id=' . $id; $now3thSection = dol_now(); print '
' . "\n"; print ''; print ''; print ''; print ''; print ''; $nowTitle = date('Y.m.d', dol_now()); print load_fiche_titre($langs->trans("SettlementsArea") . '  ' . $nowTitle, '', 'settlements.png@settlements'); print '
'; $columnWidth = 100 / count($entities); foreach ($entities as $key => $value) { if (!$entitiesArrayIsEmpty) { $checked = $entitiesArray[$key] == $key ? 'checked' : ''; } else { $checked = 'checked'; } print '
'; } print '
'; # 1 print '
'; print ''; print ''; foreach ($groups as $key => $val) { $coloredLine = $id == $key ? ' background-color: #b0c4de' : ''; print ''; } print '
' . $langs->trans("nameofgroup") . '
'; print '
'; # 2 print '
'; print ''; print ''; print ''; if (count($usersOfGroupsCol2) > 0) { foreach ($usersOfGroupsCol2 as $user) { print ''; } } else { print ''; } print '
' . $langs->trans("usersofgroup", $helper->getGroupRefByID($id)) . '
' . $langs->trans('Name') . '
' . $user['lastname'] . ' ' . $user['firstname'] . ' (' . $user['login'] . ')
' . $langs->trans('nouser') . '
'; print '
'; # 3 $colspan = 2; $payed = ''; print '
'; print ''; print ''; print ''; $allUsersCommissionsAmountForGroupsettlementButton = 0; $totalCommissionHUFEUR = 0; foreach ($datesOfRange as $date) { if (count($usersOfGroups) > 0) { $k = 0; $userOption = 0; foreach ($usersOfGroups as $userOfGroups) { $user_id = $userOfGroups['user_id']; $from = $userOfGroups['date_creation']; $logoutDate = $helper->checklogoutRecordInUserNaplo($user_id, $from, $id); $to = $logoutDate != '' ? $logoutDate : date('Y-m-d H:i:s', $now3thSection); $iNeedThisIdForRefreshDate = $logoutDate == '' ? 'class="refreshThis"' : ''; $checked = in_array($user_id, $options) ? 'checked' : ''; $dateInterval = $from; $dateInterval2 = $from . ' - ' . $to; $totalCommission = $commmissionhandler->getTotalCommission($user_id, $from, $to); $totalCommissionHUFEUR += $totalCommission; $disabledButton = $totalCommission == 0 ? 'disabled' : ''; $hiddenCommissionDataValue = $user_id . '_' . $dateInterval; $last5commissionSql = "SELECT ui.date_creation, ui.amount FROM llx_financialreport_userinvoice as ui WHERE ui.user_id = {$user_id} ORDER BY ui.rowid DESC LIMIT 2"; $last5commissionResult = $db->query($last5commissionSql); $last5CommissionArray = []; if ($db->num_rows($last5commissionResult) > 0){ while($l5row = $db->fetch_object($last5commissionResult)){ $last5CommissionArray[] = $l5row; } } print ''; print ''; $allUsersCommissionsAmountForGroupsettlementButton += $totalCommission; $currentUser = $user_id; $k++; $userOption++; } } if ($allUsersCommissionsAmountForGroupsettlementButton != 0) { $displayNone = empty($options) ? 'none;' : 'block'; print ''; } } print ''; print '' . "\n"; print ''; $formHelper->summary($id, $totalCommissionHUFEUR); // End of page llxFooter(); $db->close(); ?>
' . $langs->trans("settlements") . '
' . $langs->trans('selectAll') . '
'; print '
' . $langs->trans('asGroup') . '
' . $userOfGroups['lastname'] . ' ' . $userOfGroups['firstname'] . '
' . $helper->correctNumber($totalCommission) . ' HUF
(' . $userOfGroups['login'] . ')
' . $langs->trans('Commission') . '
' . $langs->trans('dailyMinimumCommission') . ': ' . $helper->correctNumber($commmissionhandler->getDailyMinimumCommission()) . ' HUF
' . $from . ' - ' . $to . '
'; print ''; foreach($last5CommissionArray as $commissionRecord){ print ''; } print '
Last commissions
' . $commissionRecord->date_creation . '' . $commissionRecord->amount . ' HUF
'; print ''; print '