card.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
  4. * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@zendsi.com>
  5. * Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  6. * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
  7. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. /**
  25. * \file htdocs/accountancy/supplier/card.php
  26. * \ingroup Accountancy
  27. * \brief Card expense report ventilation
  28. */
  29. require '../../main.inc.php';
  30. // Class
  31. require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
  32. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
  33. // Langs
  34. $langs->load("bills");
  35. $langs->load("accountancy");
  36. $langs->load("trips");
  37. $action = GETPOST('action', 'alpha');
  38. $codeventil = GETPOST('codeventil');
  39. $id = GETPOST('id');
  40. // Security check
  41. if ($user->societe_id > 0)
  42. accessforbidden();
  43. /*
  44. * Actions
  45. */
  46. if ($action == 'ventil' && $user->rights->accounting->bind->write) {
  47. if (! GETPOST('cancel', 'alpha')) {
  48. if ($codeventil < 0) $codeventil = 0;
  49. $sql = " UPDATE " . MAIN_DB_PREFIX . "expensereport_det";
  50. $sql .= " SET fk_code_ventilation = " . $codeventil;
  51. $sql .= " WHERE rowid = " . $id;
  52. $resql = $db->query($sql);
  53. if (! $resql) {
  54. setEventMessages($db->lasterror(), null, 'errors');
  55. }
  56. else
  57. {
  58. setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
  59. }
  60. } else {
  61. header("Location: ./lines.php");
  62. exit();
  63. }
  64. }
  65. /*
  66. * View
  67. */
  68. llxHeader("", $langs->trans('FicheVentilation'));
  69. if ($cancel == $langs->trans("Cancel")) {
  70. $action = '';
  71. }
  72. // Create
  73. $form = new Form($db);
  74. $expensereport_static = new ExpenseReport($db);
  75. $formaccounting = new FormAccounting($db);
  76. if (! empty($id)) {
  77. $sql = "SELECT er.ref, er.rowid as facid, erd.fk_c_type_fees, erd.comments, erd.rowid, erd.fk_code_ventilation,";
  78. $sql .= " f.id as type_fees_id, f.code as type_fees_code, f.label as type_fees_label,";
  79. $sql .= " aa.account_number, aa.label";
  80. $sql .= " FROM " . MAIN_DB_PREFIX . "expensereport_det as erd";
  81. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_type_fees as f ON f.id = erd.fk_c_type_fees";
  82. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON erd.fk_code_ventilation = aa.rowid";
  83. $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "expensereport as er ON er.rowid = erd.fk_expensereport";
  84. $sql .= " WHERE er.fk_statut > 0 AND erd.rowid = " . $id;
  85. $sql .= " AND er.entity IN (" . getEntity("expensereport", 0) . ")"; // We don't share object for accountancy
  86. dol_syslog("/accounting/expensereport/card.php sql=" . $sql, LOG_DEBUG);
  87. $result = $db->query($sql);
  88. if ($result) {
  89. $num_lines = $db->num_rows($result);
  90. $i = 0;
  91. if ($num_lines) {
  92. $objp = $db->fetch_object($result);
  93. print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $id . '" method="post">' . "\n";
  94. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  95. print '<input type="hidden" name="action" value="ventil">';
  96. print load_fiche_titre($langs->trans('ExpenseReportsVentilation'), '', 'title_setup');
  97. dol_fiche_head();
  98. print '<table class="border" width="100%">';
  99. // Ref
  100. print '<tr><td class="titlefield">' . $langs->trans("ExpenseReport") . '</td>';
  101. $expensereport_static->ref = $objp->ref;
  102. $expensereport_static->id = $objp->erid;
  103. print '<td>' . $expensereport_static->getNomUrl(1) . '</td>';
  104. print '</tr>';
  105. print '<tr><td>' . $langs->trans("Line") . '</td>';
  106. print '<td>' . stripslashes(nl2br($objp->rowid)) . '</td></tr>';
  107. print '<tr><td>' . $langs->trans("Description") . '</td>';
  108. print '<td>' . stripslashes(nl2br($objp->comments)) . '</td></tr>';
  109. print '<tr><td>' . $langs->trans("TypeFees") . '</td>';
  110. print '<td>' . ($langs->trans($objp->type_fees_code) == $objp->type_fees_code ? $objp->type_fees_label : $langs->trans(($objp->type_fees_code))) . '</td>';
  111. print '<tr><td>' . $langs->trans("Account") . '</td><td>';
  112. print $formaccounting->select_account($objp->fk_code_ventilation, 'codeventil', 1);
  113. print '</td></tr>';
  114. print '</table>';
  115. dol_fiche_end();
  116. print '<div class="center">';
  117. print '<input class="button" type="submit" value="' . $langs->trans("Save") . '">';
  118. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  119. print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
  120. print '</div>';
  121. print '</form>';
  122. } else {
  123. print "Error";
  124. }
  125. } else {
  126. print "Error";
  127. }
  128. } else {
  129. print "Error ID incorrect";
  130. }
  131. llxFooter();
  132. $db->close();