card.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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@open-dsi.fr>
  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 <https://www.gnu.org/licenses/>.
  22. *
  23. */
  24. /**
  25. * \file htdocs/accountancy/supplier/card.php
  26. * \ingroup Accountancy (Double entries)
  27. * \brief Card expense report ventilation
  28. */
  29. require '../../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array("bills", "accountancy", "trips"));
  34. $action = GETPOST('action', 'aZ09');
  35. $cancel = GETPOST('cancel', 'alpha');
  36. $backtopage = GETPOST('backtopage', 'alpha');
  37. $codeventil = GETPOST('codeventil', 'int');
  38. $id = GETPOST('id', 'int');
  39. // Security check
  40. if (!isModEnabled('accounting')) {
  41. accessforbidden();
  42. }
  43. if ($user->socid > 0) {
  44. accessforbidden();
  45. }
  46. if (!$user->hasRight('accounting', 'mouvements', 'lire')) {
  47. accessforbidden();
  48. }
  49. /*
  50. * Actions
  51. */
  52. if ($action == 'ventil' && $user->hasRight('accounting', 'bind', 'write')) {
  53. if (!$cancel) {
  54. if ($codeventil < 0) {
  55. $codeventil = 0;
  56. }
  57. $sql = " UPDATE ".MAIN_DB_PREFIX."expensereport_det";
  58. $sql .= " SET fk_code_ventilation = ".((int) $codeventil);
  59. $sql .= " WHERE rowid = ".((int) $id);
  60. $resql = $db->query($sql);
  61. if (!$resql) {
  62. setEventMessages($db->lasterror(), null, 'errors');
  63. } else {
  64. setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
  65. if ($backtopage) {
  66. header("Location: ".$backtopage);
  67. exit();
  68. }
  69. }
  70. } else {
  71. header("Location: ./lines.php");
  72. exit();
  73. }
  74. }
  75. /*
  76. * View
  77. */
  78. llxHeader("", $langs->trans('FicheVentilation'));
  79. if ($cancel == $langs->trans("Cancel")) {
  80. $action = '';
  81. }
  82. // Create
  83. $form = new Form($db);
  84. $expensereport_static = new ExpenseReport($db);
  85. $formaccounting = new FormAccounting($db);
  86. if (!empty($id)) {
  87. $sql = "SELECT er.ref, er.rowid as facid, erd.fk_c_type_fees, erd.comments, erd.rowid, erd.fk_code_ventilation,";
  88. $sql .= " f.id as type_fees_id, f.code as type_fees_code, f.label as type_fees_label,";
  89. $sql .= " aa.account_number, aa.label";
  90. $sql .= " FROM ".MAIN_DB_PREFIX."expensereport_det as erd";
  91. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_fees as f ON f.id = erd.fk_c_type_fees";
  92. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON erd.fk_code_ventilation = aa.rowid";
  93. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."expensereport as er ON er.rowid = erd.fk_expensereport";
  94. $sql .= " WHERE er.fk_statut > 0 AND erd.rowid = ".((int) $id);
  95. $sql .= " AND er.entity IN (".getEntity('expensereport', 0).")"; // We don't share object for accountancy
  96. dol_syslog("/accounting/expensereport/card.php", LOG_DEBUG);
  97. $result = $db->query($sql);
  98. if ($result) {
  99. $num_lines = $db->num_rows($result);
  100. $i = 0;
  101. if ($num_lines) {
  102. $objp = $db->fetch_object($result);
  103. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post">'."\n";
  104. print '<input type="hidden" name="token" value="'.newToken().'">';
  105. print '<input type="hidden" name="action" value="ventil">';
  106. print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($backtopage).'">';
  107. print load_fiche_titre($langs->trans('ExpenseReportsVentilation'), '', 'title_accountancy');
  108. print dol_get_fiche_head();
  109. print '<table class="border centpercent">';
  110. // Ref
  111. print '<tr><td class="titlefield">'.$langs->trans("ExpenseReport").'</td>';
  112. $expensereport_static->ref = $objp->ref;
  113. $expensereport_static->id = $objp->erid;
  114. print '<td>'.$expensereport_static->getNomUrl(1).'</td>';
  115. print '</tr>';
  116. print '<tr><td>'.$langs->trans("Line").'</td>';
  117. print '<td>'.stripslashes(nl2br($objp->rowid)).'</td></tr>';
  118. print '<tr><td>'.$langs->trans("Description").'</td>';
  119. print '<td>'.stripslashes(nl2br($objp->comments)).'</td></tr>';
  120. print '<tr><td>'.$langs->trans("TypeFees").'</td>';
  121. print '<td>'.($langs->trans($objp->type_fees_code) == $objp->type_fees_code ? $objp->type_fees_label : $langs->trans(($objp->type_fees_code))).'</td>';
  122. print '<tr><td>'.$langs->trans("Account").'</td><td>';
  123. print $formaccounting->select_account($objp->fk_code_ventilation, 'codeventil', 1);
  124. print '</td></tr>';
  125. print '</table>';
  126. print dol_get_fiche_end();
  127. print '<div class="center">';
  128. print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
  129. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  130. print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  131. print '</div>';
  132. print '</form>';
  133. } else {
  134. print "Error";
  135. }
  136. } else {
  137. print "Error";
  138. }
  139. } else {
  140. print "Error ID incorrect";
  141. }
  142. // End of page
  143. llxFooter();
  144. $db->close();