commissionsummaryindex.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. $res = 0;
  3. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  4. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  5. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php";
  6. }
  7. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  8. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
  9. $tmp2 = realpath(__FILE__);
  10. $i = strlen($tmp) - 1;
  11. $j = strlen($tmp2) - 1;
  12. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  13. $i--;
  14. $j--;
  15. }
  16. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) {
  17. $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
  18. }
  19. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) {
  20. $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php";
  21. }
  22. // Try main.inc.php using relative path
  23. if (!$res && file_exists("../main.inc.php")) {
  24. $res = @include "../main.inc.php";
  25. }
  26. if (!$res && file_exists("../../main.inc.php")) {
  27. $res = @include "../../main.inc.php";
  28. }
  29. if (!$res && file_exists("../../../main.inc.php")) {
  30. $res = @include "../../../main.inc.php";
  31. }
  32. if (!$res) {
  33. die("Include of main fails");
  34. }
  35. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  36. require_once DOL_DOCUMENT_ROOT . '/user/class/usergroup.class.php';
  37. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/groupusers.class.php';
  38. require_once DOL_DOCUMENT_ROOT . '/custom/financialreport/class/helper.class.php';
  39. require_once DOL_DOCUMENT_ROOT . '/custom/financialreport/class/userinvoice.class.php';
  40. require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/commissionhandler.class.php';
  41. require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
  42. $helper = new HelperUserInvoice($db);
  43. $commmissionhandler = new CommissionHandler();
  44. $userObj = new User($db);
  45. // Load translation files required by the page
  46. $langs->loadLangs(array("financialreport@financialreport"));
  47. $action = GETPOST('action', 'aZ09');
  48. $id = GETPOST('id', 'int');
  49. $idmenu = GETPOST('idmenu', 'int');
  50. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  51. $sortfield = GETPOST('sortfield', 'aZ09comma');
  52. $sortorder = GETPOST('sortorder', 'aZ09comma');
  53. $search_nickname = GETPOST('search_nickname', 'alpha');
  54. $search_name = GETPOST('search_name', 'alpha');
  55. $search_login = GETPOST('search_login', 'alpha');
  56. $searchArray = ['search_name' => $search_name, 'search_nickname' => $search_nickname];
  57. $confirmmakeupto = GETPOST('confirmmakeupto', 'alpha');
  58. $datastring = GETPOST('datastring', 'alpha');
  59. $year = GETPOST('year', 'int');
  60. $month = GETPOST('month', 'int');
  61. //print_r($_REQUEST);
  62. $search = array();
  63. foreach ($searchArray as $key => $val) {
  64. if (GETPOST($key, 'alpha') !== '') {
  65. $search[$key] = GETPOST($key, 'alpha');
  66. }
  67. }
  68. if (GETPOST('button_removefilter_x', 'alpha')) {
  69. foreach ($searchArray as $key => $val) {
  70. $search[$key] = '';
  71. $searchArray[$key] = '';
  72. $$key = '';
  73. }
  74. }
  75. if (!$sortorder) {
  76. $sortorder = "ASC";
  77. }
  78. $form = new Form($db);
  79. $formfile = new FormFile($db);
  80. include DOL_DOCUMENT_ROOT . '/custom/financialreport/core/actions_addupdatedelete.inc.php';
  81. $sql = "SELECT u.rowid, u.lastname, u.firstname, u.login, ue.nickname
  82. FROM llx_user AS u
  83. LEFT JOIN llx_user_extrafields AS ue ON u.rowid = ue.fk_object
  84. WHERE ue.user_category = '1'";
  85. if ($search_nickname) {
  86. $sql .= " AND ue.nickname LIKE '%{$search_nickname}%'";
  87. }
  88. if ($search_name) {
  89. $sql .= " AND (u.firstname LIKE '%{$search_name}%' OR u.lastname LIKE '%{$search_name}%')";
  90. }
  91. if ($search_login) {
  92. $sql .= " AND u.login LIKE '%{$search_login}%'";
  93. }
  94. $sql .= " ORDER BY u.lastname";
  95. $sql .= " {$sortorder}";
  96. $allSalesUsers = $helper->getAllSalesWithSQL($sql);
  97. if($year == '' || $year == 0 || empty($year) || is_null($year)){
  98. $year = date("Y");
  99. }
  100. if($month == '' || $month == 0 || empty($month) || is_null($month)){
  101. $month = date("n");
  102. }
  103. if($confirmmakeupto){
  104. $TMPArray = explode('|', $confirmmakeupto);
  105. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?datastring=' . $confirmmakeupto, $langs->trans('MakeUpToConfirm'), $langs->trans('MakeUpToConfirmObject', end($TMPArray), $helper->correctNumber($TMPArray[1])), 'confirm_makeupto', '', 0, 1);
  106. }
  107. $title = '';
  108. $help_url = '';
  109. $morejs = '';
  110. $morecss = '';
  111. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
  112. if ($confirmmakeupto) {
  113. print $formconfirm;
  114. }
  115. $url = $_SERVER["PHP_SELF"] . '?idmenu=' . $idmenu . '&mainmenu=financialreport&leftmenu=';
  116. print '<form method="POST" id="witholdingForm" action="' . $url . '">' . "\n";
  117. print '<input type="hidden" name="token" value="' . newToken() . '">';
  118. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  119. print '<input type="hidden" name="action" value="list">';
  120. print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
  121. print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
  122. print '<input type="hidden" name="year" value="' . $year . '">';
  123. print load_fiche_titre($langs->trans("OptionId"), '', 'financialreport.png@financialreport');
  124. print '<div style="height: 50px; background-color: lightgray; text-align: center; padding-top: 20px; border-radius: 10px;">';
  125. include DOL_DOCUMENT_ROOT . '/custom/financialreport/core/tpl/daterangedivbasecommission.tpl.php';
  126. print '</div>';
  127. print '
  128. <table style="width:100%;">
  129. <tr>
  130. <th>' . $langs->trans("username") . '</th>
  131. <th>' . $langs->trans("nickname") . '</th>
  132. <th>' . $langs->trans("MinimumCommission") . '</th>
  133. <th>' . $langs->trans("CommissionSupplement") . '</th>
  134. <th>' . $langs->trans("commission") . '</th>
  135. </tr>';
  136. $basicCommissionPage = true;
  137. include DOL_DOCUMENT_ROOT . '/custom/financialreport/core/tpl/search_fields_for_userslist.tpl.php';
  138. $rownum = 0;
  139. $helper->tableDrawerForBasicCommission($allSalesUsers, $db, $idmenu, $year, $month);
  140. print '</table>';
  141. print '</form>' . "\n";
  142. // End of page
  143. llxFooter();
  144. $db->close();