dailyclosing_card.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file settlements/settlementsindex.php
  22. * \ingroup settlements
  23. * \brief Home page of settlements top menu
  24. */
  25. // Load Dolibarr environment
  26. $res = 0;
  27. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  28. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  29. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php";
  30. }
  31. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  32. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
  33. $tmp2 = realpath(__FILE__);
  34. $i = strlen($tmp) - 1;
  35. $j = strlen($tmp2) - 1;
  36. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  37. $i--;
  38. $j--;
  39. }
  40. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) {
  41. $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
  42. }
  43. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) {
  44. $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php";
  45. }
  46. // Try main.inc.php using relative path
  47. if (!$res && file_exists("../main.inc.php")) {
  48. $res = @include "../main.inc.php";
  49. }
  50. if (!$res && file_exists("../../main.inc.php")) {
  51. $res = @include "../../main.inc.php";
  52. }
  53. if (!$res && file_exists("../../../main.inc.php")) {
  54. $res = @include "../../../main.inc.php";
  55. }
  56. if (!$res) {
  57. die("Include of main fails");
  58. }
  59. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  60. require_once DOL_DOCUMENT_ROOT . '/user/class/usergroup.class.php';
  61. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/groupusers.class.php';
  62. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/helper.class.php';
  63. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/daily_closing.class.php';
  64. require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/commissionhandler.class.php';
  65. require_once DOL_DOCUMENT_ROOT . '/custom/financialreport/class/helper.class.php';
  66. require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
  67. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/core/tpl/printPDF_szisz.php';
  68. dol_include_once('/settlements/lib/settlements_group.lib.php');
  69. $helper = new Helper($db);
  70. $commmissionhandler = new CommissionHandler();
  71. $userObj = new User($db);
  72. $dailyClosing = new DailyClosing();
  73. // Load translation files required by the page
  74. $langs->loadLangs(array("financialreport@financialreport"));
  75. $action = GETPOST('action', 'aZ09');
  76. $id = GETPOST('id', 'int');
  77. $user_id = GETPOST('user_id', 'int');
  78. $idmenu = GETPOST('idmenu', 'int');
  79. $stornochange = GETPOST('stornochange', 'aZ09');
  80. //$confirmdailyclosing = GETPOST('confirmdailyclosing', 'aZ09');
  81. $withholdingsArray = $_REQUEST['withholding']['withholdingAmount'];
  82. $withholdingsChkArray = $_REQUEST['withholding']['withholdingchk'];
  83. //var_dump($_REQUEST['withholding']['withholdingAmount']);
  84. //print_r($_REQUEST);
  85. $form = new Form($db);
  86. $formfile = new FormFile($db);
  87. $userObj = new User($db);
  88. $result = $userObj->fetch($user_id);
  89. $name = $userObj->firstname . ' ' . $userObj->lastname;
  90. if ($userObj->array_options['options_nickname'] != '') {
  91. $name .= ' (' . $userObj->array_options['options_nickname'] . ')';
  92. }
  93. //$Block1stData = $helper->get1stBlockData($user_id);
  94. if($id>0){
  95. $dailyClosingId = $id;
  96. }else{
  97. $dailyClosingId = $helper->getDailyClosingId($user_id);
  98. }
  99. //print $dailyClosingId;
  100. if (isset($dailyClosingId)) {
  101. $packageHistoryRecordObj = new PackageHistory($db);
  102. $packageHistoryRecordObj->fetch($dailyClosingId);
  103. if (!empty($packageHistoryRecordObj)) {
  104. $BLock2ndData = $helper->get2ndBlockData($packageHistoryRecordObj->package_id);
  105. $BLock3rdData = $helper->get3rdBlockData($packageHistoryRecordObj, $user_id);
  106. $factures = $helper->getAllFactures($packageHistoryRecordObj, $user_id);
  107. $addititonalDevices = $helper->getAddititonalDevices($dailyClosingId);
  108. $addititonalChangesDevices = $helper->getAddititonalChangesDevices($dailyClosingId);
  109. }
  110. }
  111. $changeMoneyHUF = 0;
  112. $changeMoneyEUR = 0;
  113. $disabled = '';
  114. if (!empty($packageHistoryRecordObj)) {
  115. $PackageHistoryOpen = $helper->searchAndFetchDailyClosingRow($packageHistoryRecordObj, $user_id, 0);
  116. }
  117. if (isset($_REQUEST['withholding']) && $stornochange == 'false') {
  118. $deviceArray = $_REQUEST['withholding']['withholdingchk'];
  119. $amountArray = $_REQUEST['withholding']['withholdingAmount'];
  120. $problemWithForm = $helper->checkForm($deviceArray, $amountArray);
  121. if ($problemWithForm == false) {
  122. $resultDailyClosing = $helper->updatePackageHistory($PackageHistoryOpen, $BLock3rdData);
  123. if ($resultDailyClosing < 0) {
  124. setEventMessage($langs->trans('dailyClosingFail'), 'errors');
  125. } else {
  126. $helper->returnDailyClosingWindowLocation($_SERVER["PHP_SELF"], $id, $user_id, $idmenu);
  127. }
  128. } else {
  129. setEventMessage($langs->trans('checklistFail'), 'errors');
  130. }
  131. }
  132. $stornochange = 'false';
  133. $title = '';
  134. $help_url = '';
  135. $morejs = '';
  136. $morecss = '';
  137. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
  138. $head = $dailyClosing->getHeader($object, $user_id, $idmenu);
  139. ###### Itt vannak a tabok ########
  140. print dol_get_fiche_head($head, 'card', $langs->trans("Group"), -1);
  141. $linkback = '<a href="' . dol_buildpath("/custom/settlements/settlementdailyclosingindex.php?idmenu=946&mainmenu=settlements&leftmenu=", 1) . '">' . '<b><span class="fa fa-arrow-left"></span> ' . $langs->trans("BackToList") . '</b></a>';
  142. print $linkback;
  143. include DOL_DOCUMENT_ROOT . '/custom/settlements/core/tpl/dailyclosing_open.tpl.php';
  144. llxFooter();
  145. $db->close();
  146. ?>
  147. <style>
  148. .dailyClosingHeader {
  149. height: 80px;
  150. text-align: center;
  151. background-color: rgb(163, 0, 51);
  152. color: white;
  153. padding-top: 0px;
  154. border-radius: 10px;
  155. }
  156. .unprintedfactures {
  157. height: 40px;
  158. text-align: center;
  159. background-color: rgb(163, 0, 51);
  160. color: white;
  161. padding-top: 0px;
  162. border-radius: 10px;
  163. cursor: pointer;
  164. }
  165. .unprintedfacturetr {
  166. font-weight: bold;
  167. }
  168. .dailyclosingTableLeftSide {
  169. width: 100%;
  170. }
  171. .withholding{
  172. background-color: lightgrey;
  173. padding-top: 3px;
  174. height: 32px;
  175. }
  176. </style>
  177. <script>
  178. $(document).ready(function () {
  179. });
  180. function saveScrollPosition() {
  181. var scrollPosition = window.pageYOffset || document.documentElement.scrollTop;
  182. localStorage.setItem('scrollPosition', scrollPosition);
  183. }
  184. function restoreScrollPosition() {
  185. var scrollPosition = localStorage.getItem('scrollPosition');
  186. if (scrollPosition) {
  187. window.scrollTo(0, scrollPosition);
  188. localStorage.removeItem('scrollPosition'); // Clear the stored position after using it
  189. }
  190. }
  191. window.onload = restoreScrollPosition;
  192. function setStorno(event) {
  193. this.saveScrollPosition();
  194. const checkbox = event.target;
  195. const isChecked = checkbox.checked;
  196. var form = document.getElementById("dailyclosingform");
  197. var xhr = new XMLHttpRequest(); // XMLHttpRequest objektum létrehozása
  198. xhr.onreadystatechange = function () {
  199. if (xhr.readyState === XMLHttpRequest.DONE) { // A kérés befejeződött
  200. if (xhr.status === 200) { // A válasz státusza OK
  201. //console.log(xhr.responseText); // A válasz tartalmának megjelenítése a konzolon
  202. $('#stornochange').val('true');
  203. form.submit();
  204. } else {
  205. console.error('Hiba történt a kérés során.'); // Hiba esetén hibaüzenet megjelenítése a konzolon
  206. }
  207. }
  208. };
  209. xhr.open("GET", "facturemarkedstorno.php?ajaxstorno=" + isChecked + "&facturerowid=" + checkbox.value, true); // A GET kérés konfigurálása, amely a "facturemarkedstorno.php" URL-t hívja meg
  210. xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  211. xhr.send(); // A kérés küldése
  212. }
  213. function setCommission(event) {
  214. this.saveScrollPosition();
  215. const checkbox = event.target;
  216. const isChecked = checkbox.checked;
  217. var form = document.getElementById("dailyclosingform");
  218. var xhr = new XMLHttpRequest(); // XMLHttpRequest objektum létrehozása
  219. xhr.onreadystatechange = function () {
  220. if (xhr.readyState === XMLHttpRequest.DONE) { // A kérés befejeződött
  221. if (xhr.status === 200) { // A válasz státusza OK
  222. //console.log(xhr.responseText); // A válasz tartalmának megjelenítése a konzolon
  223. $('#stornochange').val('true');
  224. form.submit();
  225. } else {
  226. console.error('Hiba történt a kérés során.'); // Hiba esetén hibaüzenet megjelenítése a konzolon
  227. }
  228. }
  229. };
  230. xhr.open("GET", "facturemarkedcommissiondeduction.php?ajaxstorno=" + isChecked + "&facturerowid=" + checkbox.value, true); // A GET kérés konfigurálása, amely a "facturemarkedstorno.php" URL-t hívja meg
  231. xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  232. xhr.send(); // A kérés küldése
  233. }
  234. function showFactures(event) {
  235. const checkbox = event.target;
  236. const isChecked = checkbox.checked;
  237. if ($('#unprintedfactureslist').css('display') === 'none') {
  238. $('#unprintedfactureslist').css('display', 'inline-block');
  239. $('#unprintedFactureSpan').removeClass('fa-chevron-down');
  240. $('#unprintedFactureSpan').addClass('fa-chevron-up');
  241. } else {
  242. $('#unprintedFactureSpan').addClass('fa-chevron-down');
  243. $('#unprintedFactureSpan').removeClass('fa-chevron-up');
  244. $('#unprintedfactureslist').css('display', 'none');
  245. }
  246. }
  247. function checkall(event) {
  248. const checkbox = event.target;
  249. const isChecked = checkbox.checked;
  250. $('.inputfield').val('');
  251. $('.DCcheckbox').prop('checked', isChecked);
  252. $('.fields').css('display', isChecked ? 'none' : 'inline-block');
  253. }
  254. function checkboxClick(event) {
  255. const checkbox = event.target;
  256. const dataChkValue = checkbox.getAttribute("data-chk");
  257. const dataInputValue = checkbox.getAttribute("data-input");
  258. const isChecked = checkbox.checked;
  259. $("#" + dataInputValue).val('');
  260. $("#" + dataChkValue).css('display', isChecked ? 'none' : 'inline-block');
  261. }
  262. </script>